feat (ui): Add Day Fills win
This commit is contained in:
1 parent
a2960b23a8
commit
668dfd9130
27 files changed
+1543
-4
No files matched your search
@@ -203,6 +203,7 @@ namespace mbts.ui {
|
||||
public static ImageSource CopyBoxes => create_icon(CopyBoxesGeometryKey, null, _copy_boxes_pen);
|
||||
public static ImageSource CurrencyExchange => create_icon(CurrencyExchangeGeometryKey);
|
||||
public static ImageSource DataEdit => create_icon(DataEditGeometryKey);
|
||||
public static ImageSource DayFills => create_icon(PaymentGeometryKey);
|
||||
public static ImageSource Defrag { get { return load_resource_and_freeze("Defrag"); } }
|
||||
public static ImageSource DetachAlgos => create_icon_and_rotate(DetachAlgosKey, Brushes.Red);
|
||||
public static ImageSource Disk => create_icon(DiskGeometryKey);
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Spark.Trading {
|
||||
IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_positions { get; }
|
||||
IObservable<TableUpdate<(SecurityImmutable? sec, RetrievedExchangePositionImmutable exch_pos), AccountSecurityKey>> on_exchange_positions { get; }
|
||||
IObservable<TableUpdate<ReconcileReportRowData, AccountSecurityKey>> merged_positions { get; }
|
||||
IObservable<TableUpdate<DayFillsRowData, DayFillsRowKey>> day_fills { get; }
|
||||
|
||||
// pnl
|
||||
IObservable<TableUpdate<PNLRowData, AccountSecurityKey>> pnl { get; }
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
static class DayFillsColumn {
|
||||
public static DayFillsColumn<TColFilter> create<TColFilter>(
|
||||
DayFillsColumnType key,
|
||||
IComparer<DayFillsRowData> comparer_model,
|
||||
IDataGridColumnPersistentFilter<DayFillsRowData, TColFilter> filter_model,
|
||||
string filter_template) {
|
||||
var (get_filter, set_filter) =
|
||||
DIYGridFilterModel.get_filter_prop_delegates<DayFillsFilterSettings, TColFilter>(key.ToString());
|
||||
return create(key, comparer_model, filter_model, get_filter, set_filter, filter_template);
|
||||
}
|
||||
|
||||
public static DayFillsColumn<TColFilter> create<TColFilter>(
|
||||
DayFillsColumnType key,
|
||||
IComparer<DayFillsRowData> comparer_model,
|
||||
IDataGridColumnPersistentFilter<DayFillsRowData, TColFilter> filter_model,
|
||||
Func<DayFillsFilterSettings, TColFilter> get_col_filter,
|
||||
Action<DayFillsFilterSettings, TColFilter> set_col_filter,
|
||||
string filter_template) =>
|
||||
new(key, comparer_model, filter_model, get_col_filter, set_col_filter, filter_template);
|
||||
}
|
||||
|
||||
class DayFillsColumn<TColFilter> : DIYGridColumnModel<DayFillsColumnType, DayFillsRowData, DayFillsFilterSettings>, IDayFillsColumn, DIYGrid.IFilterableColumn {
|
||||
public DayFillsColumn(
|
||||
DayFillsColumnType key,
|
||||
IComparer<DayFillsRowData> comparer_model,
|
||||
IDataGridColumnPersistentFilter<DayFillsRowData, TColFilter> filter_model,
|
||||
Func<DayFillsFilterSettings, TColFilter> get_col_filter,
|
||||
Action<DayFillsFilterSettings, TColFilter> set_col_filter,
|
||||
string filter_template) : base(
|
||||
key,
|
||||
comparer_model,
|
||||
filter_model,
|
||||
filter_template,
|
||||
f => get_col_filter(f),
|
||||
(f, cf_obj) => {
|
||||
if (cf_obj is TColFilter cf) {
|
||||
set_col_filter(f, cf);
|
||||
}
|
||||
return f;
|
||||
}) { }
|
||||
|
||||
IDataGridColumnFilter<DayFillsRowData> IFilterableDIYGridColumn<DayFillsRowData, DayFillsColumnType>.filter_model => filter_model;
|
||||
IDataGridColumnFilter IFilterableDIYGridColumn.filter_model => filter_model;
|
||||
IDataGridColumnFilter DIYGrid.IFilterableColumn.filter_model => filter_model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Spark.Trading {
|
||||
enum DayFillsColumnType {
|
||||
FillTime,
|
||||
User,
|
||||
Account,
|
||||
Exchange,
|
||||
Security,
|
||||
Symbol,
|
||||
Side,
|
||||
Quantity,
|
||||
Price,
|
||||
Bid,
|
||||
Ask,
|
||||
Driver,
|
||||
Theo,
|
||||
PNL,
|
||||
PositionDelta,
|
||||
PositionGamma,
|
||||
PositionVega,
|
||||
PositionTheta,
|
||||
PositionOptionEquivalent,
|
||||
FillKind,
|
||||
FillStatus,
|
||||
SecurityKey,
|
||||
OrderKey,
|
||||
FillKey
|
||||
}
|
||||
|
||||
static class DayFillsColumnTypeExtensions {
|
||||
public static string col_id(this DayFillsColumnType col) =>
|
||||
col.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
class DayFillsDataSource {
|
||||
public static IObservable<TableUpdate<DayFillsRowData, DayFillsRowKey>> create(
|
||||
IBus bus, SecurityStore sec_store) {
|
||||
var users = bus.subscribe(SparkTags.Users);
|
||||
var inverse_users = users
|
||||
.Select(d => d.ToDictionary(kv => kv.Value.name, kv => kv.Value))
|
||||
.Table(u => u.name);
|
||||
var pnl_data_source = bus.subscribe(SparkTags.ReportBlackboardTags.PNL.PNLData);
|
||||
return create(pnl_data_source, inverse_users, sec_store);
|
||||
}
|
||||
|
||||
public static IObservable<TableUpdate<DayFillsRowData, DayFillsRowKey>> create(
|
||||
IObservable<PNLData> pnl_data_source,
|
||||
IObservable<TableUpdate<UserTuple, string>> inverse_users,
|
||||
SecurityStore sec_store) =>
|
||||
// join pnl data w/ security and user
|
||||
pnl_data_source
|
||||
.Select(d => d.day_trades
|
||||
.Select(DayFillsRowData.from_trade)
|
||||
.ToDictionary(DayFillsRowData.key_fn))
|
||||
.Table(DayFillsRowData.key_fn)
|
||||
.join_table(sec_store, rd => rd.security_key)
|
||||
.Select(tup => new DayFillsRowData(tup.val.trade, tup.sec), DayFillsRowData.key_fn)
|
||||
.LeftJoin(
|
||||
inverse_users,
|
||||
DayFillsRowData.key_fn,
|
||||
user => user.name,
|
||||
row_data => row_data.user_name,
|
||||
(row_data, row_key, user, user_name) => new DayFillsRowData(
|
||||
row_data.trade, row_data.security, user.id),
|
||||
(row_data, row_key, user_name) => row_data,
|
||||
DayFillsRowData.key_fn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[ProtoContract]
|
||||
class DayFillsFilterSettings : IProtobuf<DayFillsFilterSettings>{
|
||||
[ProtoMember(1)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.FillTime))]
|
||||
public TimeFilterTuple? fill_time { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.User))]
|
||||
public uint[]? user { get; set; }
|
||||
|
||||
[ProtoMember(3)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Account))]
|
||||
public uint[]? account { get; set; }
|
||||
|
||||
[ProtoMember(4)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Exchange))]
|
||||
public Venue[]? exchange { get; set; }
|
||||
|
||||
[ProtoMember(5)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Security))]
|
||||
public string? security { get; set; }
|
||||
|
||||
[ProtoMember(6)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Symbol))]
|
||||
public string[]? symbol { get; set; }
|
||||
|
||||
[ProtoMember(7)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Side))]
|
||||
public Side[]? side { get; set; }
|
||||
|
||||
[ProtoMember(8)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Quantity))]
|
||||
public DoubleMinMaxState? quantity { get; set; }
|
||||
|
||||
[ProtoMember(9)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Price))]
|
||||
public DoubleMinMaxState? price { get; set; }
|
||||
|
||||
[ProtoMember(10)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Bid))]
|
||||
public DoubleMinMaxState? bid { get; set; }
|
||||
|
||||
[ProtoMember(11)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Ask))]
|
||||
public DoubleMinMaxState? ask { get; set; }
|
||||
|
||||
[ProtoMember(12)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Driver))]
|
||||
public DoubleMinMaxState? driver { get; set; }
|
||||
|
||||
[ProtoMember(13)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.Theo))]
|
||||
public DoubleMinMaxState? theo { get; set; }
|
||||
|
||||
[ProtoMember(14)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PNL))]
|
||||
public DoubleMinMaxState? pnl { get; set; }
|
||||
|
||||
[ProtoMember(15)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PositionDelta))]
|
||||
public DoubleMinMaxState? pos_delta { get; set; }
|
||||
|
||||
[ProtoMember(16)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PositionGamma))]
|
||||
public DoubleMinMaxState? pos_gamma { get; set; }
|
||||
|
||||
[ProtoMember(17)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PositionVega))]
|
||||
public DoubleMinMaxState? pos_vega { get; set; }
|
||||
|
||||
[ProtoMember(18)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PositionTheta))]
|
||||
public DoubleMinMaxState? pos_theta { get; set; }
|
||||
|
||||
[ProtoMember(19)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.PositionOptionEquivalent))]
|
||||
public DoubleMinMaxState? pos_oev { get; set; }
|
||||
|
||||
[ProtoMember(20)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.FillKind))]
|
||||
public Fill.Types.FillKind[]? fill_kind { get; set; }
|
||||
|
||||
[ProtoMember(21)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.FillStatus))]
|
||||
public Fill.Types.FillStatus[]? fill_status { get; set; }
|
||||
|
||||
[ProtoMember(22)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.SecurityKey))]
|
||||
public string? security_key { get; set; }
|
||||
|
||||
[ProtoMember(23)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.OrderKey))]
|
||||
public string? order_key { get; set; }
|
||||
|
||||
[ProtoMember(24)]
|
||||
[DIYGridColumnID(nameof(DayFillsColumnType.FillKey))]
|
||||
public string? fill_key { get; set; }
|
||||
|
||||
public Func<DayFillsRowData, bool> build_predicate() {
|
||||
var pb = new ColumnPredicateBuilder<DayFillsRowData>();
|
||||
pb.add_time_filter(fill_time ?? TimeFilterTuple.empty, r => r.fill_time);
|
||||
pb.add_discrete_values(user.empty_if_null(), r => r.user_id);
|
||||
pb.add_discrete_values(account.empty_if_null(), r => r.account_id);
|
||||
pb.add_discrete_values(exchange.empty_if_null(), r => r.exchange);
|
||||
pb.add_regex(security, r => r.security.ToString());
|
||||
pb.add_discrete_values(symbol, r => r.symbol);
|
||||
pb.add_discrete_values(side, r => r.side);
|
||||
pb.add_numeric(quantity, r => r.quantity);
|
||||
pb.add_numeric(price, r => r.price);
|
||||
pb.add_numeric(bid, r => r.bid);
|
||||
pb.add_numeric(ask, r => r.ask);
|
||||
pb.add_numeric(driver, r => r.driver);
|
||||
pb.add_numeric(theo, r => r.theo);
|
||||
pb.add_numeric(pnl, r => r.pnl);
|
||||
pb.add_numeric(pos_delta, r => r.pos_delta);
|
||||
pb.add_numeric(pos_gamma, r => r.pos_gamma);
|
||||
pb.add_numeric(pos_vega, r => r.pos_vega);
|
||||
pb.add_numeric(pos_theta, r => r.pos_theta);
|
||||
pb.add_numeric(pos_oev, r => r.pos_oev);
|
||||
pb.add_discrete_values(fill_kind, r => r.fill_kind);
|
||||
pb.add_discrete_values(fill_status, r => r.fill_status);
|
||||
pb.add_regex(security_key, r => r.security_key);
|
||||
pb.add_regex(order_key, r => r.order_key);
|
||||
pb.add_regex(fill_key, r => r.fill_key);
|
||||
return pb.to_predicate();
|
||||
}
|
||||
|
||||
public DayFillsFilterSettings Clone() =>
|
||||
ProtobufSerializationHelper.clone(this);
|
||||
|
||||
public bool Equals(DayFillsFilterSettings? other) =>
|
||||
other is not null &&
|
||||
EqualityComparer.nullable_equals(fill_time, other.fill_time) &&
|
||||
user.safe_sequence_equals(other.user) &&
|
||||
account.safe_sequence_equals(other.account) &&
|
||||
exchange.safe_sequence_equals(other.exchange) &&
|
||||
security == other.security &&
|
||||
symbol.safe_sequence_equals(other.symbol) &&
|
||||
side.safe_sequence_equals(other.side) &&
|
||||
quantity.safe_equals(other.quantity) &&
|
||||
price.safe_equals(other.price) &&
|
||||
bid.safe_equals(other.bid) &&
|
||||
ask.safe_equals(other.ask) &&
|
||||
driver.safe_equals(other.driver) &&
|
||||
theo.safe_equals(other.theo) &&
|
||||
pnl.safe_equals(other.pnl) &&
|
||||
pos_delta.safe_equals(other.pos_delta) &&
|
||||
pos_gamma.safe_equals(other.pos_gamma) &&
|
||||
pos_vega.safe_equals(other.pos_vega) &&
|
||||
pos_theta.safe_equals(other.pos_theta) &&
|
||||
pos_oev.safe_equals(other.pos_oev) &&
|
||||
fill_kind.safe_sequence_equals(other.fill_kind) &&
|
||||
fill_status.safe_sequence_equals(other.fill_status) &&
|
||||
security_key == other.security_key &&
|
||||
order_key == other.order_key &&
|
||||
fill_key == other.fill_key;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as DayFillsFilterSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
GetType().GetHashCode();
|
||||
|
||||
object ICloneable.Clone() =>
|
||||
Clone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Spark.Trading {
|
||||
using System;
|
||||
|
||||
[Flags]
|
||||
enum DayFillsMatchType {
|
||||
None = 0,
|
||||
Quantity = 1,
|
||||
Price = 1 << 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api.core;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using RowData = DayFillsRowData;
|
||||
using RowKey = DayFillsRowKey;
|
||||
|
||||
class DayFillsModel {
|
||||
public DayFillsModel(
|
||||
IObservable<TableUpdate<RowData, RowKey>> day_fills,
|
||||
IObservable<IReadOnlyDictionary<uint, AccountTuple>> accounts,
|
||||
IObservable<IReadOnlyDictionary<uint, UserTuple>> users) {
|
||||
this.day_fills = day_fills;
|
||||
this.accounts = accounts;
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public IObservable<TableUpdate<RowData, RowKey>> day_fills { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint, AccountTuple>> accounts { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint, UserTuple>> users { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.analytics;
|
||||
|
||||
using System;
|
||||
|
||||
readonly struct DayFillsRowData : IEquatable<DayFillsRowData> {
|
||||
public DayFillsRowData(
|
||||
IPNLTradeRow trade, SecurityImmutable? security = null, uint user_id = 0) {
|
||||
this.trade = trade;
|
||||
this.security = security;
|
||||
this.user_id = user_id;
|
||||
}
|
||||
|
||||
public static Func<DayFillsRowData, DayFillsRowKey> key_fn => rd => rd.row_key;
|
||||
|
||||
public DayFillsRowKey row_key => new(fill_key);
|
||||
public IPNLTradeRow trade { get; }
|
||||
|
||||
// user
|
||||
public UserTuple user => new(user_id, user_name);
|
||||
public uint user_id { get; }
|
||||
public string user_name => trade.tl_row.user;
|
||||
|
||||
// account
|
||||
public AccountTuple account => new(account_id, account_name);
|
||||
public uint account_id => trade.tl_row.account_id;
|
||||
public string account_name => trade.tl_row.account;
|
||||
|
||||
// security
|
||||
public SecurityImmutable? security { get; }
|
||||
public uint security_key => trade.tl_row.security_key;
|
||||
public Venue exchange =>
|
||||
trade.tl_row.security_expiration?.exchange ?? Venue.Unset;
|
||||
public string? symbol => security?.Symbol;
|
||||
|
||||
// order
|
||||
public int order_key => trade.tl_row.order_key;
|
||||
public Side side => trade.tl_row.size switch {
|
||||
> 0 => Side.Buy,
|
||||
< 0 => Side.Sell,
|
||||
_ => Side.Undefined
|
||||
};
|
||||
|
||||
// fill
|
||||
public string fill_key => trade.tl_row.key;
|
||||
public DateTime fill_time => trade.tl_row.time_entered;
|
||||
public Fill.Types.FillKind fill_kind => trade.tl_row.fill_kind;
|
||||
public Fill.Types.FillStatus fill_status => trade.tl_row.fill_status;
|
||||
public double quantity => trade.tl_row.size;
|
||||
public double price => trade.tl_row.price;
|
||||
|
||||
// market
|
||||
public double bid => trade.top_of_book.bid;
|
||||
public double ask => trade.top_of_book.ask;
|
||||
public double driver => trade.driver;
|
||||
|
||||
// theos/greeks
|
||||
public double theo => trade.theo;
|
||||
public double pnl => trade.pnl;
|
||||
public double pos_delta => trade.pos_delta;
|
||||
public double pos_gamma => trade.pos_gamma;
|
||||
public double pos_vega => trade.pos_vega;
|
||||
public double pos_theta => trade.pos_theta;
|
||||
public double pos_oev => trade.pos_oev;
|
||||
|
||||
public static DayFillsRowData from_trade(IPNLTradeRow trade) =>
|
||||
new(trade);
|
||||
|
||||
public DayFillsRowData with(Optional<SecurityImmutable?> security, uint? user_id = null) =>
|
||||
new(trade, security.value_or(this.security), user_id ?? this.user_id);
|
||||
|
||||
public bool Equals(DayFillsRowData other) =>
|
||||
Equals(trade, other.trade) &&
|
||||
EqualityComparer.nullable_equals(security, other.security) &&
|
||||
user == other.user;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
obj is DayFillsRowData other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(trade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using System;
|
||||
|
||||
readonly struct DayFillsRowKey : IEquatable<DayFillsRowKey>, IComparable<DayFillsRowKey> {
|
||||
readonly string _value;
|
||||
|
||||
public DayFillsRowKey(string value) =>
|
||||
_value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
|
||||
public string value => _value ?? string.Empty;
|
||||
|
||||
public int CompareTo(DayFillsRowKey other) =>
|
||||
value.CompareTo(other.value);
|
||||
|
||||
public bool Equals(DayFillsRowKey other) =>
|
||||
value == other.value;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
obj is DayFillsRowKey other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
value?.GetHashCode() ?? 0;
|
||||
|
||||
public override string ToString() =>
|
||||
value.ToString();
|
||||
|
||||
public static bool operator ==(DayFillsRowKey l, DayFillsRowKey r) =>
|
||||
l.Equals(r);
|
||||
|
||||
public static bool operator !=(DayFillsRowKey l, DayFillsRowKey r) =>
|
||||
!(l == r);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using TickDisplaySettingsImmutable = bts.api.domain.TickDisplaySettingsImmutable;
|
||||
|
||||
class DayFillsRowVM : DisposableViewModelBase, DIYGrid.IRowVM, IEquatable<DayFillsRowVM> {
|
||||
// guarentees deterministic sorting if the rows in the collection have unique row_keys
|
||||
public static readonly IComparer<DayFillsRowVM> key_comparer =
|
||||
Comparer<DayFillsRowKey>.Default.wrap<DayFillsRowKey, DayFillsRowVM>(r => r.row_key)
|
||||
.to_safe();
|
||||
|
||||
DayFillsRowData _data;
|
||||
|
||||
// display
|
||||
TickDisplaySettingsImmutable _quantity_display = Security.Defaults.quantity_display_settingsi;
|
||||
TickDisplaySettingsImmutable _price_display = Security.Defaults.price_display_settingsi;
|
||||
TickDisplaySettingsImmutable _driver_display = Security.Defaults.price_display_settingsi;
|
||||
TickDisplaySettingsImmutable _theo_display = Security.Defaults.price_display_settingsi
|
||||
.with(tick_factors: new() {
|
||||
TickBase = 1000,
|
||||
TickUnit = 1
|
||||
});
|
||||
|
||||
public DayFillsRowVM(DayFillsRowData data) =>
|
||||
_data = data;
|
||||
|
||||
public event Action? invalidated;
|
||||
|
||||
public DayFillsRowData data {
|
||||
get => _data;
|
||||
set {
|
||||
using var _ = detect_property_changes();
|
||||
_data = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DayFillsRowKey row_key => _data.row_key;
|
||||
|
||||
public UserTuple user => _data.user;
|
||||
public AccountTuple account => _data.account;
|
||||
|
||||
// security
|
||||
public SecurityImmutable? security => _data.security;
|
||||
public uint security_key => _data.security_key;
|
||||
public Venue exchange => _data.exchange;
|
||||
public string? symbol => _data.symbol;
|
||||
|
||||
// order
|
||||
public int order_key => _data.order_key;
|
||||
public Side side => _data.side;
|
||||
|
||||
public string fill_key => _data.fill_key;
|
||||
public DateTime fill_time => _data.fill_time;
|
||||
public bts.api.orderman.Fill.Types.FillKind fill_kind => _data.fill_kind;
|
||||
public bts.api.orderman.Fill.Types.FillStatus fill_status => _data.fill_status;
|
||||
public double quantity => _data.quantity;
|
||||
public double price => _data.price;
|
||||
|
||||
// market
|
||||
public double bid => _data.bid;
|
||||
public double ask => _data.ask;
|
||||
public double driver => _data.driver;
|
||||
|
||||
// theos/greeks
|
||||
public double theo => _data.theo;
|
||||
public double pnl => _data.pnl;
|
||||
public double pos_delta => _data.pos_delta;
|
||||
public double pos_gamma => _data.pos_gamma;
|
||||
public double pos_vega => _data.pos_vega;
|
||||
public double pos_theta => _data.pos_theta;
|
||||
public double pos_oev => _data.pos_oev;
|
||||
|
||||
// display
|
||||
public TickDisplaySettingsImmutable quantity_display {
|
||||
get => _quantity_display;
|
||||
set => Set(ref _quantity_display, value);
|
||||
}
|
||||
public TickDisplaySettingsImmutable price_display {
|
||||
get => _price_display;
|
||||
set => Set(ref _price_display, value);
|
||||
}
|
||||
public TickDisplaySettingsImmutable driver_display {
|
||||
get => _driver_display;
|
||||
set => Set(ref _driver_display, value);
|
||||
}
|
||||
public TickDisplaySettingsImmutable theo_display {
|
||||
get => _theo_display;
|
||||
set => Set(ref _theo_display, value);
|
||||
}
|
||||
|
||||
public void raise_invalidated() =>
|
||||
invalidated?.Invoke();
|
||||
|
||||
public bool Equals(DayFillsRowVM? other) =>
|
||||
order_key == other?.order_key;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as DayFillsRowVM);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
order_key.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
using Spark.Core.Reflection;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ColKey = DayFillsColumnType;
|
||||
using ColHeader = mbts.ui.controls.DIYGrid.DefaultColumnHeaders;
|
||||
using ColWidth = mbts.ui.controls.DIYGrid.DefaultColumnWidths;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using bts.collections;
|
||||
|
||||
[ProtoContract]
|
||||
class DayFillsSettings : IProtobuf<DayFillsSettings> {
|
||||
public const int VERSION = 1;
|
||||
|
||||
[ProtoMember(1)]
|
||||
List<SortingCriteria>? _sorting_criteria;
|
||||
|
||||
public IList<SortingCriteria> sorting_criteria =>
|
||||
_sorting_criteria ??= new(1);
|
||||
|
||||
[ProtoMember(2)]
|
||||
public GridSettings? grid { get; set; }
|
||||
|
||||
[ProtoMember(3)]
|
||||
public DayFillsFilterSettings? filter { get; set; }
|
||||
|
||||
[ProtoMember(4)]
|
||||
public SparkMenuDisplaySettings menu_display { get; set; } = SparkMenuDisplaySettings.Default;
|
||||
|
||||
public static DayFillsSettings Default() {
|
||||
var rv = new DayFillsSettings() {
|
||||
filter = new()
|
||||
};
|
||||
rv.sorting_criteria.AddRange(DefaultColumns.default_sorting_criteria);
|
||||
rv.grid = default_grid();
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static GridSettings default_grid() =>
|
||||
GridSettings.Default.with(columns: DefaultColumns.all);
|
||||
|
||||
public bool Equals(DayFillsSettings? other) =>
|
||||
other is not null &&
|
||||
grid.safe_equals(other.grid) &&
|
||||
sorting_criteria.safe_sequence_equals(other.sorting_criteria) &&
|
||||
filter.safe_equals(other.filter) &&
|
||||
menu_display.Equals(other.menu_display);
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as DayFillsSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
GetType().GetHashCode();
|
||||
|
||||
public DayFillsSettings Clone() =>
|
||||
ProtobufSerializationHelper.clone(this);
|
||||
|
||||
object ICloneable.Clone() =>
|
||||
Clone();
|
||||
|
||||
static class DefaultColumns {
|
||||
public static GridColumnSettings fill_time => _mk(
|
||||
ColKey.FillTime, ColHeader.FillTime, ColWidth.Time);
|
||||
|
||||
public static GridColumnSettings user => _mk(
|
||||
ColKey.User, ColHeader.User, ColWidth.User, false);
|
||||
|
||||
public static GridColumnSettings account => _mk(
|
||||
ColKey.Account, ColHeader.Account, ColWidth.Account);
|
||||
|
||||
public static GridColumnSettings exchange => _mk(
|
||||
ColKey.Exchange, ColHeader.Exchange, ColWidth.Exchange);
|
||||
|
||||
public static GridColumnSettings security => _mk(
|
||||
ColKey.Security, ColHeader.Security, ColWidth.Security);
|
||||
|
||||
public static GridColumnSettings symbol => _mk(
|
||||
ColKey.Symbol, ColHeader.Symbol, ColWidth.Symbol);
|
||||
|
||||
public static GridColumnSettings side => _mk(
|
||||
ColKey.Side, ColHeader.Side, ColWidth.Side);
|
||||
|
||||
public static GridColumnSettings quantity => _mkn(
|
||||
ColKey.Quantity, ColHeader.Qty, ColWidth.Qty);
|
||||
|
||||
public static GridColumnSettings price => _mkn(
|
||||
ColKey.Price, ColHeader.Price, ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings bid => _mkn(ColKey.Bid, ColHeader.Bid, ColWidth.Price);
|
||||
public static GridColumnSettings ask => _mkn(ColKey.Ask, ColHeader.Ask, ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings driver => _mkn(
|
||||
ColKey.Driver, ColHeader.Driver, ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings theo => _mkn(
|
||||
ColKey.Theo, ColHeader.Theo, ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pnl => _mkn(
|
||||
ColKey.PNL, ColHeader.PNLHeaders.PNL, ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pos_delta => _mkn(
|
||||
ColKey.PositionDelta, "P Delta", ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pos_gamma => _mkn(
|
||||
ColKey.PositionGamma, "P Gamma", ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pos_vega => _mkn(
|
||||
ColKey.PositionVega, "P Vega", ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pos_theta => _mkn(
|
||||
ColKey.PositionTheta, "P Theta", ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings pos_oev => _mkn(
|
||||
ColKey.PositionOptionEquivalent, "P OEV", ColWidth.Price);
|
||||
|
||||
public static GridColumnSettings fill_kind => _mk(
|
||||
ColKey.FillKind, ColHeader.FillKind, ColWidth.FillKind, false);
|
||||
|
||||
public static GridColumnSettings fill_status => _mk(
|
||||
ColKey.FillStatus, ColHeader.FillStatus, ColWidth.FillStatus);
|
||||
|
||||
public static GridColumnSettings fill_key => _mk(
|
||||
ColKey.FillKey, ColHeader.FillKey, ColWidth.FillKey, false);
|
||||
|
||||
public static GridColumnSettings order_key => _mk(
|
||||
ColKey.OrderKey, ColHeader.OrderKey, ColWidth.OrderKey, false);
|
||||
|
||||
public static GridColumnSettings security_key => _mk(
|
||||
ColKey.SecurityKey, ColHeader.SecurityKey, ColWidth.SecurityKey, false);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new(fill_time.id, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all =>
|
||||
ReflectionHelper.static_property_delegates_of_type<GridColumnSettings>(
|
||||
typeof(DefaultColumns)).Select(g => g());
|
||||
|
||||
/// <summary>
|
||||
/// Makes a [non-numeric] column
|
||||
/// </summary>
|
||||
static GridColumnSettings _mk(
|
||||
ColKey key,
|
||||
string? display_name = null,
|
||||
double width = 80,
|
||||
bool is_visible = true,
|
||||
Color? fg = null,
|
||||
Color? bg = null,
|
||||
HorizontalAlignment h_align = HorizontalAlignment.Left) =>
|
||||
new(
|
||||
key.ToString(),
|
||||
display_name,
|
||||
is_visible,
|
||||
font_color_override: fg,
|
||||
width: width,
|
||||
horizontal_alignment: h_align,
|
||||
background_color_override: bg);
|
||||
|
||||
/// <summary>
|
||||
/// Makes a numeric column
|
||||
/// </summary>
|
||||
static GridColumnSettings _mkn(
|
||||
ColKey key,
|
||||
string? display_name = null,
|
||||
double width = 80,
|
||||
bool is_visible = true,
|
||||
Color? fg = null,
|
||||
Color? bg = null,
|
||||
HorizontalAlignment h_align = HorizontalAlignment.Right) =>
|
||||
new(
|
||||
key.ToString(),
|
||||
display_name,
|
||||
is_visible,
|
||||
font_color_override: fg,
|
||||
width: width,
|
||||
horizontal_alignment: h_align,
|
||||
background_color_override: bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.collections;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
|
||||
using ColKey = DayFillsColumnType;
|
||||
using FilterType = mbts.spark.filters.DataGridFilterKnownTemplates;
|
||||
using RowData = DayFillsRowData;
|
||||
using RowKey = DayFillsRowKey;
|
||||
using RowVM = DayFillsRowVM;
|
||||
|
||||
class DayFillsVM : DisposableViewModelBase, IHandleGridSorting {
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
readonly DIYGridRowsModel<RowData, ColKey, DayFillsFilterSettings> _rows_model;
|
||||
readonly ObservableKeyedCollection<IDayFillsColumn, ColKey> _columns = new(c => c.id);
|
||||
|
||||
public DayFillsVM(
|
||||
DayFillsModel model,
|
||||
IWindowSettingsManager<GridSettings> settings_manager,
|
||||
ISecurityMetadataStore security_metadata) {
|
||||
_settings_manager = settings_manager;
|
||||
columns = _columns.WrapSelector(c => c.column_view);
|
||||
column_models = _columns.AsReadOnlyKeyedCollection().WrapSelector(
|
||||
c => (IDIYGridColumnModel)c);
|
||||
|
||||
// filters
|
||||
var fill_time_filter = new TimeFilterVM<RowData>(r => r.fill_time);
|
||||
var user_filter = DiscreteValuesFilterVM.Common.user<RowData>(
|
||||
model.users.Select(us => us.Values), r => r.user);
|
||||
var account_filter = DiscreteValuesFilterVM.Common.account<RowData>(
|
||||
model.accounts.Select(us => us.Values), r => r.account);
|
||||
var exchange_filter = DiscreteValuesFilterVM.Common.exchange<RowData>(
|
||||
r => r.exchange);
|
||||
var security_filter = new RegexFilterVM<RowData>(r => r.security.ToString());
|
||||
var symbol_filter = DiscreteValuesFilterVM.Common.symbol<RowData>(
|
||||
r => r.symbol ?? string.Empty);
|
||||
var side_filter = DiscreteValuesFilterVM.Common.side<RowData>(r => r.side);
|
||||
var quantity_filter = new DoubleMinMax<RowData>(r => r.quantity);
|
||||
var price_filter = new DoubleMinMax<RowData>(r => r.price);
|
||||
var bid_filter = new DoubleMinMax<RowData>(r => r.bid);
|
||||
var ask_filter = new DoubleMinMax<RowData>(r => r.ask);
|
||||
var driver_filter = new DoubleMinMax<RowData>(r => r.driver);
|
||||
var theo_filter = new DoubleMinMax<RowData>(r => r.theo);
|
||||
var pnl_filter = new DoubleMinMax<RowData>(r => r.pnl);
|
||||
var pos_delta_filter = new DoubleMinMax<RowData>(r => r.pos_delta);
|
||||
var pos_gamma_filter = new DoubleMinMax<RowData>(r => r.pos_gamma);
|
||||
var pos_vega_filter = new DoubleMinMax<RowData>(r => r.pos_vega);
|
||||
var pos_theta_filter = new DoubleMinMax<RowData>(r => r.pos_theta);
|
||||
var pos_oev_filter = new DoubleMinMax<RowData>(r => r.pos_oev);
|
||||
var fill_status_filter = DiscreteValuesFilterVM.Create<RowData, Fill.Types.FillStatus>(
|
||||
EnumHelper.get_values<Fill.Types.FillStatus>(), r => r.fill_status);
|
||||
var fill_kind_filter = DiscreteValuesFilterVM.Create<RowData, Fill.Types.FillKind>(
|
||||
EnumHelper.get_values<Fill.Types.FillKind>(), r => r.fill_kind);
|
||||
var security_key_filter = new RegexFilterVM<RowData>(r => r.security_key.ToString());
|
||||
var order_key_filter = new RegexFilterVM<RowData>(r => r.order_key.ToString());
|
||||
var fill_key_filter = new RegexFilterVM<RowData>(r => r.fill_key.ToString());
|
||||
|
||||
// columns
|
||||
add_col(ColKey.FillTime, fill_time_filter, FilterType.TimeFilter);
|
||||
add_col(ColKey.User, user_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.Account, account_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.Exchange, exchange_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.Security, security_filter, FilterType.Regex);
|
||||
add_col(ColKey.Symbol, symbol_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.Side, side_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.Quantity, quantity_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.Price, price_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.Bid, bid_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.Ask, ask_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.Driver, driver_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.Theo, theo_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PNL, pnl_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PositionDelta, pos_delta_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PositionGamma, pos_gamma_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PositionVega, pos_vega_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PositionTheta, pos_theta_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.PositionOptionEquivalent, pos_oev_filter, FilterType.DoubleMinMax);
|
||||
add_col(ColKey.FillKind, fill_kind_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.FillStatus, fill_status_filter, FilterType.DiscreteValues);
|
||||
add_col(ColKey.SecurityKey, security_key_filter, FilterType.Regex);
|
||||
add_col(ColKey.OrderKey, order_key_filter, FilterType.Regex);
|
||||
add_col(ColKey.FillKey, fill_key_filter, FilterType.Regex);
|
||||
|
||||
// rows
|
||||
_rows_model = DIYGridRowsModel.create(
|
||||
DayFillsWindow.WINDOW_TYPE_NAME,
|
||||
ColKey.FillKey,
|
||||
_columns.WrapSelector(c => c.as_filterable()),
|
||||
_columns.WrapSelector(c => c.as_sortable()),
|
||||
_get_column_comparer,
|
||||
fs => fs.build_predicate());
|
||||
|
||||
// grid settings
|
||||
grid_settings_manager = new SimpleGridSettingsManager<RowVM>(
|
||||
columns, null, rows, _load_col_settings);
|
||||
|
||||
var row_observers = RXCollection.observers<RowVM, RowData, RowKey>(
|
||||
rows, create_row_vm, r => r.data, update_row_vm, false);
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
_settings_manager.subscribe_current().OnDispatcher().Subscribe(
|
||||
grid_settings_manager.load_from),
|
||||
_rows_model.observe_comparer().OnDispatcher().Subscribe(row_observers.comp),
|
||||
model.day_fills.Filter(_rows_model.observe_filter()).OnDispatcher().Subscribe(
|
||||
row_observers.table));
|
||||
|
||||
void add_col<TFilter>(
|
||||
ColKey col_key,
|
||||
IDataGridColumnPersistentFilter<RowData, TFilter> filter,
|
||||
string filter_template) {
|
||||
var comp = _get_column_comparer(col_key);
|
||||
var col = DayFillsColumn.create(col_key, comp, filter, filter_template);
|
||||
_columns.Add(col);
|
||||
}
|
||||
|
||||
RowVM create_row_vm(RowData rd) {
|
||||
var rvm = new RowVM(rd);
|
||||
if (!rd.security.HasValue) {
|
||||
return rvm;
|
||||
}
|
||||
var meta = security_metadata.get(rd.security.Value);
|
||||
if (!meta.HasValue) {
|
||||
return rvm;
|
||||
}
|
||||
if (meta.Value.HasPriceDisplay) {
|
||||
rvm.price_display = meta.Value.PriceDisplay;
|
||||
}
|
||||
if (meta.Value.HasQuantityDisplay) {
|
||||
rvm.quantity_display = meta.Value.QuantityDisplay;
|
||||
}
|
||||
return rvm;
|
||||
}
|
||||
|
||||
RowVM update_row_vm(RowVM rvm, RowData rd) {
|
||||
rvm.data = rd;
|
||||
return rvm;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyObservableCollection<IDIYGridColumnModel> column_models { get; }
|
||||
public IReadOnlyObservableCollection<ColumnBase> columns { get; }
|
||||
public ObservableCollection<RowVM> rows { get; } = new();
|
||||
public SimpleGridSettingsManager<RowVM> grid_settings_manager { get; }
|
||||
|
||||
public DayFillsSettings get_settings() {
|
||||
var rv = new DayFillsSettings {
|
||||
grid = grid_settings_manager.create(),
|
||||
filter = get_filter_settings()
|
||||
};
|
||||
rv.sorting_criteria.AddRange(_rows_model.get_sorting_criteria());
|
||||
return rv;
|
||||
}
|
||||
|
||||
public DayFillsFilterSettings get_filter_settings() {
|
||||
var fs = new DayFillsFilterSettings();
|
||||
_rows_model.assign_to_filter(fs);
|
||||
return fs;
|
||||
}
|
||||
|
||||
public void load_settings(DayFillsSettings settings) {
|
||||
_rows_model.on_settings(settings.filter ?? new(), settings.sorting_criteria);
|
||||
if (settings.grid is not null) {
|
||||
load_grid_settings(settings.grid);
|
||||
}
|
||||
}
|
||||
|
||||
public void load_grid_settings(GridSettings grid_settings) =>
|
||||
grid_settings_manager.load_from(grid_settings);
|
||||
|
||||
public void on_sorting(object sender, DIYGridSortingEventArgs e) =>
|
||||
_rows_model.on_sorting(e);
|
||||
|
||||
static IComparer<RowData> _get_column_comparer(ColKey column) {
|
||||
return column switch {
|
||||
ColKey.FillTime => wrap(r => r.fill_time),
|
||||
ColKey.User => wrap(r => r.user),
|
||||
ColKey.Account => wrap(r => r.account),
|
||||
ColKey.Exchange => wrap(r => r.exchange),
|
||||
ColKey.Security => wrap(r => r.security),
|
||||
ColKey.Symbol => wrap(r => r.symbol),
|
||||
ColKey.Side => wrap(r => r.side),
|
||||
ColKey.Quantity => wrap(r => r.quantity),
|
||||
ColKey.Price => wrap(r => r.price),
|
||||
ColKey.Bid => wrap(r => r.bid),
|
||||
ColKey.Ask => wrap(r => r.ask),
|
||||
ColKey.Driver => wrap(r => r.driver),
|
||||
ColKey.Theo => wrap(r => r.theo),
|
||||
ColKey.PNL => wrap(r => r.pnl),
|
||||
ColKey.PositionDelta => wrap(r => r.pos_delta),
|
||||
ColKey.PositionGamma => wrap(r => r.pos_gamma),
|
||||
ColKey.PositionVega => wrap(r => r.pos_vega),
|
||||
ColKey.PositionTheta => wrap(r => r.pos_theta),
|
||||
ColKey.PositionOptionEquivalent => wrap(r => r.pos_oev),
|
||||
ColKey.FillKind => wrap(r => r.fill_kind),
|
||||
ColKey.FillStatus => wrap(r => r.fill_status),
|
||||
ColKey.SecurityKey => wrap(r => r.security_key),
|
||||
ColKey.OrderKey => wrap(r => r.order_key),
|
||||
ColKey.FillKey => wrap(r => r.fill_key),
|
||||
_ => throw ExceptionBuilder.Argument.unexpected_case(column, nameof(column)),
|
||||
};
|
||||
|
||||
static IComparer<RowData> wrap<T>(Func<RowData, T> selector) =>
|
||||
Comparer<T>.Default.wrap(selector);
|
||||
}
|
||||
|
||||
void _load_col_settings(GridSettings grid_settings) {
|
||||
var col_settings_id_map = grid_settings.columns.ToDictionary(
|
||||
cs => EnumHelper.parse<ColKey>(cs.id));
|
||||
if (col_settings_id_map.Count == _columns.Count) {
|
||||
CollectionHelper.sync_with_never_duplicate(
|
||||
_columns,
|
||||
grid_settings.columns,
|
||||
cs => throw new InvalidOperationException(),
|
||||
c => c.id,
|
||||
cs => EnumHelper.parse<ColKey>(cs.id));
|
||||
}
|
||||
// don't assume that columns:column_settings have a perfect 1:1 relationship (they
|
||||
// should, but it is possible we accidentally break the settings as grids/uis change)
|
||||
foreach (var col in _columns) {
|
||||
if (col_settings_id_map.TryGetValue(col.id, out var cs)) {
|
||||
col.column_view.load_from(cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<UserControl
|
||||
x:Class="Spark.Trading.DayFillsView"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:api="clr-namespace:bts.api;assembly=spark_api"
|
||||
xmlns:bv="clr-namespace:bts.view"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:trading="clr-namespace:Spark.Trading"
|
||||
u:WindowStyle.UnsafeWindow="{Binding Path='(u:WindowStyle.UnsafeWindow)', RelativeSource={RelativeSource AncestorType=bv:SparkWindowView}}"
|
||||
FocusManager.IsFocusScope="True"
|
||||
Background="{StaticResource CommonBackground}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<cv:ValueMap x:Key="SideToBrushConverter" Default="{x:Static Brushes.Transparent}">
|
||||
<cv:KeyValue Key="{u:Enum Buy, Type=api:Side}">
|
||||
<SolidColorBrush Color="{x:Static bid_color, MemberType={u:Nested u:BTSColors.MarketData}}" Opacity="0.33" />
|
||||
</cv:KeyValue>
|
||||
<cv:KeyValue Key="{u:Enum Sell, Type=api:Side}">
|
||||
<SolidColorBrush Color="{x:Static ask_color, MemberType={u:Nested u:BTSColors.MarketData}}" Opacity="0.33" />
|
||||
</cv:KeyValue>
|
||||
</cv:ValueMap>
|
||||
|
||||
<!--
|
||||
For some reason, the default style for TextCell (i.e., without an x:Key), is completely
|
||||
ignored. This is particularly annoying because it means the Style attribute must be
|
||||
specified for every TextCell in the RowTemplate
|
||||
-->
|
||||
<Style x:Key="TextCell" TargetType="c:TextCell">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="{Binding Path='(c:DIYGrid.Column).horizontal_alignment', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="Padding" Value="{x:Static c:DIYGrid.DefaultCellPadding}" />
|
||||
<Setter Property="Background" Value="{Binding Path='(c:DIYGrid.Column).background_brush', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="FontFamily" Value="{Binding Path='(c:DIYGrid.Column).font_family', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="FontSize" Value="{Binding Path='(c:DIYGrid.Column).font_size', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="FontWeight" Value="{Binding Path='(c:DIYGrid.Column).font_weight', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="Foreground" Value="{Binding Path='(c:DIYGrid.Column).font_brush', RelativeSource={RelativeSource Self}}" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<AdornerDecorator>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:DIYGrid
|
||||
x:Name="_grid"
|
||||
Grid.Row="0"
|
||||
Columns="{Binding columns, Mode=OneWay}"
|
||||
CurrentRow="{Binding current_row}"
|
||||
Rows="{Binding rows}"
|
||||
SelectionHighlight="{Binding grid_settings_manager.selection_highlight, Mode=OneWay}"
|
||||
SyncColumnSortDirectionWithSortDescriptions="False">
|
||||
<c:DIYGrid.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
<KeyBinding Key="Return" Command="{x:Static c:DIYGrid.DefaultRowCommand}" />
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.CommandBindings>
|
||||
<CommandBinding
|
||||
Command="{x:Static c:DIYGrid.DefaultRowCommand}"
|
||||
Executed="{x:Static c:DIYGrid.DefaultRowActionExecuted}"
|
||||
CanExecute="{x:Static c:DIYGrid.DefaultRowActionCanExecute}"
|
||||
/>
|
||||
</c:DIYGrid.CommandBindings>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<Grid
|
||||
x:Name="RowView"
|
||||
c:DIYGrid.SyncWithColumnGeometry="True"
|
||||
Height="{Binding RowHeight, RelativeSource={RelativeSource AncestorType=c:DIYGrid}}"
|
||||
Background="{Binding side, Converter={StaticResource SideToBrushConverter}}">
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.FillTime}"
|
||||
Text="{Binding fill_time}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.User}"
|
||||
Text="{Binding user}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Account}"
|
||||
Text="{Binding account}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Exchange}"
|
||||
Text="{Binding exchange}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Security}"
|
||||
Text="{Binding security}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Symbol}"
|
||||
Text="{Binding symbol}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Side}"
|
||||
Text="{Binding side}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Quantity}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="quantity" />
|
||||
<Binding Path="quantity_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Price}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="price" />
|
||||
<Binding Path="price_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Bid}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="bid" />
|
||||
<Binding Path="price_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Ask}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="ask" />
|
||||
<Binding Path="price_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Driver}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="driver" />
|
||||
<Binding Path="driver_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.Theo}"
|
||||
Style="{StaticResource TextCell}">
|
||||
<MultiBinding Converter="{x:Static cv:TickDisplayConverter.Instance}">
|
||||
<Binding Path="theo" />
|
||||
<Binding Path="theo_display" />
|
||||
</MultiBinding>
|
||||
</c:TextCell>
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PNL}"
|
||||
Text="{Binding pnl, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PositionDelta}"
|
||||
Text="{Binding pos_delta, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PositionGamma}"
|
||||
Text="{Binding pos_gamma, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PositionVega}"
|
||||
Text="{Binding pos_vega, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PositionTheta}"
|
||||
Text="{Binding pos_theta, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.PositionOptionEquivalent}"
|
||||
Text="{Binding pos_oev, StringFormat='#,0.000'}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.FillKind}"
|
||||
Text="{Binding fill_kind}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.FillStatus}"
|
||||
Text="{Binding fill_status}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.SecurityKey}"
|
||||
Text="{Binding security_key}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.OrderKey}"
|
||||
Text="{Binding order_key}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="{x:Static trading:DayFillsColumnType.FillKey}"
|
||||
Text="{Binding fill_key}"
|
||||
Style="{StaticResource TextCell}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</Grid>
|
||||
</AdornerDecorator>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,12 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using System.Windows.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MarketSheetsView.xaml
|
||||
/// </summary>
|
||||
partial class DayFillsView : UserControl {
|
||||
public DayFillsView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
|
||||
using mbts;
|
||||
using mbts.config;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
|
||||
class DayFillsWindow : SparkWindow<DayFillsSettings>, ISharedWindow {
|
||||
public const string WINDOW_TYPE_NAME = "DayFills";
|
||||
|
||||
readonly List<SparkCommand> _commands = new();
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
readonly IPositionModel _position_model;
|
||||
readonly ISecurityMetadataStore _security_metadata;
|
||||
readonly UserTuple _user;
|
||||
|
||||
DayFillsModel? _model;
|
||||
DayFillsView? _view;
|
||||
DayFillsVM? _vm;
|
||||
SparkMenuDisplayVM? _menu_display_vm;
|
||||
DayFillsSettings _settings;
|
||||
|
||||
public DayFillsWindow(
|
||||
IBus bus,
|
||||
ISaveWindow<DayFillsSettings> save,
|
||||
IPositionModel position_model,
|
||||
ISecurityMetadataStore security_metadata,
|
||||
DayFillsSettings settings,
|
||||
IWindowSettingsManager<GridSettings> settings_manager,
|
||||
UserTuple user)
|
||||
: base("Day Fills", bus, save, Icons.DayFills) {
|
||||
thread_id = Configuration.get<bts.config.MultiThreadedWindows>().day_fills ?
|
||||
WINDOW_TYPE_NAME : null;
|
||||
_position_model = position_model;
|
||||
_security_metadata = security_metadata;
|
||||
_settings = settings;
|
||||
_settings_manager = settings_manager;
|
||||
_user = user;
|
||||
_dispose = Disposable.Create(() => {
|
||||
Disposable.dispose(ref _menu_display_vm);
|
||||
Disposable.dispose(ref _vm);
|
||||
});
|
||||
}
|
||||
|
||||
public string? thread_id { get; }
|
||||
public override string window_type => WINDOW_TYPE_NAME;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
|
||||
public override DayFillsSettings SaveState {
|
||||
get {
|
||||
if (_vm is not null) {
|
||||
_settings = _vm.get_settings();
|
||||
_settings.menu_display = _menu_display_vm?.create() ??
|
||||
SparkMenuDisplaySettings.Default;
|
||||
}
|
||||
return _settings;
|
||||
}
|
||||
}
|
||||
|
||||
public override UIElement Content =>
|
||||
_view ?? throw new InvalidOperationException("Internal view is null");
|
||||
|
||||
public override double MinWidth {
|
||||
get {
|
||||
if (_settings.grid is null) {
|
||||
return base.MinWidth;
|
||||
}
|
||||
var grid_width = _settings.grid.columns.Where(c => c.is_visible).Sum(gcs => gcs.width);
|
||||
return grid_width
|
||||
+ SPARK_MENU_COLLAPSED_WIDTH
|
||||
+ LAUNCHER_BUTTON_BORDER_WIDTH
|
||||
+ EXTRA_FOR_NO_HORIZONTAL_SCROLLBAR_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(_model), nameof(_view), nameof(_vm), nameof(_menu_display_vm))]
|
||||
public void thread_init() {
|
||||
Contract.Requires(_model is null);
|
||||
Contract.Requires(_view is null);
|
||||
Contract.Requires(_vm is null);
|
||||
Contract.Requires(_menu_display_vm is null);
|
||||
Contract.Requires(!_commands.Any());
|
||||
|
||||
var accounts_src = _bus.subscribe(SparkTags.AccountsTag);
|
||||
var users_src = _bus.subscribe(SparkTags.Users);
|
||||
_model = new(_position_model.day_fills, accounts_src, users_src);
|
||||
_vm = new(_model, _settings_manager, _security_metadata);
|
||||
_vm.load_settings(_settings);
|
||||
_view = new DayFillsView {
|
||||
DataContext = _vm
|
||||
};
|
||||
_menu_display_vm = new();
|
||||
_menu_display_vm.load_from(_settings.menu_display);
|
||||
|
||||
var settings_cmd = SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var vm = new ShellSettingsDialogVM<GridSettings, SimpleGridSettingsVM>(
|
||||
_settings_manager,
|
||||
us => us.fills_grid,
|
||||
UserSettings.FileExtensions.GRID,
|
||||
s => _vm.grid_settings_manager.create_vm(
|
||||
// we need to get the most up to date GridSettings when launching b/c users may
|
||||
// have changed some settings on the grid directly, like column widths.
|
||||
s.with(_vm.columns.Select(c => c.create())))
|
||||
);
|
||||
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
|
||||
var dialog = new ShellSettingsDialog { DataContext = vm };
|
||||
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
}));
|
||||
_commands.AddRange(settings_cmd, _menu_display_vm.spark_cmd);
|
||||
}
|
||||
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
_menu_display_vm.safe_bind_to_view(parent_view);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#nullable enable
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.position;
|
||||
using bts.shell;
|
||||
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Data;
|
||||
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class DayFillsWindowFactory : ShellWindowFactory<DayFillsSettings> {
|
||||
readonly IBus _bus;
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
readonly IPositionModel _position_model;
|
||||
readonly ISecurityMetadataStore _security_metadata;
|
||||
readonly UserTuple _user;
|
||||
|
||||
public DayFillsWindowFactory(
|
||||
IShellModule module,
|
||||
IBus bus,
|
||||
UserSettingsHub settings_hub,
|
||||
IPositionModel position_model,
|
||||
ISecurityMetadataStore security_metadata,
|
||||
UserTuple user)
|
||||
: base(module, DayFillsWindow.WINDOW_TYPE_NAME) {
|
||||
_bus = bus;
|
||||
_settings_hub = settings_hub;
|
||||
_position_model = position_model;
|
||||
_security_metadata = security_metadata;
|
||||
_user = user;
|
||||
_dispose = bus.subscribe(SparkTags.show_day_fills).OnDispatcher().Subscribe(_show);
|
||||
}
|
||||
|
||||
public override Task<IShellWindow> load(DayFillsSettings state) =>
|
||||
Task.FromResult(_create(state));
|
||||
|
||||
void _show(DayFillsSettings settings) =>
|
||||
_bus.post(SparkTags.ShowWindow, _create(settings));
|
||||
|
||||
IShellWindow _create(DayFillsSettings state) {
|
||||
var settings_man = _settings_hub.create_day_fills_settings_manager(state.grid);
|
||||
return new DayFillsWindow(
|
||||
_bus, this, _position_model, _security_metadata, state, settings_man, _user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Spark.Trading {
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
interface IDayFillsColumn : IFilterableDIYGridColumn<DayFillsRowData, DayFillsColumnType, DayFillsFilterSettings>, ISortableDIYGridColumn<DayFillsColumnType> {
|
||||
DIYGrid.ColumnBase column_view { get; }
|
||||
}
|
||||
|
||||
static class DayFillsColumnExtensions {
|
||||
public static IFilterableDIYGridColumn<DayFillsRowData, DayFillsColumnType, DayFillsFilterSettings> as_filterable(
|
||||
this IDayFillsColumn rr_column) =>
|
||||
rr_column;
|
||||
|
||||
public static ISortableDIYGridColumn<DayFillsColumnType> as_sortable(this IDayFillsColumn rr_column) =>
|
||||
rr_column;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,8 @@
|
||||
new PNLWindowFactory(
|
||||
this, bus, settings_hub, orders_model, position_model, security_metadata),
|
||||
new AlgoStudioWindowFactory(this, bus, orders_model, error_reporter),
|
||||
new DayFillsWindowFactory(
|
||||
this, bus, settings_hub, position_model, security_metadata, user.Value),
|
||||
new ManualFillsWindowFactory(this, bus, orders_model, security_metadata),
|
||||
new ReconcileReportWindowFactory(
|
||||
this, bus, settings_hub, position_model, security_metadata, user.Value),
|
||||
@@ -79,6 +81,7 @@
|
||||
SparkCommands.PickLadder,
|
||||
SparkCommands.PickOrderTicket,
|
||||
SparkCommands.ShowAlgoStudio.complete(() => new AlgoStudioWindowFactory.StartupData()),
|
||||
SparkCommands.show_day_fills().complete(DayFillsSettings.Default),
|
||||
SparkCommands.ShowManualFills().complete(() => ManualFillsSettings.Default),
|
||||
SparkCommands.show_reconcile_report().complete(ReconcileReportSettings.Default)
|
||||
};
|
||||
|
||||
@@ -151,6 +151,9 @@ namespace bts.spark {
|
||||
public static PartialCommand<ReconcileReportSettings> show_reconcile_report() =>
|
||||
SparkCommand.create("Reconcile Report", Icons.Reports, SparkTags.show_reconcile_report);
|
||||
|
||||
public static PartialCommand<DayFillsSettings> show_day_fills() =>
|
||||
SparkCommand.create("Day Fills", Icons.DayFills, SparkTags.show_day_fills);
|
||||
|
||||
// Orders
|
||||
public static PartialCommand<IEnumerable<uint>> CancelSelectedOrders =>
|
||||
SparkCommand.create("Cancel Selected", Icons.CancelSelected, SparkTags.CancelOrders);
|
||||
|
||||
@@ -131,6 +131,8 @@ namespace mbts.spark {
|
||||
|
||||
public static ITag<ReconcileReportSettings> show_reconcile_report { get; } =
|
||||
_mk_tag<ReconcileReportSettings>();
|
||||
|
||||
public static ITag<DayFillsSettings> show_day_fills { get; } = _mk_tag<DayFillsSettings>();
|
||||
#endregion
|
||||
|
||||
#region Ladder
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace bts.settings {
|
||||
interface IPNLSettingsMigrationRule : ISettingsMigrationRule<PNLSettings> { }
|
||||
interface ISyntheticManagementMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IReconcileReportMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IDayFillsGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
|
||||
static class SettingsMigrationHelper {
|
||||
public static bool apply<T>(T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, out T new_settings) {
|
||||
|
||||
@@ -6,6 +6,8 @@ using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -56,6 +58,8 @@ namespace mbts.spark {
|
||||
GridSettings _time_and_sales_grid;
|
||||
[ProtoMember(7)]
|
||||
GridSettings _fills_grid;
|
||||
[ProtoMember(15)]
|
||||
GridSettings _day_fills_grid;
|
||||
[ProtoMember(8)]
|
||||
GridSettings _synthetic_management_grid;
|
||||
[ProtoMember(14)]
|
||||
@@ -79,6 +83,10 @@ namespace mbts.spark {
|
||||
public GridSettings market_view_grid => _market_view_grid ?? (_market_view_grid = bts.shell.market_view.MarketViewSettings.DefaultGridSettings);
|
||||
public GridSettings time_and_sales_grid => _time_and_sales_grid ?? (_time_and_sales_grid = GridSettings.Default.with(bts.shell.time_and_sales.TimeAndSalesSettings.DefaultColumns.all));
|
||||
public GridSettings fills_grid => _fills_grid ?? (_fills_grid = bts.shell.fills.FillsSettings.DefaultGridSettings);
|
||||
|
||||
public GridSettings day_fills_grid =>
|
||||
_day_fills_grid ??= DayFillsSettings.default_grid();
|
||||
|
||||
public GridSettings synthetic_management_grid => _synthetic_management_grid ?? (_synthetic_management_grid = bts.shell.SyntheticManagementWindowFactory.StartupData.DefaultGridSettings);
|
||||
public GridSettings reconcile_report_grid => _reconcile_report_grid ??= Spark.Trading.ReconcileReportSettings.Default().grid;
|
||||
public PNLSettings pnl => _pnl ?? (_pnl = PNLSettings.Default);
|
||||
@@ -92,6 +100,7 @@ namespace mbts.spark {
|
||||
GridSettings provided_market_view_gridsettings = null,
|
||||
GridSettings time_and_sales = null,
|
||||
GridSettings provided_fills_gridsettings = null,
|
||||
GridSettings day_fills_grid = null,
|
||||
GridSettings provided_synthetic_management_gridsettings = null,
|
||||
GridSettings reconcile_report_grid = null,
|
||||
PNLSettings pnl = null,
|
||||
@@ -107,7 +116,8 @@ namespace mbts.spark {
|
||||
_reconcile_report_grid = reconcile_report_grid ?? _reconcile_report_grid,
|
||||
_pnl = pnl ?? _pnl,
|
||||
_order_book_grid = order_book_grid ?? _order_book_grid,
|
||||
_alerts = alerts ?? _alerts
|
||||
_alerts = alerts ?? _alerts,
|
||||
_day_fills_grid = day_fills_grid ?? _day_fills_grid
|
||||
};
|
||||
us._last_ladder_profile_id = Math.Max(_last_ladder_profile_id, us.ladder_profiles.Select(p => p.id).MaxOrDefault());
|
||||
return us;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace mbts.persist {
|
||||
|
||||
static readonly IImmutableProperty<UserSettings, GridSettings>
|
||||
_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.fills_grid, (us, gs) => us.with(provided_fills_gridsettings: gs)),
|
||||
_day_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.day_fills_grid, (us, gs) => us.with(day_fills_grid: gs)),
|
||||
_mview_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.market_view_grid, (us, gs) => us.with(provided_market_view_gridsettings: gs)),
|
||||
_synth_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.synthetic_management_grid, (us, gs) => us.with(provided_synthetic_management_gridsettings: gs)),
|
||||
_reconcile_report_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.reconcile_report_grid, (us, gs) => us.with(reconcile_report_grid: gs));
|
||||
@@ -36,6 +37,7 @@ namespace mbts.persist {
|
||||
readonly object _default_settings_lock = new object();
|
||||
readonly BehaviorSubject<UserSettings> _default_settings_subject = new BehaviorSubject<UserSettings>(UserSettings.factory_defaults);
|
||||
readonly IEnumerable<IFillsGridSettingsMigrationRule> _fills_migration_rules;
|
||||
readonly IEnumerable<IDayFillsGridSettingsMigrationRule> _day_fills_migration_rules;
|
||||
readonly IEnumerable<IMarketViewGridSettingsMigrationRule> _mview_migration_rules;
|
||||
readonly IEnumerable<IPNLSettingsMigrationRule> _pnl_migration_rules;
|
||||
readonly IEnumerable<ISyntheticManagementMigrationRule> _synth_migration_rules;
|
||||
@@ -48,6 +50,7 @@ namespace mbts.persist {
|
||||
public UserSettingsHub(
|
||||
IUserPersist persist,
|
||||
[ImportMany] IEnumerable<IFillsGridSettingsMigrationRule> fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IDayFillsGridSettingsMigrationRule> day_fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IMarketViewGridSettingsMigrationRule> mview_migration_rules,
|
||||
[ImportMany] IEnumerable<IPAndLGridSettingsMigrationRule> pandl_migration_rules,
|
||||
[ImportMany] IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules,
|
||||
@@ -56,6 +59,7 @@ namespace mbts.persist {
|
||||
//
|
||||
_persist = persist;
|
||||
_fills_migration_rules = fills_migration_rules ?? Enumerable.Empty<IFillsGridSettingsMigrationRule>();
|
||||
_day_fills_migration_rules = day_fills_migration_rules ?? Enumerable.Empty<IDayFillsGridSettingsMigrationRule>();
|
||||
_mview_migration_rules = mview_migration_rules ?? Enumerable.Empty<IMarketViewGridSettingsMigrationRule>();
|
||||
_pnl_migration_rules = pnl_migration_rules ?? Enumerable.Empty<IPNLSettingsMigrationRule>();
|
||||
_synth_migration_rules = synth_migration_rules ?? Enumerable.Empty<ISyntheticManagementMigrationRule>();
|
||||
@@ -152,6 +156,13 @@ namespace mbts.persist {
|
||||
_reconcile_report_migration_rules,
|
||||
_reconcile_report_propi);
|
||||
|
||||
public IWindowSettingsManager<GridSettings> create_day_fills_settings_manager(
|
||||
GridSettings instance_settings) =>
|
||||
_create_settings_manager(
|
||||
instance_settings,
|
||||
_day_fills_migration_rules,
|
||||
_day_fills_propi);
|
||||
|
||||
public async Task save_default(UserSettings value) {
|
||||
// notify observers before persisting so the changes are reflected immediately in the ui
|
||||
lock (_default_settings_lock) {
|
||||
|
||||
@@ -6,10 +6,12 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Markup;
|
||||
|
||||
using FontFamily = System.Windows.Media.FontFamily;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
[ContentProperty(nameof(Text))]
|
||||
class TextCell : FrameworkElement {
|
||||
// these fields each represent properties that are accessed frequently,
|
||||
// they are stored locally to reduce repetative DependencyProperty lookups
|
||||
|
||||
@@ -10,10 +10,11 @@ namespace mbts.spark.filters {
|
||||
class ColumnPredicateBuilder<TRow> {
|
||||
readonly List<Func<TRow, bool>> _predicates = new List<Func<TRow, bool>>();
|
||||
|
||||
public void add_discrete_values<T>(T[] values, Func<TRow, T> selector) {
|
||||
if (values.is_null_or_empty())
|
||||
public void add_discrete_values<T>(IEnumerable<T> values, Func<TRow, T> selector) {
|
||||
var set = values.empty_if_null().ToHashSet();
|
||||
if (set.Count == 0) {
|
||||
return;
|
||||
var set = new HashSet<T>(values);
|
||||
}
|
||||
_predicates.Add(impl);
|
||||
bool impl(TRow o) => set.Contains(selector(o));
|
||||
}
|
||||
@@ -86,6 +87,15 @@ namespace mbts.spark.filters {
|
||||
}
|
||||
}
|
||||
|
||||
public void add_regex<T>(string str, Func<TRow, T> selector, Func<T, string> fmt = null) {
|
||||
fmt ??= v => v?.ToString();
|
||||
var regex = RegexFilterUtils.build_regex(str);
|
||||
if (regex == null)
|
||||
return;
|
||||
_predicates.Add(impl);
|
||||
bool impl(TRow o) => regex.IsMatch(fmt(selector(o)) ?? string.Empty);
|
||||
}
|
||||
|
||||
public void add_regex(string str, Func<TRow, string> selector) {
|
||||
var regex = RegexFilterUtils.build_regex(str);
|
||||
if (regex == null)
|
||||
|
||||
@@ -15,6 +15,9 @@ namespace bts.utils {
|
||||
public T value => has_value ?
|
||||
_value : throw new InvalidOperationException($"value uninitialized");
|
||||
|
||||
public T value_or(T default_value) =>
|
||||
has_value ? value : default_value;
|
||||
|
||||
public bool Equals(Optional<T> other) =>
|
||||
has_value == other.has_value &&
|
||||
(!has_value || EqualityComparer<T>.Default.Equals(value, other.value));
|
||||
|
||||
Reference in new issue
Block a user