ib.placeOrder AssertionError #580
Replies: 4 comments 2 replies
-
Are you sure about that? Are you're not somehow reusing an older Order object? |
Beta Was this translation helpful? Give feedback.
-
Are you re-using the opening order object to send it as closing order? |
Beta Was this translation helpful? Give feedback.
-
That new LimitOrder can't trigger the assert exception. The assert is raised when an already finished order is placed again. |
Beta Was this translation helpful? Give feedback.
-
It may be that I didn't manually cancel via TWS each order for which the ib.placeOrder AssertionError occurred (before the code line for ib.cancelOrder would have gotten executed), such that there could have been an existing, non-cancelled GTC limit order placed for some cases where the AssertionError occurred. |
Beta Was this translation helpful? Give feedback.
-
Dear ib_insync community:
In recent days, in particular outside 9am-5pm ET, my ib_insync trading script tends to crash on ib.placeOrder AssertionError, per below:
`close_order LimitOrder(action='SELL', totalQuantity=1, lmtPrice=0.038, tif='GTC', eTradeOnly=False, firmQuoteOnly=False, account='__')
AssertionError Traceback (most recent call last)
in [..]
177 print(f"close_order {close_order}")
--> 178 close = ib.placeOrder(ac, close_order)
~\anaconda3\lib\site-packages\ib_insync\ib.py in placeOrder(self, contract, order)
643 if trade:
644 # this is a modification of an existing order
--> 645 assert trade.orderStatus.status not in OrderStatus.DoneStates
646 logEntry = TradeLogEntry(now, trade.orderStatus.status, 'Modify')
647 trade.log.append(logEntry)
AssertionError:
`
The same code has worked fine previously, and still works reliably at least during liquid trading hours. There is nothing complex/advanced with the code placing the closing order. However, some of the attempted closing orders are made inactive by the broker due to margin requirements (which increase overnight), though mostly the order is just rejected, and the execution of the code resumes, without crashing, on the next line.
Regarding the ib_insync code comment # this is a modification of an existing order, the trading code only places an independent new order, and does not, itself, seek to modify any other/existing order.
How to get the code to return graciously from a (rejected?) placeOrder, and resume execution on the next line?
Beta Was this translation helpful? Give feedback.
All reactions