From 57f9e03dad84df19a6f634601ff7ef2cb6136ce0 Mon Sep 17 00:00:00 2001 From: mnsrulz Date: Thu, 18 Apr 2024 11:43:24 -0400 Subject: [PATCH] fixed the pricing issue --- src/app/api/symbols/[symbol]/options/analyze/route.ts | 2 +- src/components/stock-options-view.tsx | 4 ++-- src/lib/socket.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/api/symbols/[symbol]/options/analyze/route.ts b/src/app/api/symbols/[symbol]/options/analyze/route.ts index 386ef04..5193383 100644 --- a/src/app/api/symbols/[symbol]/options/analyze/route.ts +++ b/src/app/api/symbols/[symbol]/options/analyze/route.ts @@ -3,7 +3,7 @@ import { NextResponse } from "next/server"; //export const runtime = 'edge'; export async function GET(request: Request, p: { params: { symbol: string } }) { - const resp = await ky(`https://www.optionsprofitcalculator.com/ajax/getOptions?stock=${p.params.symbol}&reqId=1`).json<{ currentPrice: number | undefined }>(); + const resp = await ky(`https://www.optionsprofitcalculator.com/ajax/getOptions?stock=${p.params.symbol}&reqId=${new Date().getTime()}`).json<{ currentPrice: number | undefined }>(); const priceresp = await ky(`https://www.optionsprofitcalculator.com/ajax/getStockPrice?stock=${p.params.symbol}&reqId=${new Date().getTime()}`).json<{ price: { last: number | undefined } }>(); resp.currentPrice = priceresp.price.last; return NextResponse.json(resp); diff --git a/src/components/stock-options-view.tsx b/src/components/stock-options-view.tsx index b3cba78..a8f99fd 100644 --- a/src/components/stock-options-view.tsx +++ b/src/components/stock-options-view.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { NumberRange, useOptionTracker } from '../lib/socket'; import { GridColDef, DataGrid, gridClasses } from '@mui/x-data-grid'; -import { Box, FormControl, Grid, InputLabel, MenuItem, Paper, Select, Slider, Stack, Tab, Tabs } from '@mui/material'; +import { Box, FormControl, Grid, InputLabel, MenuItem, Paper, Select, Slider, Stack, Tab, Tabs, LinearProgress } from '@mui/material'; import { useState } from 'react'; import dayjs from 'dayjs'; import { percentageFormatter } from '@/lib/formatters'; @@ -61,7 +61,7 @@ export const StockOptionsView = (props: ITickerProps) => { const [priceMode, setPriceMode] = useState('AVG_PRICE'); const [valueMode, setValueMode] = useState('PRICE'); - if (isLoading) return
loading...
; + if (isLoading) return ; const allDates = data && Array.from(Object.keys(data.options)); const allStrikePrices = allDates && Array.from(new Set(allDates.flatMap(d => Object.keys(data.options[d].c))))//.map(Number).sort(function (a, b) { return a - b; }); if (!allDates || !allStrikePrices) return
no option data found!!!
; diff --git a/src/lib/socket.ts b/src/lib/socket.ts index afeb311..22510e9 100644 --- a/src/lib/socket.ts +++ b/src/lib/socket.ts @@ -112,7 +112,7 @@ export type NumberRange = { start: number, end: number } export const useOptionTracker = (symbol: string) => { const [data, setOd] = useState(); - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setIsLoading] = useState(true); const [strikePriceRange, setStrikePriceRange] = useState({ start: 0, end: Number.MAX_VALUE }); useEffect(() => {