Skip to content

Commit

Permalink
Merge pull request #13 from mnsrulz/main
Browse files Browse the repository at this point in the history
sync: main to stage
  • Loading branch information
mnsrulz authored Apr 19, 2024
2 parents 118f6dc + 131e331 commit 47b88da
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 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
8 changes: 8 additions & 0 deletions src/app/options/analyze/page.tsx
Original file line number Diff line number Diff line change
@@ -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 <TickerSearch onChange={(v) => router.push(`/options/analyze/${v.symbol}`)} />
}
2 changes: 2 additions & 0 deletions src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -77,6 +78,7 @@ function MyTabs() {
<Button><Link href="/" className=''>Home</Link></Button>
<Button><Link href="/trades" className=''>Trades</Link></Button>
<Button><Link href="/history">History</Link></Button>
<Button><Link href="/options/analyze">Option Analyzer</Link></Button>
</ButtonGroup>
);
}
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
7 changes: 5 additions & 2 deletions src/components/ticker-search.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,6 +9,7 @@ interface ITickerProps {

export const TickerSearch = (props: ITickerProps) => {
const [options, setOptions] = useState<SearchTickerItem[]>([]);
const [loading, setLoading] = useState(false);
const onInputChange = (ev: any, value: any, reason: any) => {
if (value) {
getData(value);
Expand All @@ -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 <Autocomplete filterOptions={(x) => x}
Expand All @@ -39,7 +42,7 @@ export const TickerSearch = (props: ITickerProps) => {
...params.InputProps,
endAdornment: (
<React.Fragment>
{/* {loading ? <CircularProgress color="inherit" size={20} /> : null} */}
{loading ? <CircularProgress color="inherit" size={20} /> : null}
{params.InputProps.endAdornment}
</React.Fragment>
),
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -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)
Expand Down

0 comments on commit 47b88da

Please sign in to comment.