Skip to content

Commit

Permalink
fixed the pricing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz authored Apr 18, 2024
1 parent 8c3dd14 commit 57f9e03
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/api/symbols/[symbol]/options/analyze/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/components/stock-options-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const StockOptionsView = (props: ITickerProps) => {
const [priceMode, setPriceMode] = useState<PriceModeType>('AVG_PRICE');
const [valueMode, setValueMode] = useState<ValueModeType>('PRICE');

if (isLoading) return <div>loading...</div>;
if (isLoading) return <LinearProgress /> ;
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 <div>no option data found!!!</div>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type NumberRange = { start: number, end: number }

export const useOptionTracker = (symbol: string) => {
const [data, setOd] = useState<OptionsData>();
const [isLoading, setIsLoading] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [strikePriceRange, setStrikePriceRange] = useState<NumberRange>({ start: 0, end: Number.MAX_VALUE });

useEffect(() => {
Expand Down

0 comments on commit 57f9e03

Please sign in to comment.