Skip to content

Commit 362132f

Browse files
committed
Prevent an easy to trigger order modification bug
I've hit this error for a long time and it's probably better to place the workaround directly as an API-level bug fix instead of everybody needing to check for this bug on their own. The problem is potentially our cached order objects let the IBKR API overwrite fields we didn't set on our own (so when we go to submit order updates on cached order objects, we submit data we never set ourselves). The fix for the IBKR API overwriting our own order fields is probably to create a secondary "IBKR Updated Order Metadata" object attached to our real orders so the API updates don't conflict with a user's own exact order data, but that's more work and this quick fix solved this order update problem for now (along with the error handler validation check fixes). There is one other big order placement bug where if you order a spread using limit order adaptive fast/slow, the IBKR API changes the order type to IBALGO, but you _can't_ submit order updates with IBAGLO as an `orderType` yourself (I'm not sure if you can ever use it?) so also I have other bug fixes where "orderType = 'LMT' if orderType == "IBALGO" else orderType", but I'm not sure if that is also a universal problem in need if fixing for _everybody_ yet.
1 parent 69b920d commit 362132f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ib_async/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,16 @@ def cancelMktData(self, reqId):
472472

473473
def placeOrder(self, orderId, contract, order):
474474
version = self.serverVersion()
475+
476+
# IBKR API BUG FIX:
477+
# IBKR sometimes back-populates the 'volatility' field into live orders, but then if we try to
478+
# modify an order using cached order objects, IBKR rejects modifications because 'volatility'
479+
# is not allowed to be set (even though _they_ added it to our previously submitted order).
480+
# Solution: if an order is NOT a VOL order, delete the 'volatility' value to prevent this error.
481+
if order.orderType != "VOL":
482+
# ONLY volatility orders ("VOL") can have 'volatility' set when sending API data.
483+
order.volatility = None
484+
475485
fields = [
476486
3,
477487
orderId,

0 commit comments

Comments
 (0)