From 1ed40ebbf7fafa92b6f98f97257f913ca91c3b10 Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Mon, 4 Nov 2024 09:34:21 -0300 Subject: [PATCH] venues for deribit --- piker/brokers/deribit/venues.py | 119 ++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 piker/brokers/deribit/venues.py diff --git a/piker/brokers/deribit/venues.py b/piker/brokers/deribit/venues.py new file mode 100644 index 00000000..cb8f2b62 --- /dev/null +++ b/piker/brokers/deribit/venues.py @@ -0,0 +1,119 @@ +# piker: trading gear for hackers +# Copyright (C) Tyler Goodlet (in stewardship for pikers) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" +Per market data-type definitions and schemas types. + +""" +from __future__ import annotations +from typing import ( + Literal, +) +from decimal import Decimal + +from msgspec import field + +from piker.types import Struct + + +# API endpoint paths by venue / sub-API +_domain: str = 'deribit.com' +_url = f'https://www.{_domain}' + +# WEBsocketz +_ws_url: str = f'wss://www.{_domain}/ws/api/v2' + +# test nets +_testnet_ws_url: str = f'wss://test.{_domain}/ws/api/v2' + +MarketType = Literal[ + 'option' +] + + +def get_api_eps(venue: MarketType) -> tuple[str, str]: + ''' + Return API ep root paths per venue. + + ''' + return { + 'option': ( + _ws_url, + ), + }[venue] + + +class OptionPair(Struct, frozen=True, kw_only=True): + + symbol: str + venue: str + + # src + quote_currency: str + + # dst + base_currency: str + + tick_size: float # 0.0001 + tick_size_steps: list[dict] # [{'above_price': 0.005, 'tick_size': 0.0005}] + taker_commission: float # 0.0003 + strike: float # 5000.0 + settlement_period: str # 'day' + settlement_currency: str # "BTC", + rfq: bool # false + quote_currency: str # 'BTC' + price_index: str # 'btc_usd' + option_type: str # 'call' + min_trade_amount: float # 0.1 + maker_commission: float # 0.0003 + kind: str # 'option' + is_active: bool # true + instrument_type: str # 'reversed' + instrument_name: str # 'BTC-1SEP24-55000-C' + instrument_id: int # 364671 + expiration_timestamp: int # 1725177600000 + creation_timestamp: int # 1724918461000 + counter_currency: str # 'USD' + contract_size: float # '1.0' + block_trade_tick_size: float # '0.0001' + block_trade_min_trade_amount: int # '25' + block_trade_commission: float # '0.003' + + + # NOTE: see `.data._symcache.SymbologyCache.load()` for why + ns_path: str = 'piker.brokers.deribit:OptionPair' + + @property + def venue(self) -> str: + return 'OPTION' + + @property + def bs_fqme(self) -> str: + return f'{self.symbol}.OPTION' + + @property + def bs_src_asset(self) -> str: + return f'{self.quote_currency}' + + @property + def bs_dst_asset(self) -> str: + return f'{self.base_currency}' + + @property + def bs_mktid(self) -> str: + return f'{self.symbol}.{self.venue}' + +