Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3dc0e9533 | ||
|
|
8575d92373 | ||
|
|
21ee7c6af5 | ||
|
|
1be2e81920 | ||
|
|
ea45c5c694 | ||
|
|
768567dfc7 | ||
|
|
870e7a9ef9 | ||
|
|
a9e572a1bf | ||
|
|
c7899a1dae | ||
|
|
7bb077a74d | ||
|
|
a29eaa2618 | ||
|
|
762369ad2b | ||
|
|
a8610beafd | ||
|
|
5e1a91f484 | ||
|
|
04fdb9626d | ||
|
|
689bfa1c76 | ||
|
|
70af046131 | ||
|
|
7a45013782 | ||
|
|
85f42d1e23 | ||
|
|
f8ddaab884 | ||
|
|
78373c61ce | ||
|
|
13e5c017e2 | ||
|
|
38f42fe747 | ||
|
|
3a6f9a608d | ||
|
|
e14a5b2575 | ||
|
|
04a68a4e96 | ||
|
|
526ec306ae | ||
|
|
f16ed40c82 | ||
|
|
102fefbd92 | ||
|
|
fc7a4b0800 |
No files matched your search
@@ -4,6 +4,27 @@ weight = 3
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
## 2.0.0
|
||||
### User Visible Changes
|
||||
- Support for attaching and detaching algos to existing orders
|
||||
- Support for display and update of all parameters in running algos
|
||||
- Streamlining of order badge decorations in ladder
|
||||
- New order search/filtering algorithm for order book
|
||||
- Simpler representation of complex algo chains in order book and mini order book
|
||||
- Visual and usability improvements to mini order book
|
||||
- Streamlining of algo parameter dialog in ladder
|
||||
- New spreader queue holder behaviour
|
||||
- Visual improvements to the order book
|
||||
- New server side API
|
||||
### Internal changes
|
||||
- Exchange simulator no longer requires daily sequence number reset
|
||||
- Native orders can now buffer updates/cancels when disconected or pending first acknowledgment
|
||||
|
||||
## 1.6.2
|
||||
### User Visible Changes
|
||||
### Exchange simulator
|
||||
- Exchange simulator now now produce position in queue data
|
||||
|
||||
## 1.6.0
|
||||
### User Visible Changes
|
||||
#### New Features
|
||||
|
||||
+1
-1
Submodule docker/linux updated: ce08a5129f...e13bb5d8df.
@@ -73,7 +73,7 @@ namespace mbts.spark {
|
||||
_has_working_orders = backing(nameof(has_working_orders), false);
|
||||
contract_picker_model = new ContractPickerModel(bus, false, null, new SecurityCriteria(new[] {
|
||||
new SecurityCriteriaClause() {
|
||||
exchanges = EnumHelper.get_values_except(Venue.Bts).ToLArray()
|
||||
exchanges = EnumHelper.get_values_except(Venue.Bts).ToArray()
|
||||
}
|
||||
}));
|
||||
contract_picker_model.cancel_action = _close_new_leg_popup;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using bts.utils;
|
||||
using mbts.spark.utilities;
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
struct AlgoData : IEquatable<AlgoData> {
|
||||
@@ -39,20 +40,28 @@ namespace mbts.spark {
|
||||
|
||||
struct AlgoDataVM : IEquatable<AlgoDataVM> {
|
||||
public readonly AlgoData data;
|
||||
public readonly AlgoDefinitionMetadata? meta;
|
||||
|
||||
public AlgoDataVM(AlgoData data) =>
|
||||
public AlgoDataVM(AlgoData data, AlgoDefinitionMetadata? meta = null) {
|
||||
this.data = data;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public string name => data.name;
|
||||
public Brush badge_fill => OrderUtils.badge_fill(meta, OrderDataHelper.get_metadata(data.value.CustomCase));
|
||||
public AlgoDisplayGroup group => data.key.display_group();
|
||||
|
||||
public override string ToString() =>
|
||||
data.name;
|
||||
|
||||
public static AlgoDataVM from_data(AlgoData data) =>
|
||||
new AlgoDataVM(data);
|
||||
public static AlgoDataVM from_data(AlgoData data, AlgoDefinitionMetadata? meta) =>
|
||||
new AlgoDataVM(data, meta);
|
||||
|
||||
public bool Equals(AlgoDataVM other) => data == other.data;
|
||||
public static AlgoDataVM from_data((AlgoData algo, AlgoDefinitionMetadata? meta) tup) =>
|
||||
new AlgoDataVM(tup.algo, tup.meta);
|
||||
|
||||
public bool Equals(AlgoDataVM other) => data == other.data && meta == other.meta;
|
||||
public override bool Equals(object obj) => obj is AlgoDataVM other && Equals(other);
|
||||
public override int GetHashCode() => data.GetHashCode();
|
||||
public override int GetHashCode() => EqualityComparer.aggregate_hash(data.GetHashCode(), meta.GetHashCode());
|
||||
}
|
||||
}
|
||||
@@ -47,15 +47,19 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public static void update_persisted_definition_wrappers(ObservableKeyedCollection<IAlgoVM, AlgoKey> target, TableUpdate<AlgoData, AlgoKey> update, Func<AlgoData, AlgoDefinitionVM> factory) {
|
||||
public static void update_persisted_definition_wrappers(IDictionary<AlgoKey, IAlgoVM> target, TableUpdate<AlgoData, AlgoKey> update, Func<AlgoData, AlgoDefinitionVM> factory) {
|
||||
foreach (var d in update.removed)
|
||||
target.Remove(d.key);
|
||||
foreach (var d in update.changed)
|
||||
target[d.key].load_from(d.value);
|
||||
foreach (var d in update.changed) {
|
||||
var vm = target[d.key];
|
||||
if (vm is AlgoVMWrapper wrapper) {
|
||||
wrapper.value.load(d);
|
||||
} else vm.load_from(d.value);
|
||||
}
|
||||
foreach (var d in update.added) {
|
||||
if (target.TryGetValue(d.key, out IAlgoVM def)) {
|
||||
def.load_from(d.value);
|
||||
} else target.Add(new AlgoVMWrapper(factory(d)));
|
||||
} else target.Add(d.key, new AlgoVMWrapper(factory(d)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,4 +118,4 @@ namespace mbts.spark {
|
||||
DisplayNameHelper.compare_alpha_numeric(a.display_name, b.display_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,6 +202,7 @@ namespace mbts.spark {
|
||||
public string name { get => _name.Value; set => _name.set(value); }
|
||||
public string abbreviation { get => _abbreviation.Value; set => _abbreviation.set(value); }
|
||||
public ObservableCollection<IAlgoVM> algo_roots => _algo_roots;
|
||||
public IDictionary<AlgoKey, IAlgoVM> algo_roots_index => _algo_roots;
|
||||
public IReadOnlyObservableCollection<IAlgoVM> algos_view { get; }
|
||||
public IAlgoVM algo_root { get => _algo_root.Value; set => _algo_root.set(value); }
|
||||
public IAlgoVM visible_algo_root => _visible_algo_root.Value;
|
||||
|
||||
@@ -18,12 +18,16 @@ namespace mbts.spark {
|
||||
this.algo = algo;
|
||||
this.parent = parent;
|
||||
_template_key = template_key;
|
||||
param.permissions_changed += on_permissions_changed;
|
||||
_dispose = Disposable.Create(() => param.permissions_changed -= on_permissions_changed);
|
||||
void on_permissions_changed(AlgoParamPermissions oldval, AlgoParamPermissions newval) => RaisePropertyChanged(nameof(permissions));
|
||||
}
|
||||
|
||||
public event Action invalidated;
|
||||
|
||||
public IAlgoVM algo { get; set; }
|
||||
public IAlgoParamVM param { get; }
|
||||
public AlgoParamPermissions permissions => param.permissions;
|
||||
public AlgoParamRowVM parent { get; }
|
||||
public int level => parent == null ? 0 : parent.level + 1;
|
||||
public string path_disambiguation {
|
||||
|
||||
@@ -29,13 +29,12 @@ namespace mbts.spark {
|
||||
nameof(editing_permissions),
|
||||
nameof(definition),
|
||||
nameof(display_name)
|
||||
},
|
||||
_value_echo_props = new HashSet<string> {
|
||||
nameof(AlgoDefinitionVM.name),
|
||||
nameof(AlgoDefinitionVM.abbreviation),
|
||||
nameof(AlgoDefinitionVM.badge_fill),
|
||||
nameof(AlgoDefinitionVM.can_undo),
|
||||
nameof(AlgoDefinitionVM.can_redo)
|
||||
};
|
||||
static readonly IReadOnlyDictionary<string, string>
|
||||
_value_echo_props = new Dictionary<string, string> {
|
||||
{ nameof(AlgoDefinitionVM.name), nameof(display_name) },
|
||||
{ nameof(AlgoDefinitionVM.abbreviation), nameof(abbreviation) },
|
||||
{ nameof(AlgoDefinitionVM.badge_fill), nameof(meta) }
|
||||
};
|
||||
readonly ObservableAggregateCollection<IAlgoSelector> _child_algo_selectors = new ObservableAggregateCollection<IAlgoSelector>();
|
||||
readonly ObservableAggregateCollection<IAlgoParamVM> _algo_params = new ObservableAggregateCollection<IAlgoParamVM>();
|
||||
@@ -143,8 +142,8 @@ namespace mbts.spark {
|
||||
RaisePropertyChanged(e.PropertyName);
|
||||
}
|
||||
void on_value_prop_changed(object sender, PropertyChangedEventArgs e) {
|
||||
if (_value_echo_props.Contains(e.PropertyName))
|
||||
RaisePropertyChanged(e.PropertyName);
|
||||
if (_value_echo_props.TryGetValue(e.PropertyName, out string wrapper_prop))
|
||||
RaisePropertyChanged(wrapper_prop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -52,6 +52,8 @@ namespace mbts.ui.spark {
|
||||
// AlgoParamRows
|
||||
AlgoParamRowsViewSource = new CollectionViewSource<ListCollectionView<AlgoParamRowVM>>();
|
||||
BindingOperations.SetBinding(AlgoParamRowsViewSource, CollectionViewSource.SourceProperty, new Binding(nameof(AlgoParamRows)) { Source = this });
|
||||
AlgoParamRowsViewSource.IsLiveFilteringRequested = true;
|
||||
AlgoParamRowsViewSource.LiveFilteringProperties.Add(nameof(AlgoParamRowVM.permissions));
|
||||
AlgoParamRowsViewSource.Filter += param_rows_filter;
|
||||
DataGridEditHelper.set_hooks(this);
|
||||
void param_rows_filter(object sender, FilterEventArgs e) =>
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace mbts.spark {
|
||||
public OrderType order_type => _order.order_type();
|
||||
public string display_name => OrderUtils.display_name(_order, _fill_tuple.algo);
|
||||
public OrderMetadata order_metadata => _order_metadata ?? (_order_metadata = _model.factory.get_metadata(_order.Def.CustomDef.CustomCase));
|
||||
public Brush badge_fill => _badge_fill ?? (_badge_fill = OrderUtils.badge_fill(_order, _fill_tuple.algo_meta, order_metadata));
|
||||
public Brush badge_fill => _badge_fill ?? (_badge_fill = OrderUtils.badge_fill(_fill_tuple.algo_meta, order_metadata));
|
||||
public string account { get; private set; }
|
||||
public string user => _order.user();
|
||||
public Venue exchange => security.Exchange;
|
||||
|
||||
@@ -566,7 +566,7 @@ namespace mbts.spark {
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, _get_glyph_context(row), font_size, _get_text(row), position, row_height,
|
||||
font_brush, null, horizontal_alignment, VerticalAlignment.Center, DefaultCellPadding);
|
||||
RenderUtils.get_foreground(row, font_brush), null, horizontal_alignment, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
#region Explicit Column Defs
|
||||
@@ -598,12 +598,15 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public class OrderBookOrderTypeColumn : OrderTypeColumn<Columns>, ICVOrderBookColumn {
|
||||
readonly BindingBase _foreground_binding;
|
||||
ListSortDirection? _cached_sort_direction;
|
||||
|
||||
public OrderBookOrderTypeColumn(Columns key, string badge_fill_binding_path, string display_name_binding_path, IComparer<OrderBookRowVM> row_comparer, IDataGridColumnPersistentFilter<OrderSecurityAlgoMeta, AlgoID[]> filter, string header = DefaultColumnHeaders.OrderType)
|
||||
: base(key, new Binding(badge_fill_binding_path), new Binding(display_name_binding_path), filter, header) {
|
||||
id = key.ToString();
|
||||
this.filter = filter;
|
||||
font_weight_binding = RenderUtils.get_font_weight_binding();
|
||||
_foreground_binding = RenderUtils.get_foreground_binding(this);
|
||||
_cached_sort_direction = SortDirection;
|
||||
this.comparer = row_comparer;
|
||||
}
|
||||
@@ -615,6 +618,12 @@ namespace mbts.spark {
|
||||
IDataGridColumnFilter<OrderSecurityAlgoMeta> ICVOrderBookColumn.filter => filter;
|
||||
ListSortDirection? ICVOrderBookColumn.SortDirection { get => _cached_sort_direction; set => SortDirection = value; }
|
||||
|
||||
public override FrameworkElement view_factory() {
|
||||
var view = base.view_factory();
|
||||
view.SetBinding(OrderTypeItem.ForegroundProperty, _foreground_binding);
|
||||
return view;
|
||||
}
|
||||
|
||||
protected override void OnSortDirectionChanged(ListSortDirection? new_value) {
|
||||
_cached_sort_direction = new_value;
|
||||
base.OnSortDirectionChanged(new_value);
|
||||
@@ -646,7 +655,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public class SecurityColumn : FrameworkElementColumnBase<Columns>, ICVOrderBookColumn, IFilterableColumn {
|
||||
readonly BindingBase _font_weight_binding = RenderUtils.get_font_weight_binding();
|
||||
readonly BindingBase _font_weight_binding = RenderUtils.get_font_weight_binding(), _foreground_binding;
|
||||
readonly IValueConverter _expander_visiblilty_converter = new ui.converters.BooleanToVisibilityConverter { VisibilityForFalse = Visibility.Hidden };
|
||||
readonly IValueConverter _margin_converter = new AnonymousValueConverter<int, Thickness>(level => new Thickness(10 * level, 0, 0, 0));
|
||||
|
||||
@@ -655,6 +664,7 @@ namespace mbts.spark {
|
||||
public SecurityColumn(IDataGridColumnPersistentFilter<OrderSecurityAlgoMeta, SecurityCriteria> filter) : base(Columns.Security) {
|
||||
id = key.ToString();
|
||||
this.filter = filter;
|
||||
_foreground_binding = RenderUtils.get_foreground_binding(this);
|
||||
Header = DefaultColumnHeaders.Security;
|
||||
Width = DefaultColumnWidths.Security;
|
||||
_cached_sort_direction = SortDirection;
|
||||
@@ -681,7 +691,7 @@ namespace mbts.spark {
|
||||
security_view.SetBinding(TextBlock.FontSizeProperty, new Binding(nameof(font_size)) { Source = this });
|
||||
security_view.SetBinding(TextBlock.TextProperty, nameof(OrderBookRowVM.security_text));
|
||||
security_view.SetBinding(TextBlock.HorizontalAlignmentProperty, new Binding(nameof(horizontal_alignment)) { Source = this });
|
||||
security_view.SetBinding(TextBlock.ForegroundProperty, new Binding(nameof(font_brush)) { Source = this });
|
||||
security_view.SetBinding(TextBlock.ForegroundProperty, _foreground_binding);
|
||||
security_view.SetBinding(TextBlock.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this });
|
||||
security_view.SetBinding(TextBlock.FontWeightProperty, _font_weight_binding);
|
||||
//
|
||||
@@ -1062,6 +1072,10 @@ namespace mbts.spark {
|
||||
popup.SetBinding(Popup.DataContextProperty, new Binding("PlacementTarget.DataContext") {
|
||||
RelativeSource = new RelativeSource(RelativeSourceMode.Self)
|
||||
});
|
||||
popup.Closed += (s, e) => {
|
||||
if (popup.try_find_ancestor_of_type(out MiniOrderBookView mini_ob) && mini_ob.DataContext is OrderBookVM ob_vm)
|
||||
ob_vm.is_attaching_orders = false;
|
||||
};
|
||||
|
||||
var the_whole_thing = new Grid();
|
||||
the_whole_thing.Children.Add(update_button);
|
||||
@@ -1149,19 +1163,24 @@ namespace mbts.spark {
|
||||
static class RenderUtils {
|
||||
public static FontWeight
|
||||
root_font_weight = FontWeights.Normal,
|
||||
child_font_weight = FontWeights.Light;
|
||||
child_font_weight = FontWeights.Normal;
|
||||
static readonly IMultiValueConverter _foreground_converter =
|
||||
ValueConverter.create<bool, Brush, Brush>(_get_foreground);
|
||||
|
||||
public static double font_size = FontSizes.Small;
|
||||
|
||||
public static readonly IValueConverter
|
||||
_sub_type_text_converter = new ui.spark.converters.OrderSubTypeDisplayTextConverter(),
|
||||
_side_brush_converter = new AnonymousValueConverter<Side, Brush>(s => s == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask),
|
||||
_font_weight_converter = new AnonymousValueConverter<bool, FontWeight>(is_child => is_child ? FontWeights.Light : FontWeights.Normal);
|
||||
_font_weight_converter = new AnonymousValueConverter<bool, FontWeight>(is_child => is_child ? child_font_weight : root_font_weight);
|
||||
|
||||
public static readonly IMultiValueConverter
|
||||
_price_text_converter = new ui.spark.converters.TickDisplayConverter(),
|
||||
_background_converter = new AnonymousMultiValueConverter<bool, OrderStatus, Brush>(
|
||||
(selected, status) => selected || status != OrderStatus.Working ? Brushes.Transparent : BTSColors.Orders.working_order_background_brush);
|
||||
|
||||
static readonly bool _animate_child_order_rows = mbts.config.Configuration.get<bts.config.OrderBookOptions>().animate_child_order_rows;
|
||||
|
||||
public static BindingBase _get_background_binding() {
|
||||
var mb = new MultiBinding { Converter = _background_converter };
|
||||
mb.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) });
|
||||
@@ -1169,9 +1188,29 @@ namespace mbts.spark {
|
||||
return mb;
|
||||
}
|
||||
|
||||
public static Brush get_side_brush(OrderBookRowVM r) => r.side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
}
|
||||
public static BindingBase get_foreground_binding(ColumnBase col) {
|
||||
var col_font_brush_binding = new Binding(nameof(ColumnBase.font_brush)) { Source = col };
|
||||
if (!_animate_child_order_rows)
|
||||
return col_font_brush_binding;
|
||||
var mb = new MultiBinding { Converter = _foreground_converter };
|
||||
mb.Bindings.Add(new Binding(nameof(OrderBookRowVM.is_child)));
|
||||
mb.Bindings.Add(col_font_brush_binding);
|
||||
return mb;
|
||||
}
|
||||
|
||||
public static Brush get_side_brush(OrderBookRowVM r) => get_foreground(r, r.side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask);
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
|
||||
public static Brush get_foreground(OrderBookRowVM row, Brush brush) =>
|
||||
_animate_child_order_rows ? _get_foreground(row.is_child, brush) : brush;
|
||||
|
||||
static Brush _get_foreground(bool is_child, Brush brush) {
|
||||
if (is_child) {
|
||||
brush = brush.Clone();
|
||||
brush.Opacity = 0.75;
|
||||
}
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace mbts.spark {
|
||||
public OrderSecurityAlgoMeta order_tuple { get; private set; }
|
||||
public OrderRecordImmutable order => order_tuple.order;
|
||||
public OrderMetadata order_metadata => _owner.get_metadata(this);
|
||||
public Brush badge_fill => _badge_fill ?? (_badge_fill = order_tuple.badge_fill(order_metadata));
|
||||
public Brush badge_fill => _badge_fill ?? (_badge_fill = OrderUtils.badge_fill(order_tuple.meta, order_metadata));
|
||||
public uint order_key => order.Key;
|
||||
public uint parent_order_key => order.ParentKey;
|
||||
public uint security_key => order.security_key();
|
||||
@@ -201,7 +201,7 @@ namespace mbts.spark {
|
||||
|
||||
// private props
|
||||
Color _root_algo_badge_color {
|
||||
get => _root_algo_badge_color_backing ?? (_root_algo_badge_color_backing = order_tuple.root_badge_color(root_algo_order_metadata)).Value;
|
||||
get => _root_algo_badge_color_backing ?? (_root_algo_badge_color_backing = OrderUtils.badge_color(order_tuple.root_meta, root_algo_order_metadata)).Value;
|
||||
set {
|
||||
if (_root_algo_badge_color_backing != value) {
|
||||
_root_algo_badge_color_backing = value;
|
||||
@@ -282,7 +282,7 @@ namespace mbts.spark {
|
||||
// root badge fill
|
||||
if (_root_algo_badge_color_backing.HasValue) {
|
||||
// only need to invalidate it if it had a value (it is lazily instantiated)
|
||||
_root_algo_badge_color = order_tuple.root_badge_color(root_algo_order_metadata);
|
||||
_root_algo_badge_color = OrderUtils.badge_color(order_tuple.root_meta, root_algo_order_metadata);
|
||||
RaisePropertyChanged(nameof(root_algo_badge_fill));
|
||||
}
|
||||
// root display name
|
||||
|
||||
@@ -248,10 +248,7 @@ namespace mbts.spark {
|
||||
var order_tups = selected_rows.Select(r => r.order_tuple).ToList();
|
||||
var mod_algo_vm = attach_vm.algo_vm.algo_root;
|
||||
await Task.WhenAll(order_tups.Select(t => {
|
||||
var algo = t.order.Def.CustomDef.CloneToMutable();
|
||||
if (algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite) {
|
||||
algo = algo.Composite.Definition;
|
||||
}
|
||||
var algo = t.order.Def.CustomDef.actual().CloneToMutable();
|
||||
mod_algo_vm.assign_to(algo);
|
||||
if (algo_template_key != 0) {
|
||||
algo = new CustomOrderDefinition {
|
||||
@@ -278,15 +275,14 @@ namespace mbts.spark {
|
||||
Disposable.replace(ref attach_vm_hooks,
|
||||
Disposable.Create(
|
||||
connect_common_selected_params(attach_vm),
|
||||
_selected_params_mon.subscribe_algos().Subscribe(algos => {
|
||||
attach_vm.algo_vm.observe_algo_root().Subscribe(algo_root => {
|
||||
bool show_price, show_size;
|
||||
using (var en = algos.Select(a => a.CustomCase).Distinct().GetEnumerator()) {
|
||||
if (show_price = show_size = en.MoveNext()) {
|
||||
do {
|
||||
if (show_price) show_price = AttachConf.show_price(en.Current);
|
||||
if (show_size) show_size = AttachConf.show_size(en.Current);
|
||||
} while ((show_price || show_size) && en.MoveNext());
|
||||
}
|
||||
if (algo_root == null) {
|
||||
show_price = false;
|
||||
show_size = false;
|
||||
} else {
|
||||
show_price = AttachConf.show_price(algo_root.order_type);
|
||||
show_size = AttachConf.show_size(algo_root.order_type);
|
||||
}
|
||||
attach_vm.price_permissions = bool_to_perm(show_price);
|
||||
attach_vm.size_permissions = bool_to_perm(show_size);
|
||||
@@ -295,7 +291,7 @@ namespace mbts.spark {
|
||||
}),
|
||||
// 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)))));
|
||||
AlgoCollectionHelper.update_persisted_definition_wrappers(attach_vm.algo_vm.algo_roots_index, u, mk_factory(true)))));
|
||||
// vm factory
|
||||
Func<AlgoData, AlgoDefinitionVM> mk_factory(bool connect) =>
|
||||
fd => {
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
x:Name="_grid"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:order="clr-namespace:bts.api.orderman;assembly=spark_api"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
InactiveSelectionOpacity="0.3"
|
||||
>
|
||||
<c:DIYGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
@@ -109,63 +108,4 @@
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
<KeyBinding Key="Return" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.RowStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
<!-- Completed order background -->
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{u:Enum Completed, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=completed_order_background_brush, MemberType={u:Nested u:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
<!-- Error, RejectedBySpark, Disconnected order background -->
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{u:Enum Error, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=error_order_background_brush, MemberType={u:Nested u:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{u:Enum RejectedBySpark, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=error_order_background_brush, MemberType={u:Nested u:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{u:Enum Disconnected, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=error_order_background_brush, MemberType={u:Nested u:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
<!-- Cancel order background -->
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{u:Enum Canceled, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=canceled_order_background_brush, MemberType={u:Nested u:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</c:DIYGrid.RowStyle>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<sp:OrderBookRowView/>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
@@ -1,4 +1,11 @@
|
||||
using bts.api.orderman;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.converters;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal partial class OrderBookGridView : DIYGrid {
|
||||
@@ -45,8 +52,49 @@ namespace mbts.spark {
|
||||
RootAlgoType = 1 << 29
|
||||
}
|
||||
|
||||
public OrderBookGridView() =>
|
||||
public OrderBookGridView() {
|
||||
InitializeComponent();
|
||||
var row_template_factory = new FrameworkElementFactory(typeof(OrderBookRowView));
|
||||
row_template_factory.SetValue(OrderBookRowView.BackgroundProperty, RowBackgroundHelper.row_background_binding);
|
||||
RowTemplate = new DataTemplate { VisualTree = row_template_factory };
|
||||
}
|
||||
|
||||
static class RowBackgroundHelper {
|
||||
public static readonly BindingBase row_background_binding;
|
||||
|
||||
static RowBackgroundHelper() {
|
||||
var bg_binding = new MultiBinding();
|
||||
bg_binding.Bindings.Add(new Binding(nameof(OrderBookRowVM.status)));
|
||||
bg_binding.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) });
|
||||
double overlay_opacity = config.Configuration.get<bts.config.OrderBookOptions>().status_color_opacity_when_selected;
|
||||
if (overlay_opacity > 0.1 && overlay_opacity < 0.9) {
|
||||
bg_binding.Converter = ValueConverter.create<OrderStatus, bool, Brush>((status, is_selected) => {
|
||||
var color = _status_color(status);
|
||||
return color.HasValue ? new SolidColorBrush(color.Value) { Opacity = is_selected ? overlay_opacity : 1.0 } : null;
|
||||
});
|
||||
} else {
|
||||
bg_binding.Converter = ValueConverter.create<OrderStatus, bool, Brush>((status, is_selected) => {
|
||||
if (is_selected)
|
||||
return null;
|
||||
var color = _status_color(status);
|
||||
return color.HasValue ? new SolidColorBrush(color.Value) : null;
|
||||
});
|
||||
}
|
||||
row_background_binding = bg_binding;
|
||||
}
|
||||
|
||||
static Color? _status_color(OrderStatus status) {
|
||||
switch (status) {
|
||||
case OrderStatus.Canceled: return BTSColors.Orders.canceled_order_background;
|
||||
case OrderStatus.Completed: return BTSColors.Orders.completed_order_background;
|
||||
case OrderStatus.Disconnected:
|
||||
case OrderStatus.RejectedBySpark:
|
||||
case OrderStatus.Error:
|
||||
return BTSColors.Orders.error_order_background;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OrderBookRowView : DIYGrid.HighPerformanceRow<OrderBookRowVM, OrderBookGridView.ColumnKeys> {
|
||||
|
||||
@@ -6,6 +6,7 @@ using mbts.ui;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using static mbts.ui.shell.ProtoBufSerializationHelper;
|
||||
@@ -52,9 +53,8 @@ namespace bts.shell {
|
||||
yield return _aswf;
|
||||
}
|
||||
|
||||
public Task<IShellWindow> create(Stream load_stream) {
|
||||
return dispatch_to_factory(load_stream, window_factories().ToLArray());
|
||||
}
|
||||
public Task<IShellWindow> create(Stream load_stream) =>
|
||||
dispatch_to_factory(load_stream, window_factories().ToArray());
|
||||
|
||||
public void Dispose() {
|
||||
foreach (var i in window_factories())
|
||||
|
||||
@@ -240,22 +240,12 @@ namespace mbts.spark {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static Brush badge_fill(this OrderSecurityAlgoMeta order_sam, OrderMetadata order_meta) =>
|
||||
badge_fill(order_sam.order, order_sam.meta, order_meta);
|
||||
|
||||
public static Brush badge_fill(OrderRecordImmutable order, AlgoDefinitionMetadata? algo_meta, OrderMetadata order_meta) {
|
||||
if (algo_meta?.badge_color is Color c) {
|
||||
return c.to_brush();
|
||||
} else {
|
||||
return order_meta.Color.rgb_brush();
|
||||
}
|
||||
}
|
||||
public static Brush badge_fill(AlgoDefinitionMetadata? algo_meta, OrderMetadata order_meta) =>
|
||||
new SolidColorBrush(badge_color(algo_meta, order_meta));
|
||||
|
||||
public static Color root_badge_color(this OrderSecurityAlgoMeta order_sam, OrderMetadata root_order_meta) =>
|
||||
order_sam.root_meta?.badge_color is Color c ? c : root_order_meta.Color.rgb_color();
|
||||
|
||||
public static Brush root_badge_fill(this OrderSecurityAlgoMeta order_sam, OrderMetadata root_order_meta) =>
|
||||
new SolidColorBrush(root_badge_color(order_sam, root_order_meta));
|
||||
public static Color badge_color(AlgoDefinitionMetadata? algo_meta, OrderMetadata order_meta) =>
|
||||
algo_meta?.badge_color ?? order_meta.Color.rgb_color();
|
||||
|
||||
public static string order_collection_summary(double best_price, int best_price_volume, int total_volume, ContractSpecificationImmutable spec) {
|
||||
if (total_volume == 0)
|
||||
|
||||
@@ -84,15 +84,16 @@ namespace mbts.spark {
|
||||
_security_orders_demuxer = new TableUpdateDemuxer<OrderRecordImmutable, uint, uint>(o => o.Key, o => o.security_key());
|
||||
_security_working_orders_with_piq_demuxer = new TableUpdateDemuxer<OrderSecurity, uint, uint>(o => o.order.Key, o => o.order.security_key());
|
||||
_security_positions_demuxer = new TableUpdateDemuxer<PositionUnitImmutable, int, uint>(o => o.RecordId, p => p.SecurityId);
|
||||
var algo_meta_join = algo_model.definitions.LeftJoin<AlgoData, AlgoDefinitionMetadata, (AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>(
|
||||
studio_algos_with_meta = algo_model.definitions.LeftJoin<AlgoData, AlgoDefinitionMetadata, (AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>(
|
||||
algo_model.metadata_service.subscribe_metadata().Table(m => m.id),
|
||||
d => d.key,
|
||||
m => m.id,
|
||||
(algo, k, meta) => (algo, meta),
|
||||
(algo, k) => (algo, null),
|
||||
t => t.algo.key);
|
||||
t => t.algo.key)
|
||||
.Cache();
|
||||
var order_secs_algo_meta_join = on_orders.LeftJoin(
|
||||
algo_meta_join,
|
||||
studio_algos_with_meta,
|
||||
t => t.order.Key,
|
||||
am => am.algo.key,
|
||||
t => new AlgoKey(new bts.persist.algo.AlgoPersistedKey(t.order.algo_template_key())),
|
||||
@@ -178,6 +179,7 @@ namespace mbts.spark {
|
||||
public IObservable<TableUpdate<FillTuple, string>> on_fill_tuples { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint,OrderSecurity>> working_orders { get; }
|
||||
public IObservable<TableUpdate<PositionUnitImmutable, int>> on_positions { get; }
|
||||
public IObservable<TableUpdate<(AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>> studio_algos_with_meta { get; }
|
||||
|
||||
public AdminModel admin_model { get; }
|
||||
public IAlgoStudioModel algo_model { get; }
|
||||
@@ -436,16 +438,18 @@ namespace mbts.spark {
|
||||
return rod;
|
||||
}).Select(r => r.last_update);
|
||||
|
||||
public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_all_algos(this OrdersModel orders_model) =>
|
||||
orders_model.algo_model.definitions.MergeTable(Observable.Return(
|
||||
new TableUpdate<AlgoData, AlgoKey>(
|
||||
ImmutableDictionary<AlgoKey, AlgoData>.Empty.AddRange(orders_model.factory.default_algos(OrderDataHelper.all_order_types)),
|
||||
Array.Empty<AlgoData>(),
|
||||
Array.Empty<Change<AlgoData>>(),
|
||||
Array.Empty<AlgoData>(),
|
||||
d => d.key
|
||||
public static IObservable<TableUpdate<(AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>> subscribe_all_algos(this OrdersModel orders_model) =>
|
||||
orders_model.studio_algos_with_meta.MergeTable(Observable.Return(
|
||||
new TableUpdate<(AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>(
|
||||
ImmutableDictionary<AlgoKey, (AlgoData algo, AlgoDefinitionMetadata? meta)>.Empty.AddRange(orders_model.factory.default_algos(OrderDataHelper.all_order_types).Select(kv => new KeyValuePair<AlgoKey, (AlgoData algo, AlgoDefinitionMetadata? meta)>(kv.Key, (kv.Value, null)))),
|
||||
Array.Empty<(AlgoData,AlgoDefinitionMetadata?)>(),
|
||||
Array.Empty<Change<(AlgoData,AlgoDefinitionMetadata?)>>(),
|
||||
Array.Empty<(AlgoData,AlgoDefinitionMetadata?)>(),
|
||||
d => d.algo.key
|
||||
).as_snapshot()));
|
||||
|
||||
//public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_all_algos_with_meta(this OrdersModel orders_model) =>
|
||||
|
||||
public static async Task<OrderRecordImmutable?> order_from_key(this OrdersModel orders_model, uint order_key) {
|
||||
(var tu, var success) = await orders_model.on_orders.FirstAsyncTask(t => t.state.ContainsKey(order_key), TimeSpan.FromSeconds(3));
|
||||
if (success && tu.state.TryGetValue(order_key, out var rec)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace mbts.collections
|
||||
foreach (TModel m in e.OldItems) _remove(m);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
var old_views = Values.ToLArray();
|
||||
var old_views = Values.ToArray();
|
||||
Clear();
|
||||
foreach (TValue v in old_views) ValueDestroyed?.Invoke(v);
|
||||
foreach (TModel m in _models) _add(m);
|
||||
|
||||
@@ -242,6 +242,7 @@ namespace mbts.ui.controls {
|
||||
public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 };
|
||||
public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1);
|
||||
readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb;
|
||||
double _inactive_selection_opacity = 0.2;
|
||||
DataContextHooks _data_context_hooks;
|
||||
|
||||
public static readonly DependencyProperty SelectionHighlightProperty =
|
||||
@@ -249,7 +250,7 @@ namespace mbts.ui.controls {
|
||||
nameof(SelectionHighlight),
|
||||
(o, v) => {
|
||||
o.Resources[ActiveSelectionHighlightKey] = v;
|
||||
o.Resources[InactiveSelectionHighlightKey] = new SolidColorBrush(v.Color) { Opacity = 0.2 }.frozen();
|
||||
o._reset_inactive_selection_brush();
|
||||
o.Resources[SelectionStrokeKey] = new Pen(o.SelectionHighlight.Color.to_solid_brush().frozen(), 1).frozen();
|
||||
foreach (var col in o.Columns.empty_if_null().OfType<ISelectionHighlightListener>())
|
||||
col.on_selection_fill(v);
|
||||
@@ -322,14 +323,24 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
}
|
||||
}));
|
||||
Resources[InactiveSelectionHighlightKey] = new SolidColorBrush(SelectionHighlight.Color) { Opacity = 0.2 };
|
||||
Resources[ActiveSelectionHighlightKey] = SelectionHighlight;
|
||||
_reset_inactive_selection_brush();
|
||||
_data_context_hooks = new DataContextHooks(this, DataContext);
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
public event DIYGridSortingEventHandler Sorting;
|
||||
|
||||
public double InactiveSelectionOpacity {
|
||||
get => _inactive_selection_opacity;
|
||||
set {
|
||||
if (value != _inactive_selection_opacity && value.is_within_range(0.1, 0.9)) {
|
||||
_inactive_selection_opacity = value;
|
||||
_reset_inactive_selection_brush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemContainerGenerator RowContainerGenerator =>
|
||||
_row_presenter.ItemContainerGenerator;
|
||||
|
||||
@@ -376,6 +387,18 @@ namespace mbts.ui.controls {
|
||||
void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) =>
|
||||
Disposable.replace(ref _data_context_hooks, new DataContextHooks(this, e.NewValue));
|
||||
|
||||
void _reset_inactive_selection_brush() {
|
||||
try {
|
||||
if (TryFindResource(ActiveSelectionHighlightKey) is SolidColorBrush brush) {
|
||||
var clone = brush.Clone();
|
||||
if (_inactive_selection_opacity < clone.Opacity) {
|
||||
clone.Opacity = _inactive_selection_opacity;
|
||||
}
|
||||
Resources[InactiveSelectionHighlightKey] = clone;
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
#region Column Handling
|
||||
private void invalidate_column_layout(object sender = null, EventArgs args = null) {
|
||||
var geometry = GetColumnGeometry().ToList();
|
||||
@@ -591,7 +614,7 @@ namespace mbts.ui.controls {
|
||||
_row_presenter.ItemContainerStyle = _row_style;
|
||||
}
|
||||
|
||||
public Style RowStyle { get => GetValue(RowStyleProperty) as Style; set => SetValue(StyleProperty, value); }
|
||||
public Style RowStyle { get => GetValue(RowStyleProperty) as Style; set => SetValue(RowStyleProperty, value); }
|
||||
#endregion
|
||||
|
||||
public static readonly DependencyProperty CurrentRowProperty = DependencyProperty.Register(
|
||||
@@ -915,4 +938,4 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,22 @@ using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
partial class DIYGrid {
|
||||
public class HighPerformanceRow<TRowVM, TColKey> : FrameworkElement where TRowVM : class, IRowVM {
|
||||
public class HighPerformanceRowBase : FrameworkElement {
|
||||
protected Brush cached_background;
|
||||
|
||||
public static readonly DependencyProperty BackgroundProperty =
|
||||
WPFHelper.create_dp<Brush, HighPerformanceRowBase>(
|
||||
nameof(Background),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => o.cached_background = v);
|
||||
|
||||
public Brush Background {
|
||||
get => GetValue(BackgroundProperty) as Brush;
|
||||
set => SetValue(BackgroundProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public class HighPerformanceRow<TRowVM, TColKey> : HighPerformanceRowBase where TRowVM : class, IRowVM {
|
||||
double _row_height;
|
||||
ObservableCollection<ColumnBase> _columns;
|
||||
List<ColumnGeometry> _column_layout = new List<ColumnGeometry>();
|
||||
@@ -85,6 +100,9 @@ namespace mbts.ui.controls {
|
||||
_element_cells.VisualAtIndex(index);
|
||||
|
||||
protected override void OnRender(DrawingContext dc) {
|
||||
if (cached_background != null) {
|
||||
dc.DrawRectangle(cached_background, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
}
|
||||
if (_row != null) {
|
||||
foreach (var cell in _column_layout) {
|
||||
if (!cell.column.is_collapsed && cell.column is IRenderColumn<TRowVM> rc)
|
||||
|
||||
@@ -3,17 +3,14 @@ using bts.collections;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utilities;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.spark.filters {
|
||||
static class DiscreteValuesFilterVM {
|
||||
@@ -87,7 +84,7 @@ namespace mbts.spark.filters {
|
||||
public IReadOnlyCollection<TValue> items { get; }
|
||||
public ObservableCollectionEx<TValue> selected_items { get; } = new ObservableCollectionEx<TValue>();
|
||||
|
||||
public override TValue[] get_state() => selected_items.ToLArray();
|
||||
public override TValue[] get_state() => selected_items.ToArray();
|
||||
protected override void _clear() {
|
||||
_destroy_snapshot();
|
||||
selected_items.Clear();
|
||||
@@ -147,10 +144,10 @@ namespace mbts.spark.filters {
|
||||
) : this(get_row_val, get_state, load_state, prop_name, equality_comparer, comparer) {
|
||||
//
|
||||
_items_sub = items.OnDispatcher().Subscribe(update => {
|
||||
foreach (var v in update.added)
|
||||
_items_set.Add(v);
|
||||
foreach (var v in update.removed.Except(_selected_items_set))
|
||||
_items_set.Remove(v);
|
||||
foreach (var v in update.added)
|
||||
_items_set.Add(v);
|
||||
_unsorted_items.sync_with(_items_set);
|
||||
});
|
||||
}
|
||||
@@ -262,7 +259,7 @@ namespace mbts.spark.filters {
|
||||
readonly Func<TState, IEnumerable<TKey>> _load_state;
|
||||
readonly Func<IEnumerable<TKey>, TState> _get_state;
|
||||
readonly IEqualityComparer<TValue> _comparer;
|
||||
readonly HashSet<TKey> _selected_keys = new HashSet<TKey>();
|
||||
readonly HashSet<TKey> _selected_keys = new HashSet<TKey>(), _desired_keys = new HashSet<TKey>();
|
||||
ListCollectionView<TValue> _items_view;
|
||||
|
||||
public TableUpdateItemsFilter(Func<TRow, TValue> factory, Func<TRow, TKey> row_key, Func<TValue, TKey> key, Func<TState, IEnumerable<TKey>> load_state, Func<IEnumerable<TKey>, TState> get_state)
|
||||
@@ -290,6 +287,12 @@ namespace mbts.spark.filters {
|
||||
_items.Replace(_key(ch.Old), ch.New);
|
||||
foreach (var v in table.added)
|
||||
_items.Add(v);
|
||||
var newly_selected_keys = _desired_keys.Where(_selection_model.try_select).ToList();
|
||||
if (newly_selected_keys.Count > 0) {
|
||||
_selected_keys.AddRange(newly_selected_keys);
|
||||
_desired_keys.removeRange(newly_selected_keys);
|
||||
_raise_filter_changed();
|
||||
}
|
||||
}
|
||||
|
||||
public override TState get_state() => _get_state(_selection_model.selected_items.Select(_key));
|
||||
@@ -309,8 +312,10 @@ namespace mbts.spark.filters {
|
||||
|
||||
protected override bool _filter(TValue value) => _selected_keys.Contains(_key(value));
|
||||
protected override void _load_state_internal(TState state) {
|
||||
foreach (var k in _load_state(state).empty_if_null())
|
||||
_selection_model.try_select(k);
|
||||
foreach (var k in _load_state(state).empty_if_null()) {
|
||||
if (!_selection_model.try_select(k))
|
||||
_desired_keys.Add(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -337,4 +342,4 @@ namespace mbts.spark.filters {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +163,11 @@
|
||||
<c:ListBoxEx.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ComboBox.DelineatedGroupContainerStyle}"/>
|
||||
</c:ListBoxEx.GroupStyle>
|
||||
<c:ListBoxEx.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<usp:OrderTypeItem DisplayName="{Binding name}" BadgeFill="{Binding badge_fill}" Margin="6,0,0,0"/>
|
||||
</DataTemplate>
|
||||
</c:ListBoxEx.ItemTemplate>
|
||||
</c:ListBoxEx>
|
||||
</usp:FilterContentControl>
|
||||
</DataTemplate>
|
||||
|
||||
@@ -243,7 +243,7 @@
|
||||
</MenuItem.Header>
|
||||
<MenuItem.ToolTip>
|
||||
<TextBlock>
|
||||
Make current paramaters the local defaults
|
||||
Make current paramaters the local defaults.
|
||||
<LineBreak/>
|
||||
<Italic>These values will be lost when the ladder closes.</Italic>
|
||||
</TextBlock>
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters
|
||||
{
|
||||
public class EnumCaseStringConverter<T> : IValueConverter where T : struct
|
||||
{
|
||||
namespace mbts.ui.converters {
|
||||
class EnumCaseStringConverter<T> : IValueConverter where T : struct {
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
|
||||
T t = default(T);
|
||||
if (value is T)
|
||||
t = (T)value;
|
||||
string raw_str = t.ToString();
|
||||
return raw_str.Substring(0, 1) + new String(raw_str.Skip(1).Select(Char.ToLower).ToLArray());
|
||||
string raw_str = (value is T t ? t : default).ToString();
|
||||
return raw_str.Substring(0, 1) + new string(raw_str.Skip(1).Select(char.ToLower).ToArray());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
|
||||
T t = default(T);
|
||||
string str = value as string;
|
||||
if (str != null)
|
||||
Enum.TryParse<T>(str, true, out t);
|
||||
return t;
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) =>
|
||||
value is string str && Enum.TryParse(str, true, out T result) ? result : default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,12 +106,20 @@ namespace mbts.ui
|
||||
var effect = DragDrop.DoDragDrop(_source, data, DragDropEffects.Move);
|
||||
}
|
||||
catch (Exception error) { Log.Ui.warn("Dragdrop failed: " + error.ToString()); }
|
||||
await show_document(_source, _source_window, true);
|
||||
_source = null;
|
||||
_source_window = null;
|
||||
/// Reentrancy Risk:
|
||||
/// During the await period for <see cref="show_document(TabDocument, FloatingWindow, bool)"/>,
|
||||
/// the new window hooks up to the dragdrop events via <see cref="attach_dragdrop_events(ItemsControl)"/>.
|
||||
/// It must be assured that the new window does not get a callback into <see cref="container_PreviewMouseMove(ItemsControl, MouseEventArgs)"/>
|
||||
/// and attempt to create a second <see cref="DragDropDocumentPreview"/> for the same instance <see cref="_source"/>.
|
||||
/// For this reason, <see cref="_source"/> is set to null before <see cref="show_document(TabDocument, FloatingWindow, bool)"/> is called.
|
||||
_source_image = null;
|
||||
_target = null;
|
||||
_dddp = null;
|
||||
var src = _source;
|
||||
var src_win = _source_window;
|
||||
_source = null;
|
||||
_source_window = null;
|
||||
await show_document(src, src_win, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ namespace bts.utils {
|
||||
for (int i = 1; i < num2; i++) if ((num1 * i) % num2 == 0) return i * num1;
|
||||
return num1 * num2;
|
||||
}
|
||||
|
||||
public static bool is_within_range(this double value, double min, double max) =>
|
||||
value >= min && value <= max;
|
||||
|
||||
public static int within_range(int min, int max, int value) {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
|
||||
@@ -30,11 +30,8 @@ namespace System.Collections.Generic {
|
||||
public static IEnumerable<T> OfTypeSafe<T>(this IEnumerable source) =>
|
||||
source == null ? Enumerable.Empty<T>() : source.OfType<T>();
|
||||
|
||||
public static T[] ToLArray<T>(this IEnumerable<T> enumerable) =>
|
||||
enumerable.ToList().ToArray();
|
||||
|
||||
public static TAccumulate AggregateWhile<T, TAccumulate>(this IEnumerable<T> source, TAccumulate seed, Func<TAccumulate, T, TAccumulate> aggregate, Func<TAccumulate, T, bool> predicate) =>
|
||||
AggregateWhile(source, seed, aggregate, predicate, (curr, el, next) => curr);
|
||||
AggregateWhile(source, seed, aggregate, predicate, (curr, el, next) => curr);
|
||||
|
||||
public static TAccumulate AggregateWhile<T, TAccumulate>(this IEnumerable<T> source, TAccumulate seed, Func<TAccumulate, T, TAccumulate> aggregate, Func<TAccumulate, T, bool> predicate, TAccumulate early_break_rv) =>
|
||||
AggregateWhile(source, seed, aggregate, predicate, (curr, el, next) => early_break_rv);
|
||||
|
||||
@@ -71,6 +71,11 @@ message LadderKnobs {
|
||||
optional bool use_algo_param_grid = 7 [default = true];
|
||||
}
|
||||
|
||||
message OrderBookOptions {
|
||||
optional bool animate_child_order_rows = 1 [default = false];
|
||||
optional double status_color_opacity_when_selected = 2 [default = 0.35];
|
||||
}
|
||||
|
||||
message ShellPingOptions {
|
||||
optional bool shell_ping_is_enabled = 1 [default = true];
|
||||
optional int32 workloop_milliseconds_interval = 2 [default = 5000];
|
||||
|
||||
@@ -10,6 +10,18 @@ namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
enum class CoverAlgo::Status { WORKING, WAITING_FOR_HEDGES, DONE };
|
||||
const char *CoverAlgo::status_name(Status st) {
|
||||
switch (st) {
|
||||
case Status::WORKING:
|
||||
return "WORKING";
|
||||
case Status::WAITING_FOR_HEDGES:
|
||||
return "WAITING_FOR_HEDGES";
|
||||
case Status::DONE:
|
||||
return "Done";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
struct CoverAlgo::PImpl {
|
||||
IAlgoServices *algo;
|
||||
OrderKey child_key = null_order_key();
|
||||
@@ -17,6 +29,8 @@ struct CoverAlgo::PImpl {
|
||||
ChildTemplate *child_template = nullptr;
|
||||
ChildTemplate *hedge_template = nullptr;
|
||||
Quantity hedged_fills = Quantity(0);
|
||||
Status status = Status::WORKING;
|
||||
std::vector<OrderKey> hedges;
|
||||
};
|
||||
|
||||
CoverAlgo::CoverAlgo() : me(new PImpl()) {}
|
||||
@@ -77,64 +91,96 @@ void CoverAlgo::do_launch_attached(IAlgoServices &algo, OrderKey k,
|
||||
}
|
||||
|
||||
void CoverAlgo::on_child_change(OrderKey k, ChildState const &st) {
|
||||
bts_assert(k == me->child_key); // We are not subscribed to hedge changes
|
||||
if (k == me->child_key) {
|
||||
if (st.total_fills.value() > me->hedged_fills.value()) {
|
||||
auto hedge_qty =
|
||||
Quantity(st.total_fills.value() - me->hedged_fills.value());
|
||||
auto hedge_price = securities::improve_price(
|
||||
algo().definition().side(), st.last_price,
|
||||
me->price_improvement_delta);
|
||||
|
||||
if (st.total_fills.value() > me->hedged_fills.value()) {
|
||||
auto hedge_qty =
|
||||
Quantity(st.total_fills.value() - me->hedged_fills.value());
|
||||
auto hedge_price =
|
||||
securities::improve_price(algo().definition().side(), st.last_price,
|
||||
me->price_improvement_delta);
|
||||
auto hedge =
|
||||
algo().launch_child(*me->hedge_template, hedge_price, hedge_qty);
|
||||
me->hedges.push_back(hedge);
|
||||
|
||||
algo().launch_child(*me->hedge_template, hedge_price, hedge_qty,
|
||||
false); // do not subscribe to hedge changes
|
||||
|
||||
me->hedged_fills = Quantity(hedge_qty.value() + me->hedged_fills.value());
|
||||
LOG(OrderMan, Diag,
|
||||
"CoverAlgo {}, launched new hedge in response to child fill. Hedge: "
|
||||
"{} {}@{}",
|
||||
algo().order_key().value(),
|
||||
securities::side_name(algo().definition().side()), hedge_qty.value(),
|
||||
hedge_price.value());
|
||||
}
|
||||
algo().update_fill_state(st.total_fills, st.last_price);
|
||||
switch (st.status) {
|
||||
case ChildStatus::WORKING:
|
||||
return;
|
||||
case ChildStatus::COMPLETED:
|
||||
algo().detach_all_children();
|
||||
algo().complete();
|
||||
return;
|
||||
case ChildStatus::CANCELED:
|
||||
algo().terminate_error("Unexpected child cancel");
|
||||
return;
|
||||
me->hedged_fills =
|
||||
Quantity(hedge_qty.value() + me->hedged_fills.value());
|
||||
LOG(OrderMan, Diag,
|
||||
"CoverAlgo {}, launched new hedge in response to child fill. "
|
||||
"Hedge: "
|
||||
"{} {}@{}",
|
||||
algo().order_key().value(),
|
||||
securities::side_name(algo().definition().side()),
|
||||
hedge_qty.value(), hedge_price.value());
|
||||
}
|
||||
algo().update_fill_state(st.total_fills, st.last_price);
|
||||
switch (st.status) {
|
||||
case ChildStatus::WORKING:
|
||||
break;
|
||||
case ChildStatus::COMPLETED:
|
||||
LOG(OrderMan, Info,
|
||||
"CoverAlgo {}. Child is completed, waiting for hedges ",
|
||||
algo().order_key().value());
|
||||
me->status = Status::WAITING_FOR_HEDGES;
|
||||
break;
|
||||
case ChildStatus::CANCELED:
|
||||
LOG(OrderMan, Info, "CoverAlgo {}. Child was canceled, terminating",
|
||||
algo().order_key().value());
|
||||
me->status = Status::DONE;
|
||||
algo().terminate_error("Unexpected child cancel");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (st.status) {
|
||||
case ChildStatus::WORKING:
|
||||
break;
|
||||
case ChildStatus::COMPLETED:
|
||||
if (auto it = std::find(me->hedges.begin(), me->hedges.end(), k);
|
||||
it != me->hedges.end())
|
||||
me->hedges.erase(it);
|
||||
break;
|
||||
case ChildStatus::CANCELED:
|
||||
LOG(OrderMan, Info, "CoverAlgo {}. Hedge was canceled, terminating",
|
||||
algo().order_key().value());
|
||||
me->status = Status::DONE;
|
||||
algo().terminate_error("Unexpected child cancel");
|
||||
break;
|
||||
}
|
||||
}
|
||||
check_terminate();
|
||||
}
|
||||
|
||||
void CoverAlgo::do_update(api::orderman::Update const &update) {
|
||||
LOG(OrderMan, Diag, "CoverAlgo order {} receiving update: {}",
|
||||
algo().order_key().value(), utils::pb::to_string(update));
|
||||
if (me->status == Status::WORKING) {
|
||||
LOG(OrderMan, Diag, "CoverAlgo order {} receiving update: {}",
|
||||
algo().order_key().value(), utils::pb::to_string(update));
|
||||
|
||||
if (update.has_custom() && !update.custom().has_cover()) {
|
||||
algo().terminate_error("Invalid update");
|
||||
return;
|
||||
}
|
||||
|
||||
Update child_update;
|
||||
child_update.set_price(update.price());
|
||||
child_update.set_quantity(update.quantity());
|
||||
|
||||
// process custom part of the udpate if any
|
||||
if (update.has_custom()) {
|
||||
auto &cover_update = update.custom().cover();
|
||||
set_price_improvement_delta(algo(), cover_update);
|
||||
if (cover_update.has_child()) {
|
||||
*child_update.mutable_custom() = cover_update.child();
|
||||
if (update.has_custom() && !update.custom().has_cover()) {
|
||||
algo().terminate_error("Invalid update");
|
||||
return;
|
||||
}
|
||||
if (cover_update.has_hedge())
|
||||
init_hedge_template(algo(), cover_update.hedge());
|
||||
|
||||
Update child_update;
|
||||
child_update.set_price(update.price());
|
||||
child_update.set_quantity(update.quantity());
|
||||
|
||||
// process custom part of the udpate if any
|
||||
if (update.has_custom()) {
|
||||
auto &cover_update = update.custom().cover();
|
||||
set_price_improvement_delta(algo(), cover_update);
|
||||
if (cover_update.has_child()) {
|
||||
*child_update.mutable_custom() = cover_update.child();
|
||||
}
|
||||
if (cover_update.has_hedge())
|
||||
init_hedge_template(algo(), cover_update.hedge());
|
||||
}
|
||||
algo().update_child(me->child_key, child_update);
|
||||
} else {
|
||||
LOG(OrderMan, Info,
|
||||
"CoverAlgo {}. Received update after child has completed. Ignoring "
|
||||
"it.",
|
||||
algo().order_key().value());
|
||||
}
|
||||
algo().update_child(me->child_key, child_update);
|
||||
}
|
||||
|
||||
void orderman::CoverAlgo::init_hedge_template(
|
||||
@@ -155,5 +201,18 @@ void CoverAlgo::set_price_improvement_delta(
|
||||
securities::tick_size(serv.security()).value() * cover.hedge_ticks());
|
||||
}
|
||||
|
||||
void CoverAlgo::check_terminate() {
|
||||
LOG(OrderMan, Diag,
|
||||
"CoverAlgo {} check_terminate. State: {} Hedge count: {}",
|
||||
algo().order_key(), log::CharPtrWrapper{status_name(me->status)},
|
||||
me->hedges.size());
|
||||
|
||||
if (me->status == Status::WAITING_FOR_HEDGES && me->hedges.empty()) {
|
||||
LOG(OrderMan, Info, "CoverAlgo {}. Last hedge completed, terminating",
|
||||
algo().order_key().value());
|
||||
algo().complete();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
enum class Status;
|
||||
std::unique_ptr<PImpl> me;
|
||||
IAlgoServices &algo() const;
|
||||
void
|
||||
@@ -28,6 +29,8 @@ private:
|
||||
api::orderman::CoverOrderDefinition const &);
|
||||
void init_hedge_template(IBeforeLaunchAlgoServices &,
|
||||
api::orderman::CustomOrderDefinition const &);
|
||||
void check_terminate();
|
||||
const char *status_name(Status st);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "lib/orderman/order_factory/IOrderFactory.h"
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
|
||||
namespace bts {
|
||||
@@ -20,6 +21,7 @@ struct JoinAlgo::PImpl {
|
||||
ChildTemplate *child_template = nullptr;
|
||||
Book book_at_inception;
|
||||
Book last_book;
|
||||
Price joined_price=Price(os::nan());
|
||||
};
|
||||
|
||||
JoinAlgo::JoinAlgo() : me(new PImpl()) {}
|
||||
@@ -80,7 +82,8 @@ void JoinAlgo::do_update(api::orderman::Update const &update) {
|
||||
}
|
||||
|
||||
Update child_update;
|
||||
child_update.set_price(update.price());
|
||||
Price price_to_pass = get_price_to_pass(Price(update.price()));
|
||||
child_update.set_price(price_to_pass.value());
|
||||
child_update.set_quantity(update.quantity());
|
||||
if (update.has_custom()) {
|
||||
update_join_threshold();
|
||||
@@ -146,6 +149,7 @@ void JoinAlgo::try_to_join() {
|
||||
|
||||
// Time to join
|
||||
Update child_update;
|
||||
me->joined_price = Price(my_side_psz.price());
|
||||
child_update.set_price(my_side_psz.price());
|
||||
child_update.set_quantity(algo().quantity().value());
|
||||
algo().update_child(me->child_key, child_update);
|
||||
@@ -161,6 +165,20 @@ void JoinAlgo::try_to_join() {
|
||||
}
|
||||
}
|
||||
|
||||
Price JoinAlgo::get_price_to_pass (Price price) const{
|
||||
Price rv;
|
||||
switch (me->status) {
|
||||
case Status::WAITING_FOR_MD:
|
||||
case Status::WAITING_TO_JOIN:
|
||||
rv = price;
|
||||
break;
|
||||
case Status::JOINED:
|
||||
rv = me->joined_price;
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void JoinAlgo::update_join_threshold() {
|
||||
me->min_quantity_to_join = SpreaderUtils::_quantity_threshold(
|
||||
algo().definition().custom_def().join().join_threshold(), algo().quantity());
|
||||
|
||||
@@ -31,6 +31,7 @@ private:
|
||||
void update_join_threshold();
|
||||
bool has_running_child() const;
|
||||
void try_to_join();
|
||||
Price get_price_to_pass (Price price) const;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -28,6 +28,7 @@ struct LeanAlgo::PImpl {
|
||||
Book curr_book;
|
||||
Price out_price = Price(os::nan());
|
||||
Quantity out_qty = Quantity(0);
|
||||
Price cross_price = Price(os::nan());
|
||||
};
|
||||
|
||||
LeanAlgo::LeanAlgo() : me(new PImpl()) {}
|
||||
@@ -79,7 +80,8 @@ void LeanAlgo::do_update(const api::orderman::Update &update) {
|
||||
return;
|
||||
}
|
||||
Update child_update;
|
||||
child_update.set_price(update.price());
|
||||
Price price_to_pass = _get_price_to_pass(Price(update.price()));
|
||||
child_update.set_price(price_to_pass.value());
|
||||
child_update.set_quantity(update.quantity());
|
||||
if (update.has_custom()) {
|
||||
auto &lean_update = update.custom().lean();
|
||||
@@ -195,6 +197,13 @@ LeanAlgo::MarketChange LeanAlgo::_market_change() const{
|
||||
else
|
||||
return MarketChange::SIZE_CHANGE;
|
||||
}
|
||||
Price LeanAlgo::_get_price_to_pass (Price price) const{
|
||||
// if it has crossed once, then the
|
||||
// child order is always passed that price
|
||||
if(!os::is_nan(me->cross_price.value()))
|
||||
return me->cross_price;
|
||||
return price;
|
||||
}
|
||||
// actions ////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void LeanAlgo::_analyze_and_act() {
|
||||
@@ -298,8 +307,9 @@ void LeanAlgo::_udpate_out_price_qty(Price price, Quantity qty){
|
||||
}
|
||||
bool LeanAlgo::_modify_price_price_qty(Price price, Quantity qty){
|
||||
if(me->out_price.value()!=price.value() ||
|
||||
me->out_qty.value()!=qty.value()){
|
||||
_udpate_out_price_qty(price,qty);
|
||||
me->out_qty.value()!=qty.value()){
|
||||
_udpate_out_price_qty(price,qty);
|
||||
me->cross_price = price;
|
||||
Update child_update;
|
||||
child_update.set_price(price.value()),
|
||||
child_update.set_quantity(qty.value());
|
||||
|
||||
@@ -34,7 +34,8 @@ class LeanAlgo : public IAlgoOrder {
|
||||
api::Side _opp_side() const;
|
||||
bool _within_chase_band(Price price) const;
|
||||
Price _chase_limit() const;
|
||||
MarketChange _market_change() const;
|
||||
MarketChange _market_change() const;
|
||||
Price _get_price_to_pass (Price price) const;
|
||||
void _analyze_and_act();
|
||||
bool _try_cross(Price);
|
||||
void _go_furthest_possible();
|
||||
|
||||
@@ -366,6 +366,22 @@ void SpreaderOrder::_send_hedge(size_t hedge_leg_index,
|
||||
hedge_price,
|
||||
hedge_qty);
|
||||
}
|
||||
void SpreaderOrder::_compute_nlegs_crossed_hedges(size_t filled_leg_index,
|
||||
Price filled_price,
|
||||
double filled_quantity){
|
||||
SpreaderBookkeepingData& bk_data = _bookkeeping_data();
|
||||
const LegPropertyData& q_leg_data =
|
||||
bk_data.get_leg_data(filled_leg_index).leg_property_data();
|
||||
const ISpreaderManager& spreader = *this;
|
||||
SpreaderUtils::compute_nlegs_crossed_hedges(bk_data.side(),
|
||||
bk_data.effective_price(),
|
||||
bk_data.n_legs(),
|
||||
q_leg_data,
|
||||
filled_price,
|
||||
filled_quantity,
|
||||
spreader,
|
||||
bk_data.nlegs_crossed_hedges());
|
||||
}
|
||||
void SpreaderOrder::_compute_hedge_price_quantity(size_t filled_leg_index,
|
||||
Price fill_price,
|
||||
double fill_quantity,
|
||||
@@ -386,15 +402,13 @@ void SpreaderOrder::_compute_hedge_price_quantity(size_t filled_leg_index,
|
||||
hedge_quantity);
|
||||
else{
|
||||
const QuoteLegDriver& driver_data = filled_leg_data.quoter().driver_data(quote_order_price, hedge_leg_index);
|
||||
// QuoteLegDriver driver_data;
|
||||
// driver_data.set(quote_order_price,Quantity(1),Quantity(1));
|
||||
SpreaderUtils::compute_hedge_price_size_n_legs (filled_leg_data.leg_property_data(),
|
||||
fill_price,
|
||||
fill_quantity,
|
||||
hedged_leg_data.leg_property_data(),
|
||||
driver_data,
|
||||
computed_hedge_price,
|
||||
hedge_quantity);
|
||||
hedge_quantity);
|
||||
}
|
||||
hedge_price = SpreaderUtils::apply_pre_hedge_parameters (hedged_leg_data.leg_property_data().leg_params().pre_hedge_params(),
|
||||
hedged_leg_data.book(),
|
||||
|
||||
@@ -233,6 +233,13 @@ private:
|
||||
void _send_hedge(size_t hedge_leg_index,
|
||||
Price hedge_price,
|
||||
Quantity hedge_qty);
|
||||
// computes the hedges in the case of nlegs
|
||||
// from crossing the hedge markets. If the
|
||||
// crossing doesnt result in better hedge prices
|
||||
// 0's are stored in the qty's in
|
||||
void _compute_nlegs_crossed_hedges(size_t filled_leg_index,
|
||||
Price filled_price,
|
||||
double filled_quantity);
|
||||
void _compute_hedge_price_quantity(size_t filled_leg_index,
|
||||
Price filled_price,
|
||||
double filled_quantity,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "SpreaderBookkeepingData.h"
|
||||
#include "lib/os/os.h"
|
||||
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
@@ -18,12 +19,14 @@ SpreaderBookkeepingData::SpreaderBookkeepingData (
|
||||
_inited_new (inited_new),
|
||||
_n_legs(legs.size()),
|
||||
_n_quoting_legs(_calc_n_quoting_legs(legs)),
|
||||
_side(order_def.side()),
|
||||
_order_def(order_def),
|
||||
_reported_state(){
|
||||
LOG(OrderMan, Info, "SpreaderBookkeepingData.cons started "
|
||||
"key: {} n_legs: {}",
|
||||
spreader_order_key.value(), _n_legs);
|
||||
_leg_data.reserve(_n_legs);
|
||||
_nlegs_crossed_hedges.reserve(_n_legs);
|
||||
size_t i=0;
|
||||
for (const auto& leg_property_data : legs){
|
||||
_leg_data.emplace_back(spreader_pao_services,
|
||||
@@ -33,6 +36,7 @@ _reported_state(){
|
||||
quoter_ord_defs[i],
|
||||
hedger_ord_defs[i],
|
||||
leg_property_data);
|
||||
_nlegs_crossed_hedges.emplace_back(std::pair<Price, double>(os::nan(),0.0));
|
||||
bts_assert (_sec_key_to_index.find(leg_property_data.security_key())
|
||||
== _sec_key_to_index.end());
|
||||
_sec_key_to_index.insert(std::pair<uint32_t, size_t>(
|
||||
|
||||
@@ -24,6 +24,7 @@ private:
|
||||
const bool _inited_new;
|
||||
const size_t _n_legs;
|
||||
const size_t _n_quoting_legs;
|
||||
const api::Side _side;
|
||||
// when the order is not created from the disk
|
||||
// (ie created live) this is set to true
|
||||
const api::orderman::OrderDefinition _order_def;
|
||||
@@ -35,6 +36,10 @@ private:
|
||||
Price _input_price;
|
||||
Price _effective_price;
|
||||
Quantity _quantity;
|
||||
// this is used to pass in the calcuated hedge price/qty
|
||||
// (preallocating so we dont have to allocate
|
||||
// memory when calculating and calculating values)
|
||||
std::vector<std::pair<Price,double>> _nlegs_crossed_hedges;
|
||||
private:
|
||||
size_t _calc_n_quoting_legs(const std::vector<LegPropertyData>& legs);
|
||||
public:
|
||||
@@ -61,10 +66,14 @@ public:
|
||||
/////////////////////////////////
|
||||
size_t n_legs() const { return _n_legs; }
|
||||
bool all_legs_resolved() const {return n_legs() > 0;}
|
||||
api::Side side() const {return _side;}
|
||||
const api::orderman::OrderDefinition& order_def() const {return _order_def;}
|
||||
Price input_price () const {return _input_price;}
|
||||
Price effective_price () const {return _effective_price;}
|
||||
Quantity quantity () const {return _quantity;}
|
||||
std::vector<std::pair<Price,double>>& nlegs_crossed_hedges(){
|
||||
return _nlegs_crossed_hedges;
|
||||
}
|
||||
// gets leg data from leg's sec key
|
||||
SpreaderLegData& get_leg_data (SecurityKey security_key){
|
||||
boost::container::flat_map<uint32_t, size_t>::const_iterator l_it = _sec_key_to_index.find(security_key.value());
|
||||
|
||||
@@ -121,7 +121,8 @@ public:
|
||||
void static traverse_depth_for_quantity(const orderman::Book& leg_book,
|
||||
const api::Side book_side,
|
||||
Quantity target_quantity,
|
||||
Price& out_price, Quantity& out_quantity){
|
||||
Price& out_price,
|
||||
Quantity& out_quantity){
|
||||
uint32_t cum_quantity_u = 0;
|
||||
const size_t n_levels = leg_book.n_levels();
|
||||
// we could have kept a running price, updated at each level,
|
||||
@@ -793,6 +794,47 @@ public:
|
||||
quote_fill_quantity,
|
||||
hedge_leg);
|
||||
}
|
||||
static bool compute_nlegs_crossed_hedges(
|
||||
api::Side spr_side,
|
||||
Price spr_price,
|
||||
size_t n_legs,
|
||||
const LegPropertyData& q_leg,
|
||||
Price q_fill_price,
|
||||
double q_fill_qty,
|
||||
const ISpreaderManager& spreader,
|
||||
std::vector<std::pair<Price,double>>& out_drivers){
|
||||
// spr_cross_price is the spreader price computed by
|
||||
// crossing all the hedges ie
|
||||
// spr_cross_price=sum(ratio*price) where for the filled leg
|
||||
// it is the fill price and for the hedging legs
|
||||
// it is the cross that satisifies the size
|
||||
double spr_cross_price=q_fill_price.value()*q_leg.price_multiplier();
|
||||
for (size_t i=0;i<n_legs;i++)
|
||||
if(i!=q_leg.leg_index()){
|
||||
Price hedge_price;
|
||||
Quantity hedge_qty;
|
||||
const auto& hedge_leg=spreader.get_leg_data(i);
|
||||
double hedge_qty_needed_raw =
|
||||
get_leg_quantity_from_another_leg_quantity(q_leg,
|
||||
q_fill_qty,
|
||||
hedge_leg);
|
||||
Quantity hedge_qty_needed_rounded_up =
|
||||
Quantity(_round_hedge_target(hedge_qty_needed_raw));
|
||||
traverse_depth_for_quantity(
|
||||
spreader.get_book(i),
|
||||
invert_side(hedge_leg.trading_side()),
|
||||
hedge_qty_needed_rounded_up,
|
||||
hedge_price,
|
||||
hedge_qty);
|
||||
if(hedge_qty.value()<hedge_qty_needed_rounded_up.value())
|
||||
return false;
|
||||
spr_cross_price += hedge_price.value()*hedge_leg.price_multiplier();
|
||||
auto& driver_i=out_drivers[i];
|
||||
driver_i.first=hedge_price;
|
||||
driver_i.second=hedge_qty_needed_raw;
|
||||
}
|
||||
return securities::is_better(spr_side,Price(spr_cross_price),spr_price);
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
// Rounding functions //////////////////////////////
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ $ cd spark_sdk
|
||||
|
||||
### Development
|
||||
|
||||
Algo Orders typically implement the IAlgoOrder interface to respond to events and use the IAlgoServices interface to create and control child orders as well as manage their own life cycles. See [examples/order_plugin_example.cpp](examples/order_plugin_example.cpp) for a fully fledged example
|
||||
Algo Orders typically implement the [IAlgoOrder](include/spark/lib/orderman/orders/algo/IAlgoOrder.h) interface to respond to events and use the [IAlgoServices](include/spark/lib/orderman/orders/algo/IAlgoServices.h) interface to create and control child orders as well as manage their own life cycles. See [examples/order_plugin_example.cpp](examples/order_plugin_example.cpp) for a fully fledged example
|
||||
|
||||
Look at [examples/md_publisher_example.cpp](examples/md_publisher_example.cpp) to look at how to build a custom market data producer
|
||||
|
||||
|
||||
Reference in new issue
Block a user