From 10be273ee037b84bb6b899c666d6c304994db543 Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Wed, 29 Jan 2025 23:48:32 +0000 Subject: [PATCH] Report the closest (via fuzzy match) pairs on unmatched input --- piker/brokers/deribit/api.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 68f76d4d..0450b9eb 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -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