Bit more `cryptofeed` adapter formatting and typing for clarity..
parent
b9dde98d1e
commit
dafd5a3ca5
|
@ -123,14 +123,20 @@ def str_to_cb_sym(name: str) -> Symbol:
|
|||
type=OPTION,
|
||||
strike_price=strike_price,
|
||||
option_type=option_type,
|
||||
expiry_date=new_expiry_date)
|
||||
expiry_date=new_expiry_date
|
||||
)
|
||||
|
||||
|
||||
def piker_sym_to_cb_sym(name: str) -> Symbol:
|
||||
base, expiry_date, strike_price, option_type = tuple(
|
||||
(
|
||||
base,
|
||||
expiry_date,
|
||||
strike_price,
|
||||
option_type,
|
||||
)= tuple(
|
||||
name.upper().split('-'))
|
||||
|
||||
quote = base
|
||||
quote: str = base
|
||||
|
||||
if option_type == 'P':
|
||||
option_type = PUT
|
||||
|
@ -145,7 +151,8 @@ def piker_sym_to_cb_sym(name: str) -> Symbol:
|
|||
type=OPTION,
|
||||
strike_price=strike_price,
|
||||
option_type=option_type,
|
||||
expiry_date=expiry_date)
|
||||
expiry_date=expiry_date
|
||||
)
|
||||
|
||||
|
||||
def cb_sym_to_deribit_inst(sym: Symbol):
|
||||
|
@ -208,7 +215,10 @@ def get_config() -> dict[str, Any]:
|
|||
|
||||
|
||||
class Client:
|
||||
'''
|
||||
Hi-level interface for the jsron-RPC over websocket API.
|
||||
|
||||
'''
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
|
@ -609,18 +619,33 @@ async def aio_price_feed_relay(
|
|||
from_trio: asyncio.Queue,
|
||||
to_trio: trio.abc.SendChannel,
|
||||
) -> None:
|
||||
async def _trade(data: dict, receipt_timestamp):
|
||||
to_trio.send_nowait(('trade', {
|
||||
|
||||
async def _trade(
|
||||
data: dict,
|
||||
receipt_timestamp: int,
|
||||
) -> None:
|
||||
'''
|
||||
Send `cryptofeed.FeedHandler` quotes to `piker`-side
|
||||
`trio.Task`.
|
||||
|
||||
'''
|
||||
to_trio.send_nowait((
|
||||
'trade', {
|
||||
'symbol': cb_sym_to_deribit_inst(
|
||||
str_to_cb_sym(data.symbol)).lower(),
|
||||
'last': data,
|
||||
'broker_ts': time.time(),
|
||||
'data': data.to_dict(),
|
||||
'receipt': receipt_timestamp
|
||||
}))
|
||||
'receipt': receipt_timestamp,
|
||||
},
|
||||
))
|
||||
|
||||
async def _l1(data: dict, receipt_timestamp):
|
||||
to_trio.send_nowait(('l1', {
|
||||
async def _l1(
|
||||
data: dict,
|
||||
receipt_timestamp: int,
|
||||
) -> None:
|
||||
to_trio.send_nowait((
|
||||
'l1', {
|
||||
'symbol': cb_sym_to_deribit_inst(
|
||||
str_to_cb_sym(data.symbol)).lower(),
|
||||
'ticks': [
|
||||
|
@ -645,7 +670,8 @@ async def aio_price_feed_relay(
|
|||
'size': float(data.ask_size)
|
||||
}
|
||||
]
|
||||
}))
|
||||
},
|
||||
))
|
||||
sym: Symbol = piker_sym_to_cb_sym(instrument)
|
||||
fh.add_feed(
|
||||
DERIBIT,
|
||||
|
|
Loading…
Reference in New Issue