@@ -327,6 +327,7 @@ def connectionClosed(self):
327
327
for future in self ._futures .values ():
328
328
if not future .done ():
329
329
future .set_exception (error )
330
+
330
331
globalErrorEvent .emit (error )
331
332
self .reset ()
332
333
@@ -338,8 +339,10 @@ def startReq(self, key, contract=None, container=None):
338
339
future : asyncio .Future = asyncio .Future ()
339
340
self ._futures [key ] = future
340
341
self ._results [key ] = container if container is not None else []
342
+
341
343
if contract :
342
344
self ._reqId2Contract [key ] = contract
345
+
343
346
return future
344
347
345
348
def _endReq (self , key , result = None , success = True ):
@@ -352,6 +355,7 @@ def _endReq(self, key, result=None, success=True):
352
355
if future :
353
356
if result is None :
354
357
result = self ._results .pop (key , [])
358
+
355
359
if not future .done ():
356
360
if success :
357
361
future .set_result (result )
@@ -517,9 +521,11 @@ def position(
517
521
position = Position (account , contract , posSize , avgCost )
518
522
positions = self .positions [account ]
519
523
524
+ # if this updates position to 0 quantity, remove the position
520
525
if posSize == 0 :
521
526
positions .pop (contract .conId , None )
522
527
else :
528
+ # else, add or replace the position in-place
523
529
positions [contract .conId ] = position
524
530
525
531
self ._logger .info (f"position: { position } " )
@@ -1093,6 +1099,7 @@ def tickByTickBidAsk(
1093
1099
tick = TickByTickBidAsk (
1094
1100
self .lastTime , bidPrice , askPrice , bidSize , askSize , tickAttribBidAsk
1095
1101
)
1102
+
1096
1103
ticker .tickByTicks .append (tick )
1097
1104
self .pendingTickers .add (ticker )
1098
1105
0 commit comments