Bit more `cryptofeed` adapter formatting and typing for clarity..
							parent
							
								
									e2da3bf35d
								
							
						
					
					
						commit
						b4aa8f796a
					
				|  | @ -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,43 +619,59 @@ 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', { |  | ||||||
|             '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): |     async def _trade( | ||||||
|         to_trio.send_nowait(('l1', { |         data: dict, | ||||||
|             'symbol': cb_sym_to_deribit_inst( |         receipt_timestamp: int, | ||||||
|                 str_to_cb_sym(data.symbol)).lower(), |     ) -> None: | ||||||
|             'ticks': [ |         ''' | ||||||
|                 { |         Send `cryptofeed.FeedHandler` quotes to `piker`-side | ||||||
|                     'type': 'bid', |         `trio.Task`. | ||||||
|                     'price': float(data.bid_price), | 
 | ||||||
|                     'size': float(data.bid_size) |         ''' | ||||||
|                 }, |         to_trio.send_nowait(( | ||||||
|                 { |             'trade', { | ||||||
|                     'type': 'bsize', |                 'symbol': cb_sym_to_deribit_inst( | ||||||
|                     'price': float(data.bid_price), |                     str_to_cb_sym(data.symbol)).lower(), | ||||||
|                     'size': float(data.bid_size) |                 'last': data, | ||||||
|                 }, |                 'broker_ts': time.time(), | ||||||
|                 { |                 'data': data.to_dict(), | ||||||
|                     'type': 'ask', |                 'receipt': receipt_timestamp, | ||||||
|                     'price': float(data.ask_price), |             }, | ||||||
|                     'size': float(data.ask_size) |         )) | ||||||
|                 }, | 
 | ||||||
|                 { |     async def _l1( | ||||||
|                     'type': 'asize', |         data: dict, | ||||||
|                     'price': float(data.ask_price), |         receipt_timestamp: int, | ||||||
|                     'size': float(data.ask_size) |     ) -> 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) |     sym: Symbol = piker_sym_to_cb_sym(instrument) | ||||||
|     fh.add_feed( |     fh.add_feed( | ||||||
|         DERIBIT, |         DERIBIT, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue