mview - some cols weren't updating #DIYGrid

This commit is contained in:
John Colvin committed 2018-04-22 20:39:28 -04:00
1 parent d819e440dd
commit 1073ff84e9
3 files changed
+44 -62

No files matched your search

@@ -23,10 +23,10 @@ namespace mbts.spark {
readonly ObservableCollection<OrderRecordImmutable> _orders = new ObservableCollection<OrderRecordImmutable>();
readonly ObservableFilterCollection<OrderRecordImmutable> _working_orders, _working_bids, _working_asks;
readonly string _security_text, _security_key_text;
readonly Property<double> _bid_price, _ask_price;
readonly CellProperty<double> _last_price, _day_change, _settlement, _session_high, _session_low;
readonly Property<double> _bid_price, _ask_price,_last_price, _day_change, _settlement, _session_high, _session_low;
readonly Property<ushort> _bid_size, _ask_size;
readonly CellProperty<int> _position;
readonly CellProperty<ushort> _bid_size, _ask_size, _last_size;
readonly CellProperty<ushort> _last_size;
readonly CellProperty<ulong> _volume;
readonly CellProperty<bool> _inside_bids, _inside_asks;
readonly CellProperty<int> _working_bid_volume, _working_ask_volume;
@@ -43,14 +43,14 @@ namespace mbts.spark {
_position = new CellProperty<int>(0);
_bid_price = backing(nameof(bid_price), double.NaN);
_ask_price = backing(nameof(ask_price), double.NaN);
_bid_size = new CellProperty<ushort>(0);
_ask_size = new CellProperty<ushort>(0);
_last_price = new CellProperty<double>(format_price, double.NaN);
_bid_size = backing<ushort>(nameof(bid_size), 0);
_ask_size = backing<ushort>(nameof(ask_size), 0);
_last_price = backing(nameof(last_price), double.NaN);
_last_size = new CellProperty<ushort>(0);
_day_change = new CellProperty<double>(format_price, double.NaN);
_session_low = new CellProperty<double>(format_price, double.NaN);
_session_high = new CellProperty<double>(format_price, double.NaN);
_settlement = new CellProperty<double>(format_price, double.NaN);
_day_change = backing(nameof(day_change), double.NaN);
_session_low = backing(nameof(session_low), double.NaN);
_session_high = backing(nameof(session_high), double.NaN);
_settlement = backing(nameof(settlement), double.NaN);
_volume = new CellProperty<ulong>(0);
_inside_bids = new CellProperty<bool>();
_inside_asks = new CellProperty<bool>();
@@ -91,17 +91,17 @@ namespace mbts.spark {
public bool inside_bids => _inside_bids.value;
public bool inside_asks => _inside_asks.value;
public int position => _position.value;
public double last_price => _last_price.value;
public double last_price => _last_price.Value;
public ushort last_size => _last_size.value;
public double bid_price => _bid_price.Value;
public ushort bid_size => _bid_size.value;
public ushort bid_size => _bid_size.Value;
public double ask_price => _ask_price.Value;
public ushort ask_size => _ask_size.value;
public ushort ask_size => _ask_size.Value;
public ulong volume => _volume.value;
public double settlement => _settlement.value;
public double day_change => _day_change.value;
public double session_low => _session_low.value;
public double session_high => _session_high.value;
public double settlement => _settlement.Value;
public double day_change => _day_change.Value;
public double session_low => _session_low.Value;
public double session_high => _session_high.Value;
public int working_bid_volume => _working_bid_volume.value;
public int working_ask_volume => _working_ask_volume.value;
public string working_bids_text => OrderUtils.order_collection_summary(_working_bids, (x, y) => x.CompareTo(y), security.ContractSpec);
@@ -116,49 +116,27 @@ namespace mbts.spark {
public ICommand ask_size_click { get; }
public ICommand working_asks_click { get; }
public ICommand default_command { get; }
public string this[MarketViewView.Columns column] {
get {
switch (column) {
case MarketViewView.Columns.Security: return _security_text;
case MarketViewView.Columns.Volume: return _volume.text;
case MarketViewView.Columns.Last: return _last_price.text;
case MarketViewView.Columns.LastSize: return _last_size.text;
case MarketViewView.Columns.Position: return _position.text;
case MarketViewView.Columns.WorkingBids: return _working_bids_text.text;
case MarketViewView.Columns.BidSize: return _bid_size.text;
case MarketViewView.Columns.AskSize: return _ask_size.text;
case MarketViewView.Columns.WorkingAsks: return _working_asks_text.text;
case MarketViewView.Columns.Settlement: return _settlement.text;
case MarketViewView.Columns.DayChange: return _day_change.text;
case MarketViewView.Columns.SessionLow: return _session_low.text;
case MarketViewView.Columns.SessionHigh: return _session_high.text;
case MarketViewView.Columns.SecurityKey: return _security_key_text;
default: return null;
}
}
}
#endregion
public void refresh() {
bool dirty = false;
if (md.md.get_bbo(ref _bbo_ref, out NativePriceSize b, out NativePriceSize a)) {
_bid_price.set(b.price);
_bid_size.on_next_distinct(b.size, ref dirty);
_bid_size.set(b.size);
_ask_price.set(a.price);
_ask_size.on_next_distinct(a.size, ref dirty);
_ask_size.set(a.size);
_inside_bids.on_next_distinct(_bid_price.Value >= _working_best_bid.value, ref dirty);
_inside_asks.on_next_distinct(_ask_price.Value <= _working_best_ask.value, ref dirty);
}
if (md.md.get_last_trade(ref _last_ref, out NativePriceSize ps, out DateTime ts, out ulong v)) {
_last_price.on_next_distinct(ps.price, ref dirty);
_last_price.set(ps.price);
_last_size.on_next_distinct(ps.size, ref dirty);
_volume.on_next_distinct(v, ref dirty);
}
_settlement.on_next_distinct(md.md.settlement_price, ref dirty);
_session_low.on_next_distinct(md.md.session_low, ref dirty);
_session_high.on_next_distinct(md.md.session_high, ref dirty);
_day_change.on_next_distinct(last_price - settlement, ref dirty);
_settlement.set(md.md.settlement_price);
_session_low.set(md.md.session_low);
_session_high.set(md.md.session_high);
_day_change.set(last_price - settlement);
if (dirty)
invalidated?.Invoke();
}
@@ -252,8 +230,7 @@ namespace mbts.spark {
_working_best_ask.on_next_distinct(_working_asks.Min(o => o.State.Price, double.NaN), ref dirty);
_inside_bids.on_next_distinct(_bid_price.Value >= _working_best_bid.value, ref dirty);
_inside_asks.on_next_distinct(_ask_price.Value <= _working_best_ask.value, ref dirty);
_working_bids_text.on_next_distinct(OrderUtils.order_collection_summary(_working_bids, (x, y) => x.CompareTo(y), security.ContractSpec), ref dirty);
_working_asks_text.on_next_distinct(OrderUtils.order_collection_summary(_working_asks, (x, y) => y.CompareTo(x), security.ContractSpec), ref dirty);
RaisePropertyChanged(nameof(working_bids_text), nameof(working_asks_text));
}
#endregion
}
@@ -26,25 +26,25 @@ namespace mbts.spark {
const string size_col_header = "Qty", working_col_header = "Working";
const double working_orders_col_width = 105;
IMultiValueConverter price_converter = new ui.spark.converters.TickDisplayConverter();
add_col(Columns.Security, "Security", nameof(Row.security), DefaultColumnWidths.Security, security_filter, DataGridFilterKnownTemplates.Regex);
add_col(Columns.Volume, "Volume", nameof(Row.volume), 64, volume_filter, DataGridFilterKnownTemplates.ULongMinMax);
add_col(Columns.Last, "Last", nameof(Row.last_price), DefaultColumnWidths.Price, last_price_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.LastSize, size_col_header, nameof(Row.last_size), DefaultColumnWidths.Size, last_size_filter, DataGridFilterKnownTemplates.UShortMinMax);
add_col(Columns.Position, "Pos", nameof(Row.position), DefaultColumnWidths.Size, position_filter, DataGridFilterKnownTemplates.IntMinMax, true);
add_col(Columns.Security, "Security", r => r.security.ToString(null), nameof(Row.security), DefaultColumnWidths.Security, security_filter, DataGridFilterKnownTemplates.Regex);
add_col(Columns.Volume, "Volume", r => r.volume.ToString(), nameof(Row.volume), 64, volume_filter, DataGridFilterKnownTemplates.ULongMinMax);
add_col(Columns.Last, "Last", r => r.format_price(r.last_price), nameof(Row.last_price), DefaultColumnWidths.Price, last_price_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.LastSize, size_col_header, r => r.last_size.ToString(), nameof(Row.last_size), DefaultColumnWidths.Size, last_size_filter, DataGridFilterKnownTemplates.UShortMinMax);
add_col(Columns.Position, "Pos", r => r.position.ToString(), nameof(Row.position), DefaultColumnWidths.Size, position_filter, DataGridFilterKnownTemplates.IntMinMax, true);
add_hl_working_orders_col(Columns.WorkingBids, working_col_header, nameof(Row.working_bids_text), nameof(Row.working_best_bid), nameof(Row.working_bids_click), working_bid_volume_filter, BTSColors.MarketData.bid_brush);
add_hl_size_col(Columns.BidSize, size_col_header, nameof(Row.bid_size), nameof(Row.bid_size_click), bid_size_filter, BTSColors.MarketData.bid_brush);
add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text_brush, BTSColors.MarketData.bid_brush);
add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text_brush, BTSColors.MarketData.ask_brush);
add_hl_size_col(Columns.AskSize, size_col_header, nameof(Row.ask_size), nameof(Row.ask_size_click), ask_size_filter, BTSColors.MarketData.ask_brush);
add_hl_working_orders_col(Columns.WorkingAsks, working_col_header, nameof(Row.working_asks_text), nameof(Row.working_best_ask), nameof(Row.working_asks_click), working_ask_volume_filter, BTSColors.MarketData.ask_brush);
add_col(Columns.Settlement, "Settlement", nameof(Row.settlement), DefaultColumnWidths.Price, settlement_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.DayChange, "Change", nameof(Row.day_change), DefaultColumnWidths.Price, day_change_filter, DataGridFilterKnownTemplates.DoubleMinMax, true);
add_col(Columns.SessionLow, "Low", nameof(Row.session_low), DefaultColumnWidths.Price, session_low_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.SessionHigh, "High", nameof(Row.session_high), DefaultColumnWidths.Price, session_high_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.SecurityKey, "Security Key", nameof(Row.security_key), DefaultColumnWidths.SecurityKey, security_key_filter, DataGridFilterKnownTemplates.Regex);
add_col(Columns.Settlement, "Settlement", r => r.format_price(r.settlement), nameof(Row.settlement), DefaultColumnWidths.Price, settlement_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.DayChange, "Change", r => r.format_price(r.day_change), nameof(Row.day_change), DefaultColumnWidths.Price, day_change_filter, DataGridFilterKnownTemplates.DoubleMinMax, true);
add_col(Columns.SessionLow, "Low", r => r.format_price(r.session_low), nameof(Row.session_low), DefaultColumnWidths.Price, session_low_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.SessionHigh, "High", r => r.format_price(r.session_high), nameof(Row.session_high), DefaultColumnWidths.Price, session_high_filter, DataGridFilterKnownTemplates.DoubleMinMax);
add_col(Columns.SecurityKey, "Security Key", r => r.security_key.ToString(), nameof(Row.security_key), DefaultColumnWidths.SecurityKey, security_key_filter, DataGridFilterKnownTemplates.Regex);
//
void add_col(Columns col_key, string header, string prop, double width, IDataGridColumnFilter filter, string filter_template, bool is_animatable = false) =>
columns.Add(new InternalTextColumn(col_key, filter, filter_template) {
void add_col(Columns col_key, string header, Func<Row, string> get_text, string prop, double width, IDataGridColumnFilter filter, string filter_template, bool is_animatable = false) =>
columns.Add(new InternalTextColumn(col_key, get_text, filter, filter_template) {
Header = header,
sort_member_path = prop,
Width = width,
@@ -160,8 +160,8 @@ namespace mbts.spark {
}
class InternalTextColumn : RenderTextColumn<Row>, IKeyedColumn<Columns> {
public InternalTextColumn(Columns key, IDataGridColumnFilter filter, string filter_template)
: base(r => r[key], filter, filter_template) => this.key = key;
public InternalTextColumn(Columns key, Func<Row, string> get_text, IDataGridColumnFilter filter, string filter_template)
: base(get_text, filter, filter_template) => this.key = key;
public Columns key { get; }
}
@@ -11,4 +11,9 @@ namespace mbts.spark {
public SecurityImmutable security { get; }
public uint security_key => security.Id;
}
static class SecurityRowExtensions {
public static string format_price(this ISecurityRow row, double price) =>
row.security.ContractSpec.format(price);
}
}