Hi all, In my app I have used streaming to get the data and use asyncio to do the calculation process when got an event sometimes it's still do the refresh event process but it's got update event usually it's must finish the refresh event first then do the update event but in my case it's doesn't finish refresh event it swaps to update event. Is this normal? because from my understanding I must use await in my app to swap to other tasks but my app didn't use any of it. here below is example of my code
I am not sure I fully understand your question.
Also, I am not a Python expert so cannot confirm how the asycnio task will be actioned or shutdown etc - nor can I advise on general Python 'multi-threading'.
The key point I am making is that you are dealing with live streaming data - so it is entirely possible to receive an update for an instrument before you have finished processing the Refresh.
Depending on how long your Update related calculations take, it is also entirely possible that you could receive a further update, whilst you are still processing the previous update.
For something like Java or C++, the developer could spawn off a worker thread to process the RefreshMsg leaving the main (API) thread to continue receiving and handling the Update - with some strategy to ensure that any subsequent update does not disrupt or corrupt any ongoing calculations on the same instrument still being performed on the Refresh or previous update.
You need to redesign your code so that the calculations are not done in the callback (on_data_refresh, on_data_update). For example, rather than performing any Refresh or Update calculations in the callback function - you add data to a queue and return control back to the RDP library. You could then have a separate 'thread' processing the queue? Again - not a Python expert so not sure how appropriate this is?
Not sure I fully understand your question but I will try...
Are you subscribing to multiple instruments and expecting to complete all refresh calculations for all the instruments before processing their updates? Or are you subscribing to a single instrument?
The streaming data events are delivered asynchronously - as and when there is market activity.
So, if you are spending considerable time processing the Refresh and during that time there is some market activity e.g. a price change, then you would expect to receive an update to reflect that price change.
As explained above, since the data is sent as per market activity - you can receive update events before you have finished receiving/processing Refresh events for all your instruments.
Perhaps you can consider using the Cache functionality of RDP Streaming - where you can choose when to snap the values from the cache that is maintained by the RDP library