Skip to content

Commit fd18e4c

Browse files
committed
Fix order preview reporting for more order types
This has been broken for years and it was finally tracked down thanks to contributor in #42. Problem was just the value we compared against is the raw IBKR API protocol value, but the comparison was expecting a parsed standard max float value we use everywhere else. Solution is just to parse the inbound float so it becomes a native value to compare against first. The impact of the problem was `whatIf` orders only worked for limit orders previously. Attempting to run a preview `whatIf` order on other order types always just returned bad values and couldn't show previews and wouldn't report potential commission or margin impacts. Now the `whatIf` orders run and execute fully so the caller receives a completely populated `OrderState` object with all fields properly populated. According to the API patterns, these fields are _always_ numeric from the API (which is why IBKR just uses "max float" to mean "no data") so we should _always_ be able to `float()` parse the field without any problems. If the API ever returns non-float-data then this will obviously do weird things, but so far the upstream IBKR API doesn't appear to be able to inject non-float values into these fields. Fixes #42
1 parent 4a10847 commit fd18e4c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ib_async/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def openOrder(
495495
"""
496496
if order.whatIf:
497497
# response to whatIfOrder
498-
if orderState.initMarginChange != str(UNSET_DOUBLE):
498+
if float(orderState.initMarginChange) != UNSET_DOUBLE:
499499
self._endReq(order.orderId, orderState)
500500
else:
501501
key = self.orderKey(order.clientId, order.orderId, order.permId)

0 commit comments

Comments
 (0)