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,
|
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=new_expiry_date
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def piker_sym_to_cb_sym(name: str) -> Symbol:
|
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('-'))
|
name.upper().split('-'))
|
||||||
|
|
||||||
quote = base
|
quote: str = base
|
||||||
|
|
||||||
if option_type == 'P':
|
if option_type == 'P':
|
||||||
option_type = PUT
|
option_type = PUT
|
||||||
|
@ -145,7 +151,8 @@ def piker_sym_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=expiry_date)
|
expiry_date=expiry_date
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def cb_sym_to_deribit_inst(sym: Symbol):
|
def cb_sym_to_deribit_inst(sym: Symbol):
|
||||||
|
@ -208,7 +215,10 @@ def get_config() -> dict[str, Any]:
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
'''
|
||||||
|
Hi-level interface for the jsron-RPC over websocket API.
|
||||||
|
|
||||||
|
'''
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
@ -609,18 +619,33 @@ async def aio_price_feed_relay(
|
||||||
from_trio: asyncio.Queue,
|
from_trio: asyncio.Queue,
|
||||||
to_trio: trio.abc.SendChannel,
|
to_trio: trio.abc.SendChannel,
|
||||||
) -> None:
|
) -> 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(
|
'symbol': cb_sym_to_deribit_inst(
|
||||||
str_to_cb_sym(data.symbol)).lower(),
|
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(),
|
||||||
'receipt': receipt_timestamp
|
'receipt': receipt_timestamp,
|
||||||
}))
|
},
|
||||||
|
))
|
||||||
|
|
||||||
async def _l1(data: dict, receipt_timestamp):
|
async def _l1(
|
||||||
to_trio.send_nowait(('l1', {
|
data: dict,
|
||||||
|
receipt_timestamp: int,
|
||||||
|
) -> None:
|
||||||
|
to_trio.send_nowait((
|
||||||
|
'l1', {
|
||||||
'symbol': cb_sym_to_deribit_inst(
|
'symbol': cb_sym_to_deribit_inst(
|
||||||
str_to_cb_sym(data.symbol)).lower(),
|
str_to_cb_sym(data.symbol)).lower(),
|
||||||
'ticks': [
|
'ticks': [
|
||||||
|
@ -645,7 +670,8 @@ async def aio_price_feed_relay(
|
||||||
'size': float(data.ask_size)
|
'size': float(data.ask_size)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))
|
},
|
||||||
|
))
|
||||||
sym: Symbol = piker_sym_to_cb_sym(instrument)
|
sym: Symbol = piker_sym_to_cb_sym(instrument)
|
||||||
fh.add_feed(
|
fh.add_feed(
|
||||||
DERIBIT,
|
DERIBIT,
|
||||||
|
|
Loading…
Reference in New Issue