Click or drag to resize

Remote administration

S#.Data can be used in server mode, in this mode you can remotely connect to S#.Data and get the existing data in the storage or write new ones. Enabling 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>() },
};
...

2. Saving information about the Exchange in S#.Data:

C#
...
Console.WriteLine("Enter Exchange name (example: NYSE or TESTE)");
var exch = Console.ReadLine();
var exchange = new Exchange[]
{
    new Exchange()
    {
        CountryCode = Exchange.Nyse.CountryCode,
        EngName = exch,
        Name = exch,
        RusName = exch,
    },
};
client.SaveExchanges(exchange);
...

3. Saving information about the ExchangeBoard in S#.Data:

C#
...
Console.WriteLine("Enter ExchangeBoard name (example: NYMEX or TESTB)");
var exchBoard = Console.ReadLine();
var exchangeBoard = new ExchangeBoard[]
{
    new ExchangeBoard()
    {
        Code = exchBoard,
        Exchange = exchange.First(),
        ExpiryTime = new TimeSpan(18, 45, 00),
        TimeZone = TimeZoneInfo.Utc,
        WorkingTime = new WorkingTime(),
    },
};
client.SaveExchangeBoards(exchangeBoard);
...

4. Saving instrument in S#.Data (share, futures, option, etc.) Security:

C#
...
Security[] security = new Security[]
{
    new Security()
    {
        Class = "TESTWC1F",
        Code = "TESTWCF",
        Id = "TESTWCF1@TESTWCF",
        PriceStep = 0.1m,
        Decimals = 1,
        Board = exchangeBoard.First(),
    }
};
client.SaveSecurities(security);
...

5. Getting data from S#.Data:

C#
... 
Console.WriteLine("All Exchange");
var ex = client.LoadExchanges(new Exchange());
foreach (var i in ex)
{
    Console.WriteLine("Exchange: " + i);
}
...
Console.WriteLine("All ExchangeBoard");
var eb = client.LoadExchangeBoards(new ExchangeBoard());
foreach (var i in eb)
{
    Console.WriteLine("ExchangeBoard: " + i);
}
...
Console.WriteLine("All Security");
var storageRegistry = new StorageRegistry();
client.Refresh(storageRegistry.GetSecurityStorage(), new Security(), s => { }, () => false);
var allSecurity = storageRegistry.GetSecurityStorage().Lookup(new Security());
foreach (var i in allSecurity)
{
    Console.WriteLine("Security: " + i);
}
...

6. Getting the extended information from S#.Data storage and saving the extended information to it:

C#
...
var extendedStorage = client.GetExtendedStorage("MyExtendedStorage");

Tuple<string, Type>[] ei = new Tuple<string, Type>[]
{
    new Tuple<string, Type>("NewExtensionInfo1", typeof(string)), 
    new Tuple<string, Type>("NewExtensionInfo2", typeof(string)),
    new Tuple<string, Type>("NewExtensionInfo3", typeof(string)),
};
Console.Write("Enter ExtensionInfo1:");
var str1 = Console.ReadLine();
Console.Write("Enter ExtensionInfo2:");
var str2 = Console.ReadLine();
Console.Write("Enter ExtensionInfo3:");
var str3 = Console.ReadLine();

extendedStorage.CreateSecurityExtendedFields(ei);
var sid = extendedStorage.GetSecurityStorage(MessageConverterHelper.ToSecurityId(NewSecurity[0].Id));
sid.AddSecurityExtendedInfo(new object[] { str1, str3 , str2 });
...