Compare commits

..

1 Commits

Author SHA1 Message Date
Nelson Torres cd92ef8b3a Added cryptofeed and pyarrow necessary for the feed, enable deribit
in the brokers init file, at this point the feed is working, to check
the tables use vd tool.
2024-08-28 19:01:22 +00:00
2 changed files with 21 additions and 32 deletions

View File

@ -118,12 +118,10 @@ class Trade(Struct):
instrument_name: str instrument_name: str
index_price: float index_price: float
direction: str direction: str
contracts: float
amount: float amount: float
contracts: 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]
@ -147,7 +145,9 @@ def str_to_cb_sym(name: str) -> Symbol:
else: else:
raise Exception("Couldn\'t parse option type") raise Exception("Couldn\'t parse option type")
new_expiry_date = get_values_from_cb_normalized_date(expiry_date) year, month, day = 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=new_expiry_date) expiry_date=exp)
def piker_sym_to_cb_sym(name: str) -> Symbol: def piker_sym_to_cb_sym(name: str) -> Symbol:
@ -181,13 +181,14 @@ 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):
new_expiry_date = get_values_from_cb_normalized_date(sym.expiry_date) year, month, day = 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}-{new_expiry_date}-{sym.strike_price}-{otype}' return f'{sym.base}-{exp}-{sym.strike_price}-{otype}'
def get_values_from_cb_normalized_date(expiry_date: str) -> str: def get_values_from_cb_normalized_date(expiry_date: str):
# deribit specific # deribit specific
cb_norm = [ cb_norm = [
'F', 'G', 'H', 'J', 'F', 'G', 'H', 'J',
@ -201,12 +202,11 @@ def get_values_from_cb_normalized_date(expiry_date: str) -> str:
] ]
# YYMDD # YYMDD
# 01234 # 01234
day, month, year = ( return (
expiry_date[3:], expiry_date[:2],
months[cb_norm.index(expiry_date[2:3])], months[cb_norm.index(expiry_date[2:3])],
expiry_date[:2] expiry_date[3:]
) )
return f'{day}{month}{year}'
def get_config() -> dict[str, Any]: def get_config() -> dict[str, Any]:
@ -221,6 +221,7 @@ 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
@ -233,12 +234,7 @@ def get_config() -> dict[str, Any]:
class Client: class Client:
def __init__( def __init__(self, json_rpc: Callable) -> None:
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', {})
@ -252,10 +248,7 @@ class Client:
def currencies(self): def currencies(self):
return ['btc', 'eth', 'sol', 'usd'] return ['btc', 'eth', 'sol', 'usd']
async def get_balances( async def get_balances(self, kind: str = 'option') -> dict[str, float]:
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.
""" """
@ -462,8 +455,7 @@ 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 _ws_url, response_type=JSONRPCResult) as json_rpc
) as json_rpc
): ):
client = Client(json_rpc) client = Client(json_rpc)
@ -557,9 +549,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': cb_sym_to_deribit_inst( 'symbol': piker_symbol,
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(),
@ -567,9 +559,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': cb_sym_to_deribit_inst( 'symbol': piker_symbol,
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)},

View File

@ -148,10 +148,7 @@ async def stream_quotes(
'asset_type': 'option', 'asset_type': 'option',
'price_tick_size': 0.0005 'price_tick_size': 0.0005
}, },
'shm_write_opts': { 'shm_write_opts': {'sum_tick_vml': False},
'sum_tick_vml': True,
'has_vlm': True
},
'fqsn': sym, 'fqsn': sym,
}, },
} }