2020class OutOfOrderMessageException (Exception ):
2121 pass
2222
23+ class MarketInitialisationException (Exception ):
24+ pass
25+
2326
2427def _flatten_orders (orders , reverse ):
2528 return sorted (orders .values (), key = lambda o : o .price , reverse = reverse )
@@ -38,7 +41,7 @@ def _decrement_trade(orders: Dict[str, Order], order_id: str, volume: Decimal):
3841class _MarketStreamState :
3942 def __init__ (self , first : dict ):
4043 if first is None :
41- raise Exception ("Unable to use empty message to initialise market state " )
44+ raise MarketInitialisationException ("Unable to initialise market state from an empty message " )
4245
4346 def conv_message (msg ):
4447 return Order (
@@ -136,8 +139,8 @@ async def _read_from_websocket(ws, pair: Pair, update_f: StateUpdate):
136139 async for message in ws :
137140 try :
138141 body = json .loads (message )
139- except ValueError :
140- raise Exception ( message )
142+ except ValueError as e :
143+ raise ValueError ( f"Invalid JSON received: { message } " ) from e
141144
142145 if body == "" : # Empty update, used as keepalive
143146 body = None
@@ -177,7 +180,7 @@ async def stream_market(
177180 :param update_callback: an StateUpdate function that will be called with new updates.
178181 """
179182 if len (pair ) != 6 :
180- raise Exception ( "Invalid pair" )
183+ raise ValueError ( f"pair must be length 6, got ' { pair } ' " )
181184
182185 p = Pair (pair [:3 ].upper (), pair [3 :].upper ())
183186 url = '/' .join ([base_url , 'api/1/stream' , p .base + p .counter ])
0 commit comments