Fix contract resolver: prefer rolled contract on equal volume
Changes > to >= so when both contracts have 0 volume (e.g. off-hours), the further-out standard month wins. Fixes SI resolving to SIJ (April, non-standard) instead of SIK (May, standard delivery month). Also fixes SI/SIL prefix collision by requiring month+digit after symbol. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
f112118090
commit
c99f6843a7
@@ -116,7 +116,12 @@ export async function resolveContracts(
|
|||||||
{ headers }
|
{ headers }
|
||||||
);
|
);
|
||||||
const contracts: ContractInfo[] = res.data ?? [];
|
const contracts: ContractInfo[] = res.data ?? [];
|
||||||
const match = contracts.find((c) => c.name.startsWith(sym));
|
// Match symbol exactly: after the symbol prefix, next char must be a month code (A-Z) then a digit
|
||||||
|
const match = contracts.find((c) => {
|
||||||
|
if (!c.name.startsWith(sym)) return false;
|
||||||
|
const rest = c.name.slice(sym.length);
|
||||||
|
return /^[A-Z]\d/.test(rest);
|
||||||
|
});
|
||||||
frontMonths[sym] = match ? {
|
frontMonths[sym] = match ? {
|
||||||
id: match.id,
|
id: match.id,
|
||||||
name: match.name,
|
name: match.name,
|
||||||
@@ -193,8 +198,9 @@ export async function resolveContracts(
|
|||||||
const frontVol = volumes[front.name] ?? 0;
|
const frontVol = volumes[front.name] ?? 0;
|
||||||
const rolledVol = volumes[rolled.name] ?? 0;
|
const rolledVol = volumes[rolled.name] ?? 0;
|
||||||
|
|
||||||
if (rolledVol > frontVol) {
|
if (rolledVol >= frontVol) {
|
||||||
// Rolled contract has more volume — use it
|
// Rolled contract has equal or more volume — use it
|
||||||
|
// (equal includes both-zero case: prefer the further-out month)
|
||||||
results[sym] = {
|
results[sym] = {
|
||||||
...rolled,
|
...rolled,
|
||||||
alternative: front.name,
|
alternative: front.name,
|
||||||
@@ -203,7 +209,7 @@ export async function resolveContracts(
|
|||||||
};
|
};
|
||||||
console.log(`[contract-resolver] ${sym}: ${front.name} (vol=${frontVol}) → ${rolled.name} (vol=${rolledVol}) ROLLED`);
|
console.log(`[contract-resolver] ${sym}: ${front.name} (vol=${frontVol}) → ${rolled.name} (vol=${rolledVol}) ROLLED`);
|
||||||
} else {
|
} else {
|
||||||
// Front month still has more volume — keep it
|
// Front month has more volume — keep it
|
||||||
results[sym] = {
|
results[sym] = {
|
||||||
...front,
|
...front,
|
||||||
alternative: rolled.name,
|
alternative: rolled.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user