clean code
This commit is contained in:
parent
b14db8a669
commit
e6d6842cd0
@ -25,19 +25,33 @@
|
||||
]);
|
||||
|
||||
export let data;
|
||||
export let title;
|
||||
export let title = "Gamma";
|
||||
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
}));
|
||||
const isGamma = title === "Gamma";
|
||||
|
||||
rawData = rawData?.map((item) => {
|
||||
if (title === "Gamma") {
|
||||
return {
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
});
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
@ -53,20 +67,23 @@
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
// Determine if the current data is Gamma-based or not
|
||||
const isGamma = title === "Gamma";
|
||||
|
||||
// Process and sort data by strike or expiry
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
expiry: formatDate(d?.expiry),
|
||||
callGamma: d?.call_gex,
|
||||
putGamma: d?.put_gex,
|
||||
netGamma: d?.net_gex,
|
||||
callValue: isGamma ? d?.call_gex : d?.call_delta,
|
||||
putValue: isGamma ? d?.put_gex : d?.put_delta,
|
||||
netValue: isGamma ? d?.net_gex : d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const expiries = processedData.map((d) => d.expiry);
|
||||
const callGamma = processedData.map((d) => d.callGamma?.toFixed(2));
|
||||
const putGamma = processedData.map((d) => d.putGamma?.toFixed(2));
|
||||
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
|
||||
const callValue = processedData.map((d) => d.callValue?.toFixed(2));
|
||||
const putValue = processedData.map((d) => d.putValue?.toFixed(2));
|
||||
const netValue = processedData.map((d) => d.netValue?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
@ -82,15 +99,15 @@
|
||||
formatter: function (params) {
|
||||
const expiry = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
const net = params[1].data;
|
||||
const call = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Expiry:</b> ${expiry}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Gamma:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Gamma:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Gamma:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
<div style="text-align:left;">
|
||||
<b>Expiry:</b> ${expiry}<br/>
|
||||
<span style="color:#9B5DC4;">● Put ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
@ -102,7 +119,7 @@
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Gamma",
|
||||
name: isGamma ? "Gamma" : "Delta",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
@ -118,25 +135,25 @@
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Gamma",
|
||||
name: `Put ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: putGamma,
|
||||
stack: "gamma",
|
||||
data: putValue,
|
||||
stack: isGamma ? "gamma" : "delta",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
barWidth: "40%",
|
||||
},
|
||||
{
|
||||
name: "Net Gamma",
|
||||
name: `Net ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: netGamma,
|
||||
stack: "gamma",
|
||||
data: netValue,
|
||||
stack: isGamma ? "gamma" : "delta",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Gamma",
|
||||
name: `Call ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: callGamma,
|
||||
stack: "gamma",
|
||||
data: callValue,
|
||||
stack: isGamma ? "gamma" : "delta",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
@ -165,17 +182,33 @@
|
||||
|
||||
$: columns = [
|
||||
{ key: "expiry", label: "Expiry Date", align: "left" },
|
||||
{ key: "call_gex", label: "Call GEX", align: "right" },
|
||||
{ key: "put_gex", label: "Put GEX", align: "right" },
|
||||
{ key: "net_gex", label: "Net GEX", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C GEX", align: "right" },
|
||||
{
|
||||
key: isGamma ? "call_gex" : "call_delta",
|
||||
label: isGamma ? "Call GEX" : "Call Delta",
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: isGamma ? "put_gex" : "put_delta",
|
||||
label: isGamma ? "Put GEX" : "Put Delta",
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: isGamma ? "net_gex" : "net_delta",
|
||||
label: isGamma ? "Net GEX" : "Net Delta",
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: "put_call_ratio",
|
||||
label: isGamma ? "P/C GEX" : "P/C Delta",
|
||||
align: "right",
|
||||
},
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
expiry: { order: "none", type: "date" },
|
||||
call_gex: { order: "none", type: "number" },
|
||||
put_gex: { order: "none", type: "number" },
|
||||
net_gex: { order: "none", type: "number" },
|
||||
[isGamma ? "call_gex" : "call_delta"]: { order: "none", type: "number" },
|
||||
[isGamma ? "put_gex" : "put_delta"]: { order: "none", type: "number" },
|
||||
[isGamma ? "net_gex" : "net_delta"]: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
@ -247,7 +280,7 @@
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Gamma Exposure By Expiry
|
||||
{title} Exposure By Expiry
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
@ -294,7 +327,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_gex?.toFixed(2),
|
||||
(isGamma ? item?.call_gex : item?.call_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
@ -303,7 +336,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_gex?.toFixed(2),
|
||||
(isGamma ? item?.put_gex : item?.put_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
@ -313,7 +346,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_gex?.toFixed(2),
|
||||
(isGamma ? item?.net_gex : item?.net_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
|
||||
@ -25,38 +25,52 @@
|
||||
]);
|
||||
|
||||
export let data;
|
||||
export let title;
|
||||
export let title = "Gamma";
|
||||
|
||||
$: isGamma = title === "Gamma";
|
||||
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
}));
|
||||
rawData = rawData?.map((item) => {
|
||||
if (title === "Gamma") {
|
||||
return {
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const isGamma = title === "Gamma"; // don't delete this $: isGamma is not rendered fast enough; stupid fkn javascript
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
strike: d?.strike,
|
||||
callGamma: d?.call_gex,
|
||||
putGamma: d?.put_gex,
|
||||
netGamma: d?.net_gex,
|
||||
callValue: isGamma ? d?.call_gex : d?.call_delta,
|
||||
putValue: isGamma ? d?.put_gex : d?.put_delta,
|
||||
netValue: isGamma ? d?.net_gex : d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const strikes = processedData.map((d) => d.strike);
|
||||
const callGamma = processedData.map((d) => d.callGamma?.toFixed(2));
|
||||
const putGamma = processedData.map((d) => d.putGamma?.toFixed(2));
|
||||
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
|
||||
?.sort((a, b) => a?.strike - b?.strike);
|
||||
|
||||
const strikes = processedData?.map((d) => d.strike);
|
||||
const callValues = processedData?.map((d) => d.callValue?.toFixed(2));
|
||||
const putValues = processedData?.map((d) => d.putValue?.toFixed(2));
|
||||
const netValues = processedData?.map((d) => d.netValue?.toFixed(2));
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
@ -71,16 +85,16 @@
|
||||
formatter: function (params) {
|
||||
const strike = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
const net = params[1].data;
|
||||
const call = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Strike:</b> ${strike}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Gamma:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Gamma:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Gamma:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
<span style="color:#9B5DC4;">● Put ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call ${isGamma ? "Gamma" : "Delta"}:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
@ -91,11 +105,10 @@
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Gamma",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
show: false, // Hide x-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
@ -107,24 +120,24 @@
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Gamma",
|
||||
name: `Put ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: putGamma,
|
||||
stack: "gamma",
|
||||
data: putValues,
|
||||
stack: "value",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
},
|
||||
{
|
||||
name: "Net Gamma",
|
||||
name: `Net ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: netGamma,
|
||||
stack: "gamma",
|
||||
data: netValues,
|
||||
stack: "value",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Gamma",
|
||||
name: `Call ${isGamma ? "Gamma" : "Delta"}`,
|
||||
type: "bar",
|
||||
data: callGamma,
|
||||
stack: "gamma",
|
||||
data: callValues,
|
||||
stack: "value",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
@ -153,17 +166,33 @@
|
||||
|
||||
$: columns = [
|
||||
{ key: "strike", label: "Strike Price", align: "left" },
|
||||
{ key: "call_gex", label: "Call GEX", align: "right" },
|
||||
{ key: "put_gex", label: "Put GEX", align: "right" },
|
||||
{ key: "net_gex", label: "Net GEX", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C GEX", align: "right" },
|
||||
{
|
||||
key: isGamma ? "call_gex" : "call_delta",
|
||||
label: `Call ${isGamma ? "GEX" : "Delta"}`,
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: isGamma ? "put_gex" : "put_delta",
|
||||
label: `Put ${isGamma ? "GEX" : "Delta"}`,
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: isGamma ? "net_gex" : "net_delta",
|
||||
label: `Net ${isGamma ? "GEX" : "Delta"}`,
|
||||
align: "right",
|
||||
},
|
||||
{
|
||||
key: "put_call_ratio",
|
||||
label: `P/C`,
|
||||
align: "right",
|
||||
},
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
strike: { order: "none", type: "number" },
|
||||
call_gex: { order: "none", type: "number" },
|
||||
put_gex: { order: "none", type: "number" },
|
||||
net_gex: { order: "none", type: "number" },
|
||||
[isGamma ? "call_gex" : "call_delta"]: { order: "none", type: "number" },
|
||||
[isGamma ? "put_gex" : "put_delta"]: { order: "none", type: "number" },
|
||||
[isGamma ? "net_gex" : "net_delta"]: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
@ -282,7 +311,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_gex?.toFixed(2),
|
||||
(isGamma ? item?.call_gex : item?.call_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
@ -291,7 +320,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_gex?.toFixed(2),
|
||||
(isGamma ? item?.put_gex : item?.put_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
@ -301,7 +330,7 @@
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_gex?.toFixed(2),
|
||||
(isGamma ? item?.net_gex : item?.net_delta)?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
export const load = async ({ locals, params }) => {
|
||||
const getStockNews = async () => {
|
||||
const { apiKey, apiURL } = locals;
|
||||
const postData = {
|
||||
ticker: params.tickerID,
|
||||
};
|
||||
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + "/stock-news", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-API-KEY": apiKey,
|
||||
},
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
|
||||
const output = await response.json();
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
// Make sure to return a promise
|
||||
return {
|
||||
getStockNews: await getStockNews(),
|
||||
};
|
||||
};
|
||||
@ -1,192 +0,0 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
etfTicker,
|
||||
} from "$lib/store";
|
||||
|
||||
export let data;
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
// Create a date object for the input dateString
|
||||
const inputDate = new Date(dateString);
|
||||
|
||||
// Create a date object for the current time in New York City
|
||||
const nycTime = new Date().toLocaleString("en-US", {
|
||||
timeZone: "America/New_York",
|
||||
});
|
||||
const currentNYCDate = new Date(nycTime);
|
||||
|
||||
// Calculate the difference in milliseconds
|
||||
const difference = inputDate.getTime() - currentNYCDate.getTime();
|
||||
|
||||
// Convert the difference to minutes
|
||||
const minutes = Math.abs(Math.round(difference / (1000 * 60)));
|
||||
|
||||
if (minutes < 60) {
|
||||
return `${minutes} minutes`;
|
||||
} else if (minutes < 1440) {
|
||||
const hours = Math.round(minutes / 60);
|
||||
return `${hours} hour${hours !== 1 ? "s" : ""}`;
|
||||
} else {
|
||||
const days = Math.round(minutes / 1440);
|
||||
return `${days} day${days !== 1 ? "s" : ""}`;
|
||||
}
|
||||
};
|
||||
|
||||
let rawNews = data?.getStockNews;
|
||||
let newsList = rawNews?.slice(0, 20) ?? [];
|
||||
|
||||
let videoId = null;
|
||||
|
||||
function checkIfYoutubeVideo(link) {
|
||||
const url = new URL(link);
|
||||
if (url?.hostname === "www.youtube.com") {
|
||||
const searchParams = url.searchParams;
|
||||
searchParams.delete("t"); // Remove the "t" parameter
|
||||
const videoIdMatch = url?.search?.match(/v=([^&]+)/);
|
||||
|
||||
if (videoIdMatch) {
|
||||
return videoIdMatch[1];
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function loadMoreData() {
|
||||
const nextIndex = newsList?.length;
|
||||
const newArticles = rawNews?.slice(nextIndex, nextIndex + 20);
|
||||
newsList = [...newsList, ...newArticles];
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>
|
||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
|
||||
{$displayCompanyName} ({$etfTicker}) latest Stock Market News and Breaking
|
||||
Stories · Stocknear
|
||||
</title>
|
||||
<meta
|
||||
name="description"
|
||||
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$etfTicker}).`}
|
||||
/>
|
||||
|
||||
<!-- Other meta tags -->
|
||||
<meta
|
||||
property="og:title"
|
||||
content={`${$displayCompanyName} (${$etfTicker}) latest Stock Market News and Breaking Stories · Stocknear`}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$etfTicker}).`}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<!-- Add more Open Graph meta tags as needed -->
|
||||
|
||||
<!-- Twitter specific meta tags -->
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={`${$displayCompanyName} (${$etfTicker}) latest Stock Market News and Breaking Stories · Stocknear`}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content={`Get the latest stock market news and breaking stories of ${$displayCompanyName} (${$etfTicker}).`}
|
||||
/>
|
||||
<!-- Add more Twitter meta tags as needed -->
|
||||
</svelte:head>
|
||||
|
||||
<section
|
||||
class="w-auto max-w-4xl bg-default overflow-hidden text-black h-full mb-40"
|
||||
>
|
||||
<div class="m-auto h-full overflow-hidden">
|
||||
<main class="">
|
||||
<div class="sm:p-7 m-auto mt-2 sm:mt-0">
|
||||
<div class="mb-6">
|
||||
<h1 class="text-2xl sm:text-3xl text-white font-bold">News</h1>
|
||||
</div>
|
||||
|
||||
{#if newsList.length !== 0}
|
||||
<div class="grid grid-cols-1 gap-2 pb-5">
|
||||
{#each newsList as item}
|
||||
<div class="w-full flex flex-col bg-default rounded-md m-auto">
|
||||
{#if (videoId = checkIfYoutubeVideo(item.url))}
|
||||
<iframe
|
||||
class="w-full h-96 rounded-md border border-gray-800"
|
||||
src={`https://www.youtube.com/embed/${videoId}`}
|
||||
frameborder="0"
|
||||
allow="clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen
|
||||
></iframe>
|
||||
{:else}
|
||||
<a
|
||||
href={item?.url}
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
class="border border-gray-800 rounded-md"
|
||||
>
|
||||
<div class="flex-shrink-0 m-auto">
|
||||
<img
|
||||
src={item?.image}
|
||||
class=" w-full rounded-md"
|
||||
alt="news image"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
</a>
|
||||
{/if}
|
||||
<div class="mb-1 w-full">
|
||||
<h3
|
||||
class="text-sm sm:text-md text-white text-opacity-60 truncate mb-2 mt-3"
|
||||
>
|
||||
{item?.site} · {formatDate(item?.publishedDate)} ago
|
||||
</h3>
|
||||
|
||||
<a
|
||||
href={item?.url}
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
class="text-lg font-bold text-white"
|
||||
>
|
||||
{item?.title}
|
||||
<p class="text-white text-sm mt-2 font-normal">
|
||||
{item?.text}
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-blue-400 w-full m-auto mt-5 mb-5" />
|
||||
{/each}
|
||||
</div>
|
||||
{#if newsList?.length !== rawNews?.length}
|
||||
<label
|
||||
on:click={loadMoreData}
|
||||
class="shadow-lg rounded-md cursor-pointer w-5/6 sm:w-3/5 sm:max-w-3xl flex justify-center items-center py-3 h-full text-sm sm:text-[1rem] text-center font-semibold text-white m-auto hover:bg-[#fff] bg-[#fff] bg-opacity-[0.6]"
|
||||
>
|
||||
Load More News
|
||||
</label>
|
||||
{/if}
|
||||
{:else}
|
||||
<div
|
||||
class="w-screen max-w-xl sm:flex sm:flex-row sm:items-center justify-center m-auto text-gray-100 font-medium bg-default sm:rounded-md h-auto p-5 mb-4"
|
||||
>
|
||||
<svg
|
||||
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 256 256"
|
||||
><path
|
||||
fill="#fff"
|
||||
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
|
||||
/></svg
|
||||
>
|
||||
No news article published yet!
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</section>
|
||||
@ -1,335 +1,13 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekExposure from "$lib/components/Options/GreekExposure.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let timePeriod = "3M";
|
||||
|
||||
let options = null;
|
||||
|
||||
function filterDataByPeriod(historicalData, period = "3M") {
|
||||
const currentDate = new Date();
|
||||
let startDate = new Date();
|
||||
|
||||
// Calculate the start date based on the period input
|
||||
switch (period) {
|
||||
case "3M":
|
||||
startDate.setMonth(currentDate.getMonth() - 3);
|
||||
break;
|
||||
case "6M":
|
||||
startDate.setMonth(currentDate.getMonth() - 6);
|
||||
break;
|
||||
case "1Y":
|
||||
startDate.setFullYear(currentDate.getFullYear() - 1);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported period: ${period}`);
|
||||
}
|
||||
|
||||
// Filter the data based on the calculated start date
|
||||
let filteredData = historicalData?.filter((item) => {
|
||||
if (!item?.date) return false;
|
||||
const itemDate = new Date(item.date);
|
||||
return itemDate >= startDate && itemDate <= currentDate;
|
||||
});
|
||||
|
||||
filteredData?.forEach((entry) => {
|
||||
const matchingData = data?.getHistoricalPrice?.find(
|
||||
(d) => d?.time === entry?.date,
|
||||
);
|
||||
if (matchingData) {
|
||||
entry.price = matchingData?.close;
|
||||
}
|
||||
});
|
||||
|
||||
// Extract the dates and gamma values from the filtered data
|
||||
const dateList = filteredData?.map((item) => item.date);
|
||||
const gammaList = filteredData?.map((item) => item.net_delta);
|
||||
const priceList = filteredData?.map((item) => item.price);
|
||||
|
||||
return { dateList, gammaList, priceList };
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
const data = rawData?.sort((a, b) => new Date(a?.date) - new Date(b?.date));
|
||||
const { dateList, gammaList, priceList } = filterDataByPeriod(
|
||||
data,
|
||||
timePeriod,
|
||||
);
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
hideDelay: 100,
|
||||
borderColor: "#969696", // Black border color
|
||||
borderWidth: 1, // Border width of 1px
|
||||
backgroundColor: "#313131", // Optional: Set background color for contrast
|
||||
textStyle: {
|
||||
color: "#fff", // Optional: Text color for better visibility
|
||||
},
|
||||
formatter: function (params) {
|
||||
// Get the timestamp from the first parameter
|
||||
const timestamp = params[0].axisValue;
|
||||
|
||||
// Initialize result with timestamp
|
||||
let result = timestamp + "<br/>";
|
||||
|
||||
// Add each series data
|
||||
params?.forEach((param) => {
|
||||
const marker =
|
||||
'<span style="display:inline-block;margin-right:4px;' +
|
||||
"border-radius:10px;width:10px;height:10px;background-color:" +
|
||||
param.color +
|
||||
'"></span>';
|
||||
result +=
|
||||
marker +
|
||||
param.seriesName +
|
||||
": " +
|
||||
abbreviateNumber(param.value) +
|
||||
"<br/>";
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
},
|
||||
},
|
||||
silent: true,
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "0%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "10%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: [
|
||||
{
|
||||
type: "category",
|
||||
data: dateList,
|
||||
axisLabel: {
|
||||
color: "#fff",
|
||||
|
||||
formatter: function (value) {
|
||||
// Assuming dates are in the format 'yyyy-mm-dd'
|
||||
const dateParts = value.split("-");
|
||||
const monthIndex = parseInt(dateParts[1]) - 1; // Months are zero-indexed in JavaScript Date objects
|
||||
const year = parseInt(dateParts[0]);
|
||||
const day = parseInt(dateParts[2]);
|
||||
return `${day} ${monthNames[monthIndex]} ${year}`;
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
yAxis: [
|
||||
{
|
||||
type: "value",
|
||||
splitLine: {
|
||||
show: false, // Disable x-axis grid lines
|
||||
},
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "value",
|
||||
splitLine: {
|
||||
show: false, // Disable x-axis grid lines
|
||||
},
|
||||
position: "right",
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: "Price",
|
||||
type: "line",
|
||||
data: priceList,
|
||||
yAxisIndex: 1,
|
||||
lineStyle: { width: 2 },
|
||||
itemStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
smooth: true,
|
||||
showSymbol: false,
|
||||
},
|
||||
{
|
||||
name: "Gamma",
|
||||
type: "bar",
|
||||
data: gammaList,
|
||||
itemStyle: {
|
||||
color: "#9B5DC4",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
return options;
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
// Parse the input date string (YYYY-mm-dd)
|
||||
var date = new Date(dateStr);
|
||||
|
||||
// Get month, day, and year
|
||||
var month = date.getMonth() + 1; // Month starts from 0
|
||||
var day = date.getDate();
|
||||
var year = date.getFullYear();
|
||||
|
||||
// Extract the last two digits of the year
|
||||
var shortYear = year.toString().slice(-2);
|
||||
|
||||
// Add leading zeros if necessary
|
||||
month = (month < 10 ? "0" : "") + month;
|
||||
day = (day < 10 ? "0" : "") + day;
|
||||
|
||||
var formattedDate = month + "/" + day + "/" + year;
|
||||
|
||||
return formattedDate;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "date", label: "Date", align: "left" },
|
||||
{ key: "call_delta", label: "Call Delta", align: "right" },
|
||||
{ key: "put_delta", label: "Put Delta", align: "right" },
|
||||
{ key: "net_delta", label: "Net Delta", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C Delta", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
date: { order: "none", type: "date" },
|
||||
call_delta: { order: "none", type: "number" },
|
||||
put_delta: { order: "none", type: "number" },
|
||||
net_delta: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined" && timePeriod) {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -376,127 +54,10 @@
|
||||
<div
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Daily Delta Exposure
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto mt-5">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<div
|
||||
class="flex justify-start space-x-2 absolute right-0 top-0 z-10"
|
||||
>
|
||||
{#each ["3M", "6M", "1Y"] as item}
|
||||
<label
|
||||
on:click={() => (timePeriod = item)}
|
||||
class="px-3 py-1 text-sm {timePeriod === item
|
||||
? 'bg-white text-black '
|
||||
: 'text-white bg-table text-opacity-[0.6]'} transition ease-out duration-100 sm:hover:bg-white sm:hover:text-black rounded-md cursor-pointer"
|
||||
>
|
||||
{item}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{formatDate(item?.date)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_delta,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_delta,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_delta,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekExposure {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
@ -505,21 +66,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1,250 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { abbreviateNumberWithColor } from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByExpiry from "$lib/components/Options/GreekByExpiry.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return null; // Handle null or undefined input
|
||||
const date = new Date(dateString);
|
||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "2-digit",
|
||||
});
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
expiry: formatDate(d?.expiry),
|
||||
callDelta: d?.call_delta,
|
||||
putDelta: d?.put_delta,
|
||||
netDelta: d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const expiries = processedData.map((d) => d.expiry);
|
||||
const callDelta = processedData.map((d) => d.callDelta?.toFixed(2));
|
||||
const putDelta = processedData.map((d) => d.putDelta?.toFixed(2));
|
||||
const netDelta = processedData.map((d) => d.netDelta?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const expiry = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Expiry:</b> ${expiry}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Delta:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Delta:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Delta:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "1%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "10%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Delta",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: expiries,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Delta",
|
||||
type: "bar",
|
||||
data: putDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
barWidth: "40%",
|
||||
},
|
||||
{
|
||||
name: "Net Delta",
|
||||
type: "bar",
|
||||
data: netDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Delta",
|
||||
type: "bar",
|
||||
data: callDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "expiry", label: "Expiry Date", align: "left" },
|
||||
{ key: "call_delta", label: "Call Delta", align: "right" },
|
||||
{ key: "put_delta", label: "Put Delta", align: "right" },
|
||||
{ key: "net_delta", label: "Net Delta", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C Delta", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
expiry: { order: "none", type: "date" },
|
||||
call_delta: { order: "none", type: "number" },
|
||||
put_delta: { order: "none", type: "number" },
|
||||
net_delta: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -292,113 +57,9 @@
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Delta Exposure By Expiry
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{formatDate(item?.expiry)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
<GreekByExpiry {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
@ -407,21 +68,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1,242 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByStrike from "$lib/components/Options/GreekByStrike.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
strike: d?.strike,
|
||||
callDelta: d?.call_delta,
|
||||
putDelta: d?.put_delta,
|
||||
netDelta: d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const strikes = processedData.map((d) => d.strike);
|
||||
const callDelta = processedData.map((d) => d.callDelta?.toFixed(2));
|
||||
const putDelta = processedData.map((d) => d.putDelta?.toFixed(2));
|
||||
const netDelta = processedData.map((d) => d.netDelta?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const strike = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Strike:</b> ${strike}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Delta:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Delta:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Delta:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "0%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "5%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Delta",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: strikes,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Delta",
|
||||
type: "bar",
|
||||
data: putDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
},
|
||||
{
|
||||
name: "Net Delta",
|
||||
type: "bar",
|
||||
data: netDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Delta",
|
||||
type: "bar",
|
||||
data: callDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "strike", label: "Strike Price", align: "left" },
|
||||
{ key: "call_delta", label: "Call Delta", align: "right" },
|
||||
{ key: "put_delta", label: "Put Delta", align: "right" },
|
||||
{ key: "net_delta", label: "Net Delta", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C Delta", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
strike: { order: "none", type: "number" },
|
||||
call_delta: { order: "none", type: "number" },
|
||||
put_delta: { order: "none", type: "number" },
|
||||
net_delta: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -249,7 +22,7 @@
|
||||
</title>
|
||||
<meta
|
||||
name="description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$etfTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$etfTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
|
||||
<!-- Other meta tags -->
|
||||
@ -259,7 +32,7 @@
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$etfTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$etfTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<!-- Add more Open Graph meta tags as needed -->
|
||||
@ -272,7 +45,7 @@
|
||||
/>
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$etfTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$etfTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
<!-- Add more Twitter meta tags as needed -->
|
||||
</svelte:head>
|
||||
@ -284,107 +57,8 @@
|
||||
<div
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Gamma Exposure By Strike
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{item?.strike?.toFixed(2)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekByStrike {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<div class="mt-2">
|
||||
@ -395,21 +69,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 1000px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -17,8 +17,8 @@ export const load = async ({ locals, params }) => {
|
||||
},
|
||||
body: JSON.stringify(postData),
|
||||
});
|
||||
const output = await response.json();
|
||||
|
||||
const output = await response.json();
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
|
||||
@ -1,335 +1,13 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekExposure from "$lib/components/Options/GreekExposure.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_gamma: (item?.call_gamma || 0) + (item?.put_gamma || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gamma > 0
|
||||
? Math.abs((item?.put_gamma || 0) / item?.call_gamma)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let timePeriod = "3M";
|
||||
|
||||
let options = null;
|
||||
|
||||
function filterDataByPeriod(historicalData, period = "3M") {
|
||||
const currentDate = new Date();
|
||||
let startDate = new Date();
|
||||
|
||||
// Calculate the start date based on the period input
|
||||
switch (period) {
|
||||
case "3M":
|
||||
startDate.setMonth(currentDate.getMonth() - 3);
|
||||
break;
|
||||
case "6M":
|
||||
startDate.setMonth(currentDate.getMonth() - 6);
|
||||
break;
|
||||
case "1Y":
|
||||
startDate.setFullYear(currentDate.getFullYear() - 1);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported period: ${period}`);
|
||||
}
|
||||
|
||||
// Filter the data based on the calculated start date
|
||||
let filteredData = historicalData?.filter((item) => {
|
||||
if (!item?.date) return false;
|
||||
const itemDate = new Date(item.date);
|
||||
return itemDate >= startDate && itemDate <= currentDate;
|
||||
});
|
||||
|
||||
filteredData?.forEach((entry) => {
|
||||
const matchingData = data?.getHistoricalPrice?.find(
|
||||
(d) => d?.time === entry?.date,
|
||||
);
|
||||
if (matchingData) {
|
||||
entry.price = matchingData?.close;
|
||||
}
|
||||
});
|
||||
|
||||
// Extract the dates and gamma values from the filtered data
|
||||
const dateList = filteredData?.map((item) => item.date);
|
||||
const gammaList = filteredData?.map((item) => item.net_gamma);
|
||||
const priceList = filteredData?.map((item) => item.price);
|
||||
|
||||
return { dateList, gammaList, priceList };
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
const data = rawData?.sort((a, b) => new Date(a?.date) - new Date(b?.date));
|
||||
const { dateList, gammaList, priceList } = filterDataByPeriod(
|
||||
data,
|
||||
timePeriod,
|
||||
);
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
hideDelay: 100,
|
||||
borderColor: "#969696", // Black border color
|
||||
borderWidth: 1, // Border width of 1px
|
||||
backgroundColor: "#313131", // Optional: Set background color for contrast
|
||||
textStyle: {
|
||||
color: "#fff", // Optional: Text color for better visibility
|
||||
},
|
||||
formatter: function (params) {
|
||||
// Get the timestamp from the first parameter
|
||||
const timestamp = params[0].axisValue;
|
||||
|
||||
// Initialize result with timestamp
|
||||
let result = timestamp + "<br/>";
|
||||
|
||||
// Add each series data
|
||||
params?.forEach((param) => {
|
||||
const marker =
|
||||
'<span style="display:inline-block;margin-right:4px;' +
|
||||
"border-radius:10px;width:10px;height:10px;background-color:" +
|
||||
param.color +
|
||||
'"></span>';
|
||||
result +=
|
||||
marker +
|
||||
param.seriesName +
|
||||
": " +
|
||||
abbreviateNumber(param.value) +
|
||||
"<br/>";
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
},
|
||||
},
|
||||
silent: true,
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "0%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "10%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: [
|
||||
{
|
||||
type: "category",
|
||||
data: dateList,
|
||||
axisLabel: {
|
||||
color: "#fff",
|
||||
|
||||
formatter: function (value) {
|
||||
// Assuming dates are in the format 'yyyy-mm-dd'
|
||||
const dateParts = value.split("-");
|
||||
const monthIndex = parseInt(dateParts[1]) - 1; // Months are zero-indexed in JavaScript Date objects
|
||||
const year = parseInt(dateParts[0]);
|
||||
const day = parseInt(dateParts[2]);
|
||||
return `${day} ${monthNames[monthIndex]} ${year}`;
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
yAxis: [
|
||||
{
|
||||
type: "value",
|
||||
splitLine: {
|
||||
show: false, // Disable x-axis grid lines
|
||||
},
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "value",
|
||||
splitLine: {
|
||||
show: false, // Disable x-axis grid lines
|
||||
},
|
||||
position: "right",
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: "Price",
|
||||
type: "line",
|
||||
data: priceList,
|
||||
yAxisIndex: 1,
|
||||
lineStyle: { width: 2 },
|
||||
itemStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
smooth: true,
|
||||
showSymbol: false,
|
||||
},
|
||||
{
|
||||
name: "Gamma",
|
||||
type: "bar",
|
||||
data: gammaList,
|
||||
itemStyle: {
|
||||
color: "#9B5DC4",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
return options;
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
// Parse the input date string (YYYY-mm-dd)
|
||||
var date = new Date(dateStr);
|
||||
|
||||
// Get month, day, and year
|
||||
var month = date.getMonth() + 1; // Month starts from 0
|
||||
var day = date.getDate();
|
||||
var year = date.getFullYear();
|
||||
|
||||
// Extract the last two digits of the year
|
||||
var shortYear = year.toString().slice(-2);
|
||||
|
||||
// Add leading zeros if necessary
|
||||
month = (month < 10 ? "0" : "") + month;
|
||||
day = (day < 10 ? "0" : "") + day;
|
||||
|
||||
var formattedDate = month + "/" + day + "/" + year;
|
||||
|
||||
return formattedDate;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "date", label: "Date", align: "left" },
|
||||
{ key: "call_gamma", label: "Call GEX", align: "right" },
|
||||
{ key: "put_gamma", label: "Put GEX", align: "right" },
|
||||
{ key: "net_gamma", label: "Net GEX", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C GEX", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
date: { order: "none", type: "date" },
|
||||
call_gamma: { order: "none", type: "number" },
|
||||
put_gamma: { order: "none", type: "number" },
|
||||
net_gamma: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined" && timePeriod) {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -376,120 +54,8 @@
|
||||
<div
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Daily Gamma Exposure
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto mt-5">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<div
|
||||
class="flex justify-start space-x-2 absolute right-0 top-0 z-10"
|
||||
>
|
||||
{#each ["3M", "6M", "1Y"] as item}
|
||||
<label
|
||||
on:click={() => (timePeriod = item)}
|
||||
class="px-3 py-1 text-sm {timePeriod === item
|
||||
? 'bg-white text-black '
|
||||
: 'text-white bg-table text-opacity-[0.6]'} transition ease-out duration-100 sm:hover:bg-white sm:hover:text-black rounded-md cursor-pointer"
|
||||
>
|
||||
{item}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{formatDate(item?.date)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_gamma,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_gamma,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_gamma,
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekExposure {data} title="Gamma" params="" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<div class="mt-2">
|
||||
@ -500,21 +66,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1,254 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByExpiry from "$lib/components/Options/GreekByExpiry.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return null; // Handle null or undefined input
|
||||
const date = new Date(dateString);
|
||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "2-digit",
|
||||
});
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
expiry: formatDate(d?.expiry),
|
||||
callGamma: d?.call_gex,
|
||||
putGamma: d?.put_gex,
|
||||
netGamma: d?.net_gex,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const expiries = processedData.map((d) => d.expiry);
|
||||
const callGamma = processedData.map((d) => d.callGamma?.toFixed(2));
|
||||
const putGamma = processedData.map((d) => d.putGamma?.toFixed(2));
|
||||
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const expiry = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Expiry:</b> ${expiry}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Gamma:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Gamma:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Gamma:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "1%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "10%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Gamma",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: expiries,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Gamma",
|
||||
type: "bar",
|
||||
data: putGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
barWidth: "40%",
|
||||
},
|
||||
{
|
||||
name: "Net Gamma",
|
||||
type: "bar",
|
||||
data: netGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Gamma",
|
||||
type: "bar",
|
||||
data: callGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "expiry", label: "Expiry Date", align: "left" },
|
||||
{ key: "call_gex", label: "Call GEX", align: "right" },
|
||||
{ key: "put_gex", label: "Put GEX", align: "right" },
|
||||
{ key: "net_gex", label: "Net GEX", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C GEX", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
expiry: { order: "none", type: "date" },
|
||||
call_gex: { order: "none", type: "number" },
|
||||
put_gex: { order: "none", type: "number" },
|
||||
net_gex: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -296,113 +57,9 @@
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Gamma Exposure By Expiry
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{formatDate(item?.expiry)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
<GreekByExpiry {data} title="Gamma" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
@ -411,21 +68,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1,242 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
etfTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByStrike from "$lib/components/Options/GreekByStrike.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_gex: (item?.call_gex || 0) + (item?.put_gex || 0),
|
||||
put_call_ratio:
|
||||
item?.call_gex > 0
|
||||
? Math.abs((item?.put_gex || 0) / item?.call_gex)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
strike: d?.strike,
|
||||
callGamma: d?.call_gex,
|
||||
putGamma: d?.put_gex,
|
||||
netGamma: d?.net_gex,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const strikes = processedData.map((d) => d.strike);
|
||||
const callGamma = processedData.map((d) => d.callGamma?.toFixed(2));
|
||||
const putGamma = processedData.map((d) => d.putGamma?.toFixed(2));
|
||||
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const strike = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Strike:</b> ${strike}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Gamma:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Gamma:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Gamma:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "0%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "5%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Gamma",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: strikes,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Gamma",
|
||||
type: "bar",
|
||||
data: putGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
},
|
||||
{
|
||||
name: "Net Gamma",
|
||||
type: "bar",
|
||||
data: netGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Gamma",
|
||||
type: "bar",
|
||||
data: callGamma,
|
||||
stack: "gamma",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "strike", label: "Strike Price", align: "left" },
|
||||
{ key: "call_gex", label: "Call GEX", align: "right" },
|
||||
{ key: "put_gex", label: "Put GEX", align: "right" },
|
||||
{ key: "net_gex", label: "Net GEX", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C GEX", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
strike: { order: "none", type: "number" },
|
||||
call_gex: { order: "none", type: "number" },
|
||||
put_gex: { order: "none", type: "number" },
|
||||
net_gex: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -284,114 +57,10 @@
|
||||
<div
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Gamma Exposure By Strike
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{item?.strike?.toFixed(2)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_gex?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekByStrike {data} title="Gamma" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
@ -400,21 +69,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 1000px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -55,7 +55,7 @@
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekExposure {data} title="Delta" params="" />
|
||||
<GreekExposure {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<div class="mt-2">
|
||||
|
||||
@ -1,254 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
stockTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByExpiry from "$lib/components/Options/GreekByExpiry.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return null; // Handle null or undefined input
|
||||
const date = new Date(dateString);
|
||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "2-digit",
|
||||
});
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
expiry: formatDate(d?.expiry),
|
||||
callDelta: d?.call_delta,
|
||||
putDelta: d?.put_delta,
|
||||
netDelta: d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const expiries = processedData.map((d) => d.expiry);
|
||||
const callDelta = processedData.map((d) => d.callDelta?.toFixed(2));
|
||||
const putDelta = processedData.map((d) => d.putDelta?.toFixed(2));
|
||||
const netDelta = processedData.map((d) => d.netDelta?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const expiry = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Expiry:</b> ${expiry}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Delta:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Delta:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Delta:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "1%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "10%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Delta",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: expiries,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Delta",
|
||||
type: "bar",
|
||||
data: putDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
barWidth: "40%",
|
||||
},
|
||||
{
|
||||
name: "Net Delta",
|
||||
type: "bar",
|
||||
data: netDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Delta",
|
||||
type: "bar",
|
||||
data: callDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "expiry", label: "Expiry Date", align: "left" },
|
||||
{ key: "call_delta", label: "Call Delta", align: "right" },
|
||||
{ key: "put_delta", label: "Put Delta", align: "right" },
|
||||
{ key: "net_delta", label: "Net Delta", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C Delta", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
expiry: { order: "none", type: "date" },
|
||||
call_delta: { order: "none", type: "number" },
|
||||
put_delta: { order: "none", type: "number" },
|
||||
net_delta: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -296,113 +57,9 @@
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Delta Exposure By Expiry
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{formatDate(item?.expiry)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
<GreekByExpiry {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
@ -411,21 +68,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 600px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -1,242 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
abbreviateNumberWithColor,
|
||||
abbreviateNumber,
|
||||
monthNames,
|
||||
} from "$lib/utils";
|
||||
import {
|
||||
stockTicker,
|
||||
screenWidth,
|
||||
numberOfUnreadNotification,
|
||||
displayCompanyName,
|
||||
} from "$lib/store";
|
||||
import { onMount } from "svelte";
|
||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||
|
||||
import Infobox from "$lib/components/Infobox.svelte";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import {
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
} from "echarts/components";
|
||||
import { CanvasRenderer } from "echarts/renderers";
|
||||
|
||||
use([
|
||||
LineChart,
|
||||
BarChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
CanvasRenderer,
|
||||
]);
|
||||
import GreekByStrike from "$lib/components/Options/GreekByStrike.svelte";
|
||||
|
||||
export let data;
|
||||
let rawData = data?.getData || [];
|
||||
|
||||
rawData = rawData?.map((item) => ({
|
||||
...item,
|
||||
net_delta: (item?.call_delta || 0) + (item?.put_delta || 0),
|
||||
put_call_ratio:
|
||||
item?.call_delta > 0
|
||||
? Math.abs((item?.put_delta || 0) / item?.call_delta)
|
||||
: null,
|
||||
}));
|
||||
|
||||
let displayList = rawData?.slice(0, 150);
|
||||
let options = null;
|
||||
|
||||
function plotData() {
|
||||
// Process and sort data by strike in descending order
|
||||
const processedData = rawData
|
||||
?.map((d) => ({
|
||||
strike: d?.strike,
|
||||
callDelta: d?.call_delta,
|
||||
putDelta: d?.put_delta,
|
||||
netDelta: d?.net_delta,
|
||||
}))
|
||||
.sort((a, b) => a.strike - b.strike);
|
||||
|
||||
const strikes = processedData.map((d) => d.strike);
|
||||
const callDelta = processedData.map((d) => d.callDelta?.toFixed(2));
|
||||
const putDelta = processedData.map((d) => d.putDelta?.toFixed(2));
|
||||
const netDelta = processedData.map((d) => d.netDelta?.toFixed(2));
|
||||
|
||||
const options = {
|
||||
animation: false,
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
axisPointer: {
|
||||
type: "shadow",
|
||||
},
|
||||
backgroundColor: "#313131",
|
||||
textStyle: {
|
||||
color: "#fff",
|
||||
},
|
||||
formatter: function (params) {
|
||||
const strike = params[0].axisValue;
|
||||
const put = params[0].data;
|
||||
const call = params[1].data;
|
||||
const net = params[2].data;
|
||||
|
||||
return `
|
||||
<div style="text-align:left;">
|
||||
<b>Strike:</b> ${strike}<br/>
|
||||
<span style="color:#9B5DC4;">● Put Delta:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||
<span style="color:#C4E916;">● Call Delta:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||
<span style="color:#FF2F1F;">● Net Delta:</span> ${abbreviateNumberWithColor(net, false, true)}<br/>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: $screenWidth < 640 ? "5%" : "0%",
|
||||
right: $screenWidth < 640 ? "5%" : "0%",
|
||||
bottom: "5%",
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "value",
|
||||
name: "Delta",
|
||||
nameTextStyle: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
axisLabel: {
|
||||
show: false, // Hide y-axis labels
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: "category",
|
||||
data: strikes,
|
||||
axisLine: { lineStyle: { color: "#fff" } },
|
||||
axisLabel: { color: "#fff" },
|
||||
splitLine: { show: false },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Put Delta",
|
||||
type: "bar",
|
||||
data: putDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#9B5DC4" },
|
||||
},
|
||||
{
|
||||
name: "Net Delta",
|
||||
type: "bar",
|
||||
data: netDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#FF2F1F" },
|
||||
},
|
||||
{
|
||||
name: "Call Delta",
|
||||
type: "bar",
|
||||
data: callDelta,
|
||||
stack: "Delta",
|
||||
itemStyle: { color: "#C4E916" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function handleScroll() {
|
||||
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
|
||||
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
|
||||
|
||||
if (isBottom && displayList?.length !== rawData?.length) {
|
||||
const nextIndex = displayList?.length;
|
||||
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
|
||||
displayList = [...displayList, ...filteredNewResults];
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
$: columns = [
|
||||
{ key: "strike", label: "Strike Price", align: "left" },
|
||||
{ key: "call_delta", label: "Call Delta", align: "right" },
|
||||
{ key: "put_delta", label: "Put Delta", align: "right" },
|
||||
{ key: "net_delta", label: "Net Delta", align: "right" },
|
||||
{ key: "put_call_ratio", label: "P/C Delta", align: "right" },
|
||||
];
|
||||
|
||||
$: sortOrders = {
|
||||
strike: { order: "none", type: "number" },
|
||||
call_delta: { order: "none", type: "number" },
|
||||
put_delta: { order: "none", type: "number" },
|
||||
net_delta: { order: "none", type: "number" },
|
||||
put_call_ratio: { order: "none", type: "number" },
|
||||
};
|
||||
|
||||
const sortData = (key) => {
|
||||
// Reset all other keys to 'none' except the current key
|
||||
for (const k in sortOrders) {
|
||||
if (k !== key) {
|
||||
sortOrders[k].order = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through 'none', 'asc', 'desc' for the clicked key
|
||||
const orderCycle = ["none", "asc", "desc"];
|
||||
let originalData = rawData;
|
||||
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
|
||||
sortOrders[key].order =
|
||||
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
|
||||
const sortOrder = sortOrders[key].order;
|
||||
|
||||
// Reset to original data when 'none' and stop further sorting
|
||||
if (sortOrder === "none") {
|
||||
originalData = [...rawData]; // Reset originalData to rawDataVolume
|
||||
displayList = originalData;
|
||||
return;
|
||||
}
|
||||
|
||||
// Define a generic comparison function
|
||||
const compareValues = (a, b) => {
|
||||
const { type } = sortOrders[key];
|
||||
let valueA, valueB;
|
||||
|
||||
switch (type) {
|
||||
case "date":
|
||||
valueA = new Date(a[key]);
|
||||
valueB = new Date(b[key]);
|
||||
break;
|
||||
case "string":
|
||||
valueA = a[key].toUpperCase();
|
||||
valueB = b[key].toUpperCase();
|
||||
return sortOrder === "asc"
|
||||
? valueA.localeCompare(valueB)
|
||||
: valueB.localeCompare(valueA);
|
||||
case "number":
|
||||
default:
|
||||
valueA = parseFloat(a[key]);
|
||||
valueB = parseFloat(b[key]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (sortOrder === "asc") {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Sort using the generic comparison function
|
||||
displayList = [...originalData].sort(compareValues);
|
||||
};
|
||||
|
||||
$: {
|
||||
if (typeof window !== "undefined") {
|
||||
options = plotData();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@ -249,7 +22,7 @@
|
||||
</title>
|
||||
<meta
|
||||
name="description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
|
||||
<!-- Other meta tags -->
|
||||
@ -259,7 +32,7 @@
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<!-- Add more Open Graph meta tags as needed -->
|
||||
@ -272,7 +45,7 @@
|
||||
/>
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content={`Analyze Delta Exposure by strike price for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||
content={`Discover detailed Delta Exposure analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||
/>
|
||||
<!-- Add more Twitter meta tags as needed -->
|
||||
</svelte:head>
|
||||
@ -284,107 +57,8 @@
|
||||
<div
|
||||
class="w-full relative flex justify-center items-center overflow-hidden"
|
||||
>
|
||||
{#if rawData?.length > 0}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Gamma Exposure By Strike
|
||||
</h2>
|
||||
|
||||
<div class="w-full overflow-hidden m-auto">
|
||||
{#if options !== null}
|
||||
<div class="app w-full relative">
|
||||
<Chart {init} {options} class="chart" />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center items-center h-80">
|
||||
<div class="relative">
|
||||
<label
|
||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||
>
|
||||
<span
|
||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||
></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="w-full overflow-x-scroll text-white">
|
||||
<table
|
||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||
>
|
||||
<thead>
|
||||
<TableHeader {columns} {sortOrders} {sortData} />
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||
<tr
|
||||
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||
1 ===
|
||||
displayList?.slice(0, 3)?.length &&
|
||||
data?.user?.tier !== 'Pro'
|
||||
? 'opacity-[0.1]'
|
||||
: ''}"
|
||||
>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||
>
|
||||
{item?.strike?.toFixed(2)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.call_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.put_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{@html abbreviateNumberWithColor(
|
||||
item?.net_delta?.toFixed(2),
|
||||
false,
|
||||
true,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||
>
|
||||
{#if item?.put_call_ratio <= 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#00FC50]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else if item?.put_call_ratio > 1 && item?.put_call_ratio !== null}
|
||||
<span class="text-[#FF2F1F]"
|
||||
>{item?.put_call_ratio?.toFixed(2)}</span
|
||||
>
|
||||
{:else}
|
||||
n/a
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<UpgradeToPro {data} />
|
||||
</div>
|
||||
{#if data?.getData?.length > 0}
|
||||
<GreekByStrike {data} title="Delta" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<div class="mt-2">
|
||||
@ -395,21 +69,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
height: 1000px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
|
||||
.chart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -60,11 +60,6 @@
|
||||
<GreekByExpiry {data} title="Gamma" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
|
||||
@ -61,11 +61,6 @@
|
||||
<GreekByStrike {data} title="Gamma" />
|
||||
{:else}
|
||||
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
|
||||
<h2
|
||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||
>
|
||||
Hottest Contracts
|
||||
</h2>
|
||||
<div class="mt-2">
|
||||
<Infobox text="No data is available" />
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user