Delayed data from futures stream - any ideas?

I’ve been struggling with an issue for a little while, I’m quite new to coding and so if anyone can help me understand why this might be happening I would really appreciate it.

My script is running on a Raspberry pi 4 using Ubuntu and connects to:


Using websocket:

ws = websocket.WebSocketApp(SOCKET, on_open=on_open,
                            on_close=on_close, on_message=on_message, on_error=on_error)

After some time, normally within 24 hours, the data being received can become significantly delayed… The candle data is sometimes from 5-10 periods in the past…

Thanks for any help with this.

With this info, I’m not so sure what is the root cause of delay but at the time I checked, the server looks fine on our end.
Probably you can also check from your end if on_message is a blocking method. If you always have to wait for the completion of all processes in the method, the next data might be delayed.

Is there a way to receive less frequent responses from the endpoint? The futures stream delivers updates roughly every 200-300ms, is there an easy way to only get an update every 1000ms?

So far there is no such option provided. You can tried to introduce some buffer and clear the data periodically to achieve it.

Now it turns much clearer. Your instances might share the same resources together and they may have to stop and wait for execution. When you connect to more endpoints, the amount of data increases but the resource is the same. Hence, it takes longer time to process.

I think here are some points that may be helpful for your situation:

  1. utilize async programming
    on_message function is complicated and it may have to wait for the result of order API call. That means the program can only process one data tuple at a time and the extra waiting time for the new orders causes the delay. If the program can be adapted to async, the waiting time will be decreased.
  2. reduce unnecessary I/O
    There are quite a lot of the printing operation involved in the code. I/O is actually a time consuming operation. Remove the unnecessary ones can shorten the processing time.

Btw, this forum is for API discussion. Please avoid asking programming question, thanks.

1 Like

Okay thanks for the advice.

One thing I have noticed when troubleshooting is that if I have only 1 instance of my script running, this issue does not happen… but if I have my device connected to more than 1 endpoint, then the data becomes delayed. Does anything come to your mind about why that might be?

Okay thank you for the tips.