Modify Order with ib_insync (Python, TWS - IBKR)

495 Views Asked by At

I am trying to modify an existing order in my tws with ib_insync.

My code looks like this:

for pos in ib.openOrders():
    if pos.orderId == l_TakeProfitOrder['orderId']:
        takeProfitOrder = pos
    if pos.orderId == l_StoppLossOrder['orderId']:
        stoppLossOrder = pos
print(TakeProfitOrder)
print(takeProfitOrder)
quantity = takeProfitOrder.totalQuantity
takeProfitOrder.auxPrice = round_nearest(takeProfitOrder.auxPrice + 0.2, 0.1)
print(takeProfitOrder)
ib.placeOrder(contract, takeProfitOrder)

And the output is the following:

StopOrder(orderId=7694, clientId=5, permId=871591821, action='SELL', totalQuantity=10.0, lmtPrice=0.0, auxPrice=-1.6, ocaGroup='0_DTE_BPS_2023.06.09 21:20', ocaType=1)
StopOrder(orderId=7694, clientId=5, permId=871591821, action='SELL', totalQuantity=10.0, lmtPrice=0.0, auxPrice=-1.6, ocaGroup='0_DTE_BPS_2023.06.09 21:20', ocaType=1)
StopOrder(orderId=7694, clientId=5, permId=871591821, action='SELL', totalQuantity=10.0, lmtPrice=0.0, auxPrice=-1.4, ocaGroup='0_DTE_BPS_2023.06.09 21:20', ocaType=1)

And then I get the erorr message:

Error 105, reqId 7694: Order being modified does not match original order.

So even though, I am loading an existing order and only modifying the auxPrice I get the error that both orders do not match.

I would really appreciate some help here :) Thanks in advance!

I am trying to modify an order with ib_insync but I get an error message

1

There are 1 best solutions below

0
On

Something changed on the API lately, when you request the order you get more information than before. What I did in my own code to make it work was just to:

  1. extract the relevant information (in my case) from the existing order (orderId, action,totalQuantity,orderType, auxPrice and ocaGroup) and save it as an order.
  2. modify the auxPrice on the new order
  3. place the order

Cheers,