From dc169fc4fde57ecf4a862fc8d79716e133f1c2dc Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 3 May 2019 16:51:39 -0500 Subject: [PATCH] SPARK-2388 studio-template orders should use new CompositeOrderDefinition (not CustomOrderDefinition) --- .../Modules/Trading/OrderBook/OrderBookVM.cs | 20 ++++++++++++++++--- .../spark/Orders/OrderPropertiesEditorVM.cs | 19 +++++++++++++++--- src/client/spark/Orders/OrderUtils.cs | 4 ++++ src/client/spark/Orders/OrdersModel.cs | 2 +- src/lib/api/services/OrderService.proto | 6 ++++-- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs index 4384e6eee..536e8114e 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs @@ -249,12 +249,22 @@ namespace mbts.spark { var mod_algo_vm = attach_vm.algo_vm.algo_root; await Task.WhenAll(order_tups.Select(t => { var algo = t.order.Def.CustomDef.CloneToMutable(); + if (algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite) { + algo = algo.Composite.Definition; + } mod_algo_vm.assign_to(algo); + if (algo_template_key != 0) { + algo = new CustomOrderDefinition { + Composite = new CompositeOrderDefinition { + AlgoTemplateKey = algo_template_key, + Definition = algo + } + }; + } return _model.send_order( t.order.Def.with( attach_target_order_key: t.order.Key, - custom_def: algo, - algo_template_key: algo_template_key + custom_def: algo ), double.IsNaN(price) ? t.order.price() : price, size ?? t.order.quantity()); @@ -598,7 +608,11 @@ namespace mbts.spark { await Task.WhenAll(update_params.Select(t => _model.update_order(t.order, new_price: price, new_size: size, new_algo: t.new_algo))); (OrderRecordImmutable order, CustomOrderDefinitionImmutable? new_algo) update_params_factory(OrderBookRowVM row) { var mod_algo = row.order.Def.CustomDef.CloneToMutable(); - mod_algo_vm.assign_to(mod_algo); + if (mod_algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite) { + mod_algo_vm.assign_to(mod_algo.Composite.Definition); + } else { + mod_algo_vm.assign_to(mod_algo); + } var mod_algoi = new CustomOrderDefinitionImmutable(mod_algo); return (row.order, OrderDataHelper.EqualsHelpers.equals(row.order.Def.CustomDef, mod_algoi) ? (CustomOrderDefinitionImmutable?)null : mod_algoi); } diff --git a/src/client/spark/Orders/OrderPropertiesEditorVM.cs b/src/client/spark/Orders/OrderPropertiesEditorVM.cs index e85722b3c..e035ee6f8 100644 --- a/src/client/spark/Orders/OrderPropertiesEditorVM.cs +++ b/src/client/spark/Orders/OrderPropertiesEditorVM.cs @@ -386,9 +386,22 @@ namespace mbts.spark { if (_model.algo_model.templates_enabled()) { selected_algo_template.algo_root.assign_to(order.CustomDef); } else { - selected_algo_definition.algo_root.assign_to(order.CustomDef); - if (selected_algo_definition.key.mode == AlgoKey.Mode.Persisted) - order.AlgoTemplateKey = selected_algo_definition.key.persisted.id_uint; + var algo = new CustomOrderDefinition(); + selected_algo_definition.algo_root.assign_to(algo); + switch (selected_algo_definition.key.mode) { + case AlgoKey.Mode.Persisted: + order.CustomDef = new CustomOrderDefinition { + Composite = new CompositeOrderDefinition { + AlgoTemplateKey = selected_algo_definition.key.persisted.id_uint, + Definition = algo + } + }; + selected_algo_definition.algo_root.assign_to(order.CustomDef.Composite.Definition); + break; + default: + order.CustomDef = algo; + break; + } } return order; } diff --git a/src/client/spark/Orders/OrderUtils.cs b/src/client/spark/Orders/OrderUtils.cs index 607fae654..7e983c381 100644 --- a/src/client/spark/Orders/OrderUtils.cs +++ b/src/client/spark/Orders/OrderUtils.cs @@ -82,6 +82,10 @@ namespace mbts.spark { public static string dynamic_order_type_display_name(this OrderRecordImmutable order) => order.HasDef && order.Def.HasCustomDef && order.Def.CustomDef.HasDynamic ? order.Def.CustomDef.Dynamic.DynamicOrderType : string.Empty; + public static uint algo_template_key(this OrderRecordImmutable order) => + order.HasDef && order.Def.HasCustomDef && order.Def.CustomDef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite ? + order.Def.CustomDef.Composite.AlgoTemplateKey : 0u; + public static OrderSubType sub_type(this OrderRecordImmutable order) => order.HasDef ? order.Def.SubType : OrderSubType.None; diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs index bb71156eb..5fbf47dc8 100644 --- a/src/client/spark/Orders/OrdersModel.cs +++ b/src/client/spark/Orders/OrdersModel.cs @@ -95,7 +95,7 @@ namespace mbts.spark { algo_meta_join, t => t.order.Key, am => am.algo.key, - t => new AlgoKey(new bts.persist.algo.AlgoPersistedKey(t.order.Def.AlgoTemplateKey)), + t => new AlgoKey(new bts.persist.algo.AlgoPersistedKey(t.order.algo_template_key())), (os, okey, am, mkey) => new OrderSecurityAlgoMeta(os.order, os.sec, am.algo, am.meta), (os, okey, mkey) => new OrderSecurityAlgoMeta(os.order, os.sec, null, null), ot => ot.order.Key); diff --git a/src/lib/api/services/OrderService.proto b/src/lib/api/services/OrderService.proto index f57ced2ba..844192189 100644 --- a/src/lib/api/services/OrderService.proto +++ b/src/lib/api/services/OrderService.proto @@ -57,6 +57,9 @@ message OrdersSub {} message FillsSub {} message OrderDefinition { + // deleted fields (don't reuse!): + // - uint32 algo_template_key = 15; (originally deleted 05/03/2019) + // standard order elements uint32 security_key = 1; api.Side side = 2; @@ -64,7 +67,6 @@ message OrderDefinition { uint32 user_id = 13; string account = 6; uint32 account_id = 14; - uint32 algo_template_key = 15; TimeInForce time_in_force = 7; ManualOrderIndicator manual_order_indicator = 8; CTICode cti_code = 9; @@ -192,7 +194,7 @@ message PricerOrderDefinition { CustomOrderDefinition child = 3; } message CompositeOrderDefinition { - string name = 1; + uint32 algo_template_key = 1; CustomOrderDefinition definition = 2; } message DynamicOrderDefinition {