fixed up exchanges US
This commit is contained in:
parent
5ca8fafe7e
commit
f69181a8bc
6 changed files with 121 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ import { EOD_CONFIG } from '../shared';
|
|||
interface FetchPricesInput {
|
||||
symbol: string;
|
||||
exchange: string;
|
||||
country?: string; // Optional to maintain backward compatibility
|
||||
}
|
||||
|
||||
export async function scheduleFetchPrices(
|
||||
|
|
@ -55,7 +56,8 @@ export async function scheduleFetchPrices(
|
|||
|
||||
await this.scheduleOperation('fetch-prices', {
|
||||
symbol: symbol.Code,
|
||||
exchange: symbol.Exchange
|
||||
exchange: symbol.Exchange,
|
||||
country: symbol.Country
|
||||
}, {
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
|
|
@ -84,11 +86,25 @@ export async function fetchPrices(
|
|||
input: FetchPricesInput
|
||||
): Promise<{ success: boolean; priceCount: number }> {
|
||||
const logger = this.logger;
|
||||
const { symbol, exchange } = input;
|
||||
const { symbol, exchange, country } = input;
|
||||
|
||||
try {
|
||||
logger.info(`Fetching prices for ${symbol}.${exchange}`);
|
||||
|
||||
// Use provided country or fetch from database
|
||||
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 from config
|
||||
const apiKey = EOD_CONFIG.API_TOKEN;
|
||||
if (!apiKey) {
|
||||
|
|
@ -96,7 +112,10 @@ export async function fetchPrices(
|
|||
}
|
||||
|
||||
// Build URL for EOD price data
|
||||
const url = new URL(`https://eodhd.com/api/eod/${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/eod/${symbol}.${exchangeSuffix}`);
|
||||
url.searchParams.append('api_token', apiKey);
|
||||
url.searchParams.append('fmt', 'json');
|
||||
// Fetch price data from EOD API
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue