Files
spark/src/client/spark_sdk/samples/SDKMain.cs
T

144 lines
5.3 KiB
C#

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Reactive.Disposables;
using bts.api;
using bts.api.core;
using bts.api.md;
namespace bts.sdk
{
public class SDKMain
{
public static void Main(string[] args)
{
MarketDataClient client = MarketDataClient.create();
CompositeDisposable disp = new CompositeDisposable(client);
if (args.FirstOrDefault() == "ui")
{
if (args.Length >= 6)
{
using (var ui = new ui.UISample(client))
{
ui.simple_price_ui(args[1], args[2], args[3], args[4], args[5]);
}
}
else
ui_help();
}
else if (args.Length > 0 && args.FirstOrDefault().Contains("md"))
{
var s = new MarketDataSample(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_channel(args[1], args[2], args[3]);
}
else
md_help();
}
else
md_help();
}
else if (args.FirstOrDefault() == "order")
{
OrderSample os = new OrderSample(client);
disp.Add(os);
order_sample(os, args);
}
else
help();
int ms = 100;
string p = args.FirstOrDefault(x => x.Contains("--pump="));
if (p != null)
ms = int.Parse(p.Replace("--pump=", string.Empty));
client.run_pump(TimeSpan.FromMilliseconds(ms));
wait_for_stop(disp);
}
static async void order_sample(OrderSample os, string[] args)
{
if (args.Length >= 9)
{
await os.send_order(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
}
else if (args.Length >= 7)
{
await os.send_order(args[1], args[2], args[3], args[4], args[5], args[6]);
}
else if (args.Length >= 6)
{
await os.send_order(args[1], args[2], args[3], args[4], args[5]);
}
else
order_help();
}
static void wait_for_stop(IDisposable disp)
{
Console.WriteLine("Hit q to stop");
ConsoleKeyInfo c;
do
{
c = Console.ReadKey();
Console.WriteLine();
} while (c.KeyChar != 'q');
disp.Dispose();
}
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(" ui <exchange> <security_type> <symbol> <security_desc> <poll_interval_in_ms>");
Console.WriteLine(" order <exchange> <security_type> <symbol> <security_desc> <signed_quantity> [<price>]");
Console.WriteLine("Arguments:");
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 GLBX Future ES ESM8 -2 2650.25");
Console.WriteLine(" order GLBX Future ES ESM8 -2");
Console.WriteLine(" order GLBX Future ES ESM8 10 2650.0 bts \"ACC A1\"");
Console.WriteLine(" order GLBX Future ES ESM8 10 2650.0");
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");
Console.WriteLine(" md GLBX Future ES ESZ8");
Console.WriteLine(" md GLBX Spread ES");
Environment.Exit(1);
}
static void ui_help()
{
Console.WriteLine("ui <exchange> <security_type> <symbol> <security_desc> <poll_interval_in_ms>");
Console.WriteLine("This command subscribes to market data for a specific security and writes to a UI on a specified refresh interval (in ms).");
Console.WriteLine("Marketdata is read off the wire on one thread and posted to the GUI on another through Observable.Timer()");
Console.WriteLine(" example: ui GLBX Future ES ESZ8 25");
Environment.Exit(1);
}
}
}