Skip to content

Commit 69b920d

Browse files
committed
Remove conditional ticker previous value updating
I'm not sure why it was only conditionally updating the values before because running the comparisons as `if` checks is slower than just always replacing fields with the new values each time. The only edge cases this would impact is if instruments received many last trades all of the same price and size (3x3, 5x5, 5x5, 5x5) after each other, the previous way would always show previousPrice/Size as 3x3 until a new value was received, but that's also a lie because the _previous_ reported trade was the _same_ as the current trade. Now this is both more accurate to the truth (especially since we have `lastTimestamp` being reported from the API now) and faster since it isn't doing multiple comparisons to just set the same fields each time.
1 parent 5574f3e commit 69b920d

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

ib_async/wrapper.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -902,33 +902,29 @@ def priceSizeTick(self, reqId: int, tickType: int, price: float, size: float):
902902
price = self.defaultEmptyPrice
903903
size = self.defaultEmptySize
904904

905-
# only update if there is a new price/size combination
906-
if (price, size) != (ticker.bid, ticker.bidSize):
907-
ticker.prevBid = ticker.bid
908-
ticker.prevBidSize = ticker.bidSize
909-
ticker.bid = price
910-
ticker.bidSize = size
905+
ticker.prevBid = ticker.bid
906+
ticker.prevBidSize = ticker.bidSize
907+
ticker.bid = price
908+
ticker.bidSize = size
911909
elif tickType in {2, 67}:
912910
if size == 0:
913911
price = self.defaultEmptyPrice
914912
size = self.defaultEmptySize
915913

916-
if (price, size) != (ticker.ask, ticker.askSize):
917-
ticker.prevAsk = ticker.ask
918-
ticker.prevAskSize = ticker.askSize
919-
ticker.ask = price
920-
ticker.askSize = size
914+
ticker.prevAsk = ticker.ask
915+
ticker.prevAskSize = ticker.askSize
916+
ticker.ask = price
917+
ticker.askSize = size
921918
elif tickType in {4, 68}:
922919
# for 'last' values, price can be valid with size=0 for updates like 'last SPX price' since SPX doesn't trade
923920
if price == -1 and size == 0:
924921
price = self.defaultEmptyPrice
925922
size = self.defaultEmptySize
926923

927-
if (price, size) != (ticker.last, ticker.lastSize):
928-
ticker.prevLast = ticker.last
929-
ticker.prevLastSize = ticker.lastSize
930-
ticker.last = price
931-
ticker.lastSize = size
924+
ticker.prevLast = ticker.last
925+
ticker.prevLastSize = ticker.lastSize
926+
ticker.last = price
927+
ticker.lastSize = size
932928
else:
933929
assert (
934930
tickType in PRICE_TICK_MAP

0 commit comments

Comments
 (0)