Bit more `cryptofeed` adapter formatting and typing for clarity..
							parent
							
								
									a6d6700b07
								
							
						
					
					
						commit
						ab9789d35e
					
				|  | @ -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,43 +619,59 @@ 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', { | ||||
|             '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 | ||||
|         })) | ||||
| 
 | ||||
|     async def _l1(data: dict, receipt_timestamp): | ||||
|         to_trio.send_nowait(('l1', { | ||||
|             'symbol': cb_sym_to_deribit_inst( | ||||
|                 str_to_cb_sym(data.symbol)).lower(), | ||||
|             'ticks': [ | ||||
|                 { | ||||
|                     'type': 'bid', | ||||
|                     'price': float(data.bid_price), | ||||
|                     'size': float(data.bid_size) | ||||
|                 }, | ||||
|                 { | ||||
|                     'type': 'bsize', | ||||
|                     'price': float(data.bid_price), | ||||
|                     'size': float(data.bid_size) | ||||
|                 }, | ||||
|                 { | ||||
|                     'type': 'ask', | ||||
|                     'price': float(data.ask_price), | ||||
|                     'size': float(data.ask_size) | ||||
|                 }, | ||||
|                 { | ||||
|                     'type': 'asize', | ||||
|                     'price': float(data.ask_price), | ||||
|                     'size': float(data.ask_size) | ||||
|                 } | ||||
|             ] | ||||
|         })) | ||||
|     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, | ||||
|             }, | ||||
|         )) | ||||
| 
 | ||||
|     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': [ | ||||
|                     { | ||||
|                         'type': 'bid', | ||||
|                         'price': float(data.bid_price), | ||||
|                         'size': float(data.bid_size) | ||||
|                     }, | ||||
|                     { | ||||
|                         'type': 'bsize', | ||||
|                         'price': float(data.bid_price), | ||||
|                         'size': float(data.bid_size) | ||||
|                     }, | ||||
|                     { | ||||
|                         'type': 'ask', | ||||
|                         'price': float(data.ask_price), | ||||
|                         'size': float(data.ask_size) | ||||
|                     }, | ||||
|                     { | ||||
|                         'type': 'asize', | ||||
|                         'price': float(data.ask_price), | ||||
|                         'size': float(data.ask_size) | ||||
|                     } | ||||
|                 ] | ||||
|             }, | ||||
|         )) | ||||
|     sym: Symbol = piker_sym_to_cb_sym(instrument) | ||||
|     fh.add_feed( | ||||
|         DERIBIT, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue