T-56: M1.1f — Pass 3 Stage B: pure in-memory listing matcher (EOD venue → listing, IB conid at (instrument, currency), QM/CEO ticker+span Tier 3)

This commit is contained in:
Studio 2026-11-27 16:50:47 -05:00 • committed by Boki
parent 381334720a
commit 0df989cc07
4 changed files with 162 additions and 123 deletions

View file

@ -5,6 +5,7 @@ import {
} from '../../apps/stock/data-pipeline/src/normalization/identifiers';
import {
parseTicker,
parseTickerDetailed,
type TickerSource,
} from '../../apps/stock/data-pipeline/src/normalization/ticker';
@ -86,6 +87,23 @@ describe('parseTicker', () => {
});
expect(parseTicker('RY.ABCDEFGHIJKLM', 'eod')).toBeNull();
expect(parseTicker('RY.PR.ABCDEFGHIJ', 'eod')).toBeNull();
expect(parseTickerDetailed('RY.ABCDEFGHIJKLM', 'eod')).toEqual({
ok: false,
reason: 'class_suffix_too_long',
tickerRoot: 'RY',
classSuffix: 'ABCDEFGHIJKLM',
});
expect(parseTickerDetailed('RY.PR.ABCDEFGHIJ.TO', 'ceo')).toEqual({
ok: false,
reason: 'class_suffix_too_long',
tickerRoot: 'RY',
classSuffix: 'PR.ABCDEFGHIJ',
});
expect(parseTickerDetailed('RY..A', 'eod')).toEqual({
ok: false,
reason: 'invalid_ticker',
});
});
test('completes 100,000 resolveIsin + parseTicker calls in under 500 ms', () => {

View file

@ -864,6 +864,94 @@ describe('security master Pass 3 Stage B listing matcher', () => {
expect(() => matchListingsStageB(baseInput, { spanOverlapToleranceDays: 1.5 })).toThrow(RangeError);
});
test('rejects timestamp-shaped and padded spans as invalid_span instead of shifting across UTC day boundaries', () => {
const result = matchListingsStageB({
instruments: [
{
primaryIsin: 'US0000000026',
primaryCusip: null,
issuerCountry: 'US',
canonicalName: 'FB Reused Listing',
members: [
{ source: 'eod', sourceId: 'FB_NEW.US', currency: 'USD', method: 'tier1_isin' },
{ source: 'eod', sourceId: 'FB_TS_EOD.US', currency: 'USD', method: 'tier1_isin' },
],
},
],
eodListings: [
{
sourceId: 'FB_NEW.US',
ticker: 'FB',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2025-01-02', lastBarDate: '2025-11-26' },
},
{
sourceId: 'FB_TS_EOD.US',
ticker: 'FBTS',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: {
firstBarDate: '2025-01-01T23:30:00-05:00',
lastBarDate: '2025-01-02T00:00:00Z',
},
},
],
ibContracts: [],
tickerSources: [
// Timezone offset would shift 2025-01-01T23:30:00-05:00 -> 2025-01-02 UTC and falsely match FB_NEW.US.
{
source: 'qm',
sourceId: 'QM_TZ_SHIFT',
ticker: 'FB',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: {
firstBarDate: '2025-01-01T23:30:00-05:00',
lastBarDate: '2025-01-01T23:30:00-05:00',
},
},
{
source: 'qm',
sourceId: 'QM_UTC_TS',
ticker: 'FB',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: {
firstBarDate: '2025-01-02T00:00:00Z',
lastBarDate: '2025-01-02T00:00:00Z',
},
},
{
source: 'qm',
sourceId: 'QM_PADDED_YMD',
ticker: 'FB',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: {
firstBarDate: ' 2025-01-02 ',
lastBarDate: '2025-01-03',
},
},
],
});
expect(result.listings).toHaveLength(1);
expect(result.providerMappings.filter(m => m.source === 'qm')).toEqual([]);
expect(result.unresolved).toEqual([
{ source: 'eod', sourceId: 'FB_TS_EOD.US', reason: 'invalid_span', primaryIsin: 'US0000000026' },
{ source: 'qm', sourceId: 'QM_PADDED_YMD', reason: 'invalid_span', primaryIsin: null },
{ source: 'qm', sourceId: 'QM_TZ_SHIFT', reason: 'invalid_span', primaryIsin: null },
{ source: 'qm', sourceId: 'QM_UTC_TS', reason: 'invalid_span', primaryIsin: null },
]);
assertReconciliationAndContracts(result);
});
test('enforces ticker/classSuffix/currency bounds and does not mask explicitly invalid eod.currency', () => {
const root25 = 'A'.repeat(MAX_TICKER_ROOT_LENGTH + 1);
const suffix13 = 'B'.repeat(MAX_CLASS_SUFFIX_LENGTH + 1);