@@ -327,6 +327,7 @@ def connectionClosed(self):
327327 for future in self ._futures .values ():
328328 if not future .done ():
329329 future .set_exception (error )
330+
330331 globalErrorEvent .emit (error )
331332 self .reset ()
332333
@@ -338,8 +339,10 @@ def startReq(self, key, contract=None, container=None):
338339 future : asyncio .Future = asyncio .Future ()
339340 self ._futures [key ] = future
340341 self ._results [key ] = container if container is not None else []
342+
341343 if contract :
342344 self ._reqId2Contract [key ] = contract
345+
343346 return future
344347
345348 def _endReq (self , key , result = None , success = True ):
@@ -352,6 +355,7 @@ def _endReq(self, key, result=None, success=True):
352355 if future :
353356 if result is None :
354357 result = self ._results .pop (key , [])
358+
355359 if not future .done ():
356360 if success :
357361 future .set_result (result )
@@ -517,9 +521,11 @@ def position(
517521 position = Position (account , contract , posSize , avgCost )
518522 positions = self .positions [account ]
519523
524+ # if this updates position to 0 quantity, remove the position
520525 if posSize == 0 :
521526 positions .pop (contract .conId , None )
522527 else :
528+ # else, add or replace the position in-place
523529 positions [contract .conId ] = position
524530
525531 self ._logger .info (f"position: { position } " )
@@ -1093,6 +1099,7 @@ def tickByTickBidAsk(
10931099 tick = TickByTickBidAsk (
10941100 self .lastTime , bidPrice , askPrice , bidSize , askSize , tickAttribBidAsk
10951101 )
1102+
10961103 ticker .tickByTicks .append (tick )
10971104 self .pendingTickers .add (ticker )
10981105
0 commit comments