T-38: M1.1b — Pass 2 normalization: ISIN/CUSIP validators, ticker root/suffix parser, IB fields in provider-symbol.ts
This commit is contained in:
parent
5483f7f127
commit
eb8e2aa57a
4 changed files with 27 additions and 18 deletions
|
|
@ -192,6 +192,11 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
|
||||||
return { isin, source: 'isin' };
|
return { isin, source: 'isin' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isinPrefix = isin !== null && isin.length >= 2 ? isin.slice(0, 2) : null;
|
||||||
|
if (country !== null && isNorthAmericaCountry(isinPrefix) && country !== isinPrefix) {
|
||||||
|
return { isin: null, reason: 'invalid_isin_and_no_valid_cusip' };
|
||||||
|
}
|
||||||
|
|
||||||
if (cusip !== null) {
|
if (cusip !== null) {
|
||||||
if (isValidCusip(cusip)) {
|
if (isValidCusip(cusip)) {
|
||||||
if (country !== null) {
|
if (country !== null) {
|
||||||
|
|
@ -203,7 +208,6 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
|
||||||
return { isin: derived, source: 'cusip_derived' };
|
return { isin: derived, source: 'cusip_derived' };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const isinPrefix = isin !== null && isin.length >= 2 ? isin.slice(0, 2) : null;
|
|
||||||
if (!isNorthAmericaCountry(isinPrefix)) {
|
if (!isNorthAmericaCountry(isinPrefix)) {
|
||||||
return { isin: null, reason: 'unsupported_country_for_cusip' };
|
return { isin: null, reason: 'unsupported_country_for_cusip' };
|
||||||
}
|
}
|
||||||
|
|
@ -217,13 +221,10 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isin !== null && isin.length === 12) {
|
if (isin !== null && isin.length === 12 && isNorthAmericaCountry(isinPrefix)) {
|
||||||
const isinPrefix = isin.slice(0, 2);
|
const derived = cusipToIsin(isin.slice(2, 11), isinPrefix);
|
||||||
if (isNorthAmericaCountry(isinPrefix) && (country === null || country === isinPrefix)) {
|
if (derived !== null) {
|
||||||
const derived = cusipToIsin(isin.slice(2, 11), isinPrefix);
|
return { isin: derived, source: 'cusip_derived' };
|
||||||
if (derived !== null) {
|
|
||||||
return { isin: derived, source: 'cusip_derived' };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,8 @@ export function parseTicker(
|
||||||
|
|
||||||
const tickerRoot = s.slice(0, firstSep);
|
const tickerRoot = s.slice(0, firstSep);
|
||||||
let pos = firstSep + 1;
|
let pos = firstSep + 1;
|
||||||
if (isWhitespace(s.charCodeAt(firstSep))) {
|
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
|
||||||
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
|
pos++;
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -90,12 +88,9 @@ export function parseTicker(
|
||||||
let classSuffix = s.slice(pos, secondSep);
|
let classSuffix = s.slice(pos, secondSep);
|
||||||
pos = secondSep;
|
pos = secondSep;
|
||||||
while (pos < s.length) {
|
while (pos < s.length) {
|
||||||
const sepCode = s.charCodeAt(pos);
|
|
||||||
pos++;
|
pos++;
|
||||||
if (isWhitespace(sepCode)) {
|
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
|
||||||
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
|
pos++;
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -153,11 +153,19 @@ describe('resolveIsin', () => {
|
||||||
isin: null,
|
isin: null,
|
||||||
reason: 'invalid_isin_and_no_valid_cusip',
|
reason: 'invalid_isin_and_no_valid_cusip',
|
||||||
});
|
});
|
||||||
// Explicit country contradicts embedded ISIN country prefix
|
// Explicit country contradicts embedded ISIN country prefix (with or without explicit CUSIP)
|
||||||
expect(resolveIsin({ isin: 'CA7800871029', country: 'US' })).toEqual({
|
expect(resolveIsin({ isin: 'CA7800871029', country: 'US' })).toEqual({
|
||||||
isin: null,
|
isin: null,
|
||||||
reason: 'invalid_isin_and_no_valid_cusip',
|
reason: 'invalid_isin_and_no_valid_cusip',
|
||||||
});
|
});
|
||||||
|
expect(resolveIsin({ isin: 'CA7800871029', cusip: '780087102', country: 'US' })).toEqual({
|
||||||
|
isin: null,
|
||||||
|
reason: 'invalid_isin_and_no_valid_cusip',
|
||||||
|
});
|
||||||
|
expect(resolveIsin({ isin: 'US0378331009', cusip: '037833100', country: 'CA' })).toEqual({
|
||||||
|
isin: null,
|
||||||
|
reason: 'invalid_isin_and_no_valid_cusip',
|
||||||
|
});
|
||||||
expect(resolveIsin({ cusip: '037833100', country: 'GB' })).toEqual({
|
expect(resolveIsin({ cusip: '037833100', country: 'GB' })).toEqual({
|
||||||
isin: null,
|
isin: null,
|
||||||
reason: 'unsupported_country_for_cusip',
|
reason: 'unsupported_country_for_cusip',
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ describe('parseTicker', () => {
|
||||||
test('canonicalizes separator variants across all sources', () => {
|
test('canonicalizes separator variants across all sources', () => {
|
||||||
for (const source of ALL_SOURCES) {
|
for (const source of ALL_SOURCES) {
|
||||||
expect(parseTicker('AAA-P', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
expect(parseTicker('AAA-P', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
||||||
|
expect(parseTicker('AAA- P', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
||||||
|
expect(parseTicker('AAA.\tP', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
||||||
expect(parseTicker('AAA.P', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
expect(parseTicker('AAA.P', source)).toEqual({ tickerRoot: 'AAA', classSuffix: 'P' });
|
||||||
expect(parseTicker('AACT U', source)).toEqual({ tickerRoot: 'AACT', classSuffix: 'U' });
|
expect(parseTicker('AACT U', source)).toEqual({ tickerRoot: 'AACT', classSuffix: 'U' });
|
||||||
expect(parseTicker('AACT U', source)).toEqual({ tickerRoot: 'AACT', classSuffix: 'U' });
|
expect(parseTicker('AACT U', source)).toEqual({ tickerRoot: 'AACT', classSuffix: 'U' });
|
||||||
|
|
@ -22,6 +24,7 @@ describe('parseTicker', () => {
|
||||||
expect(parseTicker('SCU.UN', source)).toEqual({ tickerRoot: 'SCU', classSuffix: 'UN' });
|
expect(parseTicker('SCU.UN', source)).toEqual({ tickerRoot: 'SCU', classSuffix: 'UN' });
|
||||||
expect(parseTicker('RY.PR.A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
expect(parseTicker('RY.PR.A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
||||||
expect(parseTicker('RY-PR-A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
expect(parseTicker('RY-PR-A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
||||||
|
expect(parseTicker('RY- PR- A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
||||||
expect(parseTicker('RY PR A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
expect(parseTicker('RY PR A', source)).toEqual({ tickerRoot: 'RY', classSuffix: 'PR.A' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -58,8 +61,10 @@ describe('parseTicker', () => {
|
||||||
'AAPL-',
|
'AAPL-',
|
||||||
'A..B',
|
'A..B',
|
||||||
'A--B',
|
'A--B',
|
||||||
|
'AAA- -P',
|
||||||
'RY.PR.',
|
'RY.PR.',
|
||||||
'RY-PR--A',
|
'RY-PR--A',
|
||||||
|
'RY-PR- -A',
|
||||||
null,
|
null,
|
||||||
undefined,
|
undefined,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue