diff --git a/lib/contract-resolver.ts b/lib/contract-resolver.ts index 17edfe1..c0bd9f7 100644 --- a/lib/contract-resolver.ts +++ b/lib/contract-resolver.ts @@ -216,14 +216,17 @@ export async function resolveContracts( console.log(`[contract-resolver] ${sym}: continuous=${continuousPrice}, candidates=[${candidates.map((c, i) => `${c.contract.name}=$${candidatePrices[i]}`).join(', ')}]`); - // Find the candidate whose price matches the continuous contract (within 0.1% tolerance) + // Find the candidate with the closest price to the continuous contract let best = candidates[0]; // default to front if (continuousPrice !== null) { + let bestDiff = Infinity; for (let i = 0; i < candidates.length; i++) { const price = candidatePrices[i]; - if (price !== null && Math.abs(price - continuousPrice) / continuousPrice < 0.001) { + if (price === null) continue; + const diff = Math.abs(price - continuousPrice); + if (diff < bestDiff) { + bestDiff = diff; best = candidates[i]; - break; // prefer the nearest matching contract } } } else {