fix lives
This commit is contained in:
1 parent
941f4bf837
commit
0d83f28cbc
5 files changed
+26
-22
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,11 @@ namespace bts.fix
|
||||
{
|
||||
readonly ConcurrentDictionary<SessionID, QuickFix.IApplication> _sessions = new ConcurrentDictionary<SessionID, IApplication>();
|
||||
readonly Func<IFixRouter, SessionID, IApplication> _factory;
|
||||
readonly MarketDataClient _mdglobal = new MarketDataClient();
|
||||
readonly MarketDataClient _md = new MarketDataClient();
|
||||
|
||||
public FixRouter(Func<IFixRouter, SessionID, IApplication> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
_mdglobal.pump_once(); //get securities
|
||||
}
|
||||
|
||||
public IApplication session(SessionID sessionID)
|
||||
@@ -87,18 +86,18 @@ namespace bts.fix
|
||||
|
||||
IEnumerable<SecurityImmutable> 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;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace bts.fix
|
||||
{
|
||||
protected IDisposable _fillsdisp;
|
||||
protected IDisposable _ordersdisp;
|
||||
|
||||
protected static Lazy<OrderService> _orderservice = new Lazy<OrderService>(() => bts.api.Locator.locate<OrderService>(), true);
|
||||
|
||||
protected readonly ConcurrentDictionary<uint, OrderRecordImmutable> _order_cache = new ConcurrentDictionary<uint, OrderRecordImmutable>();
|
||||
protected readonly ConcurrentDictionary<uint, string> _fix_clorderids = new ConcurrentDictionary<uint, string>();
|
||||
@@ -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 =>
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<UserService>();
|
||||
protected static OrderService _orderservice = bts.api.Locator.locate<OrderService>();
|
||||
protected static AdminService _adminservice = bts.api.Locator.locate<AdminService>();
|
||||
protected static bts.metrics.ShellLatencyService _latencyservice = bts.api.Locator.locate<bts.metrics.ShellLatencyService>();
|
||||
protected static AuthService _authservice = bts.api.Locator.locate<AuthService>();
|
||||
protected static Lazy<AdminService> _adminservice = new Lazy<AdminService>(() => bts.api.Locator.locate<AdminService>(), true);
|
||||
protected static Lazy<bts.metrics.ShellLatencyService> _latencyservice =
|
||||
new Lazy<bts.metrics.ShellLatencyService>(() => bts.api.Locator.locate<bts.metrics.ShellLatencyService>(), 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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user