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
Best Answer
-
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.
0
Answers
-
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.
0 -
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
0 -
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?
0 -
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
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 682 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 626 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 83 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛