T-86: M1.1k — Read-only Mongo source-symbol readers: eodSymbols / ibSymbols / qmSymbols / ceoSymbols / eodSymbolChange → Stage A + Stage B input records (no new dependencies)
This commit is contained in:
parent
cadc3d1b6d
commit
2888dfb136
3 changed files with 226 additions and 51 deletions
|
|
@ -301,10 +301,11 @@ export const REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS: readonly ExchangeSourceMap
|
|||
{ source: 'eod' as const, sourceCode: 'PINK', role: 'primary_venue' as const, mic: 'OTCM', countryIso: 'US' },
|
||||
{ source: 'eod' as const, sourceCode: 'TO', role: 'primary_venue' as const, mic: 'XTSE', countryIso: 'CA' },
|
||||
{ source: 'eod' as const, sourceCode: 'V', role: 'primary_venue' as const, mic: 'XTSX', countryIso: 'CA' },
|
||||
// IB US + CA primary venues (ATS/routing venues live in EXPLICIT_EXCHANGE_SOURCE_RULES)
|
||||
// IB US + CA venues (additional ATS/routing venues live in EXPLICIT_EXCHANGE_SOURCE_RULES)
|
||||
{ source: 'ib' as const, sourceCode: 'AMEX', role: 'primary_venue' as const, mic: 'XASE', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'ARCA', role: 'primary_venue' as const, mic: 'ARCX', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'BATS', role: 'primary_venue' as const, mic: 'BATS', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'EDGX', role: 'ats_routing' as const, mic: null, countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'ISLAND', role: 'primary_venue' as const, mic: 'XNAS', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'NASDAQ', role: 'primary_venue' as const, mic: 'XNAS', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'NEO', role: 'primary_venue' as const, mic: 'NEOE', countryIso: 'CA' },
|
||||
|
|
@ -314,7 +315,7 @@ export const REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS: readonly ExchangeSourceMap
|
|||
{ source: 'ib' as const, sourceCode: 'TSE', role: 'primary_venue' as const, mic: 'XTSE', countryIso: 'CA' },
|
||||
{ source: 'ib' as const, sourceCode: 'VALUE', role: 'primary_venue' as const, mic: 'OTCM', countryIso: 'US' },
|
||||
{ source: 'ib' as const, sourceCode: 'VENTURE', role: 'primary_venue' as const, mic: 'XTSX', countryIso: 'CA' },
|
||||
// QuoteMedia US + CA primary venues (qmExchanges has 0% OperatingMIC)
|
||||
// QuoteMedia US + CA venues (qmExchanges has 0% OperatingMIC)
|
||||
{ source: 'qm' as const, sourceCode: 'AMEX', role: 'primary_venue' as const, mic: 'XASE', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'AQL', role: 'primary_venue' as const, mic: 'NEOE', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'ARC', role: 'primary_venue' as const, mic: 'ARCX', countryIso: 'US' },
|
||||
|
|
@ -324,11 +325,16 @@ export const REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS: readonly ExchangeSourceMap
|
|||
{ source: 'qm' as const, sourceCode: 'BTS', role: 'primary_venue' as const, mic: 'BATS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'BZX', role: 'primary_venue' as const, mic: 'BATS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'CC', role: 'primary_venue' as const, mic: 'XCNQ', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CCQ TSX', role: 'composite' as const, mic: null, countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CCQ TSXV', role: 'composite' as const, mic: null, countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CDX', role: 'primary_venue' as const, mic: 'XTSX', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CNQ', role: 'primary_venue' as const, mic: 'XCNQ', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CNX', role: 'primary_venue' as const, mic: 'XCNQ', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CSE', role: 'primary_venue' as const, mic: 'XCNQ', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'CVE', role: 'primary_venue' as const, mic: 'XTSX', countryIso: 'CA' },
|
||||
{ source: 'qm' as const, sourceCode: 'EDGA', role: 'ats_routing' as const, mic: null, countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'EDGX', role: 'ats_routing' as const, mic: null, countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'EGX', role: 'ats_routing' as const, mic: null, countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'IEX', role: 'primary_venue' as const, mic: 'IEXG', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NASDAQ', role: 'primary_venue' as const, mic: 'XNAS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NCM', role: 'primary_venue' as const, mic: 'XNAS', countryIso: 'US' },
|
||||
|
|
@ -341,6 +347,7 @@ export const REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS: readonly ExchangeSourceMap
|
|||
{ source: 'qm' as const, sourceCode: 'NYE', role: 'primary_venue' as const, mic: 'XNYS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NYS', role: 'primary_venue' as const, mic: 'XNYS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NYSE', role: 'primary_venue' as const, mic: 'XNYS', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NYSE AMERICAN', role: 'primary_venue' as const, mic: 'XASE', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'NYSEMKT', role: 'primary_venue' as const, mic: 'XASE', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'OBB', role: 'primary_venue' as const, mic: 'OTCM', countryIso: 'US' },
|
||||
{ source: 'qm' as const, sourceCode: 'OTC', role: 'primary_venue' as const, mic: 'OTCM', countryIso: 'US' },
|
||||
|
|
|
|||
|
|
@ -263,7 +263,6 @@ export interface SecurityMasterSourcesResult {
|
|||
}
|
||||
|
||||
const ISO2_PATTERN = /^[A-Z]{2}$/;
|
||||
const DEFAULT_CEO_CA_CODES: readonly string[] = Object.freeze(['AQL', 'CDX', 'CNQ', 'TSX']);
|
||||
|
||||
const COUNTRY_ISO2_ALIASES: Readonly<Record<string, readonly string[]>> = Object.freeze({
|
||||
US: Object.freeze(['US', 'USA', 'U.S.', 'U.S.A.', 'United States', 'United States of America']),
|
||||
|
|
@ -842,16 +841,20 @@ function buildEodCountryFilter(
|
|||
return {};
|
||||
}
|
||||
const countryValues = expandCountryFilterValues(countries);
|
||||
const exchangeCodes =
|
||||
typeof exchangeLookup.getCodesForCountries === 'function'
|
||||
? exchangeLookup.getCodesForCountries('eod', countries)
|
||||
: [];
|
||||
|
||||
const clauses: Record<string, unknown>[] = [];
|
||||
if (countryValues.length > 0) {
|
||||
clauses.push({ Country: { $in: countryValues } });
|
||||
clauses.push({ countryCode: { $in: countryValues } });
|
||||
if (countryValues.length === 0) {
|
||||
return { ...EMPTY_MATCH_FILTER };
|
||||
}
|
||||
// When the lookup cannot enumerate in-scope venue codes, keep the query conservative
|
||||
// so countryless documents that derive country from Exchange are not dropped before the adapter.
|
||||
if (typeof exchangeLookup.getCodesForCountries !== 'function') {
|
||||
return {};
|
||||
}
|
||||
const exchangeCodes = exchangeLookup.getCodesForCountries('eod', countries);
|
||||
|
||||
const clauses: Record<string, unknown>[] = [
|
||||
{ Country: { $in: countryValues } },
|
||||
{ countryCode: { $in: countryValues } },
|
||||
];
|
||||
if (exchangeCodes.length > 0) {
|
||||
clauses.push({ Exchange: { $in: exchangeCodes } });
|
||||
clauses.push({ exchange: { $in: exchangeCodes } });
|
||||
|
|
@ -882,16 +885,18 @@ function buildQmCountryFilter(
|
|||
return {};
|
||||
}
|
||||
const countryValues = expandCountryFilterValues(countries);
|
||||
const exchangeCodes =
|
||||
typeof exchangeLookup.getCodesForCountries === 'function'
|
||||
? exchangeLookup.getCodesForCountries('qm', countries)
|
||||
: [];
|
||||
|
||||
const clauses: Record<string, unknown>[] = [];
|
||||
if (countryValues.length > 0) {
|
||||
clauses.push({ countryCode: { $in: countryValues } });
|
||||
clauses.push({ country: { $in: countryValues } });
|
||||
if (countryValues.length === 0) {
|
||||
return { ...EMPTY_MATCH_FILTER };
|
||||
}
|
||||
if (typeof exchangeLookup.getCodesForCountries !== 'function') {
|
||||
return {};
|
||||
}
|
||||
const exchangeCodes = exchangeLookup.getCodesForCountries('qm', countries);
|
||||
|
||||
const clauses: Record<string, unknown>[] = [
|
||||
{ countryCode: { $in: countryValues } },
|
||||
{ country: { $in: countryValues } },
|
||||
];
|
||||
if (exchangeCodes.length > 0) {
|
||||
clauses.push({ exchange: { $in: exchangeCodes } });
|
||||
clauses.push({ exchangeCode: { $in: exchangeCodes } });
|
||||
|
|
@ -907,18 +912,18 @@ function buildCeoCountryFilter(
|
|||
return {};
|
||||
}
|
||||
const countryValues = expandCountryFilterValues(countries);
|
||||
const exchangeCodes =
|
||||
typeof exchangeLookup.getCodesForCountries === 'function'
|
||||
? exchangeLookup.getCodesForCountries('ceo', countries)
|
||||
: countries.includes('CA')
|
||||
? [...DEFAULT_CEO_CA_CODES]
|
||||
: [];
|
||||
|
||||
const clauses: Record<string, unknown>[] = [];
|
||||
if (countryValues.length > 0) {
|
||||
clauses.push({ countryCode: { $in: countryValues } });
|
||||
clauses.push({ country: { $in: countryValues } });
|
||||
if (countryValues.length === 0) {
|
||||
return { ...EMPTY_MATCH_FILTER };
|
||||
}
|
||||
if (typeof exchangeLookup.getCodesForCountries !== 'function') {
|
||||
return {};
|
||||
}
|
||||
const exchangeCodes = exchangeLookup.getCodesForCountries('ceo', countries);
|
||||
|
||||
const clauses: Record<string, unknown>[] = [
|
||||
{ countryCode: { $in: countryValues } },
|
||||
{ country: { $in: countryValues } },
|
||||
];
|
||||
if (exchangeCodes.length > 0) {
|
||||
clauses.push({ exchange: { $in: exchangeCodes } });
|
||||
clauses.push({ exchangeCode: { $in: exchangeCodes } });
|
||||
|
|
@ -934,16 +939,18 @@ function buildEodSymbolChangeFilter(
|
|||
return {};
|
||||
}
|
||||
const countryValues = expandCountryFilterValues(countries);
|
||||
const exchangeCodes =
|
||||
typeof exchangeLookup.getCodesForCountries === 'function'
|
||||
? exchangeLookup.getCodesForCountries('eod', countries)
|
||||
: [];
|
||||
|
||||
const clauses: Record<string, unknown>[] = [];
|
||||
if (countryValues.length > 0) {
|
||||
clauses.push({ country: { $in: countryValues } });
|
||||
clauses.push({ Country: { $in: countryValues } });
|
||||
if (countryValues.length === 0) {
|
||||
return { ...EMPTY_MATCH_FILTER };
|
||||
}
|
||||
if (typeof exchangeLookup.getCodesForCountries !== 'function') {
|
||||
return {};
|
||||
}
|
||||
const exchangeCodes = exchangeLookup.getCodesForCountries('eod', countries);
|
||||
|
||||
const clauses: Record<string, unknown>[] = [
|
||||
{ country: { $in: countryValues } },
|
||||
{ Country: { $in: countryValues } },
|
||||
];
|
||||
if (exchangeCodes.length > 0) {
|
||||
clauses.push({ exchange: { $in: exchangeCodes } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,12 +219,14 @@ function createPass1ExchangeLookup(extraRows: readonly ExchangeSourceMapRow[] =
|
|||
// qmExchanges (0% OperatingMIC in QA MongoDB per phase1-investigation.md)
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'NSQ', exchangeName: 'NASDAQ', countryCode: 'US' }),
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'NYE', exchangeName: 'NYSE', countryCode: 'US' }),
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'EDGX', exchangeName: 'Cboe EDGX', countryCode: 'US' }),
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'TSE', exchangeName: 'TSX', countryCode: 'CA' }),
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'CNX', exchangeName: 'CSE', countryCode: 'CA' }),
|
||||
normalizeRawExchangeDoc('qm', { exchange: 'CC', exchangeName: 'CSE Legacy', countryCode: 'CA' }),
|
||||
// ibExchanges (0% OperatingMIC in QA MongoDB)
|
||||
normalizeRawExchangeDoc('ib', { id: 'AEQLIT', name: 'Aequitas NEO', country_code: 'CA' }),
|
||||
normalizeRawExchangeDoc('ib', { id: 'OTCLNKECN', name: 'OTC Link ECN', country_code: 'US' }),
|
||||
normalizeRawExchangeDoc('ib', { id: 'EDGX', name: 'Cboe EDGX', country_code: 'US' }),
|
||||
normalizeRawExchangeDoc('ib', { id: 'NYSE', name: 'NYSE', country_code: 'US' }),
|
||||
// ceoExchanges
|
||||
normalizeRawExchangeDoc('ceo', { exchange: 'TSX', countryCode: 'CA' }),
|
||||
|
|
@ -497,19 +499,33 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect(errorCursorClosed).toBe(true);
|
||||
});
|
||||
|
||||
test('Pass 1 lookup coverage: reviewed US+CA venue rules are valid and Pass 1 path resolves NASDAQ, NYSE, and both VOY records', async () => {
|
||||
test('Pass 1 lookup coverage: reviewed US+CA venue rules are valid and Pass 1 path resolves NASDAQ, NYSE, both VOY records, and QM EDGX (AACT.U:EGX)', async () => {
|
||||
// Structural integrity of REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS:
|
||||
// every MIC is in ISO_EXCHANGE_SEEDS with matching countryIso and zero collisions with explicit baseline.
|
||||
// sorted by (source, sourceCode), zero collisions with explicit baseline,
|
||||
// primary_venue rows reference ISO_EXCHANGE_SEEDS with matching countryIso,
|
||||
// and ats_routing/composite rows carry mic: null with US/CA countryIso.
|
||||
const seedByMic = new Map(ISO_EXCHANGE_SEEDS.map(row => [row.mic, row]));
|
||||
const explicitKeys = new Set(
|
||||
EXPLICIT_EXCHANGE_SOURCE_MAP_ROWS.map(row => `${row.source}:${row.sourceCode}`)
|
||||
);
|
||||
for (const row of REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS) {
|
||||
for (let i = 0; i < REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS.length; i++) {
|
||||
const row = REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS[i]!;
|
||||
expect(explicitKeys.has(`${row.source}:${row.sourceCode}`)).toBe(false);
|
||||
expect(row.mic).not.toBeNull();
|
||||
const seed = seedByMic.get(row.mic!);
|
||||
expect(seed).toBeDefined();
|
||||
expect(row.countryIso).toBe(seed?.countryIso);
|
||||
if (i > 0) {
|
||||
const prev = REVIEWED_US_CA_EXCHANGE_SOURCE_MAP_ROWS[i - 1]!;
|
||||
const cmp =
|
||||
compareAscii(prev.source, row.source) || compareAscii(prev.sourceCode, row.sourceCode);
|
||||
expect(cmp).toBeLessThan(0);
|
||||
}
|
||||
if (row.role === 'primary_venue') {
|
||||
expect(row.mic).not.toBeNull();
|
||||
const seed = seedByMic.get(row.mic!);
|
||||
expect(seed).toBeDefined();
|
||||
expect(row.countryIso).toBe(seed?.countryIso);
|
||||
} else {
|
||||
expect(row.mic).toBeNull();
|
||||
expect(['US', 'CA']).toContain(row.countryIso);
|
||||
}
|
||||
expect(row.reviewedBy).toBe('reviewed_us_ca_venues');
|
||||
}
|
||||
|
||||
|
|
@ -519,6 +535,31 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect(exchangeLookup.get('eod', 'NYSE')?.mic).toBe('XNYS');
|
||||
expect(exchangeLookup.get('qm', 'CNX')?.mic).toBe('XCNQ');
|
||||
expect(exchangeLookup.get('qm', 'CC')?.mic).toBe('XCNQ');
|
||||
expect(exchangeLookup.get('qm', 'EDGX')).toMatchObject({
|
||||
role: 'ats_routing',
|
||||
mic: null,
|
||||
countryIso: 'US',
|
||||
});
|
||||
expect(exchangeLookup.get('ib', 'EDGX')).toMatchObject({
|
||||
role: 'ats_routing',
|
||||
mic: null,
|
||||
countryIso: 'US',
|
||||
});
|
||||
expect(exchangeLookup.get('qm', 'NYSE American')).toMatchObject({
|
||||
role: 'primary_venue',
|
||||
mic: 'XASE',
|
||||
countryIso: 'US',
|
||||
});
|
||||
expect(exchangeLookup.get('qm', 'CCQ TSX')).toMatchObject({
|
||||
role: 'composite',
|
||||
mic: null,
|
||||
countryIso: 'CA',
|
||||
});
|
||||
expect(exchangeLookup.get('qm', 'CCQ TSXV')).toMatchObject({
|
||||
role: 'composite',
|
||||
mic: null,
|
||||
countryIso: 'CA',
|
||||
});
|
||||
|
||||
const barSpans = new BarSpanIndex();
|
||||
barSpans.merge({ source: 'eod', sourceId: 'AAPL.US', firstBarDate: '2010-01-04', lastBarDate: '2025-06-30', barCount: 3900 });
|
||||
|
|
@ -526,6 +567,7 @@ describe('security-master source-symbol-readers', () => {
|
|||
barSpans.merge({ source: 'qm', sourceId: 'AAPL:US', firstBarDate: '2010-01-04', lastBarDate: '2025-06-30', barCount: 3900 });
|
||||
barSpans.merge({ source: 'qm', sourceId: 'VOY:CNX', firstBarDate: '2022-01-03', lastBarDate: '2025-01-03', barCount: 750 });
|
||||
barSpans.merge({ source: 'qm', sourceId: 'VOY:CC', firstBarDate: '2020-01-03', lastBarDate: '2021-12-31', barCount: 500 });
|
||||
barSpans.merge({ source: 'qm', sourceId: 'AACT.U:EGX', firstBarDate: '2023-05-01', lastBarDate: '2025-06-30', barCount: 540 });
|
||||
|
||||
const reader = new FakeSourceSymbolReader(
|
||||
{
|
||||
|
|
@ -551,11 +593,25 @@ describe('security-master source-symbol-readers', () => {
|
|||
Name: 'Voyager Digital Ltd.',
|
||||
},
|
||||
],
|
||||
ibSymbols: [],
|
||||
ibSymbols: [
|
||||
// Captured phase1-investigation.md:261 shape: SLB with exchangeId='EDGX' (ATS venue)
|
||||
{
|
||||
conid: 880001,
|
||||
symbol: 'SLB',
|
||||
localSymbol: 'SLB',
|
||||
exchangeId: 'EDGX',
|
||||
isin: 'AN8068571086',
|
||||
cusip: '806857108',
|
||||
country: 'US',
|
||||
currency: 'USD',
|
||||
},
|
||||
],
|
||||
qmSymbols: [
|
||||
{ qmSearchCode: 'AAPL:US', symbol: 'AAPL', exchange: 'NSQ', countryCode: 'US', active: true },
|
||||
{ qmSearchCode: 'VOY:CNX', symbol: 'VOY', exchange: 'CNX', countryCode: 'CA', active: true },
|
||||
{ qmSearchCode: 'VOY:CC', symbol: 'VOY', exchange: 'CC', countryCode: 'CA', active: false },
|
||||
// Captured phase1-investigation.md:272 shape: AACT.U:EGX with exchange='EDGX', countryCode='US'
|
||||
{ qmSearchCode: 'AACT.U:EGX', symbol: 'AACT.U', exchange: 'EDGX', countryCode: 'US', active: true },
|
||||
],
|
||||
ceoSymbols: [],
|
||||
eodSymbolChange: [],
|
||||
|
|
@ -565,12 +621,38 @@ describe('security-master source-symbol-readers', () => {
|
|||
|
||||
const sources = await readSecurityMasterSources(reader, { exchangeLookup, barSpans });
|
||||
expect(sources.stats.eodSymbols.emitted).toBe(2);
|
||||
expect(sources.stats.qmSymbols.emitted).toBe(3);
|
||||
expect(sources.stats.qmSymbols.emitted).toBe(4);
|
||||
expect(sources.stats.qmSymbols.skips.unmappedExchange).toBe(0);
|
||||
assertStatsConservation(sources.stats.qmSymbols);
|
||||
|
||||
// IB EDGX ATS must not become primaryExchange.
|
||||
expect(sources.stageBInput.ibContracts).toEqual([
|
||||
{ sourceId: '880001', conid: 880001, currency: 'USD', primaryExchange: null },
|
||||
]);
|
||||
|
||||
// AACT.U:EGX reaches Stage B classified as ats_routing (not dropped as unmappedExchange).
|
||||
const aactQm = sources.stageBInput.tickerSources.find(
|
||||
t => t.source === 'qm' && t.sourceId === 'AACT.U:EGX'
|
||||
);
|
||||
expect(aactQm).toMatchObject({
|
||||
source: 'qm',
|
||||
sourceId: 'AACT.U:EGX',
|
||||
ticker: 'AACT.U',
|
||||
mic: null,
|
||||
role: 'ats_routing',
|
||||
currency: 'USD',
|
||||
});
|
||||
|
||||
const stageA = matchInstrumentsStageA(sources.stageARecords);
|
||||
const stageB = matchListingsStageB({ instruments: stageA.instruments, ...sources.stageBInput });
|
||||
expect(stageB.conflicts).toEqual([]);
|
||||
expect(stageB.unresolved).toEqual([]);
|
||||
expect(
|
||||
stageB.unresolved.find(u => u.source === 'qm' && u.sourceId === 'AACT.U:EGX')
|
||||
).toMatchObject({
|
||||
source: 'qm',
|
||||
sourceId: 'AACT.U:EGX',
|
||||
reason: 'ats_routing_venue',
|
||||
});
|
||||
|
||||
const qmMappedIds = stageB.providerMappings
|
||||
.filter(m => m.source === 'qm')
|
||||
|
|
@ -914,6 +996,85 @@ describe('security-master source-symbol-readers', () => {
|
|||
});
|
||||
expect(emptyResult.stats.eodSymbols.docsRead).toBe(0);
|
||||
expect(emptyResult.stats.ibSymbols.docsRead).toBe(0);
|
||||
|
||||
// Regression: a supported `get`-only ExchangeSourceLookup (without getCodesForCountries)
|
||||
// must use conservative `{}` pushdown so countryless docs (notably stored-shape US
|
||||
// eodSymbolChange with exchange='US' and effective, no country field) are not dropped
|
||||
// before the adapter enforces the country filter.
|
||||
const getOnlyLookup: ExchangeSourceLookup = {
|
||||
get: (source, sourceCode) => germanLookup.get(source, sourceCode),
|
||||
};
|
||||
const getOnlyReader = new FakeSourceSymbolReader(
|
||||
{
|
||||
eodSymbols: [
|
||||
{
|
||||
_id: 'eod-noloc-us',
|
||||
eodSearchCode: 'AAPL.US',
|
||||
Code: 'AAPL',
|
||||
Exchange: 'NASDAQ',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Name: 'Apple Inc.',
|
||||
},
|
||||
{
|
||||
_id: 'eod-noloc-de',
|
||||
eodSearchCode: 'SVQ.F',
|
||||
Code: 'SVQ',
|
||||
Exchange: 'F',
|
||||
Currency: 'EUR',
|
||||
Isin: 'DE0007164600',
|
||||
Name: 'SAP SE',
|
||||
},
|
||||
],
|
||||
ibSymbols: [],
|
||||
qmSymbols: [
|
||||
{ _id: 'qm-noloc-us', qmSearchCode: 'AAPL:US', symbol: 'AAPL', exchange: 'NSQ' },
|
||||
{ _id: 'qm-noloc-de', qmSearchCode: 'SAP:FRA', symbol: 'SAP', exchange: 'FRA' },
|
||||
],
|
||||
ceoSymbols: [
|
||||
{ _id: 'ceo-noloc-ca', ceoId: 'RY', symbol: 'RY.TO', exchange: 'TSX' },
|
||||
],
|
||||
eodSymbolChange: [
|
||||
{ _id: 'sc-us-stored', oldSymbol: 'FB', newSymbol: 'META', exchange: 'US', effective: '2022-06-09' },
|
||||
{ _id: 'sc-de-stored', oldSymbol: 'OLDDE', newSymbol: 'NEWDE', exchange: 'F', effective: '2024-09-01' },
|
||||
],
|
||||
},
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
|
||||
const getOnlyResult = await readSecurityMasterSources(getOnlyReader, {
|
||||
exchangeLookup: getOnlyLookup,
|
||||
});
|
||||
|
||||
// Conservative `{}` filter used for venue-fallback collections when getCodesForCountries is absent.
|
||||
const recordedByCollection = new Map(getOnlyReader.calls.map(c => [c.collectionName, c.filter]));
|
||||
expect(recordedByCollection.get('eodSymbols')).toEqual({});
|
||||
expect(recordedByCollection.get('qmSymbols')).toEqual({});
|
||||
expect(recordedByCollection.get('ceoSymbols')).toEqual({});
|
||||
expect(recordedByCollection.get('eodSymbolChange')).toEqual({});
|
||||
|
||||
// Stored-shape countryless US symbol change survives; out-of-scope German change is counted by adapter.
|
||||
expect(getOnlyResult.stats.eodSymbolChange.docsRead).toBe(2);
|
||||
expect(getOnlyResult.stats.eodSymbolChange.emitted).toBe(1);
|
||||
expect(getOnlyResult.stats.eodSymbolChange.skips.outOfScopeCountry).toBe(1);
|
||||
expect(getOnlyResult.stageBInput.symbolChanges).toEqual([
|
||||
{
|
||||
eodSourceId: 'META.US',
|
||||
oldTicker: 'FB',
|
||||
effectiveDate: '2022-06-09',
|
||||
},
|
||||
]);
|
||||
assertStatsConservation(getOnlyResult.stats.eodSymbolChange);
|
||||
|
||||
// Countryless US/CA EOD, QM, and CEO rows also survive; German rows skipped by adapter.
|
||||
expect(getOnlyResult.stats.eodSymbols.emitted).toBe(1);
|
||||
expect(getOnlyResult.stats.eodSymbols.skips.outOfScopeCountry).toBe(1);
|
||||
expect(getOnlyResult.stats.qmSymbols.emitted).toBe(1);
|
||||
expect(getOnlyResult.stats.qmSymbols.skips.outOfScopeCountry).toBe(1);
|
||||
expect(getOnlyResult.stats.ceoSymbols.emitted).toBe(1);
|
||||
assertStatsConservation(getOnlyResult.stats.eodSymbols);
|
||||
assertStatsConservation(getOnlyResult.stats.qmSymbols);
|
||||
assertStatsConservation(getOnlyResult.stats.ceoSymbols);
|
||||
});
|
||||
|
||||
test('edge cases: NMFQS exclusion, delisted preservation, IB ATS handling, CEO .TO/.V & double-strip guard, QM duplicates, invalid ISIN/CUSIP recovery', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue