Merge branch 'SPARK-1944-attach/detach/update' of bitbucket.org:bluetradesys/spark into SPARK-2207

This commit is contained in:
Jake Norbut committed 2019-04-11 07:27:15 -05:00
commit ae237d36b6
29 files changed
+1124 -464

No files matched your search

@@ -205,8 +205,8 @@ namespace mbts.spark {
}
void _show_order_book(Side side) =>
_bus.post(SparkTags.ShowOrderBookTag, new bts.shell.OrderBookWindowFactory.OrderBookStartupData(
new bts.shell.OrderBookWindowFactory.FilterStates {
_bus.post(SparkTags.ShowOrderBookTag, new bts.shell.orderbook.OrderBookStartupData(
new bts.shell.orderbook.FilterStates {
statuses = new[] { OrderStatus.Working },
sides = new[] { side },
security_criteria = new SecurityCriteria(security)
@@ -68,8 +68,8 @@ namespace mbts.spark {
rs => rs.HasValue, select_row_strategy_tuple
), SparkCommands.ShowLadder(SparkCommands.KeyGestures.ShowLadder).complete(
vm_connectable_builder.create(vm => vm.current_security_md), md => md.HasValue, ConvertUtils.ValueOrDefault
), SparkCommands.ShowOrders.complete(() => new OrderBookWindowFactory.OrderBookStartupData {
filters = new OrderBookWindowFactory.FilterStates {
), SparkCommands.ShowOrders.complete(() => new bts.shell.orderbook.OrderBookStartupData {
filters = new bts.shell.orderbook.FilterStates {
security_criteria = new SecurityCriteria(_vm.value.row_vms.Select(r => r.security))
}
}
@@ -170,8 +170,8 @@ namespace mbts.spark {
_bus.post(SparkTags.ShowLadderTag, md);
void _show_order_book() =>
_bus.post(SparkTags.ShowOrderBookTag, new OrderBookWindowFactory.OrderBookStartupData {
filters = new OrderBookWindowFactory.FilterStates {
_bus.post(SparkTags.ShowOrderBookTag, new bts.shell.orderbook.OrderBookStartupData {
filters = new bts.shell.orderbook.FilterStates {
security_criteria = new SecurityCriteria(security)
}
});
@@ -300,6 +300,7 @@ namespace mbts.spark {
_load_algo_data(algo_data, default_algo);
void IAlgoParamVM.revert() { }
void IAlgoParamVM.mark_committed() { }
IObservable<IAlgoVM> IAlgoSelector.subscribe_selected_algo() =>
this.observe_algo_root();
@@ -24,6 +24,20 @@ namespace mbts.spark {
rows.clear_collections
};
public static IDisposable negate_is_dirty(IReadOnlyObservableCollection<AlgoParamRowVM> rows) {
return ObservableAutoWrapper.connect_item_hooks(rows, hook);
IDisposable hook(AlgoParamRowVM r) {
r.param.is_dirty_changed += negate;
return Disposable.Create(unhook);
void negate(bool is_dirty) {
if (is_dirty)
r.param.mark_committed();
}
void unhook() =>
r.param.is_dirty_changed -= negate;
}
}
static IDisposable _wrap_rows(AlgoDefinitionVM algo_def, ObservableAggregateCollection<AlgoParamRowVM> rows, bool include_algo_type_rows) {
AlgoParamRowVM root = null;
ObservableAggregateCollection<AlgoParamRowVM> algo_params;
@@ -234,13 +234,13 @@ namespace mbts.spark {
price_filter.maximum.value = real_price;
var obvm = new OrderBookVM(null, _parent.bus, null, _parent.model.order_gateway, null, true);
var state = new bts.shell.OrderBookWindowFactory.OrderBookStartupData(
new bts.shell.OrderBookWindowFactory.FilterStates {
var state = new bts.shell.orderbook.OrderBookStartupData(
new bts.shell.orderbook.FilterStates {
security_criteria = new SecurityCriteria(_parent.security),
price = price_filter,
statuses = new[] { OrderStatus.Working }
},
bts.shell.OrderBookWindowFactory.OrderBookStartupData.default_mini_grid,
bts.shell.orderbook.OrderBookStartupData.default_mini_grid,
use_defaults: false
);
// NOTE:
@@ -399,8 +399,8 @@ namespace mbts.spark {
}
void _show_book() =>
_bus.post(SparkTags.ShowOrderBookTag, new bts.shell.OrderBookWindowFactory.OrderBookStartupData {
filters = new bts.shell.OrderBookWindowFactory.FilterStates {
_bus.post(SparkTags.ShowOrderBookTag, new bts.shell.orderbook.OrderBookStartupData {
filters = new bts.shell.orderbook.FilterStates {
security_criteria = new SecurityCriteria(security)
}
});
@@ -1,6 +1,7 @@
using bts;
using bts.api;
using bts.api.orderman;
using bts.shell.orderbook;
using bts.utils;
using mbts.spark.filters;
using mbts.ui;
@@ -22,7 +23,6 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;
using static bts.shell.OrderBookWindowFactory;
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
using static mbts.ui.controls.DIYGrid;
using OrderType = bts.api.orderman.CustomOrderDefinition.CustomOneofCase;
@@ -3,6 +3,7 @@ using bts.api;
using bts.api.core;
using bts.api.orderman;
using bts.shell;
using bts.shell.orderbook;
using bts.spark;
using bts.utils;
using mbts.collections;
@@ -26,13 +27,12 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using static bts.shell.OrderBookWindowFactory;
using _GridSettingsManager =
mbts.ui.GridSettingsManager<
mbts.spark.OrderBookRowVM,
bts.api.orderman.OrderSecurity,
mbts.OrderRecordTuplePredicate,
bts.shell.OrderBookWindowFactory.OrderBookGridSettings>;
bts.shell.orderbook.OrderBookGridSettings>;
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
namespace mbts.spark {
@@ -45,12 +45,13 @@ namespace mbts.spark {
readonly IBus _bus;
readonly OrdersModel _model;
readonly Property<OrderBookRowVM> _current_row;
readonly Property<bool> _show_ladder, _show_fills, _show_order_params;
readonly DelegateProperty<bool> _show_order_params, _show_ladder, _show_fills;
readonly OrderBookRowCollection _row_collection;
readonly OrderBookColumnCollection _columns;
readonly IWindowSettingsManager<OrderBookGridSettings> _settings_manager;
readonly IWindowSettingsManager<GridSettings> _fills_settings_manager = new WindowSettingsManager<GridSettings>.DisconnectedImpl(FillsWindowFactory.StartupData.MiniGridSettings, FillsWindowFactory.StartupData.MiniGridSettings);
readonly SelectedOrderParamsMon _selected_params_mon;
readonly RightPanelModel _right_panel = new RightPanelModel();
OrderBookFillsGridSettings _cached_fills_settings = OrderBookStartupData.DefaultFillsGrid;
double
_raw_right_panel_width = OrderBookStartupData.Default.right_panel_width,
@@ -69,9 +70,14 @@ namespace mbts.spark {
order_mod_vm = new OrderParamsVM(this, AlgoDefinitionVM.create(model, OrderDataHelper.Defaults.AlgoData(), editing_permissions: AlgoEditingPermissions.AllowEditValues));
order_mod_vm.algo_vm.editing_permissions_mask = AlgoEditingPermissions.None;
order_mod_vm.algo_vm.algo_root = null;
_show_ladder = backing(nameof(show_ladder), false);
_show_fills = backing(nameof(show_fills), false);
_show_order_params = backing(nameof(show_order_params), false);
_show_order_params = backing(nameof(show_order_params), () => (_right_panel.visible_components & OrderBookRightPanelSettings.Components.Params) != 0);
_show_ladder = backing(nameof(show_ladder), () => (_right_panel.visible_components & OrderBookRightPanelSettings.Components.Ladder) != 0);
_show_fills = backing(nameof(show_fills), () => (_right_panel.visible_components & OrderBookRightPanelSettings.Components.Fills) != 0);
_right_panel.visible_changed += vis_comps => {
_show_order_params.refresh();
_show_ladder.refresh();
_show_fills.refresh();
};
attach_vm = new OrderParamsVM(this, AlgoDefinitionVM.create(_model, OrderDataHelper.Defaults.AlgoData(CustomOrderDefinition.CustomOneofCase.Iceberg), editing_permissions: AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowEditValues));
_settings_manager = settings_manager;
_columns = new OrderBookColumnCollection(bus, model, model.on_order_securities.Select(x => (x.added.Values, x.removed.Values)));
@@ -202,6 +208,7 @@ namespace mbts.spark {
Disposable.replace(ref attach_vm_hooks,
Disposable.Create(
connect_common_selected_params(attach_vm),
AlgoParamRowsHelper.negate_is_dirty(attach_vm.param_rows),
// custom templates (created by user)
_model.algo_model.definitions.OnDispatcher().Subscribe(u =>
AlgoCollectionHelper.update_persisted_definition_wrappers(attach_vm.algo_vm.algo_roots as ObservableKeyedCollection<IAlgoVM, AlgoKey>, u, mk_factory(true))),
@@ -291,6 +298,13 @@ namespace mbts.spark {
show_order_params = true;
}
}
public OrderBookRightPanelSettings.ViewMode right_panel_view_mode {
get => _right_panel.mode;
set {
_right_panel.mode = value;
RaisePropertyChanged();
}
}
public double right_panel_width {
get => Math.Max(_raw_right_panel_width, _min_right_panel_width);
set => Set(ref _raw_right_panel_width, value);
@@ -311,9 +325,9 @@ namespace mbts.spark {
get => _is_row_collection_populated;
set => Set(ref _is_row_collection_populated, value);
}
public bool show_ladder { get => _show_ladder.Value; set => _show_ladder.set(value); }
public bool show_fills { get => _show_fills.Value; set => _show_fills.set(value); }
public bool show_order_params { get => _show_order_params.Value; set => _show_order_params.set(value); }
public bool show_order_params { get => _show_order_params.Value; set => _right_panel.on_checked(OrderBookRightPanelSettings.Components.Params, value); }
public bool show_ladder { get => _show_ladder.Value; set => _right_panel.on_checked(OrderBookRightPanelSettings.Components.Ladder, value); }
public bool show_fills { get => _show_fills.Value; set => _right_panel.on_checked(OrderBookRightPanelSettings.Components.Fills, value); }
public bool can_user_modify_selected_orders { get; private set; }
public Plurality security_plurality { get; private set; }
@@ -349,7 +363,7 @@ namespace mbts.spark {
public OrderBookStartupData create() {
var (filters, sorting) = _columns.create();
var gs = grid_settings_manager.create();
return new OrderBookStartupData(
var rv = new OrderBookStartupData(
filters,
gs.general.with(sorting_criterion: sorting),
_show_right_panel,
@@ -364,22 +378,30 @@ namespace mbts.spark {
ladder_height = ladder_height,
fills_settings = _get_fills_settings(fills_vm.value)
};
rv.right_panel.mode = right_panel_view_mode;
rv.right_panel.tab = _right_panel.last_selected;
return rv;
}
public void load_from(OrderBookStartupData state) {
if (state == null) return;
show_right_panel = state.show_right_panel;
show_order_params = state.show_order_params;
right_panel_width = state.right_panel_width;
order_params_height = state.order_params_height;
/// important: <see cref="_cached_fills_settings"/> must be assigned before <see cref="show_fills"/>, as the former is used to create the fills vm immediately after <see cref="show_fills"/> is set to true.
if (state.fills_settings != null) {
_cached_fills_settings = state.fills_settings;
_fills_settings_manager.instance_settings = state.fills_settings.general;
}
show_fills = state.show_fills;
right_panel_view_mode = state.right_panel.mode;
switch (state.right_panel.mode) {
case OrderBookRightPanelSettings.ViewMode.Stack:
show_order_params = state.right_panel.stack.show_order_params;
show_ladder = state.right_panel.stack.show_ladder;
show_fills = state.right_panel.stack.show_fills;
break;
case OrderBookRightPanelSettings.ViewMode.Tab:
_right_panel.on_checked(state.right_panel.tab, true);
break;
}
fills_height = state.fills_height;
show_ladder = state.show_ladder;
ladder_height = state.ladder_height;
var gs = state.grid_settings_wrapper();
if (gs != null) {
@@ -883,5 +905,59 @@ namespace mbts.spark {
public static bool operator !=(AlgoSecurityKey a, AlgoSecurityKey b) => !a.Equals(b);
}
}
class RightPanelModel {
OrderBookRightPanelSettings.ViewMode _mode;
OrderBookRightPanelSettings.Components _all_selected, _hidden = OrderBookRightPanelSettings.Components.None;
public event Action<OrderBookRightPanelSettings.Components> visible_changed;
public OrderBookRightPanelSettings.Components last_selected { get; private set; }
public OrderBookRightPanelSettings.ViewMode mode {
get => _mode;
set {
using (_update()) {
if (_mode == OrderBookRightPanelSettings.ViewMode.Stack && value == OrderBookRightPanelSettings.ViewMode.Tab) {
if (last_selected == OrderBookRightPanelSettings.Components.None)
last_selected = EnumHelper.get_values_except(OrderBookRightPanelSettings.Components.None).FirstOrDefault(c => (c & _all_selected) != 0);
}
_mode = value;
}
}
}
public OrderBookRightPanelSettings.Components visible_components {
get {
switch (mode) {
case OrderBookRightPanelSettings.ViewMode.Stack: return _all_selected ^ _hidden;
case OrderBookRightPanelSettings.ViewMode.Tab: return last_selected;
default: return OrderBookRightPanelSettings.Components.None;
}
}
}
public void on_checked(OrderBookRightPanelSettings.Components component, bool is_checked) {
using (_update()) {
if (is_checked) {
_hidden ^= (_hidden & component);
_all_selected |= component;
last_selected = component;
} else if (mode == OrderBookRightPanelSettings.ViewMode.Stack) {
last_selected ^= (last_selected & component);
_hidden |= component;
}
}
}
IDisposable _update() {
var prev_vis = visible_components;
return Disposable.Create(refresh);
void refresh() {
if (prev_vis != visible_components)
visible_changed?.Invoke(visible_components);
}
}
}
}
}
@@ -1,6 +1,7 @@
using bts.api;
using bts.api.orderman;
using bts.shell;
using bts.shell.orderbook;
using bts.spark;
using bts.view;
using mbts.persist;
@@ -18,16 +19,15 @@ using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using OrderBookGridSettings = bts.shell.OrderBookWindowFactory.OrderBookGridSettings;
using OrderBookGridSettingsVM = mbts.spark.GridSettingsVM<bts.api.orderman.OrderSecurity, mbts.OrderRecordTuplePredicate, bts.shell.OrderBookWindowFactory.OrderBookGridSettings>;
using OrderBookGridSettingsVM = mbts.spark.GridSettingsVM<bts.api.orderman.OrderSecurity, mbts.OrderRecordTuplePredicate, bts.shell.orderbook.OrderBookGridSettings>;
namespace mbts.spark {
internal class OrderBookWindow : SparkWindow<OrderBookWindowFactory.OrderBookStartupData>, ISharedWindow {
internal class OrderBookWindow : SparkWindow<OrderBookStartupData>, ISharedWindow {
const string _window_type = "OrderBook", _default_title = "Order Book";
readonly INotificationService _notification_service;
readonly IWindowSettingsManager<OrderBookGridSettings> _settings_manager;
IDisposable _attachment_exit_sub;
OrderBookWindowFactory.OrderBookStartupData _state;
OrderBookStartupData _state;
OrdersModel _model;
OrderBookVM _vm;
OrderBookView _view;
@@ -35,7 +35,7 @@ namespace mbts.spark {
SparkCommand[] _commands;
public OrderBookWindow(OrdersModel model, OrderBookWindowFactory factory, IBus bus, INotificationService notification_service,
OrderBookWindowFactory.OrderBookStartupData state, ImageSource icon, IWindowSettingsManager<OrderBookGridSettings> settings_manager)
OrderBookStartupData state, ImageSource icon, IWindowSettingsManager<OrderBookGridSettings> settings_manager)
: base(_default_title, bus, factory, SparkCommands.ShowOrders.icon) {
_model = model;
_factory = factory;
@@ -45,13 +45,13 @@ namespace mbts.spark {
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().order_book ? "OrderBook" : null;
}
public override OrderBookWindowFactory.OrderBookStartupData SaveState => _state = _vm?.create();
public override OrderBookStartupData SaveState => _state = _vm?.create();
public override string window_type => _window_type;
public override UIElement Content => _view;
public override IEnumerable<SparkCommand> Commands => _commands;
public override double MinWidth =>
OrderBookWindowFactory.OrderBookStartupData.DefaultGrid.general.columns.Sum(gcs => gcs.width)
OrderBookStartupData.DefaultGrid.general.columns.Sum(gcs => gcs.width)
+ SPARK_MENU_COLLAPSED_WIDTH
+ LAUNCHER_BUTTON_BORDER_WIDTH
+ EXTRA_FOR_NO_HORIZONTAL_SCROLLBAR_WIDTH;
@@ -154,7 +154,7 @@ namespace mbts.spark {
UserSettings.FileExtensions.GRID,
s => {
if (s.general is null)
s = OrderBookWindowFactory.OrderBookStartupData.DefaultGrid;
s = OrderBookStartupData.DefaultGrid;
return _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.
@@ -1,26 +1,15 @@
using bts.api;
using bts.api.orderman;
using bts.shell.orderbook;
using bts.spark;
using bts.utils;
using mbts;
using mbts.persist;
using mbts.spark;
using mbts.spark.filters;
using mbts.ui;
using mbts.ui.controls;
using mbts.ui.settings;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows;
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
namespace bts.shell {
internal class OrderBookWindowFactory : ShellWindowFactory<OrderBookWindowFactory.OrderBookStartupData> {
internal class OrderBookWindowFactory : ShellWindowFactory<OrderBookStartupData> {
readonly IBus _bus;
readonly INotificationService _notification_service;
readonly INotificationServiceDataCache _notification_service_data_cache;
@@ -48,344 +37,5 @@ namespace bts.shell {
var w = await load(startup_data);
_bus.post(SparkTags.ShowWindow, w);
}
[ProtoContract]
public class OrderBookStartupData {
const bool
_default_show_right_panel = true,
_default_show_order_params = true;
const double
_default_right_panel_width = 400,
_default_order_params_height = 250,
_default_fills_height = 300,
_default_ladder_height = 350;
// ALREADY USED TAGS
// [ProtoMember(5)]
// public readonly List<SortingCriteria> sort_criteria;
// filters
[ProtoMember(10)]
public FilterStates filters;
// grid
[ProtoMember(15)]
[Obsolete]
public GridSettings grid;
// algo editor is visible
[ProtoMember(16)]
[DefaultValue(_default_show_right_panel)]
public bool show_right_panel { get; set; }
// right panel width
[ProtoMember(17)]
[DefaultValue(_default_right_panel_width)]
public double right_panel_width { get; set; }
// show order params
[ProtoMember(23)]
[DefaultValue(_default_show_order_params)]
public bool show_order_params { get; set; }
// order params height
[ProtoMember(24)]
[DefaultValue(_default_order_params_height)]
public double order_params_height { get; set; }
// fills height
[ProtoMember(18)]
[DefaultValue(_default_fills_height)]
public double fills_height { get; set; }
// show fills
[ProtoMember(19)]
public bool show_fills { get; set; }
// fills settings
[ProtoMember(26)]
public OrderBookFillsGridSettings fills_settings { get; set; }
// ladder height
[ProtoMember(21)]
[DefaultValue(_default_ladder_height)]
public double ladder_height { get; set; }
// show ladder
[ProtoMember(22)]
public bool show_ladder { get; set; }
// predicate animations
[ProtoMember(20)]
[Obsolete]
List<OrderRecordTuplePredicateAnimations> _predicate_animations;
// use defaults
[ProtoMember(25)]
public bool use_defaults;
public OrderBookStartupData() {
show_right_panel = _default_show_right_panel;
show_order_params = _default_show_order_params;
right_panel_width = _default_right_panel_width;
order_params_height = _default_order_params_height;
fills_height = _default_fills_height;
ladder_height = _default_ladder_height;
}
public OrderBookStartupData(FilterStates filters, GridSettings grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, bool use_defaults = false) {
this.filters = filters;
this.use_defaults = use_defaults;
this.show_right_panel = show_right_panel;
this.right_panel_width = right_panel_width;
this.fills_height = fills_height;
this.show_fills = show_fills;
#pragma warning disable CS0612 // Type or member is obsolete
this.grid = grid;
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
if (predicate_animations != null)
_predicate_animations.AddRange(predicate_animations);
#pragma warning restore CS0612 // Type or member is obsolete
}
#pragma warning disable CS0612 // Type or member is obsolete
[Obsolete]
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
public OrderBookGridSettings grid_settings_wrapper() => use_defaults ? null : new OrderBookGridSettings(grid, predicate_animations);
#pragma warning restore CS0612 // Type or member is obsolete
public static OrderBookStartupData Default =>
new OrderBookStartupData(
new FilterStates { statuses = new[] { OrderStatus.Working } },
_default_general_grid,
_default_show_right_panel,
_default_right_panel_width,
_default_fills_height,
use_defaults: true) {
show_order_params = _default_show_order_params,
order_params_height = _default_order_params_height,
fills_settings = DefaultFillsGrid
};
public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid);
public static OrderBookFillsGridSettings DefaultFillsGrid {
get {
var default_fills = FillsWindowFactory.StartupData.Default();
var rv = new OrderBookFillsGridSettings {
sorting_criterion = default_fills.sorting_criterion.ToList(),
filters = default_fills.filters,
general = FillsWindowFactory.StartupData.MiniGridSettings
};
return rv;
}
}
static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.sorting_criterion);
public static GridSettings default_mini_grid => GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion);
static class DefaultColumns {
public static GridColumnSettings security => new GridColumnSettings(Columns.Security.ToString(), DIYGrid.DefaultColumnHeaders.Security, width: DIYGrid.DefaultColumnWidths.Security);
public static GridColumnSettings symbol => new GridColumnSettings(Columns.Symbol.ToString(), DIYGrid.DefaultColumnHeaders.Symbol, width: DIYGrid.DefaultColumnWidths.Symbol);
public static GridColumnSettings time_created => new GridColumnSettings(Columns.Time.ToString(), "Time", width: DIYGrid.DefaultColumnWidths.Time);
public static GridColumnSettings last_change => new GridColumnSettings(Columns.LastChange.ToString(), "Last Change", width: DIYGrid.DefaultColumnWidths.Time);
public static GridColumnSettings user => new GridColumnSettings(Columns.User.ToString(), DIYGrid.DefaultColumnHeaders.User, width: DIYGrid.DefaultColumnWidths.User);
public static GridColumnSettings account => new GridColumnSettings(Columns.Account.ToString(), DIYGrid.DefaultColumnHeaders.Account, width: DIYGrid.DefaultColumnWidths.Account);
public static GridColumnSettings exchange => new GridColumnSettings(Columns.Exchange.ToString(), DIYGrid.DefaultColumnHeaders.Exchange, width: DIYGrid.DefaultColumnWidths.Exchange);
public static GridColumnSettings time_in_force => new GridColumnSettings(Columns.TimeInForce.ToString(), DIYGrid.DefaultColumnHeaders.TimeInForce, width: DIYGrid.DefaultColumnWidths.TimeInForce);
public static GridColumnSettings order_type => new GridColumnSettings(Columns.OrderType.ToString(), DIYGrid.DefaultColumnHeaders.OrderType, width: DIYGrid.DefaultColumnWidths.OrderType);
public static GridColumnSettings sub_type => new GridColumnSettings(Columns.SubType.ToString(), "Sub Type", width: 80);
public static GridColumnSettings side => new GridColumnSettings(Columns.Side.ToString(), "B/S", width: DIYGrid.DefaultColumnWidths.Side);
public static GridColumnSettings quantity => new GridColumnSettings(Columns.Size.ToString(), "Qty", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings price => new GridColumnSettings(Columns.Price.ToString(), DIYGrid.DefaultColumnHeaders.Price, width: DIYGrid.DefaultColumnWidths.Price, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings filled_quantity => new GridColumnSettings(Columns.Filled.ToString(), "Filled Qty", width: DIYGrid.DefaultColumnWidths.Filled, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings avg_price => new GridColumnSettings(Columns.AvgFilled.ToString(), "Avg Filled", width: DIYGrid.DefaultColumnWidths.AveragePrice, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80);
public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage);
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey);
public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey);
public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey);
public static GridColumnSettings attached_target_order_key => new GridColumnSettings(Columns.AttachedTargetOrderKey.ToString(), DIYGrid.DefaultColumnHeaders.AttachedTargetOrderKey, width: DIYGrid.DefaultColumnWidths.ParentKey);
public static IEnumerable<SortingCriteria> sorting_criterion {
get {
yield return new SortingCriteria(time_created.id, false);
}
}
public static IEnumerable<GridColumnSettings> all {
get {
yield return security;
yield return symbol;
yield return time_created;
yield return last_change;
yield return user;
yield return account;
yield return exchange;
yield return time_in_force;
yield return order_type;
yield return sub_type;
yield return side;
yield return quantity;
yield return price;
yield return filled_quantity;
yield return avg_price;
yield return last_price;
yield return status;
yield return last_message;
yield return security_key;
yield return order_key;
yield return parent_key;
yield return attached_target_order_key;
}
}
private static HashSet<GridColumnSettings> _mini_mode_columns_to_hide = new HashSet<GridColumnSettings> {
time_created, exchange, sub_type, quantity, price, avg_price, last_price, status, last_message, security_key, order_key, parent_key, attached_target_order_key
};
public static IEnumerable<GridColumnSettings> mini {
get {
foreach (var col_setting in all) {
if (_mini_mode_columns_to_hide.Contains(col_setting)) {
yield return col_setting.with(is_visible: false);
} else {
yield return col_setting;
}
}
}
}
}
}
[ProtoContract]
public class FilterStates : IEquatable<FilterStates> {
[ProtoMember(1)]
public SecurityCriteria security_criteria;
[ProtoMember(2)]
public string order_key_regex;
[ProtoMember(3)]
public TimeFilterTuple time_created;
[ProtoMember(4)]
public string[] users;
[ProtoMember(5)]
public string[] accounts;
[ProtoMember(6)]
public Venue[] exchanges;
[ProtoMember(7)]
public api.orderman.TimeInForce[] tifs;
[ProtoMember(8)]
public api.orderman.CustomOrderDefinition.CustomOneofCase[] order_types;
[ProtoMember(9)]
public Side[] sides;
[ProtoMember(10)]
public UIntMinMaxState qty;
[ProtoMember(11)]
public DoubleMinMaxState price;
[ProtoMember(12)]
public UIntMinMaxState qty_filled;
[ProtoMember(13)]
public DoubleMinMaxState avg_price;
[ProtoMember(14)]
public DoubleMinMaxState last_price;
[ProtoMember(15)]
public api.orderman.OrderStatus[] statuses;
[ProtoMember(16)]
public string exchange_message_regex;
[ProtoMember(17)]
public TimeFilterTuple last_change;
//[ProtoMember(18)]
//public string security_regex;
[ProtoMember(19)]
public api.orderman.OrderSubType[] order_sub_types;
[ProtoMember(20)]
public string[] symbols;
[ProtoMember(21)]
public string parent_key_regex;
[ProtoMember(22)]
public string attached_target_order_key_regex;
public bool Equals(FilterStates other) =>
other != null &&
security_criteria.safe_equals(other.security_criteria) &&
order_key_regex == other.order_key_regex &&
parent_key_regex == other.parent_key_regex &&
attached_target_order_key_regex == other.attached_target_order_key_regex &&
time_created.Equals(other.time_created) &&
EqualityComparer.safe_sequence_equals(users, other.users) &&
EqualityComparer.safe_sequence_equals(accounts, other.accounts) &&
EqualityComparer.safe_sequence_equals(exchanges, other.exchanges) &&
EqualityComparer.safe_sequence_equals(tifs, other.tifs) &&
EqualityComparer.safe_sequence_equals(order_types, other.order_types) &&
EqualityComparer.safe_sequence_equals(sides, other.sides) &&
qty.safe_equals(other.qty) &&
price.safe_equals(other.price) &&
qty_filled.safe_equals(other.qty_filled) &&
avg_price.safe_equals(other.avg_price) &&
last_price.safe_equals(other.last_price) &&
EqualityComparer.safe_sequence_equals(statuses, other.statuses) &&
exchange_message_regex == other.exchange_message_regex &&
last_change.Equals(other.last_change) &&
EqualityComparer.safe_sequence_equals(order_sub_types, other.order_sub_types) &&
EqualityComparer.safe_sequence_equals(symbols, other.symbols);
public override bool Equals(object obj) => Equals(obj as FilterStates);
public override int GetHashCode() =>
EqualityComparer.aggregate_hash(
security_criteria?.GetHashCode() ?? 0,
order_key_regex?.GetHashCode() ?? 0,
parent_key_regex?.GetHashCode() ?? 0,
attached_target_order_key_regex?.GetHashCode() ?? 0,
time_created.GetHashCode(),
EqualityComparer.safe_aggregate_hash(users),
EqualityComparer.safe_aggregate_hash(accounts),
EqualityComparer.safe_aggregate_hash(exchanges),
EqualityComparer.safe_aggregate_hash(tifs),
EqualityComparer.safe_aggregate_hash(order_types),
EqualityComparer.safe_aggregate_hash(sides),
qty?.GetHashCode() ?? 0,
price?.GetHashCode() ?? 0,
qty_filled?.GetHashCode() ?? 0,
avg_price?.GetHashCode() ?? 0,
last_price?.GetHashCode() ?? 0,
EqualityComparer.safe_aggregate_hash(statuses),
exchange_message_regex?.GetHashCode() ?? 0,
last_change.GetHashCode(),
EqualityComparer.safe_aggregate_hash(order_sub_types),
EqualityComparer.safe_aggregate_hash(symbols));
}
[ProtoContract]
public class OrderBookGridSettings : IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>, IEquatable<OrderBookGridSettings> {
[ProtoMember(1)]
public GridSettings general { get; set; }
[ProtoMember(2)]
List<OrderRecordTuplePredicateAnimations> _predicate_animations;
public OrderBookGridSettings() { }
public OrderBookGridSettings(GridSettings general = default, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, double right_panel_width = double.NaN) {
this.general = general;
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
if (predicate_animations != null)
_predicate_animations.AddRange(predicate_animations);
}
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>> IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>.predicate_animations => predicate_animations;
public OrderBookGridSettings with(GridSettings general) =>
new OrderBookGridSettings(general ?? this.general, predicate_animations);
public bool Equals(OrderBookGridSettings other) =>
other != null &&
EqualityComparer.null_check_equals(general, other.general) &&
EqualityComparer.safe_sequence_equals(predicate_animations, other.predicate_animations);
public override bool Equals(object obj) => Equals(obj as OrderBookGridSettings);
public override int GetHashCode() =>
EqualityComparer.aggregate_hash(
EqualityComparer.safe_get_hash_code(general),
EqualityComparer.safe_aggregate_hash(predicate_animations));
}
[ProtoContract]
public class OrderBookFillsGridSettings {
[ProtoMember(1)]
public GridSettings general { get; set; }
[ProtoMember(2)]
public FillsWindowFactory.FilterStates filters { get; set; }
[ProtoMember(3)]
public List<SortingCriteria> sorting_criterion { get; set; }
public FillsWindowFactory.StartupData to_startup_data() =>
new FillsWindowFactory.StartupData(null, sorting_criterion, filters, general);
}
}
}
}
@@ -0,0 +1,19 @@
using mbts.ui;
using ProtoBuf;
using System.Collections.Generic;
using GridSettings = mbts.ui.settings.GridSettings;
namespace bts.shell.orderbook {
[ProtoContract]
class OrderBookFillsGridSettings {
[ProtoMember(1)]
public GridSettings general { get; set; }
[ProtoMember(2)]
public FillsWindowFactory.FilterStates filters { get; set; }
[ProtoMember(3)]
public List<SortingCriteria> sorting_criterion { get; set; }
public FillsWindowFactory.StartupData to_startup_data() =>
new FillsWindowFactory.StartupData(null, sorting_criterion, filters, general);
}
}
@@ -0,0 +1,109 @@
using bts.api;
using bts.api.orderman;
using bts.utils;
using mbts;
using mbts.spark;
using mbts.spark.filters;
using mbts.ui;
using ProtoBuf;
using System;
namespace bts.shell.orderbook {
[ProtoContract]
class FilterStates : IEquatable<FilterStates> {
[ProtoMember(1)]
public SecurityCriteria security_criteria;
[ProtoMember(2)]
public string order_key_regex;
[ProtoMember(3)]
public TimeFilterTuple time_created;
[ProtoMember(4)]
public string[] users;
[ProtoMember(5)]
public string[] accounts;
[ProtoMember(6)]
public Venue[] exchanges;
[ProtoMember(7)]
public TimeInForce[] tifs;
[ProtoMember(8)]
public CustomOrderDefinition.CustomOneofCase[] order_types;
[ProtoMember(9)]
public Side[] sides;
[ProtoMember(10)]
public UIntMinMaxState qty;
[ProtoMember(11)]
public DoubleMinMaxState price;
[ProtoMember(12)]
public UIntMinMaxState qty_filled;
[ProtoMember(13)]
public DoubleMinMaxState avg_price;
[ProtoMember(14)]
public DoubleMinMaxState last_price;
[ProtoMember(15)]
public OrderStatus[] statuses;
[ProtoMember(16)]
public string exchange_message_regex;
[ProtoMember(17)]
public TimeFilterTuple last_change;
//[ProtoMember(18)]
//public string security_regex;
[ProtoMember(19)]
public api.orderman.OrderSubType[] order_sub_types;
[ProtoMember(20)]
public string[] symbols;
[ProtoMember(21)]
public string parent_key_regex;
[ProtoMember(22)]
public string attached_target_order_key_regex;
public bool Equals(FilterStates other) =>
other != null &&
security_criteria.safe_equals(other.security_criteria) &&
order_key_regex == other.order_key_regex &&
parent_key_regex == other.parent_key_regex &&
attached_target_order_key_regex == other.attached_target_order_key_regex &&
time_created.Equals(other.time_created) &&
EqualityComparer.safe_sequence_equals(users, other.users) &&
EqualityComparer.safe_sequence_equals(accounts, other.accounts) &&
EqualityComparer.safe_sequence_equals(exchanges, other.exchanges) &&
EqualityComparer.safe_sequence_equals(tifs, other.tifs) &&
EqualityComparer.safe_sequence_equals(order_types, other.order_types) &&
EqualityComparer.safe_sequence_equals(sides, other.sides) &&
qty.safe_equals(other.qty) &&
price.safe_equals(other.price) &&
qty_filled.safe_equals(other.qty_filled) &&
avg_price.safe_equals(other.avg_price) &&
last_price.safe_equals(other.last_price) &&
EqualityComparer.safe_sequence_equals(statuses, other.statuses) &&
exchange_message_regex == other.exchange_message_regex &&
last_change.Equals(other.last_change) &&
EqualityComparer.safe_sequence_equals(order_sub_types, other.order_sub_types) &&
EqualityComparer.safe_sequence_equals(symbols, other.symbols);
public override bool Equals(object obj) => Equals(obj as FilterStates);
public override int GetHashCode() =>
EqualityComparer.aggregate_hash(
security_criteria?.GetHashCode() ?? 0,
order_key_regex?.GetHashCode() ?? 0,
parent_key_regex?.GetHashCode() ?? 0,
attached_target_order_key_regex?.GetHashCode() ?? 0,
time_created.GetHashCode(),
EqualityComparer.safe_aggregate_hash(users),
EqualityComparer.safe_aggregate_hash(accounts),
EqualityComparer.safe_aggregate_hash(exchanges),
EqualityComparer.safe_aggregate_hash(tifs),
EqualityComparer.safe_aggregate_hash(order_types),
EqualityComparer.safe_aggregate_hash(sides),
qty?.GetHashCode() ?? 0,
price?.GetHashCode() ?? 0,
qty_filled?.GetHashCode() ?? 0,
avg_price?.GetHashCode() ?? 0,
last_price?.GetHashCode() ?? 0,
EqualityComparer.safe_aggregate_hash(statuses),
exchange_message_regex?.GetHashCode() ?? 0,
last_change.GetHashCode(),
EqualityComparer.safe_aggregate_hash(order_sub_types),
EqualityComparer.safe_aggregate_hash(symbols));
}
}
@@ -0,0 +1,44 @@
using bts.api.orderman;
using bts.utils;
using mbts;
using mbts.spark;
using mbts.ui;
using ProtoBuf;
using System;
using System.Collections.Generic;
using GridSettings = mbts.ui.settings.GridSettings;
namespace bts.shell.orderbook {
[ProtoContract]
class OrderBookGridSettings : IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>, IEquatable<OrderBookGridSettings> {
[ProtoMember(1)]
public GridSettings general { get; set; }
[ProtoMember(2)]
List<OrderRecordTuplePredicateAnimations> _predicate_animations;
public OrderBookGridSettings() { }
public OrderBookGridSettings(GridSettings general = default, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, double right_panel_width = double.NaN) {
this.general = general;
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
if (predicate_animations != null)
_predicate_animations.AddRange(predicate_animations);
}
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>> IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>.predicate_animations => predicate_animations;
public OrderBookGridSettings with(GridSettings general) =>
new OrderBookGridSettings(general ?? this.general, predicate_animations);
public bool Equals(OrderBookGridSettings other) =>
other != null &&
EqualityComparer.null_check_equals(general, other.general) &&
EqualityComparer.safe_sequence_equals(predicate_animations, other.predicate_animations);
public override bool Equals(object obj) => Equals(obj as OrderBookGridSettings);
public override int GetHashCode() =>
EqualityComparer.aggregate_hash(
EqualityComparer.safe_get_hash_code(general),
EqualityComparer.safe_aggregate_hash(predicate_animations));
}
}
@@ -0,0 +1,124 @@
using mbts;
using ProtoBuf;
using System;
using System.ComponentModel;
namespace bts.shell.orderbook {
[ProtoContract]
class OrderBookRightPanelSettings : IEquatable<OrderBookRightPanelSettings> {
public OrderBookRightPanelSettings() {
mode = Defaults.mode;
stack = new StackSettings();
tab = Defaults.tab;
show = Defaults.show;
width = Defaults.width;
}
public enum ViewMode {
[Description("Stack Mode")]
Stack = 1,
[Description("Tab Mode")]
Tab = 1 << 1,
}
public enum Components {
None = 0,
Params = 1,
Ladder = 1 << 1,
Fills = 1 << 2
}
// show
[ProtoMember(1)]
[DefaultValue(Defaults.show)]
public bool show { get; set; }
// width
[ProtoMember(2)]
[DefaultValue(Defaults.width)]
public double width { get; set; }
// view mode
[ProtoMember(3)]
[DefaultValue(Defaults.mode)]
public ViewMode mode { get; set; }
// stack
[ProtoMember(4)]
public StackSettings stack { get; set; }
// tab
[ProtoMember(5)]
[DefaultValue(Defaults.tab)]
public Components tab { get; set; }
public bool Equals(OrderBookRightPanelSettings other) =>
other != null &&
show == other.show &&
width == other.width &&
mode == other.mode &&
tab == other.tab &&
stack.safe_equals(other.stack);
[ProtoContract]
public class StackSettings : IEquatable<StackSettings> {
// show order params
[ProtoMember(1)]
[DefaultValue(Defaults.show_order_params)]
public bool show_order_params { get; set; }
// order params height
[ProtoMember(2)]
[DefaultValue(Defaults.order_params_height)]
public double order_params_height { get; set; }
// show ladder
[ProtoMember(3)]
[DefaultValue(Defaults.show_fills)]
public bool show_ladder { get; set; }
// ladder height
[ProtoMember(4)]
[DefaultValue(Defaults.ladder_height)]
public double ladder_height { get; set; }
// show fills
[ProtoMember(5)]
[DefaultValue(Defaults.show_fills)]
public bool show_fills { get; set; }
// fills height
[ProtoMember(6)]
[DefaultValue(Defaults.fills_height)]
public double fills_height { get; set; }
// fills grid
[ProtoMember(7)]
public OrderBookFillsGridSettings fills_grid { get; set; }
public StackSettings() {
show_order_params = Defaults.show_order_params;
order_params_height = Defaults.order_params_height;
show_fills = Defaults.show_fills;
fills_height = Defaults.fills_height;
show_ladder = Defaults.show_ladder;
ladder_height = Defaults.ladder_height;
}
public bool Equals(StackSettings other) =>
other != null &&
show_ladder == other.show_ladder &&
show_order_params == other.show_order_params &&
show_fills == other.show_fills;
static class Defaults {
public const bool
show_order_params = true,
show_ladder = true,
show_fills = true;
public const double
right_panel_width = 400,
order_params_height = 250,
fills_height = 300,
ladder_height = 350;
}
}
static class Defaults {
public const ViewMode mode = ViewMode.Tab;
public const Components tab = Components.Params;
public const bool show = true;
public const double width = 400;
}
}
}
@@ -0,0 +1,197 @@
using bts.api.orderman;
using mbts;
using mbts.ui;
using mbts.ui.controls;
using mbts.ui.settings;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
using GridSettings = mbts.ui.settings.GridSettings;
namespace bts.shell.orderbook {
[ProtoContract]
class OrderBookStartupData {
const bool
_default_show_right_panel = true,
_default_show_order_params = true;
const double
_default_right_panel_width = 400,
_default_order_params_height = 250,
_default_fills_height = 300,
_default_ladder_height = 350;
[ProtoMember(16)]
OrderBookRightPanelSettings _right_panel;
// ALREADY USED TAGS
// [ProtoMember(5)]
// public readonly List<SortingCriteria> sort_criteria;
public OrderBookRightPanelSettings right_panel => _right_panel ?? (_right_panel = new OrderBookRightPanelSettings());
/// TODO: remove properties below, and redirect callers to <see cref="right_panel"/>
// right panel (host)
public bool show_right_panel { get => right_panel.show; set => right_panel.show = value; }
public double right_panel_width { get; set; }
// order params
public bool show_order_params { get => right_panel.stack.show_order_params; set => right_panel.stack.show_order_params = value; }
public double order_params_height { get; set; }
// ladder
public bool show_ladder { get; set; }
public double ladder_height { get => right_panel.stack.ladder_height; set => right_panel.stack.ladder_height = value; }
// fills
public bool show_fills { get => right_panel.stack.show_fills; set => right_panel.stack.show_fills = value; }
public double fills_height { get => right_panel.stack.fills_height; set => right_panel.stack.fills_height = value; }
// filters
[ProtoMember(10)]
public FilterStates filters;
// grid
[ProtoMember(15)]
[Obsolete]
public GridSettings grid;
// fills settings
[ProtoMember(26)]
public OrderBookFillsGridSettings fills_settings { get; set; }
// predicate animations
[ProtoMember(20)]
[Obsolete]
List<OrderRecordTuplePredicateAnimations> _predicate_animations;
// use defaults
[ProtoMember(25)]
public bool use_defaults;
public OrderBookStartupData() {
show_right_panel = _default_show_right_panel;
show_order_params = _default_show_order_params;
right_panel_width = _default_right_panel_width;
order_params_height = _default_order_params_height;
fills_height = _default_fills_height;
ladder_height = _default_ladder_height;
}
public OrderBookStartupData(FilterStates filters, GridSettings grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, bool use_defaults = false) {
this.filters = filters;
this.use_defaults = use_defaults;
this.show_right_panel = show_right_panel;
this.right_panel_width = right_panel_width;
this.fills_height = fills_height;
this.show_fills = show_fills;
#pragma warning disable CS0612 // Type or member is obsolete
this.grid = grid;
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
if (predicate_animations != null)
_predicate_animations.AddRange(predicate_animations);
#pragma warning restore CS0612 // Type or member is obsolete
}
#pragma warning disable CS0612 // Type or member is obsolete
[Obsolete]
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
public OrderBookGridSettings grid_settings_wrapper() => use_defaults ? null : new OrderBookGridSettings(grid, predicate_animations);
#pragma warning restore CS0612 // Type or member is obsolete
public static OrderBookStartupData Default =>
new OrderBookStartupData(
new FilterStates { statuses = new[] { OrderStatus.Working } },
_default_general_grid,
_default_show_right_panel,
_default_right_panel_width,
_default_fills_height,
use_defaults: true) {
show_order_params = _default_show_order_params,
order_params_height = _default_order_params_height,
fills_settings = DefaultFillsGrid
};
public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid);
public static OrderBookFillsGridSettings DefaultFillsGrid {
get {
var default_fills = FillsWindowFactory.StartupData.Default();
var rv = new OrderBookFillsGridSettings {
sorting_criterion = default_fills.sorting_criterion.ToList(),
filters = default_fills.filters,
general = FillsWindowFactory.StartupData.MiniGridSettings
};
return rv;
}
}
static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.sorting_criterion);
public static GridSettings default_mini_grid => GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion);
static class DefaultColumns {
public static GridColumnSettings security => new GridColumnSettings(Columns.Security.ToString(), DIYGrid.DefaultColumnHeaders.Security, width: DIYGrid.DefaultColumnWidths.Security);
public static GridColumnSettings symbol => new GridColumnSettings(Columns.Symbol.ToString(), DIYGrid.DefaultColumnHeaders.Symbol, width: DIYGrid.DefaultColumnWidths.Symbol);
public static GridColumnSettings time_created => new GridColumnSettings(Columns.Time.ToString(), "Time", width: DIYGrid.DefaultColumnWidths.Time);
public static GridColumnSettings last_change => new GridColumnSettings(Columns.LastChange.ToString(), "Last Change", width: DIYGrid.DefaultColumnWidths.Time);
public static GridColumnSettings user => new GridColumnSettings(Columns.User.ToString(), DIYGrid.DefaultColumnHeaders.User, width: DIYGrid.DefaultColumnWidths.User);
public static GridColumnSettings account => new GridColumnSettings(Columns.Account.ToString(), DIYGrid.DefaultColumnHeaders.Account, width: DIYGrid.DefaultColumnWidths.Account);
public static GridColumnSettings exchange => new GridColumnSettings(Columns.Exchange.ToString(), DIYGrid.DefaultColumnHeaders.Exchange, width: DIYGrid.DefaultColumnWidths.Exchange);
public static GridColumnSettings time_in_force => new GridColumnSettings(Columns.TimeInForce.ToString(), DIYGrid.DefaultColumnHeaders.TimeInForce, width: DIYGrid.DefaultColumnWidths.TimeInForce);
public static GridColumnSettings order_type => new GridColumnSettings(Columns.OrderType.ToString(), DIYGrid.DefaultColumnHeaders.OrderType, width: DIYGrid.DefaultColumnWidths.OrderType);
public static GridColumnSettings sub_type => new GridColumnSettings(Columns.SubType.ToString(), "Sub Type", width: 80);
public static GridColumnSettings side => new GridColumnSettings(Columns.Side.ToString(), "B/S", width: DIYGrid.DefaultColumnWidths.Side);
public static GridColumnSettings quantity => new GridColumnSettings(Columns.Size.ToString(), "Qty", width: DIYGrid.DefaultColumnWidths.Size, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings price => new GridColumnSettings(Columns.Price.ToString(), DIYGrid.DefaultColumnHeaders.Price, width: DIYGrid.DefaultColumnWidths.Price, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings filled_quantity => new GridColumnSettings(Columns.Filled.ToString(), "Filled Qty", width: DIYGrid.DefaultColumnWidths.Filled, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings avg_price => new GridColumnSettings(Columns.AvgFilled.ToString(), "Avg Filled", width: DIYGrid.DefaultColumnWidths.AveragePrice, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80);
public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage);
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey);
public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey);
public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey);
public static GridColumnSettings attached_target_order_key => new GridColumnSettings(Columns.AttachedTargetOrderKey.ToString(), DIYGrid.DefaultColumnHeaders.AttachedTargetOrderKey, width: DIYGrid.DefaultColumnWidths.ParentKey);
public static IEnumerable<SortingCriteria> sorting_criterion {
get {
yield return new SortingCriteria(time_created.id, false);
}
}
public static IEnumerable<GridColumnSettings> all {
get {
yield return security;
yield return symbol;
yield return time_created;
yield return last_change;
yield return user;
yield return account;
yield return exchange;
yield return time_in_force;
yield return order_type;
yield return sub_type;
yield return side;
yield return quantity;
yield return price;
yield return filled_quantity;
yield return avg_price;
yield return last_price;
yield return status;
yield return last_message;
yield return security_key;
yield return order_key;
yield return parent_key;
yield return attached_target_order_key;
}
}
private static HashSet<GridColumnSettings> _mini_mode_columns_to_hide = new HashSet<GridColumnSettings> {
time_created, exchange, sub_type, quantity, price, avg_price, last_price, status, last_message, security_key, order_key, parent_key, attached_target_order_key
};
public static IEnumerable<GridColumnSettings> mini {
get {
foreach (var col_setting in all) {
if (_mini_mode_columns_to_hide.Contains(col_setting)) {
yield return col_setting.with(is_visible: false);
} else {
yield return col_setting;
}
}
}
}
}
}
}
@@ -0,0 +1,280 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:ie="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ob="clr-namespace:bts.shell.orderbook"
xmlns:u="clr-namespace:mbts.ui"
xmlns:c="clr-namespace:mbts.ui.controls"
>
<!--Control colors.-->
<Color x:Key="WindowColor">#FFE8EDF9</Color>
<Color x:Key="DisabledControlLightColor">#FFE8EDF9</Color>
<Color x:Key="DisabledControlDarkColor">#FFC5CBF9</Color>
<Color x:Key="DisabledForegroundColor">#FF888888</Color>
<Color x:Key="SelectedBackgroundColor">#FFC5CBF9</Color>
<Color x:Key="SelectedUnfocusedColor">#FFDDDDDD</Color>
<Color x:Key="ControlLightColor">White</Color>
<Color x:Key="ControlMediumColor">#FFCCCCCC</Color>
<Color x:Key="ControlDarkColor">#FFAAAAAA</Color>
<Color x:Key="ControlMouseOverColor">#200080FF</Color>
<Color x:Key="ControlPressedColor">#800080FF</Color>
<!--Border colors-->
<Color x:Key="BorderMediumColor">#FF888888</Color>
<Color x:Key="PressedBorderLightColor">#FF888888</Color>
<Color x:Key="MouseOverBorderMediumColor">#90006CD9</Color>
<Color x:Key="DisabledBorderLightColor">#FFAAAAAA</Color>
<Color x:Key="DefaultBorderBrushDarkColor">Black</Color>
<!--Control-specific resources.-->
<Color x:Key="HeaderTopColor">#FFC5CBF9</Color>
<Color x:Key="DatagridCurrentCellBorderColor">Black</Color>
<Color x:Key="SliderTrackDarkColor">#FFC5CBF9</Color>
<Color x:Key="NavButtonFrameColor">#FF3843C4</Color>
<LinearGradientBrush x:Key="MenuPopupBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource ControlLightColor}" Offset="0"/>
<GradientStop Color="{DynamicResource ControlMediumColor}" Offset="0.5"/>
<GradientStop Color="{DynamicResource ControlLightColor}" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1,0"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ButtonBase}">
<Border
x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMouseOverColor}"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlDarkColor}"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked"/>
<VisualState x:Name="Indeterminate"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}" BasedOn="{StaticResource ToolBarButtonBaseStyle}" TargetType="{x:Type ToggleButton}"/>
<Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Cursor" Value="SizeAll"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="Transparent" SnapsToDevicePixels="True">
<Rectangle Margin="0,2">
<Rectangle.Fill>
<DrawingBrush
Viewport="0,0,4,4"
ViewportUnits="Absolute"
Viewbox="0,0,8,8"
ViewboxUnits="Absolute"
TileMode="Tile"
>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#AAA" Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z"/>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ToolBarOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
x:Name="Border"
BorderBrush="Transparent"
Background="Transparent"
BorderThickness="1,0"
SnapsToDevicePixels="True"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" BeginTime="0" Duration="0" To="{StaticResource ControlMouseOverColor}"/>
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" BeginTime="0" Duration="0" To="{StaticResource MouseOverBorderMediumColor}"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" BeginTime="0" Duration="0" To="{StaticResource DisabledBorderLightColor}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid>
<Path
x:Name="Arrow"
Fill="Black"
VerticalAlignment="Bottom"
Margin="2,3"
Data="M -0.5 3 L 5.5 3 L 2.5 6 Z"/>
<ContentPresenter/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="IsChecked" Value="False"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
<Setter Property="ToolBarTray.IsLocked" Value="True"/>
<Setter Property="Background" Value="LightGray"/>
<Setter Property="BorderBrush" Value="DarkGray"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolBar}">
<Border
x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<DockPanel>
<ToggleButton
DockPanel.Dock="Right"
IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ToolBarOverflowButtonStyle}"
>
<Popup
x:Name="OverflowPopup"
AllowsTransparency="True"
Placement="Bottom"
StaysOpen="False"
Focusable="False"
PopupAnimation="Slide"
IsOpen="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
>
<Border
x:Name="DropDownBorder"
BorderThickness="1"
BorderBrush="{u:BTSColor UI.Button.normal_border}"
Background="{StaticResource ControlBackground}"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeave">
<ie:ChangePropertyAction TargetName="OverflowPopup" PropertyName="IsOpen" Value="False"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel Orientation="Vertical">
<MenuItem
c:RadioButtonGroupManager.Manager="{Binding Path='(c:RadioButtonGroupManager.Manager)', RelativeSource={RelativeSource AncestorType=ToolBar}}"
HorizontalAlignment="Stretch"
IsCheckable="True"
DataContext="{u:Enum Tab, Type={u:Nested ob:OrderBookRightPanelSettings.ViewMode}}"
Header="{Binding}"
HeaderTemplate="{StaticResource EnumDescriptionTemplate}"
/>
<MenuItem
c:RadioButtonGroupManager.Manager="{Binding Path='(c:RadioButtonGroupManager.Manager)', RelativeSource={RelativeSource AncestorType=ToolBar}}"
HorizontalAlignment="Stretch"
IsCheckable="True"
DataContext="{u:Enum Stack, Type={u:Nested ob:OrderBookRightPanelSettings.ViewMode}}"
Header="{Binding}"
HeaderTemplate="{StaticResource EnumDescriptionTemplate}"
/>
</StackPanel>
</Border>
</Popup>
</ToggleButton>
<Thumb x:Name="ToolBarThumb" Style="{StaticResource ToolBarThumbStyle}" Width="10"/>
<ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="True"/>
</DockPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsOverflowOpen" Value="True">
<Setter TargetName="ToolBarThumb" Property="IsEnabled" Value="False"/>
</Trigger>
<Trigger Property="ToolBarTray.IsLocked" Value="True">
<Setter TargetName="ToolBarThumb" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type ToolBarTray}" TargetType="{x:Type ToolBarTray}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="{DynamicResource WindowColor}" Offset="1.0"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -11,6 +11,7 @@
xmlns:cv="clr-namespace:mbts.ui.converters"
xmlns:usp="clr-namespace:mbts.ui.spark"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:ob="clr-namespace:bts.shell.orderbook"
Grid.Row="0"
FocusManager.IsFocusScope="True"
Background="{StaticResource CommonBackground}"
@@ -20,6 +21,7 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/FilterTemplates.xaml"/>
<ResourceDictionary Source="/Modules/Trading/OrderBook/View/OrderParamsPanel.xaml"/>
<ResourceDictionary Source="/Modules/Trading/OrderBook/View/OrderBookToolBar.xaml"/>
</ResourceDictionary.MergedDictionaries>
<sys:Double x:Key="GridSplitterWidth">5</sys:Double>
<SolidColorBrush x:Key="AlgoAttachmentBackground" Color="#55009500"/>
@@ -34,6 +36,9 @@
<cv:KeyValue Key="{u:Enum Buy, Type=api:Side}" Value="{x:Static bid_brush, MemberType={u:Nested u:BTSColors.MarketData}}"/>
<cv:KeyValue Key="{u:Enum Sell, Type=api:Side}" Value="{x:Static ask_brush, MemberType={u:Nested u:BTSColors.MarketData}}"/>
</cv:ValueMap>
<c:RadioButtonGroupManager x:Key="RightPanelViewModeManager"/>
<Style TargetType="GridSplitter">
<Setter Property="IsTabStop" Value="False"/>
<Style.Triggers>
@@ -354,7 +359,19 @@
<RowDefinition Height="5" MaxHeight="5"/>
<RowDefinition Height="{Binding fills_height, Converter={StaticResource GridLengthStarConverter}, Mode=TwoWay}"/>
</Grid.RowDefinitions>
<Menu Grid.Column="1" HorizontalAlignment="Stretch" Height="26" Background="LightGray" BorderBrush="DarkGray" BorderThickness="1" ItemContainerStyle="{StaticResource RightPanel.MenuItem}">
<ToolBar
x:Name="right_panel_tool_bar"
Grid.Column="1"
HorizontalAlignment="Stretch"
Height="26"
Background="LightGray"
BorderBrush="DarkGray"
BorderThickness="1"
ItemContainerStyle="{StaticResource RightPanel.MenuItem}"
>
<c:RadioButtonGroupManager.Manager>
<c:RadioButtonGroupManager SelectedItem="{Binding DataContext.right_panel_view_mode, Source={u:DirectReference right_panel_tool_bar}, Mode=TwoWay}"/>
</c:RadioButtonGroupManager.Manager>
<MenuItem Header="Params" IsChecked="{Binding show_order_params}" Icon="{x:Static u:Icons.ModifyOrder}" ToolTip="Show Order/Algo Parameters for Selected Orders">
<MenuItem.Resources>
<Thickness x:Key="IconPadding" Left="2" Top="3" Bottom="2"/>
@@ -370,7 +387,7 @@
<Thickness x:Key="IconPadding" Left="2" Top="4.5" Bottom="4.5"/>
</MenuItem.Resources>
</MenuItem>
</Menu>
</ToolBar>
<StackPanel Grid.Row="1" Grid.Column="1" u:StateManager.VisualState="{Binding current_row, Converter={x:Static sp:OrderBookView.OrderDescriptionVisualStateConverter}}" Orientation="Vertical">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.OrderDescription}}">
@@ -438,7 +455,7 @@
AlgoRoots="{Binding algo_vm.algo_roots}"
SelectedAlgoRoot="{Binding algo_vm.algo_root}"
AlgoParamRows="{Binding param_rows}"
IsReadOnly="{Binding can_user_modify_selected_orders, Converter={StaticResource NotConverter}}"
IsReadOnly="{Binding DataContext.can_user_modify_selected_orders, ElementName=Root, Converter={StaticResource NotConverter}}"
>
<usp:OrderParamsPanel.CommandBindings>
<CommandBinding Command="{x:Static usp:OrderParamsPanel.SetPriceCommand}" Executed="{x:Static usp:OrderParamsPanel.SetPriceExecuted}"/>
@@ -36,7 +36,7 @@ namespace bts.shell {
public int priority => 20;
public IEnumerable<SparkCommand> actions => new [] {
SparkCommands.ShowOrders.complete(() => OrderBookWindowFactory.OrderBookStartupData.Default),
SparkCommands.ShowOrders.complete(() => bts.shell.orderbook.OrderBookStartupData.Default),
SparkCommands.ShowFills(null).complete(() => new FillsWindowFactory.StartupData()),
SparkCommands.ShowPAndL.complete(() => new PAndLWindowFactory.PAndLStartupData()),
SparkCommands.PickLadder,
@@ -63,6 +63,7 @@ namespace mbts.spark {
bool is_dirty { get; }
AlgoParamPermissions permissions { get; set; }
void revert();
void mark_committed();
}
interface IAlgoParamVM<T> : IAlgoParamVM {
@@ -934,6 +934,7 @@ namespace mbts.spark {
event Action<bool> IAlgoParamVM.is_dirty_changed { add { } remove { } }
void IAlgoParamVM.revert() { }
void IAlgoParamVM.mark_committed() { }
#endregion
public IObservable<IAlgoVM> subscribe_selected_algo() {
@@ -1042,7 +1043,7 @@ namespace mbts.spark {
});
}
internal void mark_committed() {
public void mark_committed() {
_committed_value = _value;
if (is_dirty)
_toggle_is_dirty();
+1 -1
View File
@@ -23,7 +23,7 @@ namespace bts.spark
SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowPickMultiple, ShowTimeAndSales);
// Trading
public static PartialCommand<OrderBookWindowFactory.OrderBookStartupData> ShowOrders =>
public static PartialCommand<bts.shell.orderbook.OrderBookStartupData> ShowOrders =>
SparkCommand.create("Order Book", Icons.Book, SparkTags.ShowOrderBookTag);
// Fills
+1 -1
View File
@@ -59,7 +59,7 @@ namespace mbts.spark
public static ITag<IReadOnlyList<SecurityMD>> ShowLaddersTag { get; } = new SparkTag<IReadOnlyList<SecurityMD>>(nameof(ShowLaddersTag));
public static ITag<IObservable<SecurityMD>> ShowLinkedLadder { get; } = new SparkTag<IObservable<SecurityMD>>("Linked Ladder");
public static ITag<SecurityCriteria> ShowMarketViewTag { get; } = new SparkTag<SecurityCriteria>("Show MarketView");
public static ITag<OrderBookWindowFactory.OrderBookStartupData> ShowOrderBookTag { get; } = new SparkTag<OrderBookWindowFactory.OrderBookStartupData>(nameof(ShowOrderBookTag));
public static ITag<bts.shell.orderbook.OrderBookStartupData> ShowOrderBookTag { get; } = new SparkTag<bts.shell.orderbook.OrderBookStartupData>(nameof(ShowOrderBookTag));
public static ITag<PAndLWindowFactory.PAndLStartupData> ShowPAndLTag { get; } = new SparkTag<PAndLWindowFactory.PAndLStartupData>(nameof(ShowPAndLTag));
public static ITag<(SecurityImmutable security, ExecutionStrategyImmutable strategy)> ShowSyntheticCloneTag { get; } = new SparkTag<(SecurityImmutable security, ExecutionStrategyImmutable strategy)>(nameof(ShowSyntheticCloneTag));
public static ITag<SecurityCriteria> ShowSyntheticCreateTag { get; } = new SparkTag<SecurityCriteria>(nameof(ShowSyntheticCreateTag));
@@ -20,7 +20,7 @@ namespace mbts.spark {
_fills_grid = bts.shell.FillsWindowFactory.StartupData.DefaultGridSettings,
_time_and_sales_grid = bts.shell.TimeAndSalesWindowFactory.StartupData.DefaultGridSettings,
_synthetic_management_grid = bts.shell.SyntheticManagementWindowFactory.StartupData.DefaultGridSettings,
_order_book_grid = bts.shell.OrderBookWindowFactory.OrderBookStartupData.DefaultGrid
_order_book_grid = bts.shell.orderbook.OrderBookStartupData.DefaultGrid
};
[ProtoMember(1)]
@@ -40,7 +40,7 @@ namespace mbts.spark {
[ProtoMember(9)]
GridSettings _pnl_grid;
[ProtoMember(10)]
bts.shell.OrderBookWindowFactory.OrderBookGridSettings _order_book_grid;
bts.shell.orderbook.OrderBookGridSettings _order_book_grid;
public UserSettings() { }
@@ -51,7 +51,7 @@ namespace mbts.spark {
public GridSettings fills_grid => _fills_grid ?? (_fills_grid = bts.shell.FillsWindowFactory.StartupData.DefaultGridSettings);
public GridSettings synthetic_management_grid => _synthetic_management_grid ?? (_synthetic_management_grid = bts.shell.SyntheticManagementWindowFactory.StartupData.DefaultGridSettings);
public GridSettings pnl_grid => _pnl_grid ?? (_pnl_grid = bts.shell.PAndLWindowFactory.PAndLStartupData.DefaultGridSettings);
public bts.shell.OrderBookWindowFactory.OrderBookGridSettings order_book_grid => _order_book_grid ?? (_order_book_grid = bts.shell.OrderBookWindowFactory.OrderBookStartupData.Default.grid_settings_wrapper());
public bts.shell.orderbook.OrderBookGridSettings order_book_grid => _order_book_grid ?? (_order_book_grid = bts.shell.orderbook.OrderBookStartupData.Default.grid_settings_wrapper());
public UserSettings with(LadderSettings ladder = null,
NotificationSettings notification = null,
@@ -60,7 +60,7 @@ namespace mbts.spark {
GridSettings provided_fills_gridsettings = null,
GridSettings provided_synthetic_management_gridsettings = null,
GridSettings provided_pnl_gridsettings = null,
bts.shell.OrderBookWindowFactory.OrderBookGridSettings order_book_grid = null) =>
bts.shell.orderbook.OrderBookGridSettings order_book_grid = null) =>
new UserSettings {
_ladder = ladder ?? _ladder,
_notification = notification ?? _notification,
+9
View File
@@ -21,6 +21,9 @@ namespace bts {
return new OneOf<A, B, C>(as_c);
} else return new OneOf<A, B, C>();
}
public static T infer<T, A, B>(object value, Func<A, T> a, Func<B, T> b) =>
OneOf<A, B>.infer(value).Match(a, b);
}
public class OneOf<A, B> {
@@ -34,6 +37,12 @@ namespace bts {
public OneOf(A a) { _a = a; _tag = 0; }
public OneOf(B b) { _b = b; _tag = 1; }
public static OneOf<A, B> infer(object obj) {
if (obj is A a) return new OneOf<A, B>(a);
if (obj is B b) return new OneOf<A, B>(b);
return new OneOf<A, B>();
}
public void Match(Action<A> a, Action<B> b) {
switch (_tag) {
case 0: a(_a); break;
@@ -1,4 +1,11 @@
using System.Collections.Generic;
using bts;
using mbts.ui.utility;
using mbts.utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -11,11 +18,9 @@ namespace mbts.ui.controls {
public static readonly DependencyProperty GroupManagerMapProperty =
DependencyProperty.Register("GroupManagerMap", typeof(RadioButtonGroupManagerMap), typeof(RadioButtonGroupManagerMap),
new PropertyMetadata((d, e) => {
if (d is RadioButton tb) {
var k = GetGroupKey(tb);
if (e.OldValue is RadioButtonGroupManagerMap old_man) old_man._leave(tb, k);
if (e.NewValue is RadioButtonGroupManagerMap new_man) new_man._join(tb, k);
}
var k = GetGroupKey(d);
if (e.OldValue is RadioButtonGroupManagerMap old_man) old_man._leave(d, k);
if (e.NewValue is RadioButtonGroupManagerMap new_man) new_man._join(RadioButtonGroupManager.mk_member(d), k);
}));
public static RadioButtonGroupManagerMap GetGroupManagerMap(DependencyObject d) => d.GetValue(GroupManagerMapProperty) as RadioButtonGroupManagerMap;
@@ -29,9 +34,9 @@ namespace mbts.ui.controls {
new PropertyMetadata((d, e) => {
var man_map = GetGroupManagerMap(d);
if (man_map != null) {
var tb = (ToggleButton)d;
man_map._leave(tb, e.OldValue);
man_map._join(tb, e.NewValue);
var m = RadioButtonGroupManager.mk_member(d);
man_map._leave(m, e.OldValue);
man_map._join(m, e.NewValue);
}
}));
@@ -42,18 +47,21 @@ namespace mbts.ui.controls {
public bool TryGetManager(object group_key, out RadioButtonGroupManager result) =>
_managers.TryGetValue(group_key, out result);
public void join(ToggleButton tb, object group_key) =>
_join(tb, group_key);
public void join(RadioButtonGroupManager.Member member, object group_key) =>
_join(member, group_key);
void _join(ToggleButton tb, object group_key) {
void _join(RadioButtonGroupManager.Member member, object group_key) {
if (group_key == null) return;
_managers.GetOrAdd(group_key, _ => new RadioButtonGroupManager()).join(tb);
_managers.GetOrAdd(group_key, _ => new RadioButtonGroupManager()).join(member);
}
void _leave(ToggleButton tb, object group_key) {
void _leave(DependencyObject d, object group_key) => _leave(group_key, man => man.leave(d));
void _leave(RadioButtonGroupManager.Member member, object group_key) => _leave(group_key, man => man.leave(member));
void _leave(object group_key, Action<RadioButtonGroupManager> leave) {
if (group_key == null) return;
if (_managers.TryGetValue(group_key, out RadioButtonGroupManager man)) {
man.leave(tb);
leave(man);
if (man.is_empty)
_managers.Remove(group_key);
}
@@ -65,10 +73,8 @@ namespace mbts.ui.controls {
public static readonly DependencyProperty ManagerProperty =
DependencyProperty.RegisterAttached("Manager", typeof(RadioButtonGroupManager), typeof(RadioButtonGroupManager),
new PropertyMetadata((d, e) => {
if (d is ToggleButton tb) {
if (e.OldValue is RadioButtonGroupManager old_man) old_man.leave(tb);
if (e.NewValue is RadioButtonGroupManager new_man) new_man.join(tb);
}
if (e.OldValue is RadioButtonGroupManager old_man) old_man.leave(d);
if (e.NewValue is RadioButtonGroupManager new_man) new_man.join(mk_member(d));
}));
public static RadioButtonGroupManager GetManager(DependencyObject d) => d.GetValue(ManagerProperty) as RadioButtonGroupManager;
@@ -90,16 +96,27 @@ namespace mbts.ui.controls {
public static void RemoveValueChangedHandler(DependencyObject d, RoutedEventHandler handler) => (d as UIElement)?.RemoveHandler(ValueChangedEvent, handler);
#endregion
readonly List<ToggleButton> _members = new List<ToggleButton>();
readonly ObservableCollection<Member> _members = new ObservableCollection<Member>();
public RadioButtonGroupManager() {
ObservableAutoWrapper.connect_item_hooks(_members, m => {
m.el.DataContextChanged += _member_DataContextChanged;
return new CompositeDisposable(
m.subscribe().Subscribe(is_checked => {
if (is_checked)
_member_Checked(m, new RoutedEventArgs());
})) {
() => m.el.DataContextChanged -= _member_DataContextChanged
};
});
}
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(RadioButtonGroupManager),
new PropertyMetadata((d, e) => {
var group = (RadioButtonGroupManager)d;
foreach (var tb in group._members) {
tb.Checked -= group._member_Checked;
var val = group._get_member_value(tb);
tb.set_current_if_changed(ToggleButton.IsCheckedProperty, Equals(e.NewValue, val));
tb.Checked += group._member_Checked;
foreach (var m in group._members) {
var val = group._get_member_value(m);
m.IsChecked = Equals(e.NewValue, val);
}
}));
@@ -107,56 +124,117 @@ namespace mbts.ui.controls {
public bool is_empty => _members.Count == 0;
public void join(ToggleButton tb) {
if (!_members.Contains(tb)) {
_members.Add(tb);
tb.SetCurrentValue(ToggleButton.IsCheckedProperty, Equals(SelectedItem, _get_member_value(tb)));
tb.Checked += _member_Checked;
tb.DataContextChanged += _member_DataContextChanged;
AddValueChangedHandler(tb, _on_value_changed);
public static Member mk_member(DependencyObject element) {
return OneOf.infer<Member, ToggleButton, MenuItem>(element, toggle_button, menu_item);
// toggle button
Member toggle_button(ToggleButton tb) {
return new Member(tb, ToggleButton.IsCheckedProperty, subscribe);
IObservable<bool> subscribe() {
return Observable.Create<bool>(o => {
tb.Checked += on_checked;
tb.Unchecked += on_unchecked;
return Disposable.Create(dispose);
void on_checked(object sender, RoutedEventArgs e) => o.OnNext(true);
void on_unchecked(object sender, RoutedEventArgs e) => o.OnNext(false);
void dispose() {
tb.Checked -= on_checked;
tb.Unchecked -= on_unchecked;
}
});
}
}
// menu item
Member menu_item(MenuItem mi) {
return new Member(mi, MenuItem.IsCheckedProperty, subscribe);
IObservable<bool> subscribe() {
return Observable.Create<bool>(o => {
mi.Checked += on_checked;
mi.Unchecked += on_unchecked;
return Disposable.Create(dispose);
void on_checked(object sender, RoutedEventArgs e) => o.OnNext(true);
void on_unchecked(object sender, RoutedEventArgs e) => o.OnNext(false);
void dispose() {
mi.Checked -= on_checked;
mi.Unchecked -= on_unchecked;
}
});
}
}
}
public void join(Member m) {
if (m == null)
return;
if (!_members.Contains(m)) {
_members.Add(m);
m.IsChecked = Equals(SelectedItem, _get_member_value(m));
AddValueChangedHandler(m.el, _on_value_changed);
}
}
void _on_value_changed(object sender, RoutedEventArgs e) =>
_update_member_value((ToggleButton)sender);
_update_member_value((Member)sender);
public void leave(ToggleButton tb) {
if (_members.Remove(tb)) {
tb.Checked -= _member_Checked;
tb.DataContextChanged -= _member_DataContextChanged;
RemoveValueChangedHandler(tb, _on_value_changed);
if (Equals(SelectedItem, tb.DataContext))
public void leave(DependencyObject d) =>
leave(_members.FirstOrDefault(m => m.el == d));
public void leave(Member m) {
if (m == null)
return;
if (_members.Remove(m)) {
RemoveValueChangedHandler(m.el, _on_value_changed);
if (Equals(SelectedItem, m.el.DataContext))
SetCurrentValue(SelectedItemProperty, null);
}
}
static bool _is_checked((FrameworkElement el, DependencyProperty dp) member) =>
member.el.GetValue(member.dp) is bool b && b;
void _member_Checked(object sender, RoutedEventArgs e) {
var tb = (ToggleButton)sender;
if (tb.IsChecked ?? false)
SetCurrentValue(SelectedItemProperty, _get_member_value(tb));
var m = (Member)sender;
if (m.IsChecked)
SetCurrentValue(SelectedItemProperty, _get_member_value(m));
}
void _member_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) =>
_update_member_value((ToggleButton)sender);
_update_member_value((Member)sender);
void _update_member_value(ToggleButton tb) {
var val = RadioButtonGroupManager.GetValue(tb);
void _update_member_value(Member m) {
var val = GetValue(m.el);
if (!_is_value_valid(val)) {
val = tb.DataContext;
val = m.el.DataContext;
if (!_is_value_valid(val)) return;
}
if (tb.IsChecked ?? false)
if (m.IsChecked)
SetCurrentValue(SelectedItemProperty, val);
}
object _get_member_value(ToggleButton tb) {
var val = RadioButtonGroupManager.GetValue(tb);
object _get_member_value(Member m) {
var val = GetValue(m.el);
if (!_is_value_valid(val))
val = tb.DataContext;
val = m.el.DataContext;
return _is_value_valid(val) ? val : null;
}
bool _is_value_valid(object value) =>
value != null && !value.Equals(DependencyProperty.UnsetValue);
public class Member {
public readonly FrameworkElement el;
public readonly DependencyProperty dp;
public readonly Func<IObservable<bool>> subscribe;
public Member(FrameworkElement el, DependencyProperty dp, Func<IObservable<bool>> subscribe) {
this.el = el;
this.dp = dp;
this.subscribe = subscribe;
}
public bool IsChecked {
get => el.GetValue(dp) is bool b && b;
set => el.SetCurrentValue(dp, value);
}
}
}
}
+7
View File
@@ -1,15 +1,22 @@
0. This needs sim market data **not** to be merged with replay (or cert), so we can create our own markets.
1. Bring up a ladder, lets say in SIN1 (does not matter which security)
2. Create both sides of the market by entering 100 lot limit orders at 15.50 and 15.515
(if there are no markets use the M View and the ticket to enter)
3. Enter a 10 lot Cover (Child=Limit, Hedge=Limit) buy at 15.505, with hedge Ticks=3.
Verify that a limit order is sent at that price
4. Move the Cover to 15.510 and back and verify the child order moves accordingly.
5. Get a 1 lot fill in the Cover by crossing a 1 lot sell limit order with it.
Make sure a hedge is sent 3 ticks away from the fill.
6. Now from the OB change the Hedge Ticks for this order to 5.
7. Repeat Step 5 and verify the hedge is sent 5 ticks away now.
8. Repeat Step 5 for a negative value and make sure it works (some thing interesting will happen)
9. Enter another 10 lot Cover order. Repeat step 5. until it is completely filled. Make sure it
+28
View File
@@ -0,0 +1,28 @@
The goal of the join order is to watch the opposite-inside market and join when the market flips and
has at least threshold size. (flip is when the best offer becomes the best bid, or the market trades
away from you (the line moves up in the gui)
0. This needs sim market data **not** to be merged with replay (or cert), so we can create our own markets.
Also make sure you have limits to trade SI Future
1. Bring up a ladder, lets say in SIN1 (does not matter which security)
2. Create both sides of the market by entering 10 lot limit orders at 15.550 and 15.575
(if there are no markets use the M View and the ticket to enter)
3. Enter a 5 lot buy Join order with an abs threshold of 1 at 15.525. When the Join order is placed
it takes a snapshot of where the top of the book was. Since its a buy, it will wait for the top of the buy side
to advance to where the ask is AND for qty >= threshold
4. Verify that a limit order is sent at where the Join is.
5. Now move the ask market up a tick and the bid market to where the ask was (15.575). Verify that the Join
moved its Child limit order to 15.575 ie it joins the bid market.
6. Cancel all orders and put the market to where it was (step 2.)
7. Now an enter a Join order with threshold 15. Repeat step 5. except that the Join order will not join
since the top of the bid qty threshold of 15 is not met.
8. Increase the top of the bid qty by adding on1 limit order there at a time. When the qty
reaches 15 it should join.
+19 -14
View File
@@ -1,20 +1,25 @@
The goal of the top order is to not trade by yourself. Meaning that if your order is at the
top of the book with very few others, you cancel it =>
If the order is on the market (top of the book) AND the quantity on that bid price (net o yours) < threshold
then cancel the order else do nothing
- Open up a ladder for a liquid future
- Make sure you have limits to trade this future
- Select Top order from the menu
Label 1) Set top thresh to absolute 50, start with a bid at the best, 10 lot
0. This needs sim market data **not** to be merged with replay (or cert), so we can create our own markets.
Also make sure you have limits to trade SI Future
The goal of the top order is to not trade by yourself.
IF the order is on the market (current bid price) AND the quantity on that bid price is below top
thresh then cancel the order else do nothing
1. Bring up a ladder, lets say in SIN1 (does not matter which security)
2. Create both sides of the market by entering 10 lot limit orders at 15.550 and 15.575
(if there are no markets use the M View and the ticket to enter)
- Verify that orders immediately cancel if you put them in and inside market with less then the threshold
- Verify that orders cancel if they end up working at an inside market with less than threshold size
3. Enter a Buy top order with threshold of 15 right at the top of the book. This should immediately
cancel. Now do the same with a threshold < 10 and it should not cancel.
Goto Label l and test a sell
Now do this test again with "Enable Hedge" checked and hedge ticks set to 1, hedge type set to limit
3. Enter a Buy top order with threshold of 15 right at the top of the book. This should immediately
cancel. Now do the same with a threshold < 10 and it should not cancel.
This should modify the behavior such that the algorithm will send a limit order on the opposite
side of the market, one tick away from fill price in a quantity equivalent to the amount of the fill
4. Enter a Buy top order with threshold of 15 way from the market. Verify that an exchange order
is sent. Now move the top of the market toward the Top order, so that the Top order eventually
is at the Top of the market. This should cancel the order. Repeat the same with a threshold of < 10
and it should not cancel.
5. Enter a top order away from the market. Cancel its child order and the Top order should be cancelled too.