84 lines
2.1 KiB
C#
84 lines
2.1 KiB
C#
using System;
|
|
using mbts.config;
|
|
using bts.utils;
|
|
using System.Threading.Tasks;
|
|
using Bts.DataStreamExpressions;
|
|
using System.Collections.Generic;
|
|
|
|
using BCG;
|
|
|
|
|
|
bts.Log.Gen.info($"Starting DSPublisher");
|
|
Console.WriteLine("Starting DSPublisher...");
|
|
static void init(string[] args)
|
|
{
|
|
Console.WriteLine("Hit key to continue");
|
|
Console.ReadLine();
|
|
Func<string, string, Task> login = async (l, p) =>
|
|
{
|
|
var login = l;
|
|
var passwd = p;
|
|
var service_ctx = bts.api.core.ServiceContext.create();
|
|
await service_ctx.login(login, passwd);
|
|
};
|
|
BTSNativeMethods.provide_command_line(args, args.Length);
|
|
Configuration.initialize();
|
|
Task.Run(async () => await login("bts", String.Empty));
|
|
}
|
|
|
|
init(args);
|
|
_publish_streams();
|
|
|
|
static ViewStream build_stream(string stream_expression)
|
|
{
|
|
try
|
|
{
|
|
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
|
var rv = exp.getView(new Dictionary<string, StatementExpression>(0));
|
|
return rv;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bts.Log.assert(false, $"Could not build stream: {stream_expression} ex: {ex}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
void _publish_streams()
|
|
{
|
|
PubTableBroker pb_broker = new PubTableBroker();
|
|
CloudStreamManager csm = new CloudStreamManager();
|
|
// get it from config
|
|
Dictionary<string, string> streams_to_publish = new Dictionary<string, string>() {
|
|
{"bbo","bbo()"},
|
|
{"instruments","instruments()"},
|
|
//{"timesales","timesales(10000)"},
|
|
{"books","books()"},
|
|
// {"seconds_1_10","second(1,10)"},
|
|
{"literal_420","literal(\"x\", \"420.0\")"},
|
|
// {"bbo_ts","timeSeries(bbo())"}
|
|
};
|
|
foreach (var kv in streams_to_publish)
|
|
{
|
|
var name = kv.Key;
|
|
var exp = kv.Value;
|
|
BCG.ViewStream vs = build_stream(exp);
|
|
ViewPublisher vpub = new ViewPublisher(name, pb_broker, vs);
|
|
vs.onChange += on_change;
|
|
}
|
|
while (true)
|
|
{
|
|
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
|
|
ViewStreamDatabase.instance.doWork();
|
|
csm.doWork();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void on_change(object obj)
|
|
{
|
|
bts.Log.Gen.info($"DSPublisher on_change dp: {obj}");
|
|
} |