question

Upvotes
Accepted
4 1 2 1

c# COM API: Clear registered Items and Register New items

Following on from your Tutorial 2 (https://developers.refinitiv.com/eikon-com/eikon-desktop-data-api/learning?content=791&type=learning_material_item ) How would I go about unregistering items being streamed and adding new ones?

Working with the example code you provide (https://developers.refinitiv.com/system/files/downloadable/EikonDesktopAPI%20-%20Realtime%20Data%20-%20Tutorials.zip?download_item_nid=9072&destination=node/634/downloads%3Fdownload_item_nid%3D9072)

I modified the main function to become:


static void Main(string[] args)
        {
            Program p = new Program();
            Console.ReadLine()
            p.AdxRtList.StopUpdates();
            p.AdxRtList.UnregisterAllItems();
            p.AdxRtList.RegisterItems("GBP=", "BID");
            p.AdxRtList.StartUpdates(RT_RunMode.RT_MODE_ONUPDATE);
        }


After the `Console.Readline();` line I get the following Runtime error on the `p.AdxRtList.StopUpdates();` line:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'ThomsonReuters.Interop.RTX.IAdxRtList'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{057B736E-03DF-11D4-99C8-00105AF7EDAD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
  Source=mscorlib
  StackTrace:
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at ThomsonReuters.Interop.RTX.IAdxRtList.StopUpdates()
   at EikonDesktopDataAPITutorial2.Program.Main(String[] args) in *************\Tutorial 2\EikonDesktopDataAPITutorial2\Program.cs:line 56

I am obviously doing something wrong. How are you supposed to do this correctly?


Thanks


eikoneikon-data-apieikon-com-apic#
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
39.4k 77 11 27

My mistake. Thanks for clarification.

I looked into the issue deeper and was able to reproduce it. The reason for the exception is rooted in COM threading architecture. By default the main thread in a console application is created using multi-threaded apartment model. All Eikon COM APIs libraries are apartment threaded. When a multi-threaded apartment in your console application creates an instance of an Eikon COM APIs class, COM spins up a single-threaded apartment model "host" thread in the client application. This host thread will create the COM object, and the interface pointer will be marshaled back to the application's multi-threaded apartment. The E_NOINTERFACE error is raised when COM cannot find a way to do this marshaling, which in this case is due to Eikon COM APIs libraries being implemented as regfree COM.

When using Eikon COM APIs it is very strongly recommended to dedicate a thread that uses single-threaded apartment model and that will house all Eikon COM APIs objects. In a GUI application this will typically be the GUI thread. In a console application or a class library this should be a dedicated STA thread that also runs Windows message pump (otherwise Eikon COM APIs objects won't be able to raise events).

If the data you need is limited to streaming market data and timeseries of price history, then indeed I'd recommend using Eikon .NET APIs. If you also need fundamental and reference data, then you have to use legacy Eikon COM APIs or more modern Eikon Data APIs. All three: Eikon COM APIs, Eikon .NET APIs and Eikon Data APIs can be used in the same application in any combination, although there's probably never a case to use all three.

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.

Thank you for your very detailed answer. I am new to both C# and Refinitiv. Still getting my head around the basics. As you suggest I think I'll end up using the .NET APIs along with the Eikon Data APIs. It took me a while to realize many APIs can do the same thing. I hadn't realized the COM APIs were considered legacy.


Thanks for your help

Upvotes
39.4k 77 11 27

@ben.jourdan

The modification you made breaks the event based logic of component instantiation in the example. The example first initializes EikonDesktopDataAPI object. Then OnStatusChanged event of EikonDesktopDataAPIClass is used to ensure EikonDesktopDataAPI object is fully initialized and connected to Eikon. Only then AdxRtList object can be created. With the modifications you made you're trying to use AdxRtList object before it has been created and fully initialized.

On a separate note you don't need to unregister items to be able to register new ones. RegisterItems method of AdxRtList can be called at any time to add new items to the watchlist without first unregistering items currently in the watchlist. In other words the action of registering new items and unregistering the items you're no longer interested in are independent.

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 Alex,

Sorry I don't think I explained everything properly. The purpose of the Console.Readline() was so I could wait until I had started seeing updates come in before continuing. Alternatively I've been using

`System.Threading.Thread.Sleep(10000);

10 seconds is surely more than enough time to ensure EikonDesktopDataAPI has been fully initialized and connected and the AdxRtList object has been created right? After about 5 seconds I start seeing updates on the console so AdxRtList must have been created.

Because of this I don't think this error is due to AdxRtList not being instantiated.

Using the following main also gives a similar error:

        static void Main(string[] args)
        {
            Program p = new Program();
            System.Threading.Thread.Sleep(10000);
            p.AdxRtList.RegisterItems("EUR=", "BID");
        }

Could the issue be to do with anything else?


Thanks

Starting to think this may not be the best API to be using. I want to pull real-time data to compute things like NAV and also do some historic data processing. Is the COM API my best option. I've started having a look at the .Net one and that looks like it has far more documentation, examples and I can see how to do the equivalent of registering and deregistering items. Why would I use the COM API instead?

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.