Report the closest (via fuzzy match) pairs on unmatched input

pull/20/head
Nelson Torres 2025-01-29 23:48:32 +00:00
parent 7d93acff6c
commit 5c19c2cec4
1 changed files with 15 additions and 1 deletions

View File

@ -28,8 +28,9 @@ from decimal import (
Decimal, Decimal,
) )
from functools import partial from functools import partial
import time
from pathlib import Path from pathlib import Path
from pprint import pformat
import time
from typing import ( from typing import (
Any, Any,
Optional, Optional,
@ -369,6 +370,19 @@ class Client:
return cached_pair return cached_pair
if sym: if sym:
opt: OptionPair|None = pair_table.get(sym)
if not opt:
closest_matches: dict[str, Pair] = match_from_pairs(
pairs=pair_table,
query=sym,
score_cutoff=40,
)
closest_syms: list[str] = list(closest_matches.keys())
raise ValueError(
f'No contract found for {sym!r}\n\n'
f'Closest {len(closest_syms)} available contracts:\n\n'
f'{pformat(closest_syms)}\n'
)
return pair_table[sym] return pair_table[sym]
else: else:
return self._pairs return self._pairs