From 76688f2d1de3b27ea5097f4051adc58e26430cf2 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 7 Jan 2025 23:45:42 +0100 Subject: [PATCH] update options page --- .../stocks/[tickerID]/options/+layout.svelte | 4 +- .../[tickerID]/options/gex/+layout.svelte | 95 ++++ .../[tickerID]/options/gex/+page.server.ts | 3 +- .../[tickerID]/options/gex/+page.svelte | 6 +- .../options/gex/expiry/+page.svelte | 0 .../options/gex/strike/+page.server.ts | 50 ++ .../options/gex/strike/+page.svelte | 525 ++++++++++++++++++ 7 files changed, 677 insertions(+), 6 deletions(-) create mode 100644 src/routes/stocks/[tickerID]/options/gex/+layout.svelte create mode 100644 src/routes/stocks/[tickerID]/options/gex/expiry/+page.svelte create mode 100644 src/routes/stocks/[tickerID]/options/gex/strike/+page.server.ts create mode 100644 src/routes/stocks/[tickerID]/options/gex/strike/+page.svelte diff --git a/src/routes/stocks/[tickerID]/options/+layout.svelte b/src/routes/stocks/[tickerID]/options/+layout.svelte index 90211153..7bdc4dc2 100644 --- a/src/routes/stocks/[tickerID]/options/+layout.svelte +++ b/src/routes/stocks/[tickerID]/options/+layout.svelte @@ -11,8 +11,8 @@ const subSectionMap = { overview: "/options", "hottest-contracts": "/options/hottest-contracts", - GEX: "/options/gex", - DEX: "/options/dex", + gex: "/options/gex", + dex: "/options/dex", }; if (state !== "overview" && subSectionMap[state]) { diff --git a/src/routes/stocks/[tickerID]/options/gex/+layout.svelte b/src/routes/stocks/[tickerID]/options/gex/+layout.svelte new file mode 100644 index 00000000..b52eb53c --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/gex/+layout.svelte @@ -0,0 +1,95 @@ + + +
+ +
diff --git a/src/routes/stocks/[tickerID]/options/gex/+page.server.ts b/src/routes/stocks/[tickerID]/options/gex/+page.server.ts index c0196205..a6db54dc 100644 --- a/src/routes/stocks/[tickerID]/options/gex/+page.server.ts +++ b/src/routes/stocks/[tickerID]/options/gex/+page.server.ts @@ -5,7 +5,8 @@ export const load = async ({ locals, params }) => { const getData = async () => { const postData = { - ticker: params.tickerID, + params: params.tickerID, + category: "overview" }; const response = await fetch(apiURL + "/options-gex-dex", { diff --git a/src/routes/stocks/[tickerID]/options/gex/+page.svelte b/src/routes/stocks/[tickerID]/options/gex/+page.svelte index f3792d13..25348aea 100644 --- a/src/routes/stocks/[tickerID]/options/gex/+page.svelte +++ b/src/routes/stocks/[tickerID]/options/gex/+page.svelte @@ -143,8 +143,8 @@ }, silent: true, grid: { - left: $screenWidth < 640 ? "5%" : "2%", - right: $screenWidth < 640 ? "5%" : "2%", + left: $screenWidth < 640 ? "5%" : "0%", + right: $screenWidth < 640 ? "5%" : "0%", bottom: "20%", containLabel: true, }, @@ -420,7 +420,7 @@
diff --git a/src/routes/stocks/[tickerID]/options/gex/expiry/+page.svelte b/src/routes/stocks/[tickerID]/options/gex/expiry/+page.svelte new file mode 100644 index 00000000..e69de29b diff --git a/src/routes/stocks/[tickerID]/options/gex/strike/+page.server.ts b/src/routes/stocks/[tickerID]/options/gex/strike/+page.server.ts new file mode 100644 index 00000000..a6db54dc --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/gex/strike/+page.server.ts @@ -0,0 +1,50 @@ + + +export const load = async ({ locals, params }) => { + const { apiKey, apiURL, user } = locals; + + const getData = async () => { + const postData = { + params: params.tickerID, + category: "overview" + }; + + const response = await fetch(apiURL + "/options-gex-dex", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + const output = await response.json(); + + return output; + }; + + + const getHistoricalPrice = async () => { + const postData = { ticker: params.tickerID, timePeriod: "one-year" }; + const response = await fetch(apiURL + "/historical-price", { + 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 { + getData: await getData(), + getHistoricalPrice: await getHistoricalPrice(), + }; +}; + + diff --git a/src/routes/stocks/[tickerID]/options/gex/strike/+page.svelte b/src/routes/stocks/[tickerID]/options/gex/strike/+page.svelte new file mode 100644 index 00000000..3747adfc --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/gex/strike/+page.svelte @@ -0,0 +1,525 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Gamma Exposure · Stocknear + + + + + + + + + + + + + + + + +
+
+
+ {#if rawData?.length > 0} +
+

+ Daily Gamma Exposure +

+ +
+ {#if options !== null} +
+
+ {#each ["3M", "6M", "1Y"] as item} + + {/each} +
+ + +
+ {:else} +
+
+ +
+
+ {/if} +
+
+
+ + + + + {#each displayList as item, index} + + + + + + + + + + {/each} + +
+ {formatDate(item?.date)} + + {@html abbreviateNumberWithColor( + item?.call_gamma, + false, + true, + )} + + {@html abbreviateNumberWithColor( + item?.put_gamma, + false, + true, + )} + + {@html abbreviateNumberWithColor( + item?.net_gamma, + false, + true, + )} + + {#if item?.put_call_ratio <= 1} + {item?.put_call_ratio?.toFixed(2)} + {:else} + {item?.put_call_ratio?.toFixed(2)} + {/if} +
+
+ + + + {:else} +
+

+ Hottest Contracts +

+
+ +
+
+ {/if} + + + + +