adding new section OI By Strike/Expiry
This commit is contained in:
parent
7a4331e7a8
commit
8d834d1d3a
347
src/lib/components/Options/OpenInterestByExpiry.svelte
Normal file
347
src/lib/components/Options/OpenInterestByExpiry.svelte
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { abbreviateNumberWithColor } from "$lib/utils";
|
||||||
|
import { screenWidth } from "$lib/store";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||||
|
import UpgradeToPro from "$lib/components/UpgradeToPro.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) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
put_call_ratio:
|
||||||
|
item?.call_oi > 0
|
||||||
|
? Math.abs((item?.put_oi || 0) / item?.call_oi)
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
let displayList = rawData?.slice(0, 150);
|
||||||
|
let options = null;
|
||||||
|
|
||||||
|
function plotData() {
|
||||||
|
const processedData = rawData?.map((d) => ({
|
||||||
|
expiry: d?.expiry,
|
||||||
|
callValue: d?.call_oi,
|
||||||
|
putValue: d?.put_oi,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const dates = processedData?.map((d) => d.expiry);
|
||||||
|
const callValues = processedData?.map((d) => d.callValue?.toFixed(2));
|
||||||
|
const putValues = processedData?.map((d) => d.putValue?.toFixed(2));
|
||||||
|
const barWidthPercentage = Math.max(100 / processedData.length, 20); // Adjust automatically, max 80%
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
animation: false,
|
||||||
|
tooltip: {
|
||||||
|
trigger: "axis",
|
||||||
|
axisPointer: {
|
||||||
|
type: "shadow",
|
||||||
|
},
|
||||||
|
backgroundColor: "#313131",
|
||||||
|
textStyle: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
formatter: function (params) {
|
||||||
|
const strike = params[0].axisValue;
|
||||||
|
const call = params[1].data;
|
||||||
|
const put = params[0].data;
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div style="text-align:left;">
|
||||||
|
<b>Strike:</b> ${strike}<br/>
|
||||||
|
<span style="color:#00FC50;">● Call OI:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||||
|
<span style="color:#FF2F1F;">● Put OI:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||||
|
</div>`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
left: $screenWidth < 640 ? "5%" : "2%",
|
||||||
|
right: $screenWidth < 640 ? "5%" : "2%",
|
||||||
|
bottom: "10%",
|
||||||
|
containLabel: true,
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
type: "value",
|
||||||
|
nameTextStyle: { color: "#fff" },
|
||||||
|
splitLine: { show: false },
|
||||||
|
axisLabel: {
|
||||||
|
show: false, // Hide x-axis labels
|
||||||
|
},
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
type: "category",
|
||||||
|
data: dates,
|
||||||
|
axisLine: { lineStyle: { color: "#fff" } },
|
||||||
|
axisLabel: {
|
||||||
|
color: "#fff",
|
||||||
|
interval: (index) => index % 2 === 0, // Show every 5th label
|
||||||
|
rotate: 45, // Rotate labels for better readability
|
||||||
|
fontSize: 12, // Adjust font size if needed
|
||||||
|
margin: 20,
|
||||||
|
},
|
||||||
|
splitLine: { show: false },
|
||||||
|
},
|
||||||
|
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: `Put`,
|
||||||
|
type: "bar",
|
||||||
|
data: putValues,
|
||||||
|
itemStyle: { color: "#FF2F1F" },
|
||||||
|
barWidth: `${barWidthPercentage}%`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Call `,
|
||||||
|
type: "bar",
|
||||||
|
data: callValues,
|
||||||
|
itemStyle: { color: "#00FC50" },
|
||||||
|
barWidth: `${barWidthPercentage}%`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
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_oi",
|
||||||
|
label: `Call OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "put_oi",
|
||||||
|
label: `Put OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "put_call_ratio",
|
||||||
|
label: `P/C OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$: sortOrders = {
|
||||||
|
expiry: { order: "none", type: "date" },
|
||||||
|
call_oi: { order: "none", type: "number" },
|
||||||
|
put_oi: { 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>
|
||||||
|
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
Open Interest (OI) By Expiry
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="w-full overflow-hidden m-auto">
|
||||||
|
{#if options !== null}
|
||||||
|
<div class="app w-full relative">
|
||||||
|
<Chart {init} {options} class="chart" />
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="flex justify-center items-center h-80">
|
||||||
|
<div class="relative">
|
||||||
|
<label
|
||||||
|
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||||
|
></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="w-full overflow-x-scroll text-white">
|
||||||
|
<table
|
||||||
|
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<TableHeader {columns} {sortOrders} {sortData} />
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||||
|
<tr
|
||||||
|
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||||
|
1 ===
|
||||||
|
displayList?.slice(0, 3)?.length && data?.user?.tier !== 'Pro'
|
||||||
|
? 'opacity-[0.1]'
|
||||||
|
: ''}"
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{new Date(item?.expiry).toLocaleDateString("en-US", {
|
||||||
|
month: "short", // Abbreviated month (e.g., Jan)
|
||||||
|
day: "numeric", // Numeric day (e.g., 10)
|
||||||
|
year: "numeric", // Full year (e.g., 2025)
|
||||||
|
})}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{@html abbreviateNumberWithColor(
|
||||||
|
item?.call_oi?.toFixed(2),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{@html abbreviateNumberWithColor(
|
||||||
|
item?.put_oi?.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>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.app {
|
||||||
|
height: 400px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.app {
|
||||||
|
width: 100%;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
345
src/lib/components/Options/OpenInterestByStrike.svelte
Normal file
345
src/lib/components/Options/OpenInterestByStrike.svelte
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { abbreviateNumberWithColor } from "$lib/utils";
|
||||||
|
import { screenWidth } from "$lib/store";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||||
|
import UpgradeToPro from "$lib/components/UpgradeToPro.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) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
put_call_ratio:
|
||||||
|
item?.call_oi > 0
|
||||||
|
? Math.abs((item?.put_oi || 0) / item?.call_oi)
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
let displayList = rawData?.slice(0, 150);
|
||||||
|
let options = null;
|
||||||
|
|
||||||
|
function plotData() {
|
||||||
|
const processedData = rawData
|
||||||
|
?.map((d) => ({
|
||||||
|
strike: d?.strike,
|
||||||
|
callValue: d?.call_oi,
|
||||||
|
putValue: d?.put_oi,
|
||||||
|
}))
|
||||||
|
?.sort((a, b) => a?.strike - b?.strike);
|
||||||
|
|
||||||
|
const strikes = processedData?.map((d) => d.strike);
|
||||||
|
const callValues = processedData?.map((d) => d.callValue?.toFixed(2));
|
||||||
|
const putValues = processedData?.map((d) => d.putValue?.toFixed(2));
|
||||||
|
const barWidthPercentage = Math.max(100 / processedData.length, 30); // Adjust automatically, max 80%
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
animation: false,
|
||||||
|
tooltip: {
|
||||||
|
trigger: "axis",
|
||||||
|
axisPointer: {
|
||||||
|
type: "shadow",
|
||||||
|
},
|
||||||
|
backgroundColor: "#313131",
|
||||||
|
textStyle: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
formatter: function (params) {
|
||||||
|
const strike = params[0].axisValue;
|
||||||
|
const call = params[1].data;
|
||||||
|
const put = params[0].data;
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div style="text-align:left;">
|
||||||
|
<b>Strike:</b> ${strike}<br/>
|
||||||
|
<span style="color:#00FC50;">● Call OI:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
||||||
|
<span style="color:#FF2F1F;">● Put OI:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
||||||
|
</div>`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
left: $screenWidth < 640 ? "5%" : "2%",
|
||||||
|
right: $screenWidth < 640 ? "5%" : "2%",
|
||||||
|
bottom: "10%",
|
||||||
|
containLabel: true,
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
type: "value",
|
||||||
|
nameTextStyle: { color: "#fff" },
|
||||||
|
splitLine: { show: false },
|
||||||
|
axisLabel: {
|
||||||
|
show: false, // Hide x-axis labels
|
||||||
|
},
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
type: "category",
|
||||||
|
data: strikes,
|
||||||
|
axisLine: { lineStyle: { color: "#fff" } },
|
||||||
|
axisLabel: {
|
||||||
|
color: "#fff",
|
||||||
|
interval: (index) => index % 5 === 0, // Show every 5th label
|
||||||
|
rotate: 45, // Rotate labels for better readability
|
||||||
|
fontSize: 14, // Adjust font size if needed
|
||||||
|
margin: 20,
|
||||||
|
},
|
||||||
|
splitLine: { show: false },
|
||||||
|
},
|
||||||
|
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: `Put`,
|
||||||
|
type: "bar",
|
||||||
|
data: putValues,
|
||||||
|
itemStyle: { color: "#FF2F1F" },
|
||||||
|
barWidth: `${barWidthPercentage}%`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Call `,
|
||||||
|
type: "bar",
|
||||||
|
data: callValues,
|
||||||
|
itemStyle: { color: "#00FC50" },
|
||||||
|
barWidth: `${barWidthPercentage}%`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
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_oi",
|
||||||
|
label: `Call OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "put_oi",
|
||||||
|
label: `Put OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "put_call_ratio",
|
||||||
|
label: `P/C OI`,
|
||||||
|
align: "right",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$: sortOrders = {
|
||||||
|
strike: { order: "none", type: "number" },
|
||||||
|
call_oi: { order: "none", type: "number" },
|
||||||
|
put_oi: { 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>
|
||||||
|
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
Open Interest (OI) By Strike
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="w-full overflow-hidden m-auto">
|
||||||
|
{#if options !== null}
|
||||||
|
<div class="app w-full relative">
|
||||||
|
<Chart {init} {options} class="chart" />
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="flex justify-center items-center h-80">
|
||||||
|
<div class="relative">
|
||||||
|
<label
|
||||||
|
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
||||||
|
></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="w-full overflow-x-scroll text-white">
|
||||||
|
<table
|
||||||
|
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<TableHeader {columns} {sortOrders} {sortData} />
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index}
|
||||||
|
<tr
|
||||||
|
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-odd border-b border-gray-800 {index +
|
||||||
|
1 ===
|
||||||
|
displayList?.slice(0, 3)?.length && data?.user?.tier !== 'Pro'
|
||||||
|
? 'opacity-[0.1]'
|
||||||
|
: ''}"
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-start whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{item?.strike?.toFixed(2)}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{@html abbreviateNumberWithColor(
|
||||||
|
item?.call_oi?.toFixed(2),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="text-white text-sm sm:text-[1rem] text-end whitespace-nowrap"
|
||||||
|
>
|
||||||
|
{@html abbreviateNumberWithColor(
|
||||||
|
item?.put_oi?.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>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.app {
|
||||||
|
height: 400px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.app {
|
||||||
|
width: 100%;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -13,6 +13,7 @@
|
|||||||
"hottest-contracts": "/options/hottest-contracts",
|
"hottest-contracts": "/options/hottest-contracts",
|
||||||
gex: "/options/gex",
|
gex: "/options/gex",
|
||||||
dex: "/options/dex",
|
dex: "/options/dex",
|
||||||
|
oi: "/options/oi",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (state !== "overview" && subSectionMap[state]) {
|
if (state !== "overview" && subSectionMap[state]) {
|
||||||
@ -32,6 +33,7 @@
|
|||||||
"hottest-contracts": "hottest-contracts",
|
"hottest-contracts": "hottest-contracts",
|
||||||
gex: "gex",
|
gex: "gex",
|
||||||
dex: "dex",
|
dex: "dex",
|
||||||
|
oi: "oi",
|
||||||
};
|
};
|
||||||
|
|
||||||
const foundSection = parts?.find((part) =>
|
const foundSection = parts?.find((part) =>
|
||||||
@ -77,6 +79,15 @@
|
|||||||
>
|
>
|
||||||
Hottest Contracts
|
Hottest Contracts
|
||||||
</a>
|
</a>
|
||||||
|
<a
|
||||||
|
href={`/stocks/${$stockTicker}/options/oi`}
|
||||||
|
on:click={() => changeSubSection("oi")}
|
||||||
|
class="p-2 px-5 cursor-pointer {displaySubSection === 'oi'
|
||||||
|
? '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]'}"
|
||||||
|
>
|
||||||
|
OI
|
||||||
|
</a>
|
||||||
<a
|
<a
|
||||||
href={`/stocks/${$stockTicker}/options/gex`}
|
href={`/stocks/${$stockTicker}/options/gex`}
|
||||||
on:click={() => changeSubSection("gex")}
|
on:click={() => changeSubSection("gex")}
|
||||||
|
|||||||
83
src/routes/stocks/[tickerID]/options/oi/+layout.svelte
Normal file
83
src/routes/stocks/[tickerID]/options/oi/+layout.svelte
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { stockTicker } from "$lib/store";
|
||||||
|
import { page } from "$app/stores";
|
||||||
|
|
||||||
|
export let data;
|
||||||
|
|
||||||
|
let displaySubSection = "strike";
|
||||||
|
|
||||||
|
function changeSubSection(state) {
|
||||||
|
const subSectionMap = {
|
||||||
|
strike: "/options/oi/strike",
|
||||||
|
expiry: "/options/gex/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 = {
|
||||||
|
strike: "strike",
|
||||||
|
expiry: "expiry",
|
||||||
|
};
|
||||||
|
|
||||||
|
const foundSection = parts?.find((part) =>
|
||||||
|
Object?.values(sectionMap)?.includes(part),
|
||||||
|
);
|
||||||
|
|
||||||
|
displaySubSection =
|
||||||
|
Object?.keys(sectionMap)?.find(
|
||||||
|
(key) => sectionMap[key] === foundSection,
|
||||||
|
) || "strike";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</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/oi`}
|
||||||
|
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/oi/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>
|
||||||
34
src/routes/stocks/[tickerID]/options/oi/+page.server.ts
Normal file
34
src/routes/stocks/[tickerID]/options/oi/+page.server.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
|
||||||
|
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-oi", {
|
||||||
|
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(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
71
src/routes/stocks/[tickerID]/options/oi/+page.svelte
Normal file
71
src/routes/stocks/[tickerID]/options/oi/+page.svelte
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
stockTicker,
|
||||||
|
numberOfUnreadNotification,
|
||||||
|
displayCompanyName,
|
||||||
|
} from "$lib/store";
|
||||||
|
|
||||||
|
import Infobox from "$lib/components/Infobox.svelte";
|
||||||
|
|
||||||
|
import OpenInterestByStrike from "$lib/components/Options/OpenInterestByStrike.svelte";
|
||||||
|
|
||||||
|
export let data;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>
|
||||||
|
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
|
||||||
|
{$displayCompanyName} ({$stockTicker}) Open Interet by Strike Price ·
|
||||||
|
Stocknear
|
||||||
|
</title>
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content={`Discover detailed Open Interest analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Other meta tags -->
|
||||||
|
<meta
|
||||||
|
property="og:title"
|
||||||
|
content={`${$displayCompanyName} (${$stockTicker}) Open Interest by Strike Price · Stocknear`}
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content={`Discover detailed Open Interest analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||||
|
/>
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<!-- Add more Open Graph meta tags as needed -->
|
||||||
|
|
||||||
|
<!-- Twitter specific meta tags -->
|
||||||
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
<meta
|
||||||
|
name="twitter:title"
|
||||||
|
content={`${$displayCompanyName} (${$stockTicker}) Open Interest by Strike Price · Stocknear`}
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
name="twitter:description"
|
||||||
|
content={`Discover detailed Open Interest analysis by strike price for ${$displayCompanyName} (${$stockTicker}). Explore historical volume, open interest, and save individual options contracts for in-depth insights.`}
|
||||||
|
/>
|
||||||
|
<!-- Add more Twitter meta tags as needed -->
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<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 data?.getData?.length > 0}
|
||||||
|
<OpenInterestByStrike {data} />
|
||||||
|
{: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>
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export const load = async ({ locals, params }) => {
|
||||||
|
const { apiKey, apiURL } = locals;
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const postData = {
|
||||||
|
params: params.tickerID,
|
||||||
|
category: "expiry"
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(apiURL + "/options-oi", {
|
||||||
|
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(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
70
src/routes/stocks/[tickerID]/options/oi/expiry/+page.svelte
Normal file
70
src/routes/stocks/[tickerID]/options/oi/expiry/+page.svelte
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
stockTicker,
|
||||||
|
numberOfUnreadNotification,
|
||||||
|
displayCompanyName,
|
||||||
|
} from "$lib/store";
|
||||||
|
|
||||||
|
import Infobox from "$lib/components/Infobox.svelte";
|
||||||
|
import OpenInterestByExpiry from "$lib/components/Options/OpenInterestByExpiry.svelte";
|
||||||
|
|
||||||
|
export let data;
|
||||||
|
let rawData = data?.getData || [];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>
|
||||||
|
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""}
|
||||||
|
{$displayCompanyName} ({$stockTicker}) OpenInterest by Expiry · Stocknear
|
||||||
|
</title>
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content={`Analyze Gamma Exposure by expiry for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Other meta tags -->
|
||||||
|
<meta
|
||||||
|
property="og:title"
|
||||||
|
content={`${$displayCompanyName} (${$stockTicker}) OpenInterest by Expiry · Stocknear`}
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
property="og:description"
|
||||||
|
content={`Analyze OpenInterest by expiry for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||||
|
/>
|
||||||
|
<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}) OpenInterest by Expiry · Stocknear`}
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
name="twitter:description"
|
||||||
|
content={`Analyze OpenInterest by expiry for ${$displayCompanyName} (${$stockTicker}). Access historical volume, open interest trends, and save options contracts for detailed analysis and insights.`}
|
||||||
|
/>
|
||||||
|
<!-- 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}
|
||||||
|
<OpenInterestByExpiry {data} />
|
||||||
|
{: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>
|
||||||
Loading…
x
Reference in New Issue
Block a user