Click or drag to resize

WCF connectivity

S#.Data can be used in server mode, in this mode it is possible remotely to connect to S#.Data and get the data available in the storage or write new ones. The activation of the S#.Data server mode is described in the Settings item.

To connect to S#.Data through WCF there is the RemoteStorageClient class in S#.API.

C#
...
var client = new RemoteStorageClient(new InMemoryExchangeInfoProvider(), new Uri("net.tcp://localhost:8000"))
{
    Credentials = { AutoLogon = true, Email = "hydra_user", Password = "qwerty".To<SecureString>() },
};
...

Getting all the instruments available in S#.Data:

C#
...
var storageRegistry = new StorageRegistry();
client.Refresh(storageRegistry.GetSecurityStorage(), new Security(), s => { }, () => false);
var allSecurity = storageRegistry.GetSecurityStorage().Lookup(new Security());
...

Getting all available data in S#.Data by instrument, and saving to local storage:

C#
...
StorageRegistry storageRegistry = new StorageRegistry();
List<DataType> supportedDataTypes = new List<DataType>()
    {
        DataType.Create(typeof (TimeFrameCandleMessage), TimeSpan.FromMinutes(1)),
        DataType.Create(typeof (TimeFrameCandleMessage), TimeSpan.FromMinutes(5)),
        DataType.Create(typeof (TimeFrameCandleMessage), TimeSpan.FromMinutes(15)),
        DataType.Create(typeof (TimeFrameCandleMessage), TimeSpan.FromHours(1)),
        DataType.Create(typeof (TimeFrameCandleMessage), TimeSpan.FromDays(1)),
        DataType.Create(typeof (ExecutionMessage), ExecutionTypes.Tick),
        DataType.Create(typeof (ExecutionMessage), ExecutionTypes.Transaction),
        DataType.Create(typeof (ExecutionMessage), ExecutionTypes.OrderLog),
        DataType.Create(typeof (QuoteChangeMessage), null),
        DataType.Create(typeof (Level1ChangeMessage), null),
        DataType.Create(typeof (NewsMessage), null),
    };
...
foreach (var dataType in supportedDataTypes)
{

    var localStorage = storageRegistry.GetStorage(security, dataType.MessageType, dataType.Arg,
        localMarketDataDrive, StorageFormats.Csv);
    var remoteStorage = client.GetRemoteStorage(security.ToSecurityId(), dataType.MessageType, dataType.Arg,
        StorageFormats.Csv);

    var dates = remoteStorage.Dates.Where(date => date >= start && date <= end).Except(localStorage.Dates).ToArray();
    foreach (var dateTime in dates)
    {
        using (var stream = remoteStorage.LoadStream(dateTime))
        {
            localStorage.Drive.SaveStream(dateTime, stream);
        }
        Console.WriteLine(dataType.MessageType + "; " + dataType.Arg + "; " + dateTime);

        var localStor = localStorage.Load(dateTime);
        foreach (var marketData in localStor)
        {
            Console.WriteLine(marketData);
        }
    }
}
...