From 57f9e03dad84df19a6f634601ff7ef2cb6136ce0 Mon Sep 17 00:00:00 2001 From: mnsrulz Date: Thu, 18 Apr 2024 11:43:24 -0400 Subject: [PATCH 1/2] 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(() => { From 131e331652cdb32044c060ac3571f0573c18d21d Mon Sep 17 00:00:00 2001 From: mnsrulz Date: Fri, 19 Apr 2024 00:39:48 +0000 Subject: [PATCH 2/2] added option analyzer as link --- src/app/options/analyze/page.tsx | 8 ++++++++ src/app/routes.tsx | 2 ++ src/components/ticker-search.tsx | 7 +++++-- src/lib/socket.ts | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/app/options/analyze/page.tsx diff --git a/src/app/options/analyze/page.tsx b/src/app/options/analyze/page.tsx new file mode 100644 index 0000000..648664c --- /dev/null +++ b/src/app/options/analyze/page.tsx @@ -0,0 +1,8 @@ +'use client'; +import { TickerSearch } from "@/components/ticker-search"; +import { useRouter } from 'next/navigation' + +export default function Page() { + const router = useRouter(); + return router.push(`/options/analyze/${v.symbol}`)} /> +} \ No newline at end of file diff --git a/src/app/routes.tsx b/src/app/routes.tsx index 4219449..404bd92 100644 --- a/src/app/routes.tsx +++ b/src/app/routes.tsx @@ -28,6 +28,7 @@ import { signOut } from 'next-auth/react' const pages = [ { title: 'Home', href: '/' }, { title: 'Trades', href: '/trades' }, + { title: 'Option analyzer', href: '/options/analyze' }, { title: 'History', href: '/history' } ]; const settings = ['Profile', 'Logout']; @@ -77,6 +78,7 @@ function MyTabs() { + ); } diff --git a/src/components/ticker-search.tsx b/src/components/ticker-search.tsx index b2849df..cf38e21 100644 --- a/src/components/ticker-search.tsx +++ b/src/components/ticker-search.tsx @@ -1,4 +1,4 @@ -import { Autocomplete, TextField, debounce } from '@mui/material'; +import { Autocomplete, CircularProgress, TextField, debounce } from '@mui/material'; import * as React from 'react'; import { SearchTickerItem, searchTicker } from '../lib/socket'; import { useEffect, useMemo, useState } from 'react'; @@ -9,6 +9,7 @@ interface ITickerProps { export const TickerSearch = (props: ITickerProps) => { const [options, setOptions] = useState([]); + const [loading, setLoading] = useState(false); const onInputChange = (ev: any, value: any, reason: any) => { if (value) { getData(value); @@ -22,8 +23,10 @@ export const TickerSearch = (props: ITickerProps) => { , []); const getData = async (searchTerm: string) => { + setLoading(true); const result = await searchTicker(searchTerm); setOptions(result); + setLoading(false); }; return x} @@ -39,7 +42,7 @@ export const TickerSearch = (props: ITickerProps) => { ...params.InputProps, endAdornment: ( - {/* {loading ? : null} */} + {loading ? : null} {params.InputProps.endAdornment} ), diff --git a/src/lib/socket.ts b/src/lib/socket.ts index 22510e9..28e4c6f 100644 --- a/src/lib/socket.ts +++ b/src/lib/socket.ts @@ -121,7 +121,7 @@ export const useOptionTracker = (symbol: string) => { setOd(r); const { currentPrice } = r; const thresholdValue = currentPrice * 0.1; - debugger; + // debugger; setStrikePriceRange({ start: Math.round(currentPrice - thresholdValue), end: Math.round(currentPrice + thresholdValue)