diff --git a/.vscode/launch.json b/.vscode/launch.json
index 71b5a8e9e..fac8a7668 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -249,7 +249,7 @@
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
"args": [
"test",
- "[mbo]"
+ "SingleWriterConcurrentVector"
],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/server/",
diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md
index 0e98e18bd..b9af27f2d 100644
--- a/doc/user/content/release_notes/_index.md
+++ b/doc/user/content/release_notes/_index.md
@@ -4,6 +4,20 @@ weight = 3
sort_by = "weight"
insert_anchor_links = "right"
+++
+## 2.0.5
+### User Visible Changes
+ - Fixed a bug in the handling of rejected QHO orders
+ - Implemented stricter position limit enforcement
+ - Fixed a bug that could cause server failure when trying to attach to already attached orders
+
+## 2.0.4
+### User Visible Changes
+ - Fixed performance regression in order manager
+
+### Internal changes
+ - Improved market data diagnostics for bad configurations
+ - Changed market data default buffer size
+
## 2.0.3
### Internal changes
- Improved backwards compatibility in UI settings
diff --git a/src/client/spark/Images/Icons.cs b/src/client/spark/Images/Icons.cs
index 1d730b6ee..dcc11df03 100644
--- a/src/client/spark/Images/Icons.cs
+++ b/src/client/spark/Images/Icons.cs
@@ -24,10 +24,12 @@ namespace mbts.ui {
AddFileThinGeometryKey = nameof(AddFileThinGeometryKey),
AttachAlgosKey = nameof(AttachAlgosKey),
CheckMarkGeometryKey = nameof(CheckMarkGeometryKey),
+ DataEditGeometryKey = nameof(DataEditGeometryKey),
DetachAlgosKey = nameof(DetachAlgosKey),
DiskGeometryKey = nameof(DiskGeometryKey),
DiskFileGeometryKey = nameof(DiskFileGeometryKey),
DocumentGeometryKey = nameof(DocumentGeometryKey),
+ DocumentAddGeometryKey = nameof(DocumentAddGeometryKey),
DocumentBrokenGeometryKey = nameof(DocumentBrokenGeometryKey),
DocumentCopyGeometryKey = nameof(DocumentCopyGeometryKey),
DocumentEmptyGeometryKey = nameof(DocumentEmptyGeometryKey),
@@ -145,11 +147,13 @@ namespace mbts.ui {
public static ImageSource ModifyOrder { get { return load_resource_and_freeze("ModifyOrder"); } }
public static ImageSource CheckMark => create_icon(CheckMarkGeometryKey);
public static ImageSource Clock { get { return load_resource_and_freeze("Clock"); } }
+ public static ImageSource DataEdit => create_icon(DataEditGeometryKey, Brushes.White, new Pen(Brushes.Black, 1).frozen());
public static ImageSource Defrag { get { return load_resource_and_freeze("Defrag"); } }
public static ImageSource DetachAlgos => create_icon_and_rotate(DetachAlgosKey, Brushes.Red);
public static ImageSource Disk => create_icon(DiskGeometryKey);
public static ImageSource DiskFile => create_icon(DiskFileGeometryKey);
public static ImageSource Display { get { return load_resource_and_freeze("Display"); } }
+ public static ImageSource DocumentAdd => create_icon(DocumentAddGeometryKey);
public static ImageSource DocumentBroken => create_icon(DocumentBrokenGeometryKey);
public static ImageSource DocumentCopy => create_icon(DocumentCopyGeometryKey);
public static ImageSource DocumentEmpty => create_icon(DocumentEmptyGeometryKey);
diff --git a/src/client/spark/Images/Vector/Icons.xaml b/src/client/spark/Images/Vector/Icons.xaml
index 115c988c4..e5c29b5e4 100644
--- a/src/client/spark/Images/Vector/Icons.xaml
+++ b/src/client/spark/Images/Vector/Icons.xaml
@@ -48,6 +48,10 @@
+
+ M10.830011,12.05L13.334007,12.05 13.334007,16.535997 17.819998,16.535997 17.819998,19.03902 13.334007,19.03902 13.334007,23.525016 10.830988,23.525016 10.830988,19.03902 6.3460046,19.03902 6.3449975,16.53499 10.830988,16.535997z M2.2799975,2.4149805L2.2799975,29.580015 22.121998,29.580015 22.121998,8.500008 15.83599,8.500008 15.83599,2.4149805z M0,0L15.83599,0 17.125998,0 22.681996,5.439977 24.407,7.125007 24.407,32.000001 0,32.000001z
+
+
diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
index 7b4a662c2..f2bf4d0e3 100644
--- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
+++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
@@ -19,6 +19,7 @@
+
@@ -31,7 +32,6 @@
-
@@ -455,13 +455,33 @@
diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs
index 1bfc35beb..f4f6ecea7 100644
--- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs
+++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs
@@ -1,4 +1,7 @@
-using bts.collections;
+using bts;
+using bts.collections;
+using bts.utils;
+using mbts.ui.converters;
using mbts.utils;
using System.Linq;
using System.Windows;
@@ -8,6 +11,35 @@ using System.Windows.Input;
namespace mbts.spark {
partial class LadderView : UserControl {
+ public static IMultiValueConverter PositionToolTipConverter =
+ ValueConverter.create((account, show_day_pos, show_total_pos) => {
+ const string day_pos_text = "day", total_pos_text = "total";
+ if (!account.HasValue)
+ return string.Empty;
+ var sb = new StringBuilderEx(account.Value.name);
+ string primary_pos;
+ if (show_day_pos) {
+ primary_pos = day_pos_text;
+ if (show_total_pos) {
+ sb.Add(" '", primary_pos, " ");
+ sb.Add("(", total_pos_text, ")' ");
+ } else {
+ sb.Add(" ", primary_pos, " ");
+ }
+ } else if (show_total_pos) {
+ primary_pos = total_pos_text;
+ sb.Add(" ", primary_pos, " ");
+ } else {
+ // unexpected code path (the button for which this tooltip is destined should be invisible in this case), but no need to throw an exception.
+ return string.Empty;
+ }
+ sb.Add("position\n(click to copy ");
+ if (show_day_pos && show_total_pos)
+ sb.Add(primary_pos, " position ");
+ sb.Add("to size)");
+ return sb.ToString();
+ });
+
readonly double _max_zoom, _min_zoom;
internal LadderView(LadderVM vm) {
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs
new file mode 100644
index 000000000..b49b47c00
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillRow.cs
@@ -0,0 +1,149 @@
+using bts.api;
+using bts.api.position;
+using bts.utils;
+using mbts;
+using mbts.spark;
+using mbts.ui.shell;
+using System;
+using System.Collections.Generic;
+using System.Reactive.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+namespace bts.shell.manual_fills {
+ class ManualFillRow : DisposableViewModelBase, IEquatable {
+ public const int _uncommitted_record_id = -1;
+ static readonly PropertyInfo[] _snapshot_props =
+ Array.ConvertAll(new[] {
+ nameof(security),
+ nameof(account),
+ nameof(user),
+ nameof(side),
+ nameof(size),
+ nameof(price)
+ }, typeof(ManualFillRow).GetProperty);
+ readonly Property _is_dirty;
+ readonly Property _editable_item_state;
+ readonly DelegateProperty _is_valid;
+ SecurityImmutable? _security;
+ AccountTuple? _account;
+ UserTuple? _user;
+ Side _side;
+ uint _size;
+ double _price;
+ bool _is_selected;
+ ManualFillData? _data;
+ IDisposable _committed_snapshot;
+
+ public ManualFillRow(ManualFillData data) {
+ _data = data;
+ key = data.key;
+ _security = data.value.security;
+ _account = data.value.account;
+ _user = data.value.user;
+ _side = data.value.manual_fill.Side;
+ _size = data.value.manual_fill.Quantity;
+ _price = data.value.manual_fill.Price;
+ if (placeholder_key.HasValue) {
+ _is_dirty = backing(nameof(is_dirty), false);
+ _editable_item_state = backing(nameof(editable_item_state), EditableItemState.Uncommitted);
+ _committed_snapshot = ObjectSnapshot.create(this, _snapshot_props);
+ } else {
+ _is_dirty = backing(nameof(is_dirty), ObjectSnapshot.dirty_monitor(this, out _committed_snapshot, _snapshot_props));
+ _editable_item_state = backing(nameof(editable_item_state), _is_dirty, ch => ch.newval ? EditableItemState.Modified : EditableItemState.None);
+ }
+ _is_valid = backing(nameof(is_valid), () => _validate(this));
+ }
+
+ public event Action is_selected_changed;
+ // key/id
+ public ManualFillKey key { get; }
+ public long? placeholder_key => key.unpersisted;
+ public int record_id => key.persisted ?? _uncommitted_record_id;
+ public string record_id_display_text => key.persisted?.ToString();
+ // security/spec
+ public SecurityImmutable? security {
+ get => _security;
+ set {
+ if (_set(ref _security, value))
+ RaisePropertyChanged(nameof(spec));
+ }
+ }
+ public ContractSpecificationImmutable? spec => security.spec_or_default();
+ // account/user
+ public AccountTuple? account { get => _account; set => _set(ref _account, value); }
+ public UserTuple? user { get => _user; set => _set(ref _user, value); }
+ // side/size/price
+ public Side side { get => _side; set => _set(ref _side, value); }
+ public uint size { get => _size; set => _set(ref _size, value); }
+ public double price { get => _price; set => _set(ref _price, value); }
+ // is selected
+ public bool is_selected {
+ get => _is_selected;
+ set {
+ if (_set(ref _is_selected, value))
+ is_selected_changed?.Invoke(value);
+ }
+ }
+ // dirty/valid/editable-state
+ public bool is_dirty => _is_dirty.Value;
+ public bool is_valid => _is_valid.Value;
+ public EditableItemState editable_item_state => _editable_item_state.Value;
+
+ public ManualFillData data => _data ??
+ (_data = new ManualFillData(key, new ManualFillTuple(new ManualFillImmutable(to_man_fill()), security, account, user))).Value;
+
+ public void revert() =>
+ _committed_snapshot.Dispose();
+
+ public IObservable subscribe_is_dirty() =>
+ _is_dirty.observe_current(true);
+
+ public IObservable subscribe_is_selected() =>
+ Observable.Create(o => {
+ o.OnNext(is_selected);
+ is_selected_changed += o.OnNext;
+ return Disposable.Create(() => is_selected_changed -= o.OnNext);
+ });
+
+ public ManualFill to_man_fill() =>
+ new ManualFill {
+ RecordId = record_id,
+ AccountId = account?.id ?? 0,
+ AccountName = account?.name ?? string.Empty,
+ UserId = user?.id ?? 0,
+ Price = price,
+ Side = side,
+ Quantity = size,
+ SecurityKey = security?.Id ?? 0
+ };
+
+ public ManualFillTuple to_tuple() =>
+ new ManualFillTuple(new ManualFillImmutable(to_man_fill()), security, account, user);
+
+ public bool Equals(ManualFillRow other) =>
+ data == other?.data;
+
+ public override bool Equals(object obj) => Equals(obj as ManualFillRow);
+ public override int GetHashCode() => record_id;
+
+ static bool _validate(ManualFillRow row) =>
+ row.security.HasValue &&
+ row.account.HasValue &&
+ row.user.HasValue &&
+ row.side != Side.Undefined &&
+ !double.IsNaN(row._price);
+
+ bool _set(ref T backing, T value, [CallerMemberName] string prop_name = "") =>
+ _set(ref backing, value, EqualityComparer.Default, prop_name);
+
+ bool _set(ref T backing, T value, IEqualityComparer comparer, [CallerMemberName] string prop_name = "") {
+ if (Set(ref backing, value, comparer, prop_name)) {
+ _is_valid.refresh();
+ _data = null;
+ return true;
+ }
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml
new file mode 100644
index 000000000..18da3c039
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml
@@ -0,0 +1,84 @@
+
+
+ 4
+ 8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml.cs
new file mode 100644
index 000000000..0c597bf14
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillRowEditor.xaml.cs
@@ -0,0 +1,22 @@
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace mbts.ui.spark {
+ ///
+ /// Interaction logic for ManualFillRowEditor.xaml
+ ///
+ partial class ManualFillRowEditor : UserControl {
+ public const string
+ SecuritiesKey = nameof(SecuritiesKey),
+ AccountsKey = nameof(AccountsKey),
+ UsersKey = nameof(UsersKey),
+ SidesKey = nameof(SidesKey);
+
+ public static readonly RoutedCommand
+ CommitCommand = new RoutedCommand(),
+ CancelCommand = new RoutedCommand();
+
+ public ManualFillRowEditor() =>
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml
new file mode 100644
index 000000000..58c33c1dd
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml.cs
new file mode 100644
index 000000000..e3a0e8cde
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsDialog.xaml.cs
@@ -0,0 +1,11 @@
+using System.Windows;
+
+namespace mbts.ui.spark {
+ ///
+ /// Interaction logic for ManualFillsImportConflictsDialog.xaml
+ ///
+ partial class ManualFillsImportConflictsDialog : Window {
+ public ManualFillsImportConflictsDialog() =>
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsVM.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsVM.cs
new file mode 100644
index 000000000..c2125db20
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsVM.cs
@@ -0,0 +1,106 @@
+using bts.api;
+using bts.collections;
+using mbts;
+using mbts.collections;
+using mbts.ui;
+using mbts.ui.shell;
+using mbts.ui.utility;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Windows.Data;
+using System.Windows.Input;
+using Component = mbts.ui.spark.ManualFillsImportConflictsView.ManualFillComponent;
+
+namespace bts.shell.manual_fills {
+ class ManualFillsImportVM : DisposableViewModelBase, IRequestViewClose {
+ readonly RefCountMap _conflicts = new RefCountMap();
+ IReadOnlyDictionary _security_map = DictionaryHelper.empty();
+
+ public ManualFillsImportVM(int num_fills) {
+ rows_view = CollectionViewSource.GetDefaultView(rows);
+ ok_cmd = new DelegateCommand(() => import_request?.Invoke());
+ cancel_cmd = new DelegateCommand(() => RequestClose?.Invoke(this, new EventArgs()));
+ this.num_fills = num_fills;
+ _dispose = ObservableAutoWrapper.connect_item_hooks(rows, r =>
+ r.subscribe_has_error().Subscribe(has_error => {
+ if (has_error) {
+ if (r.affected_fills.Count(_conflicts.increment_adds_key) == 0)
+ return;
+ } else if (r.affected_fills.Count(_conflicts.decrement_removes_key) == 0)
+ return;
+ RaisePropertyChanged(nameof(num_successfully_parsed_fills));
+ }));
+ }
+
+ public event Action import_request;
+ public event EventHandler RequestClose;
+
+ public ObservableCollection rows { get; } = new ObservableCollection();
+ public ICollectionView rows_view { get; }
+ public int num_fills { get; }
+ public int num_successfully_parsed_fills => num_fills - _conflicts.Count;
+ // misc items sources
+ public IEnumerable sides => new[] { Side.Buy, Side.Sell };
+ public ObservableCollection accounts { get; } = new ObservableCollection();
+ public ObservableCollection users { get; } = new ObservableCollection();
+ public IReadOnlyDictionary security_map {
+ get => _security_map;
+ set {
+ if (!ReferenceEquals(_security_map, value)) {
+ _security_map = value;
+ _resolve_securities();
+ RaisePropertyChanged();
+ }
+ }
+ }
+ // commands
+ public ICommand ok_cmd { get; }
+ public ICommand cancel_cmd { get; }
+
+ void _resolve_securities() {
+ if (_security_map == null)
+ return;
+ var reverse_lookup = ManualFillsParser.reverse_lookup(MappedDictionary.create(_security_map, v => v.security.ToString()));
+ foreach (var r in rows) {
+ if (r.component == Component.Security && r.has_error) {
+ var id = reverse_lookup(r.text);
+ if (id != 0 && _security_map.TryGetValue(id, out var smd))
+ r.value = smd.security;
+ }
+ }
+ }
+
+ public class Row : ViewModelBase, ITemplateSelectorKey {
+ readonly DelegateProperty _has_error;
+ object _value;
+ string _text;
+
+ public Row(Component component, string text, IReadOnlyCollection affected_fills, object error_value, object value) {
+ this.component = component;
+ this.text = text;
+ this.affected_fills = affected_fills;
+ _value = value;
+ _has_error = backing(nameof(has_error), () => Equals(this.value, error_value));
+ }
+
+ public Component component { get; }
+ public string text { get => _text; set => Set(ref _text, value); }
+ public IReadOnlyCollection affected_fills { get; }
+ public object value {
+ get => _value;
+ set {
+ if (Set(ref _value, value))
+ _has_error.refresh();
+ }
+ }
+ public bool has_error => _has_error.Value;
+ string ITemplateSelectorKey.key => component.ToString();
+
+ public IObservable subscribe_has_error() => _has_error.observe_current(true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml
new file mode 100644
index 000000000..097112a63
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml.cs
new file mode 100644
index 000000000..54e5dc78d
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsImportConflictsView.xaml.cs
@@ -0,0 +1,30 @@
+using System.Windows.Controls;
+
+namespace mbts.ui.spark {
+ ///
+ /// Interaction logic for ManualFillsImportConflictsView.xaml
+ ///
+ partial class ManualFillsImportConflictsView : UserControl {
+ public ManualFillsImportConflictsView() =>
+ InitializeComponent();
+
+ public enum ManualFillComponent {
+ Security,
+ Account,
+ User,
+ Side,
+ Size,
+ Price
+ }
+
+ public static class ManualFillComponentNames {
+ public static readonly string
+ Security = ManualFillComponent.Security.ToString(),
+ Account = ManualFillComponent.Account.ToString(),
+ User = ManualFillComponent.User.ToString(),
+ Side = ManualFillComponent.Side.ToString(),
+ Size = ManualFillComponent.Size.ToString(),
+ Price = ManualFillComponent.Price.ToString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsModel.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsModel.cs
new file mode 100644
index 000000000..871aaf940
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsModel.cs
@@ -0,0 +1,107 @@
+using bts.api.core;
+using bts.api.position;
+using bts.collections;
+using mbts.spark;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
+
+namespace bts.shell.manual_fills {
+ struct ManualFillKey : IEquatable, IComparable {
+ public readonly int? persisted;
+ public readonly long? unpersisted;
+
+ public ManualFillKey(int persisted) {
+ this.persisted = persisted;
+ unpersisted = null;
+ }
+
+ public ManualFillKey(long unpersisted) {
+ this.unpersisted = unpersisted;
+ persisted = null;
+ }
+
+ public int CompareTo(ManualFillKey other) {
+ if (persisted.HasValue) {
+ if (other.persisted.HasValue) {
+ return persisted.Value.CompareTo(other.persisted.Value);
+ } else if (other.unpersisted.HasValue) {
+ return -1;
+ } else return 1;
+ } else if (unpersisted.HasValue) {
+ return other.unpersisted.HasValue ? unpersisted.Value.CompareTo(other.unpersisted.Value) : 1;
+ } else return !other.persisted.HasValue && !other.unpersisted.HasValue ? 0 : -1;
+ }
+
+ public override string ToString() => persisted.HasValue ? persisted.Value.ToString() : unpersisted.HasValue ? unpersisted.Value.ToString() : "(N/A)";
+
+ public bool Equals(ManualFillKey other) =>
+ persisted == other.persisted &&
+ unpersisted == other.unpersisted;
+
+ public override bool Equals(object obj) =>
+ obj is ManualFillKey other && Equals(other);
+
+ public override int GetHashCode() => persisted ?? unpersisted?.GetHashCode() ?? 0;
+ public static bool operator ==(ManualFillKey a, ManualFillKey b) => a.Equals(b);
+ public static bool operator !=(ManualFillKey a, ManualFillKey b) => !a.Equals(b);
+ }
+
+ struct ManualFillData : IEquatable {
+ public static readonly Func key_fn = mfd => mfd.key;
+
+ public readonly ManualFillKey key;
+ public readonly ManualFillTuple value;
+
+ public ManualFillData(ManualFillKey key, ManualFillTuple value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public bool Equals(ManualFillData other) =>
+ key == other.key &&
+ value.Equals(other.value);
+
+ public override bool Equals(object obj) =>
+ obj is ManualFillData other && Equals(other);
+
+ public override int GetHashCode() =>
+ key.GetHashCode();
+
+ public static bool operator ==(ManualFillData a, ManualFillData b) => a.Equals(b);
+ public static bool operator !=(ManualFillData a, ManualFillData b) => !a.Equals(b);
+ }
+
+ class ManualFillsModel {
+ readonly OrdersModel _model;
+
+ public ManualFillsModel(OrdersModel model)
+ : this(model, model.on_manual_fill_tuples,
+ model.factory.subscribe_accounts().Select(d => MappedDictionary.create(d, kv => new AccountTuple(kv.Key, kv.Value))).Table(u => u.id),
+ model.factory.subscribe_users().Select(d => MappedDictionary.create(d, kv => new UserTuple(kv.Key, kv.Value))).Table(a => a.id)) { }
+
+ public ManualFillsModel(OrdersModel model, IObservable> manual_fills, IObservable> accounts, IObservable> users) {
+ _model = model;
+ this.manual_fills = manual_fills.SelectKeyValue(
+ mft => new ManualFillData(new ManualFillKey(mft.manual_fill.RecordId), mft),
+ ManualFillData.key_fn);
+ this.accounts = accounts;
+ this.users = users;
+ }
+
+ public IObservable> manual_fills { get; }
+ public IObservable> accounts { get; }
+ public IObservable> users { get; }
+
+ public async Task delete_fills(IEnumerable fills) =>
+ await _model.delete_manual_fills(fills);
+
+ public async Task create_fills(IEnumerable fills) =>
+ await _model.create_manual_fills(fills);
+
+ public async Task update_fills(IEnumerable fills) =>
+ await _model.update_manual_fills(fills);
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsParser.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsParser.cs
new file mode 100644
index 000000000..7d6ca8968
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsParser.cs
@@ -0,0 +1,162 @@
+using bts.api;
+using bts.api.position;
+using bts.collections;
+using bts.utils;
+using mbts.ui.utility;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using ManualFillComponent = mbts.ui.spark.ManualFillsImportConflictsView.ManualFillComponent;
+
+namespace bts.shell.manual_fills {
+ class ParsedManualFill {
+ public readonly Guid unpersisted_id = Guid.NewGuid();
+ public readonly ManualFill result = new ManualFill();
+
+ public (string text, bool success) security { get; set; }
+ public (string text, bool success) account { get; set; }
+ public (string text, bool success) user { get; set; }
+ public (string text, bool success) side { get; set; }
+ public (string text, bool success) quantity { get; set; }
+ public (string text, bool success) price { get; set; }
+
+ public bool Equals(ParsedManualFill other) => other != null && unpersisted_id == other.unpersisted_id;
+ public override bool Equals(object obj) => Equals(obj as ParsedManualFill);
+ public override int GetHashCode() => unpersisted_id.GetHashCode();
+ }
+
+ static class ManualFillsParser {
+ public const string file_extension = "csv";
+
+ public static Action assign_component(ManualFillComponent component) {
+ switch (component) {
+ case ManualFillComponent.Security: return (mf, val) => mf.SecurityKey = ConvertUtils.try_convert(val)?.Id ?? 0;
+ case ManualFillComponent.Account: return (mf, val) => mf.AccountId = ConvertUtils.try_convert(val)?.id ?? 0;
+ case ManualFillComponent.User: return (mf, val) => mf.UserId = ConvertUtils.try_convert(val)?.id ?? 0;
+ case ManualFillComponent.Side: return (mf, val) => mf.Side = ConvertUtils.try_convert(val, Side.Undefined);
+ case ManualFillComponent.Size: return (mf, val) => mf.Quantity = ConvertUtils.try_convert(val);
+ case ManualFillComponent.Price: return (mf, val) => mf.Price = ConvertUtils.try_convert(val, double.NaN);
+ default: throw new NotImplementedException();
+ }
+ }
+
+ /// Note: the returned dictionary will have entries for each , regardless of whether or not that component has any conflicts.
+ public static Dictionary>> get_conflicts(IEnumerable parsed_fills) {
+ var missing_components = EnumHelper.get_values().ToDictionary(c => c, c => new Dictionary>());
+ var mk_list = new Func>(_ => new List());
+ foreach (var pmf in parsed_fills) {
+ if (!pmf.security.success) {
+ add_missing(ManualFillComponent.Security, pmf.security.text, pmf);
+ }
+ if (!pmf.account.success) {
+ add_missing(ManualFillComponent.Account, pmf.account.text, pmf);
+ }
+ if (!pmf.user.success) {
+ add_missing(ManualFillComponent.User, pmf.user.text, pmf);
+ }
+ if (!pmf.quantity.success) {
+ add_missing(ManualFillComponent.Size, pmf.quantity.text, pmf);
+ }
+ if (!pmf.side.success) {
+ add_missing(ManualFillComponent.Side, pmf.side.text, pmf);
+ }
+ if (!pmf.price.success) {
+ add_missing(ManualFillComponent.Price, pmf.price.text, pmf);
+ }
+ }
+ return missing_components;
+ void add_missing(ManualFillComponent component, string text, ParsedManualFill result) =>
+ missing_components[component].GetOrAdd(text ?? string.Empty, mk_list).Add(result);
+ }
+
+ // This implementation prioritizes simplicity over speed.
+ // The security desc lookup could be better optimized, but the speed at which fills are imported is probably not a paramount concern.
+ public static IEnumerable parse_rows(IEnumerable rows, IReadOnlyDictionary security_map, IReadOnlyDictionary account_map, IReadOnlyDictionary user_map) =>
+ parse_rows(rows,
+ reverse_lookup(MappedDictionary.create(security_map, kv => kv.Value.ToString())),
+ reverse_lookup(account_map),
+ reverse_lookup(user_map));
+
+ public static IEnumerable parse_rows(IEnumerable rows, Func security_id_lookup, Func account_id_lookup, Func user_id_lookup) {
+ var columns = new[] {
+ (Headers.Security, Cells.security(security_id_lookup)),
+ (Headers.Account, Cells.account(account_id_lookup)),
+ (Headers.User, Cells.user(user_id_lookup)),
+ (Headers.Side, Cells.side),
+ (Headers.Quantity, Cells.quantity),
+ (Headers.Price, Cells.price)
+ }.ToDictionary(col => col.Item1, col => col.Item2.with_null_check());
+ return RowParser.parse_rows(rows, columns, Cells.delimiter);
+ }
+
+ public static Func reverse_lookup(IReadOnlyDictionary map) {
+ var lookup = map.ToLookup(kv => kv.Value, kv => kv.Key);
+ return cell_text => lookup.Contains(cell_text) ? lookup[cell_text].First() : default;
+ }
+
+ static class Headers {
+ public const string
+ Security = "Security",
+ Account = "Account",
+ User = "User",
+ Side = "Side",
+ Quantity = "Quantity",
+ Price = "Price";
+ }
+
+ static class Cells {
+ public const char delimiter = ',';
+
+ public static RowParser.AssignColumnValue security(Func reverse_id_lookup) {
+ return impl;
+ void impl(ref ParsedManualFill pmf, string text) {
+ pmf.result.SecurityKey = reverse_id_lookup(text);
+ pmf.security = (text, pmf.result.SecurityKey != 0);
+ }
+ }
+
+ public static void side(ref ParsedManualFill pmf, string cell_text) {
+ switch (cell_text[0]) {
+ case 'B': pmf.result.Side = Side.Buy; break;
+ case 'S': pmf.result.Side = Side.Sell; break;
+ default: pmf.side = (cell_text, false); break;
+ }
+ pmf.side = (cell_text, true);
+ }
+
+ public static void quantity(ref ParsedManualFill pmf, string cell_text) {
+ if (uint.TryParse(cell_text, out uint v)) {
+ pmf.result.Quantity = v;
+ pmf.quantity = (cell_text, true);
+ } else {
+ pmf.quantity = (cell_text, false);
+ }
+ }
+
+ public static void price(ref ParsedManualFill pmf, string cell_text) {
+ if (double.TryParse(cell_text, out var v)) {
+ pmf.result.Price = v;
+ pmf.price = (cell_text, true);
+ } else {
+ pmf.price = (cell_text, false);
+ }
+ }
+
+ public static RowParser.AssignColumnValue account(Func reverse_id_lookup) {
+ return impl;
+ void impl(ref ParsedManualFill pmf, string text) {
+ pmf.result.AccountId = reverse_id_lookup(text);
+ pmf.account = (text, pmf.result.AccountId != 0);
+ }
+ }
+
+ public static RowParser.AssignColumnValue user(Func reverse_id_lookup) {
+ return impl;
+ void impl(ref ParsedManualFill pmf, string text) {
+ pmf.result.UserId = reverse_id_lookup(text);
+ pmf.user = (text, pmf.result.UserId != 0);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsSettings.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsSettings.cs
new file mode 100644
index 000000000..725e6f374
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsSettings.cs
@@ -0,0 +1,23 @@
+using mbts.ui;
+using ProtoBuf;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace bts.shell.manual_fills {
+ [ProtoContract]
+ class ManualFillsSettings {
+ [ProtoMember(1)]
+ readonly SortingCriteria[] _sorting_criterion;
+
+ public static ManualFillsSettings Default =>
+ new ManualFillsSettings(new[] { new SortingCriteria(nameof(mbts.ui.spark.ManualFillsView.Columns.Security), true) });
+
+ public ManualFillsSettings() { }
+
+ public ManualFillsSettings(IEnumerable sorting_criterion) =>
+ _sorting_criterion = sorting_criterion.ToArray();
+
+ public IReadOnlyList sorting_criterion => _sorting_criterion ?? Array.Empty();
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsVM.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsVM.cs
new file mode 100644
index 000000000..cb2ecf39b
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsVM.cs
@@ -0,0 +1,222 @@
+using bts.api;
+using bts.api.core;
+using bts.api.position;
+using bts.collections;
+using mbts;
+using mbts.spark;
+using mbts.ui;
+using mbts.ui.controls;
+using mbts.ui.shell;
+using mbts.ui.utility;
+using mbts.utils;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using System.Windows.Input;
+using Disposable = mbts.Disposable;
+using ManualFillComponent = mbts.ui.spark.ManualFillsImportConflictsView.ManualFillComponent;
+
+namespace bts.shell.manual_fills {
+ enum EditableItemState {
+ None, // Committed and not modified
+ Modified, // Committed and modified
+ Uncommitted // Uncommitted (modified n/a)
+ }
+
+ class ManualFillsVM : DisposableViewModelBase {
+ const int _max_unconfirmed_removes = 16;
+ static readonly IComparer _row_key_comparer = Comparer.Create((a, b) => a.key.CompareTo(b.key));
+ readonly IBus _bus;
+ readonly ManualFillsModel _model;
+ readonly ObservableCollection
+ _persisted_rows = new ObservableCollection(),
+ _placeholder_rows = new ObservableCollection();
+ long _placeholder_id_counter = long.MinValue;
+ IDisposable _import_fills_hooks;
+
+ public static ManualFillsVM create(IBus bus, OrdersModel model) =>
+ new ManualFillsVM(bus, new ManualFillsModel(model));
+
+ public ManualFillsVM(IBus bus, ManualFillsModel model) {
+ _bus = bus;
+ _model = model;
+ var merged_rows = new ObservableAggregateCollection(_persisted_rows, _placeholder_rows);
+ rows_view = CollectionViewSource.GetDefaultView(merged_rows);
+ // mons
+ var dirty_mon = new ReactiveThresholdMonitor(r => r.subscribe_is_dirty());
+ var selection_mon = new ReactiveThresholdMonitor(r => r.subscribe_is_selected());
+ var placeholder_mon = new ReactiveThresholdMonitor();
+ // commands
+ commit_all_fills_cmd = ObservantAsyncCommand.create(() => _commit_async(merged_rows), out var commit_all_fils_observer);
+ commit_selected_fills_cmd = ObservantAsyncCommand.create(() => _commit_async(selection_mon.filtered_items), out var commit_selected_fills_observer);
+ revert_all_cmd = ObservantCommand.create(() => revert(dirty_mon.filtered_items.ToList()), out var revert_all_observer);
+ revert_selected_fills_cmd = ObservantCommand.create(() => revert(selection_mon.filtered_items.ToList()), out var revert_selected_fills_observer);
+ remove_selected_fills_cmd = ObservantAsyncCommand.create(remove_selected_fills_async, out var remove_selected_fills_observer);
+ add_fill_cmd = new DelegateCommand(_add_fill);
+ import_fills_cmd = FileDialogCommand.open_file(_import_fills, extensions: ManualFillsParser.file_extension);
+ //
+ var dirty_or_new_src = dirty_mon.CombineLatest(placeholder_mon, LogicalDelegates.Or);
+ _dispose = Disposable.Create(
+ RXCollection.connect(_persisted_rows,
+ _model.manual_fills.OnDispatcher(),
+ Observable.Return(Comparer.Create((a, b) => a.key.CompareTo(b.key))),
+ mfd => new ManualFillRow(mfd),
+ mfr => mfr.data),
+ _bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(m => {
+ security_map = m;
+ RaisePropertyChanged(nameof(security_map));
+ }),
+ ObservableAutoWrapper.connect_item_hooks(_persisted_rows, r => Disposable.Create(dirty_mon.join(r), selection_mon.join(r))),
+ ObservableAutoWrapper.connect_item_hooks(_placeholder_rows, r => Disposable.Create(selection_mon.join(r), placeholder_mon.join(r, Observable.Return(true)))),
+ // command param subs
+ dirty_mon.Subscribe(revert_all_observer),
+ dirty_or_new_src.OnDispatcher().Subscribe(commit_all_fils_observer),
+ selection_mon.Subscribe(remove_selected_fills_observer),
+ selection_mon.CombineLatest(dirty_mon, LogicalDelegates.And).OnDispatcher().Subscribe(revert_selected_fills_observer),
+ selection_mon.CombineLatest(dirty_or_new_src, LogicalDelegates.And).OnDispatcher().Subscribe(commit_selected_fills_observer),
+ // accounts/users subs
+ RXCollection.connect(accounts, model.accounts.OnDispatcher(), a => new AccountTuple?(a), a => a.Value, Comparer.Default),
+ RXCollection.connect(users, model.users.OnDispatcher(), u => new UserTuple?(u), u => u.Value, Comparer.Default),
+ Disposable.Create(() => Disposable.dispose(ref _import_fills_hooks))
+ );
+ // local methods
+ void revert(IReadOnlyList rows) {
+ foreach (var r in rows)
+ r.revert();
+ }
+ async Task remove_selected_fills_async() {
+ if (selection_mon.filtered_items.Count < _max_unconfirmed_removes || BTSMessageBox.Confirm($"Are you sure you want to delete {selection_mon.filtered_items.Count} fills?", "Delete Fills")) {
+ var persisted_fills = new List();
+ foreach (var r in selection_mon.filtered_items.ToList()) {
+ if (r.placeholder_key.HasValue)
+ _placeholder_rows.RemoveSorted(r, _row_key_comparer);
+ else persisted_fills.Add(r.to_man_fill());
+ }
+ await _model.delete_fills(persisted_fills);
+ }
+ }
+ }
+
+ public ICollectionView rows_view { get; }
+ // misc items sources
+ public IEnumerable sides => new[] { Side.Buy, Side.Sell };
+ public ObservableCollection accounts { get; } = new ObservableCollection();
+ public ObservableCollection users { get; } = new ObservableCollection();
+ public IReadOnlyDictionary security_map { get; private set; } = DictionaryHelper.empty();
+ // commands
+ public ICommand add_fill_cmd { get; }
+ public ICommand commit_all_fills_cmd { get; }
+ public ICommand commit_selected_fills_cmd { get; }
+ public ICommand import_fills_cmd { get; }
+ public ICommand remove_selected_fills_cmd { get; }
+ public ICommand revert_all_cmd { get; }
+ public ICommand revert_selected_fills_cmd { get; }
+
+ public ManualFillRow row_factory() =>
+ new ManualFillRow(
+ new ManualFillData(
+ new ManualFillKey(_placeholder_id_counter++),
+ new ManualFillTuple(new ManualFillImmutable(new ManualFill {
+ Side = Side.Buy
+ }), null, accounts.FirstOrDefault(), users.FirstOrDefault())));
+
+ void _add_fill(ManualFillRow new_row) =>
+ _placeholder_rows.InsertSorted((new_row ?? (new_row = row_factory())).placeholder_key.HasValue ?
+ new_row : throw new InvalidOperationException("New row is already persisted."),
+ _row_key_comparer);
+
+ async Task _commit_async(IEnumerable rows) {
+ var updates = new List();
+ var adds = new List<(ManualFill man_fill, long pl_key)>();
+ foreach (var r in rows) {
+ if (r.is_dirty) {
+ updates.Add(r.to_man_fill());
+ } else if (r.placeholder_key.HasValue) {
+ adds.Add((r.to_man_fill(), r.placeholder_key.Value));
+ }
+ }
+ if (updates.Count > 0)
+ await _model.update_fills(updates);
+ if (adds.Count > 0) {
+ await _model.create_fills(adds.WrapSelector(r => r.man_fill, null));
+ _placeholder_rows
+ .WrapSelector(r => r.placeholder_key.Value, null)
+ .RemoveSorted(adds.Select(r => r.pl_key));
+ }
+ }
+
+ void _import_fills(string file_name) {
+ try {
+ var lines = File.ReadAllLines(file_name);
+ var parsed_fills = ManualFillsParser.parse_rows(
+ lines,
+ MappedDictionary.create(security_map, kv => kv.Value.security),
+ accounts.ToDictionary(a => a.Value.id, a => a.Value.name),
+ users.ToDictionary(u => u.Value.id, u => u.Value.name)
+ ).ToList();
+ var conflicts = ManualFillsParser.get_conflicts(parsed_fills);
+ if (conflicts.Values.Any(c => c.Count > 0)) {
+ // init vm
+ var vm = new ManualFillsImportVM(parsed_fills.Count) {
+ security_map = security_map
+ };
+ // add rows
+ foreach (var kv in conflicts) {
+ var assign_del = ManualFillsParser.assign_component(kv.Key);
+ foreach (var text_groups in kv.Value) {
+ var eval = get_error_value(kv.Key);
+ var row = new ManualFillsImportVM.Row(kv.Key, text_groups.Key, text_groups.Value, eval, eval);
+ vm.rows.Add(row);
+ vm.import_request += () => {
+ foreach (var pmf in text_groups.Value)
+ assign_del(pmf.result, row.value);
+ };
+ }
+ }
+ var win = new mbts.ui.spark.ManualFillsImportConflictsDialog {
+ DataContext = vm,
+ Title = ManualFillsWindowFactory.window_name,
+ Topmost = true
+ };
+ vm.RequestClose += (s, e) => Disposable.dispose(ref _import_fills_hooks);
+ vm.import_request += () => {
+ add_imported_fills();
+ Disposable.dispose(ref _import_fills_hooks);
+ };
+ Disposable.replace(ref _import_fills_hooks, Disposable.Create(
+ ObservableAutoWrapper.connect(accounts, vm.accounts),
+ ObservableAutoWrapper.connect(users, vm.users),
+ vm,
+ Disposable.Create(close)
+ ));
+ win.move_to_mouse(-200, -75);
+ win.Show();
+ void close() => WindowUtilities.force_close(win);
+ object get_error_value(ManualFillComponent component) {
+ switch (component) {
+ case ManualFillComponent.Price: return double.NaN;
+ case ManualFillComponent.Size: return 0;
+ default: return null;
+ }
+ }
+ } else {
+ add_imported_fills();
+ }
+ void add_imported_fills() =>
+ _placeholder_rows.InsertSorted(parsed_fills.Select(pmf => new ManualFillRow(new ManualFillData(new ManualFillKey(_placeholder_id_counter++), new ManualFillTuple(new ManualFillImmutable(pmf.result),
+ pmf.result.SecurityKey != 0 && security_map.TryGetValue(pmf.result.SecurityKey, out var smd) ? smd.security : (SecurityImmutable?)null,
+ accounts.FirstOrDefault(a => a?.id == pmf.result.AccountId),
+ users.FirstOrDefault(a => a?.id == pmf.result.UserId))))), _row_key_comparer);
+ } catch (Exception ex) {
+ BTSMessageBox.Error($"Error importing fills: {ex}.", ManualFillsWindowFactory.window_name);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml
new file mode 100644
index 000000000..22f954abb
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml
@@ -0,0 +1,247 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml.cs
new file mode 100644
index 000000000..78fb5b10b
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsView.xaml.cs
@@ -0,0 +1,97 @@
+using bts.shell.manual_fills;
+using mbts.ui.controls.adorners;
+using mbts.ui.converters;
+using mbts.utils;
+using System;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace mbts.ui.spark {
+ ///
+ /// Interaction logic for ManualFillsView.xaml
+ ///
+ partial class ManualFillsView : UserControl {
+ public static readonly IMultiValueConverter
+ RowHeaderVisualStateConverter = ValueConverter.create(
+ (edit_state, is_valid) => is_valid ? edit_state.ToString() : edit_state == EditableItemState.Uncommitted ? "ErrorUncommitted" : "Error");
+
+ public enum Columns {
+ RecordID,
+ Security,
+ Account,
+ User,
+ Side,
+ Size,
+ Price
+ }
+
+ IDisposable _transaction;
+
+ public ManualFillsView() =>
+ InitializeComponent();
+
+ public static readonly DependencyProperty ImageBrushProperty =
+ DependencyProperty.RegisterAttached("ImageBrush", typeof(Brush), typeof(ManualFillsView));
+
+ public static Brush GetImageBrush(DependencyObject d) => d.GetValue(ImageBrushProperty) as Brush;
+ public static void SetImageBrush(DependencyObject d, Brush value) => d.SetValue(ImageBrushProperty, value);
+
+ public void begin_add_fill() {
+ if (!(DataContext is ManualFillsVM vm))
+ return;
+ Disposable.dispose(ref _transaction);
+ var row = vm.row_factory();
+ var row_editor = new ManualFillRowEditor { DataContext = row };
+ row_editor.CommandBindings.Add(new CommandBinding(ManualFillRowEditor.CommitCommand, commit_executed));
+ row_editor.CommandBindings.Add(new CommandBinding(ManualFillRowEditor.CancelCommand, cancel_executed));
+ // dynamic resources
+ row_editor.Resources[ManualFillRowEditor.AccountsKey] = vm.accounts;
+ row_editor.Resources[ManualFillRowEditor.UsersKey] = vm.users;
+ row_editor.Resources[ManualFillRowEditor.SidesKey] = vm.sides;
+ FocusManager.SetIsFocusScope(row_editor, true);
+ var sec_hook = vm.as_demuxer().subscribe(nameof(ManualFillsVM.security_map)).OnDispatcher().Subscribe(v => row_editor.Resources[ManualFillRowEditor.SecuritiesKey] = v);
+ // popup adorner
+ var popup_adorner = new PopupAdorner(
+ data_grid, data_grid,
+ new Border {
+ Child = row_editor,
+ Background = BTSColors.common_background_brush,
+ BorderBrush = Brushes.Black,
+ BorderThickness = new Thickness(1),
+ Padding = new Thickness(0, 6, 0, 0),
+ HorizontalAlignment = HorizontalAlignment.Left,
+ VerticalAlignment = VerticalAlignment.Top
+ },
+ HorizontalPosition.Middle,
+ VerticalPosition.Middle,
+ 0,
+ 22) {
+ OpenRelativeToMouse = true,
+ EnableDragMove = true,
+ ClipToBounds = true
+ };
+ popup_adorner.attach();
+ popup_adorner.IsOpen = true;
+ row_editor.Focus();
+ _transaction = new CompositeDisposable(sec_hook) { destroy_popup };
+ // local methods
+ void commit_executed(object sender, ExecutedRoutedEventArgs e) {
+ vm.add_fill_cmd?.TryExecuteIfCan(row);
+ Disposable.dispose(ref _transaction);
+ }
+ void cancel_executed(object sender, ExecutedRoutedEventArgs e) {
+ row.revert();
+ Disposable.dispose(ref _transaction);
+ }
+ void destroy_popup() {
+ popup_adorner.IsOpen = false;
+ popup_adorner.detach();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/ManualFills/ManualFillsWindowFactory.cs b/src/client/spark/Modules/Trading/ManualFills/ManualFillsWindowFactory.cs
new file mode 100644
index 000000000..56a3c86f4
--- /dev/null
+++ b/src/client/spark/Modules/Trading/ManualFills/ManualFillsWindowFactory.cs
@@ -0,0 +1,133 @@
+using bts.api;
+using bts.shell.manual_fills;
+using bts.spark;
+using mbts;
+using mbts.collections;
+using mbts.spark;
+using mbts.ui;
+using mbts.ui.controls;
+using mbts.ui.spark;
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace bts.shell {
+ class ManualFillsWindowFactory : ShellWindowFactory {
+ public const string
+ window_type = "ManualFills",
+ window_name = "Manual Fills";
+ const double _window_min_width = 466;
+
+ readonly IBus _bus;
+ readonly OrdersModel _orders_model;
+ readonly ManualFillsConfig _manual_fills_conf = ManualFillsConfig.read();
+
+ public ManualFillsWindowFactory(IShellModule owner, IBus bus, OrdersModel orders_model) : base(owner, window_name) {
+ _bus = bus;
+ _orders_model = orders_model;
+ _dispose = bus.subscribe(SparkTags.ShowManualFillsTag).Subscribe(open_window);
+ //
+ async void open_window(ManualFillsSettings state) =>
+ _bus.post(SparkTags.ShowWindow, await load(state));
+ }
+
+ public override Task load(ManualFillsSettings settings) {
+ return Task.FromResult(SparkWindow.create(
+ window_type, window_name, _bus, this, Icons.DataEdit, _manual_fills_conf.thread_id, thread_init, _window_min_width));
+ //
+ (UIElement, IEnumerable, Func, IDisposable) thread_init() {
+ var vm = ManualFillsVM.create(_bus, _orders_model);
+ var view = new ManualFillsView { DataContext = vm };
+ view.data_grid.Sorting += on_sorting;
+ IReadOnlyList last_sorting_criterion = Array.Empty();
+ using (apply_sort()) {
+ var col_sort_tuples =
+ from sc in settings.sorting_criterion
+ join col in view.data_grid.Columns on sc.col_name equals _col_id(col)
+ select (col, sc);
+ foreach (var (col, sc) in col_sort_tuples) {
+ col.SortDirection = sc.direction();
+ vm.rows_view.SortDescriptions.Add(new SortDescription(col.SortMemberPath, sc.direction()));
+ }
+ }
+ var cmds = new[] {
+ new SparkCommandCommand("Add New", Icons.AddBoxes, _manual_fills_conf.modal_transactions ? new DelegateCommand(() => view.begin_add_fill()) : vm.add_fill_cmd) { group = CommandGroups.Add },
+ new SparkCommandCommand("Import Fills", Icons.Import, vm.import_fills_cmd) { group = CommandGroups.Add },
+ new SparkCommandCommand("Revert Selected", Icons.UndoCircular,vm.revert_selected_fills_cmd) { group = CommandGroups.Revert, show_in_toolbar = false },
+ new SparkCommandCommand("Revert All", Icons.UndoCircular, vm.revert_all_cmd) { group = CommandGroups.Revert },
+ new SparkCommandCommand("Save Selected", Icons.Disk, vm.commit_selected_fills_cmd) { group = CommandGroups.Save, show_in_toolbar = false },
+ new SparkCommandCommand("Save All", Icons.Disk, vm.commit_all_fills_cmd) { group = CommandGroups.Save },
+ new SparkCommandCommand("Delete Selected", Icons.Trash, vm.remove_selected_fills_cmd)
+ };
+ return (view, cmds, get_settings, Disposable.Create(
+ vm.rows_view.subscribe_sorting_criterion(sm => view.data_grid.Columns.TryGetFirst(dc => dc.SortMemberPath == sm, out DataGridColumn match) ? _col_id(match) : null)
+ .Subscribe(sc => last_sorting_criterion = sc),
+ vm));
+ //
+ void on_sorting(object sender, DataGridSortingEventArgs e) {
+ e.Handled = true;
+ using (apply_sort()) {
+ var new_sort_desc = new SortDescription(e.Column.SortMemberPath, e.Column.SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending);
+ e.Column.SortDirection = new_sort_desc.Direction;
+ if (KeyboardExtensions.IsShiftDown()) {
+ if (vm.rows_view.SortDescriptions.TryGetFirst(sd => sd.PropertyName == e.Column.SortMemberPath, out var match, out int index)) {
+ vm.rows_view.SortDescriptions[index] = new_sort_desc;
+ } else {
+ vm.rows_view.SortDescriptions.Add(new_sort_desc);
+ }
+ } else {
+ vm.rows_view.SortDescriptions.Clear();
+ foreach (var col in view.data_grid.Columns.Except(new[] { e.Column }))
+ col.SortDirection = null;
+ vm.rows_view.SortDescriptions.Add(new_sort_desc);
+ }
+ }
+ }
+ /// Ensures that the primary sort description property (i.e., at index 0) is the placeholder_key.
+ /// This behavior has the effect of grouping placeholder rows at the bottom, without using (which is incompatible with row virtualization).
+ IDisposable apply_sort() =>
+ Disposable.Create(() => {
+ var pk_sort_desc = new SortDescription(nameof(ManualFillRow.placeholder_key), ListSortDirection.Ascending);
+ if (vm.rows_view.SortDescriptions.Count > 0) {
+ if (vm.rows_view.SortDescriptions[0].Equals(pk_sort_desc))
+ return;
+ vm.rows_view.SortDescriptions.removeFirst(sd => sd.PropertyName == pk_sort_desc.PropertyName);
+ }
+ vm.rows_view.SortDescriptions.Insert(0, pk_sort_desc);
+ });
+
+ ManualFillsSettings get_settings() =>
+ new ManualFillsSettings(last_sorting_criterion);
+ }
+ }
+
+ static string _col_id(DataGridColumn col) =>
+ DataGridEx.GetCellKey(col)?.ToString();
+
+ readonly struct ManualFillsConfig {
+ public readonly bool modal_transactions;
+ public readonly string thread_id;
+
+ ManualFillsConfig(string thread_id, bool modal_transactions) {
+ this.thread_id = thread_id;
+ this.modal_transactions = modal_transactions;
+ }
+
+ public static ManualFillsConfig read() => new ManualFillsConfig(
+ mbts.config.Configuration.get().manual_fills ? window_type : null,
+ mbts.config.Configuration.get().modal_transactions);
+ }
+
+ static class CommandGroups {
+ public const string
+ Add = "Add",
+ Save = "Save",
+ Revert = "Revert";
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs
index fc70dd0ee..76daca299 100644
--- a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs
@@ -176,7 +176,6 @@ namespace mbts.spark {
_wrap_comparer(r => r.order_type),
DiscreteValuesFilterVM.CreateTableUpdate(
o => new AlgoDataVM(o.algo.GetValueOrDefault()),
- o => AlgoID.from_order_def(o.order.Def),
vm => AlgoID.from_algo_key(vm.data.key), out var order_type_filter_observer, out var order_type_items_view)));
_resources.Add(algo_items_source.Subscribe(order_type_filter_observer));
order_type_items_view.CustomSort = algo_items_comp;
@@ -189,7 +188,6 @@ namespace mbts.spark {
_wrap_comparer(r => r.order_tuple.root_algo.value.CustomCase),
DiscreteValuesFilterVM.CreateTableUpdate(
o => new AlgoDataVM(o.root_algo),
- o => AlgoID.from_algo_key(o.root_algo.key),
vm => AlgoID.from_algo_key(vm.data.key), out var root_algo_type_observer, out var root_algo_type_items_view),
DefaultColumnHeaders.RootAlgoType));
_resources.Add(algo_items_source.Subscribe(root_algo_type_observer));
diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs
index cd2c7fe29..e9a7d3b6b 100644
--- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs
@@ -136,14 +136,14 @@ namespace mbts.spark {
}
}
}
- public bool is_qty_dirty => this.prospective_quantity != this.quantity;
+ public bool is_qty_dirty => this.prospective_quantity != this.quantity;
public bool is_price_dirty => this.prospective_price != this.price;
// Commands
public ICommand toggle_command => _toggle_expanded_cmd ?? (
_toggle_expanded_cmd = new DelegateCommand(() => is_expanded = !is_expanded));
- public ICommand show_order_modify_cmd =>
+ public ICommand show_order_modify_cmd =>
_show_order_modify_cmd ?? (_show_order_modify_cmd = new DelegateCommand(() => _owner.show_order_modify(this), () => status == OrderStatus.Working));
public ICommand cancel_command => _cancel_cmd ??
@@ -197,7 +197,7 @@ namespace mbts.spark {
public ICommand update_command => _update_command ?? (
_update_command = new DelegateCommand(() => {
- _select_me();
+ _select_me();
})
);
@@ -259,11 +259,11 @@ namespace mbts.spark {
// quantity
if ((Columns.Size & dirty) != 0)
RaisePropertyChanged(nameof(quantity), nameof(is_qty_dirty));
- // we need to update the prospective_quantity here b/c an update could have come in while the row was in edit mode
- // via the Mini OB update column mechanism (vs the EditableQty column)
- // prospecive price does not need to be updated in the same manner b/c if the price is changed, the whole
- // row will no longer match the filter
- prospective_quantity = quantity;
+ // we need to update the prospective_quantity here b/c an update could have come in while the row was in edit mode
+ // via the Mini OB update column mechanism (vs the EditableQty column)
+ // prospecive price does not need to be updated in the same manner b/c if the price is changed, the whole
+ // row will no longer match the filter
+ prospective_quantity = quantity;
// price
if ((Columns.Price & dirty) != 0) {
RaisePropertyChanged(nameof(price));
@@ -417,4 +417,4 @@ namespace mbts.spark {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
index 93ff9e2a1..cff54d5c4 100644
--- a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
@@ -565,7 +565,7 @@ namespace mbts.spark {
public OrderMetadata get_metadata(CustomOrderDefinition.CustomOneofCase order_type) => _model.factory.get_metadata(order_type);
- public OrderMetadata get_metadata(OrderBookRowVM row) => _model.factory.get_metadata(row.order_type);
+ public OrderMetadata get_metadata(OrderBookRowVM row) => _model.factory.get_metadata(row.order.actual_order_type());
internal OrderBookRowVM get_parent(OrderBookRowVM row) => _row_collection.get_parent(row.order_key);
diff --git a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
index 5e5cabf15..5c5caa779 100644
--- a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
@@ -1,222 +1,222 @@
-using bts.api.orderman;
-using mbts;
-using mbts.ui;
-using mbts.ui.controls;
-using mbts.ui.settings;
-using ProtoBuf;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reactive.Linq;
-using System.Windows;
-using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
-using GridSettings = mbts.ui.settings.GridSettings;
-
-namespace bts.shell.orderbook {
- [ProtoContract]
- class OrderBookStartupData {
- const bool
- _default_show_right_panel = true,
- _default_show_order_params = true;
- const double
- _default_right_panel_width = 400,
- _default_order_params_height = 250,
- _default_fills_height = 300,
- _default_ladder_height = 350;
- [ProtoMember(16)]
- OrderBookRightPanelSettings _right_panel;
- // ALREADY USED TAGS
- // [ProtoMember(5)]
- // public readonly List sort_criteria;
-
- public OrderBookRightPanelSettings right_panel => _right_panel ?? (_right_panel = new OrderBookRightPanelSettings());
- /// TODO: remove properties below, and redirect callers to
- // right panel (host)
- public bool show_right_panel { get => right_panel.show; set => right_panel.show = value; }
- public double right_panel_width { get => right_panel.width; set => right_panel.width = value; }
- // order params
- public bool show_order_params { get => right_panel.stack.show_order_params; set => right_panel.stack.show_order_params = value; }
- public double order_params_height { get; set; }
- // ladder
- public bool show_ladder { get; set; }
- public double ladder_height { get => right_panel.stack.ladder_height; set => right_panel.stack.ladder_height = value; }
- // fills
- public bool show_fills { get => right_panel.stack.show_fills; set => right_panel.stack.show_fills = value; }
- public double fills_height { get => right_panel.stack.fills_height; set => right_panel.stack.fills_height = value; }
-
- // filters
- [ProtoMember(10)]
- public FilterStates filters;
- // grid
- [ProtoMember(15)]
- [Obsolete]
- public GridSettings grid { get; set; }
- // orderbook grid
- [ProtoMember(17)]
- public OrderBookGridSettings orderbook_grid { get; set; }
- // fills settings
- [ProtoMember(26)]
- public OrderBookFillsGridSettings fills_settings { get; set; }
- // predicate animations
- [ProtoMember(20)]
- [Obsolete]
- List _predicate_animations;
- // use defaults
- [ProtoMember(25)]
- public bool use_defaults;
-
- ///
- /// Please use to get a new instance (the only reason the default constructor still exists is for ProtoBuf deserialization).
- ///
- [Obsolete]
- public OrderBookStartupData() {
- show_right_panel = _default_show_right_panel;
- show_order_params = _default_show_order_params;
- right_panel_width = _default_right_panel_width;
- order_params_height = _default_order_params_height;
- fills_height = _default_fills_height;
- ladder_height = _default_ladder_height;
- }
-
- public OrderBookStartupData(FilterStates filters, OrderBookGridSettings orderbook_grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, bool use_defaults = false) {
- this.filters = filters;
- this.use_defaults = use_defaults;
- this.show_right_panel = show_right_panel;
- this.right_panel_width = right_panel_width;
- this.fills_height = fills_height;
- this.show_fills = show_fills;
- this.orderbook_grid = orderbook_grid;
-#pragma warning disable CS0612 // Type or member is obsolete
- _predicate_animations = new List();
- if (predicate_animations != null)
- _predicate_animations.AddRange(predicate_animations);
-#pragma warning restore CS0612 // Type or member is obsolete
- }
-
-#pragma warning disable CS0612 // Type or member is obsolete
- [Obsolete]
- public IReadOnlyList predicate_animations => _predicate_animations ?? (_predicate_animations = new List());
- public OrderBookGridSettings grid_settings_wrapper() {
- if (use_defaults)
- return null;
- if (orderbook_grid == null) {
- if (grid == null)
- grid = _default_general_grid;
+using bts.api.orderman;
+using mbts;
+using mbts.ui;
+using mbts.ui.controls;
+using mbts.ui.settings;
+using ProtoBuf;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Windows;
+using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
+using GridSettings = mbts.ui.settings.GridSettings;
+
+namespace bts.shell.orderbook {
+ [ProtoContract]
+ class OrderBookStartupData {
+ const bool
+ _default_show_right_panel = true,
+ _default_show_order_params = true;
+ const double
+ _default_right_panel_width = 400,
+ _default_order_params_height = 250,
+ _default_fills_height = 300,
+ _default_ladder_height = 350;
+ [ProtoMember(16)]
+ OrderBookRightPanelSettings _right_panel;
+ // ALREADY USED TAGS
+ // [ProtoMember(5)]
+ // public readonly List sort_criteria;
+
+ public OrderBookRightPanelSettings right_panel => _right_panel ?? (_right_panel = new OrderBookRightPanelSettings());
+ /// TODO: remove properties below, and redirect callers to
+ // right panel (host)
+ public bool show_right_panel { get => right_panel.show; set => right_panel.show = value; }
+ public double right_panel_width { get => right_panel.width; set => right_panel.width = value; }
+ // order params
+ public bool show_order_params { get => right_panel.stack.show_order_params; set => right_panel.stack.show_order_params = value; }
+ public double order_params_height { get; set; }
+ // ladder
+ public bool show_ladder { get; set; }
+ public double ladder_height { get => right_panel.stack.ladder_height; set => right_panel.stack.ladder_height = value; }
+ // fills
+ public bool show_fills { get => right_panel.stack.show_fills; set => right_panel.stack.show_fills = value; }
+ public double fills_height { get => right_panel.stack.fills_height; set => right_panel.stack.fills_height = value; }
+
+ // filters
+ [ProtoMember(10)]
+ public FilterStates filters;
+ // grid
+ [ProtoMember(15)]
+ [Obsolete]
+ public GridSettings grid { get; set; }
+ // orderbook grid
+ [ProtoMember(17)]
+ public OrderBookGridSettings orderbook_grid { get; set; }
+ // fills settings
+ [ProtoMember(26)]
+ public OrderBookFillsGridSettings fills_settings { get; set; }
+ // predicate animations
+ [ProtoMember(20)]
+ [Obsolete]
+ List _predicate_animations;
+ // use defaults
+ [ProtoMember(25)]
+ public bool use_defaults;
+
+ ///
+ /// Please use to get a new instance (the only reason the default constructor still exists is for ProtoBuf deserialization).
+ ///
+ [Obsolete]
+ public OrderBookStartupData() {
+ show_right_panel = _default_show_right_panel;
+ show_order_params = _default_show_order_params;
+ right_panel_width = _default_right_panel_width;
+ order_params_height = _default_order_params_height;
+ fills_height = _default_fills_height;
+ ladder_height = _default_ladder_height;
+ }
+
+ public OrderBookStartupData(FilterStates filters, OrderBookGridSettings orderbook_grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, bool use_defaults = false) {
+ this.filters = filters;
+ this.use_defaults = use_defaults;
+ this.show_right_panel = show_right_panel;
+ this.right_panel_width = right_panel_width;
+ this.fills_height = fills_height;
+ this.show_fills = show_fills;
+ this.orderbook_grid = orderbook_grid;
+#pragma warning disable CS0612 // Type or member is obsolete
+ _predicate_animations = new List();
+ if (predicate_animations != null)
+ _predicate_animations.AddRange(predicate_animations);
+#pragma warning restore CS0612 // Type or member is obsolete
+ }
+
+#pragma warning disable CS0612 // Type or member is obsolete
+ [Obsolete]
+ public IReadOnlyList predicate_animations => _predicate_animations ?? (_predicate_animations = new List());
+ public OrderBookGridSettings grid_settings_wrapper() {
+ if (use_defaults)
+ return null;
+ if (orderbook_grid == null) {
+ if (grid == null)
+ grid = _default_general_grid;
orderbook_grid = new OrderBookGridSettings(grid.clone(), _predicate_animations);
- }
- return orderbook_grid;
- }
-#pragma warning restore CS0612 // Type or member is obsolete
-
- public static OrderBookStartupData Default =>
- new OrderBookStartupData(
- new FilterStates { statuses = new[] { OrderStatus.Working } },
- DefaultGrid,
- _default_show_right_panel,
- _default_right_panel_width,
- _default_fills_height,
- use_defaults: true) {
- show_order_params = _default_show_order_params,
- order_params_height = _default_order_params_height,
- fills_settings = DefaultFillsGrid
- };
-
- public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid) {
- algo_tree_display_mode = AlgoTreeDisplayMode.RootAndLeafNodes
- };
-
- public static OrderBookFillsGridSettings DefaultFillsGrid {
- get {
- var default_fills = FillsWindowFactory.StartupData.Default();
- var rv = new OrderBookFillsGridSettings {
- sorting_criterion = default_fills.sorting_criterion.ToList(),
- filters = default_fills.filters,
- general = FillsWindowFactory.StartupData.MiniGridSettings
- };
- return rv;
- }
- }
- static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.sorting_criterion);
+ }
+ return orderbook_grid;
+ }
+#pragma warning restore CS0612 // Type or member is obsolete
+
+ public static OrderBookStartupData Default =>
+ new OrderBookStartupData(
+ new FilterStates { statuses = new[] { OrderStatus.Working } },
+ DefaultGrid,
+ _default_show_right_panel,
+ _default_right_panel_width,
+ _default_fills_height,
+ use_defaults: true) {
+ show_order_params = _default_show_order_params,
+ order_params_height = _default_order_params_height,
+ fills_settings = DefaultFillsGrid
+ };
+
+ public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid) {
+ algo_tree_display_mode = AlgoTreeDisplayMode.RootAndLeafNodes
+ };
+
+ public static OrderBookFillsGridSettings DefaultFillsGrid {
+ get {
+ var default_fills = FillsWindowFactory.StartupData.Default();
+ var rv = new OrderBookFillsGridSettings {
+ sorting_criterion = default_fills.sorting_criterion.ToList(),
+ filters = default_fills.filters,
+ general = FillsWindowFactory.StartupData.MiniGridSettings
+ };
+ return rv;
+ }
+ }
+ static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.sorting_criterion);
public static OrderBookGridSettings default_mini_grid => new OrderBookGridSettings(GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion)) {
algo_tree_display_mode = AlgoTreeDisplayMode.RootAndLeafNodes
- };
-
- static class DefaultColumns {
- public static GridColumnSettings security => new GridColumnSettings(Columns.Security.ToString(), DIYGrid.DefaultColumnHeaders.Security, width: DIYGrid.DefaultColumnWidths.Security);
- public static GridColumnSettings symbol => new GridColumnSettings(Columns.Symbol.ToString(), DIYGrid.DefaultColumnHeaders.Symbol, width: DIYGrid.DefaultColumnWidths.Symbol, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings time_created => new GridColumnSettings(Columns.Time.ToString(), "Time", width: DIYGrid.DefaultColumnWidths.Time, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings last_change => new GridColumnSettings(Columns.LastChange.ToString(), "Last Change", width: DIYGrid.DefaultColumnWidths.Time, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings user => new GridColumnSettings(Columns.User.ToString(), DIYGrid.DefaultColumnHeaders.User, width: DIYGrid.DefaultColumnWidths.User, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings account => new GridColumnSettings(Columns.Account.ToString(), DIYGrid.DefaultColumnHeaders.Account, width: DIYGrid.DefaultColumnWidths.Account, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings exchange => new GridColumnSettings(Columns.Exchange.ToString(), DIYGrid.DefaultColumnHeaders.Exchange, width: DIYGrid.DefaultColumnWidths.Exchange, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings time_in_force => new GridColumnSettings(Columns.TimeInForce.ToString(), DIYGrid.DefaultColumnHeaders.TimeInForce, width: DIYGrid.DefaultColumnWidths.TimeInForce);
- public static GridColumnSettings order_type => new GridColumnSettings(Columns.OrderType.ToString(), DIYGrid.DefaultColumnHeaders.OrderType, width: DIYGrid.DefaultColumnWidths.OrderType);
- public static GridColumnSettings root_algo_type => new GridColumnSettings(Columns.RootAlgoType.ToString(), DIYGrid.DefaultColumnHeaders.RootAlgoType, width: DIYGrid.DefaultColumnWidths.OrderType);
- public static GridColumnSettings sub_type => new GridColumnSettings(Columns.SubType.ToString(), "Sub Type", width: 80, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings side => new GridColumnSettings(Columns.Side.ToString(), "B/S", width: DIYGrid.DefaultColumnWidths.Side, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings quantity => new GridColumnSettings(Columns.Size.ToString(), "Qty", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
- public static GridColumnSettings price => new GridColumnSettings(Columns.Price.ToString(), DIYGrid.DefaultColumnHeaders.Price, width: DIYGrid.DefaultColumnWidths.Price, horizontal_alignment: HorizontalAlignment.Right);
- public static GridColumnSettings filled_quantity => new GridColumnSettings(Columns.Filled.ToString(), "Filled Qty", width: DIYGrid.DefaultColumnWidths.Filled, horizontal_alignment: HorizontalAlignment.Right);
- public static GridColumnSettings avg_price => new GridColumnSettings(Columns.AvgFilled.ToString(), "Avg Filled", width: DIYGrid.DefaultColumnWidths.AveragePrice, horizontal_alignment: HorizontalAlignment.Right);
- public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
- public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings attached_target_order_key => new GridColumnSettings(Columns.AttachedTargetOrderKey.ToString(), DIYGrid.DefaultColumnHeaders.AttachedTargetOrderKey, width: DIYGrid.DefaultColumnWidths.ParentKey, horizontal_alignment: HorizontalAlignment.Left);
- public static GridColumnSettings piq => new GridColumnSettings(Columns.Piq.ToString(), "PIQ", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
-
- public static IEnumerable sorting_criterion {
- get {
- yield return new SortingCriteria(time_created.id, false);
- }
- }
-
- public static IEnumerable all {
- get {
- yield return security;
- yield return symbol;
- yield return time_created;
- yield return last_change;
- yield return user;
- yield return account;
- yield return exchange;
- yield return time_in_force;
- yield return order_type;
- yield return root_algo_type;
- yield return sub_type;
- yield return side;
- yield return quantity;
+ };
+
+ static class DefaultColumns {
+ public static GridColumnSettings security => new GridColumnSettings(Columns.Security.ToString(), DIYGrid.DefaultColumnHeaders.Security, width: DIYGrid.DefaultColumnWidths.Security);
+ public static GridColumnSettings symbol => new GridColumnSettings(Columns.Symbol.ToString(), DIYGrid.DefaultColumnHeaders.Symbol, width: DIYGrid.DefaultColumnWidths.Symbol, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings time_created => new GridColumnSettings(Columns.Time.ToString(), "Time", width: DIYGrid.DefaultColumnWidths.Time, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings last_change => new GridColumnSettings(Columns.LastChange.ToString(), "Last Change", width: DIYGrid.DefaultColumnWidths.Time, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings user => new GridColumnSettings(Columns.User.ToString(), DIYGrid.DefaultColumnHeaders.User, width: DIYGrid.DefaultColumnWidths.User, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings account => new GridColumnSettings(Columns.Account.ToString(), DIYGrid.DefaultColumnHeaders.Account, width: DIYGrid.DefaultColumnWidths.Account, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings exchange => new GridColumnSettings(Columns.Exchange.ToString(), DIYGrid.DefaultColumnHeaders.Exchange, width: DIYGrid.DefaultColumnWidths.Exchange, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings time_in_force => new GridColumnSettings(Columns.TimeInForce.ToString(), DIYGrid.DefaultColumnHeaders.TimeInForce, width: DIYGrid.DefaultColumnWidths.TimeInForce);
+ public static GridColumnSettings order_type => new GridColumnSettings(Columns.OrderType.ToString(), DIYGrid.DefaultColumnHeaders.OrderType, width: DIYGrid.DefaultColumnWidths.OrderType);
+ public static GridColumnSettings root_algo_type => new GridColumnSettings(Columns.RootAlgoType.ToString(), DIYGrid.DefaultColumnHeaders.RootAlgoType, width: DIYGrid.DefaultColumnWidths.OrderType);
+ public static GridColumnSettings sub_type => new GridColumnSettings(Columns.SubType.ToString(), "Sub Type", width: 80, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings side => new GridColumnSettings(Columns.Side.ToString(), "B/S", width: DIYGrid.DefaultColumnWidths.Side, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings quantity => new GridColumnSettings(Columns.Size.ToString(), "Qty", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
+ public static GridColumnSettings price => new GridColumnSettings(Columns.Price.ToString(), DIYGrid.DefaultColumnHeaders.Price, width: DIYGrid.DefaultColumnWidths.Price, horizontal_alignment: HorizontalAlignment.Right);
+ public static GridColumnSettings filled_quantity => new GridColumnSettings(Columns.Filled.ToString(), "Filled Qty", width: DIYGrid.DefaultColumnWidths.Filled, horizontal_alignment: HorizontalAlignment.Right);
+ public static GridColumnSettings avg_price => new GridColumnSettings(Columns.AvgFilled.ToString(), "Avg Filled", width: DIYGrid.DefaultColumnWidths.AveragePrice, horizontal_alignment: HorizontalAlignment.Right);
+ public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
+ public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings attached_target_order_key => new GridColumnSettings(Columns.AttachedTargetOrderKey.ToString(), DIYGrid.DefaultColumnHeaders.AttachedTargetOrderKey, width: DIYGrid.DefaultColumnWidths.ParentKey, horizontal_alignment: HorizontalAlignment.Left);
+ public static GridColumnSettings piq => new GridColumnSettings(Columns.Piq.ToString(), "PIQ", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
+
+ public static IEnumerable sorting_criterion {
+ get {
+ yield return new SortingCriteria(time_created.id, false);
+ }
+ }
+
+ public static IEnumerable all {
+ get {
+ yield return security;
+ yield return symbol;
+ yield return time_created;
+ yield return last_change;
+ yield return user;
+ yield return account;
+ yield return exchange;
+ yield return time_in_force;
+ yield return order_type;
+ yield return root_algo_type;
+ yield return sub_type;
+ yield return side;
+ yield return quantity;
yield return price;
- yield return piq;
- yield return filled_quantity;
- yield return avg_price;
- yield return last_price;
- yield return status;
- yield return last_message;
- yield return security_key;
- yield return order_key;
- yield return parent_key;
- yield return attached_target_order_key;
- }
- }
-
- private static HashSet _mini_mode_columns_to_hide = new HashSet {
- symbol, last_change, exchange, sub_type, quantity, price, avg_price, last_price, status, last_message, security_key, order_key, parent_key, attached_target_order_key
- };
-
- public static IEnumerable mini {
- get {
- foreach (var col_setting in all) {
- if (_mini_mode_columns_to_hide.Contains(col_setting)) {
- yield return col_setting.with(is_visible: false);
- } else {
- yield return col_setting;
- }
- }
- }
- }
- }
- }
+ yield return piq;
+ yield return filled_quantity;
+ yield return avg_price;
+ yield return last_price;
+ yield return status;
+ yield return last_message;
+ yield return security_key;
+ yield return order_key;
+ yield return parent_key;
+ yield return attached_target_order_key;
+ }
+ }
+
+ private static HashSet _mini_mode_columns_to_hide = new HashSet {
+ symbol, last_change, exchange, sub_type, quantity, price, avg_price, last_price, status, last_message, security_key, order_key, parent_key, attached_target_order_key
+ };
+
+ public static IEnumerable mini {
+ get {
+ foreach (var col_setting in all) {
+ if (_mini_mode_columns_to_hide.Contains(col_setting)) {
+ yield return col_setting.with(is_visible: false);
+ } else {
+ yield return col_setting;
+ }
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookView.xaml b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookView.xaml
index 16849cc70..a57e16bfe 100644
--- a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookView.xaml
+++ b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookView.xaml
@@ -548,7 +548,7 @@
Grid.Column="1"
Grid.Row="3"
Panel.ZIndex="1"
- Width="{StaticResource GridSplitterWidth}"
+ HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="{x:Static sp:OrderBookView.GridSplitterHeight}"
BorderThickness="0,1,0,0"
diff --git a/src/client/spark/Modules/Trading/PAndLWindowFactory.cs b/src/client/spark/Modules/Trading/PAndLWindowFactory.cs
index 486e261a9..07aba2002 100644
--- a/src/client/spark/Modules/Trading/PAndLWindowFactory.cs
+++ b/src/client/spark/Modules/Trading/PAndLWindowFactory.cs
@@ -19,12 +19,12 @@ using static mbts.ui.controls.DIYGrid;
namespace bts.shell {
internal class PAndLWindowFactory : ShellWindowFactory {
readonly IBus _bus;
- readonly PAndLModel _model;
+ readonly OrdersModel _orders_model;
readonly UserSettingsHub _settings_hub;
- public PAndLWindowFactory(IShellModule owner, IBus bus, UserSettingsHub settings_hub, PAndLModel model) : base(owner, "SparkPAndL") {
+ public PAndLWindowFactory(IShellModule owner, IBus bus, UserSettingsHub settings_hub, OrdersModel orders_model) : base(owner, "SparkPAndL") {
_bus = bus;
- _model = model;
+ _orders_model = orders_model;
_settings_hub = settings_hub;
_dispose = bus.subscribe(SparkTags.ShowPAndLTag).OnDispatcher().Subscribe(show);
}
@@ -45,7 +45,7 @@ namespace bts.shell {
state.grid,
get: us => us.pnl_grid,
set: (us, gs) => us.with(provided_pnl_gridsettings: gs));
- return new PAndLWindow(_model, this, _bus, state, SparkCommands.ShowPAndL.icon, settings_manager);
+ return new PAndLWindow(_orders_model, this, _bus, state, SparkCommands.ShowPAndL.icon, settings_manager);
}
[ProtoContract]
diff --git a/src/client/spark/Modules/Trading/TradingShellModule.cs b/src/client/spark/Modules/Trading/TradingShellModule.cs
index ab682751c..61234ddde 100644
--- a/src/client/spark/Modules/Trading/TradingShellModule.cs
+++ b/src/client/spark/Modules/Trading/TradingShellModule.cs
@@ -1,4 +1,5 @@
using bts.api;
+using bts.shell.manual_fills;
using bts.spark;
using mbts.persist;
using mbts.spark;
@@ -19,6 +20,7 @@ namespace bts.shell {
FillsWindowFactory _fwf;
PAndLWindowFactory _plwf;
AlgoStudioWindowFactory _aswf;
+ ManualFillsWindowFactory _mfwf;
[ImportingConstructor]
public TradingShellModule(
@@ -27,15 +29,15 @@ namespace bts.shell {
INotificationService notification_service,
INotificationServiceDataCache notification_service_data_cache,
UserSettingsHub settings_hub,
- OrdersModel orders_model,
- PAndLModel pandl_model,
+ OrdersModel orders_model,
md.MBOService mbo,
ErrorReporter error_reporter) {
_lwf = new LadderWindowFactory(this, bus, wm, settings_hub, orders_model, mbo);
_obwf = new OrderBookWindowFactory(this, bus, notification_service, notification_service_data_cache, orders_model, settings_hub);
_fwf = new FillsWindowFactory(this, bus, settings_hub, orders_model);
- _plwf = new PAndLWindowFactory(this, bus, settings_hub, pandl_model);
+ _plwf = new PAndLWindowFactory(this, bus, settings_hub, orders_model);
_aswf = new AlgoStudioWindowFactory(this, bus, orders_model, error_reporter);
+ _mfwf = new ManualFillsWindowFactory(this, bus, orders_model);
}
public ImageSource icon => Icons.Trades;
@@ -50,7 +52,8 @@ namespace bts.shell {
SparkCommands.ShowPAndL.complete(() => new PAndLWindowFactory.PAndLStartupData()),
SparkCommands.PickLadder,
SparkCommands.PickOrderTicket,
- SparkCommands.ShowAlgoStudio.complete(() => new AlgoStudioWindowFactory.StartupData())
+ SparkCommands.ShowAlgoStudio.complete(() => new AlgoStudioWindowFactory.StartupData()),
+ SparkCommands.ShowManualFills().complete(() => ManualFillsSettings.Default)
};
IEnumerable window_factories() {
@@ -59,6 +62,7 @@ namespace bts.shell {
yield return _fwf;
yield return _plwf;
yield return _aswf;
+ yield return _mfwf;
}
public Task create(Stream load_stream) =>
diff --git a/src/client/spark/Orders/FillTuple.cs b/src/client/spark/Orders/FillTuple.cs
index 7eb0b1f1b..bfcd80a5c 100644
--- a/src/client/spark/Orders/FillTuple.cs
+++ b/src/client/spark/Orders/FillTuple.cs
@@ -7,6 +7,7 @@ using static bts.api.orderman.Fill.Types;
namespace mbts.spark {
class FillTuple : IEquatable {
+ public static readonly Func key_fn = ft => ft.fill.FillKey;
public readonly FillImmutable fill;
public readonly OrderRecordImmutable? order;
public readonly SecurityImmutable? security;
diff --git a/src/client/spark/Orders/OrderDataHelper.cs b/src/client/spark/Orders/OrderDataHelper.cs
index e31fface7..96acc2caa 100644
--- a/src/client/spark/Orders/OrderDataHelper.cs
+++ b/src/client/spark/Orders/OrderDataHelper.cs
@@ -49,7 +49,7 @@ namespace mbts.spark.utilities {
public OrderFactory(AdminModel admin_model, DynamicOrderHelper dynamic_helper) {
_admin_model = admin_model;
_dynamic_helper = dynamic_helper;
- var algo_name_index = new HashSet>(OneOf.ValueEqualityComparer);
+ var algo_name_index = new HashSet>(OneOf.ValueEqualityComparer);
// add standard types
algo_name_index.AddRange(
EnumHelper.get_values_except(CustomOrderDefinition.CustomOneofCase.None)
@@ -58,7 +58,7 @@ namespace mbts.spark.utilities {
algo_name_index.AddRange(dynamic_helper.dynamic_types
.Select(dt => new OneOf(dt)));
// build abbreviation index
- _algo_abbreviation_index = DisplayNameHelper.get_word_tree_abbreviations(algo_name_index, oneof => oneof.value.ToString(), OneOf.ValueEqualityComparer);
+ _algo_abbreviation_index = DisplayNameHelper.get_word_tree_abbreviations(algo_name_index, oneof => oneof.value.ToString(), OneOf.ValueEqualityComparer);
}
public IObservable> subscribe_accounts() => _admin_model.on_accounts;
@@ -70,7 +70,7 @@ namespace mbts.spark.utilities {
public CustomOrderDefinition.CustomOneofCase default_order_type() =>
CustomOrderDefinition.CustomOneofCase.Limit;
- public CustomOrderDefinition.CustomOneofCase default_order_type(SecurityImmutable security, bool is_child=false) {
+ public CustomOrderDefinition.CustomOneofCase default_order_type(SecurityImmutable security, bool is_child = false) {
if (is_child) return CustomOrderDefinition.CustomOneofCase.Limit;
switch (security.ContractCase) {
case Security.ContractOneofCase.Synthetic: return CustomOrderDefinition.CustomOneofCase.Spreader;
@@ -78,7 +78,7 @@ namespace mbts.spark.utilities {
}
}
- public CustomOrderDefinition.CustomOneofCase default_order_type(SecurityImmutable? security, bool is_child=false) =>
+ public CustomOrderDefinition.CustomOneofCase default_order_type(SecurityImmutable? security, bool is_child = false) =>
security.HasValue ? default_order_type(security.Value, is_child) : default_order_type();
public TimeInForce default_time_in_force() =>
@@ -103,13 +103,13 @@ namespace mbts.spark.utilities {
}
}
- public IEnumerable default_order_types(SecurityImmutable? security, bool is_child=false) =>
+ public IEnumerable default_order_types(SecurityImmutable? security, bool is_child = false) =>
security.HasValue ? default_order_types(security.Value, is_child) : default_order_types();
public IEnumerable default_time_in_forces() =>
EnumHelper.get_values_except(TimeInForce.Undefined);
- public IEnumerable default_time_in_forces(SecurityImmutable security, bool is_child=false) =>
+ public IEnumerable default_time_in_forces(SecurityImmutable security, bool is_child = false) =>
default_time_in_forces();
public IEnumerable default_time_in_forces(SecurityImmutable security, CustomOrderDefinition.CustomOneofCase order_type, bool is_child = false) {
@@ -120,7 +120,7 @@ namespace mbts.spark.utilities {
return tifs;
}
- public IEnumerable default_time_in_forces(SecurityImmutable? security, bool is_child=false) =>
+ public IEnumerable default_time_in_forces(SecurityImmutable? security, bool is_child = false) =>
security.HasValue ? default_time_in_forces(security.Value, is_child) : default_time_in_forces();
public LadderSettings default_ladder_settings(SecurityImmutable security) {
@@ -201,6 +201,7 @@ namespace mbts.spark.utilities {
public LimitOrderDefinition limit_order() => OrderDataHelper.Defaults.LimitOrderDefinition();
public StopOrderDefinition stop_order() => OrderDataHelper.Defaults.StopOrderDefinition();
public StopLimitOrderDefinition stop_limit_order() => OrderDataHelper.Defaults.StopLimitOrderDefinition();
+ public GLBXIcebergOrderDefinition glbx_iceberg_order() => OrderDataHelper.Defaults.GLBXIcebergOrderDefinition();
public IcebergOrderDefinition iceberg_order() => OrderDataHelper.Defaults.IcebergOrderDefinition();
public TimeBoxOrderDefinition time_box_order() => OrderDataHelper.Defaults.TimeBoxOrderDefinition();
public TickOrderDefinition tick_order() => OrderDataHelper.Defaults.TickOrderDefinition();
@@ -226,14 +227,15 @@ namespace mbts.spark.utilities {
public CustomOrderDefinition custom_order(CustomOrderDefinition.CustomOneofCase order_type) {
var rv = new CustomOrderDefinition();
- switch(order_type) {
+ switch (order_type) {
case CustomOrderDefinition.CustomOneofCase.Market: rv.Market = market_order(); break;
case CustomOrderDefinition.CustomOneofCase.Limit: rv.Limit = limit_order(); break;
case CustomOrderDefinition.CustomOneofCase.Stop: rv.Stop = stop_order(); break;
case CustomOrderDefinition.CustomOneofCase.StopLimit: rv.StopLimit = stop_limit_order(); break;
+ case CustomOrderDefinition.CustomOneofCase.GlbxIceberg: rv.GlbxIceberg = glbx_iceberg_order(); break;
case CustomOrderDefinition.CustomOneofCase.Iceberg: rv.Iceberg = iceberg_order(); break;
case CustomOrderDefinition.CustomOneofCase.TimeBox: rv.TimeBox = time_box_order(); break;
- case CustomOrderDefinition.CustomOneofCase.Tick: rv.Tick = tick_order(); break;
+ case CustomOrderDefinition.CustomOneofCase.Tick: rv.Tick = tick_order(); break;
case CustomOrderDefinition.CustomOneofCase.Lean: rv.Lean = lean_order(); break;
case CustomOrderDefinition.CustomOneofCase.Join: rv.Join = join_order(); break;
case CustomOrderDefinition.CustomOneofCase.Top: rv.Top = top_order(); break;
@@ -244,7 +246,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Trigger: rv.Trigger = trigger_order(); break;
case CustomOrderDefinition.CustomOneofCase.Spreader: rv.Spreader = spreader_order(); break;
case CustomOrderDefinition.CustomOneofCase.Dynamic: rv.Dynamic = dynamic_order(); break;
- //case CustomOrderDefinition.CustomOneofCase.QueueHolder: rv.QueueHolder = queue_holder_order(); break;
+ //case CustomOrderDefinition.CustomOneofCase.QueueHolder: rv.QueueHolder = queue_holder_order(); break;
}
return rv;
}
@@ -257,6 +259,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Limit: return new OrderMetadata { KeyBinding = "L", Color = BTSColors.green.rgb_color(), NoProps = true };
case CustomOrderDefinition.CustomOneofCase.Stop: return new OrderMetadata { KeyBinding = "S", Color = BTSColors.red_orange.rgb_color(), NoProps = true };
case CustomOrderDefinition.CustomOneofCase.StopLimit: return new OrderMetadata { KeyBinding = "SL", Color = BTSColors.pale_green.rgb_color() };
+ case CustomOrderDefinition.CustomOneofCase.GlbxIceberg: return new OrderMetadata { KeyBinding = "GB", Color = BTSColors.Orders.glbx_iceberg_order };
case CustomOrderDefinition.CustomOneofCase.Iceberg: return new OrderMetadata { KeyBinding = "I", Color = BTSColors.pale_blue.rgb_color() };
case CustomOrderDefinition.CustomOneofCase.TimeBox: return new OrderMetadata { KeyBinding = "TB", Color = BTSColors.purple.rgb_color() };
case CustomOrderDefinition.CustomOneofCase.Tick: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.tick_order };
@@ -266,7 +269,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Cover: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.cover_order };
case CustomOrderDefinition.CustomOneofCase.Oco: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.oco_order };
case CustomOrderDefinition.CustomOneofCase.Pricer: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.pricer_order };
- case CustomOrderDefinition.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.tick_order };
+ case CustomOrderDefinition.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.off_order };
case CustomOrderDefinition.CustomOneofCase.Trigger: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.trigger_order };
case CustomOrderDefinition.CustomOneofCase.Spreader: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.spreader_order };
case CustomOrderDefinition.CustomOneofCase.Dynamic: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.top_order };
@@ -418,6 +421,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Limit: return new OrderMetadata { KeyBinding = "L", Color = BTSColors.green.rgb_color(), NoProps = true };
case CustomOrderDefinition.CustomOneofCase.Stop: return new OrderMetadata { KeyBinding = "S", Color = BTSColors.red_orange.rgb_color(), NoProps = true };
case CustomOrderDefinition.CustomOneofCase.StopLimit: return new OrderMetadata { KeyBinding = "SL", Color = BTSColors.pale_green.rgb_color() };
+ case CustomOrderDefinition.CustomOneofCase.GlbxIceberg: return new OrderMetadata { KeyBinding = "GB", Color = BTSColors.Orders.glbx_iceberg_order };
case CustomOrderDefinition.CustomOneofCase.Iceberg: return new OrderMetadata { KeyBinding = "I", Color = BTSColors.pale_blue.rgb_color() };
case CustomOrderDefinition.CustomOneofCase.TimeBox: return new OrderMetadata { KeyBinding = "TB", Color = BTSColors.purple.rgb_color() };
case CustomOrderDefinition.CustomOneofCase.Tick: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.tick_order };
@@ -427,7 +431,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Cover: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.cover_order };
case CustomOrderDefinition.CustomOneofCase.Oco: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.oco_order };
case CustomOrderDefinition.CustomOneofCase.Pricer: return new OrderMetadata { KeyBinding = "C", Color = BTSColors.Orders.pricer_order };
- case CustomOrderDefinition.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.tick_order };
+ case CustomOrderDefinition.CustomOneofCase.Offset: return new OrderMetadata { KeyBinding = "O", Color = BTSColors.Orders.off_order };
case CustomOrderDefinition.CustomOneofCase.Trigger: return new OrderMetadata { KeyBinding = "T", Color = BTSColors.Orders.trigger_order };
case CustomOrderDefinition.CustomOneofCase.Spreader: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.spreader_order };
case CustomOrderDefinition.CustomOneofCase.Dynamic: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.top_order };
@@ -440,6 +444,7 @@ namespace mbts.spark.utilities {
switch (algo_type) {
case CustomOrderDefinition.CustomOneofCase.Limit: return "LM";
case CustomOrderDefinition.CustomOneofCase.Cover: return "CV";
+ case CustomOrderDefinition.CustomOneofCase.GlbxIceberg: return "GB";
case CustomOrderDefinition.CustomOneofCase.Iceberg: return "IB";
case CustomOrderDefinition.CustomOneofCase.Lean: return "LN";
case CustomOrderDefinition.CustomOneofCase.Market: return "MA";
@@ -594,6 +599,7 @@ namespace mbts.spark.utilities {
CustomOrderDefinition.CustomOneofCase.Limit,
CustomOrderDefinition.CustomOneofCase.Stop,
CustomOrderDefinition.CustomOneofCase.StopLimit,
+ CustomOrderDefinition.CustomOneofCase.GlbxIceberg,
CustomOrderDefinition.CustomOneofCase.Iceberg,
CustomOrderDefinition.CustomOneofCase.Lean,
CustomOrderDefinition.CustomOneofCase.Join,
@@ -636,12 +642,12 @@ namespace mbts.spark.utilities {
var tgt_child = cad.get_child_from_impl(tgt_type_def);
copy_values(src_child, ref tgt_child);
}
- }
+ }
public static CustomOrderDefinition.CustomOneofCase get_order_type(IMessage order_type_def) =>
order_type_def != null && _algo_type_case_index.TryGetValue(order_type_def.Descriptor.ClrType, out CustomOrderDefinition.CustomOneofCase algo_case) ?
algo_case : CustomOrderDefinition.CustomOneofCase.None;
-
+
#region Private Members
// get child
static CustomOrderDefinitionImmutable? _get_iceberg_child(IcebergOrderDefinitionImmutable iceberg) => iceberg.HasChild ? iceberg.Child : (CustomOrderDefinitionImmutable?)null;
@@ -857,7 +863,7 @@ namespace mbts.spark.utilities {
int phase_mult = 1;
switch (def.CustomCase) {
case CustomOrderDefinition.CustomOneofCase.Cover:
- add_component(def.Cover.HedgeTicks.GetHashCode());
+ add_component(def.Cover.HedgeTicks.GetHashCode());
add_component(_get_hash(_get_cover_child(def.Cover)));
add_component(_get_hash(_get_cover_hedge(def.Cover)));
break;
@@ -981,6 +987,7 @@ namespace mbts.spark.utilities {
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Stop: rv.Stop = StopOrderDefinition(); break;
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.StopLimit: rv.StopLimit = StopLimitOrderDefinition(); break;
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Iceberg: rv.Iceberg = IcebergOrderDefinition(); break;
+ case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.GlbxIceberg: rv.GlbxIceberg = GLBXIcebergOrderDefinition(); break;
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.TimeBox: rv.TimeBox = TimeBoxOrderDefinition(); break;
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Tick: rv.Tick = TickOrderDefinition(); break;
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Lean: rv.Lean = LeanOrderDefinition(); break;
@@ -1004,6 +1011,7 @@ namespace mbts.spark.utilities {
public static LimitOrderDefinition LimitOrderDefinition() => new LimitOrderDefinition { };
public static StopOrderDefinition StopOrderDefinition() => new StopOrderDefinition { };
public static StopLimitOrderDefinition StopLimitOrderDefinition() => new StopLimitOrderDefinition { };
+ public static GLBXIcebergOrderDefinition GLBXIcebergOrderDefinition() => new GLBXIcebergOrderDefinition { MaxShowQuantity = 1 };
public static IcebergOrderDefinition IcebergOrderDefinition() => new IcebergOrderDefinition { Child = CustomOrderDefinition(), ShowQuantity = 1 };
public static TimeBoxOrderDefinition TimeBoxOrderDefinition() => new TimeBoxOrderDefinition { Child = CustomOrderDefinition(), Start = Timestamp.FromDateTime(DateTime.UtcNow), Stop = Timestamp.FromDateTime(DateTime.UtcNow) };
public static TickOrderDefinition TickOrderDefinition() => new TickOrderDefinition { Child = CustomOrderDefinition(), CrossThreshold = QuantityMeasure };
diff --git a/src/client/spark/Orders/OrderTypeVMs/GLBXIcebergOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/GLBXIcebergOrderVM.cs
new file mode 100644
index 000000000..b93f24632
--- /dev/null
+++ b/src/client/spark/Orders/OrderTypeVMs/GLBXIcebergOrderVM.cs
@@ -0,0 +1,16 @@
+using bts.api.orderman;
+
+namespace mbts.spark {
+ static partial class OrderTypeVMFactory {
+ class GLBXIcebergOrderVM : OrderTypeVMBase {
+ readonly Property _max_show_quantity;
+
+ public GLBXIcebergOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
+ : base(key, display_name, editing_permissions) {
+ _max_show_quantity = add_nullable_property(nameof(max_show_quantity), GLBXIcebergOrderDefinition.MaxShowQuantityFieldNumber);
+ }
+
+ public uint? max_show_quantity { get => _max_show_quantity.Value; set => _max_show_quantity.set(value); }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs
index 693dd9e25..5a4ae67d8 100644
--- a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs
+++ b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs
@@ -53,6 +53,7 @@ namespace mbts.spark {
public static IAlgoVM pricer(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new PricerOrderVM(key, display_name, editing_permissions);
public static IAlgoVM offset(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new OffsetOrderVM(key, display_name, editing_permissions);
public static IAlgoVM trigger(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new TriggerOrderVM(key, display_name, editing_permissions);
+ public static IAlgoVM glbx_iceberg(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new GLBXIcebergOrderVM(key, display_name, editing_permissions);
public static IAlgoVM iceberg(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new IcebergOrderVM(key, display_name, editing_permissions);
public static IAlgoVM spreader(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) => new SpreaderOrderVM(key, display_name, editing_permissions);
public static IAlgoVM dynamic(AlgoKey key, string display_name, string dynamic_type, AlgoEditingPermissions editing_permissions) => new DynamicOrderVM(key, dynamic_type, display_name, editing_permissions);
@@ -83,6 +84,7 @@ namespace mbts.spark {
case AlgoType.Pricer: return pricer(key, name, editing_permissions);
case AlgoType.Offset: vm = offset(key, name, editing_permissions); break;
case AlgoType.Trigger: vm = trigger(key, name, editing_permissions); break;
+ case AlgoType.GlbxIceberg: vm = glbx_iceberg(key, name, editing_permissions); break;
case AlgoType.Iceberg: vm = iceberg(key, name, editing_permissions); break;
case AlgoType.Spreader: vm = spreader(key, name, editing_permissions); break;
case AlgoType.Dynamic: vm = dynamic(key, name, name, editing_permissions); break;
diff --git a/src/client/spark/Orders/OrderUtils.cs b/src/client/spark/Orders/OrderUtils.cs
index 8db96ac25..aa1a68d1b 100644
--- a/src/client/spark/Orders/OrderUtils.cs
+++ b/src/client/spark/Orders/OrderUtils.cs
@@ -79,6 +79,23 @@ namespace mbts.spark {
public static CustomOrderDefinition.CustomOneofCase order_type(this OrderRecordImmutable order) =>
order.HasDef && order.Def.HasCustomDef ? order.Def.CustomDef.CustomCase : CustomOrderDefinition.CustomOneofCase.None;
+ ///
+ /// Unwraps all s (if any) to return the underlying order type.
+ ///
+ /// The order who's underlying algo will be returned.
+ /// The first non-composite algo definition in the specified .
+ public static CustomOrderDefinition.CustomOneofCase actual_order_type(this OrderRecordImmutable order) {
+ if (!order.HasDef || !order.Def.HasCustomDef)
+ return CustomOrderDefinition.CustomOneofCase.None;
+ var cdef = order.Def.CustomDef;
+ while (cdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite) {
+ if (!cdef.Composite.HasDefinition)
+ return CustomOrderDefinition.CustomOneofCase.None;
+ cdef = cdef.Composite.Definition;
+ }
+ return cdef.CustomCase;
+ }
+
public static string dynamic_order_type_display_name(this OrderRecordImmutable order) =>
order.HasDef && order.Def.HasCustomDef && order.Def.CustomDef.HasDynamic ? order.Def.CustomDef.Dynamic.DynamicOrderType : string.Empty;
@@ -112,7 +129,8 @@ namespace mbts.spark {
case CustomOrderDefinition.CustomOneofCase.Limit:
case CustomOrderDefinition.CustomOneofCase.Market:
case CustomOrderDefinition.CustomOneofCase.Stop:
- case CustomOrderDefinition.CustomOneofCase.StopLimit: return true;
+ case CustomOrderDefinition.CustomOneofCase.StopLimit:
+ case CustomOrderDefinition.CustomOneofCase.GlbxIceberg: return true;
}
}
return false;
diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs
index ff235e625..5b6811339 100644
--- a/src/client/spark/Orders/OrdersModel.cs
+++ b/src/client/spark/Orders/OrdersModel.cs
@@ -39,7 +39,7 @@ namespace mbts.spark {
readonly OrderActivitySummarizer _activity;
readonly TableUpdateDemuxer _security_orders_demuxer;
readonly TableUpdateDemuxer _security_working_orders_with_piq_demuxer;
- readonly TableUpdateDemuxer _security_positions_demuxer;
+ readonly TableUpdateDemuxer<(SecurityImmutable?, PositionUnitImmutable), int, uint> _security_positions_demuxer;
IDisposable _dispose;
[ImportingConstructor]
@@ -67,7 +67,7 @@ namespace mbts.spark {
.Table()
.Cache();
- on_positions = _position_service.subscribei_position_data().Naggle(interval, scheduler).PermissionFilter(admin_model.on_admin_data).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();
working_orders =
on_orders.Scan(
ImmutableDictionary.Empty,
@@ -83,7 +83,7 @@ namespace mbts.spark {
_activity = new OrderActivitySummarizer(bus, on_orders);
_security_orders_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key());
_security_working_orders_with_piq_demuxer = new TableUpdateDemuxer(o => o.order.Key, o => o.order.security_key());
- _security_positions_demuxer = new TableUpdateDemuxer(o => o.RecordId, p => p.SecurityId);
+ _security_positions_demuxer = new TableUpdateDemuxer<(SecurityImmutable?, PositionUnitImmutable pos), int, uint>(o => o.pos.RecordId, p => p.pos.SecurityId);
studio_algos_with_meta = algo_model.definitions.LeftJoin(
algo_model.metadata_service.subscribe_metadata().Table(m => m.id),
d => d.key,
@@ -142,6 +142,28 @@ namespace mbts.spark {
(f, fk, ok) => new FillTuple(f, null),
f => f.fill.FillKey);
on_fill_tuples = fill_order_tuples_join.Cache();
+ // manual fills
+ on_manual_fills_securities = _position_service.subscribei_manual_fills()
+ .Naggle(interval, scheduler)
+ .join(sstore, mf => mf.SecurityKey)
+ .Table().Cache();
+ var manual_fill_tuples_account_join = on_manual_fills_securities.LeftJoin(
+ admin_model.on_accounts.Select(d => MappedDictionary.create(d, kv => new AccountTuple(kv.Key, kv.Value))).Table(a => a.id),
+ mfs => mfs.Item2.RecordId,
+ AccountTuple.key_fn,
+ mfs => mfs.Item2.AccountId,
+ (mfs, mf_id, a, a_id) => new ManualFillTuple(mfs.Item2, mfs.Item1, a, null),
+ (mfs, mf_id, a_id) => new ManualFillTuple(mfs.Item2, mfs.Item1, null, null),
+ ManualFillTuple.key_fn);
+ on_manual_fill_tuples = manual_fill_tuples_account_join.LeftJoin(
+ admin_model.on_users.Select(d => MappedDictionary.create(d, kv => new UserTuple(kv.Key, kv.Value))).Table(a => a.id),
+ ManualFillTuple.key_fn,
+ UserTuple.key_fn,
+ mft => mft.manual_fill.UserId,
+ (mft, mft_id, u, u_id) => new ManualFillTuple(mft.manual_fill, mft.security, mft.account, u),
+ (mft, mft_id, u_id) => mft,
+ ManualFillTuple.key_fn)
+ .Cache();
// can attach
on_orders_can_attach = on_orders.ParentDependent(
t => t.order.Key,
@@ -184,8 +206,10 @@ namespace mbts.spark {
public IObservable> on_order_securities { get; }
public IObservable> on_fill_tuples { get; }
public IObservable> working_orders { get; }
- public IObservable> on_positions { get; }
+ public IObservable> on_positions { get; }
public IObservable> studio_algos_with_meta { get; }
+ public IObservable> on_manual_fills_securities { get; }
+ public IObservable> on_manual_fill_tuples { get; }
public AdminModel admin_model { get; }
public MBOService mbo_service => _mbo_service;
@@ -197,7 +221,7 @@ namespace mbts.spark {
public IObservable> on_security_orders(uint security) =>
_security_orders_demuxer.subscribe(security);
- public IObservable> on_security_positions(uint security) =>
+ public IObservable> on_security_positions(uint security) =>
_security_positions_demuxer.subscribe(security);
#endregion
@@ -267,6 +291,45 @@ namespace mbts.spark {
(uint? key, string error) _handle_error(Result result, string template) =>
_error.handle_error(result, template, r => r.ErrorCode, e => e == OrderError.Ok, r => new uint?(r.OrderKey));
+
+ #region Manual Fillls
+ public async Task create_manual_fills(IEnumerable fills) {
+ return await create_manual_fills(_create_fill_batch(fills));
+ }
+ public async Task create_manual_fills(ManualFillBatchImmutable fills) {
+ var result = await _position_service.create_manual_fill_async(fills);
+ return _handle_error(result);
+ }
+
+ public async Task update_manual_fills(IEnumerable fills) {
+ return await update_manual_fills(_create_fill_batch(fills));
+ }
+ public async Task update_manual_fills(ManualFillBatchImmutable fills) {
+ var result = await _position_service.update_manual_fill_async(fills);
+ return _handle_error(result);
+ }
+
+ public async Task delete_manual_fills(IEnumerable fills) {
+ return await delete_manual_fills(_create_fill_batch(fills));
+ }
+ public async Task delete_manual_fills(ManualFillBatchImmutable fills) {
+ var result = await _position_service.remove_manual_fill_async(fills);
+ return _handle_error(result);
+ }
+
+ ManualFillBatchImmutable _create_fill_batch(IEnumerable fills) {
+ var batch = new ManualFillBatch();
+ batch.ManualFill.AddRange(fills);
+ return new ManualFillBatchImmutable(batch);
+ }
+
+ bool _handle_error(Result result) {
+ if (!result.success)
+ _error.report_error(result.error_message);
+ return result.value.Response.All(r => r.Ok);
+ }
+ #endregion // Manual Fills
+
#endregion
public void Dispose() =>
@@ -362,10 +425,10 @@ namespace mbts.spark {
public static IObservable security_total_position(this OrdersModel orders_model, uint security_key, string account) =>
orders_model.on_security_positions(security_key)
- .Select(t => {
+ .Select((t,k) => {
foreach (var kv in t.state) {
- if (kv.Value.Account == account)
- return kv.Value.total_pos();
+ if (kv.Value.Item2.Account == account)
+ return kv.Value.Item2.total_pos();
}
return double.NaN;
}).DistinctUntilChanged()
diff --git a/src/client/spark/core/Bus/SparkCommands.cs b/src/client/spark/core/Bus/SparkCommands.cs
index 88291a993..2dce59fc9 100644
--- a/src/client/spark/core/Bus/SparkCommands.cs
+++ b/src/client/spark/core/Bus/SparkCommands.cs
@@ -1,15 +1,15 @@
using bts.api;
using bts.api.orderman;
using bts.shell;
+using bts.shell.manual_fills;
+using mbts;
using mbts.spark;
using mbts.ui;
-using mbts;
using System;
using System.Collections.Generic;
using System.Windows.Input;
-namespace bts.spark
-{
+namespace bts.spark {
static class SparkCommands {
// Market
public static PartialCommand ShowMarketView =>
@@ -30,6 +30,9 @@ namespace bts.spark
public static PartialCommand ShowFills(KeyGesture key_gesture = null) =>
SparkCommand.create("Fills", Icons.Payment, SparkTags.ShowFillsTag, key_gesture);
+ public static PartialCommand ShowManualFills(KeyGesture key_gesture = null) =>
+ SparkCommand.create("Manual Fills", Icons.DataEdit, SparkTags.ShowManualFillsTag, key_gesture);
+
public static PartialCommand ShowPAndL =>
SparkCommand.create("P&L", Icons.Accounting, SparkTags.ShowPAndLTag);
diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs
index d32380fe1..c1c683f1c 100644
--- a/src/client/spark/core/Bus/SparkTags.cs
+++ b/src/client/spark/core/Bus/SparkTags.cs
@@ -1,6 +1,7 @@
using bts.api;
using bts.api.orderman;
using bts.shell;
+using bts.shell.manual_fills;
using bts.spark;
using mbts.ui;
using System;
@@ -52,6 +53,7 @@ namespace mbts.spark
#region Spark Window
public static ITag ShowFillsTag { get; } = new SparkTag(nameof(ShowFillsTag));
+ public static ITag ShowManualFillsTag { get; } = new SparkTag(nameof(ShowManualFillsTag));
// TODO: maybe get rid of the singlular ShowLadderTag, and just use the plural ShowLaddersTag.
// 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.
diff --git a/src/client/spark/core/Collections/ObservableAutoWrapper.cs b/src/client/spark/core/Collections/ObservableAutoWrapper.cs
index d0de4fc77..579bae41b 100644
--- a/src/client/spark/core/Collections/ObservableAutoWrapper.cs
+++ b/src/client/spark/core/Collections/ObservableAutoWrapper.cs
@@ -83,10 +83,10 @@ namespace mbts.ui.utility {
}
}
- public static IDisposable connect(ObservableCollection source, ObservableCollection target, Func create, Action on_removed = null) =>
+ public static IDisposable connect(ObservableCollection source, IList target, Func create, Action on_removed = null) =>
connect, T, TResult>(source, target, create, null);
- public static IDisposable connect(TCollection source, ObservableCollection target, Func create, Action on_removed = null)
+ public static IDisposable connect(TCollection source, IList target, Func create, Action on_removed = null)
where TCollection : IReadOnlyList, INotifyCollectionChanged {
Action reset_cb;
Action removed_cb,
@@ -105,7 +105,8 @@ namespace mbts.ui.utility {
if (i < 0) {
throw new InvalidOperationException("Source collection invoked a CollectionChanged 'Removed' event without a valid 'OldStartingIndex.'");
} else {
- target.RemoveRange(i, old_items.Count);
+ for (int j = 0; j < old_items.Count; j++)
+ target.RemoveAt(i);
}
};
} else {
diff --git a/src/client/spark/core/Collections/RefCountMap.cs b/src/client/spark/core/Collections/RefCountMap.cs
index 7a98672ef..be9fb8678 100644
--- a/src/client/spark/core/Collections/RefCountMap.cs
+++ b/src/client/spark/core/Collections/RefCountMap.cs
@@ -9,7 +9,7 @@ namespace mbts.collections {
int count { get; }
}
- class RefCountMap : IEnumerable>, ICollection {
+ class RefCountMap : IReadOnlyCollection>, ICollection {
readonly IEqualityComparer _key_comparer;
readonly Dictionary _dictionary;
@@ -28,7 +28,7 @@ namespace mbts.collections {
public object SyncRoot => null;
public bool IsSynchronized => false;
public int this[TKey key] => _dictionary[key].count;
- public ICollection keys => _dictionary.Keys;
+ public IReadOnlyCollection keys => _dictionary.Keys;
public bool contains_key(TKey key) => _dictionary.ContainsKey(key);
public void CopyTo(Array array, int index) =>
@@ -241,4 +241,4 @@ namespace mbts.collections {
return ref_count_map.Count > count_before;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/core/Commands/AsyncCommand.cs b/src/client/spark/core/Commands/AsyncCommand.cs
index f70531eed..5b2471962 100644
--- a/src/client/spark/core/Commands/AsyncCommand.cs
+++ b/src/client/spark/core/Commands/AsyncCommand.cs
@@ -73,7 +73,7 @@ namespace mbts.ui {
public AsyncCommand(Func execute)
: base(_ => execute()) { }
- public AsyncCommand(Func execute, Func can_execute)
+ public AsyncCommand(Func execute, Func can_execute, bool allow_concurrent_executions = false)
: base(_ => execute(), _ => can_execute()) { }
public AsyncCommand(Func