From 92a861a3975cddf72a65c8988a6db792a11955a0 Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Thu, 30 Jan 2025 01:44:39 +0000 Subject: [PATCH] Update api.py Now we get the data for an e specific expiration date if and expiry_date is passed, or for all expiration if expiry_date is None --- piker/brokers/deribit/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 879abd18..112e74b4 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -123,7 +123,7 @@ def str_to_cb_sym(name: str) -> Symbol: if option_type == 'put': option_type = PUT - elif option_type == 'call': + elif option_type == 'call': option_type = CALL else: raise Exception("Couldn\'t parse option type") @@ -382,6 +382,7 @@ class Client: currency: str = 'btc', kind: str = 'option', expired: bool = False, + expiry_date: str = None, ) -> list[Symbol]: """ @@ -400,9 +401,11 @@ class Client: resp = r.result response_list = [] - for i in range(len(resp) // 10): + for i in range(len(resp)): element = resp[i] - response_list.append(piker_sym_to_cb_sym(element['instrument_name'])) + name = f'{element["instrument_name"].split("-")[1]}' + if not expiry_date or name == expiry_date.upper(): + response_list.append(piker_sym_to_cb_sym(element['instrument_name'])) return response_list @@ -879,7 +882,9 @@ async def open_oi_feed( ) as client: # to get all currencies available in deribit # currencies = await client.get_currencies() - instruments = await client.get_instruments() + instruments = await client.get_instruments( + expiry_date='6DEC24' + ) open_interests: dict[str, dict[str, dict[str, list[dict[str, Decimal]]]]] = {} fh: FeedHandler