Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 1 0 1

How to use onDataReceived callback function

Hi,

I'm trying out your .Net API (nuget package). I'm wondering how to await the callback onDataReceived function? The DataReceived function never gets hit. It is a sample console app. Below is my code:

public void Launch()
        {
            var realtime = DataServices.Instance.Realtime;
            counter = 0;


            _singleRequest = realtime.Request("GBP=", "BID", DataReceived);


            _singleSubscription = realtime.Subscribe("EUR=", "BID", DataReceived);
        }


        private void DataReceived(SingleFieldValue value)
        {
            Console.WriteLine("{0}:{1}({2}) {3}",
                counter,
                value.Ric,
                value.Field,
                value.RawValue);


            counter += 1;


            if (counter == 5)
            {
                _singleRequest = null;
                _singleSubscription.Stop();
                _singleSubscription = null;
                Console.WriteLine("Stopped");
            }
        }
eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api.net
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.

@maboobackerIs the reply below satisfactory in resolving your query?

If so please can you click the 'Accept' text next to the appropriate reply.

This will guide all community members who have a similar question.

Thanks,

AHS

Upvotes
Accepted
39.4k 77 11 27

@maboobacker
In addition to comments by @Zhenya Kovalyov make sure that Windows message pump is running on the thread housing Eikon .NET API objects, otherwise the objects will not be able to raise events. In a Winforms or WPF application Windows message pump is automatically started on the GUI thread. In a console application you need to explicitly kick off Windows message pump and make sure it keeps running as long as your application needs to retrieve data from Eikon. For an example download one from this tutorial.
And one other thing. We very strongly recommend you keep all your data retrieval from Eikon on a single thread.

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
4.6k 26 7 22

@maboobacker could you confirm that Eikon is running please? If yes, there might be some sense to subscribe OnError event as well to see why you are not receiving anything.

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
3 1 0 1

Thanks for the reply. key is Eikon should be running in the same machine where the application runs which I came to know only after conversing with your technical team.

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
2 5 0 3

Eventually any idea how to make it work? I'm not able to retrieve the values still

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.

yes, I have the same problem. And not sure, how to tackle it really. An example application, where Eikon .net Api is in a dll.

Upvote
39.4k 77 11 27

@tt1057, @mariosan28
As explained in the accepted answer on this thread, what you need to do is to ensure that Windows message pump is running on the thread housing Eikon .NET API objects. If you're creating a single threaded GUI application, then you don't need to do anything special. Even if you're creating a dll, as long as that dll will only be used on the GUI thread, you're covered. If however your dll may be called by a non GUI thread, then you do need to manage Windows message pump in your dll. Attached is one way of doing it, which I used to create a dll in one of my projects. The attached module implements EikonConnection class, which deals with Windows message pump. EikonConnection class creates an instance of EikonJobHost class, where you can do your work related to retrieving data from Eikon: initialize an instance of DataServices, manage connection state, create real-time data subscriptions etc. EikonJobHost is created on the thread running Windows message pump, which ensures that Eikon .NET API objects created on the same thread within EikonJobHost are able to raise events.
eikonconnection.zip


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
65 3 2 8

thank you Alex. Could you give me a little example for the EikonJobHost class? And how would I get data out of that class then?

and my VS2017 cannot find the reference to:

IEikonDataServiceStateChangeCallback
and what do you reference to to get:

Application

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
65 3 2 8

@Alex Putkov. does Refinitiv offer coding service? So, basically, I send you what I got in c#, and you implement the Eikon SDK in there?
I guess it should only be a few hrs work.

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
39.4k 77 11 27

@tt1057

  • No, we're not offering custom software development services.
  • Application is a member of System.Windows.Forms namespace.
  • IEikonDataServiceStateChangeCallback is a custom interface, which allows the event triggered by changes in Eikon .NET API DataServices connection state to be propagated to your application. Here's the code implementing this interface.
public interface IEikonDataServiceStateChangeCallback
{
   /// <summary>
   /// Defines a callback used to receive Service State message.
   /// </summary>
   /// <param name="state">State string received from Data Service</param>
   void OnStateChanged(string state);
}
  • It makes no sense for me to share with you my full implementation of EikonJobHost class, as this is where the business logic of your data retrieval from Eikon goes. You could for example copy & paste the code from UsageExample.cs module from the example in Real-time data retrieval tutorial. You will just need to modify the output code, as this example is a console application, which uses Console.WriteLine method to provide output. It's possible that some other minor modifications may be required. Here's an excerpt from EikonJobHost class containing the constructor and the event handler for the connection state change event.
public class EikonJobHost 
{
    private readonly IEikonDataServiceStateChangeCallback eikonDataServiceStateChange;
    /// <summary> 
    /// Class constructor of EikonJobHost 
    /// </summary> 
    /// <param name="applicationKey">String of Key value, usually the name of the application</param>
    /// <param name="EikonDataServiceStateChange">Application defined function to handle connection status changes</param>
    public EikonJobHost(string applicationKey, IEikonDataServiceStateChangeCallback EikonDataServiceStateChange)
    {
        this.eikonDataServiceStateChange = EikonDataServiceStateChange;
        DataServices.Instance.Initialize(applicationKey);
        DataServices.Instance.StateChanged += new EventHandler<DataServicesStateChangedEventArgs>(DataServicesInstance_StateChanged);
    }


private void DataServicesInstance_StateChanged(object sender, DataServicesStateChangedEventArgs e)
{
    this.eikonDataServiceStateChange.OnStateChanged(e.State.ToString());
}
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.