Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: main to stage #92

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

.env
.env
/rest/
3 changes: 0 additions & 3 deletions api.http

This file was deleted.

7 changes: 4 additions & 3 deletions src/app/api/symbols/[symbol]/options/analyze/tradier/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ export async function GET(request: Request, p: { params: { symbol: string } }) {
const strikeCountValue = parseInt(searchParams.get("sc") || '30');
console.log(`calling with ${dteValue} dtes`);
const { symbol } = p.params;
const currentPrice = await getCurrentPrice(symbol);
const cleanSymbol = symbol.replace(/\W/g, ''); //to support ^spx and other similar symbols
const currentPrice = await getCurrentPrice(cleanSymbol);
if (!currentPrice) throw new Error('Unable to evaluate current price')

const expresp = await getOptionExpirations(symbol);
const expresp = await getOptionExpirations(cleanSymbol);

const tillDate = dayjs().add(dteValue, 'days');
console.log(`all expirations: ${expresp.expirations.date}`);
const allDates = [...new Set(expresp.expirations.date.filter(j => dayjs(j).isBefore(tillDate)))];
const allOptionChains = await Promise.all(allDates.map(d => getOptionData(symbol, d)));
const allOptionChains = await Promise.all(allDates.map(d => getOptionData(cleanSymbol, d)));

const allStrikes = getCalculatedStrikes(currentPrice, strikeCountValue, [...new Set(allOptionChains.flatMap(j => j.options.option.map(s => s.strike)))]);
const finalResponse = calculateHedging(allOptionChains, allStrikes, allDates, currentPrice)
Expand Down
9 changes: 4 additions & 5 deletions src/app/options/analyze/[symbol]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client';
import { StockOptionsView } from "@/components/StockOptionsView";
import { useParams } from "next/navigation";

export default function Page() {
const { symbol } = useParams<{ symbol: string }>()
export default function Page({ params }: { params: { symbol: string } }) {
const { symbol } = params;
return (
<StockOptionsView symbol={symbol} />
// <span>{JSON.stringify({symbol: decodeURIComponent(symbol).replace(/\W/g, '')})}</span>
<StockOptionsView symbol={decodeURIComponent(symbol).replace(/\W/g, '')} />
);
}
5 changes: 3 additions & 2 deletions src/app/seasonal/[symbol]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export default async function Page({ params, searchParams }: { params: { symbol:
const { symbol } = params;
const p = await searchParams;
const mode = p['mode'] as string || 'Daily';
const component = await getComponent(mode, symbol);
const cleanSymbol = decodeURIComponent(symbol).replace(/\W/g, '');
const component = await getComponent(mode, cleanSymbol);
return <Box sx={{ mt: 1 }}>
<SeasonHeader symbol={symbol} mode={mode} />
<SeasonHeader symbol={cleanSymbol} mode={mode} />
<Divider />
{component}
</Box>
Expand Down
10 changes: 5 additions & 5 deletions src/components/HistoricalDex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const HistoricalDex = (props: { dt: string, showAllSymbols: boolean }) =>
const matchesXs = useMediaQuery(theme.breakpoints.down("sm"));
const matchesMd = useMediaQuery(theme.breakpoints.down("md"));
const numberOfItemsToDisplay = matchesXs ? 2 : matchesMd ? 3 : 4;
const imgWidth = `${(100/numberOfItemsToDisplay)}%`;
const imgWidth = `${(100 / numberOfItemsToDisplay)}%`;
const ts = cachedSummarySymbolsData.filter(r => showAllSymbols || mytickersSymbols.includes(r.name)); //make sure to load only those which are part of the watchlist.

const [openDialog, setOpenDialog] = useState(false);
Expand All @@ -34,15 +34,15 @@ export const HistoricalDex = (props: { dt: string, showAllSymbols: boolean }) =>


return <PhotoProvider>
{/* <PhotoView src="/1.jpg">
{/* <PhotoView src="/1.jpg">
<img src="/1-thumbnail.jpg" alt="" />
</PhotoView> */}
{ts.map((item) => (
{ts.map((item) => (
<PhotoView key={item.assetUrl} src={item.assetUrl} >
<img src={item.assetUrl} width={imgWidth} style={{ objectFit: 'cover' }} alt={item.assetUrl}/>
<img loading='lazy' src={item.assetUrl} width={imgWidth} height="auto" style={{ objectFit: 'cover' }} alt={item.assetUrl} />
</PhotoView>
))}
</PhotoProvider>
</PhotoProvider>

// return <><ImageList cols={numberOfItemsToDisplay} gap={1}>
// {ts.map((item) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/StockOptionsView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use client';
import * as React from 'react';
import { useOptionTracker } from '../lib/socket';
import { GridColDef, DataGrid, gridClasses } from '@mui/x-data-grid';
Expand Down
8 changes: 6 additions & 2 deletions src/lib/tradierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface Result {
type: string;
id: string;
tables: {
corporate_calendars: CorporateCalendar[];
corporate_calendars: CorporateCalendar[] | undefined;
};
}

Expand All @@ -50,6 +50,7 @@ interface CorporateCalendarResponse {
request: string;
type: string;
results: Result[];
error: string
}


Expand Down Expand Up @@ -169,7 +170,10 @@ export const getEarningDates = async (symbol: string) => {
'symbols': symbol
}
}).json<CorporateCalendarResponse[]>();
const earnings = calendar[0].results.flatMap(j => j.tables.corporate_calendars)
if(calendar[0].error) {
return [];
}
const earnings = calendar[0].results.flatMap(j => j.tables.corporate_calendars || [])
// .filter(j => j != null)
// .filter(j => j != undefined)
//.filter(j => j.event_type == 14)
Expand Down
Loading