question

Upvotes
1 0 0 0

Requesting multiple instruments of historical data at once is only returning the top data point?

I am trying to figure out the best way in the C# Workspace Data API to pull out historical OHLC data for multiple markets at once to increase the speed instead of doing one by one.


Using this sample project: 2.1.01-HistoricalPricing-Summaries


My issue is that if I have a list of symbols... in response1, where i pass a single symbol it indeed gives me back 20 days of data. However in response2 if I pass more than 1 symbol, it only returns me the last day for each symbol.


An additional issue, is when I run this on September 11, it only gives me data until September 10. Does the historical data request not include the most bar data as well?


var response1 = Summaries.Definition(symbols.Take(1)).Interval(Summaries.Interval.P1D)

.Fields("DATE", "TRDPRC_1", "MKT_OPEN", "VWAP", "LOW_1", "HIGH_1")

.Count(20)

.GetData();


var response2 = Summaries.Definition(symbols.Take(2)).Interval(Summaries.Interval.P1D)

.Fields("DATE", "TRDPRC_1", "MKT_OPEN", "VWAP", "LOW_1", "HIGH_1")

.Count(20)

.GetData();




#technologyhistoricalc#refinitiv-data-librarieslseg-data-library
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
1 0 0 0

I have a similar query with streaming multiple


    // Create a Historical Pricing stream - specifying the desired 'interday' interval

    var stream = Summaries.Definition(symbols.Take(10).ToList())

        .Fields("BID", "ASK", "HIGH_1", "LOW_1", "OPEN_PRC", "TRDPRC_1", "ACVOL_UNS")

                                              .Interval(Summaries.Interval.P1D)

                                              .Count(5)

                                              .GetStream();



    // Specify the TSI lambda expressions to capture 'Insert' and 'Update' events

    stream.OnInsert((data, stream) => Common.DisplayTable($"INSERT: {DateTime.Now}", data.Table)

          .OnUpdate((data, stream) => Common.DisplayTable($"UPDATE: {DateTime.Now}", data.Table))

          .OnStatus((status, stream) => Console.WriteLine($"Status: {status}"))

          .OnError((error, stream) => Console.WriteLine($"Error: {error}"))

          .Open();



If I use the above... all of my symbols give me the first "OnInsert", however all the following OnUpdate are only for the FIRST symbol in the list.


All in all- how do I stream daily & intraday bars for multiple symbols at once?


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
237 4 2 3

Hello @arek.majka

To stream intraday summary data for multiple instruments, you will need to:

- open a desktop session

- create and open a summary stream for each instrument

- retain streams in a list and close them when no longer required


I provided an example below:

using (ISession session = Sessions.GetSession("desktop"))
{
    session.Open();

    string[] symbols = { //your symbols }

    var summaryStreams = new List<ISummariesStream>();

    foreach (string symbol in symbols)
    {
        // Set definition details and create stream object
        var summaryStream = Summaries.Definition(symbol)
            .Fields("DATE", "OPEN_PRC", "HIGH_1", "LOW_1", "TRDPRC_1") //some specific fields
            .Interval(Summaries.Interval.PT1M) //Intraday, 1 minute bars
            .Sessions(HistoricalPricing.Sessions.normal) //Normal market hours session
            .Count(10) //Initial historical data row count
            .GetStream();

        // Set call back methods and open the stream to receive data
        summaryStream
            .OnInsert((data, stream) => {})
            .OnUpdate((data, stream) => {})
            .OnStatus((status, stream) => {})
            .OnError((error, stream) => {})
            .Open();

        summaryStreams.Add(summaryStream);
    }

    // When not required anymore, streams should be closed. 
    summaryStreams.ForEach(stream => stream.Close());
}


About your second question - "An additional issue, is when I run this on September 11, it only gives me data until September 10. Does the historical data request not include the most bar data as well?"

Yes, historical data does not contain the current bar, it only contains data about intervals that have finished.

For the current bar you will receive stream updates because it is ongoing data and not really "history".


Best regards,

Baciu Wahl Cristian

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

Hello,

Thank you for the response.

Is there no way to bulk request multiple instruments historically though? I was told by one of your colleagues that we should be using bulk requests instead of going one by one?


The requests are relatively slow; just in the fact that even if it takes a second to get the results on a single query, if you have a few hundred markets that gets to be a very long time.


The same goes with streaming. If we are using Summaries.Definition().GetStream() the startup is often times multiple seconds.


Are there other types of requests I should be using? Please note that we are indeed trying to stream bar data and not bid/ask/trade data, as we don't want to be recreating our own bars. We are upgrading from Eikon so trying to keep the same structure in tact.

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
237 4 2 3

Hello @arek.majka

When requesting for historical pricing data you should use a Summaries Definition. There are 2 different endpoints depending on the interval.

For intraday intervals, there is a GET endpoint that only accepts one instrument at a time. You can also specify the number of rows you wish to retrieve.

For interday intervals, there is a POST endpoint, that accepts multiple instruments, but it can only retrieve summary containing 1 row for each instrument from the backend. Retrieving multiple rows for an instrument is done similarly to intraday intervals, via a GET point.

I have provided an example bellow:

internal static class DataRetrievalMultipleCases
{
    public static async Task Run()
    {
        Log.Level = LogLevel.Warn;
        Common.Prompt = false;

        using (ISession session = Sessions.GetSession("desktop"))
        {
            session.Open();

            string[] symbols = { "AAPL.O", "TSLA.O", "MSFT.O", "NVDA.O", "AMZN.O", "AMD.O", };

            var tasks = new List<Task>();

            // Case 1 : Intraday 
            System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew();
            foreach (var symbol in symbols)
            {
                tasks.Add(GetIntradaySummaryData(symbol));
            }
            await Task.WhenAll(tasks);
            watch.Stop();
            Console.WriteLine($"Time to complete INTRADAY requests: {watch.Elapsed}");

            // Case 2 : Interday 
            System.Diagnostics.Stopwatch watch2 = System.Diagnostics.Stopwatch.StartNew();
            await GetInterdaySummaryData(symbols);
            watch2.Stop();
            Console.WriteLine($"Time to complete INTERDAY requests: {watch2.Elapsed}");

            Console.ReadLine();
        }
    }

    private static async Task GetIntradaySummaryData(string symbol)
    {
        // Intraday - GET - 1 instrument per request - multiple rows can be retrieved
        var data = await Summaries.Definition(symbol)
                                  .Fields("HIGH_1", "LOW_1")
                                  .Interval(Summaries.Interval.PT5M)
                                  .Count(5)
                                  .GetDataAsync();

        Common.DisplayTable(data);
    }

    private static async Task<IDataSetResponse> GetInterdaySummaryData(string[] symbols)
    {
        // Interday - POST - multiple instruments per request - 1 row per instrument retrieved
        var data = await Summaries.Definition(symbols)
                              .Fields("HIGH_1", "LOW_1")
                              .Interval(Summaries.Interval.P1D)
                              .Count(5) //ignored for multiple instruments
                              .GetDataAsync();

        Common.DisplayTable(data);
        return data;
    }
}


Best regards,

Cristian

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.