update option page
This commit is contained in:
parent
9ae13bd5eb
commit
2c90588e3b
@ -128,6 +128,23 @@
|
|||||||
return daysLeft + "D";
|
return daysLeft + "D";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calculateDTE(data, dateExpiration) {
|
||||||
|
// Convert the expiration date to a Date object
|
||||||
|
const expirationDate = new Date(dateExpiration);
|
||||||
|
|
||||||
|
return data.map((item) => {
|
||||||
|
const itemDate = new Date(item.date); // Convert item.date to a Date object
|
||||||
|
const timeDifference = expirationDate - itemDate; // Difference in milliseconds
|
||||||
|
const dte = Math.ceil(timeDifference / (1000 * 60 * 60 * 24)); // Convert ms to days
|
||||||
|
|
||||||
|
// Add the calculated DTE to the object
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
dte, // Add DTE as a new property
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let rawDataVolume = data?.getData?.volume?.map((item) => ({
|
let rawDataVolume = data?.getData?.volume?.map((item) => ({
|
||||||
...item,
|
...item,
|
||||||
dte: daysLeft(item?.date_expiration),
|
dte: daysLeft(item?.date_expiration),
|
||||||
@ -287,7 +304,7 @@
|
|||||||
let data = rawDataHistory?.sort(
|
let data = rawDataHistory?.sort(
|
||||||
(a, b) => new Date(a?.date) - new Date(b?.date),
|
(a, b) => new Date(a?.date) - new Date(b?.date),
|
||||||
);
|
);
|
||||||
|
console.log(data);
|
||||||
let dates = data?.map((item) => item?.date);
|
let dates = data?.map((item) => item?.date);
|
||||||
let avgPrice = data?.map((item) => item?.avg_price);
|
let avgPrice = data?.map((item) => item?.avg_price);
|
||||||
let priceList = data?.map((item) => item?.price);
|
let priceList = data?.map((item) => item?.price);
|
||||||
@ -361,9 +378,20 @@
|
|||||||
// Get the timestamp from the first parameter
|
// Get the timestamp from the first parameter
|
||||||
const timestamp = params[0].axisValue;
|
const timestamp = params[0].axisValue;
|
||||||
|
|
||||||
|
// Find the matching data point in rawDataHistory based on the date
|
||||||
|
const rawDataPoint = rawDataHistory.find(
|
||||||
|
(item) => item.date === timestamp,
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize result with timestamp
|
// Initialize result with timestamp
|
||||||
let result = timestamp + "<br/>";
|
let result = timestamp + "<br/>";
|
||||||
|
|
||||||
|
// Variables to store bid and ask values and their colors
|
||||||
|
let bidValue = null;
|
||||||
|
let askValue = null;
|
||||||
|
let bidColor = null;
|
||||||
|
let askColor = null;
|
||||||
|
|
||||||
// Sort params to ensure Vol appears last
|
// Sort params to ensure Vol appears last
|
||||||
params.sort((a, b) => {
|
params.sort((a, b) => {
|
||||||
if (a.seriesName === "Vol") return 1;
|
if (a.seriesName === "Vol") return 1;
|
||||||
@ -371,29 +399,50 @@
|
|||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add each series data
|
// Loop through each series data
|
||||||
params?.forEach((param) => {
|
params?.forEach((param) => {
|
||||||
const marker =
|
const marker =
|
||||||
'<span style="display:inline-block;margin-right:4px;' +
|
'<span style="display:inline-block;margin-right:4px;' +
|
||||||
"border-radius:10px;width:10px;height:10px;background-color:" +
|
"border-radius:10px;width:10px;height:10px;background-color:" +
|
||||||
param.color +
|
param.color +
|
||||||
'"></span>';
|
'"></span>';
|
||||||
result +=
|
|
||||||
marker +
|
if (param.seriesName === "Bid") {
|
||||||
param.seriesName +
|
bidValue = param.value;
|
||||||
": " +
|
bidColor = marker;
|
||||||
abbreviateNumberWithColor(param.value, false, true) +
|
} else if (param.seriesName === "Ask") {
|
||||||
"<br/>";
|
askValue = param.value;
|
||||||
|
askColor = marker;
|
||||||
|
} else {
|
||||||
|
result +=
|
||||||
|
marker +
|
||||||
|
param.seriesName +
|
||||||
|
": " +
|
||||||
|
abbreviateNumberWithColor(param.value, false, true) +
|
||||||
|
"<br/>";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add Bid x Ask line if both are present
|
||||||
|
if (bidValue !== null && askValue !== null) {
|
||||||
|
result += `${bidColor}Bid x ${askColor}Ask: ${bidValue} x ${askValue}<br/>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add DTE at the end if the data point exists
|
||||||
|
if (rawDataPoint?.dte !== undefined) {
|
||||||
|
result += `DTE: ${rawDataPoint.dte}<br/>`;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
axisPointer: {
|
axisPointer: {
|
||||||
lineStyle: {
|
lineStyle: {
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
silent: true,
|
silent: true,
|
||||||
grid: {
|
grid: {
|
||||||
left: $screenWidth < 640 ? "5%" : "2%",
|
left: $screenWidth < 640 ? "5%" : "2%",
|
||||||
@ -502,6 +551,8 @@
|
|||||||
entry.price = matchingData?.close;
|
entry.price = matchingData?.close;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rawDataHistory = calculateDTE(rawDataHistory, dateExpiration);
|
||||||
optionsData = plotData();
|
optionsData = plotData();
|
||||||
rawDataHistory = rawDataHistory?.sort(
|
rawDataHistory = rawDataHistory?.sort(
|
||||||
(a, b) => new Date(b?.date) - new Date(a?.date),
|
(a, b) => new Date(b?.date) - new Date(a?.date),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user