You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cannot get real last price from Interactive brokers, but instead yesterday's closing price
i.e:
2024-09-16 19:35:09,335: root: WARNING: Last price for AAPL not found. Using yesterday's closing price of 222.5 instead. reqId = 10004
2024-09-16 19:35:09,458: root: WARNING: Last price for BAC not found. Using yesterday's closing price of 38.65 instead. reqId = 10006
2024-09-16 19:35:09,461: root: WARNING: Last price for AXP not found. Using yesterday's closing price of 259.0 instead. reqId = 10007
2024-09-16 19:35:09,464: root: WARNING: Last price for KO not found. Using yesterday's closing price of 71.41 instead. reqId = 10008
2024-09-16 19:35:09,467: root: WARNING: Last price for CVX not found. Using yesterday's closing price of 140.61 instead. reqId = 10009
The text was updated successfully, but these errors were encountered:
I believe I have identified the source of the issue (at least, it seems to work for me). However, as I am uncertain about the original logic behind the implementation, I am providing only an explanation of the changes I made without submitting an actual code modification.
In the file interactive_brokers.py, within the tickPrice() method, the price is consistently overwritten by yesterday's closing price because tickType == 9 always follows tickType == 4.
The root cause appears to be that self.tick is never initialized, remaining None, which causes the price already set by tickType == 4 to be overwritten.
I propose changing the check self.tick is None to self.price is None to resolve this, as illustrated below:
# If the last price is not available, then use yesterday's closing price
# This can happen if the market is closed
if tickType == 9 and self.price is None and self.should_use_last_close: # Replaced self.tick with self.price
self.price = price
self.tick_type_used = tickType
Cannot get real last price from Interactive brokers, but instead yesterday's closing price
i.e:
2024-09-16 19:35:09,335: root: WARNING: Last price for AAPL not found. Using yesterday's closing price of 222.5 instead. reqId = 10004
2024-09-16 19:35:09,458: root: WARNING: Last price for BAC not found. Using yesterday's closing price of 38.65 instead. reqId = 10006
2024-09-16 19:35:09,461: root: WARNING: Last price for AXP not found. Using yesterday's closing price of 259.0 instead. reqId = 10007
2024-09-16 19:35:09,464: root: WARNING: Last price for KO not found. Using yesterday's closing price of 71.41 instead. reqId = 10008
2024-09-16 19:35:09,467: root: WARNING: Last price for CVX not found. Using yesterday's closing price of 140.61 instead. reqId = 10009
The text was updated successfully, but these errors were encountered: