Files
spark/src/client/sparkcmd/Program.cs
T
2018-06-05 10:03:17 -04:00

119 lines
4.0 KiB
C#

using bts.api;
using bts.api.core;
using bts.api.synthetic;
using bts.api.test;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace sparkcmd
{
class Program
{
static void Main(string[] args) {
if (args.FirstOrDefault() == "configcheck") {
mbts.config.Configuration.configcheck(args.Length - 1, args.Skip(1).ToArray());
return;
}
mbts.config.Configuration.initialize();
if (args.FirstOrDefault() == "usertest") {
user_test();
}
else if (args.FirstOrDefault() == "service") {
new ServiceDriver().run(args.Skip(1));
}
else if (args.FirstOrDefault() == "synthetic") {
synthetic_test();
}
else if (args.FirstOrDefault() == "hello") {
hello_test();
}
else if (args.FirstOrDefault() == "scriptserver") {
ScriptClient.runserver();
}
else if (args.FirstOrDefault() == "script") {
var qualifier = args.Skip(1).First();
var filename = args.Skip(2).FirstOrDefault();
if (!string.IsNullOrEmpty(filename)) {
Console.WriteLine("filename: " + filename);
// todo: run forever
ScriptClient.start(qualifier, System.IO.File.OpenRead(filename));
}
else {
ScriptClient.start(qualifier, Console.OpenStandardInput());
}
}
}
private static void hello_test() {
using (var ctx = new ServiceContext()) {
var hello = ctx.locate<HelloService>();
var a = hello.say_hello(new HelloRequest { Name = "Bob" });
Console.WriteLine(a.Message);
}
}
private static void synthetic_test() {
using (var ctx = new ServiceContext()) {
var security = new Security {
Symbol = "ES",
Exchange = Venue.Bts,
Currency = Currency.Usd,
Synthetic = new SyntheticContract {
Name = "Synthetic1",
PriceCalc = SyntheticContract.Types.PriceCalc.Ratio,
Legs = {
new ContractLeg {
Security = new Security {
Id = 2,
Symbol = "ES",
// ESH8
Future = new FutureContract {
ExpirationYear = 2018,
ExpirationMonth = 3,
ExpirationDay = 16
}
}
},
new ContractLeg {
Security = new Security {
Id = 5,
Symbol = "ES",
// ESU8
Future = new FutureContract {
ExpirationYear = 2018,
ExpirationMonth = 9,
ExpirationDay = 21
}
}
}
}
}
};
var service = ctx.locate<SyntheticSecurityService>();
try {
var result = service.create_synthetic(security);
if (result.Error == CreateResult.Types.Error.Ok) {
Console.WriteLine(result.Key);
}
}
catch (ApiException e) {
Console.WriteLine(e.Message);
}
}
}
private static void user_test() {
var ctx = new bts.api.core.ServiceContext();
var s = ctx.locate<bts.api.user.UserService>();
var r = new bts.api.user.GetUsersRequest();
var resp = s.get_users(r);
Console.WriteLine("{0}", resp);
}
}
}