From 1f4a5b80c442ce9996c1082da6c8f4f455a39cbc Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Fri, 8 Nov 2024 21:49:14 +0000 Subject: [PATCH] symbol_info refactor --- piker/brokers/deribit/api.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 12e0944f..d7d888a9 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -392,7 +392,7 @@ class Client: kind: str = 'option', expired: bool = False - ) -> dict[str, dict]: + ) -> dict[str, Pair] | Pair: ''' Get symbol infos. @@ -412,14 +412,29 @@ class Client: params, ) # convert to symbol-keyed table + pair_type: Type = PAIRTYPES[kind] results: list[dict] | None = resp.result - instruments: dict[str, dict] = { - item['instrument_name'].lower(): item - for item in results - } + + instruments: dict[str, Pair] = {} + for item in results: + symbol=item['instrument_name'].lower() + try: + pair: Pair = pair_type( + symbol=symbol, + **item + ) + except Exception as e: + e.add_note( + "\nDon't panic, prolly stupid deribit changed their symbology schema again..\n" + 'Check out their API docs here:\n\n' + 'https://docs.deribit.com/?python#deribit-api-v2-1-1' + ) + raise + + instruments[symbol] = pair if instrument is not None: - return instruments[instrument] + return instruments[instrument.lower()] else: return instruments