using bts.api; using bts.api.core; using bts.api.synthetic; using bts.test; using bts.md; using CommandLine; using System; using System.Threading; namespace bts { public class ServiceTestOptions { [Option(nameof(synthetic))] public bool synthetic { get; set; } [Option(nameof(user))] public bool user { get; set; } [Option(nameof(admin))] public bool admin { get; set; } [Option(nameof(mbo))] public bool mbo { get; set; } [Option("key")] public UInt32 key { get; set; } [Option("side")] public api.Side side { get; set; } } public class ServiceTest { public static int Run(ServiceTestOptions o) { if (o.synthetic) { synthetic_test(); } if (o.user) { user_test(); } if (o.admin) { admin_test(); } if (o.mbo) { mbo_test(o); } return 0; } static string try_get(string[] args, int index) { if (args.Length < index) { return args[index]; } return ""; } private static void mbo_test(ServiceTestOptions o) { var key = o.key; var side = o.side; using (var ctx = new ServiceContext()) { var mbo = ctx.locate(); var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key }); Console.WriteLine($"Order data for {data.SecurityId}"); var vector = side == api.Side.Buy ? data.Bid : data.Ask; var price = 0.0; foreach(var e in vector) { if (e.Price != price) { price = e.Price; Console.WriteLine("================"); } Console.WriteLine(e); } } } 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.Standard, 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); } } } }