From e07d602cf5cd76176dfa2ec28408b50a2f6e225f Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Mon, 10 Dec 2018 12:13:11 -0500 Subject: [PATCH] client MD refactor --- src/client/spark_api/Co2/Co2RelayControl.cs | 4 + src/client/spark_api/md/MDCombined.cs | 3 - src/client/spark_api/md/MDSource.cs | 2 +- src/client/spark_api/md/MarketDataClient.cs | 84 ++++++++++++++----- src/client/spark_api/utils/Authenticator.cs | 23 ----- src/client/spark_api/utils/Locator.cs | 7 +- .../rtd/formatting/BookMDFormatter.cs | 29 +++---- .../rtd/formatting/FormatterFactory.cs | 3 +- .../rtd/formatting/MiscMDFormatter.cs | 10 ++- .../rtd/formatting/TopOfBookMDFormatter.cs | 29 ++++--- .../rtd/formatting/TopicMDFormatter.cs | 47 ++++++----- .../rtd/subscriptions/MDSubscribe.cs | 34 ++++---- .../spark_sdk/samples/MarketDataSample.cs | 19 +++-- src/client/spark_sdk/samples/OrderSample.cs | 4 +- src/client/spark_sdk/samples/SDKMain.cs | 22 +++-- src/client/spark_sdk/samples/UISample.cs | 2 +- src/client/spark_sdk/uisamples/SparkSDKUI.cs | 2 +- 17 files changed, 187 insertions(+), 137 deletions(-) delete mode 100644 src/client/spark_api/utils/Authenticator.cs diff --git a/src/client/spark_api/Co2/Co2RelayControl.cs b/src/client/spark_api/Co2/Co2RelayControl.cs index dbc8f9060..84e17ade0 100644 --- a/src/client/spark_api/Co2/Co2RelayControl.cs +++ b/src/client/spark_api/Co2/Co2RelayControl.cs @@ -25,6 +25,10 @@ namespace mbts.co2 Co2NativeMethods.set_relay_token(_relay, token.Token); } + public void set_token(AuthTokenImmutable token) { + Co2NativeMethods.set_relay_token(_relay, token.Token); + } + public async Task preload_securities(MDRequest.Types.Flags flags=MDRequest.Types.Flags.Security) { var securities = UserSymbol.get_all(); foreach (var future in securities.Where(s => s.type == SecurityType.Future)) { diff --git a/src/client/spark_api/md/MDCombined.cs b/src/client/spark_api/md/MDCombined.cs index 741a8c62f..9c92511e2 100644 --- a/src/client/spark_api/md/MDCombined.cs +++ b/src/client/spark_api/md/MDCombined.cs @@ -54,9 +54,6 @@ namespace bts.md bool m = (_misc as IMDUpdate).update(smd, ref ml); last_update_time = new[] { bl, ll, ml }.Min(); - if (smd.md.market_timestamp > last_update_time) - { - } return b || l || m; } } diff --git a/src/client/spark_api/md/MDSource.cs b/src/client/spark_api/md/MDSource.cs index e9ae6f208..2a0ba5698 100644 --- a/src/client/spark_api/md/MDSource.cs +++ b/src/client/spark_api/md/MDSource.cs @@ -38,7 +38,7 @@ namespace bts.md Task.Run(run); } - public void set_token(AuthToken token) + public void set_token(AuthTokenImmutable token) { _relay.set_token(token); } diff --git a/src/client/spark_api/md/MarketDataClient.cs b/src/client/spark_api/md/MarketDataClient.cs index 3f469db8a..424f11fc1 100644 --- a/src/client/spark_api/md/MarketDataClient.cs +++ b/src/client/spark_api/md/MarketDataClient.cs @@ -24,8 +24,10 @@ namespace bts.md readonly ConcurrentDictionary _data = new ConcurrentDictionary(); readonly List _disp = new List(); - public MarketDataClient(AuthToken token = null) + readonly uint _default_pump_ms; + public MarketDataClient(uint default_pump_ms = 100, AuthToken token = null) { + _default_pump_ms = default_pump_ms; if (token != null) set_auth_token(token); @@ -35,40 +37,36 @@ namespace bts.md _data.AddOrUpdate(entry.Key, entry.Value, (_, __) => entry.Value); })); } - - public void set_auth_token(AuthToken toke) - { - _subscription.set_token(toke); - } - public IEnumerable securities => _data.Values.Select(x => x.security); public IObservable> on_securities { get { return _subscription.on_securities.Select(x => x.Values.Select(xx => xx.security)); } } - public IObservable subscribe_combined(Product product) + public void set_auth_token(AuthTokenImmutable? toke) { - Func where = (x => x.Exchange == product.Exchange && - x.Symbol == product.Symbol && x.security_type() == product.Type); - return subscribe_combined(where); + if(toke.HasValue) + _subscription.set_token(toke.Value); } - - public IObservable subscribe_book(Func filter) + public IObservable subscribe_book(Func filter, + TimeSpan? update_interval = null, IScheduler scheduler = null) { - return _subscribe(filter); + return _subscribe(filter, update_interval, scheduler); } - public IObservable subscribe_last(Func filter) + public IObservable subscribe_last(Func filter, + TimeSpan? update_interval = null, IScheduler scheduler = null) { - return _subscribe(filter); + return _subscribe(filter, update_interval, scheduler); } - public IObservable subscribe_misc(Func filter) + public IObservable subscribe_misc(Func filter, + TimeSpan? update_interval = null, IScheduler scheduler = null) { - return _subscribe(filter); + return _subscribe(filter, update_interval, scheduler); } - public IObservable subscribe_combined(Func filter) + public IObservable subscribe_combined(Func filter, + TimeSpan? update_interval = null, IScheduler scheduler = null) { - return _subscribe(filter); + return _subscribe(filter, update_interval, scheduler); } IObservable _subscribe(Func filter, @@ -90,6 +88,50 @@ namespace bts.md update_interval, scheduler); } + public IObservable> subscribe_book(IEnumerable ids, TimeSpan? update_interval = null, + IScheduler scheduler = null) + { + return _subscribe(ids, update_interval, scheduler); + } + public IObservable> subscribe_last(IEnumerable ids, TimeSpan? update_interval = null, + IScheduler scheduler = null) + { + return _subscribe(ids, update_interval, scheduler); + } + public IObservable> subscribe_misc(IEnumerable ids, TimeSpan? update_interval = null, + IScheduler scheduler = null) + { + return _subscribe(ids, update_interval, scheduler); + } + public IObservable> subscribe_combined(IEnumerable ids, TimeSpan? update_interval = null, + IScheduler scheduler = null) + { + return _subscribe(ids, update_interval, scheduler); + } + + IObservable> _subscribe(IEnumerable ids, TimeSpan? update_interval = null, + IScheduler scheduler = null) where T : IMDData, IMDUpdate, new() + { + List> slots = ids.Where(ii => _data.TryGetValue(ii, out SecurityMD _)).Select(x => + { + _data.TryGetValue(x, out SecurityMD smd); + return new Slot(smd); + }).ToList(); + return timer_pump>((last_timer_tick, observer) => + { + List updates = new List(); + foreach (var slot in slots) + { + bool did_update = slot.data.update(slot.secmd, ref slot.last_update_time); + if (slot.last_update_time > last_timer_tick) + updates.Add(slot.data); + } + if(updates.Count > 0) + observer.OnNext(updates); + }, + update_interval, scheduler); + } + class Slot where T : IMDData, IMDUpdate, new() { public Slot(SecurityMD md) @@ -106,7 +148,7 @@ namespace bts.md IObservable timer_pump(Action> tick, TimeSpan? interval, IScheduler scheduler = null) { if(!interval.HasValue) - interval = TimeSpan.FromMilliseconds(100); + interval = TimeSpan.FromMilliseconds(_default_pump_ms); ulong last_update_time = 0; return Observable.Create(observer => { diff --git a/src/client/spark_api/utils/Authenticator.cs b/src/client/spark_api/utils/Authenticator.cs deleted file mode 100644 index 001defa86..000000000 --- a/src/client/spark_api/utils/Authenticator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Threading.Tasks; -using bts.api; -using bts.api.core; - -namespace bts.api -{ - public class Authenticator - { - readonly static Lazy _auth = new Lazy(() => Locator.locate(), true); - AuthToken _token = null; - public Authenticator() { } - - public AuthToken last_token => _token; - public async Task login(string login, string password) - { - var res = await _auth.Value.authenticate_login_async(new user.AuthenticateLoginRequest { Login = login, Password = password }); - if (res.success) - _token = res.value.Token; - return _token; - } - } -} \ No newline at end of file diff --git a/src/client/spark_api/utils/Locator.cs b/src/client/spark_api/utils/Locator.cs index e86c98a05..a95cb9fb3 100644 --- a/src/client/spark_api/utils/Locator.cs +++ b/src/client/spark_api/utils/Locator.cs @@ -11,6 +11,11 @@ namespace bts.api public static T locate(string qualifier="") where T : class, IApiClient { return _context.Value.locate(qualifier); - } + } + static public async Task login(string username, string password) + { + return await _context.Value.login(username, password); + } + static public AuthTokenImmutable? token => _context.Value.token; } } diff --git a/src/client/spark_excel/rtd/formatting/BookMDFormatter.cs b/src/client/spark_excel/rtd/formatting/BookMDFormatter.cs index b676e4877..ceebff059 100644 --- a/src/client/spark_excel/rtd/formatting/BookMDFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/BookMDFormatter.cs @@ -1,21 +1,22 @@ using System; +using bts.md; namespace bts.excel.rtd { class BookMDFormatter : IExcelFormatter { - readonly co2.ChannelUpdate _update; - public BookMDFormatter(co2.ChannelUpdate upd) + readonly IMDBook _update; + public BookMDFormatter(IMDBook upd) { _update = upd; } - public static double format_md(long mantissa, int exponent) + public object[,] format(bool include_headers = false) { - return mantissa * Math.Pow(10, exponent); + return format(_update, include_headers); } - public object[,] format(bool include_headers = false) + static public object[,] format(IMDBook update, bool include_headers = false) { const int cols = 5; const int rows = 30; @@ -24,21 +25,21 @@ namespace bts.excel.rtd for (int j = 0; j < cols; j++) ret[i, j] = string.Empty; - if (_update.Direct != null) + if (update != null) { int idx = 0; - for (int j = _update.Direct.Asks.Count - 1; j >= 0 && idx < rows; j--) + for (int j = update.asks.Count - 1; j >= 0 && idx < rows; j--) { - var ask = _update.Direct.Asks[j]; - ret[idx, 1] = format_md(ask.Mantissa, ask.Exponent); - ret[idx, 2] = ask.Size; + var ask = update.asks[j]; + ret[idx, 1] = ask.price; + ret[idx, 2] = ask.size; idx++; } - for (int j = 0; j < _update.Direct.Bids.Count && idx < rows; j++) + for (int j = 0; j < update.bids.Count && idx < rows; j++) { - var bid = _update.Direct.Bids[j]; - ret[idx, 1] = format_md(bid.Mantissa, bid.Exponent); - ret[idx, 0] = bid.Size; + var bid = update.bids[j]; + ret[idx, 1] = bid.price; + ret[idx, 0] = bid.size; idx++; } } diff --git a/src/client/spark_excel/rtd/formatting/FormatterFactory.cs b/src/client/spark_excel/rtd/formatting/FormatterFactory.cs index b4fcbd09e..eb718e228 100644 --- a/src/client/spark_excel/rtd/formatting/FormatterFactory.cs +++ b/src/client/spark_excel/rtd/formatting/FormatterFactory.cs @@ -1,4 +1,5 @@ using System; +using bts.md; namespace bts.excel.rtd { @@ -6,7 +7,7 @@ namespace bts.excel.rtd { public static IExcelFormatter make_formatter(object data) { - if(data is co2.ChannelUpdate upd) + if(data is IMDBook upd) return new BookMDFormatter(upd); else { diff --git a/src/client/spark_excel/rtd/formatting/MiscMDFormatter.cs b/src/client/spark_excel/rtd/formatting/MiscMDFormatter.cs index 6f7119b7d..5e79d6ae5 100644 --- a/src/client/spark_excel/rtd/formatting/MiscMDFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/MiscMDFormatter.cs @@ -1,16 +1,22 @@ using System; +using bts.md; namespace bts.excel.rtd { class MiscMDFormatter : IExcelFormatter { - readonly co2.ChannelUpdate _update; - public MiscMDFormatter(co2.ChannelUpdate upd) + readonly IMDMisc _update; + public MiscMDFormatter(IMDMisc upd) { _update = upd; } public object[,] format(bool include_headers = false) + { + return format(_update, include_headers); + } + + static public object[,] format(IMDMisc update, bool include_headers = false) { return new object[0, 0]; } diff --git a/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs b/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs index 82cb46be8..9b29ea5e9 100644 --- a/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs @@ -1,17 +1,22 @@ - using System; +using bts.md; namespace bts.excel.rtd { class TopOfBookMDFormatter : IExcelFormatter { - readonly co2.ChannelUpdate _update; - public TopOfBookMDFormatter(co2.ChannelUpdate upd) + readonly IMDBook _update; + public TopOfBookMDFormatter(IMDBook upd) { _update = upd; } public object[,] format(bool include_headers = false) + { + return format(_update, include_headers); + } + + static public object[,] format(IMDBook update, bool include_headers = false) { const int cols = 4; const int rows = 1; @@ -20,22 +25,22 @@ namespace bts.excel.rtd for (int j = 0; j < cols; j++) ret[i, j] = string.Empty; - if (_update.Direct != null) + if (update != null) { int idx = 0; - for (int j = 0; j < _update.Direct.Asks.Count && idx < rows; j++) + for (int j = 0; j < update.asks.Count && idx < rows; j++) { - var ask = _update.Direct.Asks[j]; - ret[idx, 2] = BookMDFormatter.format_md(ask.Mantissa, ask.Exponent); - ret[idx, 3] = ask.Size; + var ask = update.asks[j]; + ret[idx, 2] = ask.price; + ret[idx, 3] = ask.size; idx++; } idx = 0; - for (int j = 0; j < _update.Direct.Bids.Count && idx < rows; j++) + for (int j = 0; j < update.bids.Count && idx < rows; j++) { - var bid = _update.Direct.Bids[j]; - ret[idx, 1] = BookMDFormatter.format_md(bid.Mantissa, bid.Exponent); - ret[idx, 0] = bid.Size; + var bid = update.bids[j]; + ret[idx, 1] = bid.price; + ret[idx, 0] = bid.size; idx++; } } diff --git a/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs b/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs index 92af1f8a3..3338a70bb 100644 --- a/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs @@ -1,86 +1,95 @@ using System; +using bts.md; namespace bts.excel.rtd { class TopicMDFormatter : IExcelFormatter { - readonly co2.ChannelUpdate _update; + readonly IMDCombined _update; readonly string _topic; - public TopicMDFormatter(co2.ChannelUpdate upd, string topic) + public TopicMDFormatter(IMDCombined upd, string topic) { _update = upd; _topic = topic; } public object[,] format(bool include_headers = false) + { + return format(_update, _topic, include_headers); + } + + static public object[,] format(IMDCombined update, string topic, bool include_headers = false) { var retval = new object[1, 1]; - switch (_topic.ToLower()) + if(update == null || string.IsNullOrEmpty(topic)) + return retval; + + switch (topic.ToLower()) { case "bid": case "bidprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Direct?.Bids?[0]?.Mantissa ?? 0, _update?.Direct?.Bids?[0]?.Exponent ?? 0); + retval[0, 0] = update.bids?[0]?.price; break; case "ask": case "askprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Direct?.Asks?[0]?.Mantissa ?? 0, _update?.Direct?.Asks?[0]?.Exponent ?? 0); + retval[0, 0] = update.asks?[0]?.price; break; case "bidsize": case "bidqty": - retval[0, 0] = _update?.Direct?.Bids?[0]?.Size; + retval[0, 0] = update.bids?[0]?.size; break; case "asksize": case "askqty": - retval[0, 0] = _update?.Direct?.Asks?[0]?.Size; + retval[0, 0] = update.asks?[0]?.size; break; case "impliedbid": case "impliedbidprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Implied?.Bids?[0]?.Mantissa ?? 0, _update?.Implied?.Bids?[0]?.Exponent ?? 0); + retval[0, 0] = update.bids?[0]?.price; //TODO is this the first price with impsz > 0? break; case "impliedask": case "impliedaskprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Implied?.Asks?[0]?.Mantissa ?? 0, _update?.Implied?.Asks?[0]?.Exponent ?? 0); + retval[0, 0] = update.asks?[0]?.price; break; case "impliedbidsize": case "impliedbidqty": - retval[0, 0] = _update?.Implied?.Bids?[0]?.Size; + retval[0, 0] = update.bids?[0]?.implied_size; break; case "impliedasksize": case "impliedaskqty": - retval[0, 0] = _update?.Implied?.Asks?[0]?.Size; + retval[0, 0] = update.asks?[0]?.implied_size; break; case "settlement": case "settlementprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Misc?.Settlement?.Mantissa ?? 0, _update?.Misc?.Settlement?.Exponent ?? 0); + retval[0, 0] = update.settlement_price; break; case "previoussettlement": case "previoussettlementprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.Misc?.PreviousSettlementPrice?.Mantissa ?? 0, _update?.Misc?.PreviousSettlementPrice?.Exponent ?? 0); + retval[0, 0] = update.previous_settlement_price; break; case "open": case "openprice": - retval[0, 0] = _update?.Misc?.OpenPrice; + retval[0, 0] = update.open_price; break; case "close": case "closeprice": - retval[0, 0] = _update?.Misc?.ClosePrice; + retval[0, 0] = update.close_price; break; case "high": case "highprice": - retval[0, 0] = _update?.Misc?.SessionHigh; + retval[0, 0] = update.session_high; break; case "low": case "lowprice": - retval[0, 0] = _update?.Misc?.SessionLow; + retval[0, 0] = update.session_low; break; case "last": case "lastprice": - retval[0, 0] = BookMDFormatter.format_md(_update?.LastTrade?.Mantissa ?? 0, _update?.LastTrade?.Exponent ?? 0); + retval[0, 0] = update?.last.price; break; case "lastsize": case "lastqty": - retval[0, 0] = _update?.LastTrade?.Size; + retval[0, 0] = update?.last.size; break; } return retval; diff --git a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs index 712cc5e91..6da9579b1 100644 --- a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs +++ b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs @@ -14,15 +14,19 @@ 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 { - var toke = await _auth.login(login, password); - _md.set_auth_token(toke); - handle.SetResult(toke?.Token ?? "Could not log in check user/pass"); + var res = await Locator.login(login, password); + if (res && Locator.token.HasValue) + { + _md.set_auth_token(Locator.token); + handle.SetResult("Login Successful"); + } + else + handle.SetResult("Login Error: Could not log in check user/pass"); } catch(Exception ex) { @@ -62,10 +66,10 @@ namespace bts.excel.rtd if (string.IsNullOrEmpty(contract)) return Observable.Return("Can't Parse Contract: " + contract ?? string.Empty); - Product prod = new Product() { Exchange = ven, Type = sectype, Symbol = symbol }; - Func filter = (x => x.Glbx.SecurityDesc == contract); //TODO GLBX + Func where = (x => x.Exchange == ven && x.Symbol == symbol && x.security_type() == sectype && + x.HasGlbx && x.Glbx.SecurityDesc == contract); - var stream = market_data(ven).subscribe(prod).Where(x => filter(x.Security)); + var stream = market_data(ven).subscribe_combined(where); return stream; } @@ -81,8 +85,8 @@ namespace bts.excel.rtd return ObservableRtdUtil.Observe(nameof(spark_md_book), param, () => md_observable(contract, symbol, security_type, exchange).Select(x => { - if (x is co2.ChannelUpdate upd) - return new BookMDFormatter(upd).format(); + if (x is IMDBook upd) + return BookMDFormatter.format(upd); return x; })); // security_type = string.IsNullOrEmpty(security_type) ? SecurityType.Future.ToString() : security_type; @@ -107,8 +111,8 @@ namespace bts.excel.rtd return ObservableRtdUtil.Observe(nameof(spark_md_top_of_book), param, () => md_observable(contract, symbol, security_type, exchange).Select(x => { - if (x is co2.ChannelUpdate upd) - return new TopOfBookMDFormatter(upd).format(); + if (x is IMDBook upd) + return TopOfBookMDFormatter.format(upd); return x; })); } @@ -124,8 +128,8 @@ namespace bts.excel.rtd return ObservableRtdUtil.Observe(nameof(spark_md_misc), param, () => md_observable(contract, symbol, security_type, exchange).Select(x => { - if (x is co2.ChannelUpdate upd) - return new MiscMDFormatter(upd).format(); + if (x is IMDMisc upd) + return MiscMDFormatter.format(upd); return x; })); @@ -143,8 +147,8 @@ namespace bts.excel.rtd return ObservableRtdUtil.Observe(nameof(spark_md), param, () => md_observable(contract, symbol, security_type, exchange).Select(x => { - if (x is co2.ChannelUpdate upd) - return new TopicMDFormatter(upd, topic).format(); + if (x is IMDCombined upd) + return TopicMDFormatter.format(upd, topic); return x; })); } diff --git a/src/client/spark_sdk/samples/MarketDataSample.cs b/src/client/spark_sdk/samples/MarketDataSample.cs index 6d4dd0146..11995514f 100644 --- a/src/client/spark_sdk/samples/MarketDataSample.cs +++ b/src/client/spark_sdk/samples/MarketDataSample.cs @@ -9,8 +9,7 @@ using System.Reactive.Concurrency; using bts.api; using bts.api.core; -using bts.co2; -using bts.api.md; +using bts.md; namespace bts.sdk { @@ -24,7 +23,7 @@ namespace bts.sdk _md = client; } - void print_update(ChannelUpdate update) + void print_update(IMDData update) { Console.WriteLine(update.ToString()); Console.WriteLine(); @@ -46,12 +45,14 @@ namespace bts.sdk return st; } - public void print_channel(string exch, string sectype, string symbol) + public void print_product(string exch, string sectype, string symbol) { Venue ven = parse_venue(exch); SecurityType st = parse_security_type(sectype); Product prod = new Product() { Exchange = ven, Type = st, Symbol = symbol }; - _disps.Add(_md.subscribe(prod).Subscribe(x => + Func where = (x => x.Exchange == ven && x.Symbol == symbol && x.security_type() == st); + + _disps.Add(_md.subscribe_combined(where).Subscribe(x => { print_update(x); })); @@ -61,11 +62,11 @@ namespace bts.sdk { Venue ven = parse_venue(exch); SecurityType st = parse_security_type(sectype); - Product prod = new Product() { Exchange = ven, Type = st, Symbol = symbol }; - Func filter = (x => x.Glbx.SecurityDesc == security_desc); - //if you have a security_id, we could make a more specifics subscription, but this is a command line driver.... - _disps.Add(_md.subscribe(prod).Where(x => filter(x.Security)).Subscribe(x => + Func where = (x => x.Exchange == ven && x.Symbol == symbol && x.security_type() == st && + x.HasGlbx && x.Glbx.SecurityDesc == security_desc); + + _disps.Add(_md.subscribe_combined(where).Subscribe(x => { print_update(x); })); diff --git a/src/client/spark_sdk/samples/OrderSample.cs b/src/client/spark_sdk/samples/OrderSample.cs index 186041c1a..0c6735ff2 100644 --- a/src/client/spark_sdk/samples/OrderSample.cs +++ b/src/client/spark_sdk/samples/OrderSample.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using System.Reactive.Linq; using bts.api; -using bts.api.md; +using bts.md; using bts.api.core; using bts.api.orderman; using bts.api.user; @@ -58,7 +58,7 @@ namespace bts.sdk else cr.NewOrder.CustomDef = new CustomOrderDefinition() { Market = new MarketOrderDefinition() }; var sec = await _md.find_security_async(x => x.Glbx.SecurityDesc == security_desc.ToUpper()); - cr.NewOrder.SecurityKey = sec.Id; + cr.NewOrder.SecurityKey = sec.Value.Id; Result resp = await _orders.Value.create_order_async(cr); print_update(resp); if(resp.value != null) diff --git a/src/client/spark_sdk/samples/SDKMain.cs b/src/client/spark_sdk/samples/SDKMain.cs index 3e7670e48..0ec5087b5 100644 --- a/src/client/spark_sdk/samples/SDKMain.cs +++ b/src/client/spark_sdk/samples/SDKMain.cs @@ -6,7 +6,7 @@ using System.Reactive.Disposables; using bts.api; using bts.api.core; -using bts.api.md; +using bts.md; namespace bts.sdk { @@ -14,10 +14,8 @@ namespace bts.sdk public class SDKMain { private static void user_test() - { - var ctx = new ServiceContext(); - - var s = ctx.locate(); + { + var s = Locator.locate(); var r = new api.user.GetUsersRequest(); var resp = s.get_users(r); Console.WriteLine("{0}", resp); @@ -31,7 +29,12 @@ namespace bts.sdk } else { - MarketDataClient client = new MarketDataClient(); + uint ms = 100; + string p = args.FirstOrDefault(x => x.Contains("--pump=")); + if (p != null) + ms = uint.Parse(p.Replace("--pump=", string.Empty)); + + MarketDataClient client = new MarketDataClient(ms); CompositeDisposable disp = new CompositeDisposable(client); if (args.FirstOrDefault() == "ui") { @@ -56,7 +59,7 @@ namespace bts.sdk } else if (args.Length >= 4) { - s.print_channel(args[1], args[2], args[3]); + s.print_product(args[1], args[2], args[3]); } else md_help(); @@ -73,11 +76,6 @@ namespace bts.sdk 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); } } diff --git a/src/client/spark_sdk/samples/UISample.cs b/src/client/spark_sdk/samples/UISample.cs index 6b8660454..97ae9fded 100644 --- a/src/client/spark_sdk/samples/UISample.cs +++ b/src/client/spark_sdk/samples/UISample.cs @@ -2,7 +2,7 @@ using System; using System.Linq; using bts.api; -using bts.api.md; +using bts.md; namespace bts.sdk.ui { diff --git a/src/client/spark_sdk/uisamples/SparkSDKUI.cs b/src/client/spark_sdk/uisamples/SparkSDKUI.cs index 9b56d2604..fadb12e0a 100644 --- a/src/client/spark_sdk/uisamples/SparkSDKUI.cs +++ b/src/client/spark_sdk/uisamples/SparkSDKUI.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using bts.api; -using bts.api.md; +using bts.md; namespace bts.sdk.ui {