diff --git a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
index fc8977181..49bfb654f 100644
--- a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
+++ b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml
@@ -420,7 +420,6 @@
-
, IHaveFontParams
+ {
+ IDictionary _value_store = new Dictionary();
+ public QuoteQueueHolderModel()
+ {
+ }
+ public override string display_name { get; } = "Queue Holder Length";
+ public override string help_text { get; } = "How many levels of queue to hold";
+ public override string man_page { get; } = string.Empty;
+ public override ParameterSection[] section_path { get; } = new[] { Sections.Quote };
+ public FontWeight font_weight => FontWeights.SemiBold;
+
+ public void apply_value(LegSpreaderParamsTuple leg_tup) =>
+ leg_tup.leg_params.QuoteParams.NQueueHolderOrders = _value_from_store(leg_tup);
+
+ public override uint get_value(LegSpreaderParamsTuple leg_tup) =>
+ _get_value(leg_tup).NQueueHolderOrders;
+
+ public override void set_value(LegSpreaderParamsTuple leg_tup, uint value)
+ {
+ _value_store[leg_tup.SecurityKey] = value;
+ leg_tup.leg_params.QuoteParams.NQueueHolderOrders = value ;
+ }
+
+ protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
+ _get_value(leg_tup) != null;
+
+ QuoteParams _get_value(LegSpreaderParamsTuple leg_tup) =>
+ leg_tup.leg_params.QuoteParams;
+
+ uint _value_from_store(LegSpreaderParamsTuple leg_tup) =>
+ _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => 0u);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
index 334651129..297cf49d9 100644
--- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
+++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs
@@ -200,14 +200,16 @@ namespace mbts.spark {
var post_hedge_opposite_market_based_cross_threshold = new PostHedgeOppositeMarketVolumeBasedCrossThresholdModel();
var post_hedge_opposite_market_based_cross_cross_ticks = new PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel();
+ var is_quote_model = new IsQuoteModel();
rows = new IRowModel[] {
_quantity_model,
_price_mult_model,
- new IsQuoteModel(),
+ is_quote_model,
//new EnableHedgeModel(), //TAHA_SPREADER
new HedgeRatioModel(),
//new MinLeanQtyModel(), //TAHA_SPREADER
//new QuoteHiddenModel(),
+ new QuoteQueueHolderModel(),
new MarketDataTypeModel(),
new QuoteThrottleEnabledModel(quote_throttle_inside_ticks, quote_throttle_outside_ticks),
quote_throttle_inside_ticks,
diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs
index 2f0b8baa7..33c002cb8 100644
--- a/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs
+++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderOrderVM.cs
@@ -37,6 +37,7 @@ namespace mbts.spark {
readonly Property _foreground, _background, _hoverbackground, _border;
readonly Property _has_multiple_orders_at_same_level, _is_hedge_order;
readonly Property _algo_type;
+ readonly Property _algo_studio_abbreviation;
IObservable _bs;
LadderSettings.BadgeStyle _current_badge_style;
int _n_active_price_change_ops = 0;
@@ -45,9 +46,9 @@ namespace mbts.spark {
int working_quantity;
LadderModel model => _owner.model;
- Dictionary _orders = new Dictionary();
+ Dictionary _orders = new Dictionary();
- public LadderOrderVM((OrderRecordImmutable, uint?) op, double real_price, LadderVM owner, IBus bus, IObservable bs) {
+ public LadderOrderVM((OrderRecordImmutable, uint?, AlgoDefinitionMetadata?) op, double real_price, LadderVM owner, IBus bus, IObservable bs) {
_owner = owner;
_bus = bus;
_bs = bs;
@@ -64,6 +65,7 @@ namespace mbts.spark {
_has_multiple_orders_at_same_level = backing(nameof(has_multiple_orders_at_same_level), false);
_is_hedge_order = backing(nameof(is_hedge_order), false);
_algo_type = backing(nameof(algo_type), CustomOrderDefinition.CustomOneofCase.None);
+ _algo_studio_abbreviation = backing(nameof(algo_studio_abbreviation), string.Empty);
FontFamily get_font_family(LadderSettings s) => new FontFamily(s.orders_column.font_family);
FontWeight get_font_weight(LadderSettings s) => ui.utility.text.TextUtils.from_open_type_weight_safe(s.orders_column.font_weight);
double get_font_size(LadderSettings s) => s.orders_column.font_size;
@@ -111,6 +113,10 @@ namespace mbts.spark {
var single_order = _root_nodes().First();
var single_order_metadata = _owner.model.order_gateway.factory.get_metadata(single_order);
border = single_order_metadata.Color.rgb_brush();
+ if (_orders.TryGetValue(single_order.Key, out var opm)) {
+ algo_studio_abbreviation = opm.meta?.abbreviation ?? string.Empty;
+ border = opm.meta?.badge_color?.rgb_color().rgb_brush() ?? border;
+ }
if (single_order.order_type().is_bts_algo_type()) {
algo_type = single_order.order_type();
} else {
@@ -132,7 +138,7 @@ namespace mbts.spark {
RaisePropertyChanged(nameof(text_lines));
}
- public void add_order((OrderRecordImmutable order, uint? p) new_op) {
+ public void add_order((OrderRecordImmutable order, uint? p, AlgoDefinitionMetadata? meta) new_op) {
_orders[new_op.order.Key] = new_op;
}
@@ -186,6 +192,7 @@ namespace mbts.spark {
public bool has_multiple_orders_at_same_level { get => _has_multiple_orders_at_same_level.Value; private set => _has_multiple_orders_at_same_level.Value = value; }
public bool is_hedge_order { get => _is_hedge_order.Value; private set => _is_hedge_order.Value = value; }
public CustomOrderDefinition.CustomOneofCase algo_type { get => _algo_type.Value; private set => _algo_type.Value = value; }
+ public string algo_studio_abbreviation { get => _algo_studio_abbreviation.Value; private set => _algo_studio_abbreviation.Value = value; }
public IReadOnlyList order_keys => _orders.Keys.ToReadOnlyList();
public IEnumerable root_orders => _root_nodes();
diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
index 56e3ff166..6972c606b 100644
--- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
+++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
@@ -145,10 +145,25 @@ namespace mbts.spark {
account_positions,
size_calculator = new CalculatorLogic(0, _settings_manager.subscribe_current().Select(s => s.calculator_buttons)),
bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update),
+ // we need to hook this up to model.orders which is filtered for just the security
model.order_gateway.working_orders_with_piq.OnDispatcher().Subscribe(working => {
// Here we manage N orders to 1 price slot in the ladder
Dictionary> orders_used_in_this_update = new Dictionary>(_equality);
- _cache = working;
+
+ // In master we originally had something similar to this snippet to restrict the foreach to just the orders
+ // for this ladder. In 1944, at one point we made use of model.orders, which made use of the on_security_working_orders demuxer.
+ // When we merged PIQ into 1944, we moved from that demuxer to working_orders_with_piq, so we reintroduce this little snippet here
+ // to once again restrict the processing to those working orders that match the criteria. Check with John to see if we can
+ // make a demuxer from working_orders_with_piq, which is an IReadOnlyDictionary; that probably won't work, but I have no doubt
+ // there is a better way.
+ var ladders_orders =
+ working.Values
+ .Where(o =>
+ o.order.Def.SecurityKey == security.Id &&
+ (o.order.HasState && o.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible))
+ .ToReadOnlyDictionary(os => os.order.Key, os => os);
+
+ _cache = ladders_orders;
foreach (var os in _cache.Values) {
var wo = os.order;
@@ -165,9 +180,9 @@ namespace mbts.spark {
}
if (_slot_price_vs_orders.TryGetValue(slot_price_target, out LadderOrderVM slot_vm)) {
- slot_vm.add_order((wo, os.piq));
+ slot_vm.add_order((wo, os.piq, os.meta));
} else {
- slot_vm = new LadderOrderVM((wo, os.piq), slot_price_target, this, _bus, _settings_manager.subscribe_current().Select(s => s.badge_style));
+ slot_vm = new LadderOrderVM((wo, os.piq, os.meta), slot_price_target, this, _bus, _settings_manager.subscribe_current().Select(s => s.badge_style));
_slot_price_vs_orders[slot_price_target] = slot_vm;
}
@@ -311,7 +326,7 @@ namespace mbts.spark {
public uint volume_column_width { get => _volume_column_width.Value; set => _volume_column_width.set(value); }
internal LadderModel model => _model;
internal IObservable settings => _settings_manager.subscribe_current();
- internal OrderRecordImmutable get_root_at_price((OrderRecordImmutable order, uint? _) op) {
+ internal OrderRecordImmutable get_root_at_price((OrderRecordImmutable order, uint? _, AlgoDefinitionMetadata? meta) op) {
var order = op.order;
double p = order.price();
foreach (var o in lineage(order.ParentKey)) {
diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
index f5355fd6b..7b4a662c2 100644
--- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
+++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml
@@ -489,6 +489,15 @@
+
+
+
+
+ Auto Clear
+
+
-
-
-
-
- Auto Clear
-
+
diff --git a/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml
index 140c0ad25..1aed887d6 100644
--- a/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml
+++ b/src/client/spark/Modules/Trading/Ladder/View/MiniLadderView.xaml
@@ -103,6 +103,7 @@
+
diff --git a/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml b/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml
index 59bb34cdc..751bca859 100644
--- a/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml
+++ b/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml
@@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:sp="clr-namespace:mbts.spark"
- xmlns:uc="clr-namespace:mbts.ui"
+ 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"
@@ -49,19 +49,57 @@
- -->
+
diff --git a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookGridSettings.cs b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookGridSettings.cs
index 06eb8d9f9..9acce32ff 100644
--- a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookGridSettings.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookGridSettings.cs
@@ -6,6 +6,7 @@ using mbts.ui;
using ProtoBuf;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using GridSettings = mbts.ui.settings.GridSettings;
namespace bts.shell.orderbook {
@@ -16,6 +17,7 @@ namespace bts.shell.orderbook {
[ProtoContract]
class OrderBookGridSettings : IGridSettingsWithNotifications, IEquatable {
+ const AlgoTreeDisplayMode _default_algo_tree_display_mode = AlgoTreeDisplayMode.FullTree;
// general
[ProtoMember(1)]
public GridSettings general { get; set; }
@@ -24,9 +26,11 @@ namespace bts.shell.orderbook {
List _predicate_animations;
// algo tree display mode
[ProtoMember(3)]
+ [DefaultValue(_default_algo_tree_display_mode)]
public AlgoTreeDisplayMode algo_tree_display_mode { get; set; }
- public OrderBookGridSettings() { }
+ public OrderBookGridSettings() =>
+ algo_tree_display_mode = _default_algo_tree_display_mode;
public OrderBookGridSettings(GridSettings general = default, IEnumerable predicate_animations = null) {
this.general = general;
diff --git a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
index e059755e0..619b8bf5d 100644
--- a/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/Settings/OrderBookSettings.cs
@@ -114,7 +114,10 @@ namespace bts.shell.orderbook {
fills_settings = DefaultFillsGrid
};
- public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid);
+ public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid) {
+ algo_tree_display_mode = AlgoTreeDisplayMode.RootAndLeafNodes
+ };
+
public static OrderBookFillsGridSettings DefaultFillsGrid {
get {
var default_fills = FillsWindowFactory.StartupData.Default();
diff --git a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml
index c6bc3dd1f..94f2043e5 100644
--- a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml
+++ b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml
@@ -111,19 +111,56 @@
- -->
diff --git a/src/client/spark/Orders/OrderDataHelper.cs b/src/client/spark/Orders/OrderDataHelper.cs
index 1abad75be..b9aa61c27 100644
--- a/src/client/spark/Orders/OrderDataHelper.cs
+++ b/src/client/spark/Orders/OrderDataHelper.cs
@@ -244,6 +244,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Trigger: rv.Trigger = trigger_order(); break;
case CustomOrderDefinition.CustomOneofCase.Spreader: rv.Spreader = spreader_order(); break;
case CustomOrderDefinition.CustomOneofCase.Dynamic: rv.Dynamic = dynamic_order(); break;
+ //case CustomOrderDefinition.CustomOneofCase.QueueHolder: rv.QueueHolder = queue_holder_order(); break;
}
return rv;
}
@@ -270,6 +271,7 @@ namespace mbts.spark.utilities {
case CustomOrderDefinition.CustomOneofCase.Spreader: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.spreader_order };
case CustomOrderDefinition.CustomOneofCase.Dynamic: return new OrderMetadata { KeyBinding = "", Color = BTSColors.Orders.top_order };
case CustomOrderDefinition.CustomOneofCase.None: goto default;
+ //case CustomOrderDefinition.CustomOneofCase.QueueHolder: return new OrderMetadata { KeyBinding = "Q", Color = BTSColors.purple.rgb_color() };
default: return _default_order_metadata;
}
}
@@ -955,18 +957,6 @@ namespace mbts.spark.utilities {
public static class Defaults {
// param types
public static QuantityMeasure QuantityMeasure => new QuantityMeasure { Absolute = 1 };
- public static PriceType PriceType => new PriceType { Status = PriceType.Types.Status.Bid };
- public static PriceOffset PriceOffset => new PriceOffset { PriceType = PriceType };
- public static QuantityTrigger QuantityTrigger => new QuantityTrigger { QuantityMeasure = QuantityMeasure, LessThanEqualto = true };
- public static bts.spark.AbsolutePriceTrigger AbsolutePriceTrigger => new bts.spark.AbsolutePriceTrigger { PriceType = PriceType, QuantityTrigger = QuantityTrigger };
- public static bts.spark.TrailingTrigger TrailingTrigger => new bts.spark.TrailingTrigger { PriceType = PriceType, Stop = true };
- public static PriceTrigger PriceTrigger => new PriceTrigger { AbsolutePriceTrigger = AbsolutePriceTrigger, TrailingTrigger = TrailingTrigger };
- public static OrderTime OrderTime => new OrderTime { Now = true };
- public static BTSTimedWindowParameters TimeWindow => new BTSTimedWindowParameters { Cancel = true, StartTime = OrderTime, StopTime = new OrderTime() };
- public static BTSWithATickParameters WithATick => new BTSWithATickParameters { QuantityThreshold = QuantityMeasure };
- public static BTSStopOrder BTSStopOrder => new BTSStopOrder { LimitOrder = new LimitOrder(), Price = 1, PriceTrigger = PriceTrigger, OptionalTimedParameters = TimeWindow, OptionalWithatickParameters = WithATick };
- public static BTSIcebergOrder BTSIcebergOrder => new BTSIcebergOrder { DisplayQuantity = QuantityMeasure, MarketOffset = PriceOffset, PriceTrigger = PriceTrigger, TimedWindowParameters = TimeWindow, WithatickParameters = WithATick };
-
// core data types
public static AlgoData AlgoData() => new AlgoData(CustomOrderDefinitionImmutable());
public static AlgoData AlgoData(CustomOrderDefinition.CustomOneofCase algo_type) => new AlgoData(CustomOrderDefinitionImmutable(algo_type));
diff --git a/src/client/spark/Orders/OrderSecurity.cs b/src/client/spark/Orders/OrderSecurity.cs
index 7045f2fe4..91c5aaeb1 100644
--- a/src/client/spark/Orders/OrderSecurity.cs
+++ b/src/client/spark/Orders/OrderSecurity.cs
@@ -3,21 +3,34 @@ using mbts.spark;
using System;
namespace bts.api.orderman {
- public readonly struct OrderSecurity: IEquatable {
+ readonly struct OrderSecurity: IEquatable {
public OrderSecurity(SecurityImmutable? sec, OrderRecordImmutable order) {
this.security = sec;
this.order = order;
piq = null;
+ algo = null;
+ meta = null;
}
public OrderSecurity((SecurityImmutable? sec, OrderRecordImmutable order) t) {
security = t.sec;
order = t.order;
piq = null;
+ algo = null;
+ meta = null;
}
public OrderSecurity(SecurityImmutable? sec, OrderRecordImmutable order, uint? piq) {
this.security = sec;
this.order = order;
this.piq = piq;
+ algo = null;
+ meta = null;
+ }
+ public OrderSecurity(SecurityImmutable? sec, OrderRecordImmutable order, uint? piq, AlgoData? algo, AlgoDefinitionMetadata? meta) {
+ this.security = sec;
+ this.order = order;
+ this.piq = piq;
+ this.algo = algo;
+ this.meta = meta;
}
//public OrderSecurity(OrderSecurity t) {
// security = t.security;
@@ -28,6 +41,10 @@ namespace bts.api.orderman {
public SecurityImmutable? security { get; }
public OrderRecordImmutable order { get; }
public uint? piq { get; }
+ public AlgoData? algo { get; }
+ public AlgoDefinitionMetadata? meta { get; }
+
+
public override bool Equals(object obj) => (obj is OrderSecurity os) && Equals(os);
public bool Equals(OrderSecurity other) => order.Equals(other.order) && security == other.security && piq == other.piq;
diff --git a/src/client/spark/Orders/OrderTypeVMs/QueueHolderOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/QueueHolderOrderVM.cs
new file mode 100644
index 000000000..e69ce480b
--- /dev/null
+++ b/src/client/spark/Orders/OrderTypeVMs/QueueHolderOrderVM.cs
@@ -0,0 +1,168 @@
+// using bts.api;
+// using bts.api.orderman;
+// using mbts.ui;
+// using mbts.ui.utility;
+// using mbts.utils;
+// using System;
+// using System.Collections.Generic;
+// using System.Collections.ObjectModel;
+// using System.ComponentModel;
+// using System.Linq;
+// using System.Reactive.Linq;
+// using static bts.api.orderman.CustomOrderDefinition;
+
+// namespace mbts.spark
+// {
+// static partial class OrderTypeVMFactory
+// {
+// class InlineQueueHolderOrderProperties
+// {
+// public InlineQueueHolderOrderProperties(OrderTemplateHeader selected_child_order_type, IReadOnlyCollection child_order_types)
+// {
+// ExceptionAssert.InvalidOperation.That(child_order_types.Contains(selected_child_order_type), $"Child order type {selected_child_order_type} is not in child_order_types");
+// this.selected_child_order_type = new InlineUserProperty(selected_child_order_type, true);
+// this.child_order_types = new InlineUserProperty>(child_order_types, true);
+
+// stack_len = new InlineUserProperty(1, false);
+// }
+// public readonly InlineUserProperty selected_child_order_type;
+// public readonly InlineUserProperty> child_order_types;
+
+// public readonly InlineUserProperty stack_len;
+// }
+
+// class QueueHolderOrderVM : OrderTypeVMBase, IHierarchicalOrderTypeVM, IDisposable
+// {
+// readonly IObservable _security_md_source;
+// SecurityImmutable? _security;
+// ObservableCollection _order_types = new ObservableCollection();
+// ObservableAutoWrapper _child_order_choices;
+// InlineQueueHolderOrderProperties _inline_props;
+// IOrderTypeVM _child_order;
+// IDisposable _dispose, _child_order_errors_sub;
+
+// public uint stack_len { get; set; } = 1;
+
+// public QueueHolderOrderVM(OrdersModel model, IObservable security_md_source, string id, string display_name)
+// : this(model, security_md_source, security_md_source.Select(smd =>
+// new InlineQueueHolderOrderProperties(new OrderTemplateHeader(model.factory.default_order_type(smd.security)), model.factory.default_order_types(smd.security).Select(t => new OrderTemplateHeader(t)).ToList())), id, display_name)
+// { }
+
+// public QueueHolderOrderVM(OrdersModel model, IObservable security_md_source,
+// IObservable inline_properties, string id, string display_name) : base(model, id, display_name)
+// {
+// _security_md_source = security_md_source;
+// _dispose = Disposable.Create(
+// security_md_source.OnDispatcher()
+// .Subscribe(smd => _security = smd.security),
+// inline_properties.OnDispatcher()
+// .Subscribe(p =>
+// {
+// if (_order_types.Count == 0 || p.child_order_types.force_override)
+// {
+// _order_types.SetItems(p.child_order_types.value);
+// }
+// if (_child_order_choices != null && (_child_order == null || p.selected_child_order_type.force_override))
+// {
+// _select_child_order(p.selected_child_order_type.value.key.type);
+// }
+// if (p.stack_len.force_override)
+// {
+// stack_len = p.stack_len.value;
+// RaisePropertyChanged(nameof(stack_len));
+// }
+// _inline_props = p;
+// _validate();
+// })
+// );
+// _validate();
+// }
+
+// public override void assign_to(CustomOrderDefinition value)
+// {
+// if (_child_order == null)
+// _select_child_order(model.factory.default_order_type(_security.Value, true));
+// _validate();
+// if (!HasErrors)
+// {
+// var i = factory.queue_holder_order();
+// i.NQueueOrders = stack_len;
+// child_order.assign_to(i.Child);
+// value.QueueHolder = i;
+// }
+// }
+
+// public ICollection child_order_types
+// {
+// get
+// {
+// if (_child_order_choices == null)
+// _child_order_choices = new ObservableAutoWrapper(_order_types, ot => create(ot.key.type, ot.key.name, ot.display_name, model, _security_md_source));
+// return _child_order_choices;
+// }
+// }
+
+// public IOrderTypeVM child_order
+// {
+// get
+// {
+// init();
+// return _child_order;
+// }
+// set
+// {
+// Disposable.dispose(ref _child_order_errors_sub);
+// _child_order = value;
+// _child_order?.init();
+// if (_child_order is INotifyDataErrorInfo ndei)
+// {
+// ndei.ErrorsChanged += on_errors_changed;
+// void on_errors_changed(object s, DataErrorsChangedEventArgs e) =>
+// _validate();
+// _child_order_errors_sub = Disposable.Create(() => ndei.ErrorsChanged -= on_errors_changed);
+// }
+// _validate();
+// RaisePropertyChanged(nameof(child_order));
+// }
+// }
+
+
+// public void Dispose()
+// {
+// Disposable.dispose(ref _dispose);
+// if (_child_order_choices != null)
+// _child_order_choices.OfType().DisposeAll();
+// }
+
+// public override void init()
+// {
+// if (_child_order == null && _security.HasValue)
+// _select_child_order();
+// _validate();
+// }
+
+// void _select_child_order()
+// {
+// CustomOneofCase ot = _inline_props != null && _inline_props.selected_child_order_type.has_value ?
+// _inline_props.selected_child_order_type.value.key.type :
+// model.factory.default_order_type(_security.Value, true);
+// _select_child_order(ot);
+// }
+
+// void _select_child_order(CustomOneofCase ot)
+// {
+// _child_order = child_order_types.FirstOrDefault(vm => vm.order_type == ot);
+// if (_child_order == null)
+// _child_order = child_order_types.FirstOrDefault();
+// RaisePropertyChanged(nameof(child_order));
+// }
+
+// void _validate()
+// {
+// if (_child_order == null || (_child_order is INotifyDataErrorInfo ndei && ndei.HasErrors))
+// set_error(nameof(child_order), string.Empty, true);
+// else clear_error(nameof(child_order));
+// }
+// }
+// }
+// }
\ No newline at end of file
diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs
index 5b17779b8..fe059c688 100644
--- a/src/client/spark/Orders/OrdersModel.cs
+++ b/src/client/spark/Orders/OrdersModel.cs
@@ -38,8 +38,6 @@ namespace mbts.spark {
readonly DynamicOrderHelper _dynamic_helper;
readonly OrderActivitySummarizer _activity;
readonly TableUpdateDemuxer _security_orders_demuxer, _security_working_orders_demuxer;
- // we need a new one of these for the time being since the ladder is subscribing to orders with piq
- readonly TableUpdateDemuxer _security_orders_piq_demuxer;
readonly TableUpdateDemuxer _security_positions_demuxer;
IDisposable _dispose;
static readonly bool _piq_enabled = Configuration.get().enabled;
@@ -69,24 +67,6 @@ namespace mbts.spark {
.Table()
.Cache();
- if (_piq_enabled) {
- on_orders_with_piq = on_orders
- .LeftJoin<
- (SecurityImmutable?, OrderRecordImmutable),
- OrderPIQImmutable,
- OrderSecurity,
- uint
- >(mbo_service.subscribei_piq().Table(),
- si_ort => si_ort.Item2.Key,
- p => p.OrderId,
- (si_ort, r, p) => new OrderSecurity(si_ort.Item1, si_ort.Item2, p.Position),
- (si_ort, r) => new OrderSecurity(si_ort.Item1, si_ort.Item2, null),
- osp => osp.order.Key);
- } else {
- on_orders_with_piq = on_orders
- .Select((ft) => new OrderSecurity(ft.Item1, ft.Item2, null), os => os.order.Key);
- }
-
on_positions = _position_service.subscribei_position_data().Naggle(interval, scheduler).PermissionFilter(admin_model.on_admin_data).Table().Cache();
working_orders =
on_orders.Scan(
@@ -94,13 +74,6 @@ namespace mbts.spark {
(workers, table) => _update_working_orders(workers, table))
.Replay(1).RefCount();
- working_orders_with_piq =
- on_orders_with_piq.Scan(
- ImmutableDictionary.Empty,
- (workers, table) => _update_working_orders(workers, table))
- .Replay(1).RefCount();
-
-
on_order_securities =
on_orders
.as_iincremental()
@@ -109,7 +82,6 @@ namespace mbts.spark {
_activity = new OrderActivitySummarizer(bus, on_orders);
_security_orders_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key());
- _security_orders_piq_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key());
_security_working_orders_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key());
_security_positions_demuxer = new TableUpdateDemuxer(o => o.RecordId, p => p.SecurityId);
var algo_meta_join = algo_model.definitions.LeftJoin(
@@ -128,6 +100,27 @@ namespace mbts.spark {
(os, okey, mkey) => new OrderSecurityAlgoMeta(os.order, os.sec, null, null),
ot => ot.order.Key);
on_order_tuples = order_secs_algo_meta_join.Cache();
+
+ // need to bring back the config key check
+ on_order_tuples_with_piq = on_order_tuples.LeftJoin<
+ OrderSecurityAlgoMeta,
+ OrderPIQImmutable,
+ OrderSecurity,
+ uint
+ >(mbo_service.subscribei_piq().Table(),
+ osam => osam.order.Key,
+ piq => piq.OrderId,
+ (osam, _, p) => new OrderSecurity(osam.security, osam.order, p.Position, osam.algo, osam.meta),
+ (osam, _) => new OrderSecurity(osam.security, osam.order, null, osam.algo, osam.meta),
+ osp => osp.order.Key)
+ .Cache();
+
+ working_orders_with_piq =
+ on_order_tuples_with_piq.Scan(
+ ImmutableDictionary.Empty,
+ (workers, table) => _update_working_orders(workers, table))
+ .Replay(1).RefCount();
+
var on_fills =
_service.subscribei_fills()
.Naggle(interval, scheduler)
@@ -159,7 +152,6 @@ namespace mbts.spark {
.Cache();
_dispose = Disposable.Create(
on_orders.Select(t => t.order, o => o.Key).Subscribe(_security_orders_demuxer),
- on_orders_with_piq.Select(t => t.order, o => o.Key).Subscribe(_security_orders_piq_demuxer),
on_orders
.Filter(order => order.order.is_active() && order.order.HasState && order.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible, key => key.order.Key)
.Select(t => t.order, o => o.Key)
@@ -178,7 +170,7 @@ namespace mbts.spark {
public SpreaderModel spreader => _spreader;
public DynamicOrderHelper dynamic_helper => _dynamic_helper;
public IObservable on_orders { get; }
- public IObservable on_orders_with_piq { get; }
+ public IObservable on_order_tuples_with_piq { get; }
public IObservable> on_order_tuples { get; }
public IObservable, uint>> on_orders_can_detach { get; }
public IObservable, uint>> on_orders_can_attach { get; }
diff --git a/src/client/spark/core/FontsAndColors/BTSColors.cs b/src/client/spark/core/FontsAndColors/BTSColors.cs
index 0d23ad222..14009cbf7 100644
--- a/src/client/spark/core/FontsAndColors/BTSColors.cs
+++ b/src/client/spark/core/FontsAndColors/BTSColors.cs
@@ -157,13 +157,21 @@ namespace mbts.ui {
// 'sent' and 'filled_dark' are used in the ladder log viewer to indicate sent/filled orders (both buys and sells)
// 'default_background' and 'filled' seemed too pale against the log viewer's current style
// as we restyle the ladder, and perhaps the log viewer, maybe this will change, in the meantime, here they are.
- static readonly BTSColor _sent = new BTSColor(0x92, 0x5B, 0xBE), _working_order_background = new BTSColor(0xffedcdu);
+ static readonly BTSColor _sent = new BTSColor(0x92, 0x5B, 0xBE),
+ _working_order_background = new BTSColor(0xffedcdu),
+ _completed_order_background = new BTSColor(0xd6dbe0),
+ _error_order_background = new BTSColor(0xffd6d6),
+ _canceled_order_background = new BTSColor(0xffe4b2);
+
static Orders() {
_init_brush(_sent, out sent_brush);
_init_brush(filled_dark, out filled_dark_brush);
_init_brush(working_cancel, out working_cancel_brush);
_init_brush(working_order_background, out working_order_background_brush);
+ _init_brush(completed_order_background, out completed_order_background_brush);
+ _init_brush(error_order_background, out error_order_background_brush);
+ _init_brush(canceled_order_background, out canceled_order_background_brush);
_init_brush(modified, out modified_brush);
}
@@ -186,6 +194,13 @@ namespace mbts.ui {
public static BTSColor working_cancel_text { get { return BTSCoreColors.white; } }
public static BTSColor working_order_background => _working_order_background;
public static readonly Brush working_order_background_brush;
+ public static BTSColor completed_order_background => _completed_order_background;
+ public static readonly Brush completed_order_background_brush;
+
+ public static BTSColor error_order_background => _error_order_background;
+ public static readonly Brush error_order_background_brush;
+ public static BTSColor canceled_order_background => _canceled_order_background;
+ public static readonly Brush canceled_order_background_brush;
public static BTSColor filled { get { return BTSCoreColors.green_light_light_saturated; } }
public static BTSColor filled_dark => BTSCoreColors.green;
diff --git a/src/client/spark/core/Utility/ObservableDemuxer.cs b/src/client/spark/core/Utility/ObservableDemuxer.cs
index 556eaaef3..768fe419d 100644
--- a/src/client/spark/core/Utility/ObservableDemuxer.cs
+++ b/src/client/spark/core/Utility/ObservableDemuxer.cs
@@ -168,8 +168,6 @@ namespace mbts.utils {
public void OnCompleted() { }
public void OnError(Exception error) { }
public void OnNext(TableUpdate update) {
- var add_map = update.added.Map(_group_key);
- var remove_map = update.removed.Map(_group_key);
var group_updates = new Dictionary();
foreach (var v in update.added)
group_updates.GetOrAdd(_group_key(v), gk => new UpdateTuple()).added.Add(v);
diff --git a/src/client/spark/view/Controls/Badge.cs b/src/client/spark/view/Controls/Badge.cs
index dfec16a4c..1f7f59901 100644
--- a/src/client/spark/view/Controls/Badge.cs
+++ b/src/client/spark/view/Controls/Badge.cs
@@ -39,6 +39,7 @@ namespace mbts.ui.controls {
Brush _background, _foreground, _border_brush;
bool _has_multiple_orders_at_level, _is_hedge_order;
CustomOrderDefinition.CustomOneofCase _algo_type;
+ string _abbreviation;
(Point p1, Point p2, Point p3) _current_triangle_vertices;
StreamGeometry _triangle_geometry;
Popup _popup;
@@ -233,6 +234,18 @@ namespace mbts.ui.controls {
(b, v) => b._algo_type = v,
CustomOrderDefinition.CustomOneofCase.None);
+ public string Abbreviation {
+ get { return (string)GetValue(AbbreviationProperty); }
+ set { SetValue(AbbreviationProperty, value); }
+ }
+
+ public static readonly DependencyProperty AbbreviationProperty =
+ WPFHelper.create_dp(
+ nameof(Abbreviation),
+ FrameworkPropertyMetadataOptions.AffectsRender,
+ (b, v) => b._abbreviation = v,
+ string.Empty);
+
public bool IsHedgeOrder {
get { return (bool)GetValue(IsHedgeOrderProperty); }
set { SetValue(IsHedgeOrderProperty, value); }
@@ -314,7 +327,19 @@ namespace mbts.ui.controls {
dc.DrawGlyphRun(Brushes.Black, a_glyph_run);
}
- if (AlgoType != CustomOrderDefinition.CustomOneofCase.None) {
+ if (!string.IsNullOrEmpty(Abbreviation)) {
+ var a_glyph_context = _gcr.glyph_context;
+ var a_glyph_run = a_glyph_context.get_glyph_run(
+ Abbreviation,
+ FontSize,
+ _gcr.layout_size.Width,
+ _gcr.layout_size.Height,
+ HorizontalAlignment.Left,
+ 2 * border_thickness + 1,
+ VerticalAlignment.Center,
+ 0);
+ dc.DrawGlyphRun(Brushes.Black, a_glyph_run);
+ } else if (AlgoType != CustomOrderDefinition.CustomOneofCase.None) {
var a_glyph_context = _gcr.glyph_context;
var a_glyph_run = a_glyph_context.get_glyph_run(
mbts.spark.utilities.OrderDataHelper.abbreviate_algo_type(AlgoType),
diff --git a/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs b/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs
index 72b52c498..882289093 100644
--- a/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs
+++ b/src/client/spark/view/Controls/DIYGrid/CellRender/TextCell.cs
@@ -20,16 +20,25 @@ namespace mbts.ui.controls {
GlyphRun _glyph_run;
GlyphContext _glyph_context;
- static TextCell() =>
+ static TextCell() {
WPFHelper.override_metadata(
HorizontalAlignmentProperty,
FrameworkPropertyMetadataOptions.AffectsArrange |
+ FrameworkPropertyMetadataOptions.AffectsMeasure |
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => {
o._horizontal_alignment = v;
o._glyph_run = null;
},
HorizontalAlignment.Left);
+ WPFHelper.override_metadata(
+ WidthProperty,
+ FrameworkPropertyMetadataOptions.AffectsArrange |
+ FrameworkPropertyMetadataOptions.AffectsMeasure |
+ FrameworkPropertyMetadataOptions.AffectsRender,
+ (o, v) => o._glyph_run = null,
+ double.NaN);
+ }
public TextCell() {
_background = Background;
@@ -162,10 +171,15 @@ namespace mbts.ui.controls {
}
protected override void OnRender(DrawingContext drawingContext) {
+ var rs = RenderSize;
+ var rect = new Rect(0, 0, rs.Width, rs.Height);
if (_background != null)
- drawingContext.DrawRectangle(_background, null, new Rect(RenderSize));
- if (_glyph_run != null)
+ drawingContext.DrawRectangle(_background, null, rect);
+ if (_glyph_run != null) {
+ drawingContext.PushClip(new RectangleGeometry(rect));
drawingContext.DrawGlyphRun(_foreground, _glyph_run);
+ drawingContext.Pop();
+ }
}
}
}
diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs
index 6f22c40ef..0144d032b 100644
--- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs
+++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/TextColumn.cs
@@ -22,10 +22,12 @@ namespace mbts.ui.controls {
public VerticalAlignment vertical_alignment { get; set; } = VerticalAlignment.Center;
public override FrameworkElement view_factory() {
- var v = new TextCell { Foreground = font_brush, HorizontalAlignment = horizontal_alignment, VerticalAlignment = vertical_alignment };
+ var v = new TextCell { Foreground = font_brush, VerticalAlignment = vertical_alignment };
v.SetBinding(TextCell.TextProperty, _binding);
v.SetBinding(TextCell.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this });
v.SetBinding(TextCell.FontSizeProperty, new Binding(nameof(font_size)) { Source = this });
+ v.SetBinding(TextCell.HorizontalAlignmentProperty, new Binding(nameof(horizontal_alignment)) { Source = this });
+ v.SetBinding(TextCell.WidthProperty, new Binding(nameof(ActualWidth)) { Source = this });
try_set_binding(TextCell.BackgroundProperty, background_binding);
try_set_binding(TextCell.ForegroundProperty, foreground_binding);
try_set_binding(TextCell.FontWeightProperty, font_weight_binding);
diff --git a/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml b/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml
deleted file mode 100644
index ea0da1257..000000000
--- a/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml.cs b/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml.cs
deleted file mode 100644
index 536c649f9..000000000
--- a/src/client/spark/view/Controls/Order/QuantityTriggerControl.xaml.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using bts.spark;
-using mbts.spark.utilities;
-using System;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Globalization;
-
-namespace mbts.ui.spark.algo
-{
- ///
- /// Interaction logic for QuantityTriggerControl.xaml
- ///
- public class QuantityTriggerControl : Control
- {
- static QuantityTriggerControl() {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(QuantityTriggerControl), new FrameworkPropertyMetadata(typeof(QuantityTriggerControl)));
- }
-
- #region QuantityTrigger
- public static readonly DependencyProperty QuantityTriggerProperty = DependencyProperty.Register("QuantityTrigger", typeof(QuantityTrigger), typeof(QuantityTriggerControl), new PropertyMetadata(null, OnQuantityTriggerChanged, CoerceQuantityTrigger));
- private static object CoerceQuantityTrigger(DependencyObject d, object baseValue) { return baseValue is QuantityTrigger ? baseValue : OrderDataHelper.Defaults.QuantityTrigger; }
- private static void OnQuantityTriggerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { d.SetValue(QuantityTriggerVMPropertyKey, new QuantityTriggerVM((QuantityTrigger)e.NewValue)); }
- public QuantityTrigger QuantityTrigger { get => GetValue(QuantityTriggerProperty) as QuantityTrigger; set => SetValue(QuantityTriggerProperty, value); }
- #endregion
-
- #region QuantityTriggerVM (ReadOnly)
- private static readonly DependencyPropertyKey QuantityTriggerVMPropertyKey = DependencyProperty.RegisterReadOnly("QuantityTriggerVM", typeof(QuantityTriggerVM), typeof(QuantityTriggerControl), new PropertyMetadata(null));
- internal static readonly DependencyProperty QuantityTriggerVMProperty = QuantityTriggerVMPropertyKey.DependencyProperty;
- internal QuantityTriggerVM QuantityTriggerVM { get => GetValue(QuantityTriggerVMProperty) as QuantityTriggerVM; private set => SetValue(QuantityTriggerVMPropertyKey, value); }
- #endregion
- }
-
- internal class QuantityTriggerVM
- {
- public QuantityTriggerVM(QuantityTrigger model) {
- _model = model;
- }
-
- private readonly QuantityTrigger _model;
-
- public QuantityTrigger.RelationOneofCase relation {
- get => _model.RelationCase;
- set {
- switch(value) {
- case QuantityTrigger.RelationOneofCase.GreaterThanEqualto: _model.GreaterThanEqualto = true; break;
- case QuantityTrigger.RelationOneofCase.LessThanEqualto: _model.LessThanEqualto = true; break;
- }
- }
- }
- public QuantityMeasure quantity_measure => _model.QuantityMeasure;
- public uint threshold_quantity { get => _model.ThresholdQuantity; set => _model.ThresholdQuantity = value; }
- }
-
- internal class QuantityTriggerRelationDisplayTextConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
- if (value is QuantityTrigger.RelationOneofCase) {
- switch ((QuantityTrigger.RelationOneofCase)value) {
- case QuantityTrigger.RelationOneofCase.GreaterThanEqualto: return "Minimum";
- case QuantityTrigger.RelationOneofCase.LessThanEqualto: return "Maximum";
- default: return value.ToString();
- }
- }
- return string.Empty;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownHelper.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownHelper.cs
index 6cb68ec9c..3aa62bb46 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownHelper.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownHelper.cs
@@ -1,4 +1,5 @@
-using System.Windows.Controls;
+using System;
+using System.Windows.Controls;
using System.Windows.Data;
namespace mbts.ui.controls {
@@ -24,5 +25,66 @@ namespace mbts.ui.controls {
UpdateSourceTrigger = update_source_trigger
});
}
+
+ // int
+ public static bool tick_up(int value, int increment, out int result) => _tick(value, value + increment, 1, out result);
+ public static bool tick_down(int value, int increment, out int result) => _tick(value, value - increment, -1, out result);
+ // int?
+ public static bool tick_up(int? value, int increment, out int result) => value.HasValue ? _tick(value.Value, value.Value + increment, 1, out result) : _no_op(out result);
+ public static bool tick_down(int? value, int increment, out int result) => value.HasValue ? _tick(value.Value, value.Value - increment, -1, out result) : _no_op(out result);
+
+ // uint
+ public static bool tick_up(uint value, uint increment, out uint result) => _tick(value, value + increment, 1, out result);
+ public static bool tick_down(uint value, uint increment, out uint result) => _tick(value, value - increment, -1, out result);
+ // uint?
+ public static bool tick_up(uint? value, uint increment, out uint result) => value.HasValue ? _tick(value.Value, value.Value + increment, 1, out result) : _no_op(out result);
+ public static bool tick_down(uint? value, uint increment, out uint result) => value.HasValue ? _tick(value.Value, value.Value - increment, -1, out result) : _no_op(out result);
+
+ // short
+ public static bool tick_up(short value, short incremented, out short result) => _tick(value, (short)(value + incremented), 1, out result);
+ public static bool tick_down(short value, short incremented, out short result) => _tick(value, (short)(value - incremented), -1, out result);
+ // short?
+ public static bool tick_up(short? value, short increment, out short result) => value.HasValue ? _tick(value.Value, (short)(value.Value + increment), 1, out result) : _no_op(out result);
+ public static bool tick_down(short? value, short increment, out short result) => value.HasValue ? _tick(value.Value, (short)(value.Value - increment), -1, out result) : _no_op(out result);
+
+ // ushort
+ public static bool tick_up(ushort value, ushort incremented, out ushort result) => _tick(value, (ushort)(value + incremented), 1, out result);
+ public static bool tick_down(ushort value, ushort incremented, out ushort result) => _tick(value, (ushort)(value - incremented), -1, out result);
+ // ushort?
+ public static bool tick_up(ushort? value, ushort increment, out ushort result) => value.HasValue ? _tick(value.Value, (ushort)(value.Value + increment), 1, out result) : _no_op(out result);
+ public static bool tick_down(ushort? value, ushort increment, out ushort result) => value.HasValue ? _tick(value.Value, (ushort)(value.Value - increment), -1, out result) : _no_op(out result);
+
+ // long
+ public static bool tick_up(long value, long incremented, out long result) => _tick(value, (long)(value + incremented), 1, out result);
+ public static bool tick_down(long value, long incremented, out long result) => _tick(value, (long)(value - incremented), -1, out result);
+ // long?
+ public static bool tick_up(long? value, long increment, out long result) => value.HasValue ? _tick(value.Value, (long)(value.Value + increment), 1, out result) : _no_op(out result);
+ public static bool tick_down(long? value, long increment, out long result) => value.HasValue ? _tick(value.Value, (long)(value.Value - increment), -1, out result) : _no_op(out result);
+
+ // ulong
+ public static bool tick_up(ulong value, ulong incremented, out ulong result) => _tick(value, (ulong)(value + incremented), 1, out result);
+ public static bool tick_down(ulong value, ulong incremented, out ulong result) => _tick(value, (ulong)(value - incremented), -1, out result);
+ // ulong?
+ public static bool tick_up(ulong? value, ulong increment, out ulong result) => value.HasValue ? _tick(value.Value, (ulong)(value.Value + increment), 1, out result) : _no_op(out result);
+ public static bool tick_down(ulong? value, ulong increment, out ulong result) => value.HasValue ? _tick(value.Value, (ulong)(value.Value - increment), -1, out result) : _no_op(out result);
+
+ // generic logic to avoid ticking across zero, in either direction.
+ static bool _tick(T value, T incremented, int expected_comparison, out T result) where T : struct, IComparable {
+ if (expected_comparison == 0) {
+ result = value;
+ return incremented.CompareTo(value) == 0;
+ } else if ((incremented.CompareTo(value) > 0) == (expected_comparison > 0)) {
+ result = incremented;
+ return true;
+ } else {
+ result = value;
+ return false;
+ }
+ }
+
+ static bool _no_op(out T result) {
+ result = default;
+ return false;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs
index 5b8c155af..35ca5eb59 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs
@@ -121,10 +121,14 @@ namespace mbts.ui.controls {
SetCurrentValue(ValueProperty, int.TryParse(_text_box.Text, out int i) ? i : 0);
}
- void _tick_up() =>
- SetCurrentValue(ValueProperty, Value + Increment);
+ void _tick_up() {
+ if (TickUpDownHelper.tick_up(Value, Increment, out int result))
+ SetCurrentValue(ValueProperty, result);
+ }
- void _tick_down() =>
- SetCurrentValue(ValueProperty, Value - Increment);
+ void _tick_down() {
+ if (TickUpDownHelper.tick_down(Value, Increment, out int result))
+ SetCurrentValue(ValueProperty, result);
+ }
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableInt.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableInt.cs
index a15b86015..3e7026cb3 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableInt.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableInt.cs
@@ -88,13 +88,13 @@ namespace mbts.ui.controls {
}
void _tick_up() {
- int? v = Value;
- SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
+ if (TickUpDownHelper.tick_up(Value, Increment, out int result))
+ SetCurrentValue(ValueProperty, result);
}
void _tick_down() {
- int? v = Value;
- SetCurrentValue(ValueProperty, v.HasValue ? v.Value - Increment : TickDefaultValue);
+ if (TickUpDownHelper.tick_down(Value, Increment, out int result))
+ SetCurrentValue(ValueProperty, result);
}
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUInt.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUInt.cs
index 4e24d9c35..b22d1ef48 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUInt.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUInt.cs
@@ -103,14 +103,13 @@ namespace mbts.ui.controls {
}
void _tick_up() {
- uint? v = Value;
- SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
+ if (TickUpDownHelper.tick_up(Value, Increment, out uint result))
+ SetCurrentValue(ValueProperty, result);
}
void _tick_down() {
- uint? v = Value;
- uint inc = Increment;
- SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
+ if (TickUpDownHelper.tick_down(Value, Increment, out uint result))
+ SetCurrentValue(ValueProperty, result);
}
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableULong.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableULong.cs
index 021908100..9c89e572d 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableULong.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableULong.cs
@@ -101,14 +101,13 @@ namespace mbts.ui.controls {
}
void _tick_up() {
- ulong? v = Value;
- SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
+ if (TickUpDownHelper.tick_up(Value, Increment, out ulong result))
+ SetCurrentValue(ValueProperty, result);
}
void _tick_down() {
- ulong? v = Value;
- ulong inc = Increment;
- SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
+ if (TickUpDownHelper.tick_down(Value, Increment, out ulong result))
+ SetCurrentValue(ValueProperty, result);
}
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUShort.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUShort.cs
index 2ce45f9f4..6af50aac3 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUShort.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUShort.cs
@@ -101,14 +101,13 @@ namespace mbts.ui.controls {
}
void _tick_up() {
- ushort? v = Value;
- SetCurrentValue(ValueProperty, v.HasValue ? v.Value + Increment : TickDefaultValue);
+ if (TickUpDownHelper.tick_up(Value, Increment, out ushort result))
+ SetCurrentValue(ValueProperty, result);
}
void _tick_down() {
- ushort? v = Value;
- ushort inc = Increment;
- SetCurrentValue(ValueProperty, v.HasValue && v.Value > inc ? v.Value - inc : TickDefaultValue);
+ if (TickUpDownHelper.tick_down(Value, Increment, out ushort result))
+ SetCurrentValue(ValueProperty, result);
}
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownUInt.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownUInt.cs
index 119b9862e..52c2d1224 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownUInt.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownUInt.cs
@@ -91,10 +91,14 @@ namespace mbts.ui.controls {
SetCurrentValue(ValueProperty, uint.TryParse(_text_box.Text, out uint u) ? u : 0u);
}
- void _tick_up() =>
- SetCurrentValue(ValueProperty, Value + Increment);
+ void _tick_up() {
+ if (TickUpDownHelper.tick_up(Value, Increment, out uint result))
+ SetCurrentValue(ValueProperty, result);
+ }
- void _tick_down() =>
- SetCurrentValue(ValueProperty, Value - Increment);
+ void _tick_down() {
+ if (TickUpDownHelper.tick_down(Value, Increment, out uint result))
+ SetCurrentValue(ValueProperty, result);
+ }
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownULong.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownULong.cs
index 369b97f43..6afa9e192 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownULong.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownULong.cs
@@ -95,10 +95,14 @@ namespace mbts.ui.controls {
SetCurrentValue(ValueProperty, ulong.TryParse(_text_box.Text, out ulong u) ? u : 0u);
}
- void _tick_up() =>
- SetCurrentValue(ValueProperty, Value + Increment);
+ void _tick_up() {
+ if (TickUpDownHelper.tick_up(Value, Increment, out ulong result))
+ SetCurrentValue(ValueProperty, result);
+ }
- void _tick_down() =>
- SetCurrentValue(ValueProperty, Value - Increment);
+ void _tick_down() {
+ if (TickUpDownHelper.tick_down(Value, Increment, out ulong result))
+ SetCurrentValue(ValueProperty, result);
+ }
}
}
\ No newline at end of file
diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownUShort.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownUShort.cs
index 9f0ca1da1..ee3e608ef 100644
--- a/src/client/spark/view/Controls/TickUpDown/TickUpDownUShort.cs
+++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownUShort.cs
@@ -95,10 +95,14 @@ namespace mbts.ui.controls {
SetCurrentValue(ValueProperty, ushort.TryParse(_text_box.Text, out ushort u) ? u : 0u);
}
- void _tick_up() =>
- SetCurrentValue(ValueProperty, Value + Increment);
+ void _tick_up() {
+ if (TickUpDownHelper.tick_up(Value, Increment, out ushort result))
+ SetCurrentValue(ValueProperty, result);
+ }
- void _tick_down() =>
- SetCurrentValue(ValueProperty, Value - Increment);
+ void _tick_down() {
+ if (TickUpDownHelper.tick_down(Value, Increment, out ushort result))
+ SetCurrentValue(ValueProperty, result);
+ }
}
}
\ No newline at end of file
diff --git a/src/client/spark_api/api/Update.cs b/src/client/spark_api/api/Update.cs
index 35d099212..d74f8e052 100644
--- a/src/client/spark_api/api/Update.cs
+++ b/src/client/spark_api/api/Update.cs
@@ -599,7 +599,7 @@ namespace bts.api.core {
table_source.AggregateLatest(predicate_source,
(tout, tin, pred) => TableUpdate.FilterHelper.on_source_changed(tout, tin.New.added, tin.New.changes, tin.New.removed, pred),
(tout, tin, pred) => TableUpdate.FilterHelper.on_predicate_changed(tout, tin.state, pred.Old, pred.New),
- TableUpdate.mk_empty(key),
+ () => TableUpdate.mk_empty(key),
TableUpdate.mk_empty(key),
init_predicate);
@@ -614,16 +614,16 @@ namespace bts.api.core {
var filtered = TableUpdate.FilterHelper.on_predicate_changed(tout.filtered, tin.state, pred.Old, pred.New);
return (filtered, tin);
},
- (empty, empty),
+ () => (empty, empty),
empty,
init_predicate);
}
public static IObservable AggregateLatest(this IObservable source, IObservable right,
- Func, TRight, TAggregate> update_left, Func, TAggregate> update_right, TAggregate seed, TLeft init_left = default, TRight init_right = default) =>
+ Func, TRight, TAggregate> update_left, Func, TAggregate> update_right, Func seed_factory, TLeft init_left = default, TRight init_right = default) =>
Observable.Create(o => {
Log.DataFlow.diag($"Create AggregateLatest (Left: {typeof(TLeft)}, Right: {typeof(TRight)}).");
- var aggregator = new ConcurrentAggregator(update_left, update_right, o.OnNext, seed, init_left, init_right);
+ var aggregator = new ConcurrentAggregator(update_left, update_right, o.OnNext, seed_factory(), init_left, init_right);
return new CompositeDisposable(source.Subscribe(aggregator.on_left), right.Subscribe(aggregator.on_right));
});
diff --git a/src/client/sparkcmd/Cmd/MBOCommand.cs b/src/client/sparkcmd/Cmd/MBOCommand.cs
new file mode 100644
index 000000000..c7a828e4d
--- /dev/null
+++ b/src/client/sparkcmd/Cmd/MBOCommand.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using bts.api.core;
+using bts.md;
+using CommandLine;
+using System.Linq;
+
+namespace bts {
+
+ [Verb("mbo", HelpText="MBO diagnostic command")]
+ public class MBOCommandOptions {
+ [Option('k', "key", Required = true)]
+ public UInt32 key { get; set; }
+
+ [Option('s', "side", Default = api.Side.Undefined)]
+ public api.Side side { get; set; }
+ }
+
+ public class MBOCommand {
+ public static int Run(MBOCommandOptions o) {
+ dump_mbo(o.key, o.side);
+ return 0;
+ }
+
+ static void dump_mbo(UInt32 key, api.Side side) {
+ using (var ctx = new ServiceContext()) {
+ var mbo = ctx.locate();
+ var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key });
+
+ Console.WriteLine($"Order data for {data.SecurityId}");
+ IEnumerable orders = data.Bid;
+ switch(side) {
+ case api.Side.Undefined:
+ orders = data.Ask.Concat(data.Bid);
+ break;
+ case api.Side.Buy:
+ orders = data.Bid;
+ break;
+ case api.Side.Sell:
+ orders = data.Ask;
+ break;
+ }
+ var price = 0.0;
+ foreach(var e in orders) {
+ if (e.Price != price) {
+ price = e.Price;
+ Console.WriteLine("================");
+ }
+ Console.WriteLine(e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/client/sparkcmd/Cmd/OrderStress.cs b/src/client/sparkcmd/Cmd/OrderStress.cs
index 43f8d9765..643703155 100644
--- a/src/client/sparkcmd/Cmd/OrderStress.cs
+++ b/src/client/sparkcmd/Cmd/OrderStress.cs
@@ -132,6 +132,14 @@ namespace bts {
foreach (var m in all_markets(ctx)) {
ConsoleEx.WriteLine(m.security.security_desc(), ConsoleColor.White);
var tick = m.security.ContractSpec.LowTick;
+ if (m.ask.HasValue) {
+ for (var x = 0; x < o.depth; ++x) {
+ var price = m.ask.Value.price() + (tick * x);
+ ConsoleEx.WriteLine($"Sell {o.quantity} at {price}", ConsoleColor.Red);
+ orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Sell));
+ System.Threading.Thread.Sleep(o.sleep);
+ }
+ }
if (m.bid.HasValue) {
// start at bid and place 1 order at 10 levels
for (var x=0; x < o.depth; ++x) {
@@ -141,14 +149,6 @@ namespace bts {
System.Threading.Thread.Sleep(o.sleep);
}
}
- if (m.ask.HasValue) {
- for (var x = 0; x < o.depth; ++x) {
- var price = m.ask.Value.price() + (tick * x);
- ConsoleEx.WriteLine($"Sell {o.quantity} at {price}", ConsoleColor.Red);
- orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Sell));
- System.Threading.Thread.Sleep(o.sleep);
- }
- }
}
return 3;
}
diff --git a/src/client/sparkcmd/Cmd/ServiceTestCommand.cs b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs
index 90ff496e1..52dcee6cd 100644
--- a/src/client/sparkcmd/Cmd/ServiceTestCommand.cs
+++ b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs
@@ -17,16 +17,9 @@ namespace bts {
[Option(nameof(admin))]
public bool admin { get; set; }
- [Option(nameof(mbo))]
- public bool mbo { get; set; }
-
- [Option("key")]
- public UInt32 key { get; set; }
-
- [Option("side")]
- public api.Side side { get; set; }
}
+ [Verb("servicetest", HelpText="Scratch space for testing services")]
public class ServiceTest {
public static int Run(ServiceTestOptions o) {
if (o.synthetic) {
@@ -38,9 +31,6 @@ namespace bts {
if (o.admin) {
admin_test();
}
- if (o.mbo) {
- mbo_test(o);
- }
return 0;
}
@@ -51,25 +41,6 @@ namespace bts {
return "";
}
- private static void mbo_test(ServiceTestOptions o) {
- var key = o.key;
- var side = o.side;
- using (var ctx = new ServiceContext()) {
- var mbo = ctx.locate();
- var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key });
-
- Console.WriteLine($"Order data for {data.SecurityId}");
- var vector = side == api.Side.Buy ? data.Bid : data.Ask;
- var price = 0.0;
- foreach(var e in vector) {
- if (e.Price != price) {
- price = e.Price;
- Console.WriteLine("================");
- }
- Console.WriteLine(e);
- }
- }
- }
private static void synthetic_test() {
using (var ctx = new ServiceContext()) {
diff --git a/src/client/sparkcmd/Program.cs b/src/client/sparkcmd/Program.cs
index a91fed7f2..c35332f50 100644
--- a/src/client/sparkcmd/Program.cs
+++ b/src/client/sparkcmd/Program.cs
@@ -26,8 +26,26 @@ namespace sparkcmd {
mbts.utils.BTSNativeMethods.provide_command_line(args, args.Length);
// note: this can be made to infer the options type list from the list of delegates
return Parser.Default
- .ParseArguments(args)
- .MapResult(
+ .ParseArguments<
+ ConfigcheckOptions,
+ ScriptClientOptions,
+ TailServiceOptions,
+ ServiceTestOptions,
+ SettingsManagerOptions,
+ TestCommandOptions,
+ OrderStressOptions,
+ MBOCommandOptions
+ >(args)
+ .MapResult<
+ ConfigcheckOptions,
+ ScriptClientOptions,
+ TailServiceOptions,
+ ServiceTestOptions,
+ SettingsManagerOptions,
+ TestCommandOptions,
+ OrderStressOptions,
+ MBOCommandOptions,
+ int>(
Configcheck.Run,
ScriptClientCommand.Run,
TailService.Run,
@@ -35,6 +53,7 @@ namespace sparkcmd {
SettingsManagerCommand.Run,
TestCommand.Run,
OrderStress.Run,
+ MBOCommand.Run,
errors => 1);
}
}
diff --git a/src/data_files/files/Onixs.BTS.lic b/src/data_files/files/Onixs.BTS.lic
index e43edc38f..9ff33e7a2 100644
--- a/src/data_files/files/Onixs.BTS.lic
+++ b/src/data_files/files/Onixs.BTS.lic
@@ -1,21 +1,16 @@
production
- Blue Trading Systems
+ Blue Trading Systems OF 9420-2
- 2018-08-30
- 2019-10-16
+ 2019-05-02
+ 2020-05-13
-
-
-
- 6O68+aAtrLqRaXxY9hLigajhC2ZunVeIev3NbyEXFjHk61WFrNmRTjy6tEduDtFUvGXvS6VUW3VXASaMTLrRgYteZBzfp7+dFTfVIVbzv6cn7c7dnSxWCGO5zPrjXw9cxMXlFz9cshyue6U/DRR5J36ThOhgt2kpY/OP9cgXWJo=
-
-
+
- 18F98ED1E0A87B4B11DA322403D7BDDD
+ 5E50A1DACD94D7C1BECD316EEAE5AB02
\ No newline at end of file
diff --git a/src/lib/api/services/OrderService.proto b/src/lib/api/services/OrderService.proto
index 6faf7bd07..19b168f23 100644
--- a/src/lib/api/services/OrderService.proto
+++ b/src/lib/api/services/OrderService.proto
@@ -94,6 +94,7 @@ message CustomOrderDefinition
TriggerOrderDefinition trigger = 22;
CoverOrderDefinition cover = 23;
OffsetOrderDefinition offset = 24;
+ QueueHolderDefinition queue_holder = 30;
OCOOrderDefinition oco = 25;
PricerOrderDefinition pricer = 26;
CompositeOrderDefinition composite = 27;
@@ -172,6 +173,13 @@ message OffsetOrderDefinition {
uint32 tick_offset_on_deploy = 1;
CustomOrderDefinition child = 6;
}
+message QueueHolderDefinition{
+ // this is for the number of trailing
+ // orders behind the top one (so value
+ // of 1 means 2 orders in all)
+ uint32 n_queue_orders = 1;
+ CustomOrderDefinition child=10;
+}
message OCOOrderDefinition {
CustomOrderDefinition other = 1;
int32 other_ticks = 2;
@@ -236,6 +244,7 @@ message OrderState {
TriggerOrderState trigger = 21;
CoverOrderState cover = 22;
OffsetOrderState offset = 24;
+ QueueHolderState queue_holder = 30;
OCOOrderState oco = 25;
PricerOrderState pricer = 26;
@@ -330,6 +339,7 @@ message OffsetOrderState {}
message OCOOrderState {}
message PricerOrderState {}
message DynamicOrderState {}
+message QueueHolderState {}
enum OrderStatus {
diff --git a/src/lib/orderman/events/OrderStateUpdateEvent.h b/src/lib/orderman/events/OrderStateUpdateEvent.h
index a721ea941..7556ce6b4 100644
--- a/src/lib/orderman/events/OrderStateUpdateEvent.h
+++ b/src/lib/orderman/events/OrderStateUpdateEvent.h
@@ -137,6 +137,9 @@ class OrderStateUpdateEvent : public mercury::Event {
case api::orderman::OrderState::kOffset:
result.mutable_offset();
break;
+ case api::orderman::OrderState::kQueueHolder:
+ result.mutable_queue_holder();
+ break;
case api::orderman::OrderState::kOco:
result.mutable_oco();
break;
diff --git a/src/lib/orderman/order_factory/OrderFactory.cpp b/src/lib/orderman/order_factory/OrderFactory.cpp
index a437d3578..70ddf3700 100644
--- a/src/lib/orderman/order_factory/OrderFactory.cpp
+++ b/src/lib/orderman/order_factory/OrderFactory.cpp
@@ -25,6 +25,7 @@
#include "lib/orderman/orders/book_algos/PricerOrder.h"
#include "lib/orderman/orders/spreader_orders/SpreaderOrder.h"
#include "lib/orderman/orders/CompositeOrder.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
#include
#include
@@ -200,6 +201,9 @@ Order &OrderFactory::allocate(OrderKey k, OrderKey pk,
case CustomOrderDefinition::kOffset:
order_ptr.reset(new orderman::OffsetOrder());
break;
+ case CustomOrderDefinition::kQueueHolder:
+ order_ptr.reset(new orderman::QueueHolderOrder());
+ break;
case CustomOrderDefinition::kOco:
order_ptr.reset(new orderman::OCOOrder());
break;
diff --git a/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp b/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp
index 5522bbcf5..e53aa650f 100644
--- a/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp
+++ b/src/lib/orderman/orders/algo/AlgoWrapperOrder.cpp
@@ -780,9 +780,9 @@ log::CharPtrWrapper AlgoWrapperOrder::state_name(Status st) {
ChildStatus AlgoWrapperOrder::map_child_status(api::orderman::OrderStatus st) {
switch (st) {
case ORDER_STATUS_COMPLETED:
- case ORDER_STATUS_PENDING_WORKING:
return ChildStatus::COMPLETED;
case ORDER_STATUS_WORKING:
+ case ORDER_STATUS_PENDING_WORKING:
return ChildStatus::WORKING;
case ORDER_STATUS_CANCELED:
return ChildStatus::CANCELED;
diff --git a/src/lib/orderman/orders/algo/algo_orders/CoverAlgo.cpp b/src/lib/orderman/orders/algo/algo_orders/CoverAlgo.cpp
index ec4e2e31b..1ee5e14bc 100644
--- a/src/lib/orderman/orders/algo/algo_orders/CoverAlgo.cpp
+++ b/src/lib/orderman/orders/algo/algo_orders/CoverAlgo.cpp
@@ -16,6 +16,7 @@ struct CoverAlgo::PImpl {
Price price_improvement_delta;
ChildTemplate *child_template = nullptr;
ChildTemplate *hedge_template = nullptr;
+ Quantity hedged_fills = Quantity(0);
};
CoverAlgo::CoverAlgo() : me(new PImpl()) {}
@@ -71,15 +72,16 @@ void CoverAlgo::do_launch_attached(IAlgoServices &algo, OrderKey k,
ChildState st) {
me->algo = &algo;
me->child_key = k;
+ me->hedged_fills = st.total_fills;
on_child_change(k, st);
}
void CoverAlgo::on_child_change(OrderKey k, ChildState const &st) {
bts_assert(k == me->child_key); // We are not subscribed to hedge changes
- if (st.total_fills.value() > algo().total_fills().value()) {
+ if (st.total_fills.value() > me->hedged_fills.value()) {
auto hedge_qty =
- Quantity(st.total_fills.value() - algo().total_fills().value());
+ 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);
@@ -87,6 +89,7 @@ void CoverAlgo::on_child_change(OrderKey k, ChildState const &st) {
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: "
"{} {}@{}",
@@ -95,7 +98,6 @@ void CoverAlgo::on_child_change(OrderKey k, ChildState const &st) {
hedge_price.value());
}
algo().update_fill_state(st.total_fills, st.last_price);
-
switch (st.status) {
case ChildStatus::WORKING:
return;
diff --git a/src/lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h b/src/lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h
new file mode 100644
index 000000000..fc7599ac3
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h
@@ -0,0 +1,45 @@
+#pragma once
+#include "lib/utils/bts_chrono.h"
+#include "lib/orderman/orderman_utils/orderman_common.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrderState.h"
+
+namespace bts {
+namespace trace {class CorID;}
+namespace api {namespace orderman {class OrderDefinition;class OrderRecord;}}
+namespace orderman {class PreActivationOrderServices; class OrderServices;}
+namespace orderman {class OrderStateUpdateEvent;}
+namespace orderman {
+class SpreaderOrder;
+class Book;
+
+// All the QueueHolderOrder state machine workers
+// implement this
+class IQueueHolderOrderStateWorker{
+public:
+ virtual QueueHolderOrderState state() const = 0;
+ // 0. when the state machine transits to a new state
+ virtual void on_transition() = 0;
+ // 1. called once before the other calls. state should be
+ // constructed here
+ virtual void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) = 0;
+ // 2. when constructed on recovery (with partial state)
+ virtual void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) = 0;
+ // 3. this is the end of the construction cycle. should happen
+ // after on_init_new and before all other calls. market data subs
+ // and quoter order creation happens here
+ virtual void on_activate(Price, Quantity, OrderServices&) = 0;
+ // 4. new a price, qty change
+ virtual void on_update(Price, Quantity) = 0;
+ // 5. called when the user cancels an order
+ virtual void on_cancel() = 0;
+ // 6. order callback
+ virtual void on_child_order_update(const OrderStateUpdateEvent&) = 0;
+ // 7. on market data update (support late joiners)
+ virtual void on_book(const Book&,
+ const trace::CorID&) = 0;
+ // 8. time event called by the infrastructure
+ virtual void on_time(const TimeStamp&) = 0;
+};
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/QHOOrderManager.h b/src/lib/orderman/orders/queue_holder/QHOOrderManager.h
new file mode 100644
index 000000000..88f6319b0
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/QHOOrderManager.h
@@ -0,0 +1,319 @@
+#pragma once
+
+#include "lib/os/os.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h"
+#include "lib/domain_model/Security.h"
+
+namespace bts {
+namespace orderman {
+
+// submit, modifies and cancels all orders
+// that constitute the QHO.
+// i. places, modifies and cancels orders
+// ii. helper functons to get the accumulated
+// state of the orders
+// all the order interactions are done explicitely
+// through function calls
+class QHOOrderManager{
+private:
+ bool _inited;
+ bool _orders_placed_once;
+ OrderBuilder* _order_builder;
+ api::Side _side;
+ double _tick_size;
+ uint16_t _n_eff_orders;
+ // the order of this does is not asc/desc wrt
+ // price (modify of price will make it unordered)
+ std::vector _orders;
+ Price _target_price;
+ Quantity _target_qty;
+public:
+ QHOOrderManager()
+ :
+ _inited(false),
+ _orders_placed_once(false),
+ _order_builder(nullptr),
+ _side(api::Side::SIDE_BUY),
+ _tick_size(os::nan()),
+ _n_eff_orders(1),
+ _orders(),
+ _target_price(os::nan()),
+ _target_qty(0){
+ }
+ // public interface //////////////////////////////
+ //////////////////////////////////////////////////
+
+ // We could have done away with init and
+ // moved it in the cons. The problem is that
+ // the QueueHolderOrder does not have the data
+ // at its construction time to construct
+ // QHOOrderManager. (It could alternatively
+ // have used a pointer to QueueHolderOrder
+ // but for contigous memory allocations it
+ // did not)
+ void init(OrderBuilder& order_builder,
+ SecurityKey key,
+ api::Side side,
+ double tick_size,
+ uint16_t n_orders,
+ Price price,
+ Quantity qty){
+ _inited=true;
+ _order_builder=&order_builder;
+ _side=side;
+ _tick_size=tick_size;
+ // 1 trailing order means 2 total orders and so forth
+ _n_eff_orders=n_orders+1;
+ _orders.reserve(_n_eff_orders);
+ for(uint16_t i=0;i<_n_eff_orders;i++)
+ _orders.emplace_back(key,true,true);
+ _target_price=price;
+ _target_qty=qty;
+ }
+ // this can be called only once
+ void place_order(){
+ bts_assert(_inited);
+ bts_assert(!_orders_placed_once);
+ _orders_placed_once=true;
+ Quantity target_qty=_remaining();
+ bts_assert(target_qty.value()>0);
+ double price_i=_target_price.value(),
+ move_inc=_top_down_tick_inc(_tick_size,_side);
+ for(SpreaderChildOrderState& o : _orders){
+ bts_assert(o.out_quantity().value()==0);
+ ChildOrder child_order=_order_builder->build();
+ o.re_init(child_order);
+ o.place_order(Price(price_i),
+ target_qty,
+ bts::Timer::now());
+ price_i+=move_inc;
+ }
+ }
+ // sends orders (for the remaining qty)
+ // for all terminal orders
+ void reenter_filled_orders(){
+ bts_assert(_inited);
+ bts_assert(_orders_placed_once);
+ Quantity target_qty=_remaining();
+ bts_assert(target_qty.value()>0);
+ for(SpreaderChildOrderState& o : _orders){
+ if(o.terminal_status()){
+ Price price=o.out_price();//re-init resets the price
+ ChildOrder child_order=_order_builder->build();
+ o.re_init(child_order);
+ o.place_order(price,
+ target_qty,
+ bts::Timer::now());
+ }
+ else
+ _prune_qty(o);
+ }
+ }
+ // can only modifiy if all acked and working
+ void modify_order(Price price, Quantity qty){
+ bts_assert(_inited);
+ bts_assert(_orders_placed_once);
+ Price prev_price=_target_price;
+ Quantity prev_qty=_target_qty;
+ // all acked and working
+ bts_assert(all_orders_acked() && !has_terminal_order());
+ _target_price=price;
+ _target_qty=qty;
+ bts_assert(_remaining().value()>0);
+ _modify_order(prev_price,prev_qty);
+ }
+ // cancels all the orders (and is smart
+ // enough to about working orders only)
+ void cancel(){
+ bts_assert(_inited);
+ bts_assert(_orders_placed_once);
+ for (auto& o : _orders){
+ // is_cancelled() is checked so as not to keep
+ // sending cancel requests
+ if(!o.is_cancelled()&&o.acknowledged()&&!o.terminal_status())
+ o.cancel_order();
+ }
+ }
+ // finds the orders and subsumes the update.
+ // returns false if it cant locate the order key
+ bool on_order_update(const OrderStateUpdateEvent& ev){
+ bts_assert(_inited);
+ bts_assert(_orders_placed_once);
+ for (auto& o : _orders)
+ if(o.order_key()==ev.key){
+ o.on_order_update(ev);
+ return true;
+ }
+ return false;
+ }
+ // decreases qty in case of fills.
+ // can only modifiy if all acked and working
+ void prune_quantities(){
+ bts_assert(_inited);
+ bts_assert(_orders_placed_once);
+ bts_assert(all_orders_acked() && !has_terminal_order());
+ for (auto& o : _orders)
+ _prune_qty(o);
+ }
+ ///////////////////////////////////////////////
+ inline Quantity filled_qty() const{
+ uint32_t rv=0;
+ for (const auto& o : _orders)
+ rv+=o.total_fills().value();
+ return Quantity(rv);
+ }
+ inline void filled_price(double& filled_price, uint32_t& filled_qty) const{
+ double tot_price=0.0;
+ uint32_t tot_qty=0;
+ for (const auto& o : _orders){
+ Price so_price; Quantity so_qty;
+ o.total_fills(so_qty,so_price);
+ if(so_qty.value()>0){
+ tot_qty+=so_qty.value();
+ tot_price+=so_price.value()*so_qty.value();
+ }
+ }
+ if(tot_qty>0)
+ tot_price/=tot_qty;
+ filled_price=tot_price;
+ filled_qty=tot_qty;
+ }
+ inline bool last_update_has_fills() const{
+ for (const auto& o : _orders)
+ if(o.last_update_filled_quantity().value()>0)
+ return true;
+ return false;
+ }
+ inline bool has_cancelled_order() const{
+ for (const auto& o : _orders)
+ if(o.cancelled())
+ return true;
+ return false;
+ }
+ inline bool has_completed_order() const{
+ for (const auto& o : _orders)
+ if(o.completed())
+ return true;
+ return false;
+ }
+ inline bool has_errored_order() const{
+ for (const auto& o : _orders)
+ if(o.errored())
+ return true;
+ return false;
+ }
+ inline bool has_terminal_order() const{
+ for (const auto& o : _orders)
+ if(o.terminal_status())
+ return true;
+ return false;
+ }
+ inline bool all_orders_terminal() const{
+ for (const auto& o : _orders)
+ if(!o.terminal_status())
+ return false;
+ return true;
+ }
+ inline bool all_orders_acked() const{
+ for (const auto& o : _orders)
+ if(!o.acknowledged())
+ return false;
+ return true;
+ }
+private:
+ void _modify_order(Price prev_price, Quantity){
+ double move_inc=_top_down_tick_inc(_tick_size,_side);
+ int tick_diff=bts::securities::price_diff_to_ticks(
+ prev_price.value(),
+ _target_price.value(),
+ _tick_size);
+ Quantity remaining_target=_remaining();
+ bool moving_up=tick_diff>0;
+ double price_i=_target_price.value();
+ for(uint16_t i=0;i<_n_eff_orders;i++){
+ SpreaderChildOrderState* order_i=_find_working_order_at_price(price_i);
+ if(order_i==nullptr){
+ SpreaderChildOrderState& to_move=
+ moving_up?_lowest_price_order():_highest_price_order();
+ uint32_t new_ord_qty=_adjusted_qty(to_move.current_fills().value(),
+ to_move.out_quantity().value(),
+ remaining_target.value(),
+ true); // qty inc since its
+ // changing price levels
+ to_move.modify_order(Price(price_i),Quantity(new_ord_qty));
+ }
+ else
+ _prune_qty(*order_i);
+ price_i+=move_inc;
+ }
+ }
+ // decreases qty if the order at any level can overfill
+ // the total, ie for an order out_qty-filled > total_rem
+ // if rem=5, and this order is 3/9 this will make it 3/8
+ void _prune_qty(SpreaderChildOrderState& o){
+ uint32_t new_ord_qty=_adjusted_qty(o.current_fills().value(),
+ o.out_quantity().value(),
+ _remaining().value(),
+ false); // dont inc the qty
+ bts_assert(new_ord_qty>0);
+ o.modify_order(o.out_price(),Quantity(new_ord_qty));
+ }
+ Quantity _remaining() const{
+ if(filled_qty().value()>=_target_qty.value())
+ return Quantity(0);
+ else
+ return Quantity(_target_qty.value()-filled_qty().value());
+ }
+ // finds the order who's out_price matches
+ // the arg
+ SpreaderChildOrderState* _find_working_order_at_price(double price){
+ for(auto& o : _orders)
+ if(bts::securities::test_price_equality(
+ o.out_price().value(),
+ price,
+ _tick_size) &&
+ !o.terminal_status())
+ return &o;
+ return nullptr;
+ }
+ SpreaderChildOrderState& _highest_price_order(){
+ SpreaderChildOrderState* rv=&_orders[0];
+ for(auto& o : _orders)
+ if(o.out_price().value()>rv->out_price().value())
+ rv=&o;
+ return *rv;
+ }
+ SpreaderChildOrderState& _lowest_price_order(){
+ SpreaderChildOrderState* rv=&_orders[0];
+ for(auto& o : _orders)
+ if(o.out_price().value()out_price().value())
+ rv=&o;
+ return *rv;
+ }
+ // given an order's filled and order qty, and the
+ // target left on the total qho, finds the adjusted
+ // qty of the order
+ static uint32_t _adjusted_qty (uint32_t filled_qty,
+ uint32_t order_qty,
+ uint32_t rem_target,
+ bool allow_inc){
+ bts_assert(filled_qty<=order_qty);
+ uint32_t rem_fill=order_qty-filled_qty;
+ if(rem_fill>rem_target){
+ uint32_t dec=rem_fill-rem_target;
+ return order_qty-dec;
+ }
+ else if(rem_fill
+#include
+#include "lib/os/os.h"
+
+namespace bts {
+namespace orderman {
+
+QueueHolderOrder::QueueHolderOrder()
+:
+_is_succ_inited(false),
+_is_recovered(false),
+_termination_reason(TerminationReason::NONE),
+_order_def(),
+_tick_size(bts::os::nan()),
+_order_builder(),
+_order_manager(),
+_services(nullptr),
+_reported_state(),
+_book(),
+_state_worker(nullptr),
+_start_state_worker(this),
+_waiting_for_ack_state_worker(this),
+_working_state_worker(this),
+_waiting_for_cancel_all_state_worker(this),
+_end_state_worker(this){
+ _switch_state(QueueHolderOrderState::START);
+}
+QueueHolderOrder::~QueueHolderOrder() {}
+const api::orderman::OrderDefinition& QueueHolderOrder::definition() const {
+ return _order_def;
+}
+void QueueHolderOrder::on_init_new(const api::orderman::OrderDefinition& order_def,
+ const PreActivationOrderServices& pre_os) {
+ LOG(OrderMan, Info, "QueueHolderOrder::on_init_new key:{} state:{}",
+ key(), _state_int());
+ _state_worker->on_init_new(order_def,pre_os);
+}
+void QueueHolderOrder::on_init_recovered(
+ const api::orderman::OrderRecord& rec,
+ const PreActivationOrderServices& pre_os) {
+ LOG(OrderMan, Info, "QueueHolderOrder::on_init_recovered key:{} state:{}",
+ key(), _state_int());
+ _state_worker->on_init_recovered(rec,pre_os);
+}
+OrderOpResult QueueHolderOrder::on_activate(Price price,
+ Quantity qty,
+ OrderServices& services) {
+ LOG(OrderMan, Info,
+ "QueueHolderOrder::on_activate key:{} state:{} price:{} qty:{}",
+ key(), _state_int(), price, qty);
+ _state_worker->on_activate(price,qty,services);
+ _report_state();
+ return OrderOpResult {};
+}
+// order price, qty change
+OrderOpResult QueueHolderOrder::on_update(Price price,
+ Quantity qty) {
+ _state_worker->on_update(price,qty);
+ _report_state();
+ return OrderOpResult {};
+}
+OrderOpResult QueueHolderOrder::on_cancel() {
+ _state_worker->on_cancel();
+ _report_state();
+ return OrderOpResult {};
+}
+OrderOpResult QueueHolderOrder::on_detach() {
+ return OrderOpResult {};
+}
+void QueueHolderOrder::_on_book_update(const BookUpdateEvent& b) {
+ _state_worker->on_book(b.book,b.trace);
+}
+void QueueHolderOrder::_on_child_order_update(
+ const OrderStateUpdateEvent& c) {
+ _state_worker->on_child_order_update(c);
+ _report_state();
+}
+void QueueHolderOrder::_on_time(const bts::mercury::TimerEvent& te) {
+ _state_worker->on_time(te.ts);
+}
+void QueueHolderOrder::_switch_state(QueueHolderOrderState new_state) {
+ int s0=_state_int();
+ switch (new_state){
+ case QueueHolderOrderState::START:
+ bts_assert(_state_worker==nullptr);
+ _state_worker=&_start_state_worker;
+ break;
+ case QueueHolderOrderState::WAITING_FOR_FIRST_ACK:
+ bts_assert(_state_worker->state()==QueueHolderOrderState::START ||
+ _state_worker->state()==QueueHolderOrderState::WORKING);
+ _state_worker=&_waiting_for_ack_state_worker;
+ break;
+ case QueueHolderOrderState::WORKING:
+ bts_assert(_state_worker->state()==
+ QueueHolderOrderState::WAITING_FOR_FIRST_ACK);
+ _state_worker=&_working_state_worker;
+ break;
+ case QueueHolderOrderState::WAITING_FOR_CANCEL_ALL:
+ bts_assert(_state_worker->state()==
+ QueueHolderOrderState::WAITING_FOR_FIRST_ACK ||
+ _state_worker->state()==
+ QueueHolderOrderState::WORKING);
+ _state_worker=&_waiting_for_cancel_all_state_worker;
+ break;
+ case QueueHolderOrderState::END:
+ bts_assert(_state_worker->state()!=QueueHolderOrderState::END);
+ _state_worker=&_end_state_worker;
+ break;
+ }
+ _state_worker->on_transition();
+ _report_state();
+ LOG(OrderMan, Info, "QueueHolderOrder::_switch_state key:{} {}->{}",
+ key(), s0,_state_int());
+}
+api::orderman::OrderStatus QueueHolderOrder::status(std::string& message) const{
+ QueueHolderOrderState curr_state=
+ _state_worker==nullptr?QueueHolderOrderState::START:_state();
+ switch (curr_state){
+ case QueueHolderOrderState::START:
+ case QueueHolderOrderState::WAITING_FOR_FIRST_ACK:
+ case QueueHolderOrderState::WORKING:
+ case QueueHolderOrderState::WAITING_FOR_CANCEL_ALL:
+ return api::orderman::OrderStatus::ORDER_STATUS_WORKING;
+ case QueueHolderOrderState::END:
+ switch(_termination_reason){
+ case TerminationReason::NONE:{
+ // this will happen if the order is
+ // recovered or the init failed
+ bts_assert(!_is_succ_inited||_is_recovered);
+ if(!_is_succ_inited){
+ message="Could not initialize order";
+ return api::orderman::OrderStatus::ORDER_STATUS_REJECTED_BY_SPARK;
+ }
+ else{
+ message="Recovered order";
+ // we could have done better here by [reserving ]
+ return api::orderman::OrderStatus::ORDER_STATUS_COMPLETED;
+ }
+ }
+ case TerminationReason::EXTERNAL_CANCEL:
+ return api::orderman::OrderStatus::ORDER_STATUS_CANCELED;
+ case TerminationReason::FILLED:
+ return api::orderman::OrderStatus::ORDER_STATUS_COMPLETED;
+ case TerminationReason::UNEXPECTED_CHILD_CANCEL:
+ message="Child order cancelled";
+ return api::orderman::OrderStatus::ORDER_STATUS_CANCELED;
+ case TerminationReason::CHILD_ERROR:
+ message="Child order error";
+ return api::orderman::OrderStatus::ORDER_STATUS_CANCELED;
+ }
+ }
+ return api::orderman::OrderStatus::ORDER_STATUS_WORKING;
+ }
+} // namespace orderman
+} // namespace bts
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/QueueHolderOrder.h b/src/lib/orderman/orders/queue_holder/QueueHolderOrder.h
new file mode 100644
index 000000000..1a36c9dc1
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/QueueHolderOrder.h
@@ -0,0 +1,151 @@
+#pragma once
+
+#include
+#include "lib/orderman/orders/Order.h"
+#include "lib/api/services/OrderService.server.pb.h"
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+#include "lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.h"
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.h"
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.h"
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.h"
+#include "lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QHOOrderManager.h"
+#include "lib/orderman/orders/OrderOpResult.h"
+
+namespace bts {
+namespace api {namespace orderman {class OrderDefinition;}}
+namespace mercury {class TimerEvent;}
+namespace md {class PriceSize;}
+namespace orderman {
+
+class OrderStateUpdateEvent;
+class BookUpdateEvent;
+class PreActivationOrderServices;
+
+class QueueHolderOrder : public Order
+{
+friend QHOStartStateWorker;
+friend QHOWaitingForAckStateWorker;
+friend QHOWorkingStateWorker;
+friend QHOWaitingForCancelAllStateWorker;
+friend QHOEndStateWorker;
+public:
+ QueueHolderOrder();
+ QueueHolderOrder(const QueueHolderOrder&)=delete;
+ QueueHolderOrder(QueueHolderOrder&&)=delete;
+ QueueHolderOrder& operator=(const QueueHolderOrder&)=delete;
+ QueueHolderOrder& operator=(QueueHolderOrder&&)=delete;
+ virtual ~QueueHolderOrder();
+ api::orderman::OrderDefinition const& definition() const;
+ void on_init_new(api::orderman::OrderDefinition const&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(api::orderman::OrderRecord const&,
+ const PreActivationOrderServices &) override;
+ OrderOpResult on_activate(Price, Quantity,
+ OrderServices&) override;
+ OrderOpResult on_update(Price, Quantity) override;
+ OrderOpResult on_cancel() override;
+ OrderOpResult on_detach() override;
+private:
+ enum class TerminationReason
+ {
+ // initial value at the time of the first cancel
+ NONE,
+ EXTERNAL_CANCEL,
+ // order got filled (since there are multiple
+ // orders we need to cancel the rest)
+ FILLED,
+ // one or more child orders got cancelled
+ UNEXPECTED_CHILD_CANCEL,
+ // child order errored out
+ CHILD_ERROR
+ };
+private:
+ // callbacks from book and child order udpates
+ void _on_book_update(const BookUpdateEvent&);
+ void _on_child_order_update(OrderStateUpdateEvent const&);
+ void _on_time (const bts::mercury::TimerEvent&);
+private:
+ QueueHolderOrderState _state() const{
+ return _state_worker->state();
+ }
+ int _state_int() const{
+ if (_state_worker==nullptr)
+ return -1;
+ return static_cast(_state_worker->state());
+ }
+ bool _activated() const{
+ return _services!=nullptr;
+ }
+ void _cancel_order(TerminationReason termination_reason){
+ bts_assert(termination_reason!=TerminationReason::NONE);
+ bts_assert(_termination_reason==TerminationReason::NONE);
+ _termination_reason=termination_reason;
+ _switch_state(QueueHolderOrderState::WAITING_FOR_CANCEL_ALL);
+ }
+ api::orderman::OrderStatus status(std::string& message) const;
+ // sends orders for the first time
+ void _report_state(){
+ if(_activated()){
+ std::string err_msg;
+ _reported_state.set_status(status(err_msg));
+ double filled_price;
+ uint32_t filled_qty;
+ _order_manager.filled_price(filled_price,filled_qty);
+ if(filled_qty>_reported_state.filled_quantity()){
+ // this means there was a fill reported bw last report
+ // and this, hence last_price needs to be set
+ uint32_t last_trade_qty=filled_qty-
+ _reported_state.filled_quantity();
+ double last_trade_price=filled_price*filled_qty-
+ _reported_state.avg_price()*_reported_state.filled_quantity();
+ last_trade_price/=last_trade_qty;
+ _reported_state.set_last_price(last_trade_price);
+ }
+ _reported_state.set_avg_price(filled_price);
+ _reported_state.set_filled_quantity(filled_qty);
+ _reported_state.set_last_msg(err_msg);
+ _services->report_state(_reported_state);
+ }
+ }
+ void _set_state_price_qty(Price price, Quantity qty){
+ _reported_state.set_price(price.value());
+ _reported_state.set_quantity(qty.value());
+ }
+ bool _filled() const{
+ return _order_manager.filled_qty().value()>=
+ _reported_state.quantity();
+ }
+
+ void _switch_state(QueueHolderOrderState new_state);
+
+ void _assert_false(const std::string& str) const{
+ std::ostringstream oss;
+ oss << str << " key:" << key();
+ bts_assert_msg(false, oss.str());
+ }
+private:
+ // if the init call succeeded which means
+ // i. order is properly built
+ // ii. security was successfully resolved
+ bool _is_succ_inited;
+ // tells if the order is a recovered order
+ // (as opposed to a new order)
+ bool _is_recovered;
+ TerminationReason _termination_reason;
+ api::orderman::OrderDefinition _order_def;
+ double _tick_size;
+ OrderBuilder _order_builder;
+ QHOOrderManager _order_manager;
+ OrderServices *_services;
+ api::orderman::OrderState _reported_state;
+ Book _book;
+ IQueueHolderOrderStateWorker* _state_worker;
+ QHOStartStateWorker _start_state_worker;
+ QHOWaitingForAckStateWorker _waiting_for_ack_state_worker;
+ QHOWorkingStateWorker _working_state_worker;
+ QHOWaitingForCancelAllStateWorker _waiting_for_cancel_all_state_worker;
+ QHOEndStateWorker _end_state_worker;
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/QueueHolderOrderState.h b/src/lib/orderman/orders/queue_holder/QueueHolderOrderState.h
new file mode 100644
index 000000000..c315b2cc4
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/QueueHolderOrderState.h
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace bts{
+namespace orderman{
+enum class QueueHolderOrderState{
+ // remains here till on_activate is called
+ START=0,
+ // once the order is submitted it gets into
+ // this state until it gets an ack on all
+ // the sub orders
+ WAITING_FOR_FIRST_ACK=1,
+ // all orders are ack'ed, free to accept
+ // updates
+ WORKING=2,
+ // cancel has been sent, wait for all
+ // sub orders to be in final state
+ WAITING_FOR_CANCEL_ALL=3,
+ // final state, no going back
+ END=4
+};
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.cpp b/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.cpp
new file mode 100644
index 000000000..6c376706a
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.cpp
@@ -0,0 +1,58 @@
+#include "lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
+#include "lib/domain_model/Security.h"
+#include "lib/logging/logging.h"
+#include "lib/orderman/actors/order_manager/OrderBuilder.h"
+#include "lib/orderman/events/BookUpdateEvent.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
+#include "lib/os/os.h"
+#include "lib/utils/PBUtils.h"
+#include
+#include
+#include "lib/os/os.h"
+
+namespace bts{
+namespace orderman{
+
+QHOEndStateWorker::QHOEndStateWorker(QueueHolderOrder* parent)
+:
+_porder(parent)
+{}
+
+void QHOEndStateWorker::on_transition (){
+}
+
+void QHOEndStateWorker::on_init_new(
+ const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOEndStateWorker::on_init_new");
+}
+void QHOEndStateWorker::on_init_recovered(
+ const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOEndStateWorker::on_init_recovered");
+}
+void QHOEndStateWorker::on_activate(Price,
+ Quantity,
+ OrderServices&){
+ _porder->_assert_false("QHOEndStateWorker::on_activate");
+}
+void QHOEndStateWorker::on_update(Price,
+ Quantity){
+ LOG(OrderMan, Warn, "QHOEndStateWorker::on_update "
+ "key:{} rejected",_porder->key());
+}
+void QHOEndStateWorker::on_cancel(){
+ LOG(OrderMan, Warn, "QHOEndStateWorker::on_cancel "
+ "key:{} already in termminal state",_porder->key());
+}
+void QHOEndStateWorker::on_child_order_update(const OrderStateUpdateEvent& ev){
+ LOG(OrderMan, Error, "QHOEndStateWorker::on_child_order_update "
+ "key:{} order_key:{}",_porder->key(),ev.key);
+}
+void QHOEndStateWorker::on_book(const Book&,
+ const trace::CorID&){
+}
+void QHOEndStateWorker::on_time(const TimeStamp&){
+}
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.h b/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.h
new file mode 100644
index 000000000..a12a29af2
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOEndStateWorker.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+
+namespace bts{
+namespace orderman{
+
+class QueueHolderOrder;
+// this is the starting node. since the hedger
+// can be reused, the end state can lead back to this
+class QHOEndStateWorker : public IQueueHolderOrderStateWorker
+{
+private:
+ QueueHolderOrder* const _porder;
+public:
+ QHOEndStateWorker(QueueHolderOrder* parent);
+ QueueHolderOrderState state () const override {
+ return QueueHolderOrderState::END;
+ }
+ void on_transition () override;
+ void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) override;
+ void on_activate(Price, Quantity, OrderServices&) override;
+ void on_update(Price, Quantity) override;
+ void on_cancel() override;
+ void on_child_order_update(const OrderStateUpdateEvent&) override;
+ void on_book(const Book&,
+ const trace::CorID&) override;
+ void on_time(const TimeStamp&) override;
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.cpp b/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.cpp
new file mode 100644
index 000000000..a5d2e47db
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.cpp
@@ -0,0 +1,128 @@
+#include "lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
+#include "lib/domain_model/Security.h"
+#include "lib/logging/logging.h"
+#include "lib/orderman/actors/order_manager/OrderBuilder.h"
+#include "lib/orderman/events/BookUpdateEvent.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
+#include "lib/orderman/orders/PreActivationOrderServices.h"
+#include "lib/os/os.h"
+#include "lib/utils/PBUtils.h"
+#include
+#include
+#include "lib/os/os.h"
+
+namespace bts{
+namespace orderman{
+
+QHOStartStateWorker::QHOStartStateWorker(QueueHolderOrder* parent)
+:
+_porder(parent)
+{}
+
+void QHOStartStateWorker::on_transition (){
+}
+
+void QHOStartStateWorker::on_init_new(
+ const api::orderman::OrderDefinition& order_def,
+ const PreActivationOrderServices& pre_os){
+ _porder->_is_succ_inited=_on_init_new(order_def, pre_os);
+}
+void QHOStartStateWorker::on_init_recovered(
+ const bts::api::orderman::OrderRecord& rec,
+ const PreActivationOrderServices& pre_os){
+ _porder->_is_succ_inited=_on_init_new(rec.def(), pre_os);
+ _porder->_is_recovered=true;
+}
+void QHOStartStateWorker::on_activate(Price price,
+ Quantity qty,
+ OrderServices& services){
+ api::orderman::OrderState& state=_porder->_reported_state;
+ // reference is kept even for orders that are not initialized
+ // properly or when constructed from the disk
+ _porder->_services = &services;
+ state.set_price(price.value());
+ state.set_quantity(qty.value());
+ // failed to init or recovered orders are sent directly
+ // to end (recovered have to be dealt with later)
+ if (_porder->_is_recovered || !_porder->_is_succ_inited)
+ _porder->_switch_state(QueueHolderOrderState::END);
+ else {
+ _porder->_order_builder.activate(services);
+ _porder->_order_manager.init(
+ _porder->_order_builder,
+ SecurityKey(_porder->_order_def.security_key()),
+ _porder->_order_def.side(),
+ _porder->_tick_size,
+ _porder->_order_def.custom_def().queue_holder().n_queue_orders(),
+ price,
+ qty);
+ services.subscribe_to_child_updates(
+ [this](const OrderStateUpdateEvent &os) {
+ _porder->_on_child_order_update(os);
+ });
+ services.subscribe_to_book(
+ SecurityKey(_porder->_order_def.security_key()),
+ [this](const BookUpdateEvent &bk_event) {
+ _porder->_on_book_update(bk_event);
+ });
+ services.subscribe_to_time([this](const bts::mercury::TimerEvent &te) {
+ _porder->_on_time(te);
+ });
+ _porder->_switch_state(QueueHolderOrderState::WAITING_FOR_FIRST_ACK);
+ }
+}
+void QHOStartStateWorker::on_update(Price,
+ Quantity){
+ _porder->_assert_false("QHOStartStateWorker::on_update");
+}
+void QHOStartStateWorker::on_cancel(){
+ _porder->_assert_false("QHOStartStateWorker::on_cancel");
+}
+void QHOStartStateWorker::on_child_order_update(
+ const OrderStateUpdateEvent&){
+ _porder->_assert_false("QHOStartStateWorker::on_child_order_update");
+}
+void QHOStartStateWorker::on_book(const Book&,
+ const trace::CorID&){
+ _porder->_assert_false("QHOStartStateWorker::on_book");
+}
+void QHOStartStateWorker::on_time(const TimeStamp&){
+ _porder->_assert_false("QHOStartStateWorker::on_time");
+}
+bool QHOStartStateWorker::_on_init_new(
+ const api::orderman::OrderDefinition& order_def,
+ const PreActivationOrderServices& pre_os) {
+ _porder->_order_def=order_def;
+ if (!order_def.has_custom_def() ||
+ !order_def.custom_def().has_queue_holder()) {
+ LOG(OrderMan, Error,
+ "QHOStartStateWorker::_on_init_new key:{} "
+ "OrderDefinition does not have QueueHolderDefinition",
+ _porder->key());
+ return false;
+ }
+ const bts::api::Security* sec_ptr =
+ pre_os.sec_db.resolve(SecurityKey(order_def.security_key()));
+ if (sec_ptr==nullptr) {
+ LOG(OrderMan, Error,
+ "QHOStartStateWorker::_on_init_new key:{} "
+ "Could not resolve sec_key:{}",
+ _porder->key(), order_def.security_key());
+ return false;
+ }
+ _porder->_tick_size=sec_ptr->contract_spec().low_tick();
+ const api::orderman::QueueHolderDefinition& qho_def=
+ order_def.custom_def().queue_holder();
+ api::orderman::OrderDefinition child_order_def = order_def;
+ child_order_def.mutable_custom_def()->CopyFrom(qho_def.child());
+ _porder->_order_builder = OrderBuilder(_porder->key(),
+ child_order_def,
+ pre_os.order_factory,
+ qho_def.n_queue_orders()+1);
+ LOG(OrderMan, Info,
+ "QHOStartStateWorker::_on_init_new key:{} ",
+ _porder->key());
+ return true;
+}
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.h b/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.h
new file mode 100644
index 000000000..8f81036be
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOStartStateWorker.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+
+namespace bts{
+namespace orderman{
+
+class QueueHolderOrder;
+// this is the starting state where the int_new/recover
+// and activation is done. upon activation
+// if everything is good, it places suborders and moves
+// transitions to WAITING_FOR_FIRST_ACK
+// else transitions to END
+class QHOStartStateWorker : public IQueueHolderOrderStateWorker
+{
+private:
+ QueueHolderOrder* const _porder;
+public:
+ QHOStartStateWorker(QueueHolderOrder* parent);
+ QueueHolderOrderState state () const override {
+ return QueueHolderOrderState::START;
+ }
+ void on_transition () override;
+ void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) override;
+ void on_activate(Price, Quantity, OrderServices&) override;
+ void on_update(Price, Quantity) override;
+ void on_cancel() override;
+ void on_child_order_update(const OrderStateUpdateEvent&) override;
+ void on_book(const Book&,
+ const trace::CorID&) override;
+ void on_time(const TimeStamp&) override;
+private:
+ bool _on_init_new(const api::orderman::OrderDefinition& order_def,
+ const PreActivationOrderServices& pre_os);
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.cpp b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.cpp
new file mode 100644
index 000000000..e869d10a2
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.cpp
@@ -0,0 +1,81 @@
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
+#include "lib/domain_model/Security.h"
+#include "lib/logging/logging.h"
+#include "lib/orderman/actors/order_manager/OrderBuilder.h"
+#include "lib/orderman/events/BookUpdateEvent.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
+#include "lib/os/os.h"
+#include "lib/utils/PBUtils.h"
+#include
+#include
+#include "lib/os/os.h"
+
+namespace bts{
+namespace orderman{
+
+QHOWaitingForAckStateWorker::QHOWaitingForAckStateWorker(
+ QueueHolderOrder* parent)
+:
+_porder(parent),
+_orders_placed_once(false)
+{}
+
+void QHOWaitingForAckStateWorker::on_transition (){
+ // this is the only place where orders
+ // are placed
+ if(!_orders_placed_once){
+ _porder->_order_manager.place_order();
+ _orders_placed_once=true;
+ }
+ else
+ _porder->_order_manager.reenter_filled_orders();
+}
+
+void QHOWaitingForAckStateWorker::on_init_new(
+ const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWaitingForAckStateWorker::on_init_new");
+}
+void QHOWaitingForAckStateWorker::on_init_recovered(
+ const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWaitingForAckStateWorker::on_init_recovered");
+}
+void QHOWaitingForAckStateWorker::on_activate(Price,
+ Quantity,
+ OrderServices&){
+ _porder->_assert_false("QHOWaitingForAckStateWorker::on_activate");
+}
+void QHOWaitingForAckStateWorker::on_update(Price price,
+ Quantity quantity){
+ // cache it here, and update order when
+ // transferring to WORKING
+ _porder->_set_state_price_qty(price,quantity);
+ if(_porder->_filled())
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::FILLED);
+}
+void QHOWaitingForAckStateWorker::on_cancel(){
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::EXTERNAL_CANCEL);
+}
+void QHOWaitingForAckStateWorker::on_child_order_update(
+ const OrderStateUpdateEvent& ev){
+ QHOOrderManager& order_man=_porder->_order_manager;
+ if(order_man.on_order_update(ev)){
+ if (_porder->_filled())
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::FILLED);
+ else if(order_man.all_orders_acked())
+ _porder->_switch_state(QueueHolderOrderState::WORKING);
+ }
+ else
+ LOG(OrderMan, Error,
+ "QHOWaitingForAckStateWorker::on_child_order_update "
+ "key:{} order:{} could not be found",
+ _porder->key(),ev.key);
+}
+void QHOWaitingForAckStateWorker::on_book(const Book&,
+ const trace::CorID&){
+}
+void QHOWaitingForAckStateWorker::on_time(const TimeStamp&){
+}
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.h b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.h
new file mode 100644
index 000000000..5a4f560f8
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForAckStateWorker.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+
+namespace bts{
+namespace orderman{
+
+class QueueHolderOrder;
+// orders are placed on the transition to this state. it
+// leaves the state when
+// order is cxled -> WAITING_FOR_CANCEL_ALL
+// order is overfilled -> WAITING_FOR_CANCEL_ALL
+// all orders acked -> WORKING
+// updates are passed over to the state and
+// maybe used in deiciding if filled or not
+// (since we are gong to to do away with this state
+// most of the logic is moved out)
+class QHOWaitingForAckStateWorker : public IQueueHolderOrderStateWorker
+{
+private:
+ QueueHolderOrder* const _porder;
+ bool _orders_placed_once;
+public:
+ QHOWaitingForAckStateWorker(QueueHolderOrder* parent);
+ QueueHolderOrderState state () const override {
+ return QueueHolderOrderState::WAITING_FOR_FIRST_ACK;
+ }
+ void on_transition () override;
+ void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) override;
+ void on_activate(Price, Quantity, OrderServices&) override;
+ void on_update(Price, Quantity) override;
+ void on_cancel() override;
+ void on_child_order_update(const OrderStateUpdateEvent&) override;
+ void on_book(const Book&,
+ const trace::CorID&) override;
+ void on_time(const TimeStamp&) override;
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.cpp b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.cpp
new file mode 100644
index 000000000..f621753a9
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.cpp
@@ -0,0 +1,74 @@
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
+#include "lib/domain_model/Security.h"
+#include "lib/logging/logging.h"
+#include "lib/orderman/actors/order_manager/OrderBuilder.h"
+#include "lib/orderman/events/BookUpdateEvent.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
+#include "lib/os/os.h"
+#include "lib/utils/PBUtils.h"
+#include
+#include
+#include "lib/os/os.h"
+
+namespace bts{
+namespace orderman{
+
+QHOWaitingForCancelAllStateWorker::QHOWaitingForCancelAllStateWorker(
+ QueueHolderOrder* parent)
+:
+_porder(parent)
+{}
+
+void QHOWaitingForCancelAllStateWorker::on_transition (){
+ _analyze_and_cancel();
+}
+
+void QHOWaitingForCancelAllStateWorker::on_init_new(
+ const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWaitingForCancelAllStateWorker::on_init_new");
+}
+void QHOWaitingForCancelAllStateWorker::on_init_recovered(
+ const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWaitingForCancelAllStateWorker::on_init_recovered");
+}
+void QHOWaitingForCancelAllStateWorker::on_activate(Price,
+ Quantity,
+ OrderServices&){
+ _porder->_assert_false("QHOWaitingForCancelAllStateWorker::on_activate");
+}
+void QHOWaitingForCancelAllStateWorker::on_update(Price,
+ Quantity){
+ LOG(OrderMan, Warn, "QHOWaitingForCancelAllStateWorker::on_update "
+ "key:{} rejected",_porder->key());
+}
+void QHOWaitingForCancelAllStateWorker::on_cancel(){
+ LOG(OrderMan, Info, "QHOWaitingForCancelAllStateWorker::on_cancel "
+ "key:{} already cancelled",_porder->key());
+}
+void QHOWaitingForCancelAllStateWorker::on_child_order_update(
+ const OrderStateUpdateEvent& ev){
+ if(_porder->_order_manager.on_order_update(ev))
+ _analyze_and_cancel();
+ else
+ LOG(OrderMan, Error,
+ "QHOWaitingForCancelAllStateWorker::on_child_order_update "
+ "key:{} order:{} could not be found",
+ _porder->key(),ev.key);
+}
+void QHOWaitingForCancelAllStateWorker::on_book(const Book&,
+ const trace::CorID&){
+}
+void QHOWaitingForCancelAllStateWorker::on_time(const TimeStamp&){
+ /// TODO, time-out
+}
+void QHOWaitingForCancelAllStateWorker::_analyze_and_cancel(){
+ QHOOrderManager& order_man=_porder->_order_manager;
+ if(!order_man.all_orders_terminal())
+ order_man.cancel();
+ else
+ _porder->_switch_state(QueueHolderOrderState::END);
+}
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.h b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.h
new file mode 100644
index 000000000..f2e7c53f2
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWaitingForCancelAllStateWorker.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+
+namespace bts{
+namespace orderman{
+
+class QueueHolderOrder;
+// transfer to this state means the order needs to
+// be cancelled. _analyze_and_cancel() is called
+// on_transition and everytime there is an order update.
+// _analyze_and_cancel() tried cancelling all orders,
+// and if orders are in terminal state goes to end
+class QHOWaitingForCancelAllStateWorker : public IQueueHolderOrderStateWorker
+{
+private:
+ QueueHolderOrder* const _porder;
+public:
+ QHOWaitingForCancelAllStateWorker(QueueHolderOrder* parent);
+ QueueHolderOrderState state () const override {
+ return QueueHolderOrderState::WAITING_FOR_CANCEL_ALL;
+ }
+ void on_transition () override;
+ void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) override;
+ void on_activate(Price, Quantity, OrderServices&) override;
+ void on_update(Price, Quantity) override;
+ void on_cancel() override;
+ void on_child_order_update(const OrderStateUpdateEvent&) override;
+ void on_book(const Book&,
+ const trace::CorID&) override;
+ void on_time(const TimeStamp&) override;
+private:
+ void _analyze_and_cancel();
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.cpp b/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.cpp
new file mode 100644
index 000000000..136c9b699
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.cpp
@@ -0,0 +1,112 @@
+#include "lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.h"
+#include "lib/orderman/orders/queue_holder/QueueHolderOrder.h"
+#include "lib/domain_model/Security.h"
+#include "lib/logging/logging.h"
+#include "lib/orderman/actors/order_manager/OrderBuilder.h"
+#include "lib/orderman/events/BookUpdateEvent.h"
+#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
+#include "lib/os/os.h"
+#include "lib/utils/PBUtils.h"
+#include
+#include
+#include "lib/os/os.h"
+
+namespace bts{
+namespace orderman{
+
+QHOWorkingStateWorker::QHOWorkingStateWorker(QueueHolderOrder* parent)
+:
+_porder(parent)
+{}
+void QHOWorkingStateWorker::on_transition (){
+ if(!_analyze_moving_out()){
+ const api::orderman::OrderState& state=_porder->_reported_state;
+ // cached updates while waiting for acks
+ on_update(Price(state.price()),
+ Quantity(state.quantity()));
+ }
+}
+void QHOWorkingStateWorker::on_init_new(
+ const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWorkingStateWorker::on_init_new");
+}
+void QHOWorkingStateWorker::on_init_recovered(
+ const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&){
+ _porder->_assert_false("QHOWorkingStateWorker::on_init_recovered");
+}
+void QHOWorkingStateWorker::on_activate(Price,
+ Quantity,
+ OrderServices&){
+ _porder->_assert_false("QHOWorkingStateWorker::on_activate");
+}
+void QHOWorkingStateWorker::on_update(Price price,
+ Quantity qty){
+ _porder->_set_state_price_qty(price,qty);
+ if(_porder->_filled())
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::FILLED);
+ else
+ _porder->_order_manager.modify_order(price, qty);
+}
+void QHOWorkingStateWorker::on_cancel(){
+ _porder->_order_manager.cancel();
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::EXTERNAL_CANCEL);
+}
+void QHOWorkingStateWorker::on_child_order_update(
+ const OrderStateUpdateEvent& ev){
+ QHOOrderManager& order_man=_porder->_order_manager;
+ if(order_man.on_order_update(ev)){
+ if(!_analyze_moving_out()){
+ if(order_man.last_update_has_fills())
+ // in case of fills, we can reduce
+ // the qty of the trailing orders to
+ // decrease probablity of overfills
+ order_man.prune_quantities();
+ }
+ }
+ else
+ LOG(OrderMan, Error, "QHOWorkingStateWorker::on_child_order_update "
+ "key:{} order:{} could not be found",
+ _porder->key(),ev.key);
+}
+// returns true if state is changed
+bool QHOWorkingStateWorker::_analyze_moving_out(){
+ // order is cancelled if over filled or any of the
+ // constituent orders end up in an unexpected terminal
+ // state
+ if(_porder->_filled()){
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::FILLED);
+ return true;
+ }
+ const QHOOrderManager& order_man=_porder->_order_manager;
+ if(order_man.has_cancelled_order()){
+ _porder->_cancel_order(
+ QueueHolderOrder::TerminationReason::UNEXPECTED_CHILD_CANCEL);
+ return true;
+ }
+ if(order_man.has_cancelled_order()){
+ _porder->_cancel_order(QueueHolderOrder::TerminationReason::CHILD_ERROR);
+ return true;
+ }
+ // QHO order's target qty has not been reached
+ // yet one or more component orders has been filled.
+ // switching to WAITING_FOR_FIRST_ACK will cause
+ // filled orders to be replaced with new orders
+ if (order_man.has_completed_order()){
+ _porder->_switch_state(QueueHolderOrderState::WAITING_FOR_FIRST_ACK);
+ return true;
+ }
+ // all orders have to be acked in this state &&
+ // if an order was cxled or errored out, the first
+ // if would have caught it. and if filled, the
+ // second would have
+ bts_assert(order_man.all_orders_acked() && !order_man.has_terminal_order());
+ return false;
+}
+void QHOWorkingStateWorker::on_book(const Book&,
+ const trace::CorID&){
+}
+void QHOWorkingStateWorker::on_time(const TimeStamp&){
+}
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.h b/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.h
new file mode 100644
index 000000000..57c14e6c2
--- /dev/null
+++ b/src/lib/orderman/orders/queue_holder/state_workers/QHOWorkingStateWorker.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "lib/orderman/orders/queue_holder/IQueueHolderOrderStateWorker.h"
+
+namespace bts{
+namespace orderman{
+
+class QueueHolderOrder;
+// main working state
+class QHOWorkingStateWorker : public IQueueHolderOrderStateWorker
+{
+private:
+ QueueHolderOrder* const _porder;
+public:
+ QHOWorkingStateWorker(QueueHolderOrder* parent);
+ QueueHolderOrderState state () const override {
+ return QueueHolderOrderState::WORKING;
+ }
+ void on_transition () override;
+ void on_init_new(const api::orderman::OrderDefinition&,
+ const PreActivationOrderServices&) override;
+ void on_init_recovered(const bts::api::orderman::OrderRecord&,
+ const PreActivationOrderServices&) override;
+ void on_activate(Price, Quantity, OrderServices&) override;
+ void on_update(Price, Quantity) override;
+ void on_cancel() override;
+ void on_child_order_update(const OrderStateUpdateEvent&) override;
+ void on_book(const Book&,
+ const trace::CorID&) override;
+ void on_time(const TimeStamp&) override;
+private:
+ // returns true if the state is changed
+ bool _analyze_moving_out();
+ bool _needs_cancelling() const;
+};
+
+}}
\ No newline at end of file
diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp
index 6c19fe039..622fd4cba 100644
--- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp
+++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp
@@ -45,7 +45,7 @@ void SpreaderChildOrderState::re_init (ChildOrder& child_order){
_filled_price, _filled_quantity,
_base_price, _base_quantity);
_n_place_orders = 0;
- _n_cancel_orders = _n_modify_orders = 0;
+ _n_cancel_orders = _n_modify_orders = 0;
_child_order = ChildOrder();
_child_order = std::move(child_order);
_status = bts::api::orderman::OrderStatus::ORDER_STATUS_INACTIVE;
diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h
index 3604e84eb..4046db95a 100644
--- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h
+++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.h
@@ -83,12 +83,23 @@ public:
Quantity last_update_filled_quantity () const {
return _last_filled_quantity;
}
+ // all the status calls are based on the
+ // current order (and not the subsumed ones)
bool terminal_status() const {
return SpreaderUtils::order_in_terminal_state(_status);
}
- bool acknowledged () const {
+ bool acknowledged() const {
return SpreaderUtils::order_acknowledged (_status);
}
+ bool cancelled() const{
+ return SpreaderUtils::order_in_cancelled_state(_status);
+ }
+ bool completed() const{
+ return SpreaderUtils::order_in_completed_state(_status);
+ }
+ bool errored() const{
+ return SpreaderUtils::order_in_error_state(_status);
+ }
// this is total fills across current and
// previous orders
Quantity total_fills() const {
@@ -113,9 +124,11 @@ public:
bts::TimeStamp order_place_time() const{
return _order_place_time;
}
- // const trace::CorID& last_update_trace() const{
- // return _last_update_trace;
- // }
+ // returns true if the current order has been
+ // cancelled
+ bool is_cancelled() const{
+ return _n_cancel_orders>0;
+ }
// init ///////////////////
///////////////////////////
// this assignes a new order, and subsumes the earlier order's
diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp
index 84eb24597..d6079fb3b 100644
--- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp
+++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp
@@ -45,13 +45,25 @@ bool SpreaderUtils::resolve_synthetic_spread (const SpreaderPreActivationOrderSe
quoter_order_def.set_security_key (leg.security().id());
quoter_order_def.set_side(leg_order_side);
quoter_order_def.set_sub_type(bts::api::orderman::OrderSubType::ORDER_SUB_TYPE_QUOTING_LEG);
- quoter_order_def.mutable_custom_def()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
+
+ uint32_t n_queue_holder_orders=leg_params.quote_params().n_queue_holder_orders();
+ if(n_queue_holder_orders>0){
+ api::orderman::QueueHolderDefinition qho_order_def;
+ qho_order_def.set_n_queue_orders(n_queue_holder_orders);
+ qho_order_def.mutable_child()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
+ quoter_order_def.mutable_custom_def()->mutable_queue_holder()->MergeFrom (qho_order_def);
+ }
+ else{
+ quoter_order_def.mutable_custom_def()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
+ }
+
if(leg_params.quote_params().has_quote_hidden())
quoter_order_def.set_time_in_force(bts::api::orderman::TimeInForce::TIME_IN_FORCE_IOC);
else
quoter_order_def.set_time_in_force(bts::api::orderman::TimeInForce::TIME_IN_FORCE_DAY);
// hedger order def
api::orderman::OrderDefinition hedger_order_def = quoter_order_def;
+ hedger_order_def.mutable_custom_def()->mutable_limit()->MergeFrom (api::orderman::LimitOrderDefinition());
hedger_order_def.set_time_in_force(bts::api::orderman::TimeInForce::TIME_IN_FORCE_DAY);
hedger_order_def.set_sub_type(bts::api::orderman::OrderSubType::ORDER_SUB_TYPE_HEDGING_LEG);
LegPropertyData leg_property_data(leg_idx, leg, leg_params, leg_order_side,sec.synthetic().price_calc());
diff --git a/src/lib/orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp b/src/lib/orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp
index e4ba33b7c..d0e546c28 100644
--- a/src/lib/orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp
+++ b/src/lib/orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp
@@ -3,27 +3,31 @@
namespace bts{
namespace orderman{
-SpreaderPreActivationOrderServices::SpreaderPreActivationOrderServices (const bts::orderman::PreActivationOrderServices* pre_services)
+SpreaderPreActivationOrderServices::SpreaderPreActivationOrderServices
+(const bts::orderman::PreActivationOrderServices* pre_services)
:
_pre_services(pre_services),
_test_only_pre_services (nullptr)
{}
-SpreaderPreActivationOrderServices::SpreaderPreActivationOrderServices (TestOnlySpreaderPreActivationOrderServices* test_only_pre_services)
+SpreaderPreActivationOrderServices::SpreaderPreActivationOrderServices
+(TestOnlySpreaderPreActivationOrderServices* test_only_pre_services)
:
_pre_services(nullptr),
_test_only_pre_services (test_only_pre_services)
{}
-const bts::api::Security* SpreaderPreActivationOrderServices::resolve (SecurityKey key) const{
+const bts::api::Security* SpreaderPreActivationOrderServices::resolve (
+ SecurityKey key) const{
if (is_live ())
return _pre_services->sec_db.resolve(key);
else
return _test_only_pre_services->resolve(key);
}
-bool SpreaderPreActivationOrderServices::is_live () const{
+bool SpreaderPreActivationOrderServices::is_live() const{
return _pre_services != nullptr;
}
-const bts::orderman::PreActivationOrderServices& SpreaderPreActivationOrderServices::pre_services() const{
- bts_assert(is_live ());
+const bts::orderman::PreActivationOrderServices&
+SpreaderPreActivationOrderServices::pre_services() const{
+ bts_assert(is_live());
return *_pre_services;
}
diff --git a/src/lib/sparkproto/SparkProtos.proto b/src/lib/sparkproto/SparkProtos.proto
index 08ad8512c..bcc2830d0 100644
--- a/src/lib/sparkproto/SparkProtos.proto
+++ b/src/lib/sparkproto/SparkProtos.proto
@@ -65,6 +65,11 @@ message QuoteParams
QuoteMaxOrderMove quote_max_order_move = 1040;
QuoteHidden quote_hidden = 1050;
ConditionalQuoting conditional_quoting=1060;
+ // default value 0, 1 means we will have one trailing
+ // order behind the top level
+ // (once we have ChildOrder's here, we can reture this
+ // and the user can embed a QHO here)
+ uint32 n_queue_holder_orders=2000;
}
/*************************************Quote MuteZone***********************************
@@ -450,6 +455,13 @@ message PostHedgeOppositeMarketVolumeBasedForcedCross
uint32 cross_ticks = 20;
}
+message ExecutionStrategy
+{
+ bool deleted = 1;
+ map leg_params_map = 20;
+ bool cancel_hedges_on_cancel = 30;
+}
+
// EVERYTHING BELOW THIS LINE IS OBSOLETE
// obsolete
@@ -477,329 +489,4 @@ message StopLimitOrder {
// obsolete
message IcebergOrder {
uint32 show_quantity = 20;
-}
-message ExecutionStrategy
-{
- bool deleted = 1;
- map leg_params_map = 20;
- bool cancel_hedges_on_cancel = 30;
-}
-// obsolete
-message PriceType
-{
- enum Status
- {
- BID = 0;
- ASK = 1;
- LTP = 2;
- }
-
- Status status = 10;
-}
-
-// obsolete
-message PriceOffset
-{
- PriceType price_type = 10;
- int32 offset_in_ticks = 20;
-}
-
-// obsolete
-message OrderTime
-{
- oneof Time
- {
- uint64 absolute_time = 10;
- uint64 offset_from_now = 20;
- bool now = 30;
- }
-}
-
-// /********** Trigger Data **********/
-
-// obsolete
-message TrailingTrigger
-{
- PriceType price_type = 10;
- int32 number_of_ticks = 20;
- oneof TriggerType
- {
- bool stop = 30;
- bool invserse_stop = 40;
- }
-}
-
-// obsolete
-message QuantityTrigger
-{
- QuantityMeasure quantity_measure = 10;
- oneof Relation
- {
- bool less_than_equalto = 20;
- bool greater_than_equalto = 30;
- }
- uint32 threshold_quantity = 40;
-}
-
-// obsolete
-message AbsolutePriceTrigger
-{
- PriceType price_type = 10;
- double trigger_price = 20;
- QuantityTrigger quantity_trigger = 30;
-}
-
-// obsolete
-message PriceTrigger
-{
- oneof Trigger
- {
- TrailingTrigger trailing_trigger = 10;
- AbsolutePriceTrigger absolute_price_trigger = 20;
- }
-}
-
-// /***************************************BTS ShootTillHit*******************************************
-// This is the equivelant of TT's Retry Order. This Order keeps submitting a child order at a specified
-// interval until it is either accepted or rejected a specified max number of times. This is used to get a
-// favorable position in queue before open.
-// Spreader: Not supported (legging risk of one leg getting accepted ?)
-// */
-
-// obsolete
-message BTSShootTillHitParameters
-{
- uint32 max_number_of_tries = 10;
- uint32 time_between_retries_micro_seconds = 20;
- /// This could be a specific time, now, or offset from now
- OrderTime order_entry_time = 30;
-}
-
-// obsolete
-message BTSShootTillHitOrder
-{
- /// Only support a limit or market as Retry's
- /// We can make Retry a general parameter for
- /// every order
- oneof NativeOrderType
- {
- MarketOrder market_order = 10;
- LimitOrder limit_order = 20;
- }
- BTSShootTillHitParameters shoot_till_hit_parameters = 30;
-}
-
-// /*************************************************************************************************/
-
-
-// /****************************BTS With a Tick (general parameter)**********************************
-// This order wraps around a limit order that is automatically repriced one tick towards the inside market
-// i. When the best available price to trade is more than one tick away from the limit price
-// ii. When the best available price is one tick away and the size falls below a certain threshold
-// The idea is that instead of chasing the market (and cross it), you submit it away from the market and only
-// cross the market when the liquidity of the opposite side drops below a threshold.
-// */
-
-// obsolete
-message BTSWithATickParameters
-{
- QuantityMeasure quantity_threshold = 10;
-}
-
-// obsolete
-message BTSWithATickOrder
-{
- BTSWithATickParameters order_parameters = 10;
- oneof NativeOrderType
- {
- LimitOrder limit_order = 20;
- }
- /// The price can also be submitted as an offset from B/A/LTP
- /// instead of an asbolute price
- PriceOffset price_offset = 30;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS Timed Window(general parameters)***********************
-// This order wraps a Limit or Market order in a Timed Window ie sends the order to the market
-// at the Start Time (absolute or relative). At the Stop Time, it performs the End Action for
-// which there is only one option, Cancel
-// */
-
-// obsolete
-/// This can also be a general parameter
-message BTSTimedWindowParameters
-{
- OrderTime start_time = 10;
- OrderTime stop_time = 20;
- oneof EndAction
- {
- bool cancel = 30;
- }
-}
-
-// obsolete
-message BTSTimedWindowOrder
-{
- BTSTimedWindowParameters order_parameters = 10;
- oneof NativeOrderType
- {
- MarketOrder market_order = 20;
- LimitOrder limit_order = 30;
- }
- // The price can also be submitted as an offset from B/A/LTP
- /// instead of an asbolute price
- PriceOffset price_offset = 40;
- BTSWithATickParameters withatick_parameters = 50; /// optional
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS Trailing Limit****************************************
-// Submits a limit order at a fixed distance from the market. It is repriced relative to the market.
-// Trailing orders are always set better than the current market (hence ticks can not be negative). So
-// for a bid order, it’s submitted a fixed number of ticks below the market. If the market goes up,
-// the order moves higher. If the market goes down the order price is not adjusted.
-// (However, when orders are submitted relative to LTP, they can better the market, and get filled
-// immediatly)
-// */
-
-// obsolete
-message BTSTrailingLimitOrder
-{
- PriceOffset price_offset = 10;
- BTSTimedWindowParameters optional_timed_parameters = 20;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS Stop *************************************************
-// Conditional order to buy when the price rises to a designated price level (or sell when it falls).
-// Buy stop orders are placed above the market and sells below. The trigger price (also called stop price)
-// can be an
-// i. Absolute price from where the user clicks on the ladder
-// ii. Trailing price that trails the market by a constant amount (for buy orders, trigger price goes down
-// as the market goes down, so the market penetrates the trigger price on its way up).
-// When the market penetrates the trigger price, a limit order is sent "payup" ticks away form B/A/LTP
-// */
-
-// obsolete
-message BTSStopOrder
-{
- PriceTrigger price_trigger = 10;
- oneof NativeTriggerOrderType
- {
- MarketOrder market_order = 20;
- LimitOrder limit_order = 30;
- }
- oneof TriggerOrderPrice
- {
- PriceOffset payup = 40;
- double price = 50;
- }
- BTSWithATickParameters optional_withatick_parameters = 60;
- BTSTimedWindowParameters optional_timed_parameters = 70;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS IfTouched ********************************************
-// Opposite of BTS Stop (Both in terms of where the order is placed, and how it trails the market
-// */
-
-// obsolete
-message BTSIfTouchedOrder
-{
- PriceTrigger price_trigger = 10;
- oneof NativeTriggerOrderType
- {
- MarketOrder market_order = 20;
- LimitOrder limit_order = 30;
- }
- oneof OrderPrice
- {
- PriceOffset payup = 40;
- double price = 50;
- }
- BTSWithATickParameters optional_withatick_parameters = 60;
- BTSTimedWindowParameters optional_timed_parameters = 70;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS Iceberg***********************************************
-// Breaks a large order into smaller disclosed orders, each of which is sent after the
-// previous has been filled.
-// */
-
-// obsolete
-message BTSIcebergOrder
-{
- QuantityMeasure display_quantity = 10;
- oneof ChildOrderOffset
- {
- PriceOffset market_offset = 20;
- double diff_from_last_fill = 30;
- }
- /// Optional Parameters
- BTSWithATickParameters withatick_parameters = 40;
- PriceTrigger price_trigger = 60;
- BTSTimedWindowParameters timed_window_parameters = 70;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS TimeSlice*************************************/
-
-// obsolete
-message BTSTimeSliceOrder
-{
- double interval = 10;
- QuantityMeasure display_quantity = 20;
- oneof ChildOrderType
- {
- MarketOrder market_order = 30;
- LimitOrder limit_order = 40;
- }
- PriceOffset child_order_offset = 50;
- /// the earlier order can either be left, or its
- /// price moved toward the inside market by payup_ticks
- oneof LeftOverAction
- {
- bool leave = 60;
- double payup_ticks = 70;
- }
- /// Optional Parameters
- BTSWithATickParameters withatick_parameters = 80;
- BTSTimedWindowParameters timed_window_parameters = 90;
- PriceTrigger price_trigger = 100;
-}
-
-// /*************************************************************************************************/
-
-// /***************************************BTS OCO***********************************************
-// Sends a Stop-Loss and a Limit order of the same quantity at different price levels for the same
-// security. For buy's the Limit is sent at a lower price level.
-// i. A fill in the limit order decreases the size of the Stop Order.
-// ii. If the stop order is trigerred, the Limit order is cancelled
-// */
-
-// obsolete
-message BTSOCOOrder
-{
- PriceTrigger price_trigger = 10;
- oneof NativeTriggerOrderType
- {
- MarketOrder market_order = 20;
- LimitOrder limit_order = 30;
- }
- oneof OrderPrice
- {
- PriceOffset payup = 40;
- double price = 50;
- }
- BTSWithATickParameters optional_withatick_parameters = 60;
- BTSTimedWindowParameters optional_timed_parameters = 70;
- /// The price for the limit order is in the main order object
-}
+}
\ No newline at end of file
diff --git a/src/server/sparkd/cmds/RunSim.cpp b/src/server/sparkd/cmds/RunSim.cpp
index 5baab0dbe..abaf2cd53 100644
--- a/src/server/sparkd/cmds/RunSim.cpp
+++ b/src/server/sparkd/cmds/RunSim.cpp
@@ -6,7 +6,7 @@ namespace cmd {
int RunSim::execute(std::vector const &)
{
- sim::start_exchange_sim(api::Venue::VENUE_SIM);
+ sim::start_exchange_sim(api::Venue::VENUE_SIM, nullptr);
return 0;
}
diff --git a/src/server/sparkd/exchange_sim/ExchangeSim.cpp b/src/server/sparkd/exchange_sim/ExchangeSim.cpp
index 5194cf8b4..56bf3f8d5 100644
--- a/src/server/sparkd/exchange_sim/ExchangeSim.cpp
+++ b/src/server/sparkd/exchange_sim/ExchangeSim.cpp
@@ -21,6 +21,7 @@
#include "lib/domain_model/Security.pb.h"
#include "lib/md/relay/RelayRecorder.h"
#include "lib/md/IntPrice.h"
+#include "lib/md/MBOProcessor.h"
#include
@@ -125,7 +126,7 @@ struct MDPlayer : md::IRelayWriter
};
-int start_exchange_sim(bts::api::Venue venue)
+int start_exchange_sim(bts::api::Venue venue, md::MBOWriter* mbo)
{
try
{
@@ -149,7 +150,7 @@ int start_exchange_sim(bts::api::Venue venue)
std::istringstream str{str_settings};
FIX::SessionSettings settings( str );
- ex_sim::ExchangeSimApplication application( venue );
+ ex_sim::ExchangeSimApplication application( venue, mbo );
FIX::FileStoreFactory storeFactory( settings );
FIX::FileLogFactory logFactory( settings );
FIX::SocketAcceptor acceptor( application, storeFactory, settings, logFactory );
diff --git a/src/server/sparkd/exchange_sim/ExchangeSim.h b/src/server/sparkd/exchange_sim/ExchangeSim.h
index d6df31373..2d65cc9e6 100644
--- a/src/server/sparkd/exchange_sim/ExchangeSim.h
+++ b/src/server/sparkd/exchange_sim/ExchangeSim.h
@@ -4,8 +4,9 @@
#include "lib/domain_model/Security.pb.h"
namespace bts {
+namespace md { class MBOWriter; }
namespace sim {
-int start_exchange_sim(bts::api::Venue);
+int start_exchange_sim(bts::api::Venue, md::MBOWriter*);
}}
diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp
index a37d9ee90..340eb1168 100644
--- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp
+++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp
@@ -10,12 +10,14 @@
#include "lib/md/Shm/FixedSecurity.h"
#include "lib/md/Shm/MDStructure.h"
#include "lib/md/get_symbols.h"
+#include "lib/md/MBOProcessor.h"
#include "lib/utils/Dispatcher.h"
#include "lib/utils/datetime.h"
#include "server/sparkd/exchange_sim/book/Order.h"
#include "server/sparkd/exchange_sim/book/OrderMatcher.h"
#include "server/sparkd/exchange_sim/book/book_transform.h"
#include "lib/persistence/SqliteStore.h"
+#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include
#include
@@ -99,15 +101,21 @@ struct ExchangeSimApplication::MDConsumerRec {
utils::TimeStamp last_read;
};
+inline FIX::OrderID exchange_key(const std::string& clOrdID) {
+ return FIX::OrderID(clOrdID.substr(3));
+}
+
struct ExchangeSimApplication::PImpl {
- PImpl(bts::api::Venue venue)
+ PImpl(bts::api::Venue venue, md::MBOWriter* mbo)
: venue(venue),
producer(co2::PLATFORM_SIM),
md_sn(1),
timer(utils::Dispatcher::background(), 200,
[=]() { producer.heartbeat(); }),
do_merge_with_md(config::get().merge_with_md()),
- store(new persistence::SqliteStore("ex_sim_orders_" + api::Venue_Name(venue))) {}
+ store(new persistence::SqliteStore("ex_sim_orders_" + api::Venue_Name(venue))),
+ lock(),
+ mbo(mbo) {}
IDGenerator m_generator;
bts::api::Venue venue;
@@ -120,9 +128,10 @@ struct ExchangeSimApplication::PImpl {
bool do_merge_with_md;
std::unique_ptr store;
std::mutex lock;
+ md::MBOWriter* mbo;
};
-ExchangeSimApplication::ExchangeSimApplication(bts::api::Venue venue) : me(new PImpl(venue)) {
+ExchangeSimApplication::ExchangeSimApplication(bts::api::Venue venue, md::MBOWriter* mbo) : me(new PImpl(venue, mbo)) {
auto previous_book = me->store->retrieve_all();
auto all = me->store->retrieve_all()["books"];
@@ -374,7 +383,7 @@ void ExchangeSimApplication::updateOrder(const Order &order, char status) {
FIX::TargetSubID(order.sender_sub_id());
FIX42::ExecutionReport fixOrder;
- fixOrder.set(FIX::OrderID("12345678901234567"));
+ fixOrder.set(exchange_key(order.clordid()));
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
fixOrder.set(FIX::ExecType(status));
@@ -424,7 +433,7 @@ void ExchangeSimApplication::rejectOrder(
FIX::SenderCompID senderCompID(target.getValue());
FIX42::ExecutionReport fixOrder;
- fixOrder.set(FIX::OrderID("12345678901234567"));
+ fixOrder.set(exchange_key(clOrdID.getString()));
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
fixOrder.set(FIX::ExecType(FIX::ExecType_REJECTED));
@@ -499,7 +508,7 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
handle.update_direct(utils::TimeStamp::now(), bids_temp, asks_temp, me->md_sn++);
auto new_trades = matcher.get_new_trades();
- for (auto &t : new_trades)
+ for (auto &t : new_trades) {
handle.add_trade(
utils::TimeStamp::now(),
md::PriceSize_from_double(t.price.value() * price_factor,t.quantity.value()),
@@ -507,6 +516,29 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
t.bid_aggressor ? co2::AGGRESSOR_SIDE_BUY
: ( t.ask_aggressor ? co2::AGGRESSOR_SIDE_SELL
: co2::AGGRESSOR_SIDE_NONE) );
+ }
+
+ // publish mbo
+ auto mbo = me->mbo;
+ if (mbo) {
+ // get the list of trades
+ auto ob = matcher.get_order_book(nullptr);
+ auto snap = mbo->allocate_snapshot();
+ for (const auto& order : ob.order()) {
+ auto ek = exchange_key(order.clordid());
+ md::SnapshotOrder sno {
+ md::ExchangeOrderKey(std::atoll(ek.getString().c_str())),
+ md::IntPrice_from_double(order.price() * price_factor),
+ (int)order.open_quantity() };
+ if (order.side() == api::SIDE_BUY) {
+ snap->bids.push_back(sno);
+ }
+ else if (order.side() == api::SIDE_SELL) {
+ snap->asks.push_back(sno);
+ }
+ }
+ mbo->publish_snapshot(SecurityKey(it->second.key()), &snap);
+ }
}
}
diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h
index b283aebc2..78af82a89 100644
--- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h
+++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h
@@ -44,7 +44,7 @@ GCC_DIAG_OFF("-Wignored-qualifiers")
namespace bts {
namespace api {class Security;}
-namespace md {class MDConsumerHandle;}
+namespace md {class MDConsumerHandle; class MBOWriter;}
namespace ex_sim {
static const int precision = 9;
class Order;
@@ -56,7 +56,7 @@ class ExchangeSimApplication
public FIX::MessageCracker
{
public:
- ExchangeSimApplication(bts::api::Venue venue);
+ ExchangeSimApplication(bts::api::Venue venue, md::MBOWriter*);
~ExchangeSimApplication();
void merge_with_md_book();
diff --git a/src/server/sparkd/exchange_sim/book/OrderMatcher.cpp b/src/server/sparkd/exchange_sim/book/OrderMatcher.cpp
index 03681b315..13f165d26 100644
--- a/src/server/sparkd/exchange_sim/book/OrderMatcher.cpp
+++ b/src/server/sparkd/exchange_sim/book/OrderMatcher.cpp
@@ -83,13 +83,17 @@ void OrderMatcher::add_or_merge(Order const &o, std::vector *out) {
auto range = find_level(*side,o.price());
- for (auto it = range.first; it != range.second; it++)
- if (it->owner() == o.owner()) {
- auto no_const = const_cast(&(*it));
- no_const->set_open_quantity(it->open_quantity() + o.quantity());
+ // If the last order at this level is the same owner we can update it
+ if (range.first != range.second) {
+ auto last = range.second;
+ last--;
+ if (last->owner() == o.owner()) {
+ auto no_const = const_cast(&(*last));
+ no_const->set_open_quantity(last->open_quantity() + o.quantity());
match(out);
return;
}
+ }
add_new(o,out);
}
@@ -232,14 +236,14 @@ Book OrderMatcher::get_book() const {
return result;
}
-OrderBook OrderMatcher::get_order_book(std::string const&exclude_owner) const
+OrderBook OrderMatcher::get_order_book(const char* exclude_owner) const
{
OrderBook result;
for (auto &b : me->bids)
- if (b.owner() != exclude_owner)
+ if (exclude_owner == nullptr || b.owner() != exclude_owner)
*result.add_order() = b;
for (auto &a : me->asks)
- if (a.owner() != exclude_owner)
+ if (exclude_owner == nullptr || a.owner() != exclude_owner)
*result.add_order() = a;
return result;
}
diff --git a/src/server/sparkd/exchange_sim/book/OrderMatcher.h b/src/server/sparkd/exchange_sim/book/OrderMatcher.h
index 5c8a93d57..86a5a1b3c 100644
--- a/src/server/sparkd/exchange_sim/book/OrderMatcher.h
+++ b/src/server/sparkd/exchange_sim/book/OrderMatcher.h
@@ -30,7 +30,7 @@ class OrderMatcher {
Quantity by_quantity,
std::string const& order_owner);
Book get_book() const;
- OrderBook get_order_book(std::string const&exclude_owner) const;
+ OrderBook get_order_book(const char*) const;
Order const *get_order(std::string const &clorid);
diff --git a/src/server/sparkd/md/run_md.cpp b/src/server/sparkd/md/run_md.cpp
index cd87e102a..0b5b95989 100644
--- a/src/server/sparkd/md/run_md.cpp
+++ b/src/server/sparkd/md/run_md.cpp
@@ -152,8 +152,8 @@ void run_market_datapublishers(MBOWriter* mbo) {
}));
if (config::get().use_sim()) {
- threading::make_thread("ExchangeSimGLBX", []() { sim::start_exchange_sim(api::Venue::VENUE_SIM); }).detach();
- threading::make_thread("ExchangeSimICE", []() { sim::start_exchange_sim(api::Venue::VENUE_SIMICE); }).detach();
+ threading::make_thread("ExchangeSimGLBX", [mbo]() { sim::start_exchange_sim(api::Venue::VENUE_SIM, mbo); }).detach();
+ threading::make_thread("ExchangeSimICE", [mbo]() { sim::start_exchange_sim(api::Venue::VENUE_SIMICE, mbo); }).detach();
}
boot_sleep();
}
diff --git a/src/web/CMakeDeps.cmake b/src/web/CMakeDeps.cmake
index 40156daa9..21739132b 100644
--- a/src/web/CMakeDeps.cmake
+++ b/src/web/CMakeDeps.cmake
@@ -1 +1 @@
-set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs)
\ No newline at end of file
+set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/cssstyle/scripts/run_tests.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs)
\ No newline at end of file
diff --git a/testing/manual/algos/cover.txt b/testing/manual/algos/cover.txt
index 586089f24..c1d72e318 100644
--- a/testing/manual/algos/cover.txt
+++ b/testing/manual/algos/cover.txt
@@ -5,16 +5,16 @@ gets filled, it sends out a hedge order, "Hedge Ticks" away from the fill.
1. Bring up a ladder, lets say in SIN1 (does not matter which security)
-2. Create the ask sides of the market by entering 100 lot limit order at 15.50
+2. Create the ask sides of the market by entering 100 lot limit order at 15.500
(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.
+3. Enter a 10 lot Cover (Child=Limit, Hedge=Limit) buy at 15.450, 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.
+4. Move the Cover to 15.475 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.
+Make sure a hedge is sent 3 ticks away from the fill (the hedge badge should show an H on the right)
6. Now from the OB (or miniOB) change the Hedge Ticks for this order to 5
@@ -30,7 +30,7 @@ clearly gets marked as completed
11. Clean the slate (except for the market). Enter a 10 lot buy Limit order. Attach a Cover
to it (with the same parameters from 3). Make sure this cover (the one "created" by attaching)
behaves in the same correct way as the one that was launched in 3 - ie get some fills, make
-sure the hedges are fired correctly, make sure updated to Hedge Ticks reflect the
+sure the hedges are fired correctly, make sure updates to Hedge Ticks reflect the
next hedges etc.
12. Repeat 11 but instead attach to a partially filled Limit order. Make sure the Cover does not
diff --git a/testing/manual/orders/order_book.txt b/testing/manual/orders/order_book.txt
index b905f6334..0b724e132 100644
--- a/testing/manual/orders/order_book.txt
+++ b/testing/manual/orders/order_book.txt
@@ -34,5 +34,37 @@ Left click on a cancelled parent order of a parent-child order type
The top parent order should be placed with a Qty of (Qty - Filled Qty)
* Note, child orders will *NOT* be recreated with a Qty of (Qty - Filled Qty) at this time since their intermediate fill status is unknown to their parent.
+Order tree node collapsing testing
+----------------------------------
+- Create an algo using the algo studio consisting of IB -> IB, call it IB2.
+- Launch an instance of IB2 on a normal security away from the market so it does not execute immediately
+- In an order book form ensure that the setting "Show Full Algo Tree" is checked
+- Ensure further that there are no filters on the OB
+- You should see in the OB the full tree of the IB2 you launched, that is there should 3 nodes: IB2 -> IB -> Limit
+- Now unset the "Show Full Algo Tree" setting
+- You should now sett only IB2 -> Limit, that is the intermediate IB node has been hidden
+- Now repeat the test but launch IB2 on a synthetic security
+- Now if "Show Full Algo Tree" is checked you should see 4 levels: IB2 -> IB -> Spreader -> Limit
+- If you uncheck "Show Full Algo Tree" you should see 3 levels: IB2-> Spreader -> Limit
+
+Order tree filter slice/dice
+----------------------------
+- Create an algo using the algo studio consisting of Cover -> IB, call it CIB.
+- Launch an instance of CIB on a normal security away from the market so it does not execute immediately
+- In an order book form ensure that the setting "Show Full Algo Tree" is checked
+- Ensure further that there are no filters on the OB
+- Now force some fills so that you have a mix of completed and working orders
+- Now filter the OB to show only working orders. You should see the non working disappear
+- Now filter the OB to show only limit, working orders. You should see only the limit currently being worked by the IB and the hedge orders launched by cove
+
+Filter/Collapse interaction
+---------------------------
+- Now uncheck the "Show Full Algo Tree" setting and clear all filters
+- You should only see the top algo for CIB and the the hedges and currently working limit order
+- Now filter for order type = limit, you should only the hedges and the currently working limit
+- Now filter for order type = IB and you should see nothing
+
+
+
diff --git a/testing/manual/settings/GridSettings.txt b/testing/manual/settings/GridSettings.txt
index db8cb0072..3b3bab4d5 100644
--- a/testing/manual/settings/GridSettings.txt
+++ b/testing/manual/settings/GridSettings.txt
@@ -1,3 +1,5 @@
+Test Author: Unknown
+If it breaks: John
----Grid Settings Test (11 minutes) ---------
1) Open the Orderbook
diff --git a/testing/manual/settings/SoundAndNotificationsTest.txt b/testing/manual/settings/SoundAndNotificationsTest.txt
index 27a3bcf9e..5690657f3 100644
--- a/testing/manual/settings/SoundAndNotificationsTest.txt
+++ b/testing/manual/settings/SoundAndNotificationsTest.txt
@@ -1,3 +1,6 @@
+Test Author: Unknown
+If it breaks: John
+
Sound and Notifications Test (15 min)-------------------------------------------
----Terminology-----------------------------------------------------------------
@@ -23,7 +26,7 @@ SoundNotifications {
- *add a sound trigger.
1) Sound Preview:
- First: check "Play Sound" (if it is not already checked)
+ First: click "Play Sound"
2) Duplicate sound triggers do not cause crash:
- *delete the sound trigger you added in the previous step.
@@ -36,7 +39,6 @@ SoundNotifications {
Prepare: open a ladder for a security that has steady market data activity (in the following steps you will be asked to enter trades, get filled, etc.)
3) "Any Order" filled sounds:
- First: "Play Sound" should still be checked, "Show Notifications" should NOT be checked
- select "When order filled" and "(any order)," then click apply.
- enter a 1 lot limit order across the market to trigger an immediate fill.
- as soon as it is filled, you should hear the sound.