Skip to content

Commit d3d4c09

Browse files
committed
Stop guarding "last size/price" updates on values
For some reason the Ticker objects here have always maintained a "previous value" entry, but it only updates the previous value entry if the current value isn't the previous value. But isn't that wrong? If you want the previous trade price, it should be the true "previously seen trade price" and not "only the previous price if it isn't the current price?" Also, the historical logic was updating size and price independently, so the "lastPrice" and "lastSize" details weren't guaranteed to even match in time as to being one matches the other? Now previous price is the previously received price and size data regardless of if it matches the current price details or not.
1 parent cef8440 commit d3d4c09

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

ib_async/wrapper.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,15 +1022,14 @@ def tickByTickAllLast(
10221022
self._logger.error(f"tickByTickAllLast: Unknown reqId: {reqId}")
10231023
return
10241024

1025-
if size == 0:
1025+
if price == -1 and size == 0:
10261026
price = self.defaultEmptyPrice
10271027
size = self.defaultEmptySize
10281028

1029-
if (price, size) != (ticker.last, ticker.lastSize):
1030-
ticker.prevLast = ticker.last
1031-
ticker.prevLastSize = ticker.lastSize
1032-
ticker.last = price
1033-
ticker.lastSize = size
1029+
ticker.prevLast = ticker.last
1030+
ticker.prevLastSize = ticker.lastSize
1031+
ticker.last = price
1032+
ticker.lastSize = size
10341033

10351034
tick = TickByTickAllLast(
10361035
tickType,
@@ -1147,15 +1146,14 @@ def tickString(self, reqId: int, tickType: int, value: str):
11471146
price = float(priceStr)
11481147
size = float(sizeStr)
11491148

1150-
if price and size:
1151-
if ticker.prevLast != ticker.last:
1152-
ticker.prevLast = ticker.last
1153-
ticker.last = price
1154-
if ticker.prevLastSize != ticker.lastSize:
1155-
ticker.prevLastSize = ticker.lastSize
1156-
ticker.lastSize = size
1157-
tick = TickData(self.lastTime, tickType, price, size)
1158-
ticker.ticks.append(tick)
1149+
ticker.prevLast = ticker.last
1150+
ticker.prevLastSize = ticker.lastSize
1151+
1152+
ticker.last = price
1153+
ticker.lastSize = size
1154+
1155+
tick = TickData(self.lastTime, tickType, price, size)
1156+
ticker.ticks.append(tick)
11591157
elif tickType == 59:
11601158
# Dividend tick:
11611159
# https://interactivebrokers.github.io/tws-api/tick_types.html#ib_dividends

0 commit comments

Comments
 (0)