fixed up exchanges US
This commit is contained in:
parent
5ca8fafe7e
commit
f69181a8bc
6 changed files with 121 additions and 22 deletions
|
|
@ -8,12 +8,14 @@ interface FetchIntradayInput {
|
|||
interval: '1m' | '5m' | '1h';
|
||||
fromDate?: Date;
|
||||
toDate?: Date;
|
||||
country?: string;
|
||||
}
|
||||
|
||||
interface CrawlIntradayInput {
|
||||
symbol: string;
|
||||
exchange: string;
|
||||
interval: '1m' | '5m' | '1h';
|
||||
country?: string;
|
||||
}
|
||||
|
||||
interface CrawlState {
|
||||
|
|
@ -86,7 +88,8 @@ export async function scheduleIntradayCrawl(
|
|||
await this.scheduleOperation('crawl-intraday', {
|
||||
symbol: symbol.Code,
|
||||
exchange: symbol.Exchange,
|
||||
interval
|
||||
interval,
|
||||
country: symbol.Country
|
||||
}, {
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
|
|
@ -116,7 +119,7 @@ export async function crawlIntraday(
|
|||
input: CrawlIntradayInput
|
||||
): Promise<{ success: boolean; recordsProcessed: number; finished: boolean }> {
|
||||
const logger = this.logger;
|
||||
const { symbol, exchange, interval } = input;
|
||||
const { symbol, exchange, interval, country } = input;
|
||||
|
||||
try {
|
||||
logger.info(`Starting intraday crawl for ${symbol}.${exchange} - ${interval}`);
|
||||
|
|
@ -156,7 +159,8 @@ export async function crawlIntraday(
|
|||
exchange,
|
||||
interval,
|
||||
fromDate,
|
||||
toDate
|
||||
toDate,
|
||||
country
|
||||
});
|
||||
|
||||
// Update crawl state
|
||||
|
|
@ -204,7 +208,8 @@ export async function crawlIntraday(
|
|||
await this.scheduleOperation('crawl-intraday', {
|
||||
symbol,
|
||||
exchange,
|
||||
interval
|
||||
interval,
|
||||
country
|
||||
}, {
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
|
|
@ -238,7 +243,7 @@ export async function fetchIntraday(
|
|||
input: FetchIntradayInput
|
||||
): Promise<{ success: boolean; recordsSaved: number }> {
|
||||
const logger = this.logger;
|
||||
const { symbol, exchange, interval, fromDate, toDate } = input;
|
||||
const { symbol, exchange, interval, fromDate, toDate, country } = input;
|
||||
|
||||
try {
|
||||
logger.info(`Fetching intraday data for ${symbol}.${exchange} - ${interval}`, {
|
||||
|
|
@ -246,6 +251,20 @@ export async function fetchIntraday(
|
|||
to: toDate?.toISOString().split('T')[0]
|
||||
});
|
||||
|
||||
// Get country if not provided
|
||||
let symbolCountry = country;
|
||||
if (!symbolCountry) {
|
||||
const symbolDoc = await this.mongodb.collection('eodSymbols').findOne({
|
||||
Code: symbol,
|
||||
Exchange: exchange
|
||||
});
|
||||
|
||||
if (!symbolDoc) {
|
||||
throw new Error(`Symbol ${symbol}.${exchange} not found in database`);
|
||||
}
|
||||
symbolCountry = symbolDoc.Country;
|
||||
}
|
||||
|
||||
// Get API key
|
||||
const apiKey = EOD_CONFIG.API_TOKEN;
|
||||
if (!apiKey) {
|
||||
|
|
@ -253,7 +272,10 @@ export async function fetchIntraday(
|
|||
}
|
||||
|
||||
// Build URL
|
||||
const url = new URL(`https://eodhd.com/api/intraday/${symbol}.${exchange}`);
|
||||
// For US symbols (Country: "USA"), use :US suffix instead of specific exchange code
|
||||
const exchangeSuffix = symbolCountry === 'USA' ? 'US' : exchange;
|
||||
|
||||
const url = new URL(`https://eodhd.com/api/intraday/${symbol}.${exchangeSuffix}`);
|
||||
url.searchParams.append('api_token', apiKey);
|
||||
url.searchParams.append('fmt', 'json');
|
||||
url.searchParams.append('interval', interval);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue