SPARK-1510 organize orderbook types
This commit is contained in:
1 parent
8e43f96331
commit
2ac73e3671
15 files changed
+228
-1248
No files matched your search
+19
-19
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class CVOrderBookRowVM {
|
||||
partial class OrderBookRowVM {
|
||||
public interface IOrderBookCell : IComparable {
|
||||
string text { get; }
|
||||
}
|
||||
@@ -15,55 +15,55 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public interface IOrderBookCellStore {
|
||||
CVOrderBookRowVM row { get; }
|
||||
OrderBookRowVM row { get; }
|
||||
ICVOrderBookColumn column { get; }
|
||||
string prop_name { get; }
|
||||
IOrderBookCell current { get; }
|
||||
//
|
||||
IOrderBookCellStore select_other(CVOrderBookRowVM row);
|
||||
IOrderBookCellStore select_other(OrderBookRowVM row);
|
||||
bool refresh(bool force_refresh);
|
||||
void regenerate_cell();
|
||||
}
|
||||
|
||||
public interface IOrderBookCellStore<T> : IOrderBookCellStore, IComparer<T>, IEqualityComparer<T> {
|
||||
new IOrderBookCell<T> current { get; }
|
||||
new IOrderBookCellStore<T> select_other(CVOrderBookRowVM row);
|
||||
new IOrderBookCellStore<T> select_other(OrderBookRowVM row);
|
||||
//
|
||||
T get_value(CVOrderBookRowVM row);
|
||||
T get_value(OrderBookRowVM row);
|
||||
string format(T value);
|
||||
}
|
||||
|
||||
public static class CellFactory {
|
||||
public static IOrderBookCellStore<T> create<T>(CVOrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<CVOrderBookRowVM, T> get_value, Func<CVOrderBookRowVM, IOrderBookCellStore<T>> select_other, Func<T, string> format = null) =>
|
||||
public static IOrderBookCellStore<T> create<T>(OrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<OrderBookRowVM, T> get_value, Func<OrderBookRowVM, IOrderBookCellStore<T>> select_other, Func<T, string> format = null) =>
|
||||
new OrderBookCellStore<T>(row, column, prop_name, get_value, select_other, format, new Comparison<T>(Comparer<T>.Default.Compare), EqualityComparer<T>.Default);
|
||||
|
||||
public static IOrderBookCellStore<T> create<T>(CVOrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<CVOrderBookRowVM, T> get_value, Func<CVOrderBookRowVM, IOrderBookCellStore<T>> select_other, Comparison<T> comparison, Func<T, string> format = null) =>
|
||||
public static IOrderBookCellStore<T> create<T>(OrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<OrderBookRowVM, T> get_value, Func<OrderBookRowVM, IOrderBookCellStore<T>> select_other, Comparison<T> comparison, Func<T, string> format = null) =>
|
||||
new OrderBookCellStore<T>(row, column, prop_name, get_value, select_other, format, comparison, EqualityComparer<T>.Default);
|
||||
|
||||
public static IOrderBookCellStore<T?> create_nullable<T>(CVOrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<CVOrderBookRowVM, T?> get_value, Func<CVOrderBookRowVM, IOrderBookCellStore<T?>> select_other, Func<T?, string> format = null)
|
||||
public static IOrderBookCellStore<T?> create_nullable<T>(OrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<OrderBookRowVM, T?> get_value, Func<OrderBookRowVM, IOrderBookCellStore<T?>> select_other, Func<T?, string> format = null)
|
||||
where T : struct => new OrderBookCellStore<T?>(row, column, prop_name, get_value, select_other, format, CompareUtils.nullable_comparison<T>(Comparer<T>.Default.Compare), EqualityComparer.CreateNullable<T>(EqualityComparer<T>.Default.Equals));
|
||||
|
||||
public static IOrderBookCellStore<T?> create_nullable<T>(CVOrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<CVOrderBookRowVM, T?> get_value, Func<CVOrderBookRowVM, IOrderBookCellStore<T?>> select_other, Func<T, T, int> compare, Func<T?, string> format = null)
|
||||
public static IOrderBookCellStore<T?> create_nullable<T>(OrderBookRowVM row, ICVOrderBookColumn column, string prop_name, Func<OrderBookRowVM, T?> get_value, Func<OrderBookRowVM, IOrderBookCellStore<T?>> select_other, Func<T, T, int> compare, Func<T?, string> format = null)
|
||||
where T : struct =>
|
||||
new OrderBookCellStore<T?>(row, column, prop_name, get_value, select_other, format, CompareUtils.nullable_comparison(compare), EqualityComparer.CreateNullable<T>(EqualityComparer<T>.Default.Equals));
|
||||
|
||||
class OrderBookCellStore<T> : IOrderBookCellStore<T> {
|
||||
readonly CVOrderBookRowVM _row;
|
||||
readonly OrderBookRowVM _row;
|
||||
readonly ICVOrderBookColumn _column;
|
||||
readonly string _prop_name;
|
||||
readonly Func<CVOrderBookRowVM, T> _get_value;
|
||||
readonly Func<CVOrderBookRowVM, IOrderBookCellStore<T>> _select_other;
|
||||
readonly Func<OrderBookRowVM, T> _get_value;
|
||||
readonly Func<OrderBookRowVM, IOrderBookCellStore<T>> _select_other;
|
||||
readonly Func<T, string> _format;
|
||||
readonly Comparison<T> _comparison;
|
||||
readonly IEqualityComparer<T> _eq_comparer;
|
||||
OrderBookCell<T> _current;
|
||||
|
||||
public OrderBookCellStore(
|
||||
CVOrderBookRowVM row,
|
||||
OrderBookRowVM row,
|
||||
ICVOrderBookColumn column,
|
||||
string prop_name,
|
||||
Func<CVOrderBookRowVM, T> get_value,
|
||||
Func<CVOrderBookRowVM, IOrderBookCellStore<T>> select_other,
|
||||
Func<OrderBookRowVM, T> get_value,
|
||||
Func<OrderBookRowVM, IOrderBookCellStore<T>> select_other,
|
||||
Func<T, string> format,
|
||||
Comparison<T> comparison,
|
||||
IEqualityComparer<T> eq_comparer) {
|
||||
@@ -79,7 +79,7 @@ namespace mbts.spark {
|
||||
_current = new OrderBookCell<T>(this, _get_value(_row));
|
||||
}
|
||||
|
||||
public CVOrderBookRowVM row => _row;
|
||||
public OrderBookRowVM row => _row;
|
||||
public ICVOrderBookColumn column => _column;
|
||||
public string prop_name => _prop_name;
|
||||
public IOrderBookCell<T> current => _current;
|
||||
@@ -89,9 +89,9 @@ namespace mbts.spark {
|
||||
public bool Equals(T x, T y) => _eq_comparer.Equals(x, y);
|
||||
public string format(T value) => _format(value);
|
||||
public int GetHashCode(T obj) => _eq_comparer.GetHashCode(obj);
|
||||
public T get_value(CVOrderBookRowVM row) => _get_value(row);
|
||||
public IOrderBookCellStore<T> select_other(CVOrderBookRowVM row) => _select_other(row);
|
||||
IOrderBookCellStore IOrderBookCellStore.select_other(CVOrderBookRowVM row) => select_other(row);
|
||||
public T get_value(OrderBookRowVM row) => _get_value(row);
|
||||
public IOrderBookCellStore<T> select_other(OrderBookRowVM row) => _select_other(row);
|
||||
IOrderBookCellStore IOrderBookCellStore.select_other(OrderBookRowVM row) => select_other(row);
|
||||
|
||||
public bool refresh(bool force_refresh = false) {
|
||||
T v = _get_value(_row);
|
||||
+111
-111
@@ -37,171 +37,171 @@ namespace mbts.spark {
|
||||
interface ICVOrderBookColumn : IKeyedColumn<Columns> {
|
||||
string sort_member_path { get; }
|
||||
ListSortDirection? SortDirection { get; }
|
||||
IDataGridColumnFilter<CVOrderBookRowVM> filter { get; }
|
||||
IDataGridColumnFilter<OrderBookRowVM> filter { get; }
|
||||
}
|
||||
|
||||
partial class CVOrderBookVM {
|
||||
partial class OrderBookVM {
|
||||
public class CVOrderBookColumnCollection : ObservableCollection<ColumnBase>, IDisposable {
|
||||
public CVOrderBookColumnCollection(IBus bus, OrdersModel model, OrderBookStartupData startup_data, IObservable<(IEnumerable<SecurityImmutable> added, IEnumerable<SecurityImmutable> removed)> order_securities) {
|
||||
// security
|
||||
Add(security_column = new SecurityColumn(this,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, SecurityImmutable, SecurityCriteria>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, SecurityImmutable, SecurityCriteria>(
|
||||
order_securities,
|
||||
r => r.security.value.GetValueOrDefault(SecurityDataHelper.Defaults.SecurityImmutable),
|
||||
SecurityCriteria.from_securities,
|
||||
SecurityCriteria.get_to_securities(bus),
|
||||
nameof(CVOrderBookRowVM.security),
|
||||
nameof(OrderBookRowVM.security),
|
||||
EqualityComparer.Create<SecurityImmutable, uint>(s => s.Id),
|
||||
SecurityHelper.Comparer.InstanceImmutable
|
||||
)));
|
||||
// time_created
|
||||
Add(time_created_column = new TimeCreatedColumn(
|
||||
new TimeFilterVM<CVOrderBookRowVM>(r => r.time_created.value, value_path(nameof(OrderBookRowVM.time_created)))));
|
||||
new TimeFilterVM<OrderBookRowVM>(r => r.time_created.value, value_path(nameof(OrderBookRowVM.time_created)))));
|
||||
// last_change
|
||||
Add(last_change_column = new LastChangeTimeColumn(
|
||||
new TimeFilterVM<CVOrderBookRowVM>(r => r.last_change.value, value_path(nameof(CVOrderBookRowVM.last_change)))));
|
||||
new TimeFilterVM<OrderBookRowVM>(r => r.last_change.value, value_path(nameof(OrderBookRowVM.last_change)))));
|
||||
// user
|
||||
Add(user_column = new SimpleTextColumn<string[]>(
|
||||
Columns.User,
|
||||
DefaultColumnHeaders.User,
|
||||
nameof(CVOrderBookRowVM.user),
|
||||
nameof(OrderBookRowVM.user),
|
||||
r => r.user.value,
|
||||
DefaultColumnWidths.User,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, string>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, string>(
|
||||
model.factory.subscribe_users(),
|
||||
r => r.user.value,
|
||||
value_path(nameof(CVOrderBookRowVM.user))),
|
||||
value_path(nameof(OrderBookRowVM.user))),
|
||||
DataGridFilterKnownTemplates.DiscreteValues));
|
||||
// account
|
||||
Add(account_column = new SimpleTextColumn<string[]>(
|
||||
Columns.Account,
|
||||
DefaultColumnHeaders.Account,
|
||||
nameof(CVOrderBookRowVM.account),
|
||||
nameof(OrderBookRowVM.account),
|
||||
r => r.account.value,
|
||||
DefaultColumnWidths.Account,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, string, string[]>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, string, string[]>(
|
||||
model.factory.subscribe_accounts(),
|
||||
r => r.account.value,
|
||||
vals => vals.ToArray(),
|
||||
vals => Observable.Return(vals),
|
||||
value_path(nameof(CVOrderBookRowVM.account))),
|
||||
value_path(nameof(OrderBookRowVM.account))),
|
||||
DataGridFilterKnownTemplates.DiscreteValues));
|
||||
// exchange
|
||||
Add(exchange_column = new SimpleTextColumn<Venue[]>(
|
||||
Columns.Exchange,
|
||||
DefaultColumnHeaders.Exchange,
|
||||
nameof(CVOrderBookRowVM.exchange),
|
||||
nameof(OrderBookRowVM.exchange),
|
||||
r => r.exchange.text,
|
||||
DefaultColumnWidths.Exchange,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, Venue>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, Venue>(
|
||||
EnumHelper.get_values_except(Venue.Unset).ToList(),
|
||||
r => r.exchange.value,
|
||||
value_path(nameof(CVOrderBookRowVM.exchange))),
|
||||
value_path(nameof(OrderBookRowVM.exchange))),
|
||||
DataGridFilterKnownTemplates.EnumValues));
|
||||
// time in force
|
||||
Add(time_in_force_column = new SimpleTextColumn<TimeInForce[]>(
|
||||
Columns.TimeInForce,
|
||||
DefaultColumnHeaders.TimeInForce,
|
||||
nameof(CVOrderBookRowVM.time_in_force),
|
||||
nameof(OrderBookRowVM.time_in_force),
|
||||
r => r.time_in_force.text,
|
||||
DefaultColumnWidths.TimeInForce,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, TimeInForce>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, TimeInForce>(
|
||||
EnumHelper.get_values<TimeInForce>().ToList(),
|
||||
r => r.time_in_force.value,
|
||||
value_path(nameof(CVOrderBookRowVM.time_in_force))),
|
||||
value_path(nameof(OrderBookRowVM.time_in_force))),
|
||||
DataGridFilterKnownTemplates.EnumValues));
|
||||
// order type
|
||||
Add(order_type_column = new OrderBookOrderTypeColumn(
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, OrderType>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, OrderType>(
|
||||
EnumHelper.get_values_except(OrderType.None).ToList(),
|
||||
r => r.order_type.value,
|
||||
value_path(nameof(CVOrderBookRowVM.order_type)))));
|
||||
value_path(nameof(OrderBookRowVM.order_type)))));
|
||||
// order sub type
|
||||
Add(sub_type_column = new SimpleTextColumn<OrderSubType[]>(
|
||||
Columns.SubType,
|
||||
"Sub Type",
|
||||
nameof(CVOrderBookRowVM.order_sub_type),
|
||||
nameof(OrderBookRowVM.order_sub_type),
|
||||
r => r.order_sub_type.text,
|
||||
80,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, OrderSubType>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, OrderSubType>(
|
||||
EnumHelper.get_values<OrderSubType>().ToList(),
|
||||
r => r.order_sub_type.value,
|
||||
value_path(nameof(CVOrderBookRowVM.order_sub_type))),
|
||||
value_path(nameof(OrderBookRowVM.order_sub_type))),
|
||||
SubTypeFilterTemplateKey));
|
||||
// side
|
||||
Add(side_column = new SideColumn(
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, Side>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, Side>(
|
||||
new[] { Side.Buy, Side.Sell },
|
||||
r => r.side.value,
|
||||
value_path(nameof(CVOrderBookRowVM.side)))));
|
||||
value_path(nameof(OrderBookRowVM.side)))));
|
||||
// quantity
|
||||
Add(qty_column = new SizeColumn(
|
||||
new UIntMinMax<CVOrderBookRowVM>(r => r.quantity.value, value_path(nameof(CVOrderBookRowVM.quantity)))));
|
||||
new UIntMinMax<OrderBookRowVM>(r => r.quantity.value, value_path(nameof(OrderBookRowVM.quantity)))));
|
||||
// price
|
||||
Add(price_column = new PriceColumn(
|
||||
new DoubleMinMax<CVOrderBookRowVM>(r => r.price.value, value_path(nameof(CVOrderBookRowVM.price)))));
|
||||
new DoubleMinMax<OrderBookRowVM>(r => r.price.value, value_path(nameof(OrderBookRowVM.price)))));
|
||||
// filled quantity
|
||||
Add(filled_qty_column = new FilledColumn(
|
||||
new UIntMinMax<CVOrderBookRowVM>(r => r.filled_quantity.value, value_path(nameof(CVOrderBookRowVM.filled_quantity)))));
|
||||
new UIntMinMax<OrderBookRowVM>(r => r.filled_quantity.value, value_path(nameof(OrderBookRowVM.filled_quantity)))));
|
||||
// avg filled price
|
||||
Add(avg_price_column = new AvgFilledColumn(
|
||||
new DoubleMinMax<CVOrderBookRowVM>(r => r.avg_price.value, value_path(nameof(CVOrderBookRowVM.avg_price)))));
|
||||
new DoubleMinMax<OrderBookRowVM>(r => r.avg_price.value, value_path(nameof(OrderBookRowVM.avg_price)))));
|
||||
// last filled price
|
||||
Add(last_price_column = new LastFilledColumn(
|
||||
new DoubleMinMax<CVOrderBookRowVM>(r => r.last_price.value, value_path(nameof(CVOrderBookRowVM.last_price)))));
|
||||
new DoubleMinMax<OrderBookRowVM>(r => r.last_price.value, value_path(nameof(OrderBookRowVM.last_price)))));
|
||||
// status
|
||||
Add(status_column = new SimpleTextColumn<OrderStatus[]>(
|
||||
Columns.Status,
|
||||
"Status",
|
||||
nameof(CVOrderBookRowVM.status),
|
||||
nameof(OrderBookRowVM.status),
|
||||
r => r.status.text,
|
||||
80,
|
||||
DiscreteValuesFilterVM.Create<CVOrderBookRowVM, OrderStatus>(
|
||||
DiscreteValuesFilterVM.Create<OrderBookRowVM, OrderStatus>(
|
||||
EnumHelper.get_values<OrderStatus>().ToList(),
|
||||
r => r.status.value,
|
||||
value_path(nameof(CVOrderBookRowVM.status))),
|
||||
value_path(nameof(OrderBookRowVM.status))),
|
||||
DataGridFilterKnownTemplates.EnumValues));
|
||||
// last message
|
||||
Add(last_message_column = new OrderBookLastMessageColumn(
|
||||
new RegexFilterVM<CVOrderBookRowVM>(
|
||||
new RegexFilterVM<OrderBookRowVM>(
|
||||
r => r.last_msg.value,
|
||||
value_path(nameof(CVOrderBookRowVM.last_msg)))));
|
||||
value_path(nameof(OrderBookRowVM.last_msg)))));
|
||||
// security key
|
||||
Add(security_key_column = new SimpleTextColumn<string>(
|
||||
Columns.SecurityKey,
|
||||
DefaultColumnHeaders.SecurityKey,
|
||||
nameof(CVOrderBookRowVM.security_key),
|
||||
nameof(OrderBookRowVM.security_key),
|
||||
r => r.security_key.text,
|
||||
DefaultColumnWidths.SecurityKey,
|
||||
new RegexFilterVM<CVOrderBookRowVM>(
|
||||
new RegexFilterVM<OrderBookRowVM>(
|
||||
r => r.security_key.text,
|
||||
value_path(nameof(CVOrderBookRowVM.security_key))),
|
||||
value_path(nameof(OrderBookRowVM.security_key))),
|
||||
DataGridFilterKnownTemplates.Regex));
|
||||
// order key
|
||||
Add(order_key_column = new SimpleTextColumn<string>(
|
||||
Columns.OrderKey,
|
||||
DefaultColumnHeaders.OrderKey,
|
||||
nameof(CVOrderBookRowVM.order_key),
|
||||
nameof(OrderBookRowVM.order_key),
|
||||
r => r.order_key.text,
|
||||
DefaultColumnWidths.OrderKey,
|
||||
new RegexFilterVM<CVOrderBookRowVM>(
|
||||
new RegexFilterVM<OrderBookRowVM>(
|
||||
r => r.order_key.text,
|
||||
value_path(nameof(CVOrderBookRowVM.order_key))),
|
||||
value_path(nameof(OrderBookRowVM.order_key))),
|
||||
DataGridFilterKnownTemplates.Regex));
|
||||
// parent key (this is for diagnostic purposes, remove this column once OrderBook seems stable again)
|
||||
Add(parent_key_column = new SimpleTextColumn<string>(
|
||||
Columns.ParentKey,
|
||||
"Parent Key",
|
||||
nameof(CVOrderBookRowVM.parent_order_key),
|
||||
nameof(OrderBookRowVM.parent_order_key),
|
||||
r => r.parent_order_key.text,
|
||||
80,
|
||||
new RegexFilterVM<CVOrderBookRowVM>(
|
||||
new RegexFilterVM<OrderBookRowVM>(
|
||||
r => r.parent_order_key.text,
|
||||
value_path(nameof(CVOrderBookRowVM.parent_order_key))),
|
||||
value_path(nameof(OrderBookRowVM.parent_order_key))),
|
||||
DataGridFilterKnownTemplates.Regex));
|
||||
|
||||
string value_path(string cell_name) =>
|
||||
string.Join(".", cell_name, nameof(CVOrderBookRowVM.IOrderBookCell<uint>.value)); //uint is an arbitrary 'T', just want to get compile check on 'value' path.
|
||||
string.Join(".", cell_name, nameof(OrderBookRowVM.IOrderBookCell<uint>.value)); //uint is an arbitrary 'T', just want to get compile check on 'value' path.
|
||||
|
||||
if (startup_data?.filters is FilterStates fs) {
|
||||
security_column.filter.load_state(fs.security_criteria);
|
||||
@@ -233,7 +233,7 @@ namespace mbts.spark {
|
||||
_set_active_filters();
|
||||
}
|
||||
|
||||
List<IDataGridColumnFilter<CVOrderBookRowVM>> _active_filters;
|
||||
List<IDataGridColumnFilter<OrderBookRowVM>> _active_filters;
|
||||
|
||||
public event Action filter_changed;
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace mbts.spark {
|
||||
public SimpleTextColumn<string> order_key_column { get; }
|
||||
public SimpleTextColumn<string> parent_key_column { get; }
|
||||
|
||||
public bool filter(CVOrderBookRowVM row) => _active_filters.All(f => f.filter(row));
|
||||
public bool filter(OrderBookRowVM row) => _active_filters.All(f => f.filter(row));
|
||||
|
||||
public FilterStates get_filter_states() =>
|
||||
new FilterStates {
|
||||
@@ -303,7 +303,7 @@ namespace mbts.spark {
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
readonly string _filter_template;
|
||||
|
||||
protected OrderbookColumnBase(Columns col_key, string header, string sort_prop, double width, IDataGridColumnPersistentFilter<CVOrderBookRowVM, T> filter, string filter_template) : base(col_key) {
|
||||
protected OrderbookColumnBase(Columns col_key, string header, string sort_prop, double width, IDataGridColumnPersistentFilter<OrderBookRowVM, T> filter, string filter_template) : base(col_key) {
|
||||
Width = width;
|
||||
Header = header;
|
||||
sort_member_path = sort_prop;
|
||||
@@ -312,9 +312,9 @@ namespace mbts.spark {
|
||||
_cached_sort_direction = SortDirection;
|
||||
}
|
||||
|
||||
public IDataGridColumnPersistentFilter<CVOrderBookRowVM, T> filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, T> filter { get; }
|
||||
|
||||
IDataGridColumnFilter<CVOrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter<OrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter IFilterableColumn.filter => filter;
|
||||
string IFilterableColumn.filter_template => _filter_template;
|
||||
ListSortDirection? ICVOrderBookColumn.SortDirection => _cached_sort_direction;
|
||||
@@ -325,12 +325,12 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleTextColumn<TFilterState> : OrderbookColumnBase<TFilterState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
readonly Func<CVOrderBookRowVM, string> _get_text;
|
||||
public SimpleTextColumn(Columns key, string header, string sort_prop, Func<CVOrderBookRowVM, string> get_text, double width, IDataGridColumnPersistentFilter<CVOrderBookRowVM, TFilterState> filter, string filter_template)
|
||||
public class SimpleTextColumn<TFilterState> : OrderbookColumnBase<TFilterState>, IRenderColumn<OrderBookRowVM> {
|
||||
readonly Func<OrderBookRowVM, string> _get_text;
|
||||
public SimpleTextColumn(Columns key, string header, string sort_prop, Func<OrderBookRowVM, string> get_text, double width, IDataGridColumnPersistentFilter<OrderBookRowVM, TFilterState> filter, string filter_template)
|
||||
: base(key, header, sort_prop, width, filter, filter_template) => _get_text = get_text;
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
string text = _get_text(row);
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, text, position, RowHeight,
|
||||
@@ -339,96 +339,96 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
#region Explicit Column Defs
|
||||
public class SideColumn : OrderbookColumnBase<Side[]>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public SideColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, Side[]> filter)
|
||||
: base(Columns.Side, "B/S", nameof(CVOrderBookRowVM.side), DefaultColumnWidths.Side, filter, DataGridFilterKnownTemplates.EnumValues) { }
|
||||
public class SideColumn : OrderbookColumnBase<Side[]>, IRenderColumn<OrderBookRowVM> {
|
||||
public SideColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, Side[]> filter)
|
||||
: base(Columns.Side, "B/S", nameof(OrderBookRowVM.side), DefaultColumnWidths.Side, filter, DataGridFilterKnownTemplates.EnumValues) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.side.text, position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class SizeColumn : OrderbookColumnBase<UIntMinMaxState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public SizeColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, UIntMinMaxState> filter)
|
||||
: base(Columns.Size, "Qty", nameof(CVOrderBookRowVM.quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
sort_member_path = nameof(CVOrderBookRowVM.quantity);
|
||||
public class SizeColumn : OrderbookColumnBase<UIntMinMaxState>, IRenderColumn<OrderBookRowVM> {
|
||||
public SizeColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, UIntMinMaxState> filter)
|
||||
: base(Columns.Size, "Qty", nameof(OrderBookRowVM.quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
sort_member_path = nameof(OrderBookRowVM.quantity);
|
||||
}
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.quantity.text, position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class FilledColumn : OrderbookColumnBase<UIntMinMaxState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public FilledColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, UIntMinMaxState> filter)
|
||||
: base(Columns.Filled, "Filled Qty", nameof(CVOrderBookRowVM.filled_quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
sort_member_path = nameof(CVOrderBookRowVM.filled_quantity);
|
||||
public class FilledColumn : OrderbookColumnBase<UIntMinMaxState>, IRenderColumn<OrderBookRowVM> {
|
||||
public FilledColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, UIntMinMaxState> filter)
|
||||
: base(Columns.Filled, "Filled Qty", nameof(OrderBookRowVM.filled_quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
sort_member_path = nameof(OrderBookRowVM.filled_quantity);
|
||||
}
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.filled_quantity.text, position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class PriceColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public PriceColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.Price, "Price", nameof(CVOrderBookRowVM.price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
public class PriceColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<OrderBookRowVM> {
|
||||
public PriceColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.Price, "Price", nameof(OrderBookRowVM.price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.price.text,
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class AvgFilledColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public AvgFilledColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.AvgFilled, "Avg Filled", nameof(CVOrderBookRowVM.avg_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
public class AvgFilledColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<OrderBookRowVM> {
|
||||
public AvgFilledColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.AvgFilled, "Avg Filled", nameof(OrderBookRowVM.avg_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.avg_price.text,
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
}
|
||||
|
||||
public class LastFilledColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public LastFilledColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.LastPrice, "Last Filled", nameof(CVOrderBookRowVM.last_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
public class LastFilledColumn : OrderbookColumnBase<DoubleMinMaxState>, IRenderColumn<OrderBookRowVM> {
|
||||
public LastFilledColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> filter)
|
||||
: base(Columns.LastPrice, "Last Filled", nameof(OrderBookRowVM.last_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.last_price.text,
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class TimeCreatedColumn : OrderbookColumnBase<TimeFilterTuple>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public TimeCreatedColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, TimeFilterTuple> filter)
|
||||
: base(Columns.Time, "Time", nameof(CVOrderBookRowVM.time_created), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
public class TimeCreatedColumn : OrderbookColumnBase<TimeFilterTuple>, IRenderColumn<OrderBookRowVM> {
|
||||
public TimeCreatedColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, TimeFilterTuple> filter)
|
||||
: base(Columns.Time, "Time", nameof(OrderBookRowVM.time_created), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.time_created.text,
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class LastChangeTimeColumn : OrderbookColumnBase<TimeFilterTuple>, IRenderColumn<CVOrderBookRowVM> {
|
||||
public LastChangeTimeColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, TimeFilterTuple> filter)
|
||||
: base(Columns.LastChange, "Last Change", nameof(CVOrderBookRowVM.last_change), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
public class LastChangeTimeColumn : OrderbookColumnBase<TimeFilterTuple>, IRenderColumn<OrderBookRowVM> {
|
||||
public LastChangeTimeColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, TimeFilterTuple> filter)
|
||||
: base(Columns.LastChange, "Last Change", nameof(OrderBookRowVM.last_change), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
|
||||
public void draw(CVOrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.last_change.text,
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
public class OrderBookOrderTypeColumn : OrderTypeColumn<Columns>, ICVOrderBookColumn {
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
public OrderBookOrderTypeColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, OrderType[]> filter)
|
||||
: base(Columns.OrderType, new Binding($"{nameof(CVOrderBookRowVM.order_type)}.{nameof(CVOrderBookRowVM.IOrderBookCell<OrderType>.value)}"), new Binding(nameof(CVOrderBookRowVM.order_metadata)), filter) {
|
||||
public OrderBookOrderTypeColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, OrderType[]> filter)
|
||||
: base(Columns.OrderType, new Binding($"{nameof(OrderBookRowVM.order_type)}.{nameof(OrderBookRowVM.IOrderBookCell<OrderType>.value)}"), new Binding(nameof(OrderBookRowVM.order_metadata)), filter) {
|
||||
this.filter = filter;
|
||||
sort_member_path = nameof(CVOrderBookRowVM.order_type);
|
||||
sort_member_path = nameof(OrderBookRowVM.order_type);
|
||||
font_weight_binding = RenderUtils.get_font_weight_binding();
|
||||
_cached_sort_direction = SortDirection;
|
||||
}
|
||||
|
||||
public new IDataGridColumnPersistentFilter<CVOrderBookRowVM, OrderType[]> filter { get; }
|
||||
public new IDataGridColumnPersistentFilter<OrderBookRowVM, OrderType[]> filter { get; }
|
||||
|
||||
IDataGridColumnFilter<CVOrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter<OrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
ListSortDirection? ICVOrderBookColumn.SortDirection => _cached_sort_direction;
|
||||
|
||||
protected override void OnSortDirectionChanged(ListSortDirection? new_value) {
|
||||
@@ -440,18 +440,18 @@ namespace mbts.spark {
|
||||
public class OrderBookLastMessageColumn : TextColumn<Columns>, ICVOrderBookColumn {
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
|
||||
public OrderBookLastMessageColumn(IDataGridColumnPersistentFilter<CVOrderBookRowVM, string> filter)
|
||||
: base(Columns.LastMessage, new Binding($"{nameof(CVOrderBookRowVM.last_msg)}.{nameof(CVOrderBookRowVM.IOrderBookCell<string>.value)}"), filter, DataGridFilterKnownTemplates.Regex) {
|
||||
public OrderBookLastMessageColumn(IDataGridColumnPersistentFilter<OrderBookRowVM, string> filter)
|
||||
: base(Columns.LastMessage, new Binding($"{nameof(OrderBookRowVM.last_msg)}.{nameof(OrderBookRowVM.IOrderBookCell<string>.value)}"), filter, DataGridFilterKnownTemplates.Regex) {
|
||||
this.filter = filter;
|
||||
Header = "Last Message";
|
||||
Width = 80;
|
||||
sort_member_path = nameof(CVOrderBookRowVM.last_msg);
|
||||
tooltip_binding = new Binding(nameof(CVOrderBookRowVM.last_msg));
|
||||
sort_member_path = nameof(OrderBookRowVM.last_msg);
|
||||
tooltip_binding = new Binding(nameof(OrderBookRowVM.last_msg));
|
||||
}
|
||||
|
||||
public new IDataGridColumnPersistentFilter<CVOrderBookRowVM, string> filter { get; }
|
||||
public new IDataGridColumnPersistentFilter<OrderBookRowVM, string> filter { get; }
|
||||
|
||||
IDataGridColumnFilter<CVOrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter<OrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
ListSortDirection? ICVOrderBookColumn.SortDirection => _cached_sort_direction;
|
||||
|
||||
protected override void OnSortDirectionChanged(ListSortDirection? new_value) {
|
||||
@@ -467,17 +467,17 @@ namespace mbts.spark {
|
||||
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
|
||||
public SecurityColumn(CVOrderBookColumnCollection owner, IDataGridColumnPersistentFilter<CVOrderBookRowVM, SecurityCriteria> filter) : base(Columns.Security) {
|
||||
public SecurityColumn(CVOrderBookColumnCollection owner, IDataGridColumnPersistentFilter<OrderBookRowVM, SecurityCriteria> filter) : base(Columns.Security) {
|
||||
this.filter = filter;
|
||||
Header = DefaultColumnHeaders.Security;
|
||||
Width = DefaultColumnWidths.Security;
|
||||
sort_member_path = nameof(CVOrderBookRowVM.security);
|
||||
sort_member_path = nameof(OrderBookRowVM.security);
|
||||
_cached_sort_direction = SortDirection;
|
||||
}
|
||||
|
||||
public IDataGridColumnPersistentFilter<CVOrderBookRowVM, SecurityCriteria> filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, SecurityCriteria> filter { get; }
|
||||
|
||||
IDataGridColumnFilter<CVOrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter<OrderBookRowVM> ICVOrderBookColumn.filter => filter;
|
||||
IDataGridColumnFilter IFilterableColumn.filter => filter;
|
||||
string IFilterableColumn.filter_template => DataGridFilterKnownTemplates.DiscreteValues;
|
||||
ListSortDirection? ICVOrderBookColumn.SortDirection => _cached_sort_direction;
|
||||
@@ -485,13 +485,13 @@ namespace mbts.spark {
|
||||
public override FrameworkElement view_factory() {
|
||||
// expander
|
||||
var toggle_button = new ToggleButton { ClickMode = ClickMode.Press, IsThreeState = false };
|
||||
toggle_button.SetBinding(ToggleButton.IsCheckedProperty, new Binding(nameof(CVOrderBookRowVM.is_expanded)));
|
||||
toggle_button.SetBinding(ToggleButton.MarginProperty, new Binding(nameof(CVOrderBookRowVM.depth_level)) { Converter = _margin_converter });
|
||||
toggle_button.SetBinding(ToggleButton.VisibilityProperty, new Binding(nameof(CVOrderBookRowVM.is_parent)) { Converter = _expander_visiblilty_converter });
|
||||
toggle_button.SetBinding(ToggleButton.IsCheckedProperty, new Binding(nameof(OrderBookRowVM.is_expanded)));
|
||||
toggle_button.SetBinding(ToggleButton.MarginProperty, new Binding(nameof(OrderBookRowVM.depth_level)) { Converter = _margin_converter });
|
||||
toggle_button.SetBinding(ToggleButton.VisibilityProperty, new Binding(nameof(OrderBookRowVM.is_parent)) { Converter = _expander_visiblilty_converter });
|
||||
toggle_button.SetResourceReference(ToggleButton.StyleProperty, ExpandCollapseToggleStyleKey);
|
||||
//
|
||||
var security_view = new TextBlock();
|
||||
security_view.SetBinding(TextBlock.TextProperty, $"{nameof(CVOrderBookRowVM.security)}.{nameof(CVOrderBookRowVM.IOrderBookCell<SecurityImmutable?>.text)}");
|
||||
security_view.SetBinding(TextBlock.TextProperty, $"{nameof(OrderBookRowVM.security)}.{nameof(OrderBookRowVM.IOrderBookCell<SecurityImmutable?>.text)}");
|
||||
security_view.SetBinding(TextBlock.FontWeightProperty, _font_weight_binding);
|
||||
//
|
||||
var grid = new Grid();
|
||||
@@ -526,13 +526,13 @@ namespace mbts.spark {
|
||||
public static BindingBase _get_background_binding() {
|
||||
var mb = new MultiBinding { Converter = _background_converter };
|
||||
mb.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) });
|
||||
mb.Bindings.Add(new Binding(nameof(CVOrderBookRowVM.status)));
|
||||
mb.Bindings.Add(new Binding(nameof(OrderBookRowVM.status)));
|
||||
return mb;
|
||||
}
|
||||
|
||||
public static GlyphContext get_glyph_context(CVOrderBookRowVM r) => r.is_child ? _child_glyph_context : TextUtils.StandardGlyphContext;
|
||||
public static Brush get_side_brush(CVOrderBookRowVM r) => r.side.value == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(CVOrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
public static GlyphContext get_glyph_context(OrderBookRowVM r) => r.is_child ? _child_glyph_context : TextUtils.StandardGlyphContext;
|
||||
public static Brush get_side_brush(OrderBookRowVM r) => r.side.value == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-21
@@ -11,19 +11,19 @@ using static mbts.spark.OrderBookView;
|
||||
using OrderStatus = bts.api.orderman.OrderStatus;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class CVOrderBookRowVM : DisposableViewModelBase, IEquatable<CVOrderBookRowVM>, ui.controls.DIYGrid.IRowVM, ui.controls.DIYGrid.IActionableRowVM {
|
||||
partial class OrderBookRowVM : DisposableViewModelBase, IEquatable<OrderBookRowVM>, ui.controls.DIYGrid.IRowVM, ui.controls.DIYGrid.IActionableRowVM {
|
||||
const string _unknown_security_price_format_string = "0.#########";
|
||||
const int _unknown_security_price_num_fractional_digits = 9;
|
||||
readonly CVOrderBookVM _book_vm;
|
||||
readonly OrderBookVM _book_vm;
|
||||
readonly OrdersModel _model;
|
||||
readonly Property<bool> _visible, _expanded, _passes_filter;
|
||||
readonly DelegateProperty<int> _depth_level;
|
||||
readonly HashSet<CVOrderBookRowVM> _child_rows = new HashSet<CVOrderBookRowVM>();
|
||||
readonly HashSet<OrderBookRowVM> _child_rows = new HashSet<OrderBookRowVM>();
|
||||
readonly ObservantCommand _show_order_modify_cmd;
|
||||
OrderRecordImmutable _order;
|
||||
SecurityImmutable? _security;
|
||||
CVOrderBookRowVM _parent;
|
||||
CVOrderBookVM.BranchFilterSource _branch_filter_source;
|
||||
OrderBookRowVM _parent;
|
||||
OrderBookVM.BranchFilterSource _branch_filter_source;
|
||||
IDisposable _branch_filter_sub;
|
||||
// Core
|
||||
IOrderBookCellStore<uint> _order_key_store;
|
||||
@@ -49,7 +49,7 @@ namespace mbts.spark {
|
||||
IOrderBookCellStore<string> _last_msg_store;
|
||||
IOrderBookCellStore<OrderSubType> _order_sub_type_store;
|
||||
|
||||
public CVOrderBookRowVM(IBus bus, CVOrderBookVM source_vm, OrdersModel model, OrderRecordImmutable record, SecurityImmutable? s) {
|
||||
public OrderBookRowVM(IBus bus, OrderBookVM source_vm, OrdersModel model, OrderRecordImmutable record, SecurityImmutable? s) {
|
||||
_book_vm = source_vm;
|
||||
_model = model;
|
||||
_order = record;
|
||||
@@ -113,7 +113,7 @@ namespace mbts.spark {
|
||||
|
||||
public OrderRecordImmutable order => _order;
|
||||
public OrderMetadata order_metadata => _model.factory.get_metadata(order_type.value);
|
||||
public CVOrderBookRowVM parent => _parent;
|
||||
public OrderBookRowVM parent => _parent;
|
||||
// Core
|
||||
public IOrderBookCell<uint> order_key => _order_key_store.current;
|
||||
public IOrderBookCell<uint> parent_order_key => _parent_order_key_store.current;
|
||||
@@ -143,8 +143,8 @@ namespace mbts.spark {
|
||||
// Accessories
|
||||
public bool is_parent => _child_rows.Count > 0;
|
||||
public bool is_child => _order.has_parent();
|
||||
public IReadOnlyCollection<CVOrderBookRowVM> child_orders => _child_rows;
|
||||
public CVOrderBookVM.BranchFilterSource branch_filter_source => _branch_filter_source;
|
||||
public IReadOnlyCollection<OrderBookRowVM> child_orders => _child_rows;
|
||||
public OrderBookVM.BranchFilterSource branch_filter_source => _branch_filter_source;
|
||||
public bool passes_filter => _passes_filter.Value;
|
||||
public bool row_passes_filter { get; private set; }
|
||||
public bool is_visible {
|
||||
@@ -193,15 +193,15 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public static Stack<CVOrderBookRowVM> lineage(CVOrderBookRowVM node) {
|
||||
var rv = new Stack<CVOrderBookRowVM>();
|
||||
public static Stack<OrderBookRowVM> lineage(OrderBookRowVM node) {
|
||||
var rv = new Stack<OrderBookRowVM>();
|
||||
rv.Push(node);
|
||||
while (node._parent != null)
|
||||
rv.Push((node = node._parent));
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void join_branch_filter_source(CVOrderBookVM.BranchFilterSource new_branch_filter_source) {
|
||||
public void join_branch_filter_source(OrderBookVM.BranchFilterSource new_branch_filter_source) {
|
||||
_branch_filter_source = new_branch_filter_source;
|
||||
_branch_filter_source.set_row_passes_filter(_order.Key, row_passes_filter);
|
||||
_branch_filter_source_changed?.Invoke(_branch_filter_source);
|
||||
@@ -212,7 +212,7 @@ namespace mbts.spark {
|
||||
/// <summary>
|
||||
/// Attaches the child-row to this row's branch-filter-source, and recursively refreshes sort/filter properties for the child and it's descendents.
|
||||
/// </summary>
|
||||
public void add_child_order(CVOrderBookRowVM child_row) {
|
||||
public void add_child_order(OrderBookRowVM child_row) {
|
||||
if (_child_rows.Add(child_row) && _child_rows.Count == 1)
|
||||
RaisePropertyChanged(nameof(is_parent));
|
||||
child_row._parent = this;
|
||||
@@ -224,19 +224,19 @@ namespace mbts.spark {
|
||||
child_row._on_lineage_changed();
|
||||
}
|
||||
|
||||
public void remove_child_order(CVOrderBookRowVM child_row) {
|
||||
public void remove_child_order(OrderBookRowVM child_row) {
|
||||
if (_child_rows.Remove(child_row) && _child_rows.Count == 0)
|
||||
RaisePropertyChanged(nameof(is_parent));
|
||||
}
|
||||
|
||||
public void remove_parent(CVOrderBookVM.BranchFilterSource new_branch_filter_source) {
|
||||
public void remove_parent(OrderBookVM.BranchFilterSource new_branch_filter_source) {
|
||||
_parent = null;
|
||||
join_branch_filter_source(new_branch_filter_source);
|
||||
refresh_row_passes_filter();
|
||||
foreach (var p in _book_vm.live_sorting_props)
|
||||
RaisePropertyChanged(p);
|
||||
_depth_level.refresh();
|
||||
foreach (CVOrderBookRowVM child_row in _child_rows)
|
||||
foreach (OrderBookRowVM child_row in _child_rows)
|
||||
child_row._on_lineage_changed();
|
||||
}
|
||||
|
||||
@@ -261,14 +261,14 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(CVOrderBookRowVM other) => other != null && other._order.Key == _order.Key;
|
||||
public override bool Equals(object obj) => Equals(obj as CVOrderBookRowVM);
|
||||
public bool Equals(OrderBookRowVM other) => other != null && other._order.Key == _order.Key;
|
||||
public override bool Equals(object obj) => Equals(obj as OrderBookRowVM);
|
||||
public override int GetHashCode() => (int)_order.Key;
|
||||
public override string ToString() => $"{order_key} {last_change} {parent_order_key}";
|
||||
|
||||
protected override void Dispose(bool disposing) => Disposable.dispose(ref _branch_filter_sub);
|
||||
|
||||
static IEnumerable<CVOrderBookRowVM> _descendents(CVOrderBookRowVM root) {
|
||||
static IEnumerable<OrderBookRowVM> _descendents(OrderBookRowVM root) {
|
||||
foreach (var child in root.child_orders) {
|
||||
yield return child;
|
||||
foreach (var grand_child in _descendents(child))
|
||||
@@ -276,7 +276,7 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
static IOrderBookCellStore _cell_store_from_column(CVOrderBookRowVM row, Columns column) {
|
||||
static IOrderBookCellStore _cell_store_from_column(OrderBookRowVM row, Columns column) {
|
||||
switch (column) {
|
||||
case Columns.OrderKey: return row._order_key_store;
|
||||
case Columns.ParentKey: return row._parent_order_key_store;
|
||||
@@ -330,7 +330,7 @@ namespace mbts.spark {
|
||||
invalidate = true;
|
||||
if (_book_vm.live_sorting_columns.Contains(cell_store.column.key)) {
|
||||
// refresh the sort by calling regenerate_cell() for each descendent-row
|
||||
foreach (CVOrderBookRowVM dr in _descendents(this))
|
||||
foreach (OrderBookRowVM dr in _descendents(this))
|
||||
cell_store.select_other(dr).regenerate_cell();
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+39
-42
@@ -21,29 +21,29 @@ using static mbts.spark.OrderBookView;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class CVOrderBookVM : DisposableViewModelBase, IHandleRowSelection, IOrderBookVM {
|
||||
partial class OrderBookVM : DisposableViewModelBase, IHandleRowSelection {
|
||||
// these come from -> ((ICollectionViewLiveShaping)rows_view).LiveSortingProperties
|
||||
// each row accesses the public 'live_sorting_props' when it, or an ancestor order, is updated,
|
||||
// copying the collection locally avoids constantly casting rows_view to ICollectionViewLiveShaping.
|
||||
readonly ObservableCollection<string> _live_sorting_props;
|
||||
readonly LiveSortingColumKeys _live_sorting_columns;
|
||||
readonly Property<CVOrderBookRowVM> _current_row;
|
||||
readonly Property<OrderBookRowVM> _current_row;
|
||||
readonly Subject<(IEnumerable<SecurityImmutable> added, IEnumerable<SecurityImmutable> removed)> _order_securities_subject =
|
||||
new Subject<(IEnumerable<SecurityImmutable> added, IEnumerable<SecurityImmutable> removed)>();
|
||||
|
||||
Dictionary<uint, CVOrderBookRowVM> _order_rows_cache = new Dictionary<uint, CVOrderBookRowVM>();
|
||||
Dictionary<uint, OrderBookRowVM> _order_rows_cache = new Dictionary<uint, OrderBookRowVM>();
|
||||
Dictionary<uint, BranchFilterSource> _branch_filter_roots = new Dictionary<uint, BranchFilterSource>();
|
||||
ObservableCollection<CVOrderBookRowVM> _order_rows = new ObservableCollection<CVOrderBookRowVM>();
|
||||
ObservableCollection<CVOrderBookRowVM> _selected_rows = new ObservableCollection<CVOrderBookRowVM>();
|
||||
ObservableCollection<OrderBookRowVM> _order_rows = new ObservableCollection<OrderBookRowVM>();
|
||||
ObservableCollection<OrderBookRowVM> _selected_rows = new ObservableCollection<OrderBookRowVM>();
|
||||
SetMap<uint, uint> _parent_to_children = new SetMap<uint, uint>();
|
||||
SetMap<uint, uint> _security_orders = new SetMap<uint, uint>();
|
||||
|
||||
public CVOrderBookVM(IBus bus, OrdersModel model, OrderBookStartupData state) {
|
||||
public OrderBookVM(IBus bus, OrdersModel model, OrderBookStartupData state) {
|
||||
columns = new CVOrderBookColumnCollection(bus, model, state, _order_securities_subject);
|
||||
foreach (ColumnBase col in columns)
|
||||
col.sort_direction_changed += on_column_sort_direction_changed;
|
||||
rows_view = CollectionViewSource.GetDefaultView(_order_rows);
|
||||
rows_view.Filter = obj => obj is CVOrderBookRowVM vm && vm.is_visible && vm.passes_filter;
|
||||
rows_view.Filter = obj => obj is OrderBookRowVM vm && vm.is_visible && vm.passes_filter;
|
||||
columns.filter_changed += () => {
|
||||
foreach (var vm in _order_rows)
|
||||
vm.refresh_row_passes_filter();
|
||||
@@ -52,8 +52,8 @@ namespace mbts.spark {
|
||||
_live_sorting_props = cvls.LiveSortingProperties;
|
||||
cvls.IsLiveFiltering = true;
|
||||
cvls.IsLiveSorting = true;
|
||||
cvls.LiveFilteringProperties.AddRange(nameof(CVOrderBookRowVM.is_visible), nameof(CVOrderBookRowVM.passes_filter));
|
||||
_current_row = backing<CVOrderBookRowVM>(nameof(current_row));
|
||||
cvls.LiveFilteringProperties.AddRange(nameof(OrderBookRowVM.is_visible), nameof(OrderBookRowVM.passes_filter));
|
||||
_current_row = backing<OrderBookRowVM>(nameof(current_row));
|
||||
if (state?.sort_criteria is List<SortingCriteria> lsc && lsc.Count > 0) {
|
||||
foreach (var sc in lsc) {
|
||||
rows_view.SortDescriptions.Add(new SortDescription(sc.col_name, sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending));
|
||||
@@ -61,8 +61,8 @@ namespace mbts.spark {
|
||||
_live_sorting_props.Add(sc.col_name);
|
||||
}
|
||||
} else {
|
||||
rows_view.SortDescriptions.Add(new SortDescription(nameof(CVOrderBookRowVM.time_created), ListSortDirection.Descending));
|
||||
_live_sorting_props.Add(nameof(CVOrderBookRowVM.time_created));
|
||||
rows_view.SortDescriptions.Add(new SortDescription(nameof(OrderBookRowVM.time_created), ListSortDirection.Descending));
|
||||
_live_sorting_props.Add(nameof(OrderBookRowVM.time_created));
|
||||
}
|
||||
_live_sorting_columns = new LiveSortingColumKeys(_live_sorting_props);
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace mbts.spark {
|
||||
if (table.state.TryGetValue(o.Key, out OrderRecordImmutable changed_order)) {
|
||||
changed_keys.Add(o.Key);
|
||||
_order_rows_cache[o.Key].update_order(changed_order);
|
||||
} else if (_order_rows_cache.TryPopValue(o.Key, out CVOrderBookRowVM row)) {
|
||||
} else if (_order_rows_cache.TryPopValue(o.Key, out OrderBookRowVM row)) {
|
||||
row.Dispose();
|
||||
_order_rows.Remove(row);
|
||||
if (_security_orders.removes_key(o.Def.SecurityKey, o.Key)) {
|
||||
@@ -123,7 +123,7 @@ namespace mbts.spark {
|
||||
missing_security_orders.remove(o.Key);
|
||||
}
|
||||
}
|
||||
var orphans = new Dictionary<uint, CVOrderBookRowVM>();
|
||||
var orphans = new Dictionary<uint, OrderBookRowVM>();
|
||||
foreach (var o in table.added) {
|
||||
if (changed_keys.Contains(o.Key))
|
||||
continue;
|
||||
@@ -137,7 +137,7 @@ namespace mbts.spark {
|
||||
security = null;
|
||||
_security_orders.add(o.Def.SecurityKey, o.Key);
|
||||
}
|
||||
CVOrderBookRowVM row = new CVOrderBookRowVM(bus, this, model, o, security);
|
||||
OrderBookRowVM row = new OrderBookRowVM(bus, this, model, o, security);
|
||||
if (!o.has_parent()) {
|
||||
// if it doesn't have a parent, it must be a root; create a new BranchFilterSource
|
||||
var bfs = new BranchFilterSource();
|
||||
@@ -145,7 +145,7 @@ namespace mbts.spark {
|
||||
row.join_branch_filter_source(bfs);
|
||||
} else {
|
||||
_parent_to_children.add(o.ParentKey, o.Key);
|
||||
if (_order_rows_cache.TryGetValue(o.ParentKey, out CVOrderBookRowVM pvm)) {
|
||||
if (_order_rows_cache.TryGetValue(o.ParentKey, out OrderBookRowVM pvm)) {
|
||||
pvm.add_child_order(row);
|
||||
} else {
|
||||
// (**) look for orphans' parents again after all new orders have been added to _order_vm_cache
|
||||
@@ -162,7 +162,7 @@ namespace mbts.spark {
|
||||
}
|
||||
// (**) since all new rows have been added by now, any remaining orphans will be assigned their own branch-filter-roots
|
||||
// (usually, rows are tempororily added to orphans bc their parent is just behind them in the list of added orders) (**)
|
||||
foreach (CVOrderBookRowVM row in orphans.Values) {
|
||||
foreach (OrderBookRowVM row in orphans.Values) {
|
||||
var bfs = new BranchFilterSource();
|
||||
row.join_branch_filter_source(bfs);
|
||||
_branch_filter_roots.Add(row.order.Key, bfs);
|
||||
@@ -171,10 +171,10 @@ namespace mbts.spark {
|
||||
if (added_securities.Count > 0 || removed_securities.Count > 0)
|
||||
_order_securities_subject.OnNext((added_securities, removed_securities));
|
||||
|
||||
void try_add_children(CVOrderBookRowVM row) {
|
||||
void try_add_children(OrderBookRowVM row) {
|
||||
if (_parent_to_children.try_lookup(row.order.Key, out ISet<uint> children))
|
||||
foreach (uint child_key in children) {
|
||||
CVOrderBookRowVM child_vm = _order_rows_cache[child_key];
|
||||
OrderBookRowVM child_vm = _order_rows_cache[child_key];
|
||||
// (**) if children arrived in an earlier update, this will notify them that their parent has arrived (**)
|
||||
// - their tempororary branch-filter-roots will be removed, and they will join that of their parent's
|
||||
// - for the live-filter-properties, their corresponding cells will be regenerated and they will be re-inserted beneath their new parent.
|
||||
@@ -227,12 +227,9 @@ namespace mbts.spark {
|
||||
public IReadOnlyList<string> live_sorting_props => _live_sorting_props;
|
||||
public ISet<Columns> live_sorting_columns => _live_sorting_columns;
|
||||
public ICollectionView rows_view { get; }
|
||||
// this is a misnomer, but i want to support both kinds of OrderBookVMs, and OrderBookView currently binds to 'visible_orders,'
|
||||
public ICollectionView visible_orders => rows_view;
|
||||
public CVOrderBookRowVM current_row { get => _current_row.Value; set => _current_row.Value = value ?? _selected_rows.FirstOrDefault(); }
|
||||
public OrderBookRowVM current_row { get => _current_row.Value; set => _current_row.Value = value ?? _selected_rows.FirstOrDefault(); }
|
||||
public OrderRecordImmutable? current_order => current_row?.order;
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => _selected_rows.Select(r => r.order);
|
||||
void IOrderBookVM.on_sorting(DIYGridSortingEventArgs e) { }
|
||||
|
||||
public void row_selection_changed(SelectionChangedEventArgs e) {
|
||||
RowSelectionHelper.apply_changes(_selected_rows, e);
|
||||
@@ -286,26 +283,26 @@ namespace mbts.spark {
|
||||
|
||||
public static bool try_parse(string prop_name, out Columns result) {
|
||||
switch (prop_name) {
|
||||
case nameof(CVOrderBookRowVM.security): result = Columns.Security; break;
|
||||
case nameof(CVOrderBookRowVM.time_created): result = Columns.Time; break;
|
||||
case nameof(CVOrderBookRowVM.last_change): result = Columns.LastChange; break;
|
||||
case nameof(CVOrderBookRowVM.user): result = Columns.User; break;
|
||||
case nameof(CVOrderBookRowVM.account): result = Columns.Account; break;
|
||||
case nameof(CVOrderBookRowVM.exchange): result = Columns.Exchange; break;
|
||||
case nameof(CVOrderBookRowVM.time_in_force): result = Columns.TimeInForce; break;
|
||||
case nameof(CVOrderBookRowVM.order_type): result = Columns.OrderType; break;
|
||||
case nameof(CVOrderBookRowVM.order_sub_type): result = Columns.SubType; break;
|
||||
case nameof(CVOrderBookRowVM.side): result = Columns.Side; break;
|
||||
case nameof(CVOrderBookRowVM.quantity): result = Columns.Size; break;
|
||||
case nameof(CVOrderBookRowVM.filled_quantity): result = Columns.Filled; break;
|
||||
case nameof(CVOrderBookRowVM.price): result = Columns.Price; break;
|
||||
case nameof(CVOrderBookRowVM.avg_price): result = Columns.AvgFilled; break;
|
||||
case nameof(CVOrderBookRowVM.last_price): result = Columns.LastPrice; break;
|
||||
case nameof(CVOrderBookRowVM.status): result = Columns.Status; break;
|
||||
case nameof(CVOrderBookRowVM.last_msg): result = Columns.LastMessage; break;
|
||||
case nameof(CVOrderBookRowVM.security_key): result = Columns.SecurityKey; break;
|
||||
case nameof(CVOrderBookRowVM.order_key): result = Columns.OrderKey; break;
|
||||
case nameof(CVOrderBookRowVM.parent_order_key): result = Columns.ParentKey; break;
|
||||
case nameof(OrderBookRowVM.security): result = Columns.Security; break;
|
||||
case nameof(OrderBookRowVM.time_created): result = Columns.Time; break;
|
||||
case nameof(OrderBookRowVM.last_change): result = Columns.LastChange; break;
|
||||
case nameof(OrderBookRowVM.user): result = Columns.User; break;
|
||||
case nameof(OrderBookRowVM.account): result = Columns.Account; break;
|
||||
case nameof(OrderBookRowVM.exchange): result = Columns.Exchange; break;
|
||||
case nameof(OrderBookRowVM.time_in_force): result = Columns.TimeInForce; break;
|
||||
case nameof(OrderBookRowVM.order_type): result = Columns.OrderType; break;
|
||||
case nameof(OrderBookRowVM.order_sub_type): result = Columns.SubType; break;
|
||||
case nameof(OrderBookRowVM.side): result = Columns.Side; break;
|
||||
case nameof(OrderBookRowVM.quantity): result = Columns.Size; break;
|
||||
case nameof(OrderBookRowVM.filled_quantity): result = Columns.Filled; break;
|
||||
case nameof(OrderBookRowVM.price): result = Columns.Price; break;
|
||||
case nameof(OrderBookRowVM.avg_price): result = Columns.AvgFilled; break;
|
||||
case nameof(OrderBookRowVM.last_price): result = Columns.LastPrice; break;
|
||||
case nameof(OrderBookRowVM.status): result = Columns.Status; break;
|
||||
case nameof(OrderBookRowVM.last_msg): result = Columns.LastMessage; break;
|
||||
case nameof(OrderBookRowVM.security_key): result = Columns.SecurityKey; break;
|
||||
case nameof(OrderBookRowVM.order_key): result = Columns.OrderKey; break;
|
||||
case nameof(OrderBookRowVM.parent_order_key): result = Columns.ParentKey; break;
|
||||
default: result = default; return false;
|
||||
}
|
||||
return true;
|
||||
+3
-23
@@ -44,20 +44,6 @@
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="{x:Static sp:OrderBookView.RowStyleKey}" TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{uc:Enum Working, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=working_order_background_brush, MemberType={uc:Nested uc:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="{x:Static sp:OrderBookView.CVRowStyleKey}" TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
@@ -70,14 +56,9 @@
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="{x:Static sp:OrderBookView.RowTemplateKey}">
|
||||
<sp:OrderBookRowView/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="{x:Static sp:OrderBookView.CVRowTemplateKey}">
|
||||
<sp:CVOrderBookRowView/>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
@@ -86,11 +67,10 @@
|
||||
Grid.Row="2"
|
||||
Columns="{Binding columns}"
|
||||
CurrentRow="{Binding current_row, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Rows="{Binding visible_orders}"
|
||||
Rows="{Binding rows_view}"
|
||||
RowHeight="{x:Static sp:OrderBookView.RowHeight}"
|
||||
RowStyle="{StaticResource {x:Static sp:OrderBookView.ActiveRowStyleKey}}"
|
||||
RowTemplate="{StaticResource {x:Static sp:OrderBookView.ActiveRowTemplateKey}}"
|
||||
Sorting="data_grid_sorting"
|
||||
RowStyle="{StaticResource {x:Static sp:OrderBookView.RowStyleKey}}"
|
||||
RowTemplate="{StaticResource {x:Static sp:OrderBookView.RowTemplateKey}}"
|
||||
>
|
||||
<c:DIYGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
@@ -0,0 +1,28 @@
|
||||
using mbts.ui.controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal partial class OrderBookView : UserControl {
|
||||
public enum Columns { Security, Time, LastChange, User, Account, Exchange, TimeInForce, OrderType, SubType, Side, Size, Price, Filled, AvgFilled, LastPrice, Status, LastMessage, SecurityKey, OrderKey, ParentKey }
|
||||
public const string
|
||||
SubTypeFilterTemplateKey = "SubTypeFilterTemplate",
|
||||
ExpandCollapseToggleStyleKey = "ExpandCollapseToggleStyle",
|
||||
RowStyleKey = "RowStyle",
|
||||
RowTemplateKey = "RowTemplateKey",
|
||||
CVRowStyleKey = "CVRowStyle",
|
||||
CVRowTemplateKey = "CVRowTemplateKey";
|
||||
|
||||
public const double RowHeight = 17;
|
||||
OrderBookVM _vm;
|
||||
|
||||
public OrderBookView(OrderBookVM vm) {
|
||||
InitializeComponent();
|
||||
_vm = vm;
|
||||
DataContext = vm;
|
||||
}
|
||||
}
|
||||
|
||||
class OrderBookRowView : DIYGrid.HighPerformanceRow<OrderBookRowVM, OrderBookView.Columns> {
|
||||
public OrderBookRowView() : base(OrderBookView.RowHeight) { }
|
||||
}
|
||||
}
|
||||
+5
-17
@@ -12,12 +12,10 @@ using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal class OrderBookWindow : SparkWindow<OrderBookWindowFactory.OrderBookStartupData>, ISharedWindow {
|
||||
public static readonly bool cv_orderbook_enabled = config.Configuration.get<bts.config.toggles.CVOrderBook>().enabled;
|
||||
|
||||
const string _window_type = "OrderBook", ORDERBOOK_THREAD_ID = "OrderBook";
|
||||
OrderBookWindowFactory.OrderBookStartupData _state;
|
||||
OrdersModel _model;
|
||||
IOrderBookVM _vm;
|
||||
OrderBookVM _vm;
|
||||
OrderBookView _view;
|
||||
OrderBookWindowFactory _factory;
|
||||
SparkCommand[] _commands;
|
||||
@@ -37,19 +35,13 @@ namespace mbts.spark {
|
||||
_state = state;
|
||||
}
|
||||
|
||||
public static OrderBookWindowFactory.OrderBookStartupData default_startup_data => cv_orderbook_enabled ?
|
||||
public static OrderBookWindowFactory.OrderBookStartupData default_startup_data =>
|
||||
new OrderBookWindowFactory.OrderBookStartupData(
|
||||
new List<SortingCriteria> {
|
||||
new SortingCriteria(nameof(CVOrderBookRowVM.time_created), false)
|
||||
new SortingCriteria(nameof(OrderBookRowVM.time_created), false)
|
||||
}, new OrderBookWindowFactory.FilterStates {
|
||||
statuses = new[] { OrderStatus.Working }
|
||||
})
|
||||
: new OrderBookWindowFactory.OrderBookStartupData(
|
||||
new List<SortingCriteria> {
|
||||
new SortingCriteria(nameof(OrderBookRowVM.time_created), false)
|
||||
}, new OrderBookWindowFactory.FilterStates {
|
||||
statuses = new[] { OrderStatus.Working }
|
||||
});
|
||||
});
|
||||
|
||||
public override OrderBookWindowFactory.OrderBookStartupData SaveState => _state =
|
||||
new OrderBookWindowFactory.OrderBookStartupData(
|
||||
@@ -70,11 +62,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public void thread_init() {
|
||||
_vm = cv_orderbook_enabled ?
|
||||
(IOrderBookVM)new CVOrderBookVM(_bus, _model, _state) :
|
||||
(IOrderBookVM)new OrderBookVM(_factory, base._bus, _model, _state);
|
||||
_view = new OrderBookView(_vm);
|
||||
_view.DataContext = _vm;
|
||||
_view = new OrderBookView(_vm = new OrderBookVM(_bus, _model, _state));
|
||||
|
||||
_show_fills_command = SparkCommands.ShowFills.complete(() => new FillsWindowFactory.StartupData(_vm.selected_orders.Select(r => r.Key).ToArray()));
|
||||
|
||||
+2
-2
@@ -83,8 +83,8 @@ namespace bts.shell {
|
||||
public string exchange_message_regex;
|
||||
[ProtoMember(17)]
|
||||
public TimeFilterTuple last_change;
|
||||
[ProtoMember(18)]
|
||||
public string security_regex;
|
||||
//[ProtoMember(18)]
|
||||
//public string security_regex;
|
||||
[ProtoMember(19)]
|
||||
public api.orderman.OrderSubType[] order_sub_types;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,176 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using static mbts.spark.OrderBookView;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class OrderBookVM {
|
||||
static class RenderUtils {
|
||||
public static readonly Brush _working_order_brush = 0xffedcdu.rgb_brush();
|
||||
public static readonly GlyphContext _child_glyph_context = TextUtils.StandardGlyphContext.with(FontWeights.Light);
|
||||
public static double font_size = FontSizes.Small;
|
||||
|
||||
public static readonly IValueConverter
|
||||
_sub_type_text_converter = new ui.spark.converters.OrderSubTypeDisplayTextConverter(),
|
||||
_side_brush_converter = new AnonymousValueConverter<Side, Brush>(s => s == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask),
|
||||
_font_weight_converter = new AnonymousValueConverter<bool, FontWeight>(is_child => is_child ? FontWeights.Light : FontWeights.Normal);
|
||||
public static readonly IMultiValueConverter
|
||||
_price_text_converter = new ui.spark.converters.TickDisplayConverter(),
|
||||
_background_converter = new AnonymousMultiValueConverter<bool, OrderStatus, Brush>(
|
||||
(selected, status) => selected || status != OrderStatus.Working ? Brushes.Transparent : _working_order_brush);
|
||||
|
||||
public static BindingBase _get_background_binding() {
|
||||
var mb = new MultiBinding { Converter = _background_converter };
|
||||
mb.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) });
|
||||
mb.Bindings.Add(new Binding(nameof(OrderBookRowVM.status)));
|
||||
return mb;
|
||||
}
|
||||
|
||||
static RenderUtils() => _working_order_brush.Freeze();
|
||||
|
||||
public static GlyphContext get_glyph_context(OrderBookRowVM r) => r.is_child ? _child_glyph_context : TextUtils.StandardGlyphContext;
|
||||
public static Brush get_side_brush(OrderBookRowVM r) => r.side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
public static string format_price(OrderBookRowVM row, double price) => row.security.HasValue ? row.security.Value.ContractSpec.format(price) : row.price.ToString();
|
||||
}
|
||||
|
||||
abstract class OrderbookColumnBase : ColumnBase<Columns>, IKeyedColumn<Columns>, IFilterableColumn {
|
||||
protected OrderbookColumnBase(Columns col_key, string header, string sort_prop, double width, IDataGridColumnFilter filter, string filter_template) : base(col_key) {
|
||||
Width = width;
|
||||
Header = header;
|
||||
sort_member_path = sort_prop;
|
||||
this.filter = filter;
|
||||
this.filter_template = filter_template;
|
||||
}
|
||||
|
||||
public IDataGridColumnFilter filter { get; }
|
||||
public string filter_template { get; }
|
||||
}
|
||||
|
||||
class SimpleTextColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
readonly Func<OrderBookRowVM, string> _get_text;
|
||||
public SimpleTextColumn(Columns key, string header, string sort_prop, Func<OrderBookRowVM, string> get_text, double width, IDataGridColumnFilter filter, string filter_template)
|
||||
: base(key, header, sort_prop, width, filter, filter_template) => _get_text = get_text;
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
string text = _get_text(row);
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, text, position, RowHeight,
|
||||
Brushes.Black, null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
}
|
||||
|
||||
class SideColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public SideColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.Side, "B/S", nameof(OrderBookRowVM.side), DefaultColumnWidths.Side, filter, DataGridFilterKnownTemplates.EnumValues) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.side.ToString(), position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class SizeColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public SizeColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.Size, "Qty", nameof(OrderBookRowVM.quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.quantity.ToString(), position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class FilledColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public FilledColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.Filled, "Filled Qty", nameof(OrderBookRowVM.filled_quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.filled_quantity.ToString(), position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class PriceColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public PriceColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.Price, "Price", nameof(OrderBookRowVM.price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, RenderUtils.format_price(row, row.price),
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class AvgFilledColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public AvgFilledColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.AvgFilled, "Avg Filled", nameof(OrderBookRowVM.avg_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) {
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, RenderUtils.format_price(row, row.avg_price),
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
}
|
||||
|
||||
class LastFilledColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public LastFilledColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.LastPrice, "Last Filled", nameof(OrderBookRowVM.last_price), DefaultColumnWidths.Price, filter, DataGridFilterKnownTemplates.DoubleMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, RenderUtils.format_price(row, row.last_price),
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class TimeCreatedColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public TimeCreatedColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.Time, "Time", nameof(OrderBookRowVM.time_created), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, $"{row.time_created:M/d} {row.time_created:h:mm:ss.fff tt}",
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class LastChangeTimeColumn : OrderbookColumnBase, IRenderColumn<OrderBookRowVM> {
|
||||
public LastChangeTimeColumn(IDataGridColumnFilter filter)
|
||||
: base(Columns.LastChange, "Last Change", nameof(OrderBookRowVM.last_change), DefaultColumnWidths.Time, filter, DataGridFilterKnownTemplates.TimeFilter) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, $"{row.time_created:M/d} {row.time_created:h:mm:ss.fff tt}",
|
||||
position, RowHeight, Brushes.Black, null, HorizontalAlignment.Left, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
class SecurityColumn : FrameworkElementColumnBase<Columns> {
|
||||
readonly BindingBase _font_weight_binding = RenderUtils.get_font_weight_binding();
|
||||
|
||||
public SecurityColumn(IDataGridColumnFilter filter) : base(Columns.Security) {
|
||||
this.filter = filter;
|
||||
Header = DefaultColumnHeaders.Security;
|
||||
Width = DefaultColumnWidths.Security;
|
||||
}
|
||||
|
||||
public IDataGridColumnFilter filter { get; }
|
||||
public string filter_template => DataGridFilterKnownTemplates.Regex;
|
||||
|
||||
public override FrameworkElement view_factory() {
|
||||
var toggle_button = new ToggleButton { ClickMode = ClickMode.Press, IsThreeState = false };
|
||||
toggle_button.SetBinding(ToggleButton.IsCheckedProperty, new Binding(nameof(OrderBookRowVM.is_expanded)));
|
||||
toggle_button.SetBinding(ToggleButton.MarginProperty, new Binding(nameof(OrderBookRowVM.Margin)));
|
||||
toggle_button.SetResourceReference(ToggleButton.StyleProperty, ExpandCollapseToggleStyleKey);
|
||||
var security_view = new TextBlock();
|
||||
security_view.SetBinding(TextBlock.TextProperty, nameof(OrderBookRowVM.security_text));
|
||||
security_view.SetBinding(TextBlock.FontWeightProperty, _font_weight_binding);
|
||||
var grid = new Grid();
|
||||
Grid.SetColumn(security_view, 1);
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
grid.Children.Add(toggle_button);
|
||||
grid.Children.Add(security_view);
|
||||
return grid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using static mbts.spark.SparkTags;
|
||||
using OrderStatus = bts.api.orderman.OrderStatus;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
class OrderBookRowVM : ViewModelBase, IEquatable<OrderBookRowVM>, ui.controls.DIYGrid.IRowVM, ui.controls.DIYGrid.IActionableRowVM {
|
||||
// implement Equals to be sync_with -friendly; Equals will defer to the OrderRecordImmutable
|
||||
readonly IBus _bus;
|
||||
readonly OrderBookVM _book_vm;
|
||||
readonly OrdersModel _model;
|
||||
OrderRecordImmutable _order;
|
||||
List<uint> _child_order_ids = new List<uint>();
|
||||
|
||||
//ParentOrderDateSortWrapper _time_created_parent_wrapper;
|
||||
|
||||
|
||||
public OrderBookRowVM(IBus bus, OrderBookVM source_vm, OrdersModel model, OrderRecordImmutable record, SecurityImmutable? s /*, OrderRecordImmutable? parent_order, bool sort_ascending*/) {
|
||||
_bus = bus;
|
||||
_book_vm = source_vm;
|
||||
_model = model;
|
||||
_order = record;
|
||||
security = s;
|
||||
_visible = backing(nameof(is_visible), true);
|
||||
_expanded = backing(nameof(is_expanded), true);
|
||||
toggle_command = new DelegateCommand(() => is_expanded = !is_expanded);
|
||||
show_order_modify_command = new DelegateCommand(
|
||||
execute: _ => _bus.post(ShowModifyOrderTag, _order.Key),
|
||||
can_execute: _ => { return _order.State.Status == bts.api.orderman.OrderStatus.Working; }
|
||||
);
|
||||
|
||||
//_time_created_parent_wrapper = new ParentOrderDateSortWrapper(_order, parent_order, sort_ascending);
|
||||
}
|
||||
|
||||
void ignore() {/*These setters are just for WPF databinding :(*/ throw new NotImplementedException(); }
|
||||
|
||||
// we need the equality to look at is_parent since
|
||||
// spreader orders parents can and will arrive
|
||||
// before there are any child orders
|
||||
// and we need to compare the security b/c we can get spreads
|
||||
// securities later than the orders on startup
|
||||
public bool Equals(OrderBookRowVM other) {
|
||||
if (other == null) { return false; }
|
||||
return this._order.Equals(other._order) && is_parent == other.is_parent && security == other.security;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return this.Equals(obj as OrderBookRowVM);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return this._order.GetHashCode();
|
||||
}
|
||||
|
||||
// the grid view uses this for sorting, it was just a bts.api.Security once upon a time, but that class no longer implements IComparable
|
||||
// this SelectableViewModeBase is essentially a wrapper class, which implements ISelecatble and IComparable
|
||||
public SecurityImmutable? security { get; }
|
||||
public OrderRecordImmutable order => _order;
|
||||
|
||||
public string order_key {
|
||||
get => _order.Key.ToString();
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public uint parent_order_key {
|
||||
get => _order.ParentKey;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public uint security_key {
|
||||
get => _order.Def.SecurityKey;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public Side side {
|
||||
get => _order.Def.Side;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string user {
|
||||
get => _order.Def.User;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string account {
|
||||
get => _order.Def.Account;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public TimeInForce tif {
|
||||
get => _order.Def.TimeInForce;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public ManualOrderIndicator manual_order_indicator {
|
||||
get => _order.Def.ManualOrderIndicator;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string cti_code {
|
||||
get => _order.Def.CtiCode.ToString();
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string customer_or_firm {
|
||||
get => _order.Def.CustomerOrFirm.ToString();
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public OrderStatus status {
|
||||
get => _order.State.Status;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public double price {
|
||||
get => _order.State.Price;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public uint quantity {
|
||||
get => _order.State.Quantity;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public uint filled_quantity {
|
||||
get => _order.State.FilledQuantity;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public double last_price {
|
||||
get => _order.State.LastPrice;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public double avg_price {
|
||||
get => _order.State.AvgPrice;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string last_msg {
|
||||
get => _order.State.LastMsg;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public DateTime last_change {
|
||||
get {
|
||||
if (_order.HasState && _order.State.LastChange != null) {
|
||||
return _order.State.LastChange.ToDateTime().ToLocalTime();
|
||||
}
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public DateTime time_created {
|
||||
get {
|
||||
if (_order.HasState && _order.State.HasCreated) {
|
||||
return _order.State.Created.ToDateTime().ToLocalTime();
|
||||
}
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public string security_text {
|
||||
get {
|
||||
return security.HasValue ? security.Value.ToString() : "Unkown security";
|
||||
}
|
||||
}
|
||||
|
||||
public Thickness Margin {
|
||||
get {
|
||||
int level = _book_vm.depth_level(this.order.Key);
|
||||
double left_margin = 10.0 * level;
|
||||
return new Thickness(left_margin, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public string security_text_for_depth {
|
||||
// indent child 3 spaces
|
||||
// can probably figure out levels and indent more
|
||||
get {
|
||||
int level = _book_vm.depth_level(this.order.Key);
|
||||
int num_spaces_for_indent = 3 * level;
|
||||
return new string(' ', num_spaces_for_indent) + security_text;
|
||||
}
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public Venue exchange {
|
||||
get => security.HasValue ? security.Value.Exchange : bts.api.Venue.Unset;
|
||||
set => ignore();
|
||||
}
|
||||
public CustomOrderDefinition.CustomOneofCase order_type {
|
||||
get => _order.Def.CustomDef.CustomCase;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public OrderSubType order_sub_type {
|
||||
get => _order.Def.SubType;
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
|
||||
public string order_sub_type_abbreviation {
|
||||
get => _order.Def.SubType == OrderSubType.None ? string.Empty : _order.Def.SubType.ToString().Substring(0,1);
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public OrderMetadata order_metadata {
|
||||
get => _model.factory.get_metadata(order_type);
|
||||
set => ignore();
|
||||
}
|
||||
|
||||
public bool is_selected { get; set; }
|
||||
|
||||
public bool is_paused { get; set; }
|
||||
|
||||
public bool is_parent {
|
||||
get => this._child_order_ids.Count > 0;
|
||||
set => ignore();
|
||||
}
|
||||
public bool is_child => _order.ParentKey != 0;
|
||||
|
||||
public void add_child_order(uint child_order_id) {
|
||||
_child_order_ids.Add(child_order_id);
|
||||
// we don't need to raise this every single time
|
||||
if (_child_order_ids.Count <= 1) {
|
||||
RaisePropertyChanged("is_parent");
|
||||
}
|
||||
}
|
||||
|
||||
private bool _i_match_a_filter = true;
|
||||
public bool i_match_a_filter {
|
||||
get { return _i_match_a_filter; }
|
||||
set { _i_match_a_filter = value; }
|
||||
}
|
||||
|
||||
|
||||
// the root node will contain the bit that says yah or nay regarding
|
||||
// the whole branch.
|
||||
public bool branch_matches_filter {
|
||||
get {
|
||||
if (this.order.has_parent()) {
|
||||
var parent_order = _book_vm.get_parent_order_vm(this.order.ParentKey);
|
||||
if (parent_order != null) {
|
||||
return parent_order.branch_matches_filter;
|
||||
}
|
||||
// parent can't be found, so can't check status, so show by default
|
||||
return true;
|
||||
} else {
|
||||
return i_match_a_filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OrderBookRowVM root_vm {
|
||||
get {
|
||||
if (this.order.has_parent()) {
|
||||
if(_book_vm.get_parent_order_vm(this.order.ParentKey) != null) {
|
||||
return _book_vm.get_parent_order_vm(this.order.ParentKey).root_vm;
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Property<bool> _expanded;
|
||||
public bool is_expanded {
|
||||
get => _expanded.Value;
|
||||
set {
|
||||
_expanded.set(value);
|
||||
_book_vm.set_expanded(value, _order.Key);
|
||||
}
|
||||
}
|
||||
|
||||
Property<bool> _visible;
|
||||
|
||||
public event Action invalidated;
|
||||
void _unused_invalidate() => invalidated?.Invoke();
|
||||
|
||||
public bool is_visible { get => _visible.Value; set => _visible.set(value); }
|
||||
|
||||
public ICommand toggle_command { get; }
|
||||
public ICommand show_order_modify_command { get; }
|
||||
public ICommand default_command => show_order_modify_command;
|
||||
|
||||
public override string ToString() {
|
||||
return $"{order_key} {last_change} {parent_order_key}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using static bts.shell.OrderBookWindowFactory;
|
||||
using static mbts.spark.OrderBookView;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class OrderBookVM : DisposableViewModelBase, IHandleRowSelection, IOrderBookVM {
|
||||
readonly OrderBookWindowFactory _creator;
|
||||
readonly OrdersModel _model;
|
||||
ObservableCollection<OrderBookRowVM> _selected_rows = new ObservableCollection<OrderBookRowVM>();
|
||||
|
||||
public OrderBookVM(OrderBookWindowFactory factory, IBus bus, OrdersModel model, OrderBookWindowFactory.OrderBookStartupData state) {
|
||||
// may not need the factory any longer since savestate is handled by the window
|
||||
_creator = factory;
|
||||
_bus = bus;
|
||||
_model = model;
|
||||
_visible_orders = new ObservableFilterCollection<OrderBookRowVM>(_orders, o => o.is_visible && o.branch_matches_filter);
|
||||
|
||||
#region Create grid filters and load state
|
||||
side_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, Side>(new[] { Side.Buy, Side.Sell }, r => r.side, nameof(OrderBookRowVM.side));
|
||||
order_type_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, CustomOrderDefinition.CustomOneofCase>(EnumHelper.get_values<CustomOrderDefinition.CustomOneofCase>().ToLArray(), r => r.order_type, nameof(OrderBookRowVM.order_type));
|
||||
order_sub_type_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, OrderSubType>(EnumHelper.get_values<OrderSubType>().ToLArray(), r => r.order_sub_type, nameof(OrderBookRowVM.order_sub_type));
|
||||
tif_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, TimeInForce>(EnumHelper.get_values<TimeInForce>().ToLArray(), r => r.tif, nameof(OrderBookRowVM.tif));
|
||||
exchange_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, Venue>(EnumHelper.get_values<Venue>().ToLArray(), r => r.exchange, nameof(OrderBookRowVM.exchange));
|
||||
account_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, string>(_model.factory.subscribe_accounts(), r => r.account, nameof(OrderBookRowVM.account));
|
||||
user_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, string>(_model.factory.subscribe_users(), r => r.user, nameof(OrderBookRowVM.user));
|
||||
order_key_filter = new RegexFilterVM<OrderBookRowVM>(r => r.order_key, nameof(OrderBookRowVM.order_key));
|
||||
security_key_filter = new RegexFilterVM<OrderBookRowVM>(r => r.security_key.ToString(), nameof(OrderBookRowVM.security_key));
|
||||
status_filter = DiscreteValuesFilterVM.Create<OrderBookRowVM, OrderStatus>(EnumHelper.get_values<OrderStatus>().ToLArray(), r => r.status, nameof(OrderBookRowVM.status));
|
||||
exchange_message_filter = new RegexFilterVM<OrderBookRowVM>(r => r.last_msg, nameof(OrderBookRowVM.last_msg));
|
||||
|
||||
if (state.filters != null)
|
||||
{
|
||||
order_key_filter.load_state(state.filters.order_key_regex);
|
||||
time_created_filter.load_state(state.filters.time_created);
|
||||
user_filter.load_state(state.filters.users);
|
||||
account_filter.load_state(state.filters.accounts);
|
||||
exchange_filter.load_state(state.filters.exchanges);
|
||||
tif_filter.load_state(state.filters.tifs);
|
||||
order_type_filter.load_state(state.filters.order_types);
|
||||
side_filter.load_state(state.filters.sides);
|
||||
qty_filter.load_state(state.filters.qty);
|
||||
price_filter.load_state(state.filters.price);
|
||||
qty_filled_filter.load_state(state.filters.qty_filled);
|
||||
avg_price_filter.load_state(state.filters.avg_price);
|
||||
last_price_filter.load_state(state.filters.last_price);
|
||||
status_filter.load_state(state.filters.statuses);
|
||||
exchange_message_filter.load_state(state.filters.exchange_message_regex);
|
||||
last_change_filter.load_state(state.filters.last_change);
|
||||
security_filter.load_state(state.filters.security_regex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// default order form filter to only show status == working
|
||||
status_filter.load_state(new OrderStatus[] { OrderStatus.Working });
|
||||
}
|
||||
|
||||
var fs = new List<IDataGridColumnFilter<OrderBookRowVM>>() {
|
||||
security_filter
|
||||
, time_created_filter
|
||||
, last_change_filter
|
||||
, user_filter
|
||||
, account_filter
|
||||
, exchange_filter
|
||||
, tif_filter
|
||||
, order_type_filter
|
||||
, order_sub_type_filter
|
||||
, side_filter
|
||||
, qty_filter
|
||||
, price_filter
|
||||
, qty_filled_filter
|
||||
, avg_price_filter
|
||||
, last_price_filter
|
||||
, status_filter
|
||||
, exchange_message_filter
|
||||
, security_key_filter
|
||||
, order_key_filter
|
||||
}.ToArray();
|
||||
#endregion
|
||||
|
||||
// restore sort criteria if any
|
||||
if (state.sort_criteria.Count > 0) {
|
||||
var saved_criteria = state.sort_criteria[0];
|
||||
current_sort_description = new SortDescription(saved_criteria.col_name, saved_criteria.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
|
||||
}
|
||||
|
||||
_current_row = backing<OrderBookRowVM>(nameof(current_row));
|
||||
|
||||
var securities_sequence = _bus.subscribe(SparkTags.SecuritiesTag);
|
||||
var orders_with_found_securities_sub = _model.on_orders
|
||||
.Sample(TimeSpan.FromMilliseconds(333))
|
||||
.CombineLatest(securities_sequence,
|
||||
(order_list, security_dict) => {
|
||||
List<(OrderRecordImmutable order, SecurityImmutable? security)> orders_and_securities = new List<(OrderRecordImmutable, SecurityImmutable?)>(order_list.state.Count);
|
||||
foreach (var order in order_list.state.Values) {
|
||||
if (security_dict.TryGetValue(order.Def.SecurityKey, out SecurityMD sec_md)) {
|
||||
orders_and_securities.Add((order, sec_md.security));
|
||||
} else {
|
||||
orders_and_securities.Add((order, null));
|
||||
}
|
||||
}
|
||||
return orders_and_securities;
|
||||
})
|
||||
.OnDispatcher()
|
||||
.Subscribe(order_security_pairs => {
|
||||
using (_visible_orders.defer_refresh())
|
||||
{
|
||||
apply_sort(order_security_pairs);
|
||||
apply_filter(fs);
|
||||
}
|
||||
});
|
||||
|
||||
columns.Add(new SecurityColumn(security_filter));
|
||||
columns.Add(new TimeCreatedColumn(time_created_filter));
|
||||
columns.Add(new LastChangeTimeColumn(last_change_filter));
|
||||
add_text_col(Columns.User, DefaultColumnHeaders.User, nameof(OrderBookRowVM.user), r => r.user, DefaultColumnWidths.User, user_filter, DataGridFilterKnownTemplates.DiscreteValues);
|
||||
add_text_col(Columns.Account, DefaultColumnHeaders.Account, nameof(OrderBookRowVM.account), r => r.account, DefaultColumnWidths.Account, account_filter, DataGridFilterKnownTemplates.DiscreteValues);
|
||||
add_text_col(Columns.Exchange, DefaultColumnHeaders.Exchange, nameof(OrderBookRowVM.exchange), r => r.exchange.ToString(), DefaultColumnWidths.Exchange, exchange_filter, DataGridFilterKnownTemplates.EnumValues);
|
||||
add_text_col(Columns.TimeInForce, DefaultColumnHeaders.TimeInForce, nameof(OrderBookRowVM.tif), r => r.tif.ToString(), DefaultColumnWidths.TimeInForce, tif_filter, DataGridFilterKnownTemplates.EnumValues);
|
||||
columns.Add(new OrderTypeColumn<Columns>(Columns.OrderType, new Binding(nameof(OrderBookRowVM.order_type)), new Binding(nameof(OrderBookRowVM.order_metadata)), order_type_filter) {
|
||||
font_weight_binding = RenderUtils.get_font_weight_binding()
|
||||
});
|
||||
add_text_col(Columns.SubType, "Sub Type", nameof(OrderBookRowVM.order_sub_type), r => r.order_sub_type.ToString(), 80, order_sub_type_filter, SubTypeFilterTemplateKey);
|
||||
columns.Add(new SideColumn(side_filter));
|
||||
columns.Add(new SizeColumn(qty_filter));
|
||||
columns.Add(new PriceColumn(price_filter));
|
||||
columns.Add(new FilledColumn(qty_filled_filter));
|
||||
columns.Add(new AvgFilledColumn(avg_price_filter));
|
||||
columns.Add(new LastFilledColumn(last_price_filter));
|
||||
add_text_col(Columns.Status, "Status", nameof(OrderBookRowVM.status), r => r.status.ToString(), 80, status_filter, DataGridFilterKnownTemplates.EnumValues);
|
||||
columns.Add(new TextColumn<Columns>(Columns.LastMessage, new Binding(nameof(OrderBookRowVM.last_msg)), exchange_message_filter, DataGridFilterKnownTemplates.Regex) {
|
||||
Header = "Last Message",
|
||||
Width = 80,
|
||||
tooltip_binding = new Binding(nameof(OrderBookRowVM.last_msg))
|
||||
});
|
||||
add_text_col(Columns.SecurityKey, DefaultColumnHeaders.SecurityKey, nameof(OrderBookRowVM.security_key), r => r.security_key.ToString(), DefaultColumnWidths.SecurityKey, security_key_filter, DataGridFilterKnownTemplates.Regex);
|
||||
add_text_col(Columns.OrderKey, DefaultColumnHeaders.OrderKey, nameof(OrderBookRowVM.order_key), r => r.order_key.ToString(), DefaultColumnWidths.OrderKey, order_key_filter, DataGridFilterKnownTemplates.Regex);
|
||||
//
|
||||
void add_text_col(Columns key, string header, string sort_prop, Func<OrderBookRowVM, string> get_text, double width, IDataGridColumnFilter filter, string filter_template) =>
|
||||
columns.Add(new SimpleTextColumn(key, header, sort_prop, get_text, width, filter, filter_template));
|
||||
//
|
||||
foreach (var col in columns)
|
||||
if (col.sort_member_path == current_sort_description.PropertyName)
|
||||
col.SortDirection = current_sort_description.Direction;
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
orders_with_found_securities_sub,
|
||||
DataGridFilterHelper.hook_filters(visible_orders
|
||||
, () => {
|
||||
using (_visible_orders.defer_refresh()) {
|
||||
apply_filter(fs);
|
||||
}
|
||||
}
|
||||
, fs
|
||||
));
|
||||
}
|
||||
|
||||
public ObservableCollection<ColumnBase> columns { get; } = new ObservableCollection<ColumnBase>();
|
||||
|
||||
private void apply_sort(List<(OrderRecordImmutable order, SecurityImmutable? security)> order_security_pairs) {
|
||||
// create OrderBookRowVMs for all order_security_pairs
|
||||
Dictionary<uint, OrderBookRowVM> dict = new Dictionary<uint, OrderBookRowVM>(order_security_pairs.Count());
|
||||
foreach (var entry in order_security_pairs) {
|
||||
dict.Add(entry.order.Key, new OrderBookRowVM(_bus, this, _model, entry.order, entry.security));
|
||||
}
|
||||
|
||||
// call add_child_order on the row_vm so make children known
|
||||
foreach (var i in dict.Values) {
|
||||
if (i.is_child && dict.ContainsKey(i.parent_order_key)) {
|
||||
dict[i.parent_order_key].add_child_order(i.order.Key);
|
||||
}
|
||||
}
|
||||
|
||||
if (_get_comparer_for_sort_description(current_sort_description, out Comparer<OrderBookRowVM> sorter)) {
|
||||
SortedTree<OrderBookRowVM, uint> forest = new SortedTree<OrderBookRowVM, uint>(
|
||||
sorter
|
||||
, row_vm => row_vm.order.Key
|
||||
, row_vm => row_vm.order.ParentKey
|
||||
, dict.Values
|
||||
);
|
||||
_orders.sync_with(forest);
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME Jake -- this might be slow, consider trying to work the meat of this into the _visible_orders lambda
|
||||
private void apply_filter(IDataGridColumnFilter<OrderBookRowVM>[] fs) {
|
||||
// make everything invisble
|
||||
foreach (var z in _orders) {
|
||||
if (z.root_vm != null) {
|
||||
z.root_vm.i_match_a_filter = false;
|
||||
}
|
||||
}
|
||||
|
||||
// find the rows that match the filter
|
||||
var active_filters = fs.Where(f => f.active.HasValue && f.active.Value).ToList();
|
||||
Func<OrderBookRowVM, bool> x = r => active_filters.All(f => f.filter(r));
|
||||
var rows_matching_filter = _orders.Where(x);
|
||||
|
||||
// set their root nodes to filtered
|
||||
foreach (var row_vm in rows_matching_filter) {
|
||||
if (row_vm.root_vm != null) {
|
||||
row_vm.root_vm.i_match_a_filter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void on_sorting(DIYGridSortingEventArgs e) {
|
||||
e.Column.SortDirection = e.Column.SortDirection.HasValue && e.Column.SortDirection.Value == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending;
|
||||
if (_get_comparer_for_column(e.Column, out Comparer<OrderBookRowVM> sorter)) {
|
||||
SortedTree<OrderBookRowVM, uint> forest = new SortedTree<OrderBookRowVM, uint>(
|
||||
sorter
|
||||
, row_vm => row_vm.order.Key
|
||||
, row_vm => row_vm.order.ParentKey
|
||||
, _orders
|
||||
);
|
||||
// we don't want the filter firing while the internal list is changing
|
||||
// b/c parent discovery wono't work while the list is in trasitional
|
||||
// states
|
||||
using (_visible_orders.defer_refresh()) {
|
||||
_orders.sync_with(forest);
|
||||
}
|
||||
}
|
||||
// We ALWAYS want to set this here, else the grid tries to be helpful
|
||||
// and sort with its own CollectionView, which destroys the SortedTree
|
||||
// sort order; we want it to never use the CollectionView
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private bool _get_comparer_for_sort_description(SortDescription sc, out Comparer<OrderBookRowVM> s) {
|
||||
int mult = sc.Direction == ListSortDirection.Ascending ? 1 : -1;
|
||||
switch (sc.PropertyName) {
|
||||
case nameof(OrderBookRowVM.security_text):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.security_text.CompareTo(second.security_text)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.time_created):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.time_created.CompareTo(second.time_created)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.last_change):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.last_change.CompareTo(second.last_change)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.user):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.user.CompareTo(second.user)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.account):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.account.CompareTo(second.account)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.exchange):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.exchange.CompareTo(second.exchange)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.tif):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.tif.CompareTo(second.tif)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.order_type):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.order_type.CompareTo(second.order_type)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.order_sub_type):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.order_sub_type.CompareTo(second.order_sub_type)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.side):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.side.CompareTo(second.side)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.quantity):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.quantity.CompareTo(second.quantity)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.price):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.price.CompareTo(second.price)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.filled_quantity):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.filled_quantity.CompareTo(second.filled_quantity)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.avg_price):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.avg_price.CompareTo(second.avg_price)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.last_price):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.last_price.CompareTo(second.last_price)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.status):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.status.CompareTo(second.status)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.last_msg):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.last_msg.CompareTo(second.last_msg)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.security_key):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.security_key.CompareTo(second.security_key)
|
||||
);
|
||||
return true;
|
||||
case nameof(OrderBookRowVM.order_key):
|
||||
s = Comparer<OrderBookRowVM>.Create((first, second) =>
|
||||
mult * first.order_key.CompareTo(second.order_key)
|
||||
);
|
||||
return true;
|
||||
default:
|
||||
s = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _get_comparer_for_column(ColumnBase c, out Comparer<OrderBookRowVM> sorter) {
|
||||
if (!(c.sort_member_path is string sort_path))
|
||||
sorter = null;
|
||||
else {
|
||||
var proposed_sort = new SortDescription(sort_path, c.SortDirection.Value);
|
||||
if (_get_comparer_for_sort_description(proposed_sort, out sorter)) {
|
||||
current_sort_description = proposed_sort;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private readonly IBus _bus;
|
||||
|
||||
public OrderBookRowVM get_parent_order_vm(uint target_parent_key) =>
|
||||
_orders.FirstOrDefault(x => x.order.Key == target_parent_key);
|
||||
|
||||
internal void set_expanded(bool visible, uint target_parent_key) {
|
||||
foreach (var order in _orders) {
|
||||
if (order.parent_order_key == target_parent_key) {
|
||||
order.is_visible = visible;
|
||||
set_expanded(visible, order.order.Key);
|
||||
}
|
||||
}
|
||||
_visible_orders.trigger_filter();
|
||||
}
|
||||
|
||||
internal bool order_has_children(uint order_key) {
|
||||
bool found = _orders.Any(row_vm => row_vm.parent_order_key == order_key);
|
||||
if (!found) { Debug.WriteLine($"no orders found with {order_key} as a parent ==> no children"); }
|
||||
return found;
|
||||
}
|
||||
|
||||
internal int depth_level(uint order_key) {
|
||||
int i = -1;
|
||||
while (order_key != 0) {
|
||||
i++;
|
||||
var found_order_for_key = _orders.Where(x => x.order.Key == order_key);
|
||||
if (found_order_for_key.Count() > 0) {
|
||||
order_key = found_order_for_key.First().parent_order_key;
|
||||
} else {
|
||||
// can't traverse list, so stick it at depth 1
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public void row_selection_changed(SelectionChangedEventArgs e) {
|
||||
RowSelectionHelper.apply_changes(_selected_rows, e);
|
||||
on_selected_order_changed(current_order);
|
||||
}
|
||||
|
||||
public event Action<OrderRecordImmutable?> selected_order_changed;
|
||||
|
||||
void on_selected_order_changed(OrderRecordImmutable? order) {
|
||||
selected_order_changed?.Invoke(order);
|
||||
}
|
||||
|
||||
private ObservableCollection<OrderBookRowVM> _orders = new ObservableCollection<OrderBookRowVM>();
|
||||
|
||||
private ObservableFilterCollection<OrderBookRowVM> _visible_orders;
|
||||
public ObservableFilterCollection<OrderBookRowVM> visible_orders {
|
||||
get {
|
||||
return _visible_orders;
|
||||
}
|
||||
}
|
||||
|
||||
public SortDescription current_sort_description { get; set; } = new SortDescription(nameof(OrderBookRowVM.time_created), ListSortDirection.Descending);
|
||||
|
||||
Property<OrderBookRowVM> _current_row;
|
||||
public OrderBookRowVM current_row { get => _current_row.Value; set => _current_row.Value = value ?? _selected_rows.FirstOrDefault(); }
|
||||
public OrderRecordImmutable? current_order => current_row?.order;
|
||||
public ObservableCollection<OrderBookRowVM> selected_rows => _selected_rows;
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => _selected_rows.Select(r => r.order);
|
||||
|
||||
#region Filters
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> price_filter { get; } = new DoubleMinMax<OrderBookRowVM>(r => r.price, nameof(OrderBookRowVM.price));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, UIntMinMaxState> qty_filter { get; } = new UIntMinMax<OrderBookRowVM>(r => r.quantity, nameof(OrderBookRowVM.quantity));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, UIntMinMaxState> qty_filled_filter { get; } = new UIntMinMax<OrderBookRowVM>(r => r.filled_quantity, nameof(OrderBookRowVM.filled_quantity));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, Side[]> side_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, CustomOrderDefinition.CustomOneofCase[]> order_type_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, OrderSubType[]> order_sub_type_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, TimeInForce[]> tif_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, Venue[]> exchange_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string[]> account_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string[]> user_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, TimeFilterTuple> time_created_filter { get; } = new TimeFilterVM<OrderBookRowVM>(r => r.time_created, nameof(OrderBookRowVM.time_created));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, TimeFilterTuple> last_change_filter { get; } = new TimeFilterVM<OrderBookRowVM>(r => r.last_change, nameof(OrderBookRowVM.last_change));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string> order_key_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string> security_key_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> avg_price_filter { get; } = new DoubleMinMax<OrderBookRowVM>(r => r.avg_price, nameof(OrderBookRowVM.avg_price));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, DoubleMinMaxState> last_price_filter { get; } = new DoubleMinMax<OrderBookRowVM>(r => r.last_price, nameof(OrderBookRowVM.last_price));
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, OrderStatus[]> status_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string> exchange_message_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<OrderBookRowVM, string> security_filter { get; } = new RegexFilterVM<OrderBookRowVM>(r => r.security_text, nameof(OrderBookRowVM.security_text));
|
||||
|
||||
|
||||
public FilterStates get_filter_states() =>
|
||||
new FilterStates {
|
||||
order_key_regex = order_key_filter.get_state(),
|
||||
time_created = time_created_filter.get_state(),
|
||||
users = user_filter.get_state(),
|
||||
accounts = account_filter.get_state(),
|
||||
exchanges = exchange_filter.get_state(),
|
||||
tifs = tif_filter.get_state(),
|
||||
order_types = order_type_filter.get_state(),
|
||||
sides = side_filter.get_state(),
|
||||
qty = qty_filter.get_state(),
|
||||
price = price_filter.get_state(),
|
||||
qty_filled = qty_filled_filter.get_state(),
|
||||
avg_price = avg_price_filter.get_state(),
|
||||
last_price = last_price_filter.get_state(),
|
||||
statuses = status_filter.get_state(),
|
||||
exchange_message_regex = exchange_message_filter.get_state(),
|
||||
last_change = last_change_filter.get_state(),
|
||||
security_regex = security_filter.get_state()
|
||||
};
|
||||
|
||||
public List<SortingCriteria> get_sorting_states() =>
|
||||
new List<SortingCriteria>() { new SortingCriteria(current_sort_description) };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.spark {
|
||||
interface IOrderBookVM : IDisposable {
|
||||
event Action<OrderRecordImmutable?> selected_order_changed;
|
||||
//
|
||||
OrderRecordImmutable? current_order { get; }
|
||||
IEnumerable<OrderRecordImmutable> selected_orders { get; }
|
||||
//
|
||||
void on_sorting(DIYGridSortingEventArgs e);
|
||||
List<SortingCriteria> get_sorting_states();
|
||||
OrderBookWindowFactory.FilterStates get_filter_states();
|
||||
}
|
||||
|
||||
internal partial class OrderBookView : UserControl {
|
||||
public enum Columns { Security, Time, LastChange, User, Account, Exchange, TimeInForce, OrderType, SubType, Side, Size, Price, Filled, AvgFilled, LastPrice, Status, LastMessage, SecurityKey, OrderKey, ParentKey }
|
||||
public const string
|
||||
SubTypeFilterTemplateKey = "SubTypeFilterTemplate",
|
||||
ExpandCollapseToggleStyleKey = "ExpandCollapseToggleStyle",
|
||||
RowStyleKey = "RowStyle",
|
||||
RowTemplateKey = "RowTemplateKey",
|
||||
CVRowStyleKey = "CVRowStyle",
|
||||
CVRowTemplateKey = "CVRowTemplateKey";
|
||||
|
||||
public static string ActiveRowStyleKey =>
|
||||
OrderBookWindow.cv_orderbook_enabled ? CVRowStyleKey : RowStyleKey;
|
||||
|
||||
public static string ActiveRowTemplateKey =>
|
||||
OrderBookWindow.cv_orderbook_enabled ? CVRowTemplateKey : RowTemplateKey;
|
||||
|
||||
public const double RowHeight = 17;
|
||||
IOrderBookVM _vm;
|
||||
|
||||
public OrderBookView(IOrderBookVM vm) {
|
||||
InitializeComponent();
|
||||
_vm = vm;
|
||||
DataContext = vm;
|
||||
}
|
||||
|
||||
void data_grid_sorting(object sender, DIYGridSortingEventArgs args) =>
|
||||
_vm.on_sorting(args);
|
||||
}
|
||||
|
||||
class OrderBookRowView : DIYGrid.HighPerformanceRow<OrderBookRowVM, OrderBookView.Columns> {
|
||||
public OrderBookRowView() : base(OrderBookView.RowHeight) { }
|
||||
}
|
||||
|
||||
class CVOrderBookRowView : DIYGrid.HighPerformanceRow<CVOrderBookRowVM, OrderBookView.Columns> {
|
||||
public CVOrderBookRowView() : base(OrderBookView.RowHeight) { }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user