update dex page

This commit is contained in:
MuslemRahimi 2025-01-08 13:42:50 +01:00
parent 5db8309c7e
commit 61bab23524
19 changed files with 3393 additions and 648 deletions

151
package-lock.json generated
View File

@ -2230,6 +2230,19 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/@jridgewell/source-map": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz",
"integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.5",
"@jridgewell/trace-mapping": "^0.3.25"
}
},
"node_modules/@jridgewell/sourcemap-codec": { "node_modules/@jridgewell/sourcemap-codec": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
@ -3969,9 +3982,10 @@
} }
}, },
"node_modules/acorn": { "node_modules/acorn": {
"version": "8.12.1", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
"license": "MIT",
"bin": { "bin": {
"acorn": "bin/acorn" "acorn": "bin/acorn"
}, },
@ -4258,9 +4272,9 @@
} }
}, },
"node_modules/browserslist": { "node_modules/browserslist": {
"version": "4.23.2", "version": "4.24.3",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.2.tgz", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.3.tgz",
"integrity": "sha512-qkqSyistMYdxAcw+CzbZwlBy8AGmS/eEWs+sEV5TnLRGDOL+C5M2EnH6tlZyg0YoAxGJAFKh61En9BR941GnHA==", "integrity": "sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -4276,11 +4290,12 @@
"url": "https://github.com/sponsors/ai" "url": "https://github.com/sponsors/ai"
} }
], ],
"license": "MIT",
"dependencies": { "dependencies": {
"caniuse-lite": "^1.0.30001640", "caniuse-lite": "^1.0.30001688",
"electron-to-chromium": "^1.4.820", "electron-to-chromium": "^1.5.73",
"node-releases": "^2.0.14", "node-releases": "^2.0.19",
"update-browserslist-db": "^1.1.0" "update-browserslist-db": "^1.1.1"
}, },
"bin": { "bin": {
"browserslist": "cli.js" "browserslist": "cli.js"
@ -4304,6 +4319,15 @@
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
"dev": true "dev": true
}, },
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/bytes": { "node_modules/bytes": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
@ -4406,9 +4430,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001642", "version": "1.0.30001690",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz",
"integrity": "sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==", "integrity": "sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -4423,7 +4447,8 @@
"type": "github", "type": "github",
"url": "https://github.com/sponsors/ai" "url": "https://github.com/sponsors/ai"
} }
] ],
"license": "CC-BY-4.0"
}, },
"node_modules/chai": { "node_modules/chai": {
"version": "4.4.1", "version": "4.4.1",
@ -5271,10 +5296,11 @@
"dev": true "dev": true
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.4.827", "version": "1.5.79",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.827.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.79.tgz",
"integrity": "sha512-VY+J0e4SFcNfQy19MEoMdaIcZLmDCprqvBtkii1WTCTQHpRvf5N8+3kTYCgL/PcntvwQvmMJWTuDPsq+IlhWKQ==", "integrity": "sha512-nYOxJNxQ9Om4EC88BE4pPoNI8xwSFf8pU/BAeOl4Hh/b/i6V4biTAzwV7pXi3ARKeoYO5JZKMIXTryXSVer5RA==",
"dev": true "dev": true,
"license": "ISC"
}, },
"node_modules/emoji-regex": { "node_modules/emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
@ -5365,9 +5391,10 @@
} }
}, },
"node_modules/escalade": { "node_modules/escalade": {
"version": "3.1.2", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
"integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
"license": "MIT",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
} }
@ -6838,10 +6865,11 @@
} }
}, },
"node_modules/node-releases": { "node_modules/node-releases": {
"version": "2.0.14", "version": "2.0.19",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz",
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==",
"dev": true "dev": true,
"license": "MIT"
}, },
"node_modules/normalize-path": { "node_modules/normalize-path": {
"version": "3.0.0", "version": "3.0.0",
@ -7883,6 +7911,31 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/source-map-support": {
"version": "0.5.21",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"node_modules/source-map-support/node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true,
"license": "BSD-3-Clause",
"optional": true,
"peer": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/stackback": { "node_modules/stackback": {
"version": "0.0.2", "version": "0.0.2",
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
@ -8511,6 +8564,36 @@
"node": ">=10.13.0" "node": ">=10.13.0"
} }
}, },
"node_modules/terser": {
"version": "5.37.0",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz",
"integrity": "sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA==",
"dev": true,
"license": "BSD-2-Clause",
"optional": true,
"peer": true,
"dependencies": {
"@jridgewell/source-map": "^0.3.3",
"acorn": "^8.8.2",
"commander": "^2.20.0",
"source-map-support": "~0.5.20"
},
"bin": {
"terser": "bin/terser"
},
"engines": {
"node": ">=10"
}
},
"node_modules/terser/node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/text-segmentation": { "node_modules/text-segmentation": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz", "resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
@ -8618,9 +8701,10 @@
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.7.0", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
}, },
"node_modules/type-detect": { "node_modules/type-detect": {
"version": "4.0.8", "version": "4.0.8",
@ -8691,9 +8775,9 @@
"dev": true "dev": true
}, },
"node_modules/update-browserslist-db": { "node_modules/update-browserslist-db": {
"version": "1.1.0", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz",
"integrity": "sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==", "integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {
@ -8709,9 +8793,10 @@
"url": "https://github.com/sponsors/ai" "url": "https://github.com/sponsors/ai"
} }
], ],
"license": "MIT",
"dependencies": { "dependencies": {
"escalade": "^3.1.2", "escalade": "^3.2.0",
"picocolors": "^1.0.1" "picocolors": "^1.1.0"
}, },
"bin": { "bin": {
"update-browserslist-db": "cli.js" "update-browserslist-db": "cli.js"

View File

@ -11,6 +11,8 @@
const subSectionMap = { const subSectionMap = {
overview: "/options", overview: "/options",
"hottest-contracts": "/options/hottest-contracts", "hottest-contracts": "/options/hottest-contracts",
gex: "/options/gex",
dex: "/options/dex",
}; };
if (state !== "overview" && subSectionMap[state]) { if (state !== "overview" && subSectionMap[state]) {
@ -28,6 +30,8 @@
const sectionMap = { const sectionMap = {
overview: "overview", overview: "overview",
"hottest-contracts": "hottest-contracts", "hottest-contracts": "hottest-contracts",
gex: "gex",
dex: "dex",
}; };
const foundSection = parts?.find((part) => const foundSection = parts?.find((part) =>
@ -73,6 +77,24 @@
> >
Hottest Contracts Hottest Contracts
</a> </a>
<a
href={`/etf/${$etfTicker}/options/gex`}
on:click={() => changeSubSection("gex")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'gex'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
GEX
</a>
<a
href={`/etf/${$etfTicker}/options/dex`}
on:click={() => changeSubSection("dex")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'dex'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
DEX
</a>
</ul> </ul>
</nav> </nav>
<div class="mt-2 sm:mt-0"> <div class="mt-2 sm:mt-0">

View File

@ -0,0 +1,94 @@
<script lang="ts">
import { etfTicker } from "$lib/store";
import { page } from "$app/stores";
export let data;
let displaySubSection = "overview";
function changeSubSection(state) {
const subSectionMap = {
gex: "/options/gex",
strike: "/options/gex/strike",
expiry: "/options/gex/expiry",
};
if (state !== "overview" && subSectionMap[state]) {
displaySubSection = state;
//goto(`/stocks/${$etfTicker}${subSectionMap[state]}`);
} else {
displaySubSection = state;
//goto(`/stocks/${$etfTicker}/statistics`);
}
}
$: {
if ($page?.url?.pathname) {
const parts = $page?.url?.pathname.split("/");
const sectionMap = {
overview: "overview",
strike: "strike",
expiry: "expiry",
};
const foundSection = parts?.find((part) =>
Object?.values(sectionMap)?.includes(part),
);
displaySubSection =
Object?.keys(sectionMap)?.find(
(key) => sectionMap[key] === foundSection,
) || "overview";
}
}
</script>
<section class="w-full overflow-hidden min-h-screen">
<div class="w-full overflow-hidden m-auto">
<div class="sm:p-0 flex justify-center w-full m-auto overflow-hidden">
<div
class="relative flex justify-center items-start overflow-hidden w-full"
>
<main class="w-full">
<nav
class="sm:ml-4 overflow-x-scroll pt-1 text-sm sm:text-[1rem] whitespace-nowrap"
>
<ul class="flex flex-row items-center w-full text-white">
<a
href={`/etf/${$etfTicker}/options/gex`}
on:click={() => changeSubSection("overview")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'overview'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
Overview
</a>
<a
href={`/etf/${$etfTicker}/options/gex/strike`}
on:click={() => changeSubSection("strike")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'strike'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
By Strike
</a>
<a
href={`/etf/${$etfTicker}/options/gex/expiry`}
on:click={() => changeSubSection("expiry")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'expiry'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
By Expiry
</a>
</ul>
</nav>
<div class="mt-2 sm:mt-0">
<slot />
</div>
</main>
</div>
</div>
</div>
</section>

View File

@ -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(),
};
};

View File

@ -0,0 +1,525 @@
<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,
]);
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$stockTicker}) Gamma Exposure · Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$stockTicker}) Gamma Exposure · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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} (${$stockTicker}) Gamma Exposure · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 displayList 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>
{: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>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 400px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 300px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -0,0 +1,35 @@
export const load = async ({ locals, params }) => {
const { apiKey, apiURL, user } = locals;
const getData = async () => {
const postData = {
params: params.tickerID,
category: "expiry"
};
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;
};
// Make sure to return a promise
return {
getData: await getData(),
};
};

View File

@ -0,0 +1,431 @@
<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,
]);
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 ? "0%" : "0%",
right: $screenWidth < 640 ? "0%" : "0%",
bottom: "10%",
containLabel: true,
},
xAxis: {
type: "value",
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$etfTicker}) Gamma Exposure by Strike Price ·
Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$etfTicker}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 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 displayList 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>
{: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>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 600px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 500px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -0,0 +1,35 @@
export const load = async ({ locals, params }) => {
const { apiKey, apiURL, user } = locals;
const getData = async () => {
const postData = {
params: params.tickerID,
category: "strike"
};
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;
};
// Make sure to return a promise
return {
getData: await getData(),
};
};

View File

@ -0,0 +1,420 @@
<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,
]);
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$etfTicker}) Gamma Exposure by Strike Price ·
Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$etfTicker}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 displayList 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>
{: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>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 1000px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 500px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,626 +1,86 @@
<script lang="ts"> <script>
import { screenWidth, numberOfUnreadNotification } from "$lib/store"; import { onMount } from "svelte";
import { goto } from "$app/navigation";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core"; // Toy data structure representing market sectors and stocks
import { TreemapChart } from "echarts/charts"; const data = {
import { GridComponent } from "echarts/components"; labels: [
import { CanvasRenderer } from "echarts/renderers"; "Technology",
use([TreemapChart, GridComponent, CanvasRenderer]); "Technology",
"Technology",
export let data; "Technology",
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL; "Financials",
"Financials",
let displayIndex = "S&P500"; "Healthcare",
"Healthcare",
let lowestAvg = Infinity; "Consumer",
let lowestAvgCategory = ""; "Consumer",
let highestAvg = -Infinity; "Energy",
let highestAvgCategory = ""; "Energy",
],
let rawData; parents: ["", "", "", "", "", "", "", "", "", "", "", ""],
names: [
let isLoaded = false; "NVDA",
let options; "AAPL",
"MSFT",
const visualMin = -100; "AMD",
const visualMax = 100; "JPM",
"BAC",
/* "PFE",
To-do: Add export to save as png or jpg. "JNJ",
async function exportTreemap() { "AMZN",
// Specify the desired width and height for the canvas "TSLA",
const width = 1000 ; "XOM",
const height = 1000/; "CVX",
],
// Create the canvas element with the specified width and height values: [300, 280, 250, 150, 200, 180, 120, 140, 260, 220, 130, 110],
const canvas = document.createElement('canvas'); changes: [
canvas.width = width; 4.36, -3.28, 0.21, 5.41, 1.44, 4.85, 2.26, 1.11, 1.24, -2.35, 1.1, 3.28,
canvas.height = height;
const chart = echarts.init(canvas);
chart.setOption(options);
const link = document.createElement('a');
canvas.toBlob(blob => {
const url = URL.createObjectURL(blob);
link.href = url;
link.download = 'treemap.png';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}, 'image/png');
}
*/
function getLevelOption() {
return [
{
itemStyle: {
borderColor: "#2D313C",
borderWidth: 0,
gapWidth: 1,
},
upperLabel: {
show: false,
},
},
{
itemStyle: {
borderColor: "#2D313C",
borderWidth: 5,
gapWidth: 1,
},
emphasis: {
itemStyle: {
borderColor: "#2D313C",
},
},
},
{
color: ["#942e38", "#aaa", "#269f3c"],
colorMappingBy: "value",
itemStyle: {
gapWidth: 1,
},
},
{
colorSaturation: [0.5, 0.9],
itemStyle: {
borderWidth: 5,
gapWidth: 1,
borderColorSaturation: 0.6,
},
},
];
}
function plotData(fontSize) {
rawData.forEach((category) => {
if (category?.children && category.children.length > 0) {
let sum = category.children.reduce(
(acc, stock) => acc + (stock?.changesPercentage || 0),
0,
);
let avg = sum / category.children.length;
if (avg < lowestAvg) {
lowestAvg = avg;
lowestAvgCategory = category.name;
}
if (avg > highestAvg) {
highestAvg = avg;
highestAvgCategory = category.name;
}
}
});
options = {
silent: true,
tooltip: {},
grid: {
left: "0%",
right: "0%",
top: "0%",
bottom: "0%",
containLabel: true,
},
series: [
{
breadcrumb: { show: false },
type: "treemap",
roam: false,
width: "100%",
height: "100%",
visualMin: visualMin,
visualMax: visualMax,
visualDimension: 2,
label: {
show: true,
textStyle: {
color: "#fff",
fontSize: fontSize,
fontWeight: "bold",
},
formatter: function (params) {
var changesPercentage = params.data.changesPercentage || 0; // Access changesPercentage from params.data
return params.name + "\n\n" + changesPercentage + "%";
},
},
upperLabel: {
show: true,
textStyle: {
color: "#fff",
fontSize: fontSize,
},
formatter: function (params) {
var sumChangesPercentage = 0;
if (params.data.children && params.data.children.length > 0) {
sumChangesPercentage = params.data.children.reduce(
(acc, child) => acc + (child.changesPercentage || 0),
0,
);
}
return params.name;
},
height: 40,
},
itemStyle: {
borderColor: "#2D313C",
color: function (params) {
return params.data.changesPercentage >= 0 ? "#30954F" : "#FF281E"; // Access changesPercentage from params.data
},
},
levels: getLevelOption(),
data: rawData.map((item) => ({
...item,
children: item.children.map((child) => ({
...child,
itemStyle: {
...child.itemStyle,
color: child.changesPercentage < 0 ? "#7F4650" : "#396550",
},
})),
})),
},
], ],
}; };
}
function changeIndex(indexName) { let plotlyDiv;
displayIndex = indexName;
}
function sectorSelector(sector) { onMount(async () => {
let path; // Dynamically import Plotly to avoid SSR issues
switch (sector) { const Plotly = await import("plotly.js-dist");
case "Financials":
path = "financial-sector";
break;
case "Healthcare":
path = "healthcare-sector";
break;
case "Information Technology":
path = "technology-sector";
break;
case "Technology":
path = "technology-sector";
break;
case "Financial Services":
path = "financial-sector";
break;
case "Industrials":
path = "industrials-sector";
break;
case "Energy":
path = "energy-sector";
break;
case "Utilities":
path = "utilities-sector";
break;
case "Consumer Cyclical":
path = "consumer-cyclical-sector";
break;
case "Real Estate":
path = "real-estate-sector";
break;
case "Basic Materials":
path = "basic-materials-sector";
break;
case "Communication Services":
path = "communication-services-sector";
break;
case "Consumer Defensive":
path = "consumer-defensive-sector";
break;
default:
// Handle default case if needed
break;
}
goto("list/" + path);
}
$: { // Calculate colors based on percentage changes
if (typeof window !== "undefined" && displayIndex) { const colors = data.changes.map((change) =>
isLoaded = false; change >= 0
? `rgb(${Math.max(0, 255 - Math.floor(change * 20))}, 255, ${Math.max(0, 255 - Math.floor(change * 20))})`
: `rgb(255, ${Math.max(0, 255 + Math.floor(change * 20))}, ${Math.max(0, 255 + Math.floor(change * 20))})`,
);
if (displayIndex === "S&P500") { // Create text labels with stock symbol and percentage change
rawData = data?.getSP500HeatMap; const text = data.names.map(
} else if (displayIndex === "Dow Jones") { (name, i) =>
rawData = data?.getDowJonesHeatMap; `${name}<br>${data.changes[i] >= 0 ? "+" : ""}${data.changes[i].toFixed(2)}%`,
} else if (displayIndex === "Nasdaq") { );
rawData = data?.getNasdaqHeatMap;
}
const fontSize = $screenWidth < 640 ? 12 : 16;
plotData(fontSize);
isLoaded = true; const layout = {
} title: "Market Sectors Treemap",
} width: 1000,
height: 800,
showlegend: false,
margin: { t: 30, l: 0, r: 0, b: 0 },
};
let charNumber = 40; const trace = {
$: { type: "treemap",
if ($screenWidth < 640) { labels: data.labels,
charNumber = 20; parents: data.parents,
} else { values: data.values,
charNumber = 40; text: text,
} textinfo: "text",
} hoverongaps: false,
marker: {
colors: colors,
line: { width: 1 },
},
};
Plotly.newPlot(plotlyDiv, [trace], layout);
});
</script> </script>
<!-- HEADER FOR BETTER SEO --> <div bind:this={plotlyDiv} class="w-full h-full"></div>
<svelte:head>
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} Market
Heatmaps · Stocknear</title
>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta
name="description"
content="Stock Heatmaps of S&P500, Nasdaq and Dow Jones to see percentage changes of the return for different time periods"
/>
<!-- Other meta tags -->
<meta property="og:title" content="Market Heatmaps · Stocknear" />
<meta
property="og:description"
content="Stock Heatmaps of S&P500, Nasdaq and Dow Jones to see percentage changes of the return for different time periods"
/>
<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="Market Heatmaps · Stocknear" />
<meta
name="twitter:description"
content="Stock Heatmaps of S&P500, Nasdaq and Dow Jones to see percentage changes of the return for different time periods"
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full max-w-3xl sm:max-w-screen-xl overflow-hidden min-h-screen pt-5 pb-40"
>
<div
class="w-full m-auto sm:bg-primary sm:rounded-xl h-auto pl-10 pr-10 pt-5 sm:pb-10 sm:pt-10 mt-3 mb-8"
>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-10">
<!-- Start Column -->
<div>
<div class="flex flex-row justify-center items-center">
<h1
class="text-3xl sm:text-4xl text-white text-center font-bold mb-5"
>
Market Heatmaps
</h1>
</div>
<span
class="hidden sm:block text-white text-md font-medium text-center flex justify-center items-center"
>
Latest market changes to never miss another bullish or bearish rally.
</span>
</div>
<!-- End Column -->
<!-- Start Column -->
<div class="hidden sm:block relative m-auto mb-5 mt-5 sm:mb-0 sm:mt-0">
<svg
class="w-40 -my-5"
viewBox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<filter id="glow">
<feGaussianBlur stdDeviation="5" result="glow" />
<feMerge>
<feMergeNode in="glow" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<path
fill="#1E40AF"
d="M57.6,-58.7C72.7,-42.6,81.5,-21.3,82,0.5C82.5,22.3,74.7,44.6,59.7,60.1C44.6,75.6,22.3,84.3,0,84.3C-22.3,84.2,-44.6,75.5,-61.1,60.1C-77.6,44.6,-88.3,22.3,-87.6,0.7C-86.9,-20.8,-74.7,-41.6,-58.2,-57.7C-41.6,-73.8,-20.8,-85.2,0.2,-85.4C21.3,-85.6,42.6,-74.7,57.6,-58.7Z"
transform="translate(100 100)"
filter="url(#glow)"
/>
</svg>
<div class="z-1 absolute top-0 left-8">
<img
class="w-32 h-fit"
src={cloudFrontUrl + "/assets/heatmaps_logo.png"}
alt="logo"
loading="lazy"
/>
</div>
</div>
<!-- End Column -->
</div>
</div>
<body class="w-full overflow-hidden m-auto">
{#if isLoaded}
<section class="w-full overflow-hidden m-auto">
<div class="p-0 flex justify-center w-full m-auto overflow-hidden">
<div
class="relative flex justify-center items-center overflow-hidden w-full"
>
<main class="w-full">
<div
class="w-full text-center sm:text-start sm:flex sm:flex-row sm:items-center m-auto text-gray-100 border border-gray-800 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
>
<span>
Today, <label
on:click={() => sectorSelector(lowestAvgCategory)}
class="cursor-pointer text-blue-400 sm:hover:text-white"
>{lowestAvgCategory}</label
>
took the lead as the {displayIndex} largest loser, marking a average
return of
<span class="text-white font-medium"
>{lowestAvg?.toFixed(2)}%</span
>, while
<label
on:click={() => sectorSelector(highestAvgCategory)}
class="cursor-pointer text-blue-400 sm:hover:text-white"
>{highestAvgCategory}</label
>
surged ahead as the top performer with an impressive average return
of
<span class="text-white font-medium"
>{highestAvg?.toFixed(2)}%</span
>.
</span>
</div>
<div class="w-full pt-3">
<div class="relative right-0 bg-default">
<ul
class="relative w-fit flex flex-wrap px-2 list-none rounded-[3px]"
>
<li
class="px-3 py-1.5 flex-auto text-center bg-[#2E3238] rounded-[3px]"
>
<label
for="indexModal"
class="cursor-pointer border flex items-center justify-center w-full px-0 py-1 mb-0 border-0 rounded-[3px] bg-inherit"
>
<span class="text-sm sm:text-md text-white ml-1">
Market Index:
</span>
<span
class="text-sm sm:text-md font-medium text-white ml-2 mr-2"
>
{displayIndex}
</span>
<svg
class="ml-auto sm:ml-0 mr-5 h-4 w-4 inline-block transform transition-transform mr-2 rotate-180"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1024 1024"
><path
fill="#fff"
d="m488.832 344.32l-339.84 356.672a32 32 0 0 0 0 44.16l.384.384a29.44 29.44 0 0 0 42.688 0l320-335.872l319.872 335.872a29.44 29.44 0 0 0 42.688 0l.384-.384a32 32 0 0 0 0-44.16L535.168 344.32a32 32 0 0 0-46.336 0z"
/></svg
>
</label>
</li>
<!--
<li class="pl-3 py-1.5 flex-auto text-center bg-[#2E3238] rounded-[3px]">
<label for="exportDataModal" class="cursor-pointer border flex items-center justify-center w-full px-0 py-1 mb-0 border-0 rounded-[3px] bg-inherit">
<span class="text-sm font-medium text-white ml-3">
Export
</span>
<svg class="ml-auto mr-5 h-4 w-4 inline-block transform transition-transform mr-2 rotate-180" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="#fff" d="m488.832 344.32l-339.84 356.672a32 32 0 0 0 0 44.16l.384.384a29.44 29.44 0 0 0 42.688 0l320-335.872l319.872 335.872a29.44 29.44 0 0 0 42.688 0l.384-.384a32 32 0 0 0 0-44.16L535.168 344.32a32 32 0 0 0-46.336 0z"/></svg>
</label>
</li>
-->
</ul>
</div>
</div>
<div class="app w-full h-full mt-10">
<Chart
id="treemap"
{init}
{options}
class="chart w-full h-full"
/>
</div>
</main>
</div>
</div>
</section>
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-secondary 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 text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</body>
</section>
<!--Start IndexModal -->
<input type="checkbox" id="indexModal" class="modal-toggle" />
<dialog id="indexModal" class="modal modal-bottom sm:modal-middle">
<label
id="indexModal"
for="indexModal"
class="cursor-pointer modal-backdrop bg-[#fff] bg-opacity-[0.02] sm:bg-[#000] sm:bg-opacity-[0.5]"
></label>
<div
class="modal-box w-full bg-[#000] sm:bg-default sm:border sm:border-gray-600"
>
<label
for="indexModal"
class="cursor-pointer absolute right-5 top-2 bg-[#000] sm:bg-default text-[1.8rem] text-white"
>
</label>
<div class="text-white">
<h3 class="font-medium text-lg sm:text-xl mb-10">Market Index</h3>
<div
class="flex flex-col items-center w-full max-w-3xl bg-[#000] sm:bg-default"
>
<label
for="indexModal"
on:click={() => changeIndex("S&P500")}
class="cursor-pointer w-full flex flex-row justify-start items-center mb-5"
>
<div
class="flex flex-row items-center w-full bg-default bg-opacity-[0.7] sm:bg-opacity-[1.0] sm:bg-[#303030] p-3 rounded-md {displayIndex ===
'S&P500'
? 'ring-2 ring-[#04E000]'
: ''}"
>
<span class="ml-1 text-white font-medium mr-auto"> S&P500 </span>
</div>
</label>
<label
for="indexModal"
on:click={() => changeIndex("Dow Jones")}
class="cursor-pointer w-full flex flex-row justify-start items-center mb-5"
>
<div
class="flex flex-row items-center w-full bg-default bg-opacity-[0.7] sm:bg-opacity-[1.0] sm:bg-[#303030] p-3 rounded-md {displayIndex ===
'Dow Jones'
? 'ring-2 ring-[#04E000]'
: ''}"
>
<span class="ml-1 text-white font-medium mr-auto"> Dow Jones </span>
</div>
</label>
<label
for="indexModal"
on:click={() => changeIndex("Nasdaq")}
class="cursor-pointer w-full flex flex-row justify-start items-center mb-5"
>
<div
class="flex flex-row items-center w-full bg-default bg-opacity-[0.7] sm:bg-opacity-[1.0] sm:bg-[#303030] p-3 rounded-md {displayIndex ===
'Nasdaq'
? 'ring-2 ring-[#04E000]'
: ''}"
>
<span class="ml-1 text-white font-medium mr-auto"> Nasdaq </span>
</div>
</label>
</div>
</div>
</div>
</dialog>
<!--End Index Modal-->
<!--Start Export -->
<input type="checkbox" id="exportDataModal" class="modal-toggle" />
<dialog id="exportDataModal" class="modal modal-bottom sm:modal-middle">
<label
id="exportDataModal"
for="exportDataModal"
class="cursor-pointer modal-backdrop bg-[#fff] bg-opacity-[0.02] sm:bg-[#000] sm:bg-opacity-[0.5]"
></label>
<div
class="modal-box w-full bg-[#000] sm:bg-default sm:border sm:border-gray-600"
>
<label
for="exportDataModal"
class="cursor-pointer absolute right-5 top-2 bg-[#000] sm:bg-default text-[1.8rem] text-white"
>
</label>
<div class="text-white">
<h3 class="font-medium text-lg sm:text-xl mb-10">Export</h3>
<div
class="flex flex-col items-center w-full max-w-3xl bg-[#000] sm:bg-default"
>
<label
for="exportDataModal"
on:click={() => exportTreemap()}
class="cursor-pointer w-full flex flex-row justify-start items-center mb-5"
>
<div
class="flex flex-row items-center w-full bg-default bg-opacity-[0.7] sm:bg-opacity-[1.0] sm:bg-[#303030] p-3 rounded-md ring-2 ring-[#04E000]"
>
<span class="ml-1 text-white font-medium mr-auto">
Save as PNG
</span>
</div>
</label>
<label
for="exportDataModal"
class="cursor-pointer w-full flex flex-row justify-start items-center mb-5"
>
<div
class="flex flex-row items-center w-full bg-default bg-opacity-[0.7] sm:bg-opacity-[1.0] sm:bg-[#303030] p-3 rounded-md ring-2 ring-[#04E000]"
>
<span class="ml-1 text-white font-medium mr-auto">
Save as JPG
</span>
</div>
</label>
</div>
</div>
</div>
</dialog>
<!--End Export-->
<style>
.app {
height: 1200px;
width: 100%;
}
.chart {
width: 100%;
}
</style>

View File

@ -0,0 +1,94 @@
<script lang="ts">
import { stockTicker } from "$lib/store";
import { page } from "$app/stores";
export let data;
let displaySubSection = "overview";
function changeSubSection(state) {
const subSectionMap = {
dex: "/options/dex",
strike: "/options/dex/strike",
expiry: "/options/dex/expiry",
};
if (state !== "overview" && subSectionMap[state]) {
displaySubSection = state;
//goto(`/stocks/${$stockTicker}${subSectionMap[state]}`);
} else {
displaySubSection = state;
//goto(`/stocks/${$stockTicker}/statistics`);
}
}
$: {
if ($page?.url?.pathname) {
const parts = $page?.url?.pathname.split("/");
const sectionMap = {
overview: "overview",
strike: "strike",
expiry: "expiry",
};
const foundSection = parts?.find((part) =>
Object?.values(sectionMap)?.includes(part),
);
displaySubSection =
Object?.keys(sectionMap)?.find(
(key) => sectionMap[key] === foundSection,
) || "overview";
}
}
</script>
<section class="w-full overflow-hidden min-h-screen">
<div class="w-full overflow-hidden m-auto">
<div class="sm:p-0 flex justify-center w-full m-auto overflow-hidden">
<div
class="relative flex justify-center items-start overflow-hidden w-full"
>
<main class="w-full">
<nav
class="sm:ml-4 overflow-x-scroll pt-1 text-sm sm:text-[1rem] whitespace-nowrap"
>
<ul class="flex flex-row items-center w-full text-white">
<a
href={`/stocks/${$stockTicker}/options/dex`}
on:click={() => changeSubSection("overview")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'overview'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
Overview
</a>
<a
href={`/stocks/${$stockTicker}/options/dex/strike`}
on:click={() => changeSubSection("strike")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'strike'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
By Strike
</a>
<a
href={`/stocks/${$stockTicker}/options/dex/expiry`}
on:click={() => changeSubSection("expiry")}
class="p-2 px-5 cursor-pointer {displaySubSection === 'expiry'
? 'text-white bg-primary sm:hover:bg-opacity-[0.95]'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
By Expiry
</a>
</ul>
</nav>
<div class="mt-2 sm:mt-0">
<slot />
</div>
</main>
</div>
</div>
</div>
</section>

View File

@ -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(),
};
};

View File

@ -0,0 +1,525 @@
<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,
]);
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$stockTicker}) Gamma Exposure · Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$stockTicker}) Gamma Exposure · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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} (${$stockTicker}) Gamma Exposure · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 displayList 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>
{: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>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 400px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 300px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -0,0 +1,35 @@
export const load = async ({ locals, params }) => {
const { apiKey, apiURL, user } = locals;
const getData = async () => {
const postData = {
params: params.tickerID,
category: "expiry"
};
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;
};
// Make sure to return a promise
return {
getData: await getData(),
};
};

View File

@ -0,0 +1,432 @@
<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,
]);
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$stockTicker}) Gamma Exposure by Strike Price ·
Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$stockTicker}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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} (${$stockTicker}) Gamma Exposure by Strike Price · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 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 displayList 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>
{: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>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 600px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 500px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -0,0 +1,35 @@
export const load = async ({ locals, params }) => {
const { apiKey, apiURL, user } = locals;
const getData = async () => {
const postData = {
params: params.tickerID,
category: "strike"
};
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;
};
// Make sure to return a promise
return {
getData: await getData(),
};
};

View File

@ -0,0 +1,415 @@
<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,
]);
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>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
{$displayCompanyName} ({$stockTicker}) Delta Exposure by Strike Price ·
Stocknear
</title>
<meta
name="description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Other meta tags -->
<meta
property="og:title"
content={`${$displayCompanyName} (${$stockTicker}) Delta Exposure by Strike Price · Stocknear`}
/>
<meta
property="og:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<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} (${$stockTicker}) Delta Exposure by Strike Price · Stocknear`}
/>
<meta
name="twitter:description"
content={`Explore historic volume & open interest of option chains & save individual contracts for later`}
/>
<!-- Add more Twitter meta tags as needed -->
</svelte:head>
<section
class="w-full bg-default overflow-hidden text-white min-h-screen pb-40"
>
<div class="w-full flex h-full overflow-hidden">
<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 displayList 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>
{:else}
<div class="sm:p-7 w-full m-auto mt-2 sm:mt-0">
<div class="mt-2">
<Infobox text="No data is available" />
</div>
</div>
{/if}
</div>
</div>
</section>
<style>
.app {
height: 1000px;
width: 100%;
}
@media (max-width: 560px) {
.app {
width: 100%;
height: 500px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -77,6 +77,7 @@
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2)); const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
const options = { const options = {
animation: false,
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
axisPointer: { axisPointer: {

View File

@ -66,6 +66,7 @@
const netGamma = processedData.map((d) => d.netGamma?.toFixed(2)); const netGamma = processedData.map((d) => d.netGamma?.toFixed(2));
const options = { const options = {
animation: false,
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
axisPointer: { axisPointer: {