-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
order gets lost #66
Comments
Hi @disaster123 , I do not see any obvious problems with the script you shared and my experience says it should work fine. A few steps you could use to debug are
Would be helpful if you can share more relevant code and even more detailed logs. Happy to help. |
Thx. |
I would suggest to use events rather than a blocking loop right after placing your orders. the reason you need to Something like this should work def on_fill(trade,fill):
orderok = True
print("IBKR: orderstatus.status: %s" % (trade.orderStatus.status))
orderok = False
trade = Ibkr2.myib.placeOrder(contract, order)
trade.fillEvent.connect(on_fill) notice that the ordering notebook is using trade = ib.placeOrder(contract, order)
while not trade.isDone():
ib.waitOnUpdate() which does not block the event loop Always follow The One Rule |
@gnzsnz thanks for your suggestions and help. Some questions.
isn't a race possible in this case? - so the order is filled before the event is attached? Also Submitted is OK to me as well. I had waitOnUpdate used in the past but there were problems with it - for example that if there i no event the loop neber proceed. For example trade goes to Submitted and than nothing happens - your loop blocks. |
A couple things can happen: I've seen orders go directly from You can subscribe to also just There is currently a bug where if you submit an order modification which is rejected (update has a bad price or rejected algo settings), the trade gets deleted from your client and won't show up until a restart even though it's still live ( After you place your trade, the trade status and event handlers can't run again until you wait with a proper sleep or another Also, it all depends on your own system design and program logic. You should also subscribe your entire ib client to status and error events (also documented at the usual place. If your trade fails to work the first time, it won't exist for any status updates. You probably want None of this is simple or easy to get right without a lot of testing in various live situations, so just keep trying on maybe a test/sandbox account or low value trades until it starts working as expected. |
it's possible that the order is filled before, but I have never seen it to actually happen. on my code i use transmit=False, then i attach the event, then submit again with transmit=True, but because my trade logic depends on this and i want to be 300% sure. But i never use it on my "quick tests" because it just never happens. not sure what could be your problem with waitOnUpdate, personally I never use it. take into account that if you code is blocking, is possible that you are blocking waitOnUpdate as well, that's why i suggested The One Rule. the original name of this project was great, because it's "insync". from the surface it looks synchronous, but it's just an appearance. |
That's actually an interesting use case. Maybe we could allow the order API to also take an empty Given the way the event loop works, between Another issue with the event system is it doesn't queue events. Events are either fired against active listeners or dropped forever. We may want to eventually explore allowing certain events to "queue up" until consumed by an event handler (I currently get around this by having my event handlers set their own |
we could add a parameter async def trade_fill_event_handler():
your code here
trade = ib.placeOrder(contract,oder,fillEvent=trade_fill_event_handler) but to be honest, they way it is right now is fine with me. |
Hello,
i'm using the following code to place an order:
While the output is:
This order does not show up in ibkr client and was never executed nor is it in pending orders. This happens frequently...
Greets,
The text was updated successfully, but these errors were encountered: