bugfixing market flow
This commit is contained in:
parent
302e96eac0
commit
c7a42ea1dd
@ -210,21 +210,50 @@
|
|||||||
.sort(compareValues)
|
.sort(compareValues)
|
||||||
?.slice(0, 50);
|
?.slice(0, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPlotOptions() {
|
function getPlotOptions() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
let dates = marketTideData?.map((item) => item?.time);
|
|
||||||
const priceList = marketTideData?.map((item) =>
|
|
||||||
item?.close !== null ? item?.close : item?.close,
|
|
||||||
);
|
|
||||||
const netCallPremList = marketTideData?.map(
|
|
||||||
(item) => item?.net_call_premium,
|
|
||||||
);
|
|
||||||
const netPutPremList = marketTideData?.map((item) => item?.net_put_premium);
|
|
||||||
const volumeList = marketTideData?.map((item) => item?.net_volume);
|
|
||||||
|
|
||||||
const positiveVolume = volumeList?.map((v) => (v >= 0 ? v : "-"));
|
// Determine the base date (using the first data point, or fallback to today)
|
||||||
const negativeVolume = volumeList?.map((v) => (v < 0 ? v : "-"));
|
const baseDate =
|
||||||
|
marketTideData && marketTideData.length
|
||||||
|
? new Date(marketTideData[0].time)
|
||||||
|
: new Date();
|
||||||
|
|
||||||
|
// Set the fixed start and end times (9:30 and 16:10)
|
||||||
|
const startTime = new Date(
|
||||||
|
baseDate.getFullYear(),
|
||||||
|
baseDate.getMonth(),
|
||||||
|
baseDate.getDate(),
|
||||||
|
9,
|
||||||
|
30,
|
||||||
|
).getTime();
|
||||||
|
const endTime = new Date(
|
||||||
|
baseDate.getFullYear(),
|
||||||
|
baseDate.getMonth(),
|
||||||
|
baseDate.getDate(),
|
||||||
|
16,
|
||||||
|
10,
|
||||||
|
).getTime();
|
||||||
|
|
||||||
|
// Create series arrays with x (timestamp) and y values.
|
||||||
|
// This removes the need for xAxis.categories.
|
||||||
|
const priceSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.close,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
|
const netCallPremSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.net_call_premium,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
|
const netPutPremSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.net_put_premium,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
chart: {
|
chart: {
|
||||||
@ -260,19 +289,18 @@
|
|||||||
formatter: function () {
|
formatter: function () {
|
||||||
// Format the x value to display time in hh:mm format
|
// Format the x value to display time in hh:mm format
|
||||||
let tooltipContent = `<span class="m-auto text-white text-[1rem] font-[501]">${new Date(
|
let tooltipContent = `<span class="m-auto text-white text-[1rem] font-[501]">${new Date(
|
||||||
this?.x,
|
this.x,
|
||||||
).toLocaleTimeString("en-US", {
|
).toLocaleTimeString("en-US", {
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
// Uncomment the next line for 12-hour format with AM/PM
|
|
||||||
// hour12: true,
|
|
||||||
// For 24-hour format, either leave it or set hour12: false
|
|
||||||
})}</span><br>`;
|
})}</span><br>`;
|
||||||
|
|
||||||
// Loop through each point in the shared tooltip
|
// Loop through each point in the shared tooltip
|
||||||
this.points.forEach((point) => {
|
this.points.forEach((point) => {
|
||||||
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
||||||
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumberWithColor(point.y)}</span><br>`;
|
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumberWithColor(
|
||||||
|
point.y,
|
||||||
|
)}</span><br>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return tooltipContent;
|
return tooltipContent;
|
||||||
@ -281,27 +309,22 @@
|
|||||||
|
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: "datetime",
|
type: "datetime",
|
||||||
|
min: startTime, // Force start at 9:30
|
||||||
|
max: endTime, // Force end at 16:10
|
||||||
crosshair: {
|
crosshair: {
|
||||||
color: "#fff", // Set the color of the crosshair line
|
color: "#fff", // Set the color of the crosshair line
|
||||||
width: 1, // Adjust the line width as needed
|
width: 1, // Adjust the line width as needed
|
||||||
dashStyle: "Solid", // You can change the dash style if desired
|
dashStyle: "Solid",
|
||||||
},
|
},
|
||||||
endOnTick: false,
|
|
||||||
categories: dates,
|
|
||||||
labels: {
|
labels: {
|
||||||
style: {
|
style: {
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
distance: 20, // Increases space between label and axis
|
distance: 20, // Increases space between label and axis
|
||||||
formatter: function () {
|
formatter: function () {
|
||||||
const date = new Date(this.value);
|
return new Date(this.value).toLocaleTimeString("en-US", {
|
||||||
return date.toLocaleTimeString("en-US", {
|
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
// Uncomment the line below for 12-hour format with AM/PM
|
|
||||||
// hour12: true,
|
|
||||||
// For 24-hour format, you can either leave hour12 as false (default) or set it explicitly:
|
|
||||||
// hour12: false
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -310,7 +333,7 @@
|
|||||||
const positions = [];
|
const positions = [];
|
||||||
const info = this.getExtremes();
|
const info = this.getExtremes();
|
||||||
const tickCount = 5; // Reduce number of ticks displayed
|
const tickCount = 5; // Reduce number of ticks displayed
|
||||||
const interval = Math.floor((info.max - info.min) / tickCount);
|
const interval = (info.max - info.min) / tickCount;
|
||||||
|
|
||||||
for (let i = 0; i <= tickCount; i++) {
|
for (let i = 0; i <= tickCount; i++) {
|
||||||
positions.push(info.min + i * interval);
|
positions.push(info.min + i * interval);
|
||||||
@ -345,7 +368,7 @@
|
|||||||
{
|
{
|
||||||
name: "Price",
|
name: "Price",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: priceList,
|
data: priceSeries,
|
||||||
yAxis: 0,
|
yAxis: 0,
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
marker: {
|
marker: {
|
||||||
@ -362,7 +385,7 @@
|
|||||||
{
|
{
|
||||||
name: "Net Call Prem",
|
name: "Net Call Prem",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: netCallPremList,
|
data: netCallPremSeries,
|
||||||
yAxis: 1,
|
yAxis: 1,
|
||||||
color: "#90EE90",
|
color: "#90EE90",
|
||||||
marker: {
|
marker: {
|
||||||
@ -377,7 +400,7 @@
|
|||||||
{
|
{
|
||||||
name: "Net Put Prem",
|
name: "Net Put Prem",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: netPutPremList,
|
data: netPutPremSeries,
|
||||||
yAxis: 1,
|
yAxis: 1,
|
||||||
color: "#FF6B6B",
|
color: "#FF6B6B",
|
||||||
marker: {
|
marker: {
|
||||||
@ -398,9 +421,11 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
config = marketTideData ? getPlotOptions() : null;
|
config = marketTideData ? getPlotOptions() : null;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -234,18 +234,48 @@
|
|||||||
|
|
||||||
function getPlotOptions() {
|
function getPlotOptions() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
let dates = marketTideData?.map((item) => item?.time);
|
|
||||||
const priceList = marketTideData?.map((item) =>
|
|
||||||
item?.close !== null ? item?.close : item?.close,
|
|
||||||
);
|
|
||||||
const netCallPremList = marketTideData?.map(
|
|
||||||
(item) => item?.net_call_premium,
|
|
||||||
);
|
|
||||||
const netPutPremList = marketTideData?.map((item) => item?.net_put_premium);
|
|
||||||
const volumeList = marketTideData?.map((item) => item?.net_volume);
|
|
||||||
|
|
||||||
const positiveVolume = volumeList?.map((v) => (v >= 0 ? v : "-"));
|
// Determine the base date (using the first data point, or fallback to today)
|
||||||
const negativeVolume = volumeList?.map((v) => (v < 0 ? v : "-"));
|
const baseDate =
|
||||||
|
marketTideData && marketTideData.length
|
||||||
|
? new Date(marketTideData[0].time)
|
||||||
|
: new Date();
|
||||||
|
|
||||||
|
// Set the fixed start and end times (9:30 and 16:10)
|
||||||
|
const startTime = new Date(
|
||||||
|
baseDate.getFullYear(),
|
||||||
|
baseDate.getMonth(),
|
||||||
|
baseDate.getDate(),
|
||||||
|
9,
|
||||||
|
30,
|
||||||
|
).getTime();
|
||||||
|
const endTime = new Date(
|
||||||
|
baseDate.getFullYear(),
|
||||||
|
baseDate.getMonth(),
|
||||||
|
baseDate.getDate(),
|
||||||
|
16,
|
||||||
|
10,
|
||||||
|
).getTime();
|
||||||
|
|
||||||
|
// Create series arrays with x (timestamp) and y values.
|
||||||
|
// This removes the need for xAxis.categories.
|
||||||
|
const priceSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.close,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
|
const netCallPremSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.net_call_premium,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
|
const netPutPremSeries =
|
||||||
|
marketTideData?.map((item) => ({
|
||||||
|
x: new Date(item.time).getTime(),
|
||||||
|
y: item.net_put_premium,
|
||||||
|
})) || [];
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
chart: {
|
chart: {
|
||||||
@ -281,19 +311,18 @@
|
|||||||
formatter: function () {
|
formatter: function () {
|
||||||
// Format the x value to display time in hh:mm format
|
// Format the x value to display time in hh:mm format
|
||||||
let tooltipContent = `<span class="m-auto text-white text-[1rem] font-[501]">${new Date(
|
let tooltipContent = `<span class="m-auto text-white text-[1rem] font-[501]">${new Date(
|
||||||
this?.x,
|
this.x,
|
||||||
).toLocaleTimeString("en-US", {
|
).toLocaleTimeString("en-US", {
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
// Uncomment the next line for 12-hour format with AM/PM
|
|
||||||
// hour12: true,
|
|
||||||
// For 24-hour format, either leave it or set hour12: false
|
|
||||||
})}</span><br>`;
|
})}</span><br>`;
|
||||||
|
|
||||||
// Loop through each point in the shared tooltip
|
// Loop through each point in the shared tooltip
|
||||||
this.points.forEach((point) => {
|
this.points.forEach((point) => {
|
||||||
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
||||||
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumberWithColor(point.y)}</span><br>`;
|
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumberWithColor(
|
||||||
|
point.y,
|
||||||
|
)}</span><br>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return tooltipContent;
|
return tooltipContent;
|
||||||
@ -302,27 +331,22 @@
|
|||||||
|
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: "datetime",
|
type: "datetime",
|
||||||
|
min: startTime, // Force start at 9:30
|
||||||
|
max: endTime, // Force end at 16:10
|
||||||
crosshair: {
|
crosshair: {
|
||||||
color: "#fff", // Set the color of the crosshair line
|
color: "#fff", // Set the color of the crosshair line
|
||||||
width: 1, // Adjust the line width as needed
|
width: 1, // Adjust the line width as needed
|
||||||
dashStyle: "Solid", // You can change the dash style if desired
|
dashStyle: "Solid",
|
||||||
},
|
},
|
||||||
endOnTick: false,
|
|
||||||
categories: dates,
|
|
||||||
labels: {
|
labels: {
|
||||||
style: {
|
style: {
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
distance: 20, // Increases space between label and axis
|
distance: 20, // Increases space between label and axis
|
||||||
formatter: function () {
|
formatter: function () {
|
||||||
const date = new Date(this.value);
|
return new Date(this.value).toLocaleTimeString("en-US", {
|
||||||
return date.toLocaleTimeString("en-US", {
|
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
// Uncomment the line below for 12-hour format with AM/PM
|
|
||||||
// hour12: true,
|
|
||||||
// For 24-hour format, you can either leave hour12 as false (default) or set it explicitly:
|
|
||||||
// hour12: false
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -331,7 +355,7 @@
|
|||||||
const positions = [];
|
const positions = [];
|
||||||
const info = this.getExtremes();
|
const info = this.getExtremes();
|
||||||
const tickCount = 5; // Reduce number of ticks displayed
|
const tickCount = 5; // Reduce number of ticks displayed
|
||||||
const interval = Math.floor((info.max - info.min) / tickCount);
|
const interval = (info.max - info.min) / tickCount;
|
||||||
|
|
||||||
for (let i = 0; i <= tickCount; i++) {
|
for (let i = 0; i <= tickCount; i++) {
|
||||||
positions.push(info.min + i * interval);
|
positions.push(info.min + i * interval);
|
||||||
@ -366,7 +390,7 @@
|
|||||||
{
|
{
|
||||||
name: "Price",
|
name: "Price",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: priceList,
|
data: priceSeries,
|
||||||
yAxis: 0,
|
yAxis: 0,
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
marker: {
|
marker: {
|
||||||
@ -383,7 +407,7 @@
|
|||||||
{
|
{
|
||||||
name: "Net Call Prem",
|
name: "Net Call Prem",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: netCallPremList,
|
data: netCallPremSeries,
|
||||||
yAxis: 1,
|
yAxis: 1,
|
||||||
color: "#90EE90",
|
color: "#90EE90",
|
||||||
marker: {
|
marker: {
|
||||||
@ -398,7 +422,7 @@
|
|||||||
{
|
{
|
||||||
name: "Net Put Prem",
|
name: "Net Put Prem",
|
||||||
type: "spline",
|
type: "spline",
|
||||||
data: netPutPremList,
|
data: netPutPremSeries,
|
||||||
yAxis: 1,
|
yAxis: 1,
|
||||||
color: "#FF6B6B",
|
color: "#FF6B6B",
|
||||||
marker: {
|
marker: {
|
||||||
@ -419,6 +443,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user