ui: Add exec fee columns to fills grid
This commit is contained in:
1 parent
0ba34da70e
commit
614e4de884
11 files changed
+104
-4
No files matched your search
@@ -74,6 +74,9 @@ namespace mbts.spark {
|
||||
dependent_props: new[] { nameof(display_size), nameof(display_quantity_text) });
|
||||
}
|
||||
|
||||
public double exec_fee_rate => fill_tuple.exec_fee_rate;
|
||||
public double exec_fee => fill_tuple.exec_fee;
|
||||
|
||||
public Fill.Types.FillKind fill_kind => _fill.FillKind;
|
||||
public Fill.Types.FillStatus fill_status => _fill.FillStatus;
|
||||
public string fill_key => _fill.FillKey;
|
||||
|
||||
@@ -302,6 +302,26 @@ namespace mbts.spark {
|
||||
(fs, cf) => fs.is_aggressor = cf,
|
||||
DefaultColumnWidths.IsAggressor);
|
||||
|
||||
add_col(
|
||||
Columns.ExecFee,
|
||||
DefaultColumnHeaders.ExecFee,
|
||||
r => r.security.spec_or_default().format(r.exec_fee),
|
||||
new DoubleMinMax<FillTuple>(r => r.exec_fee),
|
||||
DataGridFilterKnownTemplates.DoubleMinMax,
|
||||
fs => fs.exec_fee,
|
||||
(fs, cf) => fs.exec_fee = cf,
|
||||
DefaultColumnWidths.Price);
|
||||
|
||||
add_col(
|
||||
Columns.ExecFeeRate,
|
||||
DefaultColumnHeaders.ExecFeeRate,
|
||||
r => r.exec_fee_rate.ToString("0.000###"),
|
||||
new DoubleMinMax<FillTuple>(r => r.exec_fee_rate),
|
||||
DataGridFilterKnownTemplates.DoubleMinMax,
|
||||
fs => fs.exec_fee_rate,
|
||||
(fs, cf) => fs.exec_fee_rate = cf,
|
||||
DefaultColumnWidths.Price);
|
||||
|
||||
add_col(
|
||||
Columns.OrderKey,
|
||||
DefaultColumnHeaders.OrderKey,
|
||||
@@ -524,6 +544,8 @@ namespace mbts.spark {
|
||||
case Columns.FillStatus: return wrap_default(ft => ft.fill.FillStatus);
|
||||
case Columns.FillTime: return wrap(ft => ft.fill.Timestamp.to_local_time());
|
||||
case Columns.IsAggressor: return wrap_default(ft => ft.fill.FillAggressorFlag == FillAggressorFlag.Aggressor);
|
||||
case Columns.ExecFeeRate: return wrap_default(ft => ft.exec_fee_rate);
|
||||
case Columns.ExecFee: return wrap_default(ft => ft.exec_fee_rate * ft.fill.LastShares * ft.fill.AvgPrice);
|
||||
case Columns.OrderKey: return wrap(ft => ft.fill.OrderKey);
|
||||
case Columns.OrderType: return wrap_default(ft => ft.order?.order_type() ?? OrderType.None);
|
||||
case Columns.RootAlgoType: return wrap_default(ft => ft.root_algo.HasValue ? ft.root_algo.Value.value.CustomCase : OrderType.None);
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace mbts.ui.spark {
|
||||
Size,
|
||||
NotionalValue,
|
||||
IsAggressor,
|
||||
ExecFee,
|
||||
ExecFeeRate,
|
||||
FillKind,
|
||||
FillStatus,
|
||||
FillKey,
|
||||
|
||||
@@ -94,6 +94,14 @@ namespace bts.shell.fills {
|
||||
[DIYGridColumnID(nameof(Columns.IsAggressor))]
|
||||
public bool[] is_aggressor { get; set; }
|
||||
|
||||
[ProtoMember(20)]
|
||||
[DIYGridColumnID(nameof(Columns.ExecFee))]
|
||||
public DoubleMinMaxState exec_fee { get; set; }
|
||||
|
||||
[ProtoMember(21)]
|
||||
[DIYGridColumnID(nameof(Columns.ExecFeeRate))]
|
||||
public DoubleMinMaxState exec_fee_rate { get; set; }
|
||||
|
||||
// PNL's Expiration group popups use this prop to filtered data by a particular exp (it isn't
|
||||
// serialized bc it's not part of the main window's settings)
|
||||
public ExpirationDate? exp_date { get; set; }
|
||||
@@ -125,6 +133,8 @@ namespace bts.shell.fills {
|
||||
pb.add_numeric(fs.size, ft => ft.fill.LastShares);
|
||||
pb.add_numeric(fs.notional_value, ft => ft.fill.notional_value());
|
||||
pb.add_numeric(fs.price, ft => ft.fill.LastPrice);
|
||||
pb.add_numeric(fs.exec_fee_rate, ft => ft.exec_fee_rate);
|
||||
pb.add_numeric(fs.exec_fee, ft => ft.exec_fee);
|
||||
|
||||
if (fs.exp_date.HasValue) {
|
||||
pb.add_exp_date(fs.exp_date.Value, f => f.security?.earliest_expiration());
|
||||
|
||||
@@ -60,6 +60,8 @@ namespace bts.shell.fills {
|
||||
public static GridColumnSettings quantity => new GridColumnSettings(col_id(Columns.Size), DefaultColumnHeaders.Qty, width: DefaultColumnWidths.Qty, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings price => new GridColumnSettings(col_id(Columns.Price), DefaultColumnHeaders.Price, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings is_aggressor => new GridColumnSettings(col_id(Columns.IsAggressor), DefaultColumnHeaders.IsAggressor, width: DefaultColumnWidths.CheckMark);
|
||||
public static GridColumnSettings exec_fee => new(col_id(Columns.ExecFee), DefaultColumnHeaders.ExecFee, width: DefaultColumnWidths.Price);
|
||||
public static GridColumnSettings exec_fee_rate => new(col_id(Columns.ExecFeeRate), DefaultColumnHeaders.ExecFeeRate, width: DefaultColumnWidths.Price, is_visible: false);
|
||||
public static GridColumnSettings fill_kind => new GridColumnSettings(col_id(Columns.FillKind), DefaultColumnHeaders.FillKind, width: DefaultColumnWidths.FillKind);
|
||||
public static GridColumnSettings fill_status => new GridColumnSettings(col_id(Columns.FillStatus), DefaultColumnHeaders.FillStatus, width: DefaultColumnWidths.FillStatus);
|
||||
public static GridColumnSettings fill_key => new GridColumnSettings(col_id(Columns.FillKey), DefaultColumnHeaders.FillKey, width: DefaultColumnWidths.FillKey);
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace mbts.spark {
|
||||
using mbts.ui;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Api.Position;
|
||||
using Spark.Api.Reactive;
|
||||
@@ -44,6 +45,7 @@ namespace mbts.spark {
|
||||
Configuration.get<bts.config.toggles.PlacementInQueue>().Enabled;
|
||||
public readonly MarketDataAuxiliaryModel md_auxiliary_model;
|
||||
public readonly ISecurityMetadataStore sec_meta_store;
|
||||
public readonly IExecFeeCalculator exec_fee_calculator;
|
||||
|
||||
readonly IBus _bus;
|
||||
readonly IAlgoProvider _algo_provider, _attachable_algo_provider;
|
||||
@@ -74,6 +76,7 @@ namespace mbts.spark {
|
||||
AdminModel admin_model,
|
||||
IAlgoStudioModel algo_model,
|
||||
ISecurityMetadataStore sec_meta_store,
|
||||
IExecFeeCalculator exec_fee_calculator,
|
||||
MarketDataAuxiliaryModel md_auxiliary_model,
|
||||
IAlgoProvider algo_provider,
|
||||
IAttachableAlgoProvider attachable_algo_provider,
|
||||
@@ -94,6 +97,7 @@ namespace mbts.spark {
|
||||
this.algo_model = algo_model;
|
||||
this.md_auxiliary_model = md_auxiliary_model;
|
||||
this.sec_meta_store = sec_meta_store;
|
||||
this.exec_fee_calculator = exec_fee_calculator;
|
||||
var scheduler = ThreadPoolScheduler.Instance;
|
||||
var interval = TimeSpan.FromMilliseconds(100);
|
||||
var bootstraps = new DisposableBuilder();
|
||||
@@ -190,8 +194,8 @@ namespace mbts.spark {
|
||||
f => f.val.FillKey,
|
||||
o => o.order.Key,
|
||||
f => f.val.OrderKey,
|
||||
(f, fk, o, ok) => new FillTuple(f, o),
|
||||
(f, fk, ok) => new FillTuple(f, null),
|
||||
getFillTuple,
|
||||
getFillTuple,
|
||||
f => f.fill.FillKey);
|
||||
|
||||
on_fill_tuples = bootstraps.emplace(fill_order_tuples_join.Cache().ToObservable());
|
||||
@@ -204,8 +208,8 @@ namespace mbts.spark {
|
||||
f => f.val.FillKey,
|
||||
o => o.order.order.Key,
|
||||
f => f.val.OrderKey,
|
||||
(f, fk, o, ok) => new FillTuple(f.val, f.sec, o),
|
||||
(f, fk, ok) => new FillTuple(f.val, f.sec, null),
|
||||
getFillTuple,
|
||||
getFillTuple,
|
||||
FillTuple.key_fn)
|
||||
.Cache()
|
||||
.ToObservable());
|
||||
@@ -490,6 +494,21 @@ namespace mbts.spark {
|
||||
return _handle_error(result);
|
||||
}
|
||||
|
||||
FillTuple getFillTuple((SecurityImmutable? sec, FillImmutable val) f, string fk, OrderRecordTupleWithRoot o, uint ok) =>
|
||||
new(f.val, f.sec, o) {
|
||||
exec_fee_rate = exec_fee_calculator.GetExecFee(f.sec, f.val.Account, f.val.FillAggressorFlag == FillAggressorFlag.Aggressor)
|
||||
};
|
||||
|
||||
FillTuple getFillTuple((SecurityImmutable? sec, FillImmutable val) f, string fk, OrderRecordTuple o, uint ok) =>
|
||||
new(f, o) {
|
||||
exec_fee_rate = exec_fee_calculator.GetExecFee(f.sec, f.val.Account, f.val.FillAggressorFlag == FillAggressorFlag.Aggressor)
|
||||
};
|
||||
|
||||
FillTuple getFillTuple((SecurityImmutable? sec, FillImmutable val) f, string fk, uint ok) =>
|
||||
new(f.val, f.sec, null) {
|
||||
exec_fee_rate = exec_fee_calculator.GetExecFee(f.sec, f.val.Account, f.val.FillAggressorFlag == FillAggressorFlag.Aggressor)
|
||||
};
|
||||
|
||||
ManualFillBatchImmutable _create_fill_batch(IEnumerable<ManualFill> fills) {
|
||||
var batch = new ManualFillBatch();
|
||||
batch.ManualFill.AddRange(fills);
|
||||
|
||||
@@ -151,6 +151,8 @@ namespace mbts.ui.controls {
|
||||
FilledNotionalValue = "Fill Notional",
|
||||
FillStatus = "Fill Status",
|
||||
IsAggressor = "Aggressor",
|
||||
ExecFee = "Fee",
|
||||
ExecFeeRate = "Fee %",
|
||||
Name = "Name",
|
||||
Description = "Description",
|
||||
N_Legs = "# Legs",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Reactive;
|
||||
using Spark.Core.Data;
|
||||
|
||||
@@ -37,6 +38,8 @@
|
||||
// Models a generic multi-window host
|
||||
public class ShellModel : IDisposable {
|
||||
Lazy<CompositionHost> _container = new Lazy<CompositionHost>(create_container);
|
||||
readonly Lazy<IExecFeeCalculator> _exec_fee_calculator = new(
|
||||
() => new ExecFeeCalculator(SecurityMetadataStore.instance));
|
||||
|
||||
public CompositionHost container => _container.Value;
|
||||
|
||||
@@ -59,6 +62,9 @@
|
||||
public ISecurityMetadataStore security_metadata_store =>
|
||||
SecurityMetadataStore.instance;
|
||||
|
||||
[Export]
|
||||
public IExecFeeCalculator exec_fee_calculator => _exec_fee_calculator.Value;
|
||||
|
||||
public void Initialize(string config_source) {
|
||||
PerformMEFComposition(config_source);
|
||||
InitInitializers();
|
||||
|
||||
@@ -68,6 +68,9 @@ namespace mbts.spark {
|
||||
public bool is_aggressor =>
|
||||
fill.FillAggressorFlag == FillAggressorFlag.Aggressor;
|
||||
|
||||
public double exec_fee => exec_fee_rate * fill.AvgPrice * fill.LastShares;
|
||||
public double exec_fee_rate { get; init; }
|
||||
|
||||
public bool Equals(FillTuple other) =>
|
||||
other != null &&
|
||||
_order_tuple.Equals(other._order_tuple) &&
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#nullable enable
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
using bts.api;
|
||||
|
||||
using Spark.Core.Data;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
class ExecFeeCalculator : IExecFeeCalculator {
|
||||
readonly ISecurityMetadataStore secMetaStore;
|
||||
|
||||
public ExecFeeCalculator(ISecurityMetadataStore secMetaStore) =>
|
||||
this.secMetaStore = secMetaStore;
|
||||
|
||||
public double GetExecFee(SecurityImmutable? sec, string account, bool isAggressor) {
|
||||
var execFeeRules = (sec.HasValue ? secMetaStore.get(sec.Value) : null)?.ExecFeeRules;
|
||||
return execFeeRules.empty_if_null().TryGetFirst(r => Regex.IsMatch(account, r.Account), out var r)
|
||||
? isAggressor ? r.TakerFee : r.MakerFee
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#nullable enable
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
using bts.api;
|
||||
|
||||
public interface IExecFeeCalculator {
|
||||
double GetExecFee(SecurityImmutable? sec, string account, bool isAggressor);
|
||||
}
|
||||
Reference in new issue
Block a user