question

Upvotes
Accepted
89 2 6 9

one RIC but many files (change date, expiration date)

RIC: ESM0 (RawLegacyMarketDepth)

Problem:

I find RIC: ESM0, as shown in the pictures, under RIC: ESM0 there are many files with different "Change Date" and "Expiration Date" (06/18/2020 and 06/19/2020)


Which of these RICs is correct?

Problem, downloading everything, all RIC: ESM0 with different "Change Date" and "Expiration Date"

files of 90 gigabytes

Help with the answer, what to change in the code so that only one RIC is downloaded with the correct expiration date and where is the earliest update date of the message in history or earliest RIC date.

Please give an example of the code in the answer in C #example code.

code:

using System;
using System.Linq;
using System.Diagnostics;
using System.IO;
using ThomsonReuters.Dss.Api.StandardExtractions;
using ThomsonReuters.Dss.Api;
using ThomsonReuters.Dss.Api.Content;
using ThomsonReuters.Dss.Api.Extractions;
using ThomsonReuters.Dss.Api.Extractions.ExtractionRequests;
using ThomsonReuters.Dss.Api.Extractions.ReportExtractions;
using ThomsonReuters.Dss.Api.Extractions.ReportTemplates;
using ThomsonReuters.Dss.Api.Extractions.Schedules;
using ThomsonReuters.Dss.Api.Extractions.SubjectLists;
using ThomsonReuters.Dss.Api.Search;
using ThomsonReuters.Dss.Core.RestApi;
using System.Text;
using ICSharpCode.SharpZipLib.GZip;

namespace RefinitivHistoryTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            //-----------------------------------------------------------------
            //Connect and authenticate to the DSS server:
            //-----------------------------------------------------------------
            Uri dssUri = new Uri("https://hosted.datascopeapi.reuters.com/RestApi/v1/");
            string dssUserName = "*****";
            string dssUserPassword = "*****";

            var out_dir = @".\Storage\";
            var SearchContext = new SearchContext(dssUri, dssUserName, dssUserPassword);

            var ExtractionsContext = new ExtractionsContext(dssUri, dssUserName, dssUserPassword);
            ExtractionsContext.Options.AutomaticDecompression = false;
            try
            {
                ExtractionsContext.DefaultRequestHeaders.Add("x-direct-download", "true");
            }
            catch (Exception)
            { }

            var availableMbPFields = ExtractionsContext.GetValidContentFieldTypes(ReportTemplateTypes.TickHistoryRaw);
            var availableTnSFields = ExtractionsContext.GetValidContentFieldTypes(ReportTemplateTypes.TickHistoryTimeAndSales);


            var dateRange = DateTimeRange.Create(
                new DateTimeOffset(2008, 01, 01, 0, 0, 0, TimeSpan.Zero),
                new DateTimeOffset(2020, 12, 22, 0, 0, 0, TimeSpan.Zero));

            var request = new HistoricalChainResolutionRequest
            {
                ChainRics = new[] { "0#ESM0" },//{ "0#ESH1"},//{ "0#ECSSH1" },//{ "0#1URO:" },
                Range = dateRange
            };

            var chain_results = SearchContext.HistoricalChainResolution(request);
            foreach (var chain in chain_results)
            {
                Console.WriteLine("Chain Identifier: {0} {1}, Constituents: {2}", chain.IdentifierType, chain.Identifier, chain.Constituents.Count());
                foreach (var constituent in chain.Constituents)
                {
                    var searchResults = SearchContext.HistoricalSearch(
                        HistoricalSearchRequest.Create(
                            constituent.Identifier, constituent.IdentifierType, dateRange, HistoricalResultsBy.Ric, null));

                    //foreach (var result in from pos in searchResults where pos.DomainCode == "8" select pos)
                    //foreach (var result in searchResults)

                    var result = searchResults.FirstOrDefault(pos => pos.Identifier.Contains("ESM0"));//("ESH1m"));//("ECSSH1"));
                    if (result != null)
                    {

                        var extractionDatesResult = ExtractionsContext.Extract(
                            new HistoricalReferenceExtractionRequest
                            {
                                ContentFieldNames = new DssCollection<string>()
                                {
                                    "RIC", "Start date", "Change Date", "Expiration Date"
                                },

                                Condition = new HistoricalReferenceCondition
                                {
                                    StartDate = result.FirstDate,
                                    EndDate = result.LastDate
                                },

                                IdentifierList = new InstrumentIdentifierList
                                {
                                    InstrumentIdentifiers = new[]
                                    {
                                        InstrumentIdentifier.Create(result.IdentifierType, result.Identifier)
                                    },
                                    ValidationOptions = new InstrumentValidationOptions
                                    {
                                        AllowHistoricalInstruments = true
                                    },
                                    UseUserPreferencesForValidationOptions = false
                                }
                            });

                       dynamic srcLastDate = null;
                        foreach (var content in extractionDatesResult)
                            foreach (var prop in content.DynamicProperties)
                            {
                                Console.WriteLine("{0}\t {1},\r", prop.Key, prop.Value);
                                if (srcLastDate == null && prop.Key == "Expiration Date" && prop.Value != null) srcLastDate = prop.Value;
                            }

                        dynamic lastDate = srcLastDate != null ? new DateTimeOffset(srcLastDate) : new DateTimeOffset(DateTime.UtcNow);   //result.LastDate;
                        dynamic startDate = result.FirstDate;//lastDate.AddMonths(-1);//new DateTimeOffset(2020, 12, 22, 0, 0, 0, TimeSpan.Zero); //lastDate.AddMonths(-4);//result.FirstDate;


                        Console.WriteLine("{0},\t {1},\t {2},\t {3},\t {4}", result.Identifier, result.IdentifierType, startDate, lastDate, result.DomainCode);

                        var extractionResult = ExtractionsContext.ExtractRaw(

                               new TickHistoryMarketDepthExtractionRequest
                                {
                                    Condition = new TickHistoryMarketDepthCondition
                                    {
                                        ReportDateRangeType = ReportDateRangeType.Range,
                                        QueryStartDate = startDate, //new DateTimeOffset(2016, 07, 25, 20, 0, 0, TimeSpan.Zero),
                                        QueryEndDate = lastDate, //new DateTimeOffset(2016, 08, 02, 19, 59, 59, TimeSpan.Zero),
                                        ExtractBy = TickHistoryExtractByMode.Ric,
                                        MessageTimeStampIn = TickHistoryTimeOptions.GmtUtc,
                                        SortBy = TickHistorySort.SingleByRic,
                                        View = TickHistoryMarketDepthViewOptions.LegacyLevel2,
                                        DisplaySourceRIC = true

                                    },
                                    IdentifierList = new InstrumentIdentifierList
                                    {
                                        InstrumentIdentifiers = new[]
                                        {
                                            InstrumentIdentifier.Create(result.IdentifierType, result.Identifier)
                                        },
                                        ValidationOptions = new InstrumentValidationOptions
                                        {
                                            AllowHistoricalInstruments = true
                                        }
                                    },

                                });

                        string line;
                        var fileName = out_dir + "_" + result.Identifier + "_" + startDate.DateTime.ToString("dd.MM.yyyy") + "_" + lastDate.DateTime.ToString("dd.MM.yyyy") + "_RawLegacyMarketDepth.csv";
                        var sw = new StreamWriter(fileName, false);
                        var streamResponse = ExtractionsContext.GetReadStream(extractionResult);
                        using (GZipInputStream gzip = new GZipInputStream(streamResponse.Stream))
                        {
                            using (StreamReader reader = new StreamReader(gzip, Encoding.UTF8))
                            {
                                while ((line = reader.ReadLine()) != null)
                                {
                                    sw.WriteLine(line);
                                }
                            }
                        }
                        sw.Close();
                    }
                }
            }
            try
            {
                ExtractionsContext.DefaultRequestHeaders.Remove("x-direct-download");
            }
            catch (Exception)
            { }
            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
    }
}


tick-history-rest-apic#Download
esm0m-1.png (67.8 KiB)
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
23k 22 9 14

Hello @s61670,

These are, from my understanding, the results of Historical Reference requests. They are search results, rather then files.

Historical Reference request aims to provide the complete set of information for the instrument, in history, and instruments, over the years, sometimes undergo changes, this is the history of any changes that have taken place.

You can use this request, to identify the Expiration Date, for an instrument.

You do not need to request the biggest file, in my understanding. From the other question, you were looking to request the content on the Expiration Date, this request provides you with the Expiration date to use

If you require to learn more about every specific change that the instrument has underwent over the history, you will need to request additional fields, to pinpoint these changes.

From the API usage perspective, you can learn more about Historical Reqference request, and how to obtain the complete list of the available fields, so that you can select the fields that you require from this tutorial .

As a customer, if you need help identifying the required content and explaining it, the best way is to refer it to Refinitiv Helpdesk Online -> Content , to be connect with the Refinitiv content expert for your required content set. The members of dev forum and moderators are developers, and are not experts in all diverse kinds of content that are provided by Refinitiv.

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.

Upvotes
89 2 6 9

very different size between files. The first file was downloaded 90 gigabytes, the second 285 gigabytes.

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.

Click below to post an Idea Post Idea