diff --git a/examples/derivs/__init__.py b/examples/derivs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/max_pain.py b/examples/derivs/max_pain.py similarity index 90% rename from examples/max_pain.py rename to examples/derivs/max_pain.py index 7aef9581..03232397 100644 --- a/examples/max_pain.py +++ b/examples/derivs/max_pain.py @@ -23,7 +23,21 @@ def check_if_complete( async def max_pain_daemon( ) -> None: - expiry_date: str = input('Please enter a valid expiration date (7feb25): ').upper() + oi_by_strikes: dict[str, dict[str, Decimal | None]] + expiry_dates: list[str] + currency: str = 'btc' + kind: str = 'option' + + async with get_client( + ) as client: + expiry_dates: list[str] = await client.get_expiration_dates( + currency=currency, + kind=kind + ) + + print(f'Available expiration dates for {currency}-{kind}:') + print(f'{expiry_dates}') + expiry_date: str = input('Please enter a valid expiration date: ').upper() print('Starting little daemon...') instruments: list[Symbol] = [] oi_by_strikes: dict[str, dict[str, Decimal]] diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 7efa6b65..2f73856b 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -411,6 +411,29 @@ class Client: return response_list + async def get_expiration_dates( + self, + currency: str = 'btc', + kind: str = 'option', + + ) -> list[str]: + """ + Get a dict with all expiration dates listed as value and currency as key. + """ + + params: dict[str, str] = { + 'currency': currency.upper(), + 'kind': kind, + } + + r: JSONRPCResult = await self._json_rpc_auth_wrapper( + 'public/get_expirations', + params, + ) + resp = r.result + + return resp[currency][kind] + def get_strikes_dict( self, instruments: list[Symbol],