stock-bot/apps/stock/data-pipeline/src/normalization/provider-symbol.ts

50 lines
1.7 KiB
TypeScript

/** Fields retained by the QM, EOD and IB symbol collections, including older spellings. */
export interface ProviderSymbolDocument {
symbol?: string | null;
code?: string | null;
Code?: string | null;
exchangeCode?: string | null;
exchange?: string | null;
exchange_id?: string | null;
Exchange?: string | null;
companyName?: string | null;
name?: string | null;
company_name?: string | null;
Name?: string | null;
countryCode?: string | null;
country_code?: string | null;
Country?: string | null;
currency?: string | null;
Currency?: string | null;
qmSearchCode?: string | null;
eodSearchCode?: string | null;
}
/** Provider codes stay exact: exchange resolution and curated mappings belong to SQL. */
export interface ProviderSymbol {
symbol: string;
exchangeCode: string;
providerSymbol: string;
companyName: string | null;
country: string | null;
currency: string | null;
}
/** Preserve the existing field precedence without guessing suffixes or exchange aliases. */
export function normalizeProviderSymbol(document: ProviderSymbolDocument): ProviderSymbol | null {
const symbol = document.symbol || document.code || document.Code;
const exchangeCode =
document.exchangeCode || document.exchange || document.exchange_id || document.Exchange;
if (!symbol || !exchangeCode) {
return null;
}
return {
symbol,
exchangeCode,
providerSymbol: document.qmSearchCode || document.eodSearchCode || symbol,
companyName:
document.companyName || document.name || document.company_name || document.Name || null,
country: document.countryCode || document.country_code || document.Country || null,
currency: document.currency || document.Currency || null,
};
}