websocket order update messages not received several hours after subscription.
Describe the bug
when I subscribe orders channel, initially I can receive the order update messages. but after several hours, I can't receive the messages any more.
Steps to Reproduce
Steps to reproduce the behaviour:
- subscribe order channel
- create a limit order, I can receive the realtime order update message now.
- 7 hours later, the order is filled, but there's no update messages received.
Expected Behaviour
I can always receive the realtime messages as long as the connection is there.
Additional context
I am trying to monitor my order status, and create new orders when my old order is filled.
Possible Solution
https://www.interactivebrokers.com/campus/ibkr-api-page/cpapi-v1/#ws-ping per this doc, it is need to ping the channel every minutes to keep channel actually alive.
Your Environment
- IBind version: 0.1.19
- Python version (e.g. 3.10): 3.10.12
- Authentication method (Gateway, IBeam or OAuth): IBeam
- Operating System and version: Ubuntu 22.04.4 LTS
- Link to your project/code (if public) :
hey @simpzan thanks for the detailed bug report 👍
The behaviour you're observing seems in line with the filtered /orders endpoint (live_orders(filters=...) method) polluting the Live Order Updates WS channel. In short, if you call /orders with filters parameter specified, it stops the Live Order Updates WS messages, see doc:
Please be aware that filtering orders using the /iserver/account/orders endpoint will prevent order details from coming through over the websocket “sor” topic. To resolve this issue, developers should set “force=true” in a follow-up /iserver/account/orders call to clear any cached behavior surrounding the endpoint prior to calling for the websocket request.
To rule out this cause, can you check in your code if you're ever calling live_orders(filters=...) anywhere in your code base? If that is the root cause, I'll be able to assist you in solving it elegantly.
I called live_orders, but filters parameter is not used. Following is my code.
def list_live_orders(self, reverse=False):
resp = self.client.live_orders(account_id=account_id)
orders = resp.data['orders']
orders.sort(key=lambda x: x['lastExecutionTime_r'], reverse=reverse)
return orders
The issue is not reproduced if I call this new IbkrWsClient.tic() method every minute.
https://github.com/Voyz/ibind/compare/master...simpzan:ibind:master
@simpzan that's very useful. Do you also call REST /tickle endpoint apart from sending that 'tic' payload?
@Voyz No, I didn't call tickle in my own code. But ibeam docker seems will call it regularly.
Right, so what seems to have worked for you is having IBeam call /tickle and have your system call that 'tic' regularly, right? That's useful to know. I've released 0.1.21rc3 with 'tic' included in case you'd like to try it out