From 28e8628c61db0ad4ffaf896ed8ff6cddca1b5607 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 19 Nov 2024 17:50:26 -0500 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