From 70db5ceb10a95581885d153efe59a31049088dca Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Mon, 10 Dec 2018 12:19:16 -0500 Subject: [PATCH] added spark_md_last to excel --- .../rtd/formatting/LastMDFormatter.cs | 35 +++++++++++++++++++ .../rtd/subscriptions/MDSubscribe.cs | 22 ++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/client/spark_excel/rtd/formatting/LastMDFormatter.cs diff --git a/src/client/spark_excel/rtd/formatting/LastMDFormatter.cs b/src/client/spark_excel/rtd/formatting/LastMDFormatter.cs new file mode 100644 index 000000000..5c1bfca4c --- /dev/null +++ b/src/client/spark_excel/rtd/formatting/LastMDFormatter.cs @@ -0,0 +1,35 @@ +using System; +using bts.md; + +namespace bts.excel.rtd +{ + class LastMDFormatter : IExcelFormatter + { + readonly IMDLast _update; + public LastMDFormatter(IMDLast upd) + { + _update = upd; + } + + public object[,] format(bool include_headers = false) + { + return format(_update, include_headers); + } + + static public object[,] format(IMDLast update, bool include_headers = false) + { + const int cols = 3; + const int rows = 1; + var ret = new object[rows, cols]; + + if (update != null) + { + ret[0, 0] = update.last?.price; + ret[0, 1] = update.last?.size; + ret[0, 1] = update.last_time; + } + return ret; + } + } + +} \ No newline at end of file diff --git a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs index 6da9579b1..bf73fae89 100644 --- a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs +++ b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs @@ -115,7 +115,25 @@ namespace bts.excel.rtd return TopOfBookMDFormatter.format(upd); return x; })); - } + } + + [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark last trade market data")] + public static object spark_md_last( + [ExcelArgument("Required. The specific contract, GCZ8 or ZNU8-ZNZ8, etc")] string contract, + [ExcelArgument("Required. The symbol, GC or ZN, etc")] string symbol, + [ExcelArgument("Optional. The type, Future or Spread, default = Future")] string security_type = null, + [ExcelArgument("Optional. The exchange, default = GLBX")] string exchange = null) + { + var param = new object[] { contract, symbol, security_type, exchange }; + return ObservableRtdUtil.Observe(nameof(spark_md_last), param, + () => md_observable(contract, symbol, security_type, exchange).Select(x => + { + if (x is IMDLast upd) + return LastMDFormatter.format(upd); + return x; + })); + + } [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark miscellaneous market data")] public static object spark_md_misc( @@ -135,7 +153,7 @@ namespace bts.excel.rtd } - [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark top of book market data")] + [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark topic based market data")] public static object spark_md( [ExcelArgument("Required. The 'Topic' string, 'bid', 'ask', etc")] string topic, [ExcelArgument("Required. The specific contract, GCZ8 or ZNU8-ZNZ8, etc")] string contract,