diff --git a/src/client/sparkcmd/Cmd/ConfigCheckCommand.cs b/src/client/sparkcmd/Cmd/ConfigCheckCommand.cs new file mode 100644 index 000000000..432fce36b --- /dev/null +++ b/src/client/sparkcmd/Cmd/ConfigCheckCommand.cs @@ -0,0 +1,15 @@ +using ManyConsole; +using System.Linq; + +namespace bts { + public class Configcheck : ConsoleCommand { + public Configcheck() { + IsCommand("configcheck", "Ye olde Configcheck"); + HasAdditionalArguments(null, " [Keys to check]"); + } + public override int Run(string[] args) { + mbts.config.Configuration.configcheck(args.Length, args.ToArray()); + return 0; + } + } +} \ No newline at end of file diff --git a/src/client/sparkcmd/ScriptClient.cs b/src/client/sparkcmd/Cmd/ScriptClientCommand.cs similarity index 73% rename from src/client/sparkcmd/ScriptClient.cs rename to src/client/sparkcmd/Cmd/ScriptClientCommand.cs index c9eb30693..18f0c18c9 100644 --- a/src/client/sparkcmd/ScriptClient.cs +++ b/src/client/sparkcmd/Cmd/ScriptClientCommand.cs @@ -6,8 +6,37 @@ using System.Reflection; using System.Threading.Tasks; using System.Reactive.Linq; using System.Reactive; +using ManyConsole; +using System.Linq; namespace sparkcmd { + public class ScriptClientCommand : ConsoleCommand { + bool _server = false; + string _host; + string _logfile; + + public ScriptClientCommand() { + IsCommand("script", "Remote control for shell diagnostic host"); + HasOption("s|server", "Run a script server for testing.", x => _server = true); + HasOption("h|host", "Connect to {host}", h => _host = h); + HasOption("f|fromfile", "Read commands from file instead of stdin", f => _logfile = f); + } + public override int Run(string[] args) { + if (_server) { + ScriptClient.runserver(); + } + else { + var host = string.IsNullOrEmpty(_host) ? args.First() : _host; + if (string.IsNullOrEmpty(_logfile) && File.Exists(_logfile)) { + ScriptClient.start(host, File.OpenRead(_logfile)); + } + else { + ScriptClient.start(host, Console.OpenStandardInput()); + } + } + return 0; + } + } internal static class ScriptClient { internal static void start(string qualifier, Stream stream) { using (var ctx = new ServiceContext()) { @@ -82,10 +111,9 @@ namespace sparkcmd { public static void runserver() { // for debugging using (var ctx = new ServiceContext()) { - var assembly = Assembly.GetAssembly(typeof(mbts.ui.shell.App)); + var assembly = Assembly.Load("spark.exe"); var stype = assembly.GetType("bts.api.diagnostic.ShellDiagnosticsServiceServer"); var server = Activator.CreateInstance(stype, ctx); - //ShellDiagnosticsServiceServer server = new bts.api.diagnostic.ShellDiagnosticsServiceServer(ctx); while (true) System.Threading.Thread.Sleep(1000); } } diff --git a/src/client/sparkcmd/Cmd/ServiceTestCommand.cs b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs new file mode 100644 index 000000000..3f693b548 --- /dev/null +++ b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs @@ -0,0 +1,86 @@ +using bts.api; +using bts.api.core; +using bts.api.synthetic; +using ManyConsole; +using System; + +namespace bts { + public class ServiceTest : ConsoleCommand { + bool _synthetic; + bool _user; + + public ServiceTest() { + IsCommand("service", "Put code here for testing during service development"); + HasOption("synthetic", "Run synthetic test", _ => _synthetic = true); + HasOption("user", "user test", _ => _user = true); + } + public override int Run(string[] remainingArguments) { + if (_synthetic) { + synthetic_test(); + } + if (_user) { + user_test(); + } + return 0; + } + 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(); + 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 ServiceContext(); + + var s = ctx.locate(); + var r = new api.user.GetUsersRequest(); + var resp = s.get_users(r); + Console.WriteLine("{0}", resp); + } + } +} diff --git a/src/client/sparkcmd/Cmd/TestCommand.cs b/src/client/sparkcmd/Cmd/TestCommand.cs new file mode 100644 index 000000000..e69de29bb diff --git a/src/client/sparkcmd/Program.cs b/src/client/sparkcmd/Program.cs index 06c0bd83f..a4eeaaa20 100644 --- a/src/client/sparkcmd/Program.cs +++ b/src/client/sparkcmd/Program.cs @@ -2,115 +2,19 @@ using bts.api.core; using bts.api.synthetic; using bts.api.test; +using ManyConsole; using System; using System.Linq; -using System.Threading.Tasks; -namespace sparkcmd -{ - class Program - { +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() == "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()); - } - } - + var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); + ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); + return; } - private static void hello_test() { - using (var ctx = new ServiceContext()) { - var hello = ctx.locate(); - 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(); - 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(); - var r = new bts.api.user.GetUsersRequest(); - var resp = s.get_users(r); - Console.WriteLine("{0}", resp); - } } } \ No newline at end of file diff --git a/src/client/sparkcmd/sparkcmd.csproj b/src/client/sparkcmd/sparkcmd.csproj index 1bf66d16d..9394ce3e6 100644 --- a/src/client/sparkcmd/sparkcmd.csproj +++ b/src/client/sparkcmd/sparkcmd.csproj @@ -1,22 +1,26 @@ - - - - Exe - net471 - win7-x64;ubuntu.16.04-x64 - Blue Trading Systems - Blue Trading Systems - Spark - x64 - AnyCPU - 1.0.0 - 7.2 - - + + + + Exe + net471 + + win7-x64;ubuntu.16.04-x64 + Blue Trading Systems + Blue Trading Systems + Spark + x64 + 1.0.0 + 7.2 + + + + + + + + + - - - - - - + + +