move object classes to venue

deribit_fix
Nelson Torres 2024-11-15 11:15:25 -03:00
parent 0916b707e2
commit df8d1274ae
2 changed files with 66 additions and 67 deletions

View File

@ -62,6 +62,11 @@ from .venues import (
PAIRTYPES, PAIRTYPES,
Pair, Pair,
OptionPair, OptionPair,
JSONRPCResult,
JSONRPCChannel,
KLinesResult,
Trade,
LastTradesResult,
) )
from piker.accounting import ( from piker.accounting import (
Asset, Asset,
@ -95,55 +100,6 @@ _ws_url = 'wss://www.deribit.com/ws/api/v2'
_testnet_ws_url = 'wss://test.deribit.com/ws/api/v2' _testnet_ws_url = 'wss://test.deribit.com/ws/api/v2'
class JSONRPCResult(Struct):
id: int
usIn: int
usOut: int
usDiff: int
testnet: bool
jsonrpc: str = '2.0'
result: Optional[list[dict]] = None
error: Optional[dict] = None
class JSONRPCChannel(Struct):
method: str
params: dict
jsonrpc: str = '2.0'
class KLinesResult(Struct):
close: list[float]
cost: list[float]
high: list[float]
low: list[float]
open: list[float]
status: str
ticks: list[int]
volume: list[float]
class Trade(Struct):
trade_seq: int
trade_id: str
timestamp: int
tick_direction: int
price: float
mark_price: float
iv: float
instrument_name: str
index_price: float
direction: str
contracts: float
amount: float
combo_trade_id: Optional[int] = 0,
combo_id: Optional[str] = '',
block_trade_leg_count: Optional[int] = 0,
block_trade_id: Optional[str] = '',
class LastTradesResult(Struct):
trades: list[Trade]
has_more: bool
# convert datetime obj timestamp to unixtime in milliseconds # convert datetime obj timestamp to unixtime in milliseconds
def deribit_timestamp(when): def deribit_timestamp(when):
return int((when.timestamp() * 1000) + (when.microsecond / 1000)) return int((when.timestamp() * 1000) + (when.microsecond / 1000))

View File

@ -19,6 +19,7 @@ Per market data-type definitions and schemas types.
""" """
from __future__ import annotations from __future__ import annotations
import pendulum
from typing import ( from typing import (
Literal, Literal,
) )
@ -66,29 +67,27 @@ class Pair(Struct, frozen=True, kw_only=True):
# dst # dst
base_currency: str # "BTC", base_currency: str # "BTC",
tick_size: float # 0.0001 tick_size: float # 0.0001 # [{'above_price': 0.005, 'tick_size': 0.0005}]
tick_size_steps: list[dict[str, str | int | float]] # [{'above_price': 0.005, 'tick_size': 0.0005}] tick_size_steps: list[dict[str, float]]
@property @property
def price_tick(self) -> Decimal: def price_tick(self) -> Decimal:
step_size: float = self.tick_size_steps[0].get('above_price') return Decimal(str(self.tick_size_steps[0]['above_price']))
return Decimal(step_size)
@property @property
def size_tick(self) -> Decimal: def size_tick(self) -> Decimal:
step_size: float = self.tick_size_steps[0].get('tick_size') return Decimal(str(self.tick_size))
return Decimal(step_size)
@property @property
def bs_fqme(self) -> str: def bs_fqme(self) -> str:
return self.symbol return f'{self.symbol}'
@property @property
def bs_mktid(self) -> str: def bs_mktid(self) -> str:
return f'{self.symbol}' return f'{self.symbol}.{self.venue}'
class OptionPair(Pair, frozen=True, kw_only=True): class OptionPair(Pair, frozen=True):
taker_commission: float # 0.0003 taker_commission: float # 0.0003
strike: float # 5000.0 strike: float # 5000.0
@ -118,17 +117,16 @@ class OptionPair(Pair, frozen=True, kw_only=True):
@property @property
def expiry(self) -> str: def expiry(self) -> str:
symbol: str = self.instrument_name.lower() iso_date = pendulum.from_timestamp(self.expiration_timestamp / 1000).isoformat()
pair, expiry, strike_price, otype = symbol.split('-') return iso_date
return f'{expiry}'
@property @property
def venue(self) -> str: def venue(self) -> str:
return 'OPTION' return 'option'
@property @property
def bs_fqme(self) -> str: def bs_fqme(self) -> str:
return f'{self.symbol}.{self.venue}.{self.expiry}' return f'{self.symbol}'
@property @property
def bs_src_asset(self) -> str: def bs_src_asset(self) -> str:
@ -136,13 +134,58 @@ class OptionPair(Pair, frozen=True, kw_only=True):
@property @property
def bs_dst_asset(self) -> str: def bs_dst_asset(self) -> str:
return f'{self.base_currency}'
@property
def bs_mktid(self) -> str:
return f'{self.symbol}' return f'{self.symbol}'
PAIRTYPES: dict[MarketType, Pair] = { PAIRTYPES: dict[MarketType, Pair] = {
'option': OptionPair, 'option': OptionPair,
} }
class JSONRPCResult(Struct):
id: int
usIn: int
usOut: int
usDiff: int
testnet: bool
jsonrpc: str = '2.0'
error: Optional[dict] = None
result: Optional[list[dict]] = None
class JSONRPCChannel(Struct):
method: str
params: dict
jsonrpc: str = '2.0'
class KLinesResult(Struct):
low: list[float]
cost: list[float]
high: list[float]
open: list[float]
close: list[float]
ticks: list[int]
status: str
volume: list[float]
class Trade(Struct):
iv: float
price: float
amount: float
trade_id: str
contracts: float
direction: str
trade_seq: int
timestamp: int
mark_price: float
index_price: float
tick_direction: int
instrument_name: str
combo_id: Optional[str] = '',
combo_trade_id: Optional[int] = 0,
block_trade_id: Optional[str] = '',
block_trade_leg_count: Optional[int] = 0,
class LastTradesResult(Struct):
trades: list[Trade]
has_more: bool