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
This is a fairly big change for usability, but it shouldn't change
behavior unless you opt-in to new values yourself.
IBKR uses a strictly typed API where integer fields can only send
integers and float fields can only send floats and string fields can
only send strings.
This is why, in some places, IBKR uses FLOAT_MAX of
"1.7976931348623157e+308" to mean "no data available" while in other
places IBKR uses "price=-1, size=0" to mean "no data available," and
historically ib_insync has also uses `nan` to mean "field is not
initialized with API data yet."
So there are potentially 4 different ways to check if data is not
actually real data. This causes more problems when people are being lazy
(and who isn't?) when just using price data, but price=-1 when price is
missing (and many negative prices _are_ valid when using credit
spreads), so it can cause actual problems.
Now we have a way to request different defaults.
The `IB()` constructor now takes an optional argument as:
```python
ib = IB(IBDefaults(
emptyPrice=None,
emptySize=None,
unset=None,
timezone=pytz.timezone("US/Eastern")
)
```
Providing an `IBDefaults()` object will overwrite the IBKR defaults of
`emptyPrice=-1, emptySize=0, unset=nan, timezone=datetime.timezone.utc`
with your own defaults.
You can technically set any value there, but it's your own fault if you
set `emptySize=3` or something awful on your own.
You can be even more explicit and define your _own_ empty objects or
enums to represent empty data too. Just make sure if you do use things
like `None` for price, you run your checks as `price is not None`
because for certain spread opportunities, prices _can_ be valid limit
prices to execute (so `if price:` would fail a valid price of `0`).
This is currently still undergoing more testing, but it works so far for
me (and it's nicer having timestamps in my own exchange timezone instead
of utc when printing tickers and order event logs everywhere).
We may add another couple default types to allow removing `UNSET_DOUBLE`
from showing up in user API output anywhere too.
0 commit comments