104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using bts.api;
|
|
using bts.api.core;
|
|
using bts.api.synthetic;
|
|
using bts.test;
|
|
using ManyConsole.CommandLineUtils;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
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<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 ServiceContext();
|
|
|
|
var s = ctx.locate<api.user.UserService>();
|
|
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<api.admin.AdminService>();
|
|
var resp = s.get_admin_data(new VoidMessage());
|
|
Console.WriteLine("{0}", resp);
|
|
}
|
|
}
|
|
}
|