dxFeed / dxfeed-graal-net-api

For .NET developers, this library offers easy access to dxFeed market data. Built upon the GraalVM Native Image and our flagship dxFeed Java API, it provides a seamless experience for .NET-based applications
Mozilla Public License 2.0
11 stars 6 forks source link

Best Way to get InstrumentProfile for Schedule.GetInstance(profile) #69

Closed EcBen closed 5 months ago

EcBen commented 5 months ago

Trying to use the new Schedule class to get an instruments trading sessions requires passing an InstrumentProfile. I can get an InstrumentProfile from the IPF URL:

However, this data can be HUGE. For one account, it's only 4.6MB. For another, it's 300.9MB. I only need one or two InstrumentProfiles from this data. Using this library, is there another way to get a single InstrumentProfile than loading the full list? I already have a DXEndpoint created and connected to a dxlink URL.

var col = new DxFeed.Graal.Net.Ipf.Live.InstrumentProfileCollector();
var ipf = DxFeed.Graal.Net.Ipf.Live.InstrumentProfileConnection.CreateConnection("https://user:pass@tools.dxfeed.com/ipf", col);
ipf.Start();
var ipfList = col.View();
foreach (var profile in ipfList)
{
    if (profile.Symbol == "SPY")
    {
        var time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
        var schedule = Schedule.GetInstance(profile);
        schedule.TryGetNearestSessionByTime(time, SessionFilter.REGULAR, out var session);
        var day = schedule.GetDayByTime(time);
        var sessions = day.GetSessions();
        var nextDay = day.GetNextDay(DayFilter.TRADING);
    }
}
stdcion commented 5 months ago

Hi @EcBen!

Yes, you can specify the required symbols in the HTTP request. Detailed information on all available parameters can be found here https://tools.dxfeed.com/ipf?help.

Also, if you're using Schedule, you can trigger auto update of schedule.properties (this file contains the schedule) from our site by using SystemProperty com.dxfeed.schedule.download=auto. File will be reupdated once a day, or you can control it using the form: com.dxfeed.schedule.download=auto,4h (this will cause updates to be once each 4 hours). By default it will update once a day, this is usually enough, we don't update this file that often.

Here's an example:

SystemProperty.SetProperty("com.dxfeed.schedule.download", "auto");
var symbol = "SPY";
var reader = new InstrumentProfileReader();
var profiles = reader.ReadFromFile($"https://user:password@tools.dxfeed.com/ipf?SYMBOL={symbol}");
foreach (var profile in profiles)
{
    if (profile.Symbol.Equals(symbol, StringComparison.Ordinal))
    {
        var time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
        var schedule = Schedule.GetInstance(profile);
        schedule.TryGetNearestSessionByTime(time, SessionFilter.REGULAR, out var session);
        var day = schedule.GetDayByTime(time);
        var sessions = day.GetSessions();
        var nextDay = day.GetNextDay(DayFilter.TRADING);
    }
}
await Task.Delay(Timeout.Infinite);
stdcion commented 5 months ago

Also, if you are using InstrumentProfileCollector, you should add a listener (AddUpdateListener) because receiving IPF by the collector is asynchronous. If you just try to call col.View, you may not see the changes immediately. If you want a blocking call, it's easier to use InstrumentProfileReader and `ReadFromFile method.

Best regards, dxFeed APIs Team

EcBen commented 5 months ago

Thanks for the quick response! I'll give that a try. Today, we found that DxFeed's REST API for sessions is incorrect, but the Schedule for this library is correct, so we want to switch to it:

                {
                    "date": "20240703",
                    "isTrading": "true",
                    "startTime": "2024-07-03 08:30:00-0500",
                    "endTime": "2024-07-03 15:00:00-0500",
                    "type": "REGULAR"
                },

The equity REGULAR session ended today at 12:00 noon Central Daylight Time, not 15:00.

EcBen commented 5 months ago

It was also wrong on the Good Friday holiday.

stdcion commented 5 months ago

This is unexpected behavior. Can I ask you to create a ticket on our customer portal? It is actually more efficient for us to handle requests using this portal as it is a single point of entry for customers, ensuring that your issue is tracked and resolved promptly.

EcBen commented 5 months ago

Yes, just added it to the customer portal.