Skip to content

Commit 4a10847

Browse files
committed
Clear market depth when depth is stopped
Previously the stopped market depth data remained in the Ticker object until the next depth request, but it would obviously be old and just using extra memory unnecessarily since it wasn't being used anymore. Now we clear the market depth data on: - initial market data request (ib.py) - upstream market data "reset" signal (wrapper.py) - market data stop/cancel (ib.py)
1 parent 7ffac04 commit 4a10847

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ib_async/ib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,13 @@ def cancelMktDepth(self, contract: Contract, isSmartDepth=False):
15331533
reqId = self.wrapper.endTicker(ticker, "mktDepth") if ticker else 0
15341534
if ticker and reqId:
15351535
self.client.cancelMktDepth(reqId, isSmartDepth)
1536+
1537+
# clear market depth state from live ticker since it is not longer
1538+
# being updated after the cancel request.
1539+
ticker.domBids.clear()
1540+
ticker.domAsks.clear()
1541+
ticker.domBidsDict.clear()
1542+
ticker.domAsksDict.clear()
15361543
else:
15371544
self._logger.error(
15381545
f"cancelMktDepth: No reqId found for contract {contract}"

0 commit comments

Comments
 (0)