-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor refactoring in the options analysis page
- Loading branch information
Showing
9 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import { getDexGexAnalysisView } from "@/lib/tradierService"; | ||
import { C } from "./C"; | ||
import { DexGexType } from "@/lib/types"; | ||
import { Suspense } from "react"; | ||
import { LinearProgress } from "@mui/material"; | ||
import { OptionsAnalysisChartWrapper } from "@/components/OptionsAnalysisChartWrapper"; | ||
|
||
const ChartWrapper = async (props: { symbol: string, dte: number, tab: DexGexType, strikeCountValue: number }) => { | ||
const { symbol, dte, tab, strikeCountValue } = props; | ||
const cachedDates: string[] = [];//await getCachedSummaryDatesBySymbol(symbol); | ||
const { currentPrice, mappedOptions } = await getDexGexAnalysisView(symbol); | ||
const dataMode = 'Live' | ||
return <C cachedDates={cachedDates} dte={dte} sc={strikeCountValue} dataMode={dataMode} data={mappedOptions} symbol={symbol} price={currentPrice} tab={tab} /> | ||
} | ||
|
||
export default async function Page({ params, searchParams }: { params: { symbol: string }, searchParams: { [key: string]: string | number } }) { | ||
export default async function OptionsAnalysisPage({ params, searchParams }: { params: { symbol: string }, searchParams: { [key: string]: string | number } }) { | ||
const search = searchParams; | ||
const { symbol } = params; | ||
const strikeCountValue = (search['sc'] || 30) as number; | ||
const dte = (search['dte'] || 50) as number; | ||
const tab = (search['tab'] || 'DEX') as DexGexType; | ||
const strikeCount = (search['sc'] || 30) as number; | ||
const daysToExpiration = (search['dte'] || 50) as number; | ||
const analysisType = (search['tab'] || 'DEX') as DexGexType; | ||
|
||
return <Suspense fallback={<LinearProgress />}> | ||
<ChartWrapper symbol={symbol} dte={dte} strikeCountValue={strikeCountValue} tab={tab} /> | ||
<OptionsAnalysisChartWrapper symbol={symbol} daysToExpiration={daysToExpiration} strikeCount={strikeCount} analysisType={analysisType} /> | ||
</Suspense> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getDexGexAnalysisView } from "@/lib/tradierService"; | ||
import { DexGexType } from "@/lib/types"; | ||
import { getDexGexAnalysisViewCboe } from "@/lib/cboeService"; | ||
import { OptionsAnalysisComponent } from "@/components/OptionsAnalysisComponent"; | ||
|
||
export const OptionsAnalysisChartWrapper = async (props: { symbol: string, daysToExpiration: number, analysisType: DexGexType, strikeCount: number }) => { | ||
const { symbol, daysToExpiration, analysisType, strikeCount } = props; | ||
const cachedDates: string[] = [];//await getCachedSummaryDatesBySymbol(symbol); | ||
const { currentPrice, mappedOptions } = await getDexGexAnalysisView(symbol); | ||
const dataMode = 'Live'; | ||
|
||
return <OptionsAnalysisComponent cachedDates={cachedDates} dte={daysToExpiration} | ||
sc={strikeCount} dataMode={dataMode} data={mappedOptions} symbol={symbol} | ||
price={currentPrice} tab={analysisType} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import ky from "ky"; | ||
|
||
const client = ky.create({ | ||
headers: { | ||
'Accept': 'application/json' | ||
}, | ||
cache: 'no-cache' | ||
}); | ||
|
||
//JUST FOR REF.. PLANNING TO USE THE MZTRADING-DATA SERVICE FOR THIS | ||
export const getDexGexAnalysisViewCboe = async (symbol: string) => { | ||
const optionChain = await client(`https://cdn.cboe.com/api/global/delayed_quotes/options/${symbol}.json`).json<{ | ||
data: { | ||
options: { | ||
option: string, | ||
open_interest: number, | ||
delta: number, | ||
volume: number, | ||
gamma: number, | ||
}[], | ||
close: number | ||
} | ||
}>(); | ||
const currentPrice = optionChain.data.close; //TODO: is this the close price which remains same if the market is open?? | ||
|
||
console.time(`getDexGexAnalysisViewCboe-mapping-${symbol}`) | ||
const mappedOptions = optionChain.data.options.map(({ option, open_interest,volume, delta, gamma }) => { | ||
//implement mem cache for regex match?? | ||
const rxMatch = /(\w+)(\d{6})([CP])(\d+)/.exec(option); | ||
if(!rxMatch) throw new Error('error parsing option') | ||
|
||
return { | ||
strike: Number(`${rxMatch[4]}`)/1000, | ||
expiration_date: `20${rxMatch[2].substring(0,2)}-${rxMatch[2].substring(2,4)}-${rxMatch[2].substring(4,6)}`, | ||
open_interest, | ||
option_type: (rxMatch[3] == 'C' ? 'call': 'put') as 'call' | 'put', | ||
volume, | ||
greeks: { | ||
delta: delta || 0, | ||
gamma: gamma || 0, | ||
} | ||
} | ||
}); | ||
console.timeEnd(`getDexGexAnalysisViewCboe-mapping-${symbol}`) | ||
return { mappedOptions, currentPrice } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
import numeral from 'numeral'; | ||
|
||
export const percentageFormatter = (v: number) => v && Number(v).toLocaleString(undefined, { style: 'percent', minimumFractionDigits: 2 }) || ''; | ||
export const currencyFormatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }).format; | ||
export const numberFormatter = new Intl.NumberFormat('en-US', { style: 'decimal', maximumFractionDigits: 2 }).format; | ||
export const positiveNegativeNumberFormatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2, signDisplay: 'always' }).format; | ||
export const fixedCurrencyFormatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format; | ||
|
||
export const humanAbsCurrencyFormatter = (tick: number) => { | ||
tick = Math.abs(tick); | ||
if (tick >= 1000000000) { | ||
return `${(tick / 1000000000).toFixed(1)}B`; // Billions | ||
} else if (tick >= 1000000) { | ||
return `${(tick / 1000000).toFixed(1)}M`; // Millions | ||
} else if (tick >= 1000) { | ||
return `${(tick / 1000).toFixed(1)}K`; // Thousands | ||
} | ||
return `${tick}`; | ||
export const humanAbsCurrencyFormatter = (tick: number) => { | ||
return numeral(Math.abs(tick)).format('0.[0]a').toUpperCase(); | ||
} |