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

fix_deribit_hist_queries
Tyler Goodlet 2024-11-19 17:50:26 -05:00
parent b734245183
commit 28e8628c61
1 changed files with 15 additions and 1 deletions

View File

@ -28,8 +28,9 @@ from decimal import (
Decimal,
)
from functools import partial
import time
from pathlib import Path
from pprint import pformat
import time
from typing import (
Any,
Optional,
@ -369,6 +370,19 @@ class Client:
return cached_pair
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]
else:
return self._pairs