Compare commits
82
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f62d29f66 | ||
|
|
dc8e65923d | ||
|
|
1469373b9c | ||
|
|
820e937336 | ||
|
|
8b73878782 | ||
|
|
b15106dac4 | ||
|
|
100316b791 | ||
|
|
3c98425226 | ||
|
|
1aa9c46367 | ||
|
|
5211cab351 | ||
|
|
e89a4cce53 | ||
|
|
cb56b90737 | ||
|
|
761a89f052 | ||
|
|
cab6b56606 | ||
|
|
8a743a91a5 | ||
|
|
5dec5dc392 | ||
|
|
27aa4fca26 | ||
|
|
84a2e50bf7 | ||
|
|
297eb5b25b | ||
|
|
d9d0e1f4ef | ||
|
|
6ec0cc8bbe | ||
|
|
795b77ea3f | ||
|
|
91c97d32bb | ||
|
|
e0c50703d7 | ||
|
|
dab1e76766 | ||
|
|
b8c927df27 | ||
|
|
2684d25f09 | ||
|
|
7c95a77ae2 | ||
|
|
31b115d13b | ||
|
|
d681a6924b | ||
|
|
d0cce84d2e | ||
|
|
532591c34f | ||
|
|
7f187224c1 | ||
|
|
79b2121f5e | ||
|
|
0bd477594c | ||
|
|
149cd90fb4 | ||
|
|
f74e719a9f | ||
|
|
8b68beae96 | ||
|
|
9cc0b471f2 | ||
|
|
50e61604ba | ||
|
|
6bd23f106f | ||
|
|
dfd8348724 | ||
|
|
d2e9352e48 | ||
|
|
da42e95754 | ||
|
|
a878a55ac1 | ||
|
|
4305d560aa | ||
|
|
055f0015e7 | ||
|
|
80850146c1 | ||
|
|
0680dddab4 | ||
|
|
70aa62c0cf | ||
|
|
06165b3842 | ||
|
|
f21902d60d | ||
|
|
a27f383b62 | ||
|
|
35d4fcc513 | ||
|
|
8a96b00f64 | ||
|
|
2d06fd3d92 | ||
|
|
76050e0722 | ||
|
|
a3f0c2fbf6 | ||
|
|
1ccc4c3746 | ||
|
|
e5d85db888 | ||
|
|
e47b1c3048 | ||
|
|
039791a296 | ||
|
|
e6884b6654 | ||
|
|
8cbae28dd8 | ||
|
|
010a1fecb1 | ||
|
|
999973c349 | ||
|
|
4663ae9e4d | ||
|
|
d7d170f228 | ||
|
|
1d538b4cb0 | ||
|
|
b42febdf60 | ||
|
|
71915de4b0 | ||
|
|
be5f54326e | ||
|
|
f89fb76cb2 | ||
|
|
16adb9ee18 | ||
|
|
154a637ee1 | ||
|
|
399e4bf654 | ||
|
|
5908b4478e | ||
|
|
44571a5af5 | ||
|
|
62274f5129 | ||
|
|
b5b5101faf | ||
|
|
bb232d8f1e | ||
|
|
aaca502500 |
No files matched your search
@@ -34,5 +34,3 @@ trace_data/
|
||||
/doc/user/public/*
|
||||
.ionide/*
|
||||
/.ignore
|
||||
/build
|
||||
/analysis_data
|
||||
+1
-1
@@ -40,7 +40,7 @@ else ()
|
||||
-fPIC -Wall -pedantic -Wextra -Werror \
|
||||
-Wno-missing-braces -Wno-ignored-qualifiers \
|
||||
--std=c++17 -fdiagnostics-color")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG -O3")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef")
|
||||
add_subdirectory(src/server/sparkd)
|
||||
add_subdirectory(src/lib)
|
||||
|
||||
@@ -4,6 +4,19 @@ weight = 3
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
## 2.11.0
|
||||
### User Visible Changes
|
||||
- Fixed fills form time filter to also apply to SOD fills
|
||||
- Addressed an issue that could prevent the web Admin UI from displaying over slow HTTP connections
|
||||
- Removed the option to enter manual spread fills
|
||||
- Fixed an issue that could cause erroneous fill account attribution in the event of a crash
|
||||
### Internal Changes
|
||||
- Added support for tag 1031. Currently defaults to Y, can it be override through config.
|
||||
- To facilitate support, allowed the bts user to view and edit algos from all other users
|
||||
- Improved system tests
|
||||
- Improved log messages in UI to include dispatcher thread name
|
||||
- Added support for Windows core dumps in the UI
|
||||
|
||||
## 2.10.0
|
||||
### User Visible Changes
|
||||
- Fills now include information about the algo that originated the fill
|
||||
|
||||
@@ -1,83 +1,74 @@
|
||||
using bts;
|
||||
using bts.api.admin;
|
||||
using bts.api.core;
|
||||
using bts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using bts.api.core;
|
||||
using mbts.ui.shell;
|
||||
|
||||
namespace mbts.spark {
|
||||
[Export]
|
||||
class AdminModel : IDisposable {
|
||||
public readonly UserTuple user;
|
||||
|
||||
readonly BehaviorSubject<IReadOnlyDictionary<uint, string>>
|
||||
_accounts_subject = new BehaviorSubject<IReadOnlyDictionary<uint, string>>(new Dictionary<uint, string>()),
|
||||
_users_subject = new BehaviorSubject<IReadOnlyDictionary<uint, string>>(new Dictionary<uint, string>());
|
||||
IReadOnlyDictionary<uint, string>
|
||||
_account_map = new Dictionary<uint, string>(),
|
||||
_user_map = new Dictionary<uint, string>();
|
||||
readonly BehaviorSubject<AdminModelWrapper> _wrapper_subject = new BehaviorSubject<AdminModelWrapper>(new AdminModelWrapper());
|
||||
IDisposable _dispose;
|
||||
|
||||
IDisposable _dispose;
|
||||
IReadOnlyDictionary<uint, string> _account_map = DictionaryHelper.empty<uint, string>();
|
||||
|
||||
[ImportingConstructor]
|
||||
AdminModel(AdminService service, [Import]UserTuple user) {
|
||||
AdminModel(AdminService service, UserTuple user) {
|
||||
this.user = user;
|
||||
_dispose = service.subscribei_admin_data().Select(update => {
|
||||
_wrapper_subject.OnNext(new AdminModelWrapper(update.all.TryFirst(), user.name));
|
||||
IEnumerable<BTSUserImmutable> active_users =
|
||||
from admin_data in update.all
|
||||
from bts_user in admin_data.Users
|
||||
where bts_user.Name == user.name && bts_user.HasUserData && bts_user.UserData.HasAccountPermissions
|
||||
select bts_user;
|
||||
|
||||
IEnumerable<BTSAccountImmutable> active_accounts =
|
||||
from admin_data in update.all
|
||||
from bts_account in admin_data.Accounts
|
||||
where bts_account.IsPresent && _wrapper_subject.Value.can_view_account(bts_account.Name)
|
||||
join account_id in (
|
||||
from bts_user in active_users
|
||||
from account_id in bts_user.UserData.AccountPermissions.AccountPermissions.Keys
|
||||
select account_id
|
||||
) on bts_account.Id equals account_id
|
||||
select bts_account;
|
||||
|
||||
var users = active_users.ToDictionary(u => u.Id, u => u.Name);
|
||||
var accounts = active_accounts.ToDictionary(a => a.Id, a => a.Name);
|
||||
return (users, accounts);
|
||||
}).Subscribe(t => {
|
||||
_account_map = t.accounts;
|
||||
_user_map = t.users;
|
||||
_users_subject.OnNext(_user_map = t.users);
|
||||
_accounts_subject.OnNext(_account_map = t.accounts);
|
||||
});
|
||||
// accounts
|
||||
on_accounts = service.subscribei_admin_data()
|
||||
.Select(up => up.all.TryGetFirst(out var ad) && ad.Users.Where(u => u.Name == user.name).TryGetSingle(out var usr) && usr.HasUserData && usr.UserData.HasAccountPermissions ?
|
||||
usr.UserData.AccountPermissions.AccountPermissions
|
||||
.Where(kv => (kv.Value.TradingPermission != null && kv.Value.TradingPermission.HasPermissions) || kv.Value.AdminPermission.HasPermissions)
|
||||
.Select(kv => ad.Accounts.Where(a => a.Id == kv.Key).TryGetSingle(out var acc) ? acc : (BTSAccountImmutable?)null)
|
||||
.Where(acc => acc.HasValue)
|
||||
.Select(acc => acc.Value)
|
||||
.ToDictionary(acc => acc.Id, acc => acc.Name) :
|
||||
new Dictionary<uint, string>(0))
|
||||
.Replay(1)
|
||||
.RefCount();
|
||||
// users
|
||||
on_users = Observable.Return(DictionaryHelper.wrap_value(user.id, user.name));
|
||||
all_user_tuples = user.permissions == UserTuple.Permissions.Admin ?
|
||||
service.subscribei_admin_data()
|
||||
.Select(u => u.all.TryFirst())
|
||||
.Where(ad => ad.HasValue)
|
||||
.Select(ad => ad.Value.Users
|
||||
.Where(u => user.can_access_user_data(u.Id))
|
||||
.Select(u => new UserTuple(u.Id, u.Name))
|
||||
.ToDictionary(UserTuple.key_fn))
|
||||
.Table(UserTuple.key_fn)
|
||||
.Cache() :
|
||||
Observable.Return(TableUpdate<UserTuple, uint>.mk_empty(UserTuple.key_fn).with_added(new[] { user }));
|
||||
_dispose = on_accounts.Subscribe(map => _account_map = map);
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> on_users => _users_subject.AsObservable();
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> on_accounts => _accounts_subject.AsObservable();
|
||||
public IObservable<IReadOnlyList<UserTuple>> on_user_tuples => on_users.Select(d => d.Select(kv => new UserTuple(kv.Key, kv.Value)).ToList());
|
||||
public IObservable<IReadOnlyList<AccountTuple>> on_account_tuples => on_accounts.Select(d => d.Select(kv => new AccountTuple(kv.Key, kv.Value)).ToList());
|
||||
public IObservable<AdminModelWrapper> on_admin_data => _wrapper_subject.AsObservable();
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> on_users { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> on_accounts { get; }
|
||||
public IObservable<TableUpdate<UserTuple, uint>> all_user_tuples { get; }
|
||||
public IObservable<IReadOnlyList<AccountTuple>> on_account_tuples => on_accounts.Select(d => d.Select(kv => new AccountTuple(kv.Key, kv.Value)).ToListSorted(a => a.name));
|
||||
|
||||
public AccountTuple? get_default_account() {
|
||||
foreach (var kv in _account_map) {
|
||||
return new AccountTuple(kv.Key, kv.Value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public uint? get_user_id(string user) => _id_for_name(user, _user_map);
|
||||
public uint? get_account_id(string account) => _id_for_name(account, _account_map);
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
public IObservable<Update<T, TKey>> permission_filter<T, TKey>(IObservable<Update<T, TKey>> positions, Func<T, uint> get_account_id) where TKey : IEquatable<TKey> =>
|
||||
user.permissions == UserTuple.Permissions.Admin ?
|
||||
positions :
|
||||
positions.Filter(on_accounts.Select(map => new Func<T, bool>(p => map.ContainsKey(get_account_id(p)))));
|
||||
|
||||
static uint? _id_for_name(string name, IReadOnlyDictionary<uint, string> map) {
|
||||
foreach (var kv in map) {
|
||||
if (kv.Value == name)
|
||||
return kv.Key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public IObservable<Update<T, TKey>> permission_filter<T, TKey>(IObservable<Update<T, TKey>> positions, Func<T, string> get_account_name) where TKey : IEquatable<TKey> =>
|
||||
user.permissions == UserTuple.Permissions.Admin ?
|
||||
positions :
|
||||
positions.Filter(on_accounts.Select(map => {
|
||||
var hash = new HashSet<string>(map.Values);
|
||||
return new Func<T, bool>(v => hash.Contains(get_account_name(v)));
|
||||
}));
|
||||
|
||||
public AccountTuple? get_default_account() =>
|
||||
_account_map.Select(kv => new AccountTuple(kv.Key, kv.Value)).TryFirst();
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,10 @@ using mbts;
|
||||
using mbts.config;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
@@ -23,8 +18,8 @@ namespace bts.ui {
|
||||
IDisposable _dispose;
|
||||
|
||||
[ImportingConstructor]
|
||||
public AboutDaemon(IBus bus, [Import(LoginContainer.Exports.UserName)]string username) {
|
||||
_user = username;
|
||||
public AboutDaemon(IBus bus, UserTuple user) {
|
||||
_user = user.name;
|
||||
_bus = bus;
|
||||
_dispose = bus.subscribe(SparkTags.About).OnDispatcher().Subscribe(_ => show_about());
|
||||
}
|
||||
@@ -63,4 +58,4 @@ namespace bts.ui {
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,11 @@ using mbts.ui;
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows;
|
||||
using System.Threading.Tasks;
|
||||
using mbts.ui.shell;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace bts.spark
|
||||
{
|
||||
namespace bts.spark {
|
||||
[Export, Export(typeof(IShellDaemon))]
|
||||
public class ErrorReporter : IShellDaemon, IDisposable {
|
||||
readonly ErrorReportService _svc;
|
||||
@@ -21,9 +19,9 @@ namespace bts.spark
|
||||
IDisposable _dispose;
|
||||
|
||||
[ImportingConstructor]
|
||||
public ErrorReporter(ErrorReportService svc, IBus bus, [Import(LoginContainer.Exports.UserName)] string username) {
|
||||
public ErrorReporter(ErrorReportService svc, IBus bus, UserTuple user) {
|
||||
_svc = svc;
|
||||
_username = username;
|
||||
_username = user.name;
|
||||
_dispose = bus.subscribe(SparkTags.Support).OnDispatcher().Subscribe(msg => show_support_window(msg, "Report a problem"));
|
||||
}
|
||||
|
||||
@@ -48,6 +46,45 @@ namespace bts.spark
|
||||
ErrorMessage = message,
|
||||
});
|
||||
}
|
||||
public async Task report_silently(string contact, string description, string userdata) {
|
||||
var request = append_logs(new ErrorReport {
|
||||
User = _username,
|
||||
ErrorMessage = description,
|
||||
UserDescription = userdata,
|
||||
Contact = contact
|
||||
}.immutable());
|
||||
var reply = await _svc.send_report_async(request);
|
||||
}
|
||||
|
||||
public static ErrorReportImmutable append_logs(ErrorReportImmutable src) {
|
||||
var result = src.CloneToMutable();
|
||||
|
||||
var windows_log = LogUtil.read_windows_event_log();
|
||||
if (!windows_log.IsEmpty) {
|
||||
result.Files.Add(new FileData {
|
||||
Name = "Application.evtx.gz",
|
||||
Contents = windows_log
|
||||
});
|
||||
}
|
||||
|
||||
var (data,date) = LogUtil.read_latest_crash_dump();
|
||||
if (!data.IsEmpty) {
|
||||
result.Files.Add(new FileData {
|
||||
Name = $"spark-{date.ToString("s")}.dmp.gz",
|
||||
Contents = data
|
||||
});
|
||||
}
|
||||
|
||||
var spark_log = LogUtil.read_logs_compressed();
|
||||
if (!spark_log.IsEmpty) {
|
||||
result.Files.Add(new FileData {
|
||||
Name = "log.gz",
|
||||
Contents = spark_log
|
||||
});
|
||||
}
|
||||
return result.immutable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class ErrorReporterExtensions {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using bts.api;
|
||||
using bts.api.synthetic;
|
||||
using bts.md;
|
||||
using mbts;
|
||||
using mbts.co2;
|
||||
using mbts.spark;
|
||||
@@ -7,15 +8,10 @@ using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using SecurityKey = System.UInt32;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using bts.api.user;
|
||||
using bts.md;
|
||||
using mbts.ui.shell;
|
||||
|
||||
namespace bts {
|
||||
[Export(typeof(IInitializable))]
|
||||
@@ -25,17 +21,21 @@ namespace bts {
|
||||
readonly Lazy<SyntheticSecurityService> _ss;
|
||||
readonly Dictionary<SecurityKey, SecurityMD> _deleted_synthetics = new Dictionary<SecurityKey, SecurityMD>();
|
||||
|
||||
static uint get_naggle() => mbts.config.Configuration.get<md.RelayOptions>().naggle_ms;
|
||||
|
||||
[ImportingConstructor]
|
||||
public MDDaemon(Lazy<IBus> bus, Lazy<AuthTokenImmutable> token, Lazy<SyntheticSecurityService> ss, [Import(LoginContainer.Exports.UserID)]uint user_id) :
|
||||
base(get_naggle(), MDSourceOptions.DeferInit, user_id) {
|
||||
public MDDaemon(Lazy<IBus> bus, Lazy<AuthTokenImmutable> token, Lazy<SyntheticSecurityService> ss, UserTuple user)
|
||||
: base(mbts.config.Configuration.get<md.RelayOptions>().naggle_ms, MDSourceOptions.DeferInit, user) {
|
||||
_bus = bus;
|
||||
_token = token;
|
||||
_ss = ss;
|
||||
_ss = ss;
|
||||
}
|
||||
|
||||
override public void initialize() {
|
||||
public int priority => 55;
|
||||
|
||||
[Export]
|
||||
MDConsumer consumer => _consumer;
|
||||
IBus bus => _bus.Value;
|
||||
|
||||
public override void initialize() {
|
||||
_relay.set_token(_token.Value);
|
||||
_dispose.Add(
|
||||
_ss.Value.subscribei_metadata()
|
||||
@@ -60,16 +60,8 @@ namespace bts {
|
||||
// Post full dictionary of syntheics here
|
||||
bus.post(SparkTags.SyntheticstrategiesTag, t);
|
||||
}));
|
||||
_dispose.Add( this.on_securities.Subscribe( (md) => {
|
||||
bus.post(SparkTags.SecuritiesTag, md);
|
||||
}));
|
||||
_dispose.Add(on_securities.Subscribe(md => bus.post(SparkTags.SecuritiesTag, md)));
|
||||
Task.Run(run);
|
||||
}
|
||||
|
||||
[Export]
|
||||
MDConsumer consumer => _consumer;
|
||||
|
||||
public int priority => 55;
|
||||
IBus bus => _bus.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using mbts.ui;
|
||||
using mbts;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.spark {
|
||||
[Export(typeof(IShellDaemon))]
|
||||
class OopsDaemon : IShellDaemon, IDisposable {
|
||||
[ImportingConstructor]
|
||||
public OopsDaemon(ErrorReporter e) {
|
||||
var pid = get_pid();
|
||||
if (pid.HasValue) {
|
||||
handle_unclean_shutdown(e, pid.Value);
|
||||
}
|
||||
save_pid();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
clear_pid();
|
||||
}
|
||||
|
||||
void handle_unclean_shutdown(ErrorReporter e, int oldpid) {
|
||||
string extra = "";
|
||||
try {
|
||||
var conf = mbts.config.Configuration.get<bts.config.System>();
|
||||
extra = JsonConvert.SerializeObject(conf, Formatting.Indented);
|
||||
}
|
||||
catch { }
|
||||
Task.Run(() => e.report_silently(
|
||||
$"Host: {Environment.MachineName}",
|
||||
$"pid: {oldpid}\n{extra}",
|
||||
"Automated crash report")
|
||||
);
|
||||
}
|
||||
|
||||
const string _subkey = @"Software\BTS";
|
||||
private void save_pid() {
|
||||
using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_subkey)) {
|
||||
key.SetValue("pid", System.Diagnostics.Process.GetCurrentProcess().Id, Microsoft.Win32.RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
private void clear_pid() {
|
||||
using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_subkey)) {
|
||||
key.DeleteValue("pid",false);
|
||||
}
|
||||
}
|
||||
private int? get_pid() {
|
||||
using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_subkey)) {
|
||||
return key.GetValue("pid") as int?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,13 @@ using bts.metrics;
|
||||
using mbts;
|
||||
using mbts.config;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.perf {
|
||||
|
||||
[Export, Export(typeof(IShellDaemon))]
|
||||
class ShellLatencyDaemon : IShellDaemon, IDisposable {
|
||||
readonly ShellLatencyService _service;
|
||||
@@ -24,10 +20,10 @@ namespace bts.perf {
|
||||
Ping _pinger = new Ping();
|
||||
|
||||
[ImportingConstructor]
|
||||
public ShellLatencyDaemon(ShellLatencyService service, [Import(LoginContainer.Exports.UserName)] string user) {
|
||||
public ShellLatencyDaemon(ShellLatencyService service, UserTuple user) {
|
||||
_service = service;
|
||||
_version = Configuration.get<bts.config.System>().version;
|
||||
_username = user;
|
||||
_username = user.name;
|
||||
_hostname = Environment.MachineName;
|
||||
|
||||
_forever_ping_host(_pinger);
|
||||
@@ -105,4 +101,4 @@ namespace bts.perf {
|
||||
Disposable.dispose(ref _subs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using mbts.co2;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
@@ -13,13 +12,11 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using static mbts.ui.shell.ProtoBufSerializationHelper;
|
||||
|
||||
namespace bts.shell
|
||||
{
|
||||
namespace bts.shell {
|
||||
[Export(typeof(IShellModule))]
|
||||
class MarketShellModule : IShellModule
|
||||
{
|
||||
class MarketShellModule : IShellModule {
|
||||
[ImportingConstructor]
|
||||
public MarketShellModule(IBus bus, MDConsumer consumer, UserSettingsHub settings_hub, OrdersModel orders_model, [Import(LoginContainer.Exports.UserName)]string user_name) {
|
||||
public MarketShellModule(IBus bus, MDConsumer consumer, UserSettingsHub settings_hub, OrdersModel orders_model) {
|
||||
_tsf = new TimeAndSalesWindowFactory(this, bus, consumer, settings_hub);
|
||||
_mvf = new MarketViewWindowFactory(this, bus, settings_hub, orders_model);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using bts.api;
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.synthetic;
|
||||
using bts.collections;
|
||||
using bts.spark;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
@@ -18,11 +20,36 @@ namespace mbts.spark {
|
||||
readonly uint _user_id;
|
||||
|
||||
[ImportingConstructor]
|
||||
public SpreaderModel(IBus bus, SyntheticSecurityService service, ErrorReporter error, [Import(LoginContainer.Exports.UserID)]uint user_id) {
|
||||
public SpreaderModel(IBus bus, SyntheticSecurityService service, AdminModel admin_model, ErrorReporter error, UserTuple user) {
|
||||
_bus = bus;
|
||||
_service = service;
|
||||
_error = error;
|
||||
_user_id = user_id;
|
||||
_user_id = user.id;
|
||||
// synthetic tuples
|
||||
var strategy_source = _bus.subscribe(SparkTags.SyntheticstrategiesTag)
|
||||
.Select(map => MappedDictionary.create<uint, ExecutionStrategyImmutable, (uint security_id, ExecutionStrategyImmutable strategy)>(map, (k, v) => (k, v)))
|
||||
.Table(tup => tup.security_id);
|
||||
|
||||
var synthetic_source = _bus.subscribe(SparkTags.SecuritiesTag)
|
||||
.Select(map => new FilteredDictionary<uint, SecurityMD>(map, smd => smd.security.ContractCase == Security.ContractOneofCase.Synthetic))
|
||||
.Table(smd => smd.security.Id);
|
||||
|
||||
var synthetic_user_join = synthetic_source.LeftJoin(
|
||||
admin_model.all_user_tuples,
|
||||
SecurityMD.key_fn,
|
||||
UserTuple.key_fn,
|
||||
smd => smd.security.Synthetic.UserId,
|
||||
(smd, sid, ut, uid) => new SyntheticTuple(smd.security, ut.name, null),
|
||||
(smd, sid, uid) => new SyntheticTuple(smd.security, null, null),
|
||||
SyntheticTuple.key_fn);
|
||||
|
||||
synthetic_tuples = synthetic_user_join.LeftJoin(
|
||||
strategy_source,
|
||||
SyntheticTuple.key_fn,
|
||||
tup => tup.security_id,
|
||||
(synth_tup, id, strat_tup) => new SyntheticTuple(synth_tup.security, synth_tup.user_name, strat_tup.strategy),
|
||||
(synth_tup, id) => synth_tup,
|
||||
SyntheticTuple.key_fn);
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyDictionary<uint, ExecutionStrategyImmutable>> strategy => _bus.subscribe(SparkTags.SyntheticstrategiesTag);
|
||||
@@ -36,6 +63,8 @@ namespace mbts.spark {
|
||||
.LeftJoin(strategies, (security, strategy) => (new ExecutionStrategyImmutable?(strategy), security), security => (new ExecutionStrategyImmutable?(), security))
|
||||
);
|
||||
|
||||
public IObservable<TableUpdate<SyntheticTuple, uint>> synthetic_tuples { get; }
|
||||
|
||||
public IObservable<ExecutionStrategyImmutable> security_strategy(uint security_key) =>
|
||||
strategy.TrySelect(s => {
|
||||
bool success = s.TryGetValue(security_key, out ExecutionStrategyImmutable result);
|
||||
|
||||
@@ -7,8 +7,15 @@ namespace mbts.ui.spark {
|
||||
/// Interaction logic for SyntheticManagementView.xaml
|
||||
/// </summary>
|
||||
partial class SyntheticManagementView : UserControl {
|
||||
public enum Columns {
|
||||
Name,
|
||||
Description,
|
||||
n_legs,
|
||||
n_working_orders,
|
||||
SecurityKey,
|
||||
User
|
||||
}
|
||||
|
||||
public enum Columns { Name, Description, n_legs, n_working_orders, SecurityKey}
|
||||
public SyntheticManagementView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
@@ -27,7 +28,7 @@ namespace mbts.spark {
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
|
||||
public SyntheticManagementWindow(SyntheticManagementWindowFactory factory, IBus bus, OrdersModel orders_model, StartupData state, WindowSettingsManager<GridSettings> settings_manager)
|
||||
public SyntheticManagementWindow(SyntheticManagementWindowFactory factory, IBus bus, OrdersModel orders_model, StartupData state, IWindowSettingsManager<GridSettings> settings_manager)
|
||||
: base("Synthetic Management", bus, factory, SparkCommands.ShowSyntheticManagement.icon) {
|
||||
_orders_model = orders_model;
|
||||
_state = state;
|
||||
@@ -66,8 +67,8 @@ namespace mbts.spark {
|
||||
), SparkCommand.create("Clone", Icons.CloneSynthetic, SparkTags.ShowSyntheticCloneTag).complete(
|
||||
current_row_connectable_builder.create(observe_row_strategy),
|
||||
rs => rs.HasValue, select_row_strategy_tuple
|
||||
), SparkCommands.ShowLadder(SparkCommands.KeyGestures.ShowLadder).complete(
|
||||
vm_connectable_builder.create(vm => vm.current_security_md), md => md.HasValue, ConvertUtils.ValueOrDefault
|
||||
), SparkCommands.ShowLadderAutoLookup(SparkCommands.KeyGestures.ShowLadder).complete(
|
||||
vm_connectable_builder.create(vm => vm.current_security_observable.Select(s => s.HasValue ? ImmutableHashSet<uint>.Empty.Add(s.Value.Id) : null)), id => id != null
|
||||
), SparkCommands.ShowOrders.complete(() => {
|
||||
var ob_settings = bts.shell.orderbook.OrderBookStartupData.Default;
|
||||
ob_settings.filters = new bts.shell.orderbook.FilterStates {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts.api;
|
||||
using bts.settings;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.spark.filters;
|
||||
@@ -7,6 +8,7 @@ using mbts.ui.settings;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
@@ -33,13 +35,8 @@ namespace bts.shell {
|
||||
public async void show(SparkTags.Nothing nothing) =>
|
||||
_bus.post(SparkTags.ShowWindow, await load(new StartupData()));
|
||||
|
||||
IShellWindow _create(StartupData state) {
|
||||
var settings_manager = new WindowSettingsManager<GridSettings>(_settings_hub,
|
||||
state.grid,
|
||||
get: us => us.synthetic_management_grid,
|
||||
set: (us, gs) => us.with(provided_synthetic_management_gridsettings: gs));
|
||||
return new SyntheticManagementWindow(this, _bus, _orders_model, state, settings_manager);
|
||||
}
|
||||
IShellWindow _create(StartupData state) =>
|
||||
new SyntheticManagementWindow(this, _bus, _orders_model, state, _settings_hub.create_synth_settings_manager(state.grid));
|
||||
|
||||
[ProtoContract]
|
||||
public class StartupData {
|
||||
@@ -67,6 +64,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings n_legs => new GridColumnSettings(col_id(Columns.n_legs), DefaultColumnHeaders.N_Legs, width: DefaultColumnWidths.N_Legs);
|
||||
public static GridColumnSettings n_working_orders => new GridColumnSettings(col_id(Columns.n_working_orders), DefaultColumnHeaders.N_Working_Orders, width: DefaultColumnWidths.N_Working_Orders);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings user => new GridColumnSettings(col_id(Columns.User), DefaultColumnHeaders.User, is_visible: false, width: DefaultColumnWidths.User);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
get {
|
||||
@@ -81,6 +79,7 @@ namespace bts.shell {
|
||||
yield return n_legs;
|
||||
yield return n_working_orders;
|
||||
yield return security_key;
|
||||
yield return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +100,15 @@ namespace bts.shell {
|
||||
public UIntMinMaxState n_working_orders;
|
||||
[ProtoMember(6)]
|
||||
public string security_key;
|
||||
[ProtoMember(7)]
|
||||
public uint[] user;
|
||||
}
|
||||
|
||||
// migration rules
|
||||
[Export(typeof(ISyntheticManagementMigrationRule))]
|
||||
class AddMissingColumnsMigrationRule : ISyntheticManagementMigrationRule {
|
||||
public bool apply(GridSettings settings, out GridSettings new_settings) =>
|
||||
settings.add_missing_columns(StartupData.DefaultGridSettings.columns, out new_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
using bts.api;
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using mbts.persist;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
@@ -17,43 +20,45 @@ using static mbts.ui.controls.DIYGrid;
|
||||
using static mbts.ui.spark.SyntheticManagementView;
|
||||
|
||||
namespace mbts.spark {
|
||||
class SyntheticManagementDialogVM : SecurityMDGrid<SyntheticManagementDialogVM.Row, (ExecutionStrategyImmutable? strategy, SecurityMD md)> {
|
||||
class SyntheticManagementDialogVM : SecurityGrid<SyntheticManagementDialogVM.Row, SyntheticTuple> {
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _orders_model;
|
||||
IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
public SyntheticManagementDialogVM(IBus bus, OrdersModel orders_model, IWindowSettingsManager<GridSettings> settings_manager) : this(bus, orders_model, settings_manager, null, null) { }
|
||||
public SyntheticManagementDialogVM(IBus bus, OrdersModel orders_model, IWindowSettingsManager<GridSettings> settings_manager, IReadOnlyCollection<SortingCriteria> sorting, FilterStates filters)
|
||||
: base(orders_model.spreader.strategy_tuple.Select(map => map.Values), sorting) {
|
||||
: base(orders_model.spreader.synthetic_tuples.Select(t => t.state.Values), sorting) {
|
||||
_bus = bus;
|
||||
_orders_model = orders_model;
|
||||
_settings_manager = settings_manager;
|
||||
// init filters
|
||||
user_filter = DiscreteValuesFilterVM.CreateTableUpdate<Row, UserTuple, uint>(r => r.user_tuple, UserTuple.key_fn, out var user_filter_items_observer, out var user_filter_items_view, nameof(Row.user_tuple));
|
||||
user_filter_items_view.CustomSort = Comparer<string>.Default.wrap<string, UserTuple>(ut => ut.name).to_non_generic();
|
||||
if (filters != null) {
|
||||
create_time_filter.load_state(filters.create_time);
|
||||
name_filter.load_state(filters.name);
|
||||
description_filter.load_state(filters.description);
|
||||
n_legs_filter.load_state(filters.n_legs);
|
||||
n_working_orders_filter.load_state(filters.n_working_orders);
|
||||
security_key_filter.load_state(filters.security_key);
|
||||
security_key_filter.load_state(filters.security_key);
|
||||
user_filter.load_state(filters.user);
|
||||
}
|
||||
_settings_manager = settings_manager;
|
||||
// columns
|
||||
add_col(Columns.Name, DefaultColumnHeaders.Name, r => r.name, nameof(Row.name), name_filter, DataGridFilterKnownTemplates.Regex, DefaultColumnWidths.Security);
|
||||
add_col(Columns.Description, DefaultColumnHeaders.Description, r => r.description, nameof(Row.description), description_filter, DataGridFilterKnownTemplates.Regex, DefaultColumnWidths.Description);
|
||||
add_col(Columns.n_legs, DefaultColumnHeaders.N_Legs, r => r.n_legs.ToString(), nameof(Row.n_legs), n_legs_filter, DataGridFilterKnownTemplates.IntMinMax, DefaultColumnWidths.N_Legs);
|
||||
columns.Add(new HyperlinkElementColumn<Row, Columns>(
|
||||
Columns.n_working_orders,
|
||||
new Binding(nameof(Row.n_working_orders)),
|
||||
Columns.n_working_orders,
|
||||
new Binding(nameof(Row.n_working_orders)),
|
||||
new Binding(nameof(Row.show_order_book)),
|
||||
n_working_orders_filter,
|
||||
DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
id = col_id(Columns.n_working_orders),
|
||||
Header = DefaultColumnHeaders.N_Working_Orders,
|
||||
Width = DefaultColumnWidths.N_Working_Orders
|
||||
}
|
||||
);
|
||||
});
|
||||
add_col(Columns.SecurityKey, DefaultColumnHeaders.SecurityKey, r => r.security_key.ToString(), nameof(Row.security_key), security_key_filter, DataGridFilterKnownTemplates.Regex, DefaultColumnWidths.SecurityKey);
|
||||
|
||||
add_col(Columns.User, DefaultColumnHeaders.User, r => r.user_name, nameof(Row.user_name), user_filter, DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.User);
|
||||
//
|
||||
void add_col(Columns col_key, string header, Func<Row, string> get_text, string prop, IDataGridColumnFilter filter, string filter_template, double width) =>
|
||||
columns.Add(new RenderTextColumn<Row, Columns>(col_key, get_text, filter, filter_template) {
|
||||
@@ -63,42 +68,39 @@ namespace mbts.spark {
|
||||
Width = width
|
||||
});
|
||||
//
|
||||
grid_settings_manager = new SimpleGridSettingsManager<Row>(columns, new Dictionary<string, GridColumnSettingsFeatureFlags> { }, row_vms);
|
||||
grid_settings_manager = new SimpleGridSettingsManager<Row>(columns, DictionaryHelper.empty<string, GridColumnSettingsFeatureFlags>(), row_vms);
|
||||
// this will initialize the immutable properties that correspond to the col_settings_flags above (e.g. Bid/Ask font_color_override, etc.)
|
||||
grid_settings_manager.load_from(settings_manager.current_settings());
|
||||
|
||||
_resources.AddRange(
|
||||
DataGridFilterHelper.hook_filters(rows_view, create_time_filter, name_filter, description_filter, n_legs_filter, n_working_orders_filter, security_key_filter),
|
||||
orders_model.admin_model.all_user_tuples.OnDispatcher().Subscribe(user_filter_items_observer),
|
||||
DataGridFilterHelper.hook_all<SyntheticManagementDialogVM, Row>(this, rows_view),
|
||||
settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager)
|
||||
);
|
||||
}
|
||||
|
||||
protected override Row row_factory((ExecutionStrategyImmutable? strategy, SecurityMD md) row_model) =>
|
||||
new Row(_bus, row_model.md, row_model.strategy, _orders_model);
|
||||
|
||||
protected override void on_row_removed(Row row) => row.Dispose();
|
||||
|
||||
public ObservableCollection<ColumnBase> columns { get; } = new ObservableCollection<ColumnBase>();
|
||||
public ObservableCollection<ColumnBase> columns { get; } = new ObservableCollection<ColumnBase>();
|
||||
public SimpleGridSettingsManager<Row> grid_settings_manager { get; }
|
||||
|
||||
public GridSettings get_grid_save_state() {
|
||||
if (_settings_manager.instance_settings == null)
|
||||
return null;
|
||||
else
|
||||
return grid_settings_manager.create();
|
||||
}
|
||||
|
||||
public StartupData create() =>
|
||||
new StartupData(rows_view.get_sorting_criteria(columns), _get_filter_states(), get_grid_save_state());
|
||||
|
||||
|
||||
#region Filters
|
||||
public IDataGridColumnPersistentFilter<Row, TimeFilterTuple> create_time_filter { get; } = new TimeFilterVM<Row>(r => r.create_time, nameof(Row.create_time));
|
||||
public IDataGridColumnPersistentFilter<Row, string> name_filter { get; } = new RegexFilterVM<Row>(r => r.name, nameof(Row.name));
|
||||
public IDataGridColumnPersistentFilter<Row, string> description_filter { get; } = new RegexFilterVM<Row>(r => r.description, nameof(Row.description));
|
||||
public IDataGridColumnPersistentFilter<Row, IntMinMaxState> n_legs_filter { get; } = new IntMinMax<Row>(r => r.n_legs, nameof(Row.n_legs));
|
||||
public IDataGridColumnPersistentFilter<Row, UIntMinMaxState> n_working_orders_filter { get; } = new UIntMinMax<Row>(r => r.n_working_orders, nameof(Row.n_legs));
|
||||
public IDataGridColumnPersistentFilter<Row, string> security_key_filter { get; } = new RegexFilterVM<Row>(r => r.security_key.ToString(), nameof(Row.security_key));
|
||||
public IDataGridColumnPersistentFilter<Row, uint[]> user_filter { get; }
|
||||
|
||||
public GridSettings get_grid_save_state() =>
|
||||
_settings_manager.instance_settings == null ? null : grid_settings_manager.create();
|
||||
|
||||
public StartupData create() =>
|
||||
new StartupData(rows_view.get_sorting_criteria(columns), _get_filter_states(), get_grid_save_state());
|
||||
|
||||
protected override Row row_factory(SyntheticTuple row_model) =>
|
||||
new Row(_bus, row_model, _orders_model);
|
||||
|
||||
protected override void on_row_removed(Row row) =>
|
||||
row.Dispose();
|
||||
|
||||
FilterStates _get_filter_states() =>
|
||||
new FilterStates {
|
||||
@@ -107,19 +109,19 @@ namespace mbts.spark {
|
||||
name = name_filter.get_state(),
|
||||
n_legs = n_legs_filter.get_state(),
|
||||
n_working_orders = n_working_orders_filter.get_state(),
|
||||
security_key = security_key_filter.get_state()
|
||||
security_key = security_key_filter.get_state(),
|
||||
user = user_filter.get_state()
|
||||
};
|
||||
#endregion
|
||||
|
||||
public class Row : SecurityMDRow, IEquatable<Row>, IRowVM, IActionableRowVM {
|
||||
public readonly ExecutionStrategyImmutable? strategy;
|
||||
public class Row : SecurityRow, IEquatable<Row>, IRowVM, IActionableRowVM {
|
||||
public readonly SyntheticTuple synthetic_tuple;
|
||||
|
||||
readonly IBus _bus;
|
||||
readonly Property<uint> _n_working_orders;
|
||||
|
||||
public Row(IBus bus, SecurityMD security_md, ExecutionStrategyImmutable? strategy, OrdersModel orders_model) : base(security_md) {
|
||||
public Row(IBus bus, SyntheticTuple synthetic_tuple, OrdersModel orders_model) : base(synthetic_tuple.security) {
|
||||
_bus = bus;
|
||||
this.strategy = strategy;
|
||||
this.synthetic_tuple = synthetic_tuple;
|
||||
_n_working_orders = backing(nameof(n_working_orders),
|
||||
orders_model.on_security_orders(security_key)
|
||||
.Select(t => (uint)(t.state
|
||||
@@ -133,25 +135,23 @@ namespace mbts.spark {
|
||||
show_order_book = new DelegateCommand(_show_order_book);
|
||||
}
|
||||
|
||||
public event Action invalidated;
|
||||
|
||||
public DateTime create_time => DateTime.MinValue; //TODO
|
||||
public string name { get; }
|
||||
public string user_name => synthetic_tuple.user_name;
|
||||
public UserTuple user_tuple => new UserTuple(synthetic_tuple.security.Synthetic.UserId, user_name);
|
||||
public int n_legs { get; }
|
||||
public string description { get; }
|
||||
public ExecutionStrategyImmutable? strategy => synthetic_tuple.strategy;
|
||||
public bool strategy_present => strategy.HasValue;
|
||||
public uint n_working_orders => _n_working_orders.Value;
|
||||
public ICommand show_ladder { get; }
|
||||
public ICommand show_order_book { get; }
|
||||
public ICommand default_command => show_ladder;
|
||||
|
||||
|
||||
public ObservableCollection<RowAnimation> row_animations => new ObservableCollection<RowAnimation>();
|
||||
|
||||
public IReadOnlyList<IGridCellStore> cell_stores => new IGridCellStore[0];
|
||||
|
||||
|
||||
public event Action invalidated;
|
||||
|
||||
public void raise_invalidated() => invalidated?.Invoke();
|
||||
public void raise_invalidated() =>
|
||||
invalidated?.Invoke();
|
||||
|
||||
public bool Equals(Row other) =>
|
||||
other != null &&
|
||||
@@ -163,10 +163,8 @@ namespace mbts.spark {
|
||||
public override int GetHashCode() =>
|
||||
security_key.GetHashCode();
|
||||
|
||||
|
||||
|
||||
void _show_ladder() =>
|
||||
_bus.post(SparkTags.ShowLadderTag, md);
|
||||
_bus.post(SparkTags.ShowLadderAutoLookupTag, ImmutableHashSet<uint>.Empty.Add(security.Id));
|
||||
|
||||
void _show_order_book() {
|
||||
var ob_settings = bts.shell.orderbook.OrderBookStartupData.Default;
|
||||
@@ -177,4 +175,4 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace mbts.spark {
|
||||
_error_reporter = error_reporter;
|
||||
definitions =
|
||||
service.subscribei_algo_definitions()
|
||||
.Filter(r => r.Metadata.IsActive && r.Metadata.CreatorUserId == _admin_model.user.id)
|
||||
.Filter(r => r.Metadata.IsActive && _admin_model.user.can_access_user_data(r.Metadata.CreatorUserId))
|
||||
.SelectKeyValue(_definition_data, d => d.key)
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
@@ -118,8 +118,8 @@ namespace mbts.spark {
|
||||
add_col_expl(Columns.Side, new SideColumn<Row, Columns>(Columns.Side, r => r.side, side_filter) { id = col_id(Columns.Side) }, side_filter);
|
||||
// all others (easily identified by the enum 'Columns.Foo')
|
||||
add_col(Columns.FillTime, DefaultColumnHeaders.FillTime, r => r.fill_time.ToString("M/d h:mm:ss tt"), new TimeFilterVM<FillTuple>(r => r.fill.Timestamp.ToDateTimeOffset().LocalDateTime), DataGridFilterKnownTemplates.TimeFilter, DefaultColumnWidths.Time);
|
||||
add_col(Columns.User, DefaultColumnHeaders.User, r => r.user, dv_filter_rx(_model.factory.subscribe_users().Select(d => d.Values), r => r.order?.user() ?? string.Empty), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.User);
|
||||
add_col(Columns.Account, DefaultColumnHeaders.Account, r => r.account, dv_filter_rx(_model.factory.subscribe_accounts().Select(d => d.Values), r => r.account), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.Account);
|
||||
add_col(Columns.User, DefaultColumnHeaders.User, r => r.user, dv_filter_rx(_model.factory.subscribe_users().Select(d => d.Values.Ordered()), r => r.order?.user() ?? string.Empty), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.User);
|
||||
add_col(Columns.Account, DefaultColumnHeaders.Account, r => r.account, dv_filter_rx(_model.factory.subscribe_accounts().Select(d => d.Values.Ordered()), r => r.account), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.Account);
|
||||
add_col(Columns.Exchange, DefaultColumnHeaders.Exchange, r => r.exchange.ToString(), dv_filter(EnumHelper.get_values<Venue>().ToArray(), r => r.security.exchange_or_default()), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.Exchange);
|
||||
add_col(Columns.TimeInForce, DefaultColumnHeaders.TimeInForce, r => r.time_in_force.ToString(), dv_filter(EnumHelper.get_values<TimeInForce>().ToArray(), r => r.order?.time_in_force() ?? TimeInForce.Undefined), DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.TimeInForce);
|
||||
add_col(Columns.Size, DefaultColumnHeaders.Size, r => r.size.ToString(), new DoubleMinMax<FillTuple>(r => r.fill.LastShares), DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.Size);
|
||||
@@ -147,6 +147,7 @@ namespace mbts.spark {
|
||||
});
|
||||
_dispose = new CompositeDisposable(
|
||||
ObservableAutoWrapper.connect(col_tups, columns, ct => ct.col),
|
||||
ObservableAutoWrapper.connect_item_hooks(col_tups, ct => ct.filter as IDisposable),
|
||||
RXCollection.connect(rows, fills_buffer.Filter(filter_src, FillTuple.key_fn), comp_src, ft => new Row(ft, model), r => r.fill_tuple),
|
||||
fills_source.OnDispatcher().Subscribe(t => {
|
||||
last_unfiltered_fills = t;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.md;
|
||||
using mbts;
|
||||
using mbts.config;
|
||||
@@ -50,6 +51,7 @@ namespace bts.shell {
|
||||
_mbo = mbo;
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s),
|
||||
bus.subscribe(SparkTags.ShowLadderAutoLookupTag).Subscribe(_show_windows),
|
||||
bus.subscribe(SparkTags.ShowLadderTag).OnDispatcher().Subscribe(s => show_windows(new[] { s })),
|
||||
bus.subscribe(SparkTags.ShowLaddersTag).OnDispatcher().Subscribe(show_windows)
|
||||
);
|
||||
@@ -273,7 +275,21 @@ namespace bts.shell {
|
||||
});
|
||||
}
|
||||
|
||||
void show_windows(IReadOnlyCollection<SecurityMD> securities) {
|
||||
async void _show_windows(IImmutableSet<uint> securities) {
|
||||
if (securities == null)
|
||||
return;
|
||||
var start_time = DateTime.Now;
|
||||
do {
|
||||
var found = securities.KeyJoin(_securities).ToList();
|
||||
securities = securities.RemoveRange(found.Select(SecurityMD.key_fn));
|
||||
show_windows(found);
|
||||
if (securities.Count == 0)
|
||||
break;
|
||||
await Task.Delay(500);
|
||||
} while ((DateTime.Now - start_time) < _ladder_conf.security_timeout);
|
||||
}
|
||||
|
||||
void show_windows(IEnumerable<SecurityMD> securities) {
|
||||
int n_allowed = (int)_ladder_conf.max_open_ladders - _wm.list_windows().Where(w => w.window_type == _window_type).Count();
|
||||
int n_opened = 0;
|
||||
foreach (var s in securities) {
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace bts.shell.manual_fills {
|
||||
mfd => new ManualFillRow(mfd),
|
||||
mfr => mfr.data),
|
||||
_bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(m => {
|
||||
security_map = m;
|
||||
security_map = new FilteredDictionary<uint, SecurityMD>(m, smd => smd.security.ContractCase == Security.ContractOneofCase.Future);
|
||||
RaisePropertyChanged(nameof(security_map));
|
||||
}),
|
||||
ObservableAutoWrapper.connect_item_hooks(_persisted_rows, r => Disposable.Create(dirty_mon.join(r), selection_mon.join(r))),
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace mbts.spark {
|
||||
r => r.user,
|
||||
DefaultColumnWidths.User,
|
||||
DiscreteValuesFilterVM.Create<OrderSecurityRootPair, string>(
|
||||
model.factory.subscribe_users().Select(d => d.Values),
|
||||
model.factory.subscribe_users().Select(d => d.Values.Ordered()),
|
||||
ort => ort.order.order.user(),
|
||||
nameof(OrderBookRowVM.user)),
|
||||
DataGridFilterKnownTemplates.DiscreteValues,
|
||||
@@ -133,7 +133,7 @@ namespace mbts.spark {
|
||||
r => r.account,
|
||||
DefaultColumnWidths.Account,
|
||||
DiscreteValuesFilterVM.Create<OrderSecurityRootPair, string, string[]>(
|
||||
model.factory.subscribe_accounts().Select(d => d.Values),
|
||||
model.factory.subscribe_accounts().Select(d => d.Values.Ordered()),
|
||||
ort => ort.order.order.account(),
|
||||
vals => vals.ToArray(),
|
||||
vals => Observable.Return(vals),
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace mbts.spark {
|
||||
grid_settings_manager,
|
||||
order_mod_vm.algo_vm.connect_data(Observable.Return(model)),
|
||||
order_mod_vm.algo_vm.connect_data(_selected_params_mon.subscribe_spreader_security()),
|
||||
order_mod_vm.algo_vm,
|
||||
order_mod_vm,
|
||||
attach_vm,
|
||||
_show_fills.observe_current(true)
|
||||
.Subscribe(is_visible => {
|
||||
@@ -735,17 +735,13 @@ namespace mbts.spark {
|
||||
_size_permissions = AlgoParamPermissions.ReadOnly | AlgoParamPermissions.Write;
|
||||
SecurityMD? _security_md;
|
||||
|
||||
public OrderParamsVM(OrderBookVM owner, AlgoFormats init_format, AlgoEditingPermissions init_permissions)
|
||||
: this(owner,
|
||||
AlgoDefinitionVM.create(
|
||||
owner._model,
|
||||
AlgoData.create_unpersisted(OrderDataHelper.Defaults.CustomOrderDefinitionImmutable(CustomOrderDefinition.CustomOneofCase.Iceberg), CustomOrderDefinition.CustomOneofCase.Iceberg.display_name()),
|
||||
init_format: init_format,
|
||||
editing_permissions: init_permissions)) { }
|
||||
|
||||
OrderParamsVM(OrderBookVM owner, AlgoDefinitionVM algo_vm) {
|
||||
public OrderParamsVM(OrderBookVM owner, AlgoFormats init_format, AlgoEditingPermissions init_permissions) {
|
||||
_owner = owner;
|
||||
this.algo_vm = algo_vm;
|
||||
algo_vm = AlgoDefinitionVM.create(
|
||||
owner._model,
|
||||
AlgoData.create_unpersisted(OrderDataHelper.Defaults.CustomOrderDefinitionImmutable(CustomOrderDefinition.CustomOneofCase.Iceberg), CustomOrderDefinition.CustomOneofCase.Iceberg.display_name()),
|
||||
init_format: init_format,
|
||||
editing_permissions: init_permissions);
|
||||
_accounts = backing(
|
||||
nameof(selected_account),
|
||||
_model.factory.subscribe_account_tuples(),
|
||||
@@ -784,7 +780,8 @@ namespace mbts.spark {
|
||||
appended_param_rows.insert_front(new AlgoParamRowVM(root, _price_param, null, AlgoParamTemplateKeys.Price));
|
||||
}
|
||||
}),
|
||||
ObservableAutoWrapper.connect_item_hooks(param_rows, dirty_params_mon.join));
|
||||
ObservableAutoWrapper.connect_item_hooks(param_rows, dirty_params_mon.join),
|
||||
algo_vm);
|
||||
// payup methods
|
||||
void payup_bid(int ticks) => payup(bbo.bid, -ticks);
|
||||
void payup_ask(int ticks) => payup(bbo.ask, ticks);
|
||||
|
||||
@@ -67,7 +67,6 @@ namespace mbts.spark.utilities {
|
||||
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> subscribe_accounts() => _admin_model.on_accounts;
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> subscribe_users() => _admin_model.on_users;
|
||||
public IObservable<IReadOnlyList<UserTuple>> subscribe_user_tuples() => _admin_model.on_user_tuples;
|
||||
public IObservable<IReadOnlyList<AccountTuple>> subscribe_account_tuples() => _admin_model.on_account_tuples;
|
||||
|
||||
#region Defaults
|
||||
|
||||
@@ -59,18 +59,26 @@ namespace mbts.spark {
|
||||
this.md_auxiliary_model = md_auxiliary_model;
|
||||
var scheduler = ThreadPoolScheduler.Instance;
|
||||
var interval = TimeSpan.FromMilliseconds(100);
|
||||
on_orders =
|
||||
_service
|
||||
.subscribei_orders()
|
||||
.Naggle(interval, scheduler)
|
||||
.PermissionFilter(admin_model.on_admin_data)
|
||||
.join(sstore, order => order.security_key())
|
||||
on_orders = admin_model
|
||||
.permission_filter(
|
||||
_service.subscribei_orders()
|
||||
.Naggle(interval, scheduler),
|
||||
o => o.account_id()
|
||||
).join(sstore, order => order.security_key())
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
on_positions = _position_service.subscribei_position_data().Naggle(interval, scheduler).PermissionFilter(admin_model.on_admin_data).join(sstore, pos => pos.SecurityId).Table().Cache();
|
||||
on_pnl = _position_service.subscribei_pnl_data()
|
||||
.Naggle(interval, scheduler)
|
||||
on_positions = admin_model
|
||||
.permission_filter(
|
||||
_position_service.subscribei_position_data().Naggle(interval, scheduler),
|
||||
p => p.AccountId)
|
||||
.join(sstore, pos => pos.SecurityId)
|
||||
.Table()
|
||||
.Cache();
|
||||
on_pnl = admin_model
|
||||
.permission_filter(
|
||||
_position_service.subscribei_pnl_data().Naggle(interval, scheduler),
|
||||
p => p.Pos.AccountId)
|
||||
.join(sstore, p => p.Pos.SecurityId)
|
||||
.TableCheckedAutoCorrect(EqualityComparer<(SecurityImmutable? sec, PNLUnitImmutable data)>.Default)
|
||||
.Where(t => t.has_changes())
|
||||
@@ -173,10 +181,11 @@ namespace mbts.spark {
|
||||
.Where(t => t.has_changes())
|
||||
.Cache();
|
||||
// fill tuples
|
||||
var on_fills =
|
||||
_service.subscribei_fills()
|
||||
.Naggle(interval, scheduler)
|
||||
.PermissionFilter(admin_model.on_admin_data)
|
||||
var on_fills = admin_model
|
||||
.permission_filter(
|
||||
_service.subscribei_fills()
|
||||
.Naggle(interval, scheduler),
|
||||
f => f.Account)
|
||||
.join(sstore, f => f.SecurityKey)
|
||||
.Table().Cache();
|
||||
var fill_order_tuples_join = on_fills.LeftJoin(
|
||||
|
||||
@@ -8,6 +8,7 @@ using mbts.spark;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace bts.spark {
|
||||
@@ -41,6 +42,9 @@ namespace bts.spark {
|
||||
SparkCommand.create("P&L (2.0)", Icons.Accounting, SparkTags.ShowPNLTag);
|
||||
|
||||
// Ladder
|
||||
public static PartialCommand<IImmutableSet<uint>> ShowLadderAutoLookup(KeyGesture key_gesture = null) =>
|
||||
SparkCommand.create("Ladder", Icons.Ladder, SparkTags.ShowLadderAutoLookupTag, key_gesture);
|
||||
|
||||
public static PartialCommand<SecurityMD> ShowLadder(KeyGesture key_gesture = null) =>
|
||||
SparkCommand.create("Ladder", Icons.Ladder, SparkTags.ShowLadderTag, key_gesture);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using bts.spark;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.spark {
|
||||
@@ -55,6 +56,8 @@ namespace mbts.spark {
|
||||
// The owners of the various SparkWindows may remove dependencies on the former at their leasure.
|
||||
// For now, both tags go through the same logic in the LadderWindowFactory anyways.
|
||||
public static ITag<SecurityMD> ShowLadderTag { get; } = new SparkTag<SecurityMD>("Show Ladder");
|
||||
// TODO: get rid of the SecurityMD ShowLadderTag. This has created burdensome dependency issues.
|
||||
public static ITag<IImmutableSet<uint>> ShowLadderAutoLookupTag { get; } = new SparkTag<IImmutableSet<uint>>("Show Ladder Auto Lookup");
|
||||
public static ITag<IReadOnlyList<SecurityMD>> ShowLaddersTag { get; } = new SparkTag<IReadOnlyList<SecurityMD>>(nameof(ShowLaddersTag));
|
||||
public static ITag<IObservable<SecurityMD>> ShowLinkedLadder { get; } = new SparkTag<IObservable<SecurityMD>>("Linked Ladder");
|
||||
public static ITag<SecurityCriteria> ShowMarketViewTag { get; } = new SparkTag<SecurityCriteria>("Show MarketView");
|
||||
|
||||
@@ -11,6 +11,7 @@ using bts.api.persistence;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reactive.Linq;
|
||||
using bts.spark;
|
||||
using bts;
|
||||
|
||||
namespace mbts.persist
|
||||
{
|
||||
@@ -146,16 +147,18 @@ namespace mbts.persist
|
||||
}
|
||||
|
||||
[Export(typeof(IUserPersist))]
|
||||
public class UserUISettings : UISettingsBase
|
||||
{
|
||||
public class UserUISettings : UISettingsBase {
|
||||
string _user;
|
||||
|
||||
[ImportingConstructor]
|
||||
public UserUISettings([Import("userid")]uint user, [Import("settings")]PersistenceService persist, ErrorReporter err)
|
||||
public UserUISettings(uint user_id, [Import("settings")]PersistenceService persist, ErrorReporter err)
|
||||
: base(persist,err) {
|
||||
_user = $"User {user}";
|
||||
_user = $"User {user_id}";
|
||||
}
|
||||
|
||||
[ImportingConstructor]
|
||||
UserUISettings(UserTuple user, [Import("settings")]PersistenceService persist, ErrorReporter err)
|
||||
: this(user.id, persist, err) { }
|
||||
|
||||
protected override string user() { return _user; }
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace bts.settings {
|
||||
interface IMarketViewGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPNLSettingsMigrationRule : ISettingsMigrationRule<PNLSettings> { }
|
||||
interface ISyntheticManagementMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
|
||||
static class SettingsMigrationHelper {
|
||||
public static bool apply<T>(T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, out T new_settings) {
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace mbts.persist {
|
||||
static readonly IImmutableProperty<UserSettings, GridSettings>
|
||||
_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.fills_grid, (us, gs) => us.with(provided_fills_gridsettings: gs)),
|
||||
_mview_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.market_view_grid, (us, gs) => us.with(provided_market_view_gridsettings: gs)),
|
||||
_pandl_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.pnl_grid, (us, gs) => us.with(provided_pnl_gridsettings: gs));
|
||||
_pandl_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.pnl_grid, (us, gs) => us.with(provided_pnl_gridsettings: gs)),
|
||||
_synth_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.synthetic_management_grid, (us, gs) => us.with(provided_synthetic_management_gridsettings: gs));
|
||||
|
||||
static readonly IImmutableProperty<UserSettings, PNLSettings>
|
||||
_pnl_propi = ImmutableProperty.create<UserSettings, PNLSettings>(us => us.pnl, (us, pnl) => us.with(pnl: pnl));
|
||||
@@ -36,6 +37,7 @@ namespace mbts.persist {
|
||||
readonly IEnumerable<IMarketViewGridSettingsMigrationRule> _mview_migration_rules;
|
||||
readonly IEnumerable<IPAndLGridSettingsMigrationRule> _pandl_migration_rules;
|
||||
readonly IEnumerable<IPNLSettingsMigrationRule> _pnl_migration_rules;
|
||||
readonly IEnumerable<ISyntheticManagementMigrationRule> _synth_migration_rules;
|
||||
readonly IUserPersist _persist;
|
||||
|
||||
UserSettings _default_settings;
|
||||
@@ -46,13 +48,15 @@ namespace mbts.persist {
|
||||
[ImportMany]IEnumerable<IFillsGridSettingsMigrationRule> fills_migration_rules,
|
||||
[ImportMany]IEnumerable<IMarketViewGridSettingsMigrationRule> mview_migration_rules,
|
||||
[ImportMany]IEnumerable<IPAndLGridSettingsMigrationRule> pandl_migration_rules,
|
||||
[ImportMany]IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules) {
|
||||
[ImportMany]IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules,
|
||||
[ImportMany]IEnumerable<ISyntheticManagementMigrationRule> synth_migration_rules) {
|
||||
//
|
||||
_persist = persist;
|
||||
_fills_migration_rules = fills_migration_rules ?? Enumerable.Empty<IFillsGridSettingsMigrationRule>();
|
||||
_mview_migration_rules = mview_migration_rules ?? Enumerable.Empty<IMarketViewGridSettingsMigrationRule>();
|
||||
_pandl_migration_rules = pandl_migration_rules ?? Enumerable.Empty<IPAndLGridSettingsMigrationRule>();
|
||||
_pnl_migration_rules = pnl_migration_rules ?? Enumerable.Empty<IPNLSettingsMigrationRule>();
|
||||
_synth_migration_rules = synth_migration_rules ?? Enumerable.Empty<ISyntheticManagementMigrationRule>();
|
||||
init();
|
||||
async void init() {
|
||||
UserSettings s;
|
||||
@@ -62,7 +66,9 @@ namespace mbts.persist {
|
||||
var wrapped_rules = new[] {
|
||||
_fills_migration_rules.merge().wrap(_fills_propi),
|
||||
_mview_migration_rules.merge().wrap(_mview_propi),
|
||||
_pandl_migration_rules.merge().wrap(_pandl_propi)
|
||||
_pandl_migration_rules.merge().wrap(_pandl_propi),
|
||||
_pnl_migration_rules.merge().wrap(_pnl_propi),
|
||||
_synth_migration_rules.merge().wrap(_synth_propi)
|
||||
};
|
||||
SettingsMigrationHelper.apply_quiet(ref s, wrapped_rules);
|
||||
// TODO: move ladder sanitization logic into ISettingsMigrationRule
|
||||
@@ -136,6 +142,12 @@ namespace mbts.persist {
|
||||
_pnl_migration_rules,
|
||||
_pnl_propi);
|
||||
|
||||
public IWindowSettingsManager<GridSettings> create_synth_settings_manager(GridSettings instance_settings) =>
|
||||
_create_settings_manager(
|
||||
instance_settings,
|
||||
_synth_migration_rules,
|
||||
_synth_propi);
|
||||
|
||||
public async Task save_default(UserSettings value) {
|
||||
// notify observers before persisting so the changes are reflected immediately in the ui
|
||||
lock (_default_settings_lock) {
|
||||
|
||||
@@ -15,12 +15,8 @@ namespace bts.utils {
|
||||
}
|
||||
|
||||
static class ObjectSnapshot {
|
||||
public static IEnumerable<Func<TSource, TValue>> property_delegates_of_type<TSource, TValue>() where TSource : class where TValue : class {
|
||||
var tval = typeof(TValue);
|
||||
return typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(p => tval.IsAssignableFrom(p.PropertyType))
|
||||
.Select(_prop_getter<TSource, TValue>);
|
||||
}
|
||||
public static IReadOnlyList<Func<TSource, TValue>> property_delegates_of_type<TSource, TValue>() =>
|
||||
PropertyGetterStore<TSource, TValue>.value;
|
||||
|
||||
public static IObservable<TableUpdate<(string name, object current, object original), string>> property_table<T>(T instance, params string[] prop_names) where T : INotifyPropertyChanged =>
|
||||
_property_table(instance, Array.ConvertAll(prop_names, PropertyInfoStore<T>.type.GetProperty));
|
||||
@@ -162,6 +158,18 @@ namespace bts.utils {
|
||||
}
|
||||
}
|
||||
|
||||
static class PropertyGetterStore<TSource, TValue> {
|
||||
public static readonly IReadOnlyList<Func<TSource, TValue>> value;
|
||||
|
||||
static PropertyGetterStore() {
|
||||
var tval = typeof(TValue);
|
||||
value = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(p => tval.IsAssignableFrom(p.PropertyType))
|
||||
.Select(_prop_getter<TSource, TValue>)
|
||||
.ToReadOnlyList();
|
||||
}
|
||||
}
|
||||
|
||||
class PropNode {
|
||||
public readonly PropertyInfo prop;
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using System;
|
||||
|
||||
namespace bts {
|
||||
struct SyntheticTuple : IEquatable<SyntheticTuple>, IComparable<SyntheticTuple>, IComparable {
|
||||
public static readonly Func<SyntheticTuple, uint> key_fn = a => a.security.Id;
|
||||
public static readonly Func<SyntheticTuple?, uint> nullable_key_fn = a => a.HasValue ? a.Value.security.Id : 0u;
|
||||
|
||||
public readonly SecurityImmutable security;
|
||||
public readonly string user_name;
|
||||
public readonly ExecutionStrategyImmutable? strategy;
|
||||
public readonly int? num_working_orders;
|
||||
|
||||
public SyntheticTuple(SecurityImmutable security, string user_name, ExecutionStrategyImmutable? strategy, int? num_working_orders = null) {
|
||||
this.security = security;
|
||||
this.user_name = user_name;
|
||||
this.strategy = strategy;
|
||||
this.num_working_orders = num_working_orders;
|
||||
}
|
||||
|
||||
public int CompareTo(SyntheticTuple other) =>
|
||||
SecurityHelper.Comparer.Compare(security, other.security);
|
||||
|
||||
int IComparable.CompareTo(object obj) =>
|
||||
obj is SyntheticTuple other ? CompareTo(other) : 1;
|
||||
|
||||
public bool Equals(SyntheticTuple other) =>
|
||||
security == other.security &&
|
||||
user_name == other.user_name &&
|
||||
EqualityComparer.nullable_equals(strategy, other.strategy);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
EqualityComparer.equals_obj(this, obj);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
security.Id.GetHashCode();
|
||||
|
||||
public override string ToString() =>
|
||||
user_name == null ? security.ToString() : $"{user_name}:{security}";
|
||||
|
||||
public static bool operator ==(SyntheticTuple a, SyntheticTuple b) => a.Equals(b);
|
||||
public static bool operator !=(SyntheticTuple a, SyntheticTuple b) => !a.Equals(b);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,22 @@
|
||||
using System;
|
||||
using bts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark.filters {
|
||||
static class DataGridFilterHelper {
|
||||
public static IDisposable hook_filters<TRow>(ICollectionView rows, params IDataGridColumnFilter<TRow>[] filters) {
|
||||
public static IDisposable hook_all<TSource, TRow>(TSource source, ICollectionView rows) =>
|
||||
hook_filters(rows,
|
||||
ObjectSnapshot.property_delegates_of_type<TSource, IDataGridColumnFilter<TRow>>()
|
||||
.Select(f => f(source))
|
||||
.ExceptNull()
|
||||
.ToList());
|
||||
|
||||
public static IDisposable hook_filters<TRow>(ICollectionView rows, params IDataGridColumnFilter<TRow>[] filters) =>
|
||||
hook_filters(rows, filters.AsEnumerable());
|
||||
|
||||
public static IDisposable hook_filters<TRow>(ICollectionView rows, IEnumerable<IDataGridColumnFilter<TRow>> filters) {
|
||||
var icvls = (ICollectionViewLiveShaping)rows;
|
||||
icvls.IsLiveFiltering = true;
|
||||
return _hook_filters(set_filter, filters);
|
||||
@@ -22,7 +33,7 @@ namespace mbts.spark.filters {
|
||||
}
|
||||
}
|
||||
|
||||
static IDisposable _hook_filters<TRow>(Action set_filter, params IDataGridColumnFilter<TRow>[] filters) {
|
||||
static IDisposable _hook_filters<TRow>(Action set_filter, IEnumerable<IDataGridColumnFilter<TRow>> filters) {
|
||||
foreach (var f in filters)
|
||||
f.filter_changed += set_filter;
|
||||
set_filter();
|
||||
@@ -34,7 +45,7 @@ namespace mbts.spark.filters {
|
||||
});
|
||||
}
|
||||
|
||||
static List<IDataGridColumnFilter<TRow>> _get_active_filters<TRow>(IDataGridColumnFilter<TRow>[] filters) =>
|
||||
static List<IDataGridColumnFilter<TRow>> _get_active_filters<TRow>(IEnumerable<IDataGridColumnFilter<TRow>> filters) =>
|
||||
filters.Where(f => f.active.HasValue && f.active.Value).ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +68,11 @@ namespace mbts.spark.filters {
|
||||
Func<TRow, TValue> factory,
|
||||
Func<TValue, TKey> key,
|
||||
out IObserver<TableUpdate<TValue, TKey>> items_observer,
|
||||
out ListCollectionView<TValue> items_view)
|
||||
out ListCollectionView<TValue> items_view,
|
||||
string prop_name = null)
|
||||
where TKey : struct, IEquatable<TKey> =>
|
||||
//
|
||||
CreateTableUpdate(factory, key, keys => keys, keys => keys.ToArray(), out items_observer, out items_view);
|
||||
CreateTableUpdate(factory, key, keys => keys, keys => keys.ToArray(), out items_observer, out items_view, prop_name);
|
||||
|
||||
public static IDataGridColumnPersistentFilter<TRow, TState> CreateTableUpdate<TRow, TValue, TKey, TState>(
|
||||
Func<TRow, TValue> factory,
|
||||
@@ -79,10 +80,11 @@ namespace mbts.spark.filters {
|
||||
Func<TState, IEnumerable<TKey>> load_state,
|
||||
Func<IEnumerable<TKey>, TState> get_state,
|
||||
out IObserver<TableUpdate<TValue, TKey>> items_observer,
|
||||
out ListCollectionView<TValue> items_view)
|
||||
out ListCollectionView<TValue> items_view,
|
||||
string prop_name = null)
|
||||
where TKey : struct, IEquatable<TKey> {
|
||||
//
|
||||
var filter = new TableUpdateItemsFilter<TRow, TValue, TKey, TState>(factory, key, load_state, get_state);
|
||||
var filter = new TableUpdateItemsFilter<TRow, TValue, TKey, TState>(factory, key, load_state, get_state, prop_name);
|
||||
items_observer = filter;
|
||||
items_view = filter.items_view;
|
||||
return filter;
|
||||
@@ -291,8 +293,8 @@ namespace mbts.spark.filters {
|
||||
readonly HashSet<TKey> _selected_keys = new HashSet<TKey>(), _desired_keys = new HashSet<TKey>();
|
||||
ListCollectionView<TValue> _items_view;
|
||||
|
||||
public TableUpdateItemsFilter(Func<TRow, TValue> factory, Func<TValue, TKey> key, Func<TState, IEnumerable<TKey>> load_state, Func<IEnumerable<TKey>, TState> get_state)
|
||||
: base(factory, null) {
|
||||
public TableUpdateItemsFilter(Func<TRow, TValue> factory, Func<TValue, TKey> key, Func<TState, IEnumerable<TKey>> load_state, Func<IEnumerable<TKey>, TState> get_state, string prop_name)
|
||||
: base(factory, prop_name) {
|
||||
_factory = factory;
|
||||
_key = key;
|
||||
_load_state = load_state;
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace mbts.ui {
|
||||
public TimeTextTuple end => _end;
|
||||
public bool is_active =>
|
||||
_mode == TimeFilterMode.Today ||
|
||||
_mode == TimeFilterMode.CMEOpen ||
|
||||
(_mode == TimeFilterMode.Period && (_begin.result.HasValue || _end.result.HasValue));
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using bts.support;
|
||||
using Google.Protobuf;
|
||||
using mbts;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -18,6 +12,13 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using bts.support;
|
||||
using Google.Protobuf;
|
||||
using mbts;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
namespace bts.view.controls {
|
||||
partial class SupportRequestWindow : Window {
|
||||
@@ -50,28 +51,40 @@ namespace bts.view.controls {
|
||||
_base = report_base;
|
||||
send_command = new DelegateCommand(send_report, _ => !string.IsNullOrWhiteSpace(_text.Value));
|
||||
_text = backing(nameof(user_text), "");
|
||||
_text.Changed += (_,__) => send_command.TryRaiseCanExecuteChanged();
|
||||
_text.Changed += (_, __) => send_command.TryRaiseCanExecuteChanged();
|
||||
_contact = backing(nameof(user_contact), "");
|
||||
_contact.Changed += (_,__) => send_command.TryRaiseCanExecuteChanged();
|
||||
_contact.Changed += (_, __) => send_command.TryRaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
async void send_report(object _) {
|
||||
ByteString screenshot = null;
|
||||
if (include_screenshot) {
|
||||
var stream = ScreenCapture.capture_encoded("jpeg");
|
||||
screenshot = await ByteString.FromStreamAsync(stream);
|
||||
}
|
||||
var reply = await _service.send_report_async(_base.with(
|
||||
user_description: _text.Value,
|
||||
contact: user_contact,
|
||||
log: include_logs ? LogUtil.read_logs() : "",
|
||||
image: screenshot
|
||||
));
|
||||
if (reply.success) {
|
||||
BTSMessageBox.Show("Your message has been received.", "Thank You", BTSMessageBoxButtons.OK, MessageBoxImage.Information, is_modal: false, top_most:true);
|
||||
}
|
||||
else {
|
||||
BTSMessageBox.Show($"There was an error submitting your message. '{reply.error_message}'", "Error", BTSMessageBoxButtons.OK, MessageBoxImage.Error, is_modal: false, top_most: true);
|
||||
using (var d = new BusyDialog { Text = "Sending your error report...", Topmost = true }) {
|
||||
d.Show();
|
||||
ByteString screenshot = null;
|
||||
if (include_screenshot) {
|
||||
var stream = ScreenCapture.capture_encoded("jpeg");
|
||||
screenshot = await ByteString.FromStreamAsync(stream);
|
||||
}
|
||||
var request = await Task.Run(() => {
|
||||
var result = _base.with(
|
||||
user_description: _text.Value,
|
||||
contact: user_contact,
|
||||
image: screenshot);
|
||||
if (include_logs) {
|
||||
result = spark.ErrorReporter.append_logs(result);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
var reply = await _service.send_report_async(request);
|
||||
if (reply.success) {
|
||||
Log.Ui.info("Support request message has been received.");
|
||||
BTSMessageBox.Show("Your message has been received.", "Thank You", BTSMessageBoxButtons.OK, MessageBoxImage.Information, is_modal: false, top_most: true);
|
||||
}
|
||||
else {
|
||||
var errmsg = $"There was an error submitting your message. '{reply.error_message}'";
|
||||
Log.Ui.error(errmsg);
|
||||
BTSMessageBox.Show(errmsg, "Error", BTSMessageBoxButtons.OK, MessageBoxImage.Error, is_modal: false, top_most: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -457,15 +457,15 @@
|
||||
Name="PART_TextBox"
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
BorderThickness="0">
|
||||
<TextBox.Style>
|
||||
<TextBox.Style>
|
||||
<Style TargetType="{x:Type TextBox}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}"></Setter>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBox.Style>
|
||||
</Style>
|
||||
</TextBox.Style>
|
||||
</TextBox>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
|
||||
@@ -93,7 +93,6 @@
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
u:Behavior.DisablePaste="True"
|
||||
Height="20"
|
||||
BorderThickness="0"
|
||||
>
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Up" Command="{x:Static c:DateTimePicker.TickTimeComponentCommand}" CommandParameter="{u:Int 1}"/>
|
||||
|
||||
@@ -15,8 +15,7 @@ namespace mbts.ui.shell {
|
||||
// The LoginContainer participates in the startup Import/Export dependency system
|
||||
// Since the login form should not depend on *anything* it will be shown before this is created
|
||||
// Once this is created it access the global LoginModel and retrieves the username
|
||||
internal class LoginContainer
|
||||
{
|
||||
class LoginContainer {
|
||||
[ImportingConstructor]
|
||||
public LoginContainer(ServiceContext context) {
|
||||
var model = LoginModel.instance;
|
||||
@@ -28,10 +27,8 @@ namespace mbts.ui.shell {
|
||||
model.Dispose();
|
||||
}
|
||||
|
||||
[Export(Exports.UserName)]
|
||||
public string UserName { get; private set; }
|
||||
|
||||
[Export(Exports.UserID)]
|
||||
public uint UserId { get; private set; }
|
||||
|
||||
[Export]
|
||||
@@ -42,13 +39,6 @@ namespace mbts.ui.shell {
|
||||
|
||||
[Export("workspace")]
|
||||
public string Workspace { get; private set; }
|
||||
|
||||
public static class Exports {
|
||||
public const string
|
||||
UserName = "username",
|
||||
UserID = "userid",
|
||||
UserTuple = "usertuple";
|
||||
}
|
||||
}
|
||||
|
||||
public struct User {
|
||||
|
||||
@@ -114,10 +114,16 @@ namespace mbts.ui
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
foreach (IShellModule module in _modules.OrderBy(m => m.priority).Reverse()) {
|
||||
foreach (var module in _modules.OrderBy(m => m.priority).Reverse()) {
|
||||
module.Dispose();
|
||||
}
|
||||
_modules.Clear();
|
||||
foreach (var daemon in _services) {
|
||||
if (daemon is IDisposable d) {
|
||||
d.Dispose();
|
||||
}
|
||||
}
|
||||
_services.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,7 @@ using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.shell {
|
||||
[Export(typeof(ILauncher))]
|
||||
public class LauncherVM : ViewModelBase, ILauncher
|
||||
{
|
||||
public class LauncherVM : ViewModelBase, ILauncher {
|
||||
Window _window;
|
||||
string _user;
|
||||
readonly IBus _bus;
|
||||
@@ -23,9 +22,9 @@ namespace mbts.ui.shell {
|
||||
[ImportingConstructor]
|
||||
public LauncherVM(
|
||||
ObservableCollection<IShellModule> modules,
|
||||
[Import(LoginContainer.Exports.UserName)]string username,
|
||||
UserTuple user,
|
||||
ErrorReporter errors, IBus bus) {
|
||||
_user = username;
|
||||
_user = user.name;
|
||||
_modules = new ObservableAutoWrapper<ShellModuleVM, IShellModule>(modules, m => new ShellModuleVM(m, bus));
|
||||
_error_service = errors;
|
||||
_bus = bus;
|
||||
@@ -123,7 +122,7 @@ namespace mbts.ui.shell {
|
||||
_shown = true;
|
||||
if (_window != null) {
|
||||
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
|
||||
if (shown != null) shown();
|
||||
shown?.Invoke();
|
||||
_window.Show();
|
||||
}
|
||||
}
|
||||
@@ -140,4 +139,4 @@ namespace mbts.ui.shell {
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,8 @@ namespace mbts.ui.shell
|
||||
try {
|
||||
Dispatcher.Run();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.assert(false, e.ToString());
|
||||
catch (Exception ex) {
|
||||
Log.assert(false, $"Exception on dispatcher thread '{name}': {ex}.");
|
||||
}
|
||||
finally {
|
||||
Log.Ui.info("Disposing slow {0} and cleaning up background thread.".fmt(name));
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace bts.api.core {
|
||||
// Add
|
||||
foreach (var v in next.added) {
|
||||
var k = _key(v);
|
||||
if (removed.TryPop(k, out var oldval)) {
|
||||
if (removed.Remove(k, out var oldval)) {
|
||||
changes.AddOrMerge(new Change<T>(oldval, v));
|
||||
} else {
|
||||
added[k] = v;
|
||||
@@ -110,7 +110,7 @@ namespace bts.api.core {
|
||||
// Change
|
||||
foreach (var c in next.changes) {
|
||||
var k = _key(c.Old);
|
||||
if (!added.TryReplace(k, c.New))
|
||||
if (!added.Replace(k, c.New))
|
||||
changes.AddOrMerge(c);
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ namespace bts.api.core {
|
||||
public bool Remove(TKey key) =>
|
||||
_cache.Remove(key);
|
||||
|
||||
public bool TryPop(TKey key, out TValue value) =>
|
||||
public bool Remove(TKey key, out TValue value) =>
|
||||
_cache.TryGetValue(key, out value) && _cache.Remove(key);
|
||||
|
||||
public bool TryReplace(TKey key, TValue value) {
|
||||
public bool Replace(TKey key, TValue value) {
|
||||
if (_cache.ContainsKey(key)) {
|
||||
_cache[key] = value;
|
||||
return true;
|
||||
@@ -745,13 +745,19 @@ namespace bts.api.core {
|
||||
return new CompositeDisposable(source.Subscribe(aggregator.on_left), right.Subscribe(aggregator.on_right));
|
||||
});
|
||||
|
||||
public static IObservable<TResult> AggregateLatest<TLeft, TRight, TAggregate, TResult>(this IObservable<TLeft> source, IObservable<TRight> right,
|
||||
Func<TAggregate, Change<TLeft>, TRight, TAggregate> update_left, Func<TAggregate, TLeft, Change<TRight>, TAggregate> update_right, TAggregate seed,
|
||||
public static IObservable<TResult> AggregateLatest<TLeft, TRight, TAggregate, TResult>(
|
||||
this IObservable<TLeft> source,
|
||||
IObservable<TRight> right,
|
||||
Func<TAggregate, Change<TLeft>, TRight, TAggregate> update_left,
|
||||
Func<TAggregate, TLeft, Change<TRight>, TAggregate> update_right,
|
||||
Func<TAggregate> seed_factory,
|
||||
Func<TAggregate, TResult> result_selector,
|
||||
TLeft init_left = default, TRight init_right = default) =>
|
||||
TLeft init_left = default,
|
||||
TRight init_right = default) =>
|
||||
//
|
||||
Observable.Create<TResult>(o => {
|
||||
Log.DataFlow.diag($"Create AggregateLatest (Left: {typeof(TLeft)}, Right: {typeof(TRight)}).");
|
||||
var aggregator = new ConcurrentAggregator<TLeft, TRight, TAggregate>(update_left, update_right, agg => o.OnNext(result_selector(agg)), seed, init_left, init_right);
|
||||
var aggregator = new ConcurrentAggregator<TLeft, TRight, TAggregate>(update_left, update_right, agg => o.OnNext(result_selector(agg)), seed_factory(), init_left, init_right);
|
||||
return new CompositeDisposable(source.Subscribe(aggregator.on_left), right.Subscribe(aggregator.on_right));
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace bts.api.core {
|
||||
return left_source.AggregateLatest<TableUpdate<TLeft, TKey>, TableUpdate<TRight, TKey>, (TableUpdate<TResult, TKey> result, IReadOnlyDictionary<TKey, TLeft> left_state, IReadOnlyDictionary<TKey, TRight> right_state), TableUpdate<TResult, TKey>>(right_source,
|
||||
process_left,
|
||||
process_right,
|
||||
(TableUpdate<TResult, TKey>.mk_empty(result_key), new Dictionary<TKey, TLeft>(0), new Dictionary<TKey, TRight>(0)),
|
||||
() => (TableUpdate<TResult, TKey>.mk_empty(result_key), new Dictionary<TKey, TLeft>(0), new Dictionary<TKey, TRight>(0)),
|
||||
t => t.result,
|
||||
TableUpdate<TLeft, TKey>.mk_empty(left_key), TableUpdate<TRight, TKey>.mk_empty(right_key));
|
||||
// left
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace bts.api.core {
|
||||
right_source,
|
||||
process_left,
|
||||
process_right,
|
||||
(TableUpdate<TResult, TLeftKey>.mk_empty(result_key), new Dictionary<TRightKey, HashSet<TLeftKey>>()),
|
||||
() => (TableUpdate<TResult, TLeftKey>.mk_empty(result_key), new Dictionary<TRightKey, HashSet<TLeftKey>>()),
|
||||
state => state.result,
|
||||
TableUpdate<TLeft, TLeftKey>.mk_empty(left_key),
|
||||
TableUpdate<TRight, TRightKey>.mk_empty(right_key));
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace bts {
|
||||
struct UserTuple : IEquatable<UserTuple>, IComparable<UserTuple>, IComparable {
|
||||
public readonly struct UserTuple : IEquatable<UserTuple>, IComparable<UserTuple>, IComparable {
|
||||
const string _admin_name = "bts";
|
||||
|
||||
public static readonly Func<UserTuple, uint> key_fn = u => u.id;
|
||||
public static UserTuple admin => new UserTuple(0, _admin_name, Permissions.Admin);
|
||||
|
||||
public readonly uint id;
|
||||
public readonly string name;
|
||||
public readonly Permissions permissions;
|
||||
|
||||
public UserTuple(uint id, string name) {
|
||||
public UserTuple(uint id, string name)
|
||||
: this(id, name, name == _admin_name ? Permissions.Admin : Permissions.Regular) { }
|
||||
|
||||
public UserTuple(uint id, string name, Permissions permissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public enum Permissions {
|
||||
Regular,
|
||||
Admin
|
||||
}
|
||||
|
||||
public int CompareTo(UserTuple other) {
|
||||
@@ -28,4 +41,9 @@ namespace bts {
|
||||
public static bool operator ==(UserTuple a, UserTuple b) => a.Equals(b);
|
||||
public static bool operator !=(UserTuple a, UserTuple b) => !a.Equals(b);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UserTupleExtensions {
|
||||
public static bool can_access_user_data(this UserTuple user, uint user_id) =>
|
||||
user.id == user_id || user.permissions == UserTuple.Permissions.Admin;
|
||||
}
|
||||
}
|
||||
@@ -13,84 +13,78 @@ namespace bts.md {
|
||||
enum MDSourceOptions {
|
||||
DeferInit = 1,
|
||||
}
|
||||
class MDSource : IObserver<List<SecurityAndHandle>>, IDisposable
|
||||
{
|
||||
|
||||
class MDSource : IObserver<List<SecurityAndHandle>>, IDisposable {
|
||||
const uint _no_user_id = 0;
|
||||
|
||||
protected readonly MDConsumer _consumer = new MDConsumer();
|
||||
protected readonly Co2RelayControl _relay;
|
||||
protected DateTime _version = DateTime.MinValue;
|
||||
protected readonly ConcurrentDictionary<SecurityKey, SecurityMD> _exchange_sec_map = new ConcurrentDictionary<SecurityKey, SecurityMD>();
|
||||
protected List<IDisposable> _dispose = new List<IDisposable>();
|
||||
protected readonly MDSourceOptions _options;
|
||||
readonly uint _user_id;
|
||||
protected DateTime _version = DateTime.MinValue;
|
||||
protected List<IDisposable> _dispose = new List<IDisposable>();
|
||||
|
||||
public MDSource(uint naggle_ms, MDSourceOptions options = 0, uint user_id = _no_user_id)
|
||||
{
|
||||
readonly UserTuple _user;
|
||||
readonly BehaviorSubject<ConcurrentDictionary<SecurityKey, SecurityMD>> _on_securities =
|
||||
new BehaviorSubject<ConcurrentDictionary<SecurityKey, SecurityMD>>(new ConcurrentDictionary<SecurityKey, SecurityMD>());
|
||||
|
||||
public MDSource(uint naggle_ms, MDSourceOptions options = 0)
|
||||
: this(naggle_ms, options, UserTuple.admin) { }
|
||||
|
||||
public MDSource(uint naggle_ms, MDSourceOptions options, UserTuple user) {
|
||||
_options = options;
|
||||
_user_id = user_id;
|
||||
_user = user;
|
||||
_relay = new Co2RelayControl(_consumer, naggle_ms);
|
||||
_relay.preload_securities((co2.MDRequest.Types.Flags)0xff).ignore();
|
||||
_dispose.Add(_consumer.on_security.Subscribe(this));
|
||||
if(!options.HasFlag(MDSourceOptions.DeferInit))
|
||||
if (!options.HasFlag(MDSourceOptions.DeferInit))
|
||||
initialize();
|
||||
}
|
||||
|
||||
readonly BehaviorSubject<ConcurrentDictionary<SecurityKey, SecurityMD>> _on_securities =
|
||||
new BehaviorSubject<ConcurrentDictionary<SecurityKey, SecurityMD>>( new ConcurrentDictionary<SecurityKey, SecurityMD>() );
|
||||
public IObservable<ConcurrentDictionary<SecurityKey, SecurityMD>> on_securities => _on_securities;
|
||||
|
||||
virtual public void initialize()
|
||||
{
|
||||
public virtual void initialize() =>
|
||||
Task.Run(run);
|
||||
}
|
||||
|
||||
public void set_token(AuthTokenImmutable token)
|
||||
{
|
||||
public void set_token(AuthTokenImmutable token) =>
|
||||
_relay.set_token(token);
|
||||
}
|
||||
|
||||
public void OnCompleted() { }
|
||||
public void OnError(Exception error) => Log.Md.error(error.ToString());
|
||||
|
||||
public void OnError(Exception error) =>
|
||||
Log.Md.error(error.ToString());
|
||||
|
||||
public void OnNext(List<SecurityAndHandle> values) {
|
||||
if (values.Count > 0) {
|
||||
foreach (var v in values) {
|
||||
if (_user_id != _no_user_id &&
|
||||
v.security.ContractCase == Security.ContractOneofCase.Synthetic &&
|
||||
v.security.Synthetic.UserId != _user_id &&
|
||||
v.security.Synthetic.UserId != _no_user_id) {
|
||||
continue;
|
||||
if (v.security.ContractCase != Security.ContractOneofCase.Synthetic || _user.can_access_user_data(v.security.Synthetic.UserId)) {
|
||||
var smd = new SecurityMD(new SecurityImmutable(v.security), v.handle);
|
||||
_exchange_sec_map.AddOrUpdate(smd.security.Id, smd, (_, __) => smd);
|
||||
}
|
||||
var smd = new SecurityMD(new SecurityImmutable(v.security), v.handle);
|
||||
_exchange_sec_map.AddOrUpdate(smd.security.Id, smd, (_, __) => smd);
|
||||
}
|
||||
_version = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() => Disposable.dispose(_dispose);
|
||||
async protected Task run()
|
||||
{
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(_dispose);
|
||||
|
||||
protected async Task run() {
|
||||
DateTime run_version = DateTime.MinValue;
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
var exch = _exchange_sec_map;
|
||||
var current_version = _version;
|
||||
if (current_version > run_version)
|
||||
{
|
||||
if (current_version > run_version) {
|
||||
run_version = current_version;
|
||||
try
|
||||
{
|
||||
try {
|
||||
Log.Md.info($"MDSource publishing {exch.Count} securities");
|
||||
_on_securities.OnNext(exch);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
Log.Md.error($"Error in publish_securities: {e}");
|
||||
}
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
using bts.api;
|
||||
using mbts.co2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts {
|
||||
struct SecurityMD : IEquatable<SecurityMD> {
|
||||
readonly struct SecurityMD : IEquatable<SecurityMD> {
|
||||
public static readonly Func<SecurityMD, uint> key_fn = smd => smd.security.Id;
|
||||
|
||||
public SecurityImmutable security { get; }
|
||||
public MDConsumerHandle md { get; }
|
||||
|
||||
@@ -36,4 +34,4 @@ namespace mbts {
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ namespace bts {
|
||||
Plugin,
|
||||
ClientSdk,
|
||||
Http,
|
||||
OrderMan2,
|
||||
// Please keep this list in sync with logging.h/logging.cpp
|
||||
}
|
||||
|
||||
@@ -106,7 +105,6 @@ namespace bts {
|
||||
internal static Logger DataFlow => new Logger(Subsystem.DataFlow);
|
||||
public static Logger ClientSdk => new Logger(Subsystem.ClientSdk);
|
||||
public static Logger Http => new Logger(Subsystem.Http);
|
||||
public static Logger OrderMan2 => new Logger(Subsystem.OrderMan2);
|
||||
|
||||
internal static void log_at(this Logger logger, Level level, string message) {
|
||||
switch (level) {
|
||||
|
||||
@@ -278,6 +278,9 @@ namespace System.Collections.Generic {
|
||||
public static IComparer<KeyValuePair<TKey, TValue>> key_comparer<TKey, TValue>() =>
|
||||
Impl<TKey, TValue>.key_comparer;
|
||||
|
||||
public static IReadOnlyDictionary<TKey, TValue> wrap_value<TKey, TValue>(TKey key, TValue value) =>
|
||||
new Impl<TKey, TValue>.ValueWrapper(key, value);
|
||||
|
||||
static class Impl<TKey, TValue> {
|
||||
public static readonly IReadOnlyDictionary<TKey, TValue> empty =
|
||||
new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>(0));
|
||||
@@ -297,6 +300,57 @@ namespace System.Collections.Generic {
|
||||
public int Compare(object x, object y) =>
|
||||
x is KeyValuePair<TKey, TValue> xkv ? (y is KeyValuePair<TKey, TValue> ykv ? Compare(xkv, ykv) : 1) : -1;
|
||||
}
|
||||
|
||||
public class ValueWrapper : IReadOnlyDictionary<TKey, TValue> {
|
||||
readonly TKey _key;
|
||||
readonly TValue _value;
|
||||
readonly IEqualityComparer<TKey> _key_comparer;
|
||||
|
||||
public ValueWrapper(TKey key, TValue value)
|
||||
: this(key, value, EqualityComparer<TKey>.Default) { }
|
||||
|
||||
public ValueWrapper(TKey key, TValue value, IEqualityComparer<TKey> key_comparer) {
|
||||
_key = key;
|
||||
_value = value;
|
||||
_key_comparer = key_comparer;
|
||||
}
|
||||
|
||||
public TValue this[TKey key] =>
|
||||
_key_comparer.Equals(key, _key) ? _value : throw new KeyNotFoundException();
|
||||
|
||||
public int Count => 1;
|
||||
|
||||
public IEnumerable<TKey> Keys {
|
||||
get {
|
||||
yield return _key;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> Values {
|
||||
get {
|
||||
yield return _value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsKey(TKey key) => _key_comparer.Equals(key, _key);
|
||||
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() {
|
||||
yield return new KeyValuePair<TKey, TValue>(_key, _value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
yield return new KeyValuePair<TKey, TValue>(_key, _value);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey key, out TValue value) {
|
||||
if (_key_comparer.Equals(key, _key)) {
|
||||
value = _value;
|
||||
return true;
|
||||
}
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,6 +343,18 @@ namespace System.Collections.Generic {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<T> ToListSorted<T, TKey>(this IEnumerable<T> enumerable, Func<T, TKey> key_selector) =>
|
||||
enumerable.ToListSorted(key_selector, Comparer<TKey>.Default);
|
||||
|
||||
public static List<T> ToListSorted<T, TKey>(this IEnumerable<T> enumerable, Func<T, TKey> key_selector, IComparer<TKey> key_comparer) =>
|
||||
enumerable.ToListSorted(key_comparer.wrap(key_selector));
|
||||
|
||||
public static List<T> ToListSorted<T>(this IEnumerable<T> enumerable, IComparer<T> comparer) {
|
||||
var list = new List<T>(enumerable);
|
||||
list.Sort(comparer);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simply returns enumerable.ToList(), under the guise ofo IReadOnlyList<>
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace bts.collections {
|
||||
public static class ImmutableSetExtensions {
|
||||
public static IImmutableSet<T> RemoveRange<T>(this IImmutableSet<T> source, IEnumerable<T> values) {
|
||||
/// Prefer the <see cref="ImmutableHashSet{T}"/> implementation.
|
||||
/// It uses an <see cref="ImmutableHashSet{T}.Builder"/> to remove values, which is optimized for bulk changes (less memory allocations, etc.).
|
||||
if (source is ImmutableHashSet<T> ihs) {
|
||||
return ihs.RemoveRange(values);
|
||||
}
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (values == null) throw new ArgumentNullException(nameof(values));
|
||||
foreach (var v in values)
|
||||
source = source.Remove(v);
|
||||
return source;
|
||||
}
|
||||
|
||||
public static ImmutableHashSet<T> RemoveRange<T>(this ImmutableHashSet<T> source, IEnumerable<T> values) {
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (values == null) throw new ArgumentNullException(nameof(values));
|
||||
var bd = source.ToBuilder();
|
||||
foreach (var v in values)
|
||||
bd.Remove(v);
|
||||
return bd.ToImmutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ using System.Diagnostics;
|
||||
namespace bts.test {
|
||||
public static class InProcessTestRunner {
|
||||
|
||||
public static void run_test_synchronously(string v, TestEnumerator enumerator, Action<TestResult> report) {
|
||||
foreach (var t in enumerator.find(v)) {
|
||||
run_test_synchronously(t, report);
|
||||
public static void run_test_synchronously(string v, TestType type, TestEnumerator enumerator, Action<TestResult> report) {
|
||||
foreach (var t in enumerator.find(v,type)) {
|
||||
run_test_synchronously(t, report);
|
||||
}
|
||||
}
|
||||
public static void run_test_synchronously(TestMethod test, Action<TestResult> report) {
|
||||
|
||||
@@ -36,18 +36,19 @@ namespace bts.test {
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<TestMethod> find(string name) {
|
||||
public IEnumerable<TestMethod> find(string name, TestType type) {
|
||||
foreach (var g in TestGroups) {
|
||||
foreach (var t in g.methods) {
|
||||
if (g.name == name || t.name == name || t.full_name == name) {
|
||||
if (g.test_type == type &&
|
||||
(g.name == name || t.name == name || t.full_name == name)) {
|
||||
yield return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TestMethod> match(IEnumerable<string> names) {
|
||||
return names.SelectMany(find).Distinct();
|
||||
public IEnumerable<TestMethod> match(TestType type, IEnumerable<string> names) {
|
||||
return names.SelectMany(name => find(name,type)).Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
using bts;
|
||||
using bts.api.admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.api.core
|
||||
{
|
||||
public class AdminModelWrapper
|
||||
{
|
||||
readonly AdminDataImmutable? _admin_data;
|
||||
public AdminDataImmutable? admin_data => _admin_data;
|
||||
readonly string _user_name;
|
||||
readonly List<BTSAccountImmutable> _allowed_accounts;
|
||||
readonly Dictionary<string, string> _allowed_account_dict = new Dictionary<string, string>();
|
||||
public AdminModelWrapper(AdminDataImmutable? admin_data = null, string user_name = null)
|
||||
{
|
||||
_admin_data = admin_data;
|
||||
_user_name = user_name ?? string.Empty;
|
||||
_allowed_accounts = search_admin(u => u.Name == _user_name).Where(x =>
|
||||
{
|
||||
return (x.Item2 != null && x.Item2.HasPermissions) || (x.Item3 != null && x.Item3.HasPermissions);
|
||||
}).Select(xx => xx.Item1).ToList();
|
||||
foreach (var val in _allowed_accounts)
|
||||
_allowed_account_dict[val.Name] = val.Name;
|
||||
}
|
||||
public IEnumerable<BTSAccountImmutable> viewable_accounts()
|
||||
{
|
||||
return _allowed_accounts;
|
||||
}
|
||||
public bool can_view_account(string account)
|
||||
{
|
||||
return _allowed_account_dict.ContainsKey(account) || _user_name.ToLower().Equals("bts");
|
||||
}
|
||||
|
||||
IEnumerable<Tuple<BTSAccountImmutable, TradingPermissionUnit, AdminPermissionUnit>>
|
||||
search_admin(Func<BTSUserImmutable, bool> predicate)
|
||||
{
|
||||
var rv = new List<Tuple<BTSAccountImmutable, TradingPermissionUnit, AdminPermissionUnit>>();
|
||||
if (_admin_data.HasValue)
|
||||
{
|
||||
var users = _admin_data.Value.Users.Where(predicate);
|
||||
if (users != null && users.Count() == 1)
|
||||
{
|
||||
var user = users.ElementAt(0);
|
||||
if (user.HasUserData && user.UserData.HasAccountPermissions)
|
||||
{
|
||||
foreach (var kv in user.UserData.AccountPermissions.AccountPermissions)
|
||||
{
|
||||
var account_id = kv.Key;
|
||||
var accounts = _admin_data.Value.Accounts.Where(a => a.Id == account_id);
|
||||
if (accounts != null && accounts.Count() == 1)
|
||||
{
|
||||
var account = accounts.ElementAt(0);
|
||||
rv.Add(Tuple.Create(account, kv.Value.TradingPermission, kv.Value.AdminPermission));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace bts.api.core
|
||||
{
|
||||
public static class PermissionFilters
|
||||
{
|
||||
public static IObservable<Update<PositionUnitImmutable, int>>
|
||||
PermissionFilter(this IObservable<Update<PositionUnitImmutable, int>> source, IObservable<AdminModelWrapper> am)
|
||||
{
|
||||
var pred = Observable.Create<Func<PositionUnitImmutable, bool>>( observer =>
|
||||
{
|
||||
return am.Subscribe(x =>
|
||||
{
|
||||
Func<PositionUnitImmutable, bool> filter = (z => x.can_view_account(z.Account));
|
||||
observer.OnNext(filter);
|
||||
});
|
||||
});
|
||||
|
||||
return source.Filter(pred);
|
||||
}
|
||||
|
||||
public static IObservable<Update<OrderRecordImmutable, uint>>
|
||||
PermissionFilter(this IObservable<Update<OrderRecordImmutable, uint>> source, IObservable<AdminModelWrapper> am)
|
||||
{
|
||||
var pred = Observable.Create<Func<OrderRecordImmutable, bool>>(observer =>
|
||||
{
|
||||
return am.Subscribe(x =>
|
||||
{
|
||||
Func<OrderRecordImmutable, bool> filter = (z => x.can_view_account(z.Def.Account ?? string.Empty));
|
||||
observer.OnNext(filter);
|
||||
});
|
||||
});
|
||||
|
||||
return source.Filter(pred);
|
||||
}
|
||||
|
||||
public static IObservable<Update<FillImmutable, string>>
|
||||
PermissionFilter(this IObservable<Update<FillImmutable, string>> source, IObservable<AdminModelWrapper> am)
|
||||
{
|
||||
var pred = Observable.Create<Func<FillImmutable, bool>>(observer =>
|
||||
{
|
||||
return am.Subscribe(x =>
|
||||
{
|
||||
Func<FillImmutable, bool> filter = (z => x.can_view_account(z.Account));
|
||||
observer.OnNext(filter);
|
||||
});
|
||||
});
|
||||
|
||||
return source.Filter(pred);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using mbts.config;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using Google.Protobuf;
|
||||
using bts;
|
||||
using System.Linq;
|
||||
using bts.support;
|
||||
|
||||
namespace mbts
|
||||
{
|
||||
public static class LogUtil {
|
||||
private static string log_path = Path.Combine(Configuration.get<bts.config.System>().data_path, "logging", "log");
|
||||
|
||||
|
||||
|
||||
public static ByteString read_logs_compressed() {
|
||||
return FileUtils.read_and_gzip(log_path);
|
||||
}
|
||||
|
||||
public static (ByteString,DateTime) read_latest_crash_dump() {
|
||||
// Find the latest crash dump
|
||||
// If it is < 5 days old
|
||||
// gzip it in place (delete original)
|
||||
// upload the gziped dump
|
||||
|
||||
var crash_dump_folder = "c:\\programdata\\bts\\crash_dumps";
|
||||
FileUtils.keep_n_matching_files(crash_dump_folder, "*.gz", 4);
|
||||
try {
|
||||
if (Directory.Exists(crash_dump_folder)) {
|
||||
var latest =
|
||||
Directory.GetFiles(crash_dump_folder, "*.dmp")
|
||||
.Select(f => new { name = f, modified = File.GetLastWriteTimeUtc(f) })
|
||||
.OrderBy(f => f.modified)
|
||||
.Reverse()
|
||||
.FirstOrDefault();
|
||||
if (latest != null) {
|
||||
if (DateTime.Now - latest.modified <= TimeSpan.FromDays(5)) {
|
||||
var newname = FileUtils.gzip_file_in_place(latest.name);
|
||||
if (!string.IsNullOrEmpty(newname)) {
|
||||
return (ByteString.FromStream(File.OpenRead(newname)), latest.modified);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.Gen.error($"Failed to read crash dumps. Exception: {e.Message}");
|
||||
}
|
||||
return (ByteString.Empty, DateTime.MinValue);
|
||||
}
|
||||
|
||||
public static ByteString read_windows_event_log() {
|
||||
// try to export the events to temp
|
||||
var temp = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".evtx");
|
||||
bool success = NativeMethods.EvtExportLog(
|
||||
IntPtr.Zero,
|
||||
"Application",
|
||||
"*",
|
||||
temp,
|
||||
NativeMethods.EventExportLogFlags.ChannelPath);
|
||||
if (success) {
|
||||
var result = FileUtils.read_and_gzip(temp);
|
||||
FileUtils.try_delete(temp);
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
string msg = new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).Message;
|
||||
Log.Gen.error($"Error exporting windows event log. {msg}");
|
||||
}
|
||||
return ByteString.Empty;
|
||||
}
|
||||
|
||||
|
||||
static class NativeMethods {
|
||||
[Flags]
|
||||
public enum EventExportLogFlags {
|
||||
ChannelPath = 1,
|
||||
LogfilePath = 2,
|
||||
TolerateQueryErrors = 0x1000
|
||||
}
|
||||
|
||||
[DllImport("wevtapi.dll", CallingConvention=CallingConvention.Winapi, CharSet = CharSet.Auto, SetLastError =true)]
|
||||
public static extern bool EvtExportLog(
|
||||
IntPtr session,
|
||||
string path,
|
||||
string query,
|
||||
string targetPath,
|
||||
[MarshalAs(UnmanagedType.I4)]
|
||||
EventExportLogFlags flags);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Mail;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using mbts.config;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace mbts
|
||||
{
|
||||
public static class LogUtil {
|
||||
public static string read_logs() {
|
||||
var log_path = Path.Combine(Configuration.get<bts.config.System>().data_path, "logging", "log");
|
||||
if (File.Exists(log_path)) {
|
||||
try {
|
||||
using (var f = File.Open(log_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
|
||||
var reader = new StreamReader(f);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
return "Log file does not exist";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace bts.support {
|
||||
static class FileUtils {
|
||||
public static bool try_delete(string path) {
|
||||
try {
|
||||
if (File.Exists(path)) {
|
||||
File.Delete(path);
|
||||
}
|
||||
else if (Directory.Exists(path)) {
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ByteString read_and_gzip(string path) {
|
||||
if (File.Exists(path)) {
|
||||
try {
|
||||
using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite /*Note: ReadWrite is more permissive than Read*/))
|
||||
using (var ms = new MemoryStream())
|
||||
using (var gz = new GZipStream(ms, CompressionMode.Compress, true)) {
|
||||
fs.CopyTo(gz);
|
||||
gz.Close();
|
||||
return ByteString.CopyFrom(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.Gen.error($"Failed to read file '{path}' -- {e.Message}");
|
||||
return ByteString.Empty;
|
||||
}
|
||||
}
|
||||
return ByteString.Empty;
|
||||
}
|
||||
|
||||
|
||||
// If input exists compress it and add a .gz extension
|
||||
// original file is deleted
|
||||
public static string gzip_file_in_place(string file) {
|
||||
if (File.Exists(file)) {
|
||||
string destination = file + ".gz";
|
||||
using (var input = File.OpenRead(file)) {
|
||||
using (var output = File.OpenWrite(destination)) {
|
||||
using (var writer = new GZipStream(output, CompressionMode.Compress)) {
|
||||
input.CopyTo(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
try_delete(file);
|
||||
return destination;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Delete the oldest files matching pattern (*.txt) keeping {count} files
|
||||
public static void keep_n_matching_files(string directory, string pattern, int count) {
|
||||
var to_delete =
|
||||
Directory.GetFiles(directory, pattern)
|
||||
.Select(f => new { name = f, modified = File.GetLastWriteTimeUtc(f) })
|
||||
.OrderBy(f => f.modified)
|
||||
.Reverse()
|
||||
.Skip(count);
|
||||
|
||||
foreach (var f in to_delete) {
|
||||
try_delete(f.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using bts.co2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -39,8 +40,29 @@ namespace bts.tests {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<SecurityImmutable>> get_multiple_securities(MarketDataRelay relay, IEnumerable<Product> products, SecurityType security_type, MDRequest.Types.Flags flags = MDRequest.Types.Flags.Bbo, Venue v = Venue.Sim) {
|
||||
var request = new MDRequest() { Host = _MD_HOST };
|
||||
request.Channels.AddRange(products.Select(z =>
|
||||
new SecurityChannel() {
|
||||
Time = 0,
|
||||
Flags = (uint)flags,
|
||||
Type = security_type,
|
||||
Exchange = v,
|
||||
Symbol = z.Symbol,
|
||||
TradeCursor = 0,
|
||||
RfqCursor = 0
|
||||
}));
|
||||
|
||||
var result = await relay.requestmd_async(request);
|
||||
|
||||
if (result.success) {
|
||||
return result.value.Channels.Where(s => s.Updates.Count > 0).Select(x => (SecurityImmutable) x.Updates.First().Security);
|
||||
}
|
||||
return Enumerable.Empty<SecurityImmutable>();
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<FutureContract>> get_expirations(MarketDataRelay relay, string symbol, SecurityType security_type, MDRequest.Types.Flags flags = MDRequest.Types.Flags.Bbo, Venue v = Venue.Sim) {
|
||||
var request = new MDRequest() {
|
||||
var request = new MDRequest() {
|
||||
Host = _MD_HOST,
|
||||
Channels = {
|
||||
new SecurityChannel() {
|
||||
|
||||
@@ -158,18 +158,22 @@ namespace bts.tests.utils {
|
||||
}
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
//UserSymbol.get_all() in MDConsumer.cs
|
||||
|
||||
bts.test.Assert.IsTrue(products != null, "No products found");
|
||||
var filtered_products = products.Products.Where(z => z.Exchange == Venue.Sim && z.Type == SecurityType.Future);
|
||||
bts.test.Assert.IsTrue(filtered_products.Count() > 0, "No suitable products found");
|
||||
IEnumerable<Product> filtered_products = products.Products.Where(z => z.Exchange == Venue.Sim && z.Type == SecurityType.Future);
|
||||
bts.test.Assert.IsTrue(filtered_products.Count() > 0, "No suitable products found"); //products are not guaranteed to have securities, so I need to get the product from the list of securities
|
||||
|
||||
uint? sec_id = null;
|
||||
|
||||
/* get securities if the list is not empty use the top one */
|
||||
|
||||
for(int i = 0; i < 10; i++) {
|
||||
var test_security = await MarketDataUtilities.get_security(mdrelay, filtered_products.First().Symbol, SecurityType.Future, f => true);
|
||||
if(test_security.HasValue) {
|
||||
var test_security = await MarketDataUtilities.get_multiple_securities(mdrelay, filtered_products, SecurityType.Future);
|
||||
|
||||
if(test_security.Count() > 0) {
|
||||
Console.Write("," + i);
|
||||
sec_id = test_security.Value.Id;
|
||||
sec_id = test_security.FirstOrDefault().Id;
|
||||
break;
|
||||
}
|
||||
await Task.Delay(10000);
|
||||
|
||||
@@ -347,6 +347,12 @@ namespace mbts.api.Test {
|
||||
var a3 = new Update<string, int>(new[] { "a3" }, empty, new[] { new Change<string>("a2", "a3") }, empty, key);
|
||||
var merged = a2.merge(a3);
|
||||
Assert.SequenceEqual(new[] { new Change<string>("a1", "a3") }, merged.changes);
|
||||
// clear the state, then add a2 back
|
||||
// (this validates the fix for the Update.naggle bug where interim changes were converted into added/removed).
|
||||
var cleared = new Update<string, int>(empty, empty, Array.Empty<Change<string>>(), merged.all, key);
|
||||
a2 = new Update<string, int>(new[] { "a2" }, new[] { "a2" }, Array.Empty<Change<string>>(), empty, key);
|
||||
merged = merged.merge(cleared).merge(a2);
|
||||
Assert.SequenceEqual(new[] { new Change<string>("a1", "a2") }, merged.changes);
|
||||
}
|
||||
|
||||
T id<T>(T t) => t;
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace sparkcmd {
|
||||
}
|
||||
else Configuration.initialize();
|
||||
|
||||
Console.WriteLine(JsonConvert.SerializeObject(o));
|
||||
ConsoleEx.WriteLine(JsonConvert.SerializeObject(o), ConsoleColor.DarkGray);
|
||||
|
||||
if (o.list) {
|
||||
list_tests((o.type));
|
||||
@@ -58,13 +58,19 @@ namespace sparkcmd {
|
||||
if (o.timeout == 0 && o.tests.Count() == 1 && !o.self_contained) {
|
||||
//System.Threading.Thread.Sleep(5000);
|
||||
using (var trr = new TestResultReceiver(true)) {
|
||||
InProcessTestRunner.run_test_synchronously(o.tests.First(), Enumerator, trr.get_reporter());
|
||||
InProcessTestRunner.run_test_synchronously(o.tests.First(), o.type, Enumerator, trr.get_reporter());
|
||||
trr.print_summary();
|
||||
if (trr.ResultCount == 0) {
|
||||
ConsoleEx.Write("No ", ConsoleColor.Red);
|
||||
ConsoleEx.Write(o.type.ToString(), ConsoleColor.Yellow);
|
||||
ConsoleEx.WriteLine($" tests matched filter '{o.tests.First()}'", ConsoleColor.Red);
|
||||
return -1;
|
||||
}
|
||||
return trr.ErrorCount;
|
||||
}
|
||||
}
|
||||
else if (o.tests.Count() > 0) {
|
||||
return run_tests(o, Enumerator.match(o.tests));
|
||||
return run_tests(o, Enumerator.match(o.type, o.tests));
|
||||
}
|
||||
else {
|
||||
return run_tests(o, Enumerator.get_of_type(o.type));
|
||||
|
||||
@@ -29,8 +29,13 @@ namespace sparkcmd {
|
||||
// initialized from c++ instead of c#
|
||||
BTSNativeMethods.provide_command_line(args, args.Length);
|
||||
|
||||
var parser = new Parser(ps => {
|
||||
ps.CaseInsensitiveEnumValues = true;
|
||||
ps.HelpWriter = Console.Out;
|
||||
});
|
||||
|
||||
// note: this can be made to infer the options type list from the list of delegates
|
||||
return Parser.Default
|
||||
return parser
|
||||
.ParseArguments<
|
||||
ConfigcheckOptions,
|
||||
ScriptClientOptions,
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
||||
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
|
||||
NGG 1OXPqNxPhbqbzm0kF92e qlUrwY1KG1Pyq-TcbJgMqYXmBTQoAi-wEEBERRDRZPE 2019-12-20 2020-12-20 NEWRELEASE
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/FillStore.cpp;orderman/actors/GLBXExecutionGateway.cpLine truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orLine truncated
|
||||
@@ -10,6 +10,7 @@ namespace {{package}} {
|
||||
{{#each message_type}}
|
||||
partial class {{name}} : bts.api.IImmutableMessage {
|
||||
MessageDescriptor bts.api.IImmutableMessage.Descriptor => {{name}}.Descriptor;
|
||||
public {{name}}Immutable immutable() => new {{name}}Immutable(this);
|
||||
}
|
||||
public readonly partial struct {{name}}Immutable : bts.api.IImmutableMessage {
|
||||
readonly {{name}} _impl;
|
||||
|
||||
@@ -1028,38 +1028,60 @@ std::string AdminServiceUtils::find_user_company_id (const bts::api::admin::Admi
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::pair<const bts::api::admin::BTSAccount*, const bts::api::admin::BTSUser*>
|
||||
AdminServiceUtils::find_user_account_matches (const bts::api::admin::AdminData& admin_data,
|
||||
const std::string& connection, const std::string& exchange_account,
|
||||
std::pair<const BTSAccount*, const BTSUser*>
|
||||
AdminServiceUtils::find_user_account_matches (const AdminData& admin_data,
|
||||
const std::string& connection,
|
||||
const std::string& exchange_account,
|
||||
const std::string& exchange_user,
|
||||
api::Venue exchange){
|
||||
bts::api::admin::AdminServiceOperationResult find_account_result, find_user_result;
|
||||
auto account_ptrs = accounts(admin_data, false);
|
||||
auto user_ptrs = users(admin_data, false);
|
||||
for(const bts::api::admin::BTSAccount* account_ptr : account_ptrs){
|
||||
if (account_has_connection(*account_ptr, connection)){
|
||||
if (boost::algorithm::iequals(exchange_account, find_account_exchange_account(admin_data,*account_ptr,exchange,find_account_result)) &&
|
||||
find_account_result.is_success())
|
||||
{
|
||||
for(const bts::api::admin::BTSUser* user_ptr : user_ptrs)
|
||||
{
|
||||
if (boost::algorithm::iequals(exchange_user,find_user_exchange_id(admin_data,*user_ptr,exchange,find_user_result)) &&
|
||||
find_user_result.is_success())
|
||||
return std::pair<const bts::api::admin::BTSAccount*, const bts::api::admin::BTSUser*>(account_ptr,user_ptr);
|
||||
|
||||
//This code eventually gets called by get_reverse_routing_record(...)
|
||||
//At the ice, they send back the login level tag50 in exec reports which doesn't match any user level tag50s in the exchange_user
|
||||
//so instead we look for the CompanyID (or client_id, tag 109) field here. If this field matches we have a good bet that
|
||||
//the user we find is enough to fulfill the routing record enough to cancel or modify orphaned orders, etc
|
||||
if (boost::algorithm::iequals(exchange_user,find_user_company_id(admin_data,*user_ptr,exchange,find_user_result)) &&
|
||||
find_user_result.is_success())
|
||||
return std::pair<const bts::api::admin::BTSAccount*, const bts::api::admin::BTSUser*>(account_ptr,user_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
AdminServiceOperationResult find_account_result, find_user_result;
|
||||
// i. uses the exchange and exchange_user to reverse lookup the user(s)
|
||||
auto user_ptrs = users(admin_data, false);
|
||||
std::vector<BTSUser const*> matching_users;
|
||||
for (BTSUser const* u : user_ptrs){
|
||||
auto exchange_u = find_user_exchange_id(admin_data, *u,
|
||||
exchange, find_user_result);
|
||||
if (find_user_result.is_success() && boost::algorithm::iequals (
|
||||
exchange_u,
|
||||
exchange_user))
|
||||
matching_users.push_back(u);
|
||||
}
|
||||
return std::pair<const bts::api::admin::BTSAccount*, const bts::api::admin::BTSUser*>(nullptr, nullptr);
|
||||
// i.5
|
||||
//At the ice, they send back the login level tag50 in exec reports which doesn't match any user level tag50s in the exchange_user
|
||||
//so instead we look for the CompanyID (or client_id, tag 109) field here. If this field matches we have a good bet that
|
||||
//the user we find is enough to fulfill the routing record enough to cancel or modify orphaned orders, etc
|
||||
for (BTSUser const* u : user_ptrs)
|
||||
{
|
||||
auto exchange_u = find_user_company_id(admin_data, *u, exchange, find_user_result);
|
||||
if (find_user_result.is_success() && boost::algorithm::iequals ( exchange_u, exchange_user))
|
||||
matching_users.push_back(u);
|
||||
}
|
||||
// ii. uses the exchange, connection and exchange_account to reverse lookup the account(s)
|
||||
auto account_ptrs = accounts(admin_data, false);
|
||||
std::vector<BTSAccount const*> matching_accounts;
|
||||
for (BTSAccount const* a :account_ptrs)
|
||||
if (account_has_connection(*a, connection)){
|
||||
auto exchange_a = find_account_exchange_account(admin_data, *a,
|
||||
exchange,
|
||||
find_account_result);
|
||||
if (find_account_result.is_success() && boost::algorithm::iequals (
|
||||
exchange_a,
|
||||
exchange_account))
|
||||
matching_accounts.push_back(a);
|
||||
}
|
||||
// iii. finds the first account from ii that the user from i is authorized to trade
|
||||
for (BTSUser const* u : matching_users){
|
||||
std::vector<BTSAccount const*> user_auth_accounts;
|
||||
find_user_trading_accounts (admin_data, u->id(), user_auth_accounts);
|
||||
for (BTSAccount const* i : user_auth_accounts)
|
||||
for (BTSAccount const* j : matching_accounts)
|
||||
if(i->id() == j->id())
|
||||
return std::pair<BTSAccount const*, BTSUser const*>(i,u);
|
||||
}
|
||||
return std::pair<const BTSAccount*, const BTSUser*>(nullptr, nullptr);
|
||||
}
|
||||
|
||||
|
||||
// for a given user finds the account permissions (if permissions are
|
||||
// derived from the group, it traverses the group hierarcy to find the
|
||||
// correct permissions.
|
||||
|
||||
@@ -215,6 +215,9 @@ public:
|
||||
const BTSUser& user,
|
||||
api::Venue exchange,
|
||||
AdminServiceOperationResult& out_result);
|
||||
// i. uses the exchange and exchange_user to reverse lookup the user(s)
|
||||
// ii. uses the exchange, connection and exchange_account to reverse lookup the account(s)
|
||||
// iii. finds the first account from ii that a user from i is authorized to trade
|
||||
static std::string find_user_company_id (
|
||||
const AdminData& data,
|
||||
const BTSUser& user,
|
||||
|
||||
@@ -4,6 +4,11 @@ option csharp_namespace="bts.support";
|
||||
import "lib/api/apioptions.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
message FileData {
|
||||
string name = 1;
|
||||
bytes contents = 2;
|
||||
}
|
||||
|
||||
message ErrorReport {
|
||||
google.protobuf.Timestamp timestamp = 1;
|
||||
string user = 2;
|
||||
@@ -13,6 +18,7 @@ message ErrorReport {
|
||||
string log = 6;
|
||||
bytes image = 7;
|
||||
string contact = 8;
|
||||
repeated FileData files = 9;
|
||||
}
|
||||
message ErrorResponse {
|
||||
}
|
||||
|
||||
@@ -334,6 +334,7 @@ message RoutingRecord {
|
||||
string smp_id = 6 ;
|
||||
SelfMatchPreventionInstruction smp_instruction = 7;
|
||||
string location = 8;
|
||||
string cust_order_handling_inst = 9;
|
||||
|
||||
string sender_compid = 15;
|
||||
string clearing_firm = 20;
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
|
||||
#nusers: 1
|
||||
#allow concurrent : true
|
||||
#expires: 2019-Dec-31 00:00:00 637133472000000000
|
||||
#generation_time: 2019-Sep-16 17:50:57.225054 5248728548999638444
|
||||
#generation_time: 2019-Sep-30 15:52:10.434845 5248740573731736354
|
||||
EncryptedKeyCode {
|
||||
value {
|
||||
keycode: "E7sUCxYuveyuvvBfwMdTrUCpFROJWQvsy4pYjwZ+zonjHwEmDkjxbxaqUEKqMzBbAq3YFnxIGOrQpRJte71SEoG5FGy4ZoRrVOjrMdNVLmieUWtZU43FKGJzImj/tJKEXu2xgwYJRZTj/AJ8C30PuVnzm0qUmR+UCgCOxKVeK0OFlo6zSqyDutcy5kLW3va+nTuFp43aknm6Iiu8LFW16wa6QDDCSQd4QgnHmiz5wyMC90yGBE4qObTKRGKDl5mWsjEL16aWK2ZO/0/ebFgGG8WygQfkeFzJS7B4q5Ta0nkSkVyLZjq1LN2/g9AXeCzCJUX5/F96kdfsnfSgAJepeg=="
|
||||
keycode: "fVZlub92ulkXME+uZSyO9+WmyAXYKD735Qzxxfdj4G+SqEDTuwfNxOZVPS3TCFQqWPDmgjKTbbvfqIrGe3icxkVObUcUoS7lBXRXFrSvzOfs9eTz9RqHRvquDidnOzKxmSXsxV2bMb21UqBCJFeTzb4Q6Agp8EtjXJRc57UMVVygvdXg528S3ocBIq1V4W5NYraFn5WpqrTuBhpYbnsZAHi77s/EEwUT+6la3J2OHPtbiQnB6JFb0zsExMuzE4gwp79ojuQ5pnV2DXBZFNwxYvFyBUU/ac6oU89saZ/ay1DbOjz76TNqnNFewZvzdXZl3y6+X1eblX2streH2pn7gg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,33 +31,4 @@ OrdermanCfg {
|
||||
hosted_actor: "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OrderManThreadingCfg {
|
||||
value {
|
||||
thread {
|
||||
name: "om_1"
|
||||
poll: true
|
||||
actor: { name: "order_manager" }
|
||||
}
|
||||
|
||||
thread {
|
||||
name: "om_2"
|
||||
poll: true
|
||||
actor: { name: "order_manager" }
|
||||
}
|
||||
|
||||
thread {
|
||||
name: "gw_1"
|
||||
poll: true
|
||||
actor: { name: "gateway" arg: "sim" }
|
||||
actor: { name: "gateway" arg: "cme_mc5_99" }
|
||||
}
|
||||
|
||||
thread {
|
||||
name: "om_slow"
|
||||
actor: {name: "storage"}
|
||||
actor: {name: "service_bridge"}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,11 @@ message JetFIX {
|
||||
required string name = 10;
|
||||
|
||||
enum JetFIXPlatform {
|
||||
GLBX = 1;
|
||||
GLBX = 1;
|
||||
CBOE = 6;
|
||||
SIM = 2;
|
||||
ICE = 3;
|
||||
SIMICE = 4;
|
||||
CBOE = 6;
|
||||
}
|
||||
optional JetFIXPlatform platform = 15 [default = GLBX];
|
||||
|
||||
|
||||
@@ -9,20 +9,5 @@ message OrdermanCfg {
|
||||
}
|
||||
repeated Executor executor = 1;
|
||||
optional uint32 default_iceberg_pause_secs = 2 [default = 0];
|
||||
optional string fallback_cust_order_handling_inst = 3 [default = "Y"];
|
||||
}
|
||||
|
||||
message OrderManThreadingCfg {
|
||||
|
||||
message Actor {
|
||||
required string name = 1;
|
||||
repeated string arg = 2;
|
||||
}
|
||||
|
||||
message Thread {
|
||||
required string name = 1;
|
||||
optional bool poll = 2 [default = false];
|
||||
optional uint32 slow_worker_period = 3 [default = 100000];
|
||||
repeated Actor actor = 4;
|
||||
}
|
||||
repeated Thread thread= 1;
|
||||
}
|
||||
@@ -58,3 +58,7 @@ message EnsureOnScreenWithWorkAreaRect {
|
||||
// Should verify that the code works with every monitor arrangement before enabling by default.
|
||||
optional bool enabled = 1 [default = false];
|
||||
}
|
||||
|
||||
message IgnoreNansInDayPnL {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace jetfix {
|
||||
namespace fix {
|
||||
|
||||
typedef BoolField<1028> ManualOrderIndicator;
|
||||
typedef StringField<1031> CustOrderHandlingInst;
|
||||
typedef BoolField<123> GapFillFlag;
|
||||
typedef BoolField<43> PossDupFlag;
|
||||
typedef BoolField<9768> InFlightMitigation;
|
||||
|
||||
@@ -45,7 +45,8 @@ typedef FIXMsg<MessageTypes::ExecutionReport,
|
||||
Text,
|
||||
TargetSubID,
|
||||
MsgSeqNum,
|
||||
TransactTimeStr>
|
||||
TransactTimeStr,
|
||||
CustOrderHandlingInst >
|
||||
ExecutionReportMsg;
|
||||
|
||||
typedef FIXMsg<MessageTypes::BusinessMessageReject,Text>
|
||||
|
||||
@@ -11,7 +11,7 @@ inline int d_toa(double n, char *buffer, size_t buffer_size, int decimal_digits=
|
||||
static double_conversion::DoubleToStringConverter const &c =
|
||||
double_conversion::DoubleToStringConverter::EcmaScriptConverter();
|
||||
|
||||
bts_assert_d(buffer_size);
|
||||
bts_assert(buffer_size);
|
||||
|
||||
if (pad == -1) {
|
||||
// no padding, return the smallest number that contains all the
|
||||
@@ -34,8 +34,8 @@ inline int d_toa(double n, char *buffer, size_t buffer_size, int decimal_digits=
|
||||
// padding, return something with a fixed size
|
||||
|
||||
std::array<char, 128> pre_buffer;
|
||||
bts_assert_d((int)buffer_size > pad);
|
||||
bts_assert_d((int)pre_buffer.size() >= pad);
|
||||
bts_assert((int)buffer_size > pad);
|
||||
bts_assert((int)pre_buffer.size() >= pad);
|
||||
|
||||
double_conversion::StringBuilder builder(&pre_buffer[0], pre_buffer.size());
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ size_t extract(char *start, char *end,
|
||||
std::vector<InMsgBuffer> *msgs) {
|
||||
auto first_unprocessed_byte = 0;
|
||||
auto current = start;
|
||||
|
||||
|
||||
for (;;) {
|
||||
// consume prefix
|
||||
auto this_msg_begin = current;
|
||||
@@ -143,20 +143,20 @@ void AsyncReader::dispatch() {
|
||||
// see what we can parse with the just read bytes
|
||||
framed_msgs.clear();
|
||||
|
||||
// extract as many messages as we can from the last
|
||||
// unprocessed byte to the current write cursor, return
|
||||
// offset of first byte in the buffer that we could not
|
||||
// process (possibly the first byte of an incomplete msg)
|
||||
auto first_unprocessed_offset =
|
||||
extract(&((*me->working_buffer)[me->first_pending_msg]),
|
||||
&((*me->working_buffer)[me->write_cursor]),
|
||||
me->working_buffer, &framed_msgs);
|
||||
// extract as many messages as we can from the last unprocess
|
||||
// byte to the current write cursor, return offset of first
|
||||
// byte in the buffer that we could not process (possibly the
|
||||
// first byte of an incomplete msg)
|
||||
auto first_unprocessed_offset = extract(
|
||||
&((*me->working_buffer)[me->first_pending_msg]),
|
||||
&((*me->working_buffer)[me->write_cursor]), me->working_buffer,
|
||||
&framed_msgs);
|
||||
me->first_pending_msg += first_unprocessed_offset;
|
||||
|
||||
for (auto &msg : framed_msgs) {
|
||||
trace.sn = msg.get_seq_num();
|
||||
socket_read_time.shift_ns(1);
|
||||
me->perf_log.log(trace, socket_read_time, "fix_msg_r");
|
||||
me->perf_log.log(trace, socket_read_time,"fix_msg_r");
|
||||
msg.set_trace(trace);
|
||||
me->sink.in_msg_raw(msg);
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace jetfix {
|
||||
|
||||
enum class CoreGateway::State {
|
||||
OFF,
|
||||
PAUSED,
|
||||
CONNECTING,
|
||||
READY,
|
||||
WREADER_DISCONNECT,
|
||||
WSESSION_TERMINATE
|
||||
};
|
||||
PAUSED,
|
||||
CONNECTING,
|
||||
READY,
|
||||
WREADER_DISCONNECT,
|
||||
WSESSION_TERMINATE
|
||||
};
|
||||
|
||||
struct CoreGateway::SessionInfo {
|
||||
SessionInfo() : connection(), store(), reader(), session() {}
|
||||
@@ -47,21 +47,21 @@ struct CoreGateway::EventData {
|
||||
typedef void (CoreGateway::*Handler)(EventData const &ev);
|
||||
|
||||
EventData(const EventData &src)
|
||||
: handler(src.handler), out_msgs(src.out_msgs), in_msg(src.in_msg),
|
||||
trace(src.trace), ts(src.ts) {}
|
||||
: handler(src.handler), out_msgs(src.out_msgs), in_msg(src.in_msg),
|
||||
trace(src.trace), ts(src.ts) {}
|
||||
|
||||
EventData() : handler(), out_msgs(), in_msg(), trace(), ts() {}
|
||||
EventData(Handler handler)
|
||||
: handler(handler), out_msgs(), in_msg(), trace(), ts() {}
|
||||
: handler(handler), out_msgs(), in_msg(), trace(), ts() {}
|
||||
EventData(Handler handler, trace::CorID const &trace,
|
||||
OutFIXPtr const &out_msgs)
|
||||
: handler(handler), out_msgs(out_msgs), in_msg(), trace(trace), ts() {}
|
||||
: handler(handler), out_msgs(out_msgs), in_msg(), trace(trace), ts() {}
|
||||
|
||||
EventData(Handler handler, InMsgBuffer const &in_msg)
|
||||
: handler(handler), out_msgs(), in_msg(in_msg), trace(), ts() {}
|
||||
: handler(handler), out_msgs(), in_msg(in_msg), trace(), ts() {}
|
||||
|
||||
EventData(Handler handler, std::shared_ptr<std::string> const &ts)
|
||||
: handler(handler), out_msgs(), in_msg(), trace(), ts(ts) {}
|
||||
: handler(handler), out_msgs(), in_msg(), trace(), ts(ts) {}
|
||||
|
||||
EventData &operator=(EventData &src) {
|
||||
handler = src.handler;
|
||||
@@ -91,11 +91,11 @@ struct CoreGateway::PImpl {
|
||||
PImpl(config::JetFIX::Connection const &cfg, ICoreGatewayObserver &observer,
|
||||
ConnectionFactory const &conn_factory,
|
||||
StoreFactory const &store_factory, trace::PerfLog &l)
|
||||
: cfg(cfg), observer(observer), make_connection(conn_factory),
|
||||
make_store(store_factory), state(State::OFF), start_of_pause(),
|
||||
session_info(), event_queue(), timer_thread(), destroy(false),
|
||||
is_on(false), has_replayed(false), send_batch(), recv_batch(),
|
||||
connection_attempts(0), perf_log(l) {
|
||||
: cfg(cfg), observer(observer), make_connection(conn_factory),
|
||||
make_store(store_factory), state(State::OFF), start_of_pause(),
|
||||
session_info(), event_queue(), timer_thread(), destroy(false),
|
||||
is_on(false), has_replayed(false), send_batch(), recv_batch(),
|
||||
connection_attempts(0), perf_log(l) {
|
||||
send_batch.reserve(1024);
|
||||
recv_batch.reserve(1024);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ CoreGateway::CoreGateway(config::JetFIX::Connection const &cfg,
|
||||
ConnectionFactory const &conn_factory,
|
||||
StoreFactory const &store_factory,
|
||||
trace::PerfLog &perf_trace)
|
||||
: me(new PImpl(cfg, observer, conn_factory, store_factory, perf_trace)) {
|
||||
: me(new PImpl(cfg, observer, conn_factory, store_factory, perf_trace)) {
|
||||
me->timer_thread = make_timer_thread();
|
||||
}
|
||||
|
||||
@@ -148,6 +148,14 @@ void CoreGateway::send(OutFIXPtr const &fix, trace::CorID trace) {
|
||||
me->event_queue.push(EventData(&CoreGateway::sync_send, trace, fix));
|
||||
}
|
||||
|
||||
void CoreGateway::send_hb() {
|
||||
me->event_queue.push(EventData(&CoreGateway::sync_send_hb));
|
||||
}
|
||||
|
||||
void CoreGateway::send_test_request() {
|
||||
me->event_queue.push(EventData(&CoreGateway::sync_send_test_request));
|
||||
}
|
||||
|
||||
void CoreGateway::start() {
|
||||
me->event_queue.push(EventData(&CoreGateway::sync_start));
|
||||
}
|
||||
@@ -190,7 +198,7 @@ void CoreGateway::dispatch_events() {
|
||||
if (me->send_batch.size() || me->recv_batch.size()) {
|
||||
for (auto &ev : me->send_batch)
|
||||
(this->*ev.handler)(ev);
|
||||
for (auto &ev : me->recv_batch)
|
||||
for (auto &ev : me->recv_batch)
|
||||
(this->*ev.handler)(ev);
|
||||
me->send_batch.clear();
|
||||
me->recv_batch.clear();
|
||||
@@ -201,7 +209,7 @@ void CoreGateway::call_time() {
|
||||
while (!me->destroy) {
|
||||
std::this_thread::sleep_for(10ms);
|
||||
auto ts = std::make_shared<std::string>(
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
me->event_queue.push(EventData(&CoreGateway::sync_time, ts)); // NOLINT
|
||||
}
|
||||
}
|
||||
@@ -268,6 +276,42 @@ void CoreGateway::sync_send(EventData const &ev) {
|
||||
}
|
||||
}
|
||||
|
||||
void CoreGateway::sync_send_hb(EventData const &) {
|
||||
switch (me->state) {
|
||||
case State::OFF:
|
||||
bts_assert(false);
|
||||
break;
|
||||
case State::PAUSED:
|
||||
case State::CONNECTING:
|
||||
case State::WREADER_DISCONNECT:
|
||||
case State::WSESSION_TERMINATE:
|
||||
break;
|
||||
case State::READY:
|
||||
me->session_info->session->send_hb();
|
||||
break;
|
||||
default:
|
||||
bts_assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CoreGateway::sync_send_test_request(EventData const &) {
|
||||
switch (me->state) {
|
||||
case State::OFF:
|
||||
bts_assert(false);
|
||||
break;
|
||||
case State::PAUSED:
|
||||
case State::CONNECTING:
|
||||
case State::WREADER_DISCONNECT:
|
||||
case State::WSESSION_TERMINATE:
|
||||
break;
|
||||
case State::READY:
|
||||
me->session_info->session->send_test_request();
|
||||
break;
|
||||
default:
|
||||
bts_assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CoreGateway::sync_session_ready(EventData const &) {
|
||||
switch (me->state) {
|
||||
case State::OFF:
|
||||
@@ -399,8 +443,7 @@ void CoreGateway::sync_time(EventData const &ev) {
|
||||
|
||||
if (!me->has_replayed) {
|
||||
auto msgs_to_replay = me->session_info->store->replay();
|
||||
LOG(Jetfix, Warn, "Replaying {} FIX msgs",
|
||||
msgs_to_replay.size());
|
||||
LOG(Jetfix, Warn, "Replaying {} FIX msgs", msgs_to_replay.size());
|
||||
me->observer.replay(msgs_to_replay);
|
||||
me->has_replayed = true;
|
||||
}
|
||||
@@ -425,13 +468,13 @@ void CoreGateway::sync_time(EventData const &ev) {
|
||||
me->cfg.name());
|
||||
|
||||
me->session_info->session.reset(new Session(
|
||||
me->cfg, *me->session_info->connection,
|
||||
*me->session_info->store, *this,
|
||||
[]() { return utils::TimeStamp::now(); }, me->perf_log));
|
||||
me->cfg, *me->session_info->connection,
|
||||
*me->session_info->store, *this,
|
||||
[]() { return utils::TimeStamp::now(); }, me->perf_log));
|
||||
me->session_info->reader.reset(new AsyncReader(
|
||||
*me->session_info->connection, me->cfg.name(), *this,
|
||||
me->perf_log, me->cfg.msg_buffer_sz(),
|
||||
me->cfg.msg_high_water_mark()));
|
||||
*me->session_info->connection, me->cfg.name(), *this,
|
||||
me->perf_log, me->cfg.msg_buffer_sz(),
|
||||
me->cfg.msg_high_water_mark()));
|
||||
me->session_info->reader->start();
|
||||
me->session_info->session->start();
|
||||
transition(State::CONNECTING);
|
||||
|
||||
@@ -35,6 +35,10 @@ public:
|
||||
void send (OutFIXPtr const &msgs, trace::CorID trace);
|
||||
void dispatch_events ();
|
||||
|
||||
// for certification use only
|
||||
void send_hb ();
|
||||
void send_test_request ();
|
||||
|
||||
private:
|
||||
enum class State;
|
||||
struct SessionInfo;
|
||||
@@ -52,6 +56,8 @@ private:
|
||||
void sync_start (EventData const &);
|
||||
void sync_stop (EventData const &);
|
||||
void sync_send (EventData const &);
|
||||
void sync_send_hb (EventData const&);
|
||||
void sync_send_test_request (EventData const&);
|
||||
void sync_session_ready (EventData const&) ;
|
||||
void sync_session_terminated (EventData const&);
|
||||
void sync_reader_disconnected (EventData const&) ;
|
||||
|
||||
@@ -67,6 +67,10 @@ public:
|
||||
DispatcherTuple>::value> (_dispatchers).handler;
|
||||
}
|
||||
|
||||
// for CERT purposes
|
||||
void send_hb () {_core.send_hb ();}
|
||||
void send_test_request () {_core.send_test_request ();}
|
||||
|
||||
private:
|
||||
struct IDispatcher
|
||||
{
|
||||
|
||||
@@ -830,8 +830,8 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
buffer.add<EncodedTextLen>(ld.access_key.size());
|
||||
buffer.add<EncodedText>(ld.access_key);
|
||||
buffer.add<EncryptedPasswordMethod>("CME-1-SHA-256");
|
||||
buffer.add<EncryptedPasswordLen>(ld.signature_base64.size());
|
||||
buffer.add<EncryptedPassword>(ld.signature_base64);
|
||||
buffer.add<EncryptedPasswordLen>(ld.signature.size());
|
||||
buffer.add<EncryptedPassword>(ld.signature);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
class InMsgBuffer;
|
||||
|
||||
class IFIXStore
|
||||
|
||||
@@ -5,204 +5,136 @@
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
boost::gregorian::greg_weekday parse_weekday(std::string weekday_str) {
|
||||
boost::to_lower(weekday_str);
|
||||
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str)
|
||||
{
|
||||
boost::to_lower (weekday_str);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
auto gw_day = boost::gregorian::greg_weekday(i);
|
||||
auto prefix = std::string(gw_day.as_short_string());
|
||||
boost::to_lower(prefix);
|
||||
if (weekday_str.find(prefix) == 0)
|
||||
auto gw_day = boost::gregorian::greg_weekday (i);
|
||||
auto prefix = std::string (gw_day.as_short_string ());
|
||||
boost::to_lower (prefix);
|
||||
if (weekday_str.find (prefix) == 0)
|
||||
return gw_day;
|
||||
}
|
||||
bts_assert(false);
|
||||
return boost::gregorian::greg_weekday(0);
|
||||
bts_assert (false);
|
||||
return boost::gregorian::greg_weekday (0);
|
||||
}
|
||||
|
||||
boost::posix_time::time_duration parse_time(std::string const &time_str) {
|
||||
boost::posix_time::time_duration parse_time (std::string const &time_str)
|
||||
{
|
||||
try {
|
||||
return boost::posix_time::duration_from_string(time_str);
|
||||
} catch (boost::bad_lexical_cast &) {
|
||||
bts_assert(false);
|
||||
return boost::posix_time::time_duration();
|
||||
return boost::posix_time::duration_from_string (time_str);
|
||||
}
|
||||
catch (boost::bad_lexical_cast &)
|
||||
{
|
||||
bts_assert (false);
|
||||
return boost::posix_time::time_duration ();
|
||||
}
|
||||
}
|
||||
|
||||
datetime::PTime closest_before(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day) {
|
||||
if (ref_date.date().day_of_week() == weekday) {
|
||||
if (time_of_day < ref_date.time_of_day())
|
||||
return datetime::PTime(ref_date.date(), time_of_day);
|
||||
datetime::PTime closest_before (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day)
|
||||
{
|
||||
if (ref_date.date ().day_of_week () == weekday) {
|
||||
if (time_of_day < ref_date.time_of_day ())
|
||||
return datetime::PTime (ref_date.date (),time_of_day);
|
||||
else {
|
||||
return datetime::PTime(
|
||||
ref_date.date() - boost::gregorian::date_duration(7), time_of_day);
|
||||
return datetime::PTime (ref_date.date () - boost::gregorian::date_duration (7),
|
||||
time_of_day);
|
||||
}
|
||||
} else {
|
||||
auto distance =
|
||||
ref_date.date().day_of_week().as_number() - weekday.as_number();
|
||||
ref_date.date ().day_of_week ().as_number () -
|
||||
weekday.as_number ();
|
||||
if (distance < 0)
|
||||
distance += 7;
|
||||
return datetime::PTime(ref_date.date() -
|
||||
boost::gregorian::date_duration(distance),
|
||||
time_of_day);
|
||||
return datetime::PTime (ref_date.date () - boost::gregorian::date_duration (distance),
|
||||
time_of_day);
|
||||
}
|
||||
}
|
||||
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
auto t = ref_date.time_of_day();
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
auto t = ref_date.time_of_day ();
|
||||
if (time_of_day_start < time_of_day_end)
|
||||
return t >= time_of_day_start && t <= time_of_day_end;
|
||||
else
|
||||
return t >= time_of_day_start || t <= time_of_day_end;
|
||||
}
|
||||
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
auto closest_earlier_start =
|
||||
closest_before(ref_date, weekday_start, time_of_day_start);
|
||||
auto closest_earlier_end =
|
||||
closest_before(ref_date, weekday_end, time_of_day_end);
|
||||
return closest_earlier_end < closest_earlier_start;
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
auto closest_earlier_start = closest_before (ref_date,weekday_start,time_of_day_start);
|
||||
auto closest_earlier_end = closest_before (ref_date,weekday_end,time_of_day_end);
|
||||
return closest_earlier_end<closest_earlier_start;
|
||||
}
|
||||
|
||||
SessionName
|
||||
session_name_from_ptime(datetime::PTime t,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
std::string result(10, ' ');
|
||||
std::string session_name_from_ptime (datetime::PTime t,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
std::string result (10,' ');
|
||||
auto start_of_session = t;
|
||||
|
||||
if (time_of_day_start > time_of_day_end &&
|
||||
start_of_session.time_of_day() <= time_of_day_end)
|
||||
start_of_session -= boost::gregorian::date_duration(1);
|
||||
|
||||
sprintf(&result[0], "%04d-%02d-%02d",
|
||||
(unsigned short)start_of_session.date().year(),
|
||||
start_of_session.date().month().as_number(),
|
||||
start_of_session.date().day().as_number());
|
||||
return {result,t};
|
||||
}
|
||||
|
||||
std::optional<SessionName> session_name(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
if (in_session(ref_date, weekday_start, time_of_day_start, weekday_end,
|
||||
time_of_day_end))
|
||||
return session_name_from_ptime(
|
||||
closest_before(ref_date, weekday_start, time_of_day_start),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 1));
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<SessionName> session_name(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
if (in_session(ref_date, time_of_day_start, time_of_day_end))
|
||||
return session_name_from_ptime(ref_date, time_of_day_start,
|
||||
time_of_day_end);
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<SessionName> session_name(config::JetFIX::Connection const &session_cfg) {
|
||||
auto now = datetime::local_now();
|
||||
|
||||
if (session_cfg.has_start_day()) {
|
||||
bts_assert(session_cfg.has_end_day());
|
||||
return session_name(now, parse_weekday(session_cfg.start_day()),
|
||||
parse_time(session_cfg.start_time()),
|
||||
parse_weekday(session_cfg.end_day()),
|
||||
parse_time(session_cfg.end_time()));
|
||||
} else
|
||||
return session_name(now, parse_time(session_cfg.start_time()),
|
||||
parse_time(session_cfg.end_time()));
|
||||
}
|
||||
|
||||
SessionSpan session_span(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
auto one_week = boost::gregorian::date_duration(7);
|
||||
auto closest_earlier_start =
|
||||
closest_before(ref_date, weekday_start, time_of_day_start);
|
||||
auto closest_earlier_end =
|
||||
closest_before(ref_date, weekday_end, time_of_day_end);
|
||||
if (closest_earlier_end < closest_earlier_start)
|
||||
// we are in the session
|
||||
return {closest_earlier_start, closest_earlier_end + one_week };
|
||||
else
|
||||
// need to wait for the next session
|
||||
return {closest_earlier_start+one_week, closest_earlier_end + one_week };
|
||||
}
|
||||
|
||||
SessionSpan session_span(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end) {
|
||||
auto t = ref_date.time_of_day();
|
||||
auto today = ref_date.date() ;
|
||||
auto tomorrow = today + boost::gregorian::date_duration(1) ;
|
||||
auto yesterday = today - boost::gregorian::date_duration(1) ;
|
||||
|
||||
if (time_of_day_start < time_of_day_end) {
|
||||
// scheduled start/scheduled end do not span midnight
|
||||
|
||||
if (t <= time_of_day_end) {
|
||||
// we are inside the schedule
|
||||
return {
|
||||
datetime::PTime(today,time_of_day_start),
|
||||
datetime::PTime(today,time_of_day_end)
|
||||
};
|
||||
}
|
||||
else {
|
||||
// too late for today, tomorrow is the time for the session
|
||||
return {
|
||||
datetime::PTime(tomorrow,time_of_day_start),
|
||||
datetime::PTime(tomorrow,time_of_day_end)
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// the start/stop span over midnight
|
||||
|
||||
if (t <= time_of_day_end) {
|
||||
// we are inside the the schedule
|
||||
return {
|
||||
datetime::PTime(yesterday,time_of_day_start),
|
||||
datetime::PTime(today,time_of_day_end)
|
||||
};
|
||||
}
|
||||
else {
|
||||
// too late, skip to next session
|
||||
return {
|
||||
datetime::PTime(today,time_of_day_start),
|
||||
datetime::PTime(tomorrow,time_of_day_end)
|
||||
};
|
||||
}
|
||||
}
|
||||
if (time_of_day_start > time_of_day_end &&
|
||||
start_of_session.time_of_day () <= time_of_day_end)
|
||||
start_of_session -= boost::gregorian::date_duration (1);
|
||||
|
||||
sprintf (&result[0], "%04d-%02d-%02d",
|
||||
(unsigned short) start_of_session.date ().year (),
|
||||
start_of_session.date ().month ().as_number (),
|
||||
start_of_session.date ().day ().as_number ());
|
||||
return result;
|
||||
}
|
||||
|
||||
SessionSpan session_span(config::JetFIX::Connection const &session_cfg) {
|
||||
auto now = datetime::local_now();
|
||||
|
||||
if (session_cfg.has_start_day()) {
|
||||
bts_assert(session_cfg.has_end_day());
|
||||
return session_span(now, parse_weekday(session_cfg.start_day()),
|
||||
parse_time(session_cfg.start_time()),
|
||||
parse_weekday(session_cfg.end_day()),
|
||||
parse_time(session_cfg.end_time()));
|
||||
} else
|
||||
return session_span(now, parse_time(session_cfg.start_time()),
|
||||
parse_time(session_cfg.end_time()));
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,weekday_start,time_of_day_start,weekday_end,time_of_day_end))
|
||||
return session_name_from_ptime (closest_before (ref_date,weekday_start,time_of_day_start),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 1));
|
||||
else
|
||||
return std::string ();
|
||||
}
|
||||
|
||||
} // namespace jetfix
|
||||
} // namespace bts
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,time_of_day_start,time_of_day_end))
|
||||
return session_name_from_ptime (ref_date, time_of_day_start, time_of_day_end);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg)
|
||||
{
|
||||
auto now = datetime::local_now ();
|
||||
|
||||
if (session_cfg.has_start_day ()) {
|
||||
bts_assert (session_cfg.has_end_day ());
|
||||
return session_name (now,
|
||||
parse_weekday (session_cfg.start_day ()),
|
||||
parse_time (session_cfg.start_time ()),
|
||||
parse_weekday (session_cfg.end_day ()),
|
||||
parse_time (session_cfg.end_time ()));
|
||||
} else
|
||||
return session_name (now,
|
||||
parse_time (session_cfg.start_time ()),
|
||||
parse_time (session_cfg.end_time ()));
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <string>
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace boost {
|
||||
namespace gregorian {
|
||||
@@ -19,11 +17,6 @@ class time_duration;
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
struct SessionName {
|
||||
std::string name;
|
||||
datetime::PTime time;
|
||||
};
|
||||
|
||||
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str);
|
||||
bool parse_time (std::string const &time_str,boost::posix_time::time_duration *out);
|
||||
|
||||
@@ -41,22 +34,16 @@ bool in_session (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
std::optional<SessionName> session_name (datetime::PTime const &ref_date,
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
std::optional<SessionName> session_name (datetime::PTime const &ref_date,
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
std::optional<SessionName> session_name (config::JetFIX::Connection const &session_cfg);
|
||||
|
||||
struct SessionSpan {
|
||||
datetime::PTime start;
|
||||
datetime::PTime stop;
|
||||
};
|
||||
SessionSpan session_span(config::JetFIX::Connection const&session_cfg);
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg);
|
||||
|
||||
}}
|
||||
@@ -120,7 +120,6 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
|
||||
{log::Plugin,"Plugin"},
|
||||
{log::ClientSdk,"ClientSdk"},
|
||||
{log::Http,"Http"},
|
||||
{log::OrderMan2,"OrderMan2"},
|
||||
};
|
||||
|
||||
real_cfg.sinks["console"] =
|
||||
|
||||
@@ -24,8 +24,7 @@ constexpr log::Level Sys {log::Level::Max-1};
|
||||
|
||||
namespace log {
|
||||
|
||||
// Please keep this list in sync with Log.cs and make sure
|
||||
// to replicate the change in logging.cpp
|
||||
// Please keep this list in sync with Log.cs
|
||||
constexpr log::Subsystem Gen {0 };
|
||||
constexpr log::Subsystem Cfg {Gen.ordinal+1 };
|
||||
constexpr log::Subsystem QBus {Cfg.ordinal+1 };
|
||||
@@ -47,7 +46,6 @@ constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
|
||||
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
|
||||
constexpr log::Subsystem ClientSdk {Plugin.ordinal+1 };
|
||||
constexpr log::Subsystem Http {ClientSdk.ordinal+1 };
|
||||
constexpr log::Subsystem OrderMan2 {Http.ordinal+1 };
|
||||
|
||||
struct LoggerHandle {
|
||||
LoggerHandle(LoggerHandle const&) = delete;
|
||||
|
||||
@@ -80,9 +80,9 @@ class BrokerProxy : public ILocalBroker {
|
||||
send(m);
|
||||
}
|
||||
|
||||
void do_work(trace::PerfLog& ) {
|
||||
void do_work(trace::PerfLog& log) {
|
||||
_cycles++;
|
||||
_outgoing.consume_all([this](BrokerMsg *m) {
|
||||
_outgoing.consume_all([this,&log](BrokerMsg *m) {
|
||||
switch (m->msg_type) {
|
||||
case BrokerMsgType::ADD_NEIGHBOUR:
|
||||
_real_broker.add_neighbour(*m->neighbour);
|
||||
@@ -102,9 +102,13 @@ class BrokerProxy : public ILocalBroker {
|
||||
case BrokerMsgType::UNSUBSCRIBE:
|
||||
_real_broker.unsubscribe(m->broker_id, m->sub_id, m->stream_id);
|
||||
break;
|
||||
case BrokerMsgType::NOTIFY:
|
||||
case BrokerMsgType::NOTIFY: {
|
||||
LOG(Latency, Diag, "Notify broker {}. Cycles: {}", _id.value(),
|
||||
_cycles);
|
||||
auto scoped_do_work = trace::log_scope(log, {}, "BrokerProxy::notify");
|
||||
_real_broker.notify(m->broker_id, m->stream_id, m->sub_id,
|
||||
m->notification);
|
||||
}
|
||||
break;
|
||||
case BrokerMsgType::LOCAL_SUBSCRIBE:
|
||||
_real_broker.local_subscribe(m->local_sub_id, m->filter,
|
||||
|
||||
@@ -1,38 +1,45 @@
|
||||
#include "lib/mercury/executor/Executor.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/mercury/actors/IPollableActor.h"
|
||||
#include "lib/mercury/broker/Broker.h"
|
||||
#include "lib/mercury/broker/BrokerProxy.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/mercury/actors/IPollableActor.h"
|
||||
|
||||
namespace bts {
|
||||
namespace mercury {
|
||||
|
||||
Executor::Executor()
|
||||
: _broker(), _incoming_proxies(), _my_proxy(make_proxy()),
|
||||
_actor_broker(_my_proxy), _actors() {}
|
||||
Executor::Executor() :
|
||||
_broker(),
|
||||
_incoming_proxies(),
|
||||
_my_proxy(make_proxy()),
|
||||
_actor_broker(_my_proxy),
|
||||
_actors() {}
|
||||
|
||||
Executor::~Executor() {
|
||||
for (auto &a : _actors)
|
||||
a->deactivate();
|
||||
}
|
||||
|
||||
void Executor::init_neighbours(std::vector<Executor *> const &neighbours) {
|
||||
|
||||
void Executor::init_neighbours(std::vector<Executor*> const&neighbours)
|
||||
{
|
||||
for (auto e : neighbours)
|
||||
if (e != this)
|
||||
if (e != this)
|
||||
_outgoing_proxies.push_back(&e->make_proxy());
|
||||
for (auto n : _outgoing_proxies)
|
||||
_broker.add_neighbour(*n);
|
||||
}
|
||||
|
||||
void Executor::activate(Actor *actor) {
|
||||
_actors.push_back(std::unique_ptr<Actor>(actor));
|
||||
auto pollable = dynamic_cast<IPollableActor *>(actor);
|
||||
|
||||
void Executor::activate(Actor *actor)
|
||||
{
|
||||
_actors.push_back(std::unique_ptr<Actor> (actor));
|
||||
auto pollable = dynamic_cast<IPollableActor*> (actor);
|
||||
if (pollable)
|
||||
_pollable_actors.push_back(pollable);
|
||||
actor->activate(_actor_broker);
|
||||
}
|
||||
actor->activate(_actor_broker);}
|
||||
|
||||
|
||||
BrokerProxy &Executor::make_proxy() {
|
||||
BrokerProxy& Executor::make_proxy()
|
||||
{
|
||||
_incoming_proxies.push_back(std::make_unique<BrokerProxy>(_broker));
|
||||
return *_incoming_proxies.back();
|
||||
}
|
||||
|
||||
@@ -262,6 +262,10 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
if (msg.has<fix::ExecID>())
|
||||
str_to(msg.get<fix::ExecID>(), &data->exchange_fill_id);
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &data->transact_time);
|
||||
|
||||
if (msg.has<fix::CustOrderHandlingInst>())
|
||||
data->cust_order_handling_inst = msg.get<fix::CustOrderHandlingInst>();
|
||||
|
||||
data->cfg = &me->cfg;
|
||||
data->msg = text_msg;
|
||||
data->exchange = api::Venue::VENUE_GLBX;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "lib/md/cme/MDP3Utils.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/mercury/actors/IPollableActor.h"
|
||||
#include "lib/mercury/events/TimerEvent.h"
|
||||
#include "lib/orderman/events/BookUpdateEvent.h"
|
||||
#include "lib/orderman/events/MDRequestEvent.h"
|
||||
#include "lib/orderman/events/TickerUpdateEvent.h"
|
||||
@@ -24,8 +25,7 @@ namespace orderman {
|
||||
// polls a md consumer and publishes BookUpdate events when new MD is
|
||||
// available. To avoid the overhead of maintaing synopsis as well as
|
||||
// polling only relevant MD, observes a MDRequestEvent and limits
|
||||
// updates to requested securities. Also provides trade and security
|
||||
// status events in a similar on demand fashion.
|
||||
// updates to requested securities.
|
||||
|
||||
class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
public:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/orderman/events/StoredFillEvent.h"
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
@@ -42,7 +42,7 @@ class DynamicOrderRegistry;
|
||||
} // namespace bts
|
||||
// end fwds
|
||||
|
||||
// Provides a threading bridge between the quickbus/service world and
|
||||
// Provides a threading bridge between the quickbux/service world and
|
||||
// the mercury event broker.
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "lib/orderman/actors/order_manager/OrderServices.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderServicesData.h"
|
||||
#include "lib/orderman/events/AccountPnLUpdateEvent.h"
|
||||
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
|
||||
#include "lib/orderman/events/FilledPositionEvent.h"
|
||||
#include "lib/orderman/events/ExcessLiquidityUpdateEvent.h"
|
||||
#include "lib/orderman/events/NewAdminDataEvent.h"
|
||||
#include "lib/orderman/events/NewSecuritiesEvent.h"
|
||||
#include "lib/orderman/events/OrderManagerReadyEvent.h"
|
||||
@@ -111,8 +111,7 @@ void OrderManager::on_excess_liquidity_update(
|
||||
const mercury::Update<ExcessLiquidityUpdateEvent> &u) {
|
||||
if (u.events)
|
||||
for (auto ev : *u.events)
|
||||
me->services_data.limiter.set_excess_liquidity(ev.account_id,
|
||||
ev.excess_liquidity);
|
||||
me->services_data.limiter.set_excess_liquidity(ev.account_id, ev.excess_liquidity);
|
||||
}
|
||||
|
||||
void OrderManager::on_securities(
|
||||
@@ -542,7 +541,7 @@ void OrderManager::init_order_services() {
|
||||
std::make_unique<ContentSubscription<TickerUpdateEvent>>(
|
||||
*this, on_ticker_sub, log);
|
||||
me->services_data.status_subs =
|
||||
std::make_unique<ContentSubscription<StatusUpdateEvent>>(
|
||||
std::make_unique<ContentSubscription<StatusUpdateEvent>>(
|
||||
*this, on_status_sub, log);
|
||||
me->services_data.settlement_subs =
|
||||
std::make_unique<ContentSubscription<SettlementUpdateEvent>>(
|
||||
@@ -582,7 +581,10 @@ void OrderManager::reload_fix_buffer(SessionServicesData &osd) {
|
||||
}
|
||||
}
|
||||
|
||||
void OrderManager::on_poll(trace::PerfLog &) {
|
||||
void OrderManager::on_poll(trace::PerfLog &log) {
|
||||
auto scoped_do_work =
|
||||
trace::log_scope(log, {}, "OrderManager::dispatch_incoming_fix_messages",
|
||||
utils::TimeStamp::Interval::from_microseconds(2));
|
||||
for (auto &osd : me->services_data.sessions)
|
||||
osd->gw->dispatch_incoming_fix_messages();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/jetfix/common/OutFIXPtr.h"
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
#include "lib/mercury/actors/Actor.h"
|
||||
#include "lib/mercury/actors/IPollableActor.h"
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
#include "lib/orderman/events/ActivateOrderEvent.h"
|
||||
#include "lib/orderman/events/CancelOrderEvent.h"
|
||||
#include "lib/orderman/events/DetachOrderEvent.h"
|
||||
@@ -64,9 +64,8 @@ namespace orderman {
|
||||
|
||||
class OrderManager : public mercury::Actor, public mercury::IPollableActor {
|
||||
public:
|
||||
OrderManager(DynamicOrderRegistry const &, trace::PerfLog &,
|
||||
md::SecurityOracle);
|
||||
|
||||
OrderManager(DynamicOrderRegistry const &dyn_order_builder, trace::PerfLog &, md::SecurityOracle);
|
||||
|
||||
~OrderManager();
|
||||
void init() override;
|
||||
|
||||
@@ -87,9 +86,8 @@ class OrderManager : public mercury::Actor, public mercury::IPollableActor {
|
||||
void on_timer(const mercury::Update<mercury::TimerEvent> &);
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &);
|
||||
void on_pnl_update(const mercury::Update<AccountPnLUpdateEvent> &);
|
||||
void on_excess_liquidity_update(
|
||||
const mercury::Update<ExcessLiquidityUpdateEvent> &);
|
||||
void on_poll(trace::PerfLog &log) override;
|
||||
void on_excess_liquidity_update(const mercury::Update<ExcessLiquidityUpdateEvent> &);
|
||||
void on_poll(trace::PerfLog& log) override;
|
||||
// end external events
|
||||
|
||||
void init_order_services();
|
||||
@@ -99,8 +97,8 @@ class OrderManager : public mercury::Actor, public mercury::IPollableActor {
|
||||
void after_event() override;
|
||||
|
||||
void add_child_order(OrderServices &parent, Order &child);
|
||||
Order *lookup_order(OrderKey k);
|
||||
|
||||
Order* lookup_order(OrderKey k);
|
||||
|
||||
void publish_order_def_update(
|
||||
OrderKey k,
|
||||
std::shared_ptr<api::orderman::OrderDefinition const> const &def);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
** Attach/Detach semantics
|
||||
*** Semantics
|
||||
- An order base definition can include a list of running orders to attach
|
||||
to
|
||||
- Each custom definition can have parameters that allow configuration
|
||||
of the specific order type with respect to the attachment
|
||||
list. Obvious configuration alternatives are:
|
||||
- Attach to each of the listed orders directly or
|
||||
- Forward attachment list to children
|
||||
- Only orders with no parent or parents in a terminal state can be
|
||||
attached to
|
||||
- a detach(order_key) message can be sent to any order, even if that
|
||||
order was not started through attachment to an existing order. the
|
||||
expected semantics is for the order in question to stop managing the
|
||||
child order and transition to completed.
|
||||
|
||||
*** API
|
||||
- IOrderServices:
|
||||
- attach_to_order(ok, std::function<void(Result,ChildOrder)>
|
||||
on_attach_complete);
|
||||
- detach(ChildOrder)
|
||||
- Order
|
||||
- on_detach(order_key)
|
||||
- on_attached();
|
||||
- on_detached();
|
||||
message OrderDefinition {
|
||||
CTICode cti_code = 9;
|
||||
l CUSTOMERORFIRM customer_or_firm = 10;
|
||||
OrderSubType sub_type = 12;
|
||||
+ repeated uint32 attach_to_order = 13;
|
||||
CustomOrderDefinition custom_def = 11;
|
||||
}
|
||||
* Order fields
|
||||
| Field | Group | Muttable | on_attach |
|
||||
|------------------------+--------------+----------+-------------|
|
||||
| security_key | standard def | N | from child |
|
||||
| side | | N | from child |
|
||||
| user | | N | from parent |
|
||||
| user_id | | Y | from parent |
|
||||
| account | | Y | from parent |
|
||||
| account_id | | Y | from parent |
|
||||
| time_in_force | | N | from child |
|
||||
| manual_order_indicator | | Y | from parent |
|
||||
| cti_code | | N | from child |
|
||||
| customer_or_firm | | N | from child |
|
||||
| sub_type | | N | |
|
||||
| attach_order | | N | |
|
||||
|------------------------+--------------+----------+-------------|
|
||||
| custom_def | custom_def | Y | from child |
|
||||
| | | | |
|
||||
|------------------------+--------------+----------+-------------|
|
||||
| key | order_record | N | |
|
||||
| parent_key | | Y | from parent |
|
||||
|------------------------+--------------+----------+-------------|
|
||||
| status | order_state | Y | |
|
||||
| price | | Y | |
|
||||
| quantity | | Y | |
|
||||
| filled_quantity | | Y | |
|
||||
| last_price | | Y | |
|
||||
| avg_price | | Y | |
|
||||
| last_msg | | Y | |
|
||||
| created | | Y | |
|
||||
| last_change | | Y | |
|
||||
| custom_state | custom_state | Y | |
|
||||
|
||||
Binary file not shown.
+75
-42
@@ -5,22 +5,9 @@
|
||||
| completed | O | | | |
|
||||
| canceled | canceled | | | |
|
||||
| error | X | | | |
|
||||
| disconnected | | | | |
|
||||
| disconnected | | | | |
|
||||
| rejected by spark | X | | | |
|
||||
* References
|
||||
** Timmings
|
||||
| thing | cost | note |
|
||||
|-------------------------+------+----------------------|
|
||||
| lock/unlock | 8 | test_and_set |
|
||||
| shared_ptr cpy | 14 | |
|
||||
| binary_search_int64/8 | 7 | |
|
||||
| binary_search_int64/512 | 13 | |
|
||||
| mem_copy/8 | 5 | |
|
||||
| mem_copy/64 | 5 | |
|
||||
| mem_copy/512 | 14 | |
|
||||
| new/delete | 58 | |
|
||||
| boost pool new/delete | 2 | no synchronizatio |
|
||||
| boost pool new/delete | 19 | with synchronization |
|
||||
** To Exchange
|
||||
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/New+Order][NewOrderSingle]]
|
||||
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Order%2BCancel-Replace%2BRequest][CancelReplace]]
|
||||
@@ -35,8 +22,8 @@
|
||||
- Trade Correction
|
||||
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Execution+Report+-+Trade+Correction][Msg]]
|
||||
- [[https://www.cmegroup.com/confluence/display/EPICSANDBOX/Execution+Report+-+Trade+Correction][Discussion]]
|
||||
** Order Chain trace
|
||||
*** NewOrder
|
||||
* Order Chain trace
|
||||
** NewOrder
|
||||
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
BodyLength = 271 9=271
|
||||
@@ -108,7 +95,7 @@ ExpireDate = 20161102 432=20161102
|
||||
5979 = 1478119007620967425 5979=1478119007620967425
|
||||
7928 = 8056218 7928=8056218
|
||||
CheckSum = 038 10=038
|
||||
*** Cancel
|
||||
** Cancel
|
||||
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
BodyLength = 327 9=327
|
||||
@@ -182,7 +169,7 @@ ExpireDate = 20161102 432=20161102
|
||||
7928 = 8056218 7928=8056218
|
||||
9717 = 2KjMkw-1C22h9-001v8Q 9717=2KjMkw-1C22h9-001v8Q
|
||||
CheckSum = 033 10=033
|
||||
*** Cancel/Replace
|
||||
** Cancel/Replace
|
||||
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
BodyLength = 344 9=344
|
||||
@@ -260,7 +247,7 @@ ExpireDate = 20161102 432=20161102
|
||||
9717 = 2KjMkw-1C22gp-001v8P 9717=2KjMkw-1C22gp-001v8P
|
||||
CheckSum = 151 10=151
|
||||
|
||||
*** Trade Correction
|
||||
** Trade Correction
|
||||
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
BodyLength = 000234 9=000234
|
||||
@@ -414,7 +401,35 @@ CheckSum = 207 10=207
|
||||
37711 = MDTradeEntryID
|
||||
ExecRefID
|
||||
|
||||
** Notes on "A guide to spread trading futures"
|
||||
* Open Issues
|
||||
- Re-Connection is done on the fast thread, slowing everything down
|
||||
- Need to make sure there are no duplicate order state update events
|
||||
- Once we have multiple OM's we will need to guarantee that they can
|
||||
see each others order, which means we need to use some sort of
|
||||
synopsis or other mechanism to ensure that they are synchronized
|
||||
- fill mitigation
|
||||
- should cancel on disconnect be on
|
||||
- handling of reject
|
||||
- garbage collection of orders
|
||||
- garbage collection of fills
|
||||
- consider including restatement reason
|
||||
- see if handling of cancel rejects is any good
|
||||
- impossible to shutdown orderservice at the moment
|
||||
* Timmings
|
||||
- 10.96.25.35
|
||||
| thing | cost | note |
|
||||
|-------------------------+------+----------------------|
|
||||
| lock/unlock | 8 | test_and_set |
|
||||
| shared_ptr cpy | 14 | |
|
||||
| binary_search_int64/8 | 7 | |
|
||||
| binary_search_int64/512 | 13 | |
|
||||
| mem_copy/8 | 5 | |
|
||||
| mem_copy/64 | 5 | |
|
||||
| mem_copy/512 | 14 | |
|
||||
| new/delete | 58 | |
|
||||
| boost pool new/delete | 2 | no synchronizatio |
|
||||
| boost pool new/delete | 19 | with synchronization |
|
||||
* Notes on "A guide to spread trading futures"
|
||||
- Correlations are discovered by traders
|
||||
- Spread trading exploits correlations between securities and mean
|
||||
reversion
|
||||
@@ -456,28 +471,47 @@ ExecRefID
|
||||
- Strategies
|
||||
- Mean Reversion
|
||||
|
||||
* Open Issues
|
||||
- Re-Connection is done on the fast thread, slowing everything down
|
||||
- Need to make sure there are no duplicate order state update events
|
||||
- Once we have multiple OM's we will need to guarantee that they can
|
||||
see each others order, which means we need to use some sort of
|
||||
synopsis or other mechanism to ensure that they are synchronized
|
||||
- consider including restatement reason
|
||||
- see if handling of cancel rejects is any good
|
||||
- impossible to shutdown orderservice at the moment
|
||||
* Event Flow
|
||||
| | MDSource | OManager | Timer | AsyncF | OrderStore | FillStore | SecSrc | MdSup | Bridge |
|
||||
|------------+----------+----------+-------+--------+------------+-----------+--------+-------+--------|
|
||||
| MSource | | | | | | | | | |
|
||||
| OManager | | | | | | | | | |
|
||||
| Timer | | | | | | | | | |
|
||||
| AsyncF | | | | | | | | | |
|
||||
| OrderStore | | | | | | | | | |
|
||||
| FillStore | | | | | | | | | |
|
||||
| SecSrc | | | | | | | | | |
|
||||
| MdSup | | | | | | | | | |
|
||||
| Bridge | | | | | | | | | |
|
||||
|------------+----------+----------+-------+--------+------------+-----------+--------+-------+--------|
|
||||
#+begin_src dot :file event_flow.pdf :cmdline -Kdot -Tpdf
|
||||
digraph G {
|
||||
bgcolor="transparent";
|
||||
|
||||
subgraph cluster_fast {
|
||||
label="Fast Core";
|
||||
GW
|
||||
OMan
|
||||
MDSrc
|
||||
}
|
||||
|
||||
subgraph cluster_slow {
|
||||
label="Slow Core";
|
||||
FillStore
|
||||
SecSrc
|
||||
UI
|
||||
OrderStore
|
||||
Factory
|
||||
}
|
||||
|
||||
OMan -> Factory [label=req]
|
||||
Factory -> OMan [label=rep]
|
||||
SecSrc -> GW [label=psec]
|
||||
SecSrc -> OrderStore [label=psec]
|
||||
SecSrc -> OMan [label=psec]
|
||||
GW -> FillStore [label=xmsgs]
|
||||
GW -> OMan [label=xmsgs]
|
||||
OMan -> GW [label=fix]
|
||||
OMan -> OrderStore [label=oupdate]
|
||||
OrderStore -> OMan [label=rec_orders]
|
||||
OrderStore -> UI [label=orecs]
|
||||
FillStore-> UI [label=frecs]
|
||||
UI -> OMan [label="crud"]
|
||||
MDSrc -> OMan [label="md"]
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
[[file:event_flow.pdf]]
|
||||
|
||||
* Better event broker:
|
||||
** unbundle events from topics and synopsis.
|
||||
- develop Channels = Channel<Event,Tag,Synopsis>
|
||||
@@ -526,4 +560,3 @@ ExecRefID
|
||||
- Recovery from disk
|
||||
- Jetfix gateway threading model is wrong, cannot take one thread for
|
||||
each session
|
||||
* Rewrite <2019-09-23 Mon>
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "lib/mercury/events/Event.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/tracing/PerfLog.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class DetachOrderEvent : public mercury::Event<DetachOrderEvent> {
|
||||
public:
|
||||
using SynopsisPolicy = mercury::NoSynopsis;
|
||||
|
||||
DetachOrderEvent(uint32_t req_id, OrderKey k)
|
||||
: req_id(req_id), k(k) {}
|
||||
|
||||
uint32_t req_id;
|
||||
// used by ContentSubscription
|
||||
OrderKey key() const { return k; }
|
||||
OrderKey k;
|
||||
};
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
Loaded 100 of 325 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user