From 9c8bb7efeb7882c03f282897724e30226fb8b3fc Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Fri, 9 Nov 2018 12:12:31 -0500 Subject: [PATCH] excel is in with the mics --- .../extensions/OrderService_Excel.cs | 26 ++++++++++++++++++- .../rtd/formatting/JsonFormatter.cs | 3 ++- .../rtd/subscriptions/MDSubscribe.cs | 3 ++- src/client/spark_excel/utils/Utilities.cs | 15 +++++++++++ tools/runexcel.cmd | 4 +++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tools/runexcel.cmd diff --git a/src/client/spark_excel/extensions/OrderService_Excel.cs b/src/client/spark_excel/extensions/OrderService_Excel.cs index dcdb0dec6..e081916aa 100644 --- a/src/client/spark_excel/extensions/OrderService_Excel.cs +++ b/src/client/spark_excel/extensions/OrderService_Excel.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; using ExcelDna.Integration; +using ExcelDna.Integration.Rtd; +using ExcelDna.Registration.Utils; using bts.api.admin; using bts.excel; @@ -16,7 +19,28 @@ namespace bts.api.orderman { readonly static Lazy _users = new Lazy(() => Locator.locate(), true); readonly static Lazy _admin = new Lazy(() => Locator.locate(), true); - + + [ExcelFunction(Category = "BTS", Description = "Get All Accessible Accounts")] + async public static void spark_get_accounts(string login_token, ExcelAsyncHandle handle) + { + try + { + List accts = new List(); + var admin = await _admin.Value.get_filtered_admin_data_async(new FilteredAdminDataRequest { Token = login_token }); + if (admin.success) + { + foreach (var acc in admin.value.Accounts) + if(acc.IsPresent) + accts.Add(acc.Name); + } + var res = Utilities.make_column_vector(accts.ToArray()); + handle.SetResult(res); + } + catch (Exception ex) + { + handle.SetException(ex); + } + } [ExcelFunction(Category = "BTS", Description = "Cancel an Order by Order ID", IsMacroType = true)] public static object spark_orderservice_cancel_order(long order_id) diff --git a/src/client/spark_excel/rtd/formatting/JsonFormatter.cs b/src/client/spark_excel/rtd/formatting/JsonFormatter.cs index 1db45e17b..06dddf859 100644 --- a/src/client/spark_excel/rtd/formatting/JsonFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/JsonFormatter.cs @@ -6,6 +6,7 @@ using System.Reactive.Linq; using Google.Protobuf; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using ExcelDna.Integration; namespace bts.excel.rtd { @@ -17,7 +18,7 @@ namespace bts.excel.rtd _data = data; } - #region parser + #region parser static IDictionary parse_dictionary(object[,] range) { Dictionary dict = new Dictionary(); diff --git a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs index 8b60cdcfd..cdfc364b4 100644 --- a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs +++ b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs @@ -4,17 +4,18 @@ using System.Linq; using ExcelDna.Integration; using ExcelDna.Integration.Rtd; +using ExcelDna.Registration.Utils; using System.Reactive.Linq; using bts.api; using bts.api.md; using bts.api.orderman; -using ExcelDna.Registration.Utils; namespace bts.excel.rtd { public class MDSubscribe { static Authenticator _auth = new Authenticator(); + [ExcelFunction(Category = "BTS", Description = "Log in to BTS Spark")] async public static void spark_login(string login, string password, ExcelAsyncHandle handle) { try diff --git a/src/client/spark_excel/utils/Utilities.cs b/src/client/spark_excel/utils/Utilities.cs index b50d116a3..70c6dded1 100644 --- a/src/client/spark_excel/utils/Utilities.cs +++ b/src/client/spark_excel/utils/Utilities.cs @@ -5,12 +5,27 @@ using System.Reflection; using System.Text.RegularExpressions; using ExcelDna.Integration; using bts.api; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace bts.excel { public class Utilities { + [ExcelFunction] + public static object bts_json_lookup(string json, string key1, string key2 = null, string key3 = null) + { + var jo = JObject.Parse(json); + if (key1 != null && key2 != null && key3 != null) + return jo[key1][key2][key3]; + else if (key1 != null && key2 != null) + return jo[key1][key2]; + else if (key1 != null) + return jo[key1]; + return json; + } + public static bool parse_venue(string exch, out Venue ven) { if (!Enum.TryParse(exch.ToUpper(), true, out ven)) diff --git a/tools/runexcel.cmd b/tools/runexcel.cmd new file mode 100644 index 000000000..8d1c9ea90 --- /dev/null +++ b/tools/runexcel.cmd @@ -0,0 +1,4 @@ +@echo off +pushd %~dp0\..\build\debug\bin\net471\ +start spark_excel-addin64.xll +popd