|
|
@ -118,10 +118,12 @@ class Trade(Struct):
|
|
|
|
instrument_name: str
|
|
|
|
instrument_name: str
|
|
|
|
index_price: float
|
|
|
|
index_price: float
|
|
|
|
direction: str
|
|
|
|
direction: str
|
|
|
|
amount: float
|
|
|
|
|
|
|
|
contracts: float
|
|
|
|
contracts: float
|
|
|
|
|
|
|
|
amount: float
|
|
|
|
combo_trade_id: Optional[int] = 0,
|
|
|
|
combo_trade_id: Optional[int] = 0,
|
|
|
|
combo_id: Optional[str] = '',
|
|
|
|
combo_id: Optional[str] = '',
|
|
|
|
|
|
|
|
block_trade_leg_count: Optional[int] = 0,
|
|
|
|
|
|
|
|
block_trade_id: Optional[str] = '',
|
|
|
|
|
|
|
|
|
|
|
|
class LastTradesResult(Struct):
|
|
|
|
class LastTradesResult(Struct):
|
|
|
|
trades: list[Trade]
|
|
|
|
trades: list[Trade]
|
|
|
@ -145,9 +147,7 @@ def str_to_cb_sym(name: str) -> Symbol:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise Exception("Couldn\'t parse option type")
|
|
|
|
raise Exception("Couldn\'t parse option type")
|
|
|
|
|
|
|
|
|
|
|
|
year, month, day = get_values_from_cb_normalized_date(expiry_date)
|
|
|
|
new_expiry_date = get_values_from_cb_normalized_date(expiry_date)
|
|
|
|
|
|
|
|
|
|
|
|
exp = f'{day}{month}{year}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Symbol(
|
|
|
|
return Symbol(
|
|
|
|
base=base,
|
|
|
|
base=base,
|
|
|
@ -155,7 +155,7 @@ def str_to_cb_sym(name: str) -> Symbol:
|
|
|
|
type=OPTION,
|
|
|
|
type=OPTION,
|
|
|
|
strike_price=strike_price,
|
|
|
|
strike_price=strike_price,
|
|
|
|
option_type=option_type,
|
|
|
|
option_type=option_type,
|
|
|
|
expiry_date=exp)
|
|
|
|
expiry_date=new_expiry_date)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def piker_sym_to_cb_sym(name: str) -> Symbol:
|
|
|
|
def piker_sym_to_cb_sym(name: str) -> Symbol:
|
|
|
@ -181,14 +181,13 @@ def piker_sym_to_cb_sym(name: str) -> Symbol:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cb_sym_to_deribit_inst(sym: Symbol):
|
|
|
|
def cb_sym_to_deribit_inst(sym: Symbol):
|
|
|
|
year, month, day = get_values_from_cb_normalized_date(sym.expiry_date)
|
|
|
|
new_expiry_date = get_values_from_cb_normalized_date(sym.expiry_date)
|
|
|
|
exp = f'{day}{month}{year}'
|
|
|
|
|
|
|
|
otype = 'C' if sym.option_type == CALL else 'P'
|
|
|
|
otype = 'C' if sym.option_type == CALL else 'P'
|
|
|
|
|
|
|
|
|
|
|
|
return f'{sym.base}-{exp}-{sym.strike_price}-{otype}'
|
|
|
|
return f'{sym.base}-{new_expiry_date}-{sym.strike_price}-{otype}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_values_from_cb_normalized_date(expiry_date: str):
|
|
|
|
def get_values_from_cb_normalized_date(expiry_date: str) -> str:
|
|
|
|
# deribit specific
|
|
|
|
# deribit specific
|
|
|
|
cb_norm = [
|
|
|
|
cb_norm = [
|
|
|
|
'F', 'G', 'H', 'J',
|
|
|
|
'F', 'G', 'H', 'J',
|
|
|
@ -202,11 +201,12 @@ def get_values_from_cb_normalized_date(expiry_date: str):
|
|
|
|
]
|
|
|
|
]
|
|
|
|
# YYMDD
|
|
|
|
# YYMDD
|
|
|
|
# 01234
|
|
|
|
# 01234
|
|
|
|
return (
|
|
|
|
day, month, year = (
|
|
|
|
expiry_date[:2],
|
|
|
|
expiry_date[3:],
|
|
|
|
months[cb_norm.index(expiry_date[2:3])],
|
|
|
|
months[cb_norm.index(expiry_date[2:3])],
|
|
|
|
expiry_date[3:]
|
|
|
|
expiry_date[:2]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return f'{day}{month}{year}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config() -> dict[str, Any]:
|
|
|
|
def get_config() -> dict[str, Any]:
|
|
|
@ -221,7 +221,6 @@ def get_config() -> dict[str, Any]:
|
|
|
|
section: dict = {}
|
|
|
|
section: dict = {}
|
|
|
|
section['deribit'] = conf.get('deribit')
|
|
|
|
section['deribit'] = conf.get('deribit')
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: document why we send this, basically because logging params for cryptofeed
|
|
|
|
|
|
|
|
section['log'] = {}
|
|
|
|
section['log'] = {}
|
|
|
|
section['log']['disabled'] = True
|
|
|
|
section['log']['disabled'] = True
|
|
|
|
|
|
|
|
|
|
|
@ -234,7 +233,12 @@ def get_config() -> dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
class Client:
|
|
|
|
class Client:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, json_rpc: Callable) -> None:
|
|
|
|
def __init__(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_rpc: Callable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) -> None:
|
|
|
|
self._pairs: dict[str, Any] = None
|
|
|
|
self._pairs: dict[str, Any] = None
|
|
|
|
|
|
|
|
|
|
|
|
config = get_config().get('deribit', {})
|
|
|
|
config = get_config().get('deribit', {})
|
|
|
@ -248,7 +252,10 @@ class Client:
|
|
|
|
def currencies(self):
|
|
|
|
def currencies(self):
|
|
|
|
return ['btc', 'eth', 'sol', 'usd']
|
|
|
|
return ['btc', 'eth', 'sol', 'usd']
|
|
|
|
|
|
|
|
|
|
|
|
async def get_balances(self, kind: str = 'option') -> dict[str, float]:
|
|
|
|
async def get_balances(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
kind: str = 'option'
|
|
|
|
|
|
|
|
) -> dict[str, float]:
|
|
|
|
"""Return the set of positions for this account
|
|
|
|
"""Return the set of positions for this account
|
|
|
|
by symbol.
|
|
|
|
by symbol.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -455,7 +462,8 @@ async def get_client(
|
|
|
|
async with (
|
|
|
|
async with (
|
|
|
|
trio.open_nursery() as n,
|
|
|
|
trio.open_nursery() as n,
|
|
|
|
open_jsonrpc_session(
|
|
|
|
open_jsonrpc_session(
|
|
|
|
_ws_url, response_type=JSONRPCResult) as json_rpc
|
|
|
|
_ws_url, response_type=JSONRPCResult
|
|
|
|
|
|
|
|
) as json_rpc
|
|
|
|
):
|
|
|
|
):
|
|
|
|
client = Client(json_rpc)
|
|
|
|
client = Client(json_rpc)
|
|
|
|
|
|
|
|
|
|
|
@ -549,9 +557,9 @@ async def aio_price_feed_relay(
|
|
|
|
to_trio: trio.abc.SendChannel,
|
|
|
|
to_trio: trio.abc.SendChannel,
|
|
|
|
) -> None:
|
|
|
|
) -> None:
|
|
|
|
async def _trade(data: dict, receipt_timestamp):
|
|
|
|
async def _trade(data: dict, receipt_timestamp):
|
|
|
|
piker_symbol = cb_sym_to_deribit_inst(str_to_cb_sym(data.symbol)).lower()
|
|
|
|
|
|
|
|
to_trio.send_nowait(('trade', {
|
|
|
|
to_trio.send_nowait(('trade', {
|
|
|
|
'symbol': piker_symbol,
|
|
|
|
'symbol': cb_sym_to_deribit_inst(
|
|
|
|
|
|
|
|
str_to_cb_sym(data.symbol)).lower(),
|
|
|
|
'last': data,
|
|
|
|
'last': data,
|
|
|
|
'broker_ts': time.time(),
|
|
|
|
'broker_ts': time.time(),
|
|
|
|
'data': data.to_dict(),
|
|
|
|
'data': data.to_dict(),
|
|
|
@ -559,9 +567,9 @@ async def aio_price_feed_relay(
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
async def _l1(data: dict, receipt_timestamp):
|
|
|
|
async def _l1(data: dict, receipt_timestamp):
|
|
|
|
piker_symbol = cb_sym_to_deribit_inst(str_to_cb_sym(data.symbol)).lower()
|
|
|
|
|
|
|
|
to_trio.send_nowait(('l1', {
|
|
|
|
to_trio.send_nowait(('l1', {
|
|
|
|
'symbol': piker_symbol,
|
|
|
|
'symbol': cb_sym_to_deribit_inst(
|
|
|
|
|
|
|
|
str_to_cb_sym(data.symbol)).lower(),
|
|
|
|
'ticks': [
|
|
|
|
'ticks': [
|
|
|
|
{'type': 'bid',
|
|
|
|
{'type': 'bid',
|
|
|
|
'price': float(data.bid_price), 'size': float(data.bid_size)},
|
|
|
|
'price': float(data.bid_price), 'size': float(data.bid_size)},
|
|
|
|