From 7b02df9b49599b4ba3b9f773ca367034b014029d Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Fri, 29 Nov 2024 10:38:17 -0300 Subject: [PATCH] Update api.py This function receive a date in this format DDMMMYY and returns timestamps int --- piker/brokers/deribit/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 4eb15c73..420fd101 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -112,6 +112,10 @@ def deribit_timestamp(when: datetime) -> int: ) +def get_timestamp_int(expiry_date: str) -> int: + return int(time.mktime(time.strptime(expiry_date, '%d%b%y'))) + + def str_to_cb_sym(name: str) -> Symbol: base, strike_price, expiry_date, option_type = name.split('-') @@ -124,8 +128,9 @@ def str_to_cb_sym(name: str) -> Symbol: else: raise Exception("Couldn\'t parse option type") - new_expiry_date = get_values_from_cb_normalized_date(expiry_date) - + new_expiry_date: int = get_timestamp_int( + get_values_from_cb_normalized_date(expiry_date) + ) return Symbol( base=base, quote=quote, @@ -145,6 +150,7 @@ def piker_sym_to_cb_sym(name: str) -> Symbol: )= tuple( name.upper().split('-')) + new_expiry_date = get_timestamp_int(expiry_date) quote: str = base if option_type == 'P': @@ -160,7 +166,7 @@ def piker_sym_to_cb_sym(name: str) -> Symbol: type=OPTION, strike_price=strike_price, option_type=option_type, - expiry_date=expiry_date + expiry_date=new_expiry_date )