question

Upvotes
Accepted
5 1 2 7

How to retrieve currency exchange rate in a snap time using Elektron service?

The QuickStartConsumer example code retrieves market price for given currency RIC as a stream of data. The data keeps on coming as a response event and displayed on console. How do I retrieve a market price at a snap of a time? Are there any examples for this method, like if I want to retrieve current exchange rate for GBPINR on click of a button?

refinitiv-realtimeelektron-sdktreprfarfa-apiricssnapshot-pricing
icon clock
10 |1500

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

Upvote
Accepted
20.3k 73 10 20

Hi @anil.s

I recommend you work through the tutorials - as this will give a good overview of how RFA works including dispatching, connection events etc and most likely save you time in the long run.

As mentioned previously QuickStartConsumer is a very basic example.

You will initially get 'Source unavailable' because you have made a connection request, sent a Login request and an item request immediately after each other. i.e. requesting an item before you are fully connected and logged in and so the API is just letting you know that the source you are requesting data from is not yet available.

Just remember that RFA.NET works asynchronously - i.e. you send your requests and the responses arrive asynchronously.

Therefore, if you were to wait till the connection was made and successful Login - before sending the item request then you should not see the 'Source unavailable' message - assuming the service was up and running.

With regard the dispatching, you should really be dispatching continuously. This will ensure your application receives any relevant events such as logged out, service down, connection lost (assuming you have registered interest in connection events - which you should). You can use this information to keep your application user informed of the login / connection status etc.

icon clock
10 |1500

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

Yes I did the same thing. I separated the login dispatch part and market request dispatch part in two separate events. Should be ok for me now.

Upvotes
20.3k 73 10 20

Hi @anil.s

Are you using EMA or RFA.NET - please confirm?

I will assume you are using RFA.NET based on the example name and your earlier questions...

If you don't want streaming data - only snapshot - then remove the

ReqMsg.InteractionTypeFlag.InterestAfterRefresh

from ReqMag.InteractionType when making the GBPINR item request.

So, for your click button scenario you would need to make the item request i.e populate the ReqMsg and call RegisterClient etc, when the button is clicked.

As it is a snapshot request, the item stream will be closed by the API once it has provided the InitialImage (i.e. snapshot). So, you will need to re-request it each time someone presses the button.

It is also possible to pause and resume the stream, i.e. pause the stream once you get the rate and resume when someone clicks the button and then pause again as soon as you get the rate and so on....

icon clock
10 |1500

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

Yes, I am using .NET and it's in continuation with my efforts related to earlier questions. :)

Thanks for the details. Do I need to do below things each time user clicks on "RefreshRate" button:

a. Initialize RFA
b. Create EventQueue
c. Create consumer object
d. Acquire session
e. Login
f. Register event
g. Call ommConsumer.RegisterClient() method for requried RIC
h. Unregister event
i. Destroy and release

Can I do a to e when app starts & just do g on click of a button, followed by h to i when app ends? Does the session persist so log, say for 10 hours or so once acquired?

Upvote
20.3k 73 10 20

Hi @anil.s

You only need to call registerClient for the required RIC each time you want a snapshot.

You don't need to re-initialise RFA, create queue, Login etc each time.

Also, as mentioned - when making a snapshot request, the API will close the event stream once it has delivered the Image/Refresh - so you don't need to call unregisterClient for the RIC item each time.

You should only need to call unregisterClient for the Login Handle, release, destroy - i.e. the cleanup code when you terminate the application.

So, yes you are correct in your last sentence about what to do at startup, each button click and for shutdown.

The session should persist indefinitely, unless connectivity is lost or planned/unplanned Elektron Server downtime etc. Even when connection is lost etc, the API will attempt to re-establish a connection on your behalf when possible. Please refer to the documentation for further details on recovery / retry etc.

NOTE: The QuickStartConsumer is a very basic example and therefore should not be used for production purpose. I recommend you work through the RFA.NET tutorials and also refer to the RFA C++ tutorials for additional guidance - and use what you learn to write your own application.

For example the QuickStartConsumer uses local data dictionary files - which is not advisable for a production application - as they change quite often. You should really download these from the server - as demonstrated in the RFA C++ Tutorial Step 10.

You can also refer to the fuller RFA.NET Consumer example for code which demonstrates how to download the dictionary.

Tutorials

RFA C++ Tutorials

RFA.NET Tutorials

icon clock
10 |1500

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

After removing the InterestAfterRefresh attribute, I am able to get the rates only once as needed. However, to achieve this I must set the dispatch interval to more than 10.

System.DateTime endTime = currentTime.AddSeconds(25);

Because, every time I run the code with lesser dispatch interval (like 5 or 10), it takes atleast 2-3 dispatch calls for getting the response with market rates. For first couple of times, it always gets response as "Source unavailable... will recover when source is up". Is there any reason why it gets such response every time for first couple of dispatch calls?

Click below to post an Idea Post Idea