fix rem locator

This commit is contained in:
John Colvin committed 2024-02-08 19:04:12 -06:00
1 parent d09ed6a8dd
commit 7a6e9bc3c8
2 files changed
+177 -173

No files matched your search

+9 -6
View File
@@ -25,21 +25,22 @@ namespace bts.sdk
readonly List<IDisposable> _disps = new List<IDisposable>();
IReadOnlyDictionary<uint, SecurityImmutable> _securities =
new Dictionary<uint, SecurityImmutable>(0);
readonly Lazy<OrderService> _orders;
readonly Lazy<AdminService> _admin;
public OrderSample(
ServiceContext serviceContext,
OrdersClient orders_client,
MarketDataClient md_client,
IObservable<IReadOnlyDictionary<uint, SecurityImmutable>> securities_src
) {
_orders_client = orders_client;
_md = md_client;
_orders = new(() => serviceContext.locate<OrderService>(), true);
_admin = new(() => serviceContext.locate<AdminService>(), true);
_disps.Add(securities_src.Subscribe(secs => _securities = secs));
}
readonly static Lazy<OrderService> _orders = new Lazy<OrderService>(() => Locator.locate<OrderService>(), true);
readonly static Lazy<AuthService> _users = new Lazy<AuthService>(() => Locator.locate<AuthService>(), true);
readonly static Lazy<AdminService> _admin = new Lazy<AdminService>(() => Locator.locate<AdminService>(), true);
void print_update<T>(T update)
{
Console.WriteLine(update.ToString());
@@ -94,7 +95,10 @@ namespace bts.sdk
return resp;
}
static void order_setup(Create cr, string username, string accountname)
void order_setup(Create cr, string username, string accountname) =>
order_setup(cr, username, accountname, _admin.Value.get_admin_data(new VoidMessage()));
static void order_setup(Create cr, string username, string accountname, AdminData admin)
{
cr.NewOrder = new OrderDefinition();
cr.NewOrder.ManualOrderIndicator = ManualOrderIndicator.Yes;
@@ -102,7 +106,6 @@ namespace bts.sdk
cr.NewOrder.CustomerOrFirm = CustomerOrFirm.Firm;
cr.NewOrder.SubType = OrderSubType.None;
cr.NewOrder.TimeInForce = TimeInForce.Day;
var admin = _admin.Value.get_admin_data(new VoidMessage());
BTSUser user = admin.Users.FirstOrDefault( x=> username != null ? x.Name.ToLowerInvariant() == username.ToLowerInvariant() : true );
if (user != null)
{
+168 -167
View File
@@ -1,167 +1,168 @@
namespace bts.sdk {
using bts.api.admin;
using bts.api.core;
using bts.api.orderman;
using bts.api.position;
using bts.co2;
using bts.md;
using Spark.Api.Admin;
using Spark.Api.Orders;
using Spark.Api.Reactive;
using System;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
public class SDKMain
{
private static void user_test(ServiceContext ctx)
{
var s = ctx.locate<api.user.AuthService>();
var r = new api.user.GetUsersRequest();
var resp = s.get_users(r);
Console.WriteLine("{0}", resp);
}
public static void Main(string[] args)
{
BTS.init();
Log.Sdk.info("Welcome to the BTS Client Side SDK example");
var ctx = new ServiceContext();
string u = args.FirstOrDefault(x => x.Contains("--user="));
string p = args.FirstOrDefault(x => x.Contains("--pass="));
u = u?.Replace("--user=", string.Empty) ?? string.Empty;
p = p?.Replace("--pass=", string.Empty) ?? string.Empty;
var lr = ctx.login(u,p).Result;
if (!lr.success)
{
Console.WriteLine("Login failure: " + lr.reason);
help();
}
if (args.FirstOrDefault() == "users")
{
user_test(ctx);
}
else
{
uint ms = 100;
string pu = args.FirstOrDefault(x => x.Contains("--pump="));
if (pu != null)
ms = uint.Parse(p.Replace("--pump=", string.Empty));
var order_service = ctx.locate<OrderService>();
var position_service = ctx.locate<PositionService>();
var admin_service = ctx.locate<AdminService>();
var md_relay = ctx.locate<MarketDataRelay>();
var md_source = new MDSource(TimeSpan.FromSeconds(0.1));
var md_client = new MarketDataClient(md_source);
var admin_client = new AdminClient(admin_service, UserTuple.admin);
var sec_resolver = new SecurityResolver(md_relay, md_source.subscribe_securities());
var orders_client = new OrdersClient(
order_service, position_service, admin_client, sec_resolver);
using(var disp = new CompositeDisposable(md_source)) {
if (args.Length > 0 && args.FirstOrDefault().Contains("md"))
{
var s = new MarketDataSample(md_client);
if (args.FirstOrDefault() == "md")
{
if (args.Length >= 5)
{
s.print_security(args[1], args[2], args[3], args[4]);
}
else if (args.Length >= 4)
{
s.print_product(args[1], args[2], args[3]);
}
else
md_help();
}
else
md_help();
}
else if (args.FirstOrDefault() == "order")
{
var os = new OrderSample(
orders_client,
md_client,
md_source.subscribe_securities().Select(sec_map =>
sec_map.ToDictionary(kv => kv.Key, kv => kv.Value.security)));
disp.Add(os);
order_sample(os, u, args);
}
else
help();
wait_for_stop();
}
}
}
static void order_sample(OrderSample os, string user, string[] args)
{
if (args.Length >= 10) //--user and --pass are in args[]
{
os.send_order(user, args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
}
else if (args.Length >= 9)
{
os.send_order(user, args[1], args[2], args[3], args[4], args[5], args[6]);
}
else
order_help();
}
static void wait_for_stop()
{
Console.WriteLine("Hit q to stop");
ConsoleKeyInfo c;
do
{
c = Console.ReadKey();
Console.WriteLine();
} while (c.KeyChar != 'q');
}
static void help()
{
Console.WriteLine("BTS Spark SDK");
Console.WriteLine("Usages: spark_sdk [command] [arguments]");
Console.WriteLine();
Console.WriteLine("Commands:");
Console.WriteLine(" md <exchange> <security_type> <symbol> [<security_desc>]");
Console.WriteLine(" order <account> <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]");
Console.WriteLine("Arguments:");
Console.WriteLine(" --user=<bts user name>");
Console.WriteLine(" --pass=<password>");
Console.WriteLine(" --pump=<pump_interval_in_ms=100 default>");
Environment.Exit(1);
}
static void order_help()
{
Console.WriteLine("order <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>] [<user>] [<account>]");
Console.WriteLine("This command sends a limit or market DAY order for the specified security_desc. Leave off the price for a market order");
Console.WriteLine(" example: order \"ACC A1\" GLBX Future ES ESM8 10 2650.0");
Console.WriteLine(" order \"ACC A1\" SIM Future ES SIM:ESM8 -10 2650.0");
Console.WriteLine(" order \"ACC A1\" GLBX Future ES ESM8 10 (this is a market order)");
Environment.Exit(1);
}
static void md_help()
{
Console.WriteLine("md <exchange> <security_type> <symbol>");
Console.WriteLine("This command subscribes to market data for an exchange-type-symbol channel and writes to console.");
Console.WriteLine("Marketdata is read off the wire on the same thread as is used to read and print");
Console.WriteLine(" example: md GLBX Future ES --user=bts --pass=password");
Console.WriteLine(" md SIM Future ES SIM:ESZ8 --user=bts --pass=password");
Console.WriteLine(" md GLBX Spread ES --user=bts --pass=password");
Environment.Exit(1);
}
}
}
namespace bts.sdk {
using bts.api.admin;
using bts.api.core;
using bts.api.orderman;
using bts.api.position;
using bts.co2;
using bts.md;
using Spark.Api.Admin;
using Spark.Api.Orders;
using Spark.Api.Reactive;
using System;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
public class SDKMain
{
private static void user_test(ServiceContext ctx)
{
var s = ctx.locate<api.user.AuthService>();
var r = new api.user.GetUsersRequest();
var resp = s.get_users(r);
Console.WriteLine("{0}", resp);
}
public static void Main(string[] args)
{
BTS.init();
Log.Sdk.info("Welcome to the BTS Client Side SDK example");
var ctx = new ServiceContext();
string u = args.FirstOrDefault(x => x.Contains("--user="));
string p = args.FirstOrDefault(x => x.Contains("--pass="));
u = u?.Replace("--user=", string.Empty) ?? string.Empty;
p = p?.Replace("--pass=", string.Empty) ?? string.Empty;
var lr = ctx.login(u,p).Result;
if (!lr.success)
{
Console.WriteLine("Login failure: " + lr.reason);
help();
}
if (args.FirstOrDefault() == "users")
{
user_test(ctx);
}
else
{
uint ms = 100;
string pu = args.FirstOrDefault(x => x.Contains("--pump="));
if (pu != null)
ms = uint.Parse(p.Replace("--pump=", string.Empty));
var order_service = ctx.locate<OrderService>();
var position_service = ctx.locate<PositionService>();
var admin_service = ctx.locate<AdminService>();
var md_relay = ctx.locate<MarketDataRelay>();
var md_source = new MDSource(TimeSpan.FromSeconds(0.1));
var md_client = new MarketDataClient(md_source);
var admin_client = new AdminClient(admin_service, UserTuple.admin);
var sec_resolver = new SecurityResolver(md_relay, md_source.subscribe_securities());
var orders_client = new OrdersClient(
order_service, position_service, admin_client, sec_resolver);
using(var disp = new CompositeDisposable(md_source)) {
if (args.Length > 0 && args.FirstOrDefault().Contains("md"))
{
var s = new MarketDataSample(md_client);
if (args.FirstOrDefault() == "md")
{
if (args.Length >= 5)
{
s.print_security(args[1], args[2], args[3], args[4]);
}
else if (args.Length >= 4)
{
s.print_product(args[1], args[2], args[3]);
}
else
md_help();
}
else
md_help();
}
else if (args.FirstOrDefault() == "order")
{
var os = new OrderSample(
ctx,
orders_client,
md_client,
md_source.subscribe_securities().Select(sec_map =>
sec_map.ToDictionary(kv => kv.Key, kv => kv.Value.security)));
disp.Add(os);
order_sample(os, u, args);
}
else
help();
wait_for_stop();
}
}
}
static void order_sample(OrderSample os, string user, string[] args)
{
if (args.Length >= 10) //--user and --pass are in args[]
{
os.send_order(user, args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
}
else if (args.Length >= 9)
{
os.send_order(user, args[1], args[2], args[3], args[4], args[5], args[6]);
}
else
order_help();
}
static void wait_for_stop()
{
Console.WriteLine("Hit q to stop");
ConsoleKeyInfo c;
do
{
c = Console.ReadKey();
Console.WriteLine();
} while (c.KeyChar != 'q');
}
static void help()
{
Console.WriteLine("BTS Spark SDK");
Console.WriteLine("Usages: spark_sdk [command] [arguments]");
Console.WriteLine();
Console.WriteLine("Commands:");
Console.WriteLine(" md <exchange> <security_type> <symbol> [<security_desc>]");
Console.WriteLine(" order <account> <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]");
Console.WriteLine("Arguments:");
Console.WriteLine(" --user=<bts user name>");
Console.WriteLine(" --pass=<password>");
Console.WriteLine(" --pump=<pump_interval_in_ms=100 default>");
Environment.Exit(1);
}
static void order_help()
{
Console.WriteLine("order <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>] [<user>] [<account>]");
Console.WriteLine("This command sends a limit or market DAY order for the specified security_desc. Leave off the price for a market order");
Console.WriteLine(" example: order \"ACC A1\" GLBX Future ES ESM8 10 2650.0");
Console.WriteLine(" order \"ACC A1\" SIM Future ES SIM:ESM8 -10 2650.0");
Console.WriteLine(" order \"ACC A1\" GLBX Future ES ESM8 10 (this is a market order)");
Environment.Exit(1);
}
static void md_help()
{
Console.WriteLine("md <exchange> <security_type> <symbol>");
Console.WriteLine("This command subscribes to market data for an exchange-type-symbol channel and writes to console.");
Console.WriteLine("Marketdata is read off the wire on the same thread as is used to read and print");
Console.WriteLine(" example: md GLBX Future ES --user=bts --pass=password");
Console.WriteLine(" md SIM Future ES SIM:ESZ8 --user=bts --pass=password");
Console.WriteLine(" md GLBX Spread ES --user=bts --pass=password");
Environment.Exit(1);
}
}
}