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
Nelson Torres 2025-01-30 01:44:39 +00:00
parent 4e9e72f0f1
commit 92a861a397
1 changed files with 9 additions and 4 deletions

View File

@ -123,7 +123,7 @@ def str_to_cb_sym(name: str) -> Symbol:
if option_type == 'put': if option_type == 'put':
option_type = PUT option_type = PUT
elif option_type == 'call': elif option_type == 'call':
option_type = CALL option_type = CALL
else: else:
raise Exception("Couldn\'t parse option type") raise Exception("Couldn\'t parse option type")
@ -382,6 +382,7 @@ class Client:
currency: str = 'btc', currency: str = 'btc',
kind: str = 'option', kind: str = 'option',
expired: bool = False, expired: bool = False,
expiry_date: str = None,
) -> list[Symbol]: ) -> list[Symbol]:
""" """
@ -400,9 +401,11 @@ class Client:
resp = r.result resp = r.result
response_list = [] response_list = []
for i in range(len(resp) // 10): for i in range(len(resp)):
element = resp[i] 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 return response_list
@ -879,7 +882,9 @@ async def open_oi_feed(
) as client: ) as client:
# to get all currencies available in deribit # to get all currencies available in deribit
# currencies = await client.get_currencies() # 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]]]]] = {} open_interests: dict[str, dict[str, dict[str, list[dict[str, Decimal]]]]] = {}
fh: FeedHandler fh: FeedHandler