-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get rid of yahoo finance api for now
- Loading branch information
Showing
8 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
POSTGRES_PRISMA_URL= | ||
POSTGRES_PRISMA_URL= | ||
AUTH_SECRET=test123 | ||
NEXTAUTH_URL=https://p63xdw4l-3000.use.devtunnels.ms/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import ky from "ky"; | ||
import { NextResponse } from "next/server"; | ||
import yf from 'yahoo-finance2'; | ||
// export const runtime = 'edge'; | ||
//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 priceResponse = await yf.quoteSummary(p.params.symbol); | ||
resp.currentPrice = priceResponse.price?.regularMarketPrice; | ||
const resp = await ky(`https://www.optionsprofitcalculator.com/ajax/getOptions?stock=${p.params.symbol}&reqId=1`).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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { StockPriceData } from "@/lib/types"; | ||
import ky from "ky"; | ||
import { NextResponse } from "next/server"; | ||
import yf from 'yahoo-finance2'; | ||
|
||
// export const runtime = 'edge'; //This specifies the runtime environment that the middleware function will be executed in. | ||
//export const runtime = 'edge'; //This specifies the runtime environment that the middleware function will be executed in. | ||
|
||
export async function GET(request: Request, p: { params: { symbol: string } }) { | ||
const resp = await yf.quoteSummary(p.params.symbol); | ||
const priceresp = await ky(`https://www.optionsprofitcalculator.com/ajax/getStockPrice?stock=${p.params.symbol}&reqId=${new Date().getTime()}`, { | ||
retry: { | ||
limit: 3 | ||
} | ||
}).json<{ price: { last: number | undefined } }>(); | ||
return NextResponse.json({ | ||
quoteSummary: resp | ||
}); | ||
quoteSummary: { | ||
price: { regularMarketPrice: priceresp.price.last as number } | ||
} | ||
} as StockPriceData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import yf from 'yahoo-finance2'; | ||
import ky from "ky"; | ||
|
||
type OptionsData = Record<string, { "l": 0.01, }>; | ||
|
||
type optionPriceType = { symbol: string, strike: number, expirationDate: Date, type: 'CALLS' | 'PUTS' } | ||
export const getOptionPrice = async (args: optionPriceType) => { | ||
const { expirationDate, strike, symbol, type } = args; | ||
const resp = await yf.options(args.symbol, { | ||
date: expirationDate | ||
}); | ||
const existingOption = resp.options.find(r => r.expirationDate.getDate() == expirationDate.getDate()); | ||
|
||
const resp = await ky(`https://www.optionsprofitcalculator.com/ajax/getOptions?stock=${args.symbol}&reqId=1`).json<{ | ||
options: Record<string, { | ||
c: OptionsData, | ||
p: OptionsData | ||
}> | ||
}>(); | ||
|
||
// console.log(resp); | ||
const expiry = expirationDate.toISOString().substring(0, 10); | ||
console.log(expiry); | ||
|
||
const existingOption = resp.options[expiry]; | ||
const pp = (() => { | ||
switch (type) { | ||
case 'CALLS': | ||
return existingOption?.calls | ||
return existingOption?.c | ||
case 'PUTS': | ||
return existingOption?.puts | ||
return existingOption?.p | ||
default: | ||
return null | ||
} | ||
})()?.find(c => c.strike == strike) | ||
return pp; | ||
})(); | ||
const sk = strike.toLocaleString(undefined, { minimumFractionDigits: 2 }); | ||
return pp && pp[sk]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters