question

Upvotes
Accepted
5 0 0 3

About RDP streaming event

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

1637216616539.png

rdp-api
1637216616539.png (34.8 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
25.3k 87 12 25

Hi @nuttanon.jitsamran

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?


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
25.3k 87 12 25

Hi @nuttanon.jitsamran

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.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @umer.nalla

Yes, I'm expecting to complete all refresh calculations for all the instruments before swapping to do the update event. right now my app just discards the refresh event before it finishes and does the update event instead.

Upvote
25.3k 87 12 25

Hi @nuttanon.jitsamran

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

Example.RDPLibrary.Python/2.3.2 - Content - StreamingPrices - As a cache.ipynb at master · Refinitiv-API-Samples/Example.RDPLibrary.Python (github.com)


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
5 0 0 3

Hi @umer.nalla

So it's mean that if my calculation process from refresh event took too long and In a meanwhile app got the update event. It's shutdown the asyncio task from refresh event to do update event am I right?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
5 0 0 3

Hi @umer.nalla

Thanks for the advice I'll try to redesign my code.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.