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:
parent
381334720a
commit
0df989cc07
4 changed files with 162 additions and 123 deletions
|
|
@ -7,6 +7,13 @@ export interface ParsedTicker {
|
|||
classSuffix: string;
|
||||
}
|
||||
|
||||
export type ParseTickerFailureReason = 'invalid_ticker' | 'class_suffix_too_long';
|
||||
|
||||
export type ParseTickerDetailedResult =
|
||||
| { ok: true; tickerRoot: string; classSuffix: string }
|
||||
| { ok: false; reason: 'invalid_ticker' }
|
||||
| { ok: false; reason: 'class_suffix_too_long'; tickerRoot: string; classSuffix: string };
|
||||
|
||||
const CODE_TAB = 9;
|
||||
const CODE_SPACE = 32;
|
||||
const CODE_DASH = 45;
|
||||
|
|
@ -37,21 +44,21 @@ function findNextSeparator(str: string, start: number): number {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses a raw provider ticker into a canonical uppercase `(tickerRoot, classSuffix)` pair.
|
||||
* Parses a raw provider ticker into a canonical uppercase `(tickerRoot, classSuffix)` pair,
|
||||
* returning a structured failure reason (`invalid_ticker` or `class_suffix_too_long`) on failure.
|
||||
* Strips embedded `.TO` / `.V` venue suffixes only when `source === 'ceo'`.
|
||||
* Plain tickers return `classSuffix: ''`; empty or malformed inputs return `null`.
|
||||
*/
|
||||
export function parseTicker(
|
||||
export function parseTickerDetailed(
|
||||
raw: string | null | undefined,
|
||||
source: TickerSource
|
||||
): ParsedTicker | null {
|
||||
): ParseTickerDetailedResult {
|
||||
if (typeof raw !== 'string') {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
|
||||
let s = raw.trim().toUpperCase();
|
||||
if (s.length === 0) {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
|
||||
if (source === 'ceo') {
|
||||
|
|
@ -61,16 +68,16 @@ export function parseTicker(
|
|||
s = s.slice(0, -2).trimEnd();
|
||||
}
|
||||
if (s.length === 0) {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
}
|
||||
|
||||
const firstSep = findNextSeparator(s, 0);
|
||||
if (firstSep === -1) {
|
||||
return { tickerRoot: s, classSuffix: '' };
|
||||
return { ok: true, tickerRoot: s, classSuffix: '' };
|
||||
}
|
||||
if (firstSep === 0) {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
|
||||
const tickerRoot = s.slice(0, firstSep);
|
||||
|
|
@ -79,13 +86,16 @@ export function parseTicker(
|
|||
pos++;
|
||||
}
|
||||
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
|
||||
const secondSep = findNextSeparator(s, pos);
|
||||
if (secondSep === -1) {
|
||||
const classSuffix = s.slice(pos);
|
||||
return classSuffix.length <= MAX_CLASS_SUFFIX_LENGTH ? { tickerRoot, classSuffix } : null;
|
||||
if (classSuffix.length > MAX_CLASS_SUFFIX_LENGTH) {
|
||||
return { ok: false, reason: 'class_suffix_too_long', tickerRoot, classSuffix };
|
||||
}
|
||||
return { ok: true, tickerRoot, classSuffix };
|
||||
}
|
||||
|
||||
let classSuffix = s.slice(pos, secondSep);
|
||||
|
|
@ -96,7 +106,7 @@ export function parseTicker(
|
|||
pos++;
|
||||
}
|
||||
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
||||
return null;
|
||||
return { ok: false, reason: 'invalid_ticker' };
|
||||
}
|
||||
const nextSep = findNextSeparator(s, pos);
|
||||
if (nextSep === -1) {
|
||||
|
|
@ -108,8 +118,21 @@ export function parseTicker(
|
|||
}
|
||||
|
||||
if (classSuffix.length > MAX_CLASS_SUFFIX_LENGTH) {
|
||||
return null;
|
||||
return { ok: false, reason: 'class_suffix_too_long', tickerRoot, classSuffix };
|
||||
}
|
||||
|
||||
return { tickerRoot, classSuffix };
|
||||
return { ok: true, tickerRoot, classSuffix };
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a raw provider ticker into a canonical uppercase `(tickerRoot, classSuffix)` pair.
|
||||
* Strips embedded `.TO` / `.V` venue suffixes only when `source === 'ceo'`.
|
||||
* Plain tickers return `classSuffix: ''`; empty or malformed inputs return `null`.
|
||||
*/
|
||||
export function parseTicker(
|
||||
raw: string | null | undefined,
|
||||
source: TickerSource
|
||||
): ParsedTicker | null {
|
||||
const result = parseTickerDetailed(raw, source);
|
||||
return result.ok ? { tickerRoot: result.tickerRoot, classSuffix: result.classSuffix } : null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue