Replies: 4 comments 2 replies
-
Hi Matt, thanks for bringing this issue to our attention - I wasn't aware that -1 was the default for unset prices! I usually see 'nan' when using ticker.marketPrice() and the market is closed... As someone who trades spreads and regularly deals with negative prices, I agree we should move away from -1. Your idea of setting a parameter at startup is a good one, and will allow flexibility for everyone. Keep us posted please! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
thanks for bringing this for discussion. I agree that https://stackoverflow.com/questions/6601812/sending-nan-in-json |
Beta Was this translation helpful? Give feedback.
-
Added some attempts at the change here (along with other updates) https://github.com/ib-api-reloaded/ib_async/tree/next — feel free to look / review / test / feedback. All the details are in the expanded commit messages for now. It's on a temporary branch so we can still change anything before it hits a wider audience. I've been running this most of this week and everything has worked nicely so far. |
Beta Was this translation helpful? Give feedback.
-
I was looking around more of the internals, and I found where unset prices are defaulted to
-1
which has always caused problems in my code everywhere (because with spreads, negative prices are valid and it's annoying to check if-1
is an error or a valid credit price!)How does everybody else think the change would impact their current systems if instead of reporting unknown prices as
-1
(during after hours, unpopulated quote tickers, live bids or asks with no volume) we instead moved to havingbid=None, ask=None
(instead ofbid=-1, ask=-1
)?I guess we could also make it a runtime option to have a "default price" setting somewhere so you could switch between -1, None, or even
nan
if you wanted to (or your own "UnknownPrice" class).We'd make a new major version number for the breaking change (though, if we make it configurable no breaking change needed), but I think it would reduce the number of math bugs I've run across over the years from accidentally averaging a
-1
bid into a valid ask for example.If anybody wants to test their own code on the change locally, the line to update is here and it should turn-1
unknown prices intoNone
everywhere:ib_async/ib_async/wrapper.py
Line 870 in 38cf54a
Update: so that's not where the value is set. It's set in a couple places, but I've found out how to make all the
NaN
values go away and turn into something else. I already added the fix to my own cli project and it's working as expected (only took two hours of refactoring all my accidental math against-1
s everywhere (mostly in quote displays on startup as Ticker values load in async over a couple seconds)).Current idea is just a parameter to
IB()
asIB(defaultEmptyValue=None)
which will allow people to change the default behavior ofIB(defaultEmptyValue=float('nan'))
.In other news, I found some un-parsed tick types for extra streaming data I've enabled for my own testing (last trade timestamp, stock average volumes over 3, 5, 10 minutes). If those keep working for me I'll add those soon along with additional error handlers so we notice missing tick types sooner.
Beta Was this translation helpful? Give feedback.
All reactions