PR suggestions

This commit is contained in:
Jake Norbut committed 2018-12-05 16:07:44 -06:00
1 parent 05d0eee8c7
commit 631158ebbc
3 files changed
+34 -30

No files matched your search

@@ -45,28 +45,28 @@ namespace mbts.spark {
_security_text = smd.security.ToString();
_security_key_text = security_key.ToString();
string format_price(double price) => security.ContractSpec.format(price);
_position = new CellProperty<int>(0);
_position = new CellProperty<int>(this, nameof(position), 0);
_bid_price = backing(nameof(bid_price), double.NaN);
_ask_price = backing(nameof(ask_price), double.NaN);
_last_price = backing(nameof(last_price), double.NaN);
_last_size = new CellProperty<uint>(0);
_last_size = new CellProperty<uint>(this, nameof(last_size), 0);
_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>();
_working_bid_volume = new CellProperty<int>();
_working_ask_volume = new CellProperty<int>();
_volume = new CellProperty<ulong>(this, nameof(volume), 0);
_inside_bids = new CellProperty<bool>(this, nameof(inside_bids));
_inside_asks = new CellProperty<bool>(this, nameof(inside_asks));
_working_bid_volume = new CellProperty<int>(this, nameof(working_bid_volume));
_working_ask_volume = new CellProperty<int>(this, nameof(working_ask_volume));
//
_working_orders = new ObservableFilterCollection<OrderRecordImmutable>(_orders, o => o.is_active());
_working_bids = new ObservableFilterCollection<OrderRecordImmutable>(_working_orders, o => o.Def.Side == Side.Buy);
_working_asks = new ObservableFilterCollection<OrderRecordImmutable>(_working_orders, o => o.Def.Side == Side.Sell);
_working_best_bid = new CellProperty<double>(format_price, double.NaN);
_working_best_ask = new CellProperty<double>(format_price, double.NaN);
_working_bids_text = new CellProperty<string>(string.Empty);
_working_asks_text = new CellProperty<string>(string.Empty);
_working_best_bid = new CellProperty<double>(this, nameof(working_best_bid), format_price, double.NaN);
_working_best_ask = new CellProperty<double>(this, nameof(working_best_ask), format_price, double.NaN);
_working_bids_text = new CellProperty<string>(this, nameof(working_bids_text), string.Empty);
_working_asks_text = new CellProperty<string>(this, nameof(working_asks_text), string.Empty);
//
default_command = new DelegateCommand(_show_ladder);
bid_price_click = new DelegateCommand(() => _show_order_ticket(MarketViewView.Columns.Bid));
@@ -267,17 +267,17 @@ namespace mbts.spark {
_inside_bids.on_next_distinct(_order_summarizer.best_working_bid >= bid_price, ref dirty);
_inside_asks.on_next_distinct(_order_summarizer.best_working_ask <= ask_price, ref dirty);
// Here we need to RaisePropertyChanged for the non-Property<> cols that are bound to a filter
// (Property implements INotifyPropretyChanged, so this is taken for us autmagically)
// Here we need to RaisePropertyChanged for the non-Property/CellProperty<> cols that are bound to a filter
// (Property and CellProperty implement INotifyPropretyChanged and/or IRaiseNotifyPropertyChanged, so this is taken care of for us autmagically)
// This is so that when the data changes behind the filter, the filter runs again for evaulation
// on whether to show or hide the row
RaisePropertyChanged(
nameof(security),
nameof(volume),
// volume is a CellProperty<>
// last price is a Property<>
nameof(last_size),
nameof(position),
nameof(working_bid_volume),
// last_size is a CellProperty<>
// position is a CellProperty<>
// working_bid_volume is a CellProperty<>
nameof(bid_implied_size),
nameof(bid_direct_size),
nameof(bid_merged_size),
@@ -286,7 +286,7 @@ namespace mbts.spark {
nameof(ask_merged_size),
nameof(ask_direct_size),
nameof(ask_implied_size),
nameof(working_ask_volume),
// working_ask_volume is a CellProperty
// setlltement is a Property<>
// change is a Property<>
// low is a Property<>
@@ -1,16 +1,21 @@
using System;
using mbts.ui.shell;
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace mbts.spark {
class CellProperty<T> : ISubject<T, (T oldval, T newval)> {
readonly Func<T, string> _format;
readonly IRaiseNotifyPropertyChanged _owner;
readonly string _prop_name;
string _text;
public CellProperty(T initial_value = default)
: this(t => t.ToString(), initial_value) { }
public CellProperty(IRaiseNotifyPropertyChanged owner, string prop_name, T initial_value = default)
: this(owner, prop_name, t => t.ToString(), initial_value) { }
public CellProperty(Func<T, string> format, T initial_value = default) {
public CellProperty(IRaiseNotifyPropertyChanged owner, string prop_name, Func<T, string> format, T initial_value = default) {
_owner = owner;
_prop_name = prop_name;
_format = format;
value = initial_value;
}
@@ -24,6 +29,7 @@ namespace mbts.spark {
if (!value.Equals(this.value)) {
OnNext(value);
dirty = true;
_owner.raise_notify_property_changed(_prop_name);
}
}
@@ -15,7 +15,7 @@ namespace mbts.spark {
class PnLSummaryRow : ViewModelBase, IEquatable<PnLSummaryRow>, DIYGrid.IRowVM {
static readonly SignedDataStore<Brush> _brushes;
readonly PnLDoubleBrushCell _start_pnl, _day_pnl, _total_pnl;
readonly PnLPriceCell _pnl_price, _weighted_average_buy, _weighted_average_sell;
readonly CellProperty<double> _pnl_price, _weighted_average_buy, _weighted_average_sell;
(string account, Venue? exchange, string symbol, SecurityImmutable? security, SecurityMD? sec_md, SecurityType? sec_type) key;
IEnumerable<FillImmutable> _fills;
double _driver;
@@ -38,9 +38,9 @@ namespace mbts.spark {
day_short_quantity = day_sell_quant;
total_net_position = net_pos;
start_net_position = sod_pos;
_pnl_price = new PnLPriceCell(this, nameof(pnl_price));
_weighted_average_buy = new PnLPriceCell(this, nameof(weighted_average_buy), wavg_buy);
_weighted_average_sell = new PnLPriceCell(this, nameof(weighted_average_sell), wavg_sell);
_pnl_price = new CellProperty<double>(this, nameof(pnl_price), price => this.security.spec_or_default().format(price), 0);
_weighted_average_buy = new CellProperty<double>(this, nameof(weighted_average_buy), price => this.security.spec_or_default().format(price), wavg_buy);
_weighted_average_sell = new CellProperty<double>(this, nameof(weighted_average_sell), price => this.security.spec_or_default().format(price), wavg_sell);
_fills = fills;
// set the initial pnl and pnl_price when there has been a
@@ -193,10 +193,9 @@ namespace mbts.spark {
class PnLDoubleBrushCell : CellProperty<double> {
Brush _background;
public PnLDoubleBrushCell(PnLSummaryRow owner, string prop) : base(d => double.IsNaN(d) ? string.Empty : d.ToString("N2"), double.NaN) =>
public PnLDoubleBrushCell(PnLSummaryRow owner, string prop) : base(owner, prop, d => double.IsNaN(d) ? string.Empty : d.ToString("N2"), double.NaN) =>
_value_set += _ => {
_background = null;
owner.RaisePropertyChanged(prop);
};
public Brush background => _background ?? (_background = _brushes.get(value));
@@ -204,8 +203,7 @@ namespace mbts.spark {
class PnLPriceCell : CellProperty<double> {
public PnLPriceCell(PnLSummaryRow owner, string prop, double init = 0)
: base(price => owner.security.spec_or_default().format(price), init) =>
_value_set += _ => owner.RaisePropertyChanged(prop);
: base(owner, prop, price => owner.security.spec_or_default().format(price), init) { }
}
}
}