|
|
|
@ -104,21 +104,12 @@ export async function* makeGetOptionContractAggregatesIterator({
|
|
|
|
|
const currentDateAsDateObject = new Date(firstDate);
|
|
|
|
|
while (currentDateAsDateObject <= expirationDateAsDateObject) {
|
|
|
|
|
const asOfDate = currentDateAsDateObject.toISOString().substring(0, 10);
|
|
|
|
|
let latestBatchResponse = await pRetry(
|
|
|
|
|
async () =>
|
|
|
|
|
(await (
|
|
|
|
|
await fetch(
|
|
|
|
|
`https://api.polygon.io/v2/aggs/ticker/${optionContractTicker}/range/1/minute/${asOfDate}/${asOfDate}?adjusted=false&sort=asc&limit=50000&apiKey=${await getApiKey()}`
|
|
|
|
|
)
|
|
|
|
|
).json()) as PolygonOptionContractAggregatesResponse,
|
|
|
|
|
{ retries: 5, factor: 2, minTimeout: 1000, maxTimeout: 60 * 1000 }
|
|
|
|
|
);
|
|
|
|
|
if (latestBatchResponse.status.toLowerCase() !== "ok") {
|
|
|
|
|
console.error(latestBatchResponse);
|
|
|
|
|
throw new Error(
|
|
|
|
|
`error fetching option contract aggregate ${optionContractTicker}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
const url = `https://api.polygon.io/v2/aggs/ticker/${optionContractTicker}/range/1/minute/${asOfDate}/${asOfDate}?adjusted=false&sort=asc&limit=50000&apiKey=${await getApiKey()}`;
|
|
|
|
|
let latestBatchResponse;
|
|
|
|
|
latestBatchResponse = (await (
|
|
|
|
|
await fetch(url)
|
|
|
|
|
).json()) as PolygonOptionContractAggregatesResponse;
|
|
|
|
|
if (latestBatchResponse.status.toLowerCase() === "ok") {
|
|
|
|
|
yield latestBatchResponse.results?.map((result) => ({
|
|
|
|
|
symbol,
|
|
|
|
|
expirationDate,
|
|
|
|
@ -131,6 +122,12 @@ export async function* makeGetOptionContractAggregatesIterator({
|
|
|
|
|
low: result.l,
|
|
|
|
|
high: result.h,
|
|
|
|
|
})) || [];
|
|
|
|
|
} else if (latestBatchResponse.status === "NOT_AUTHORIZED") {
|
|
|
|
|
console.error("Skipping due to:", latestBatchResponse);
|
|
|
|
|
} else {
|
|
|
|
|
console.error(latestBatchResponse);
|
|
|
|
|
throw new Error(`error fetching option contract aggregate ${url}`);
|
|
|
|
|
}
|
|
|
|
|
currentDateAsDateObject.setUTCDate(
|
|
|
|
|
currentDateAsDateObject.getUTCDate() + 1
|
|
|
|
|
);
|
|
|
|
|