adjustable table, start date, and end date

master
Avraham Sakal 4 months ago
parent ba8bac0b61
commit 5e0ff00d02

@ -9,6 +9,9 @@ dotenv.config();
const env = new Env(); const env = new Env();
const POLYGON_API_KEY = env.require("POLYGON_API_KEY"); const POLYGON_API_KEY = env.require("POLYGON_API_KEY");
const CONCURRENCY = Number.parseInt(env.get("CONCURRENCY", "6")); const CONCURRENCY = Number.parseInt(env.get("CONCURRENCY", "6"));
const OPTION_QUOTES_TABLE = env.get("OPTION_QUOTES_TABLE", "option_quotes");
const START_DATE = env.get("START_DATE", "2022-06-07");
const END_DATE = env.get("END_DATE", "2025-01-03");
const polygon = restClient(POLYGON_API_KEY, "https://api.polygon.io", { const polygon = restClient(POLYGON_API_KEY, "https://api.polygon.io", {
pagination: true, pagination: true,
@ -38,7 +41,7 @@ function* dateRange(
} }
} }
for (const date of dateRange("2024-05-02", "2024-05-03")) { for (const date of dateRange(START_DATE, END_DATE)) {
const contracts = await polygon.reference.optionsContracts({ const contracts = await polygon.reference.optionsContracts({
underlying_ticker: "SPY", underlying_ticker: "SPY",
as_of: date, as_of: date,
@ -62,7 +65,7 @@ for (const date of dateRange("2024-05-02", "2024-05-03")) {
); );
if (quotes.status?.toLowerCase() === "ok" && quotes.results) { if (quotes.status?.toLowerCase() === "ok" && quotes.results) {
await client.insert({ await client.insert({
table: "option_quotes2", table: OPTION_QUOTES_TABLE,
values: quotes.results.map( values: quotes.results.map(
({ bid_price, ask_price, sip_timestamp }) => ({ ({ bid_price, ask_price, sip_timestamp }) => ({
option_type: contract.contract_type, option_type: contract.contract_type,
@ -76,13 +79,14 @@ for (const date of dateRange("2024-05-02", "2024-05-03")) {
), ),
format: "JSONEachRow", format: "JSONEachRow",
}); });
console.log(date, contract.ticker, quotes.results?.length); // console.log(date, contract.ticker, quotes.results?.length);
} }
} }
}); });
} }
} }
} }
console.log("finished", date);
} }
// const data = await polygon.options.quotes( // const data = await polygon.options.quotes(

Loading…
Cancel
Save