diff --git a/src/client/spark_api/utils/Locator.cs b/src/client/spark_api/utils/Locator.cs index 64bbe1711..3d7b3d3aa 100644 --- a/src/client/spark_api/utils/Locator.cs +++ b/src/client/spark_api/utils/Locator.cs @@ -16,6 +16,10 @@ namespace bts.api { return await _context.Value.login(username, password); } + static public void login_with_token(AuthTokenImmutable token) + { + _context.Value.login(token); + } static public AuthTokenImmutable? token => _context.Value.token; } } diff --git a/src/client/spark_fix/FixRouter.cs b/src/client/spark_fix/FixRouter.cs index 670e17fb4..3b06fab04 100644 --- a/src/client/spark_fix/FixRouter.cs +++ b/src/client/spark_fix/FixRouter.cs @@ -31,12 +31,11 @@ namespace bts.fix { readonly ConcurrentDictionary _sessions = new ConcurrentDictionary(); readonly Func _factory; - readonly MarketDataClient _mdglobal = new MarketDataClient(); + readonly MarketDataClient _md = new MarketDataClient(); public FixRouter(Func factory) { _factory = factory; - _mdglobal.pump_once(); //get securities } public IApplication session(SessionID sessionID) @@ -87,18 +86,18 @@ namespace bts.fix IEnumerable IFixRouter.get_securities() { - return _mdglobal.get_securities(); + return _md.securities; } SecurityImmutable? IFixRouter.lookup(uint key) { - return _mdglobal.lookup(key); + return _md.lookup(key); } SecurityImmutable? IFixRouter.lookup(string desc) { - if (_mdglobal.lookup_security_key_from_desc(desc, out uint key)) - return _mdglobal.lookup(key); + if (_md.lookup_security_key_from_desc(desc, out uint key)) + return _md.lookup(key); else return null; } diff --git a/src/client/spark_fix/session/DropCopySession.cs b/src/client/spark_fix/session/DropCopySession.cs index 1a5978036..3de5a9194 100644 --- a/src/client/spark_fix/session/DropCopySession.cs +++ b/src/client/spark_fix/session/DropCopySession.cs @@ -21,7 +21,7 @@ namespace bts.fix { protected IDisposable _fillsdisp; protected IDisposable _ordersdisp; - + protected static Lazy _orderservice = new Lazy(() => bts.api.Locator.locate(), true); protected readonly ConcurrentDictionary _order_cache = new ConcurrentDictionary(); protected readonly ConcurrentDictionary _fix_clorderids = new ConcurrentDictionary(); @@ -114,8 +114,8 @@ namespace bts.fix var scheduler = TaskPoolScheduler.Default; var interval = TimeSpan.FromMilliseconds(500); - var on_orders = _orderservice.subscribei_orders().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache(); - var on_fills = _orderservice.subscribei_fills().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache(); + var on_orders = _orderservice.Value.subscribei_orders().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache(); + var on_fills = _orderservice.Value.subscribei_fills().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache(); _ordersdisp = on_orders.Subscribe(o => { diff --git a/src/client/spark_fix/session/OrderSession.cs b/src/client/spark_fix/session/OrderSession.cs index b235bf3bf..58835fffe 100644 --- a/src/client/spark_fix/session/OrderSession.cs +++ b/src/client/spark_fix/session/OrderSession.cs @@ -69,7 +69,7 @@ namespace bts.fix cr.NewOrder = def; cr.Quantity = Convert.ToUInt32(Math.Abs(req.OrderQty.getValue())); - _orderservice.create_order_async(cr); + _orderservice.Value.create_order_async(cr); } private void set_ordertype(OrderDefinition def, QuickFix.FIX44.NewOrderSingle req, out bool price_req) diff --git a/src/client/spark_fix/session/SessionBase.cs b/src/client/spark_fix/session/SessionBase.cs index 34febe17a..31006229f 100644 --- a/src/client/spark_fix/session/SessionBase.cs +++ b/src/client/spark_fix/session/SessionBase.cs @@ -4,27 +4,28 @@ using System.Linq; using System.Reactive.Linq; using System.Reactive.Concurrency; using System.Text; +using System.Collections.Concurrent; +using System.Runtime.CompilerServices; using QuickFix; using QuickFix.Fields; - +using mbts; +using bts.api; using bts.api.core; using bts.api.orderman; using bts.api.user; using bts.api.admin; -using System.Collections.Concurrent; -using System.Runtime.CompilerServices; namespace bts.fix { abstract class SessionBase : QuickFix.MessageCracker, QuickFix.IApplication { - protected static UserService _userservice = bts.api.Locator.locate(); - protected static OrderService _orderservice = bts.api.Locator.locate(); - protected static AdminService _adminservice = bts.api.Locator.locate(); - protected static bts.metrics.ShellLatencyService _latencyservice = bts.api.Locator.locate(); + protected static AuthService _authservice = bts.api.Locator.locate(); + protected static Lazy _adminservice = new Lazy(() => bts.api.Locator.locate(), true); + protected static Lazy _latencyservice = + new Lazy(() => bts.api.Locator.locate(), true); protected string _user_name; protected AuthToken _token; @@ -41,14 +42,14 @@ namespace bts.fix _router = router; _sess = sess; - _clockdisp = _latencyservice.subscribe_clock().Subscribe(x => + _clockdisp = _latencyservice.Value.subscribe_clock().Subscribe(x => { var t = x.all.FirstOrDefault(); if(t != null) _clock = t.Timestamp; }); - _adminobservable = _adminservice.subscribei_admin_data().Select(x => + _adminobservable = _adminservice.Value.subscribei_admin_data().Select(x => { return new AdminModelWrapper(x.all.TryFirst(), _user_name); }); @@ -82,7 +83,7 @@ namespace bts.fix string pass = string.Empty; if(msg.IsSetPassword()) pass = msg.Password.getValue(); - var resp = _userservice.authenticate_login(new AuthenticateLoginRequest { + var resp = _authservice.authenticate_login(new AuthenticateLoginRequest { Login = msg.Username.getValue(), Password = pass}); if (resp != null && resp.IsValid) _token = resp.Token; @@ -113,8 +114,8 @@ namespace bts.fix async protected void handle_heartbeat(QuickFix.FIX44.Heartbeat hb, SessionID sessionID) { - var resp = await _latencyservice.report_async(new bts.metrics.Report { HostName = "BTSFIX_" + sessionID.ToString(), - Timestamp = _clock, User = _user_name }); + var resp = await _latencyservice.Value.report_async(new bts.metrics.Report { HostName = "BTSFIX_" + sessionID.ToString(), + Timestamp = _clock, User = _user_name }); if (resp.success) send(hb, sessionID); }