using bts.api; using bts.api.core; using bts.api.synthetic; using bts.test; using ManyConsole; using System; using System.Threading; namespace bts { public class ServiceTest : ConsoleCommand { bool _synthetic; bool _user; bool _admin; 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); HasOption("admin", "admin test", _ => _admin = true); } public override int Run(string[] remainingArguments) { if (_synthetic) { synthetic_test(); } if (_user) { user_test(); } if (_admin) { admin_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); } private static void admin_test() { var ctx = new ServiceContext(); var s = ctx.locate(); var d = s.subscribei_admin_data().Subscribe(Console.WriteLine); //var resp = s.get_admin_data(new VoidMessage()); //Console.WriteLine("{0}", resp); while (true) { Thread.Sleep(100); } } } }