Files
mika@stocksharp.com 3b814d26d2 Samples: build from the applications' sources again and follow the awaited API
The applications moved every host into a folder of its own, so the projects the from-source samples reference
are under Xaml\Avalonia and Xaml\Wpf now, and the FIX connector they named lives in the public connectors
repository. Nine WPF samples still named Xaml and Xaml.Charting where they were before: a missing project
reference is only a warning, so they failed later, at the first DevExpress or StockSharp tag of their markup.

The MultiConnect samples sign in through the window the WPF head has. That head keeps the credentials window
in Studio.WebApi.UI, taking the site's client service; the samples asked StockSharp.Xaml for one taking a
fetcher, which the head does not have, and did not compile from sources. The published UI packages are far
behind the sources and are not what the samples are kept in step with: the package-based projects of these
samples compile once the WPF packages built from that head are published.

The WPF samples await the connector's settings window, which the WPF library offers as ConfigureAsync only,
and the active-orders sample awaits the chart's save instead of the obsolete blocking wrapper. The
package-based projects of the same samples compile once a StockSharp.Xaml package that has ConfigureAsync is
published.

The Avalonia samples keep the connection settings through the awaited store: IConnectorSettingsStore reads
and writes through awaited members now, so the sample store reads or writes its file when it is asked instead
of reading both files up front and queueing its writes. The chart sample saves and loads its chart the same
way.

Eight Avalonia samples put the wheel date picker into columns of 150-170 pixels. It does not get narrower
than about three hundred, so the two of them ran over each other and over the Start and Stop buttons. They
take the compact calendar editor now, which the history testing sample already had.
2026-10-15 23:02:33 +03:00
..
2025-03-23 13:44:06 +03:00

Hydra Server Mode Data Retrieval Example

Overview

This program illustrates how to connect to Hydra operating in server mode and retrieve various types of market data using the StockSharp framework. It includes setting up remote data retrieval, storing it locally, and displaying some of the data to the user.

Detailed Code Walkthrough

Logging Setup

var logger = new LogManager();
logger.Listeners.Add(new ConsoleLogListener());
  • LogManager: Creates a logging system for tracking operations.
  • ConsoleLogListener: Configures logging to output to the console.

Storage Setup

var storageRegistry = new StorageRegistry();
var registry = new CsvEntityRegistry(Path.Combine(Directory.GetCurrentDirectory(), "Storage"));
var securityStorage = (ISecurityStorage)registry.Securities;
  • StorageRegistry: Creates a registry for managing various storage mechanisms.
  • CsvEntityRegistry: Sets up a registry for storing entities in CSV format in the "Storage" directory.
  • securityStorage: Interface for accessing security information stored in the registry.

Configuring Remote Data Access

var remoteDrive = new RemoteMarketDataDrive(RemoteMarketDataDrive.DefaultAddress, new FixMessageAdapter(new IncrementalIdGenerator()))
{
    Logs = logger.Application,

    Credentials =
    {
        Email = "hydra_user",

        //
        // required for non anonymous access
        //
        //Password = "hydra_user".To<SecureString>()
    },

    //
    // uncomment to enable binary mode
    //
    //IsBinaryEnabled = true,
};
  • RemoteMarketDataDrive: Sets up a connection to the remote Hydra server using the default address and FIX messaging for communication.
  • Logs: Connects the logger to track application-level events.
  • Credentials: Configures for anonymous access by default (password is commented out).
  • Binary Mode Option: Commented out but available if needed for improved performance.

Security Identification

var secId = new SecurityId
{
    SecurityCode = "BTCUSDT",
    BoardCode = BoardCodes.BinanceFut,
};
  • SecurityId: Identifies the specific market instrument to retrieve (BTCUSDT futures on Binance).
  • BoardCodes.BinanceFut: Uses the predefined board code for Binance Futures.

Downloading and Storing Security Information

var exchangeInfoProvider = new InMemoryExchangeInfoProvider();
remoteDrive.LookupSecurities(new() { SecurityId = secId }, registry.Securities,
    s => securityStorage.Save(s.ToSecurity(exchangeInfoProvider), false), () => false,
    (c, t) => Console.WriteLine($"Downloaded [{c}]/[{t}]"));

var securities = securityStorage.LookupAll();

foreach (var sec in securities)
{
    Console.WriteLine(sec);
}

Console.ReadLine();
  • InMemoryExchangeInfoProvider: Provides exchange information for converting messages to securities.
  • LookupSecurities: Retrieves specific security information (BTCUSDT) from the remote Hydra instance.
  • Progress tracking shows download counts in the console.
  • Displays all retrieved securities to the console.

Setup for Historical Data Retrieval

var startDate = DateTime.Now.AddDays(-30);
var endDate = DateTime.Now;

const string pathHistory = "Storage";
pathHistory.SafeDeleteDir();

var localDrive = new LocalMarketDataDrive(pathHistory);

const StorageFormats format = StorageFormats.Binary;
  • Date Range: Sets up to retrieve the last 30 days of data.
  • Storage Directory: Clears and resets the "Storage" directory.
  • LocalMarketDataDrive: Configures the local storage location.
  • Storage Format: Sets binary format for storing retrieved data.

Retrieving and Storing Market Data

foreach (var dataType in remoteDrive.GetAvailableDataTypes(secId, format))
{
    var localStorage = storageRegistry.GetStorage(secId, dataType.MessageType, dataType.Arg, localDrive, format);
    var remoteStorage = remoteDrive.GetStorageDrive(secId, dataType, format);

    Console.WriteLine($"Remote {dataType}: {remoteStorage.Dates.FirstOrDefault()}-{remoteStorage.Dates.LastOrDefault()}");

    var dates = remoteStorage.Dates.Where(date => date >= startDate && date <= endDate).ToList();

    foreach (var dateTime in dates)
    {
        using (var stream = remoteStorage.LoadStream(dateTime))
        {
            if (stream == Stream.Null)
                continue;

            localStorage.Drive.SaveStream(dateTime, stream);
        }

        Console.WriteLine($"{dataType}={dateTime}");

        var localStor = localStorage.Load(dateTime);
        foreach (var marketDate in localStor.Take(100))
        {
            Console.WriteLine(marketDate);
        }
    }
}
  • GetAvailableDataTypes: Discovers all available data types for the specified security.
  • Displays available date ranges for each data type.
  • Filters dates to match the specified 30-day range.
  • Downloads each data file as a stream and saves it locally.
  • Loads and displays the first 100 entries from each stored data file.

Key Features

  • Anonymous Access: Configured by default for anonymous access to Hydra.
  • Specific Security Focus: Retrieves data for BTCUSDT on Binance Futures.
  • Console Logging: Provides detailed operation logging.
  • Binary Storage Format: Uses efficient binary format for data storage.
  • Incremental Download: Retrieves data for specific dates within a 30-day range.
  • Data Verification: Displays retrieved data for verification purposes.

Conclusion

This example demonstrates how to connect to Hydra in server mode, retrieve cryptocurrency market data (specifically BTCUSDT futures), and store it locally for further analysis. The program uses anonymous access by default and retrieves a 30-day history of available data types. This setup is ideal for applications requiring automated data retrieval and storage management in cryptocurrency markets analysis. The code can be adapted for different securities, date ranges, or authentication methods as needed.