question

Upvotes
Accepted
5 4 2 5

Dex2 Sample - Create RData request C# to get "TR.CLOSE" or "CF_CLOSE" do not work

I am using the Dex2 sample (CSharpEikonnect). I have Eikon desktop version 4.0.36 running and no problems with steps 1 to 4 (Connecting to Eikon, Creating Dex2 Manager, Creating RData request…). In step 4 Request the Data does not work properly. What other commands I could use? I had a look at the Data Item Browser, but none of the commands there does return any results. Am I missing something? What I would like to do is to replicate the following:

privatevoid CreateRData(string InstrumentIDList,

string FieldList,

string RequestParam,

string DisplayParam)

{

// Create a RData

MyRData = MyDex2Mgr.CreateRData(MyDex2Cookie);

MyRData.OnUpdate += OnUpdate;

// Initialize the RData to request

if (MyRData != null)

{

MyRData.InstrumentIDList = InstrumentIDList; // “AAPL.O”

MyRData.FieldList = FieldList; // “TR.CLOSE” or “CF_CLOSE” or “CF_LAST”

MyRData.RequestParam = RequestParam; // “edate: -20d sdate: -9d”

MyRData.DisplayParam = DisplayParam; // “RH:In CH:Fd”

}

}

Thank you.

eikoneikon-com-api
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
Accepted
966 11 21 26

For reference data, you can reference DEX2.dll and EikonDesktopDataAPI.dll and use the following sample. The way to set up the call is different for these so called 'ADC' calls, where the fields are identified with TR.something. You will notice the mDexCookieADC.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EikonDesktopDataAPI;
using Dex2;


namespace DEX2ADC
{
    class Program
    {
        //******************************************************************************
        // class variables
        //
        EikonDesktopDataAPI.EikonDesktopDataAPI sdk;
        Dex2.Dex2Mgr d2m;
        Dex2.RData rdta;
        int mDexCookieADC;


        public Program()
        {
            mDexCookieADC = 0;
            //******************************************************************************
            // Create EikonDesktopDataAPI object and connect to its outgoing interface
            //
            sdk = new EikonDesktopDataAPI.EikonDesktopDataAPI();
            if (sdk != null)
            {
                EikonDesktopDataAPI.EEikonDataAPIInitializeResult l_result = sdk.Initialize();
                if (l_result != EikonDesktopDataAPI.EEikonDataAPIInitializeResult.Succeed)
                {
                    //Error Handling
                }
                //Add a handler to OnStatusChanged event
            }
            sdk.OnStatusChanged += OnStatusChanged;
            Console.ReadLine();//stop the command window closing and the program ending
        }//main end




        //******************************************************************************
        // what to do when the user logs on to Eikon
        //
        public void OnStatusChanged(EEikonStatus EStatus)
        {
            switch (EStatus)
            {
                case EEikonStatus.Connected://Eikon is now connected so we can start making the API call
                    CreateDex2Mgr();
                    //CreateRData("594918AY0=;36962G4J0=", "TR.IssuerRating;TR.GR.Rating", "", "RH:In CH:fd");
                    //CreateRData(".FTSE", "TR.IndexConstituentRIC;TR.IndexConstituentWeightPercent", "", "CH:fd");
                    CreateRData("NVDA.O", "TR.PRICEAVG100D;TR.PriceNetChg1D;TR.PriceMoRegionRank;TR.RSISimple14D;TR.CompanyName;TR.TRBCEconomicSector;TR.CreditComboRegionRank", "", "CH:fd");
                    break;


                case EEikonStatus.Disconnected:


                    break;


                case EEikonStatus.Offline:


                    break;
            }
        }




        //******************************************************************************
        // Create dex manager
        //
        private void CreateDex2Mgr()
        {
            d2m = sdk.CreateDex2Mgr();
            var d2mADC  = (IDex2Mgr2) d2m;


            if (d2mADC != null)
            {
                mDexCookieADC = d2mADC.Initialize(DEX2_MetadataCaller.DE_MC_ADC_POWERLINK);
            }
        }




        //******************************************************************************
        // Create RData object
        //
        private void CreateRData(string instrumentIdList, string fieldList, string requestParam, string displayParam)
        {
            rdta = d2m.CreateRData(mDexCookieADC);
            rdta.OnUpdate += OnUpdate;
            if (rdta != null)
            {
                rdta.InstrumentIDList = instrumentIdList;
                rdta.FieldList = fieldList;
                rdta.RequestParam = requestParam;
                rdta.DisplayParam = displayParam;
                rdta.Subscribe();
            }
        }




        //******************************************************************************
        // Data retrieved call back
        //
        public void OnUpdate(Dex2.DEX2_DataStatus dataStatus, object error)
        {
            switch (dataStatus)
            {
                case DEX2_DataStatus.DE_DS_FULL:
                    long i = 0;
                    long j = 0;
                    Array l_response = rdta.Data as Array;


                    for (i = l_response.GetLowerBound(0); i <= l_response.GetUpperBound(0); ++i)
                    {
                        long l_row;
                        l_row = i - l_response.GetLowerBound(0) + 1;
                        for (j = l_response.GetLowerBound(1); j <= l_response.GetUpperBound(1); ++j)
                        {
                            // error handling could be done here
                            Console.WriteLine(" " + rdta.Data[i, j]);
                        }
                        Console.WriteLine(Environment.NewLine);
                    }
                    break;


                case DEX2_DataStatus.DE_DS_NULL_EMPTY:
                    if (error != null)
                        Console.WriteLine("Error : " + error);
                    else
                        Console.WriteLine("Error : DE_DS_NULL_EMPTY");


                    break;
                case DEX2_DataStatus.DE_DS_NULL_ERROR:
                    if (error != null)
                        Console.WriteLine("Error : " + error);
                    else
                        Console.WriteLine("Error : DE_DS_NULL_ERROR");


                    break;
                case DEX2_DataStatus.DE_DS_NULL_TIMEOUT:
                    if (error != null)
                        Console.WriteLine("Error : " + error);
                    else
                        Console.WriteLine("Error : DE_DS_NULL_TIMEOUT");


                    break;
                case DEX2_DataStatus.DE_DS_PARTIAL:
                    if (error != null)
                        Console.WriteLine("Error : " + error);
                    else
                        Console.WriteLine("Error : DE_DS_PARTIAL");


                    break;
            }
        }


        static void Main(string[] args)
        {
            Program prog = new Program();
        }
    }//class end
}// namespace end


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
78.8k 250 52 74

From the code, I assume that you would like to retrieve the daily historical data of CLOSE field.

You can use .NET APIs to retrieve this information. Please refer to:

  • Usage Example Time series API from this page
  • Or, Time series tutorial from this page

The snippet code is:

tsDataRequest = timeSeries.SetupDataRequest("AAPL.O")
  .WithAllFields() 
  .WithInterval(CommonInterval.Daily)
  .From(DateTime.Now.AddDays(-20))
  .To(DateTime.Now.AddDays(-9)) 
  .OnDataReceived(OnTSReceived).CreateAndSend();


private void OnTSReceived(DataChunk chuck)
{
    Console.WriteLine("OnTSRecieved {0}", chuck.IsLast);
    foreach (IData record in chuck.Records)
    {
        foreach (var sample in record)
        {
            Console.WriteLine("{0} {1}", sample.Key, sample.Value);
        }
        Console.WriteLine();
    }
}

The output looks like:

HIGH 106
CLOSE 105.87
LOW 105.28
OPEN 105.58
VOLUME 27408650
TIMESTAMP 8/4/2016 12:00:00 AM
COUNT 147500


HIGH 107.65
CLOSE 107.48
LOW 106.18
OPEN 106.27
VOLUME 40553402
TIMESTAMP 8/5/2016 12:00:00 AM
COUNT 182161


HIGH 108.37
CLOSE 108.37
LOW 107.16
OPEN 107.52
VOLUME 28037220
TIMESTAMP 8/8/2016 12:00:00 AM
COUNT 143108
...

You may also refer to this question.

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 4 2 5

Hi and thank you for the reply. I am already using the .NET as you suggested and that is great.! I would like to replicated some of the functions available in Office API like:

=TR("NVDA.O", "TR.PRICEAVG100D")

=TR("NVDA.O","TR.PriceNetChg1D")

=TR("NVDA.O","TR.PriceMoRegionRank")

=TR("NVDA.O","TR.RSISimple14D ")

=TR("NVDA.O","TR.CompanyName")

=TR("NVDA.O","TR.TRBCEconomicSector")

=TR("NVDA.O", "TR.CreditComboRegionRank")

Is that possible with the .NET API? According to the documentation that is available in the DEX2 API.

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 4 2 5

That was exactly what I was looking for! Thank you!

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
17 3 7 10

Any chance someone could translate this to R?

I am particularly interested in getting the following to work:

=RSearch("FUND",A2:B3,"NBROWS:2000",,C2)

(A2:B3 are search parameters, RCSAssetCategoryGenealogy and RCSIssuerDomicileCountry)

=TR($C2,"TR.FundRollingPerformance(RollTimeFrame=SI Interval=M).value","Transpose=Y NULL=NULL",M2)

=TR($C2,"TR.FundNAV(Align=ME).value","EDate=1D SDate=1980-01-01 Transpose=Y NULL=NULL",F2)

=TR($C2,"TR.FundType")

=TR($C2," TR.PrimaryIssueRICCode")

=TR($C2,"TR.FundBenchmarkInstrumentCode")

Any help would be greatly appreciated.

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.