diff --git a/.vscode/launch.json b/.vscode/launch.json
index f3c362de0..17ef37c0b 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -281,5 +281,42 @@
"RedirectOutput"
]
},
+ {
+ "name": ".NET Core Remote Attach",
+ "type": "coreclr",
+ "request": "attach",
+ "processId": "${command:pickRemoteProcess}",
+ "pipeTransport": {
+ "pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
+ "pipeArgs": ["bts@sparkvm"],
+ "debuggerPath": "/home/bts/vsdbg/vsdbg",
+ "pipeCwd": "${workspaceRoot}",
+ "quoteArgs": true
+ },
+ "sourceFileMap": {
+ "/home/bts/spark/": "${workspaceRoot}"
+ },
+ "justMyCode": true
+ },
+ {
+ "name": ".NET Core Remote Launch",
+ "type": "coreclr",
+ "request": "launch",
+ "program": "/usr/bin/dotnet",
+ "args": ["sparkcmd.dll", "test", "test_join_create_and_takeout_market"],
+ "stopAtEntry": false,
+ "cwd": "/home/bts/spark/build/ninja_debug/server",
+ "pipeTransport": {
+ "pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
+ "pipeArgs": ["bts@sparkvm"],
+ "debuggerPath": "/home/bts/vsdbg/vsdbg",
+ "pipeCwd": "${workspaceRoot}",
+ "quoteArgs": true
+ },
+ "sourceFileMap": {
+ "/home/bts/spark/": "${workspaceRoot}"
+ },
+ "justMyCode": false
+ },
]
}
\ No newline at end of file
diff --git a/doc/user/CMakeDeps.cmake b/doc/user/CMakeDeps.cmake
index 5f3811807..1b1ac7fc0 100644
--- a/doc/user/CMakeDeps.cmake
+++ b/doc/user/CMakeDeps.cmake
@@ -1 +1 @@
-set(sources /home/ppinto/Dropbox/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Help/index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Launcher/index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Logging-In-to-the-System/index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/index.md;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/My-Windows/index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Settings/index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Spreader/index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/index.md;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/bts_spark_sdk/Client/Overview.md;content/bts_spark_sdk/Client/Threading.md;content/bts_spark_sdk/Client/_index.md;content/bts_spark_sdk/Server/_index.md;content/bts_spark_sdk/_index.md;content/release_notes/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
\ No newline at end of file
+set(sources /home/ppinto/Dropbox/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Algos/_index.md;content/bts_spark/Glossary/index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Help/index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Launcher/index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Logging-In-to-the-System/index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/index.md;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/My-Windows/index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Settings/index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Spreader/index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/index.md;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
\ No newline at end of file
diff --git a/doc/user/build.sh b/doc/user/build.sh
index 663e6aa53..80e6dd052 100644
--- a/doc/user/build.sh
+++ b/doc/user/build.sh
@@ -8,7 +8,6 @@ zola_path=$(readlink -f "../../externals/linux/bin/zola/zola")
mkdir -p $temp_path
cp -r ./* $temp_path
-
cd $temp_path
$zola_path build -u '/docs/' -o $1 >$tmpfile 2>&1
diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md
index f37e8d038..f7fb3889d 100644
--- a/doc/user/content/release_notes/_index.md
+++ b/doc/user/content/release_notes/_index.md
@@ -4,6 +4,29 @@ weight = 3
sort_by = "weight"
insert_anchor_links = "right"
+++
+## 2.0.0
+### User Visible Changes
+ - Support for attaching and detaching algos to existing orders
+ - Support for display and update of all parameters in running algos
+ - Streamlining of order badge decorations in ladder
+ - New order search/filtering algorithm for order book
+ - Simpler representation of complex algo chains in order book and mini order book
+ - Visual and usability improvements to mini order book
+ - Streamlining of algo parameter dialog in ladder
+ - New spreader queue holder behavior
+ - Visual improvements to the order book
+ - New server side API
+ - Improved admin UI performance
+ - Optimized PIQ rendering
+### Internal changes
+ - Exchange simulator no longer requires daily sequence number reset
+ - Improved MD resilience to corrupted shared memory
+ - Native orders can now buffer updates/cancels when disconnected or pending first acknowledgment
+ - Improved settings manager tool output
+ - Added diagnostics in the event MD memory corruption is detected
+ - Added systems tests for join,lean, iceberg and spreader orders
+ - Made exchange order recovery more resilient in the presence of database loss
+
## 1.6.2
### User Visible Changes
### Exchange simulator
diff --git a/src/client/spark/Images/Icons.cs b/src/client/spark/Images/Icons.cs
index 5ac03d359..1d730b6ee 100644
--- a/src/client/spark/Images/Icons.cs
+++ b/src/client/spark/Images/Icons.cs
@@ -22,7 +22,9 @@ namespace mbts.ui {
AddBoxesGeometryKey = nameof(AddBoxesGeometryKey),
AddFileGeometryKey = nameof(AddFileGeometryKey),
AddFileThinGeometryKey = nameof(AddFileThinGeometryKey),
+ AttachAlgosKey = nameof(AttachAlgosKey),
CheckMarkGeometryKey = nameof(CheckMarkGeometryKey),
+ DetachAlgosKey = nameof(DetachAlgosKey),
DiskGeometryKey = nameof(DiskGeometryKey),
DiskFileGeometryKey = nameof(DiskFileGeometryKey),
DocumentGeometryKey = nameof(DocumentGeometryKey),
@@ -35,10 +37,14 @@ namespace mbts.ui {
EditDocumentAltGeometryKey = nameof(EditDocumentAltGeometryKey),
EditDocumentGeometryKey = nameof(EditDocumentGeometryKey),
GearGeometryKey = nameof(GearGeometryKey),
+ LetterAKey = nameof(LetterAKey),
+ LetterDKey = nameof(LetterDKey),
OrdersGeometryKey = nameof(OrdersGeometryKey),
PaymentGeometryKey = nameof(PaymentGeometryKey),
PencilGeometryKey = nameof(PencilGeometryKey),
PlayGeometryKey = nameof(PlayGeometryKey),
+ ProhibitedGeometryKey = nameof(ProhibitedGeometryKey),
+ RubberStampGeometryKey = nameof(RubberStampGeometryKey),
StarGeometryKey = nameof(StarGeometryKey),
ToolsGeometryKey = nameof(ToolsGeometryKey),
TrashGeometryKey = nameof(TrashGeometryKey),
@@ -115,6 +121,7 @@ namespace mbts.ui {
public static ImageSource AddBoxes => create_icon(AddBoxesGeometryKey);
public static ImageSource AddEncircled { get { return load_resource_and_freeze("AddEncircled"); } }
public static ImageSource AddFile => create_icon(Smashicons.AddFileGeometryKey);
+ public static ImageSource AttachAlgos => create_icon(AttachAlgosKey);
public static ImageSource Beaker { get { return load_resource_and_freeze("Beaker"); } }
public static ImageSource Book { get { return load_resource_and_freeze("Book"); } }
@@ -139,6 +146,7 @@ namespace mbts.ui {
public static ImageSource CheckMark => create_icon(CheckMarkGeometryKey);
public static ImageSource Clock { get { return load_resource_and_freeze("Clock"); } }
public static ImageSource Defrag { get { return load_resource_and_freeze("Defrag"); } }
+ public static ImageSource DetachAlgos => create_icon_and_rotate(DetachAlgosKey, Brushes.Red);
public static ImageSource Disk => create_icon(DiskGeometryKey);
public static ImageSource DiskFile => create_icon(DiskFileGeometryKey);
public static ImageSource Display { get { return load_resource_and_freeze("Display"); } }
@@ -158,6 +166,8 @@ namespace mbts.ui {
public static ImageSource Knight { get { return load_resource_and_freeze("Knight"); } }
public static ImageSource Payment => create_icon(PaymentGeometryKey);
public static ImageSource Pencil => create_icon(PencilGeometryKey);
+ public static ImageSource Prohibited => create_icon(ProhibitedGeometryKey);
+ public static ImageSource RubberStamp => create_icon(RubberStampGeometryKey);
public static ImageSource RedoCircular => create_icon(UndoCircularGeometryKey, Brushes.Black, null, new ScaleTransform(-1, 1));
public static ImageSource Spawn { get { return load_resource_and_freeze("Spawn"); } }
public static ImageSource Star => create_icon(StarGeometryKey);
@@ -186,6 +196,19 @@ namespace mbts.ui {
return rv;
}
+ public static ImageSource create_icon_and_rotate(string geometric_path_key, Brush brush = null, Pen pen = null, Transform transform = null, double degrees = 90) {
+ if (brush == null) {
+ brush = Brushes.Black;
+ }
+ var drawing = create_drawing(geometric_path_key, brush, pen, transform);
+ var dg = new DrawingGroup();
+ dg.Children.Add(drawing);
+ dg.Transform = new RotateTransform(degrees);
+ var rv = new DrawingImage(dg);
+ rv.Freeze();
+ return rv;
+ }
+
public static Drawing create_drawing(string geometric_path_key) =>
create_drawing(geometric_path_key, Brushes.Black);
diff --git a/src/client/spark/Images/Vector/Icons.xaml b/src/client/spark/Images/Vector/Icons.xaml
index 9cba2864c..115c988c4 100644
--- a/src/client/spark/Images/Vector/Icons.xaml
+++ b/src/client/spark/Images/Vector/Icons.xaml
@@ -5,6 +5,14 @@
xmlns:mbts="clr-namespace:mbts.ui"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
+
+
+ M10.519881,14.945064C11.300896,14.955074,12.079896,15.102078,12.819896,15.386075L10.878893,17.326085C9.6458764,17.201085,8.3688531,17.591071,7.4258485,18.533091L3.5977991,22.360102C1.9327704,24.026093 1.9317786,26.736124 3.5977991,28.402117 5.2638197,30.068108 7.9748359,30.068108 9.6398644,28.402117L13.467914,24.575106C14.410919,23.632109,14.800938,22.355097,14.675937,21.121083L16.615963,19.180096C17.523962,21.546103,17.034943,24.325104,15.126931,26.234108L11.298882,30.061119C8.7138591,32.64612 4.5238051,32.64612 1.9387672,30.062127 -0.64625573,27.477126 -0.64625573,23.287106 1.9387672,20.701098L5.7668166,16.875065C7.077837,15.564055,8.8018727,14.923061,10.519881,14.945064z M19.825993,10.418039L21.580012,12.17305 12.089907,21.665091 10.333873,19.911087z M25.383069,0C27.077088,3.0538786E-08 28.771109,0.64599859 30.063117,1.9390028 32.647133,4.5230274 32.647133,8.7120385 30.062109,11.298047L26.235068,15.125058C24.327055,17.033085,21.547022,17.52207,19.181973,16.614077L21.121998,14.674067C22.356022,14.799068,23.633046,14.409051,24.57605,13.466054L28.403094,9.6400513C30.068121,7.9740295 30.069129,5.2630205 28.403094,3.5980362 26.738064,1.9320143 24.027033,1.9320143 22.362034,3.5980362L18.533986,7.4240398C17.591958,8.3670363,17.201968,9.643042,17.32697,10.877056L15.385937,12.817066C14.478913,10.452035,14.968939,7.6730337,16.875945,5.7660436L20.703019,1.9390028C21.995026,0.64599859,23.689047,3.0538786E-08,25.383069,0z
+
+
+ M19.522852,25.255011L20.920847,25.256994 20.920847,29.729012 19.522852,29.729012z M22.826874,21.952002L25.989905,25.113989 25.001887,26.101996 21.838856,22.941015z M25.269894,19.506992L29.742937,19.509007 29.742937,20.906012 25.269894,20.907995z M10.519729,14.945011C11.300744,14.954991,12.079745,15.103001,12.818766,15.386997L10.878742,17.327C9.6457264,17.200016,8.368704,17.592014,7.4257004,18.532993L3.597655,22.359015C1.9326275,24.025 1.9316508,26.734991 3.597655,28.40299 5.2636887,30.068001 7.9747178,30.066017 9.6397144,28.40299L13.468767,24.575018C14.410794,23.633001,14.800783,22.355993,14.674774,21.122015L16.615807,19.181004C17.523806,21.547003,17.034817,24.325995,15.126776,26.233008L11.298761,30.061012C8.713709,32.644997 4.5236599,32.644997 1.9396465,30.061012 -0.64638097,27.475012 -0.64638097,23.286017 1.9386395,20.702002L5.7666852,16.875004C7.0777046,15.562992,8.8017227,14.922001,10.519729,14.945011z M2.1536381,10.959994L6.6257035,10.959994 6.6266801,12.359988 2.1536381,12.359988z M6.7686803,5.894014L9.9307338,9.0549947 8.9427158,10.044008 5.7806932,6.8819901z M10.976735,2.1390082L12.374761,2.1390082 12.375768,6.6130081 10.975728,6.6130081z M25.382902,0C27.076922,-1.8170738E-08 28.770941,0.6470033 30.063955,1.9389956 32.646992,4.5220043 32.646992,8.7130147 30.061941,11.297L26.234902,15.126011C24.326891,17.032993,21.546862,17.521,19.181845,16.614994L21.121868,14.674015C22.35586,14.798008,23.63389,14.407992,24.575886,13.467013L28.403933,9.6390096C30.067953,7.972994 30.069967,5.2619945 28.403933,3.5960094 26.738905,1.9310002 24.0269,1.9320073 22.361872,3.5960094L18.533827,7.4249893C17.591829,8.3659993,17.201811,9.6440145,17.32782,10.87601L15.385781,12.817996C14.477781,10.453005,14.968784,7.6730062,16.875818,5.7659928L20.702858,1.9379885C21.994864,0.64599622,23.688883,-1.8170738E-08,25.382902,0z
+
+
+
+ M32.759,0C14.696,0,0,14.695,0,32.759s14.695,32.759,32.759,32.759s32.759-14.695,32.759-32.759S50.822,0,32.759,0z
+ M6,32.759C6,18.004,18.004,6,32.759,6c6.648,0,12.734,2.443,17.419,6.472L12.472,50.178C8.443,45.493,6,39.407,6,32.759z
+ M32.759,59.518c-5.948,0-11.447-1.953-15.895-5.248l37.405-37.405c3.295,4.448,5.248,9.947,5.248,15.895
+ C59.518,47.514,47.514,59.518,32.759,59.518z
+
+
4
@@ -559,85 +557,27 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ />
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml.cs b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml.cs
index 2cfd8b971..95214f635 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml.cs
@@ -1,8 +1,6 @@
using mbts.spark;
using mbts.ui.converters;
-using mbts.ui.extensions;
using System;
-using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
@@ -18,26 +16,11 @@ namespace mbts.ui.spark {
public AlgoStudioView() {
InitializeComponent();
DataContextChanged += (s, e) => set_controller();
- content_host.PreviewMouseMove += content_host_PreviewMouseMove;
- content_host.MouseEnter += content_host_MouseEnter;
- content_host.MouseLeave += content_host_MouseLeave;
set_controller();
// local methods
void set_controller() => Disposable.replace(ref _controller, AlgoStudioViewControllerFactory.create(DataContext, _tree_view, name_text_box, custom_badge_color_picker_button, custom_badge_color_picker_popup));
- void content_host_PreviewMouseMove(object sender, MouseEventArgs e) => refresh_is_mouse_over_content_host(e);
- void content_host_MouseEnter(object sender, MouseEventArgs e) => refresh_is_mouse_over_content_host(e);
- void content_host_MouseLeave(object sender, MouseEventArgs e) => refresh_is_mouse_over_content_host(e);
- void refresh_is_mouse_over_content_host(MouseEventArgs e) => content_host.set_current_if_changed(IsMouseOverNodeContentProperty, this.ChildAtPoint(e.GetPosition(this)) == content_host);
}
- #region IsMouseOverNodeContent
- public static readonly DependencyProperty IsMouseOverNodeContentProperty =
- DependencyProperty.RegisterAttached("IsMouseOverNodeContent", typeof(bool), typeof(AlgoStudioView), new PropertyMetadata(false));
-
- public static bool GetIsMouseOverNodeContent(DependencyObject d) => (bool)d.GetValue(IsMouseOverNodeContentProperty);
- public static void SetIsMouseOverNodeContent(DependencyObject d, bool value) => d.SetValue(IsMouseOverNodeContentProperty, value);
- #endregion
-
public new AlgoStudioVM DataContext {
get => base.DataContext as AlgoStudioVM;
set => base.DataContext = value;
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs
index d3dd820fb..73ec53f5a 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs
@@ -13,7 +13,7 @@ using System.Windows;
using StartupData = bts.shell.AlgoStudioWindowFactory.StartupData;
namespace mbts.spark {
- internal class AlgoStudioWindow : SparkWindow, IShellWindow {
+ internal class AlgoStudioWindow : SparkWindow, ISharedWindow {
public const string
NAME = "Algo Studio",
TemplatesEnabledKey = nameof(TemplatesEnabledKey),
@@ -37,7 +37,7 @@ namespace mbts.spark {
: base(NAME, bus, factory, SparkCommands.ShowAlgoStudio.icon) {
_model = model;
_state = state;
- thread_init();
+ thread_id = config.Configuration.get().algo_studio ? "AlgoStudio" : null;
}
public override StartupData SaveState => _state = _vm.create();
@@ -45,12 +45,12 @@ namespace mbts.spark {
public override string window_type => NAME;
public override UIElement Content => _view;
public override IEnumerable Commands => _commands;
- public string thread_id => NAME;
public override double MinWidth =>
SPARK_MENU_COLLAPSED_WIDTH +
LAUNCHER_BUTTON_BORDER_WIDTH +
DEFAULT_CONTENT_WIDTH;
public override double MinHeight => DEFAULT_CONTENT_HEIGHT;
+ public string thread_id { get; }
bts.config.AlgoStudioOptions _ui_configuration => _model.algo_model.ui_configuration;
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoData.cs b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoData.cs
index 58f92670c..3acd47fcc 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoData.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoData.cs
@@ -2,6 +2,7 @@
using bts.utils;
using mbts.spark.utilities;
using System;
+using System.Windows.Media;
namespace mbts.spark {
struct AlgoData : IEquatable {
@@ -36,4 +37,31 @@ namespace mbts.spark {
public static bool operator ==(AlgoData a, AlgoData b) => a.Equals(b);
public static bool operator !=(AlgoData a, AlgoData b) => !a.Equals(b);
}
+
+ struct AlgoDataVM : IEquatable {
+ public readonly AlgoData data;
+ public readonly AlgoDefinitionMetadata? meta;
+
+ public AlgoDataVM(AlgoData data, AlgoDefinitionMetadata? meta = null) {
+ this.data = data;
+ this.meta = meta;
+ }
+
+ public string name => data.name;
+ public Brush badge_fill => OrderUtils.badge_fill(meta, OrderDataHelper.get_metadata(data.value.CustomCase));
+ public AlgoDisplayGroup group => data.key.display_group();
+
+ public override string ToString() =>
+ data.name;
+
+ public static AlgoDataVM from_data(AlgoData data, AlgoDefinitionMetadata? meta) =>
+ new AlgoDataVM(data, meta);
+
+ public static AlgoDataVM from_data((AlgoData algo, AlgoDefinitionMetadata? meta) tup) =>
+ new AlgoDataVM(tup.algo, tup.meta);
+
+ public bool Equals(AlgoDataVM other) => data == other.data && meta == other.meta;
+ public override bool Equals(object obj) => obj is AlgoDataVM other && Equals(other);
+ public override int GetHashCode() => EqualityComparer.aggregate_hash(data.GetHashCode(), meta.GetHashCode());
+ }
}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoKey.cs b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoKey.cs
index fc236e6a4..98c414a46 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoKey.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoKey.cs
@@ -1,9 +1,76 @@
using bts.api.orderman;
using bts.persist.algo;
using bts.utils;
+using ProtoBuf;
using System;
namespace mbts.spark {
+ [ProtoContract]
+ struct AlgoID : IEquatable {
+ [ProtoMember(1)]
+ readonly CustomOrderDefinition.CustomOneofCase? _factory_key;
+ [ProtoMember(2)]
+ readonly string _dynamic_key;
+ [ProtoMember(3)]
+ readonly uint? _persisted_key;
+
+ public AlgoID(CustomOrderDefinition.CustomOneofCase factory_key) {
+ _factory_key = factory_key;
+ _dynamic_key = null;
+ _persisted_key = null;
+ }
+
+ public AlgoID(string dynamic_key) {
+ _factory_key = null;
+ _dynamic_key = dynamic_key;
+ _persisted_key = null;
+ }
+
+ public AlgoID(uint persisted_key) {
+ _factory_key = null;
+ _dynamic_key = null;
+ _persisted_key = persisted_key;
+ }
+
+ public static AlgoID from_order_def(OrderDefinitionImmutable order_def) {
+ switch (order_def.CustomDef.CustomCase) {
+ case CustomOrderDefinition.CustomOneofCase.Composite: return new AlgoID(order_def.CustomDef.Composite.AlgoTemplateKey);
+ case CustomOrderDefinition.CustomOneofCase.Dynamic: return new AlgoID(order_def.CustomDef.Dynamic.DynamicOrderType);
+ default: return new AlgoID(order_def.CustomDef.CustomCase);
+ }
+ }
+
+ public static AlgoID from_algo_key(AlgoKey key) {
+ switch (key.mode) {
+ case AlgoKey.Mode.Factory:
+ if (key.factory.structure.structure.Count > 0)
+ return new AlgoID((CustomOrderDefinition.CustomOneofCase)key.factory.structure.structure[0]);
+ break;
+ case AlgoKey.Mode.Persisted:
+ return new AlgoID(key.persisted.id_uint);
+ }
+ return new AlgoID(CustomOrderDefinition.CustomOneofCase.None);
+ }
+
+ public bool Equals(AlgoID other) =>
+ _factory_key == other._factory_key &&
+ _dynamic_key == other._dynamic_key &&
+ _persisted_key == other._persisted_key;
+
+ public override bool Equals(object obj) =>
+ obj is AlgoID && Equals(obj);
+
+ public override int GetHashCode() =>
+ EqualityComparer.aggregate_hash(
+ _factory_key?.GetHashCode() ?? 0,
+ _dynamic_key?.GetHashCode() ?? 0,
+ _persisted_key?.GetHashCode() ?? 0);
+
+ public static bool operator ==(AlgoID a, AlgoID b) => a.Equals(b);
+ public static bool operator !=(AlgoID a, AlgoID b) => !a.Equals(b);
+ }
+
+ /// TODO: Remove , and redirect references to .
struct AlgoKey : IEquatable {
readonly AlgoPersistedKey? _persisted_key;
readonly AlgoNameStructureKey? _factory_key;
@@ -83,4 +150,4 @@ namespace mbts.spark {
InvalidOperationException _unexpected_mode_ex() => new InvalidOperationException($"Unexpected Mode '{mode}.'");
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoStructureKey.cs b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoStructureKey.cs
index fb2c0666e..95c1c9110 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoStructureKey.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/Model/AlgoStructureKey.cs
@@ -1,8 +1,9 @@
using bts.api.orderman;
using bts.utils;
using mbts.spark.utilities;
-using ProtoBuf;
+using mbts.ui.utility;
using System;
+using System.Collections.Generic;
using System.Linq;
namespace mbts.spark {
@@ -10,12 +11,6 @@ namespace mbts.spark {
public readonly string name;
public readonly AlgoStructureKey structure;
- public AlgoNameStructureKey(CustomOrderDefinitionImmutable definition)
- : this(definition.CustomCase.type_id(), definition) { }
-
- public AlgoNameStructureKey(string name, CustomOrderDefinitionImmutable definition)
- : this(name, new AlgoStructureKey(definition)) { }
-
public AlgoNameStructureKey(CustomOrderDefinition.CustomOneofCase base_type)
: this(base_type.type_id(), new AlgoStructureKey(base_type)) { }
@@ -31,71 +26,139 @@ namespace mbts.spark {
public static bool operator !=(AlgoNameStructureKey a, AlgoNameStructureKey b) => !a.Equals(b);
}
- [ProtoContract]
struct AlgoStructureKey : IEquatable {
- [ProtoMember(1)]
readonly int[] _structure;
public AlgoStructureKey(CustomOrderDefinition.CustomOneofCase base_type)
: this(new[] { (int)base_type }) { }
- public AlgoStructureKey(CustomOrderDefinitionImmutable definition) {
- int[] s = new[] { (int)definition.CustomCase };
- _build_structure(definition, ref s, 1);
- _structure = s;
- }
+ public AlgoStructureKey(CustomOrderDefinitionImmutable definition, IMaskIndexInt32 dynamic_type_index) =>
+ _structure = AlgoStructureSerializer.to_array(definition, dynamic_type_index);
public AlgoStructureKey(int[] structure) =>
_structure = structure;
- public CustomOrderDefinitionImmutable build_def() {
- int pos = 0;
- var mdef = new CustomOrderDefinition();
- _build_def(_structure, ref pos, ref mdef);
- return new CustomOrderDefinitionImmutable(mdef);
- }
+ public IReadOnlyList structure => _structure ?? Array.Empty();
- public bool Equals(AlgoStructureKey other) =>
- _structure.Length == other._structure.Length &&
- _structure.SequenceEqual(other._structure);
+ public bool Equals(AlgoStructureKey other) {
+ if (_structure == null) {
+ return other._structure == null;
+ } else {
+ /// is not optimized to check Count/Length, since the args are .
+ return other._structure != null && _structure.Length == other._structure.Length && _structure.SequenceEqual(other._structure);
+ }
+ }
public override bool Equals(object obj) =>
obj is AlgoStructureKey other && Equals(other);
public override int GetHashCode() =>
- EqualityComparer.aggregate_hash(_structure);
+ _structure == null ? 0 : EqualityComparer.aggregate_hash(_structure);
public static bool operator ==(AlgoStructureKey a, AlgoStructureKey b) => a.Equals(b);
public static bool operator !=(AlgoStructureKey a, AlgoStructureKey b) => !a.Equals(b);
+ }
- static void _build_structure(CustomOrderDefinitionImmutable definition, ref int[] structure, int pos) =>
- _build_structure(definition.CloneToMutable(), ref structure, pos);
+ static class AlgoStructureSerializer {
+ const int
+ _dynamic_mask = 1 << 31,
+ _child_mask_offset = 30;
- static void _build_structure(CustomOrderDefinition algo, ref int[] structure, int pos) {
- var cad = OrderDataHelper.get_child_algo_data(algo);
- for (int di = 0; di < cad.Count; di++) {
- if (cad[di].get_child(algo) is CustomOrderDefinition child_algo) {
- ArrayHelper.ensure_capacity(ref structure, pos + 1);
- int del_mask = 1 << (31 - di);
- structure[pos++] = (int)child_algo.CustomCase | del_mask;
- _build_structure(child_algo, ref structure, pos);
- break;
- }
- }
- ArrayHelper.trim(ref structure, pos);
+ public static CustomOrderDefinitionImmutable build_algoi(this AlgoStructureKey structure_key, DynamicOrderHelper dynamic_helper) =>
+ parsei(structure_key.structure, dynamic_helper);
+
+ public static CustomOrderDefinitionImmutable build_algo(this AlgoStructureKey structure_key, DynamicOrderHelper dynamic_helper) =>
+ parsei(structure_key.structure, dynamic_helper);
+
+ public static CustomOrderDefinition.CustomOneofCase order_type(this AlgoStructureKey structure_key) =>
+ structure_key.structure.Count > 0 ? (CustomOrderDefinition.CustomOneofCase)structure_key.structure[0] : CustomOrderDefinition.CustomOneofCase.None;
+
+ public static AlgoStructureKey structure_key(CustomOrderDefinitionImmutable algo, IMaskIndexInt32 dynamic_type_index) =>
+ new AlgoStructureKey(to_array(algo, dynamic_type_index));
+
+ public static AlgoStructureKey structure_key(CustomOrderDefinition algo, IMaskIndexInt32 dynamic_type_index) =>
+ new AlgoStructureKey(to_array(algo, dynamic_type_index));
+
+ public static int[] to_array(CustomOrderDefinitionImmutable algo, IMaskIndexInt32 dynamic_type_index) =>
+ to_array(algo.CloneToMutable(), dynamic_type_index);
+
+ public static int[] to_array(CustomOrderDefinition algo, IMaskIndexInt32 dynamic_type_index) {
+ int[] s = new[] { (int)algo.CustomCase };
+ _build_structure(algo, ref s, dynamic_type_index);
+ return s;
}
- static void _build_def(int[] structure, ref int pos, ref CustomOrderDefinition algo) {
- for (int i = pos; i < structure.Length; i++) {
+ public static CustomOrderDefinitionImmutable from_array(int[] structure, DynamicOrderHelper dynamic_helper) =>
+ parsei(structure, dynamic_helper);
+
+ public static CustomOrderDefinitionImmutable parsei(IReadOnlyList structure, DynamicOrderHelper dynamic_helper) =>
+ new CustomOrderDefinitionImmutable(parse(structure, dynamic_helper));
+
+ public static CustomOrderDefinition parse(IReadOnlyList structure, DynamicOrderHelper dynamic_helper) {
+ if (structure == null || structure.Count == 0)
+ return new CustomOrderDefinition();
+ int pos = 1;
+ var mdef = OrderDataHelper.create_algo((CustomOrderDefinition.CustomOneofCase)structure[0]);
+ _build_def(structure, ref pos, ref mdef, dynamic_helper);
+ return mdef;
+ }
+
+ static void _build_structure(CustomOrderDefinition algo, ref int[] structure, IMaskIndexInt32 dynamic_type_index) {
+ if (structure == null || structure.Length == 0)
+ structure = new int[1];
+ structure[0] = (int)algo.CustomCase;
+ int p = 1;
+ _build_structure(algo, ref structure, ref p, dynamic_type_index);
+ ArrayHelper.trim(ref structure, p);
+ }
+
+ static void _build_structure(CustomOrderDefinition algo, ref int[] structure, ref int pos, IMaskIndexInt32 dynamic_type_index) {
+ IEnumerable<(CustomOrderDefinition child_algo, int field_pos)> children;
+ if (algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
+ ArrayHelper.ensure_capacity(ref structure, pos + 1);
+ structure[pos++] = dynamic_type_index.to_int(algo.Dynamic.DynamicOrderType) | _dynamic_mask;
+ children = algo.Dynamic.OrderParams.Where(kv => kv.Value.ValueCase == DynamicOrderParam.ValueOneofCase.AsOrderDef).Select((kv, i) => (kv.Value.AsOrderDef, i));
+ } else {
var cad = OrderDataHelper.get_child_algo_data(algo);
- for (int di = 0; di < cad.Count; di++) {
- int mask = 1 << (31 - di);
- if ((structure[i] & mask) == mask) {
- var type = (CustomOrderDefinition.CustomOneofCase)(structure[i] ^ mask);
- var child_algo = OrderDataHelper.Defaults.CustomOrderDefinition(type);
- pos++;
- _build_def(structure, ref pos, ref child_algo);
- cad[di].assign_child(algo, child_algo);
+ children = cad.Select((c, i) => (c.get_child(algo), i));
+ children = children.Where(c => c.child_algo != null);
+ }
+ foreach ((var child, int field_pos) in children) {
+ ArrayHelper.ensure_capacity(ref structure, pos + 1);
+ structure[pos++] = EnumMaskIndexInt32.to_int(child.CustomCase) | _child_algo_mask(field_pos);
+ _build_structure(child, ref structure, ref pos, dynamic_type_index);
+ }
+ }
+
+ ///
+ /// Gets a mask for a particular child-algo field of a particular algo definition.
+ ///
+ /// The index wrt the deterministic enumeration of child algos for a particular definition (e.g., Hedge = 0, Child = 1).
+ static int _child_algo_mask(int field_pos) => 1 << (_child_mask_offset - field_pos);
+
+ static void _build_def(IReadOnlyList structure, ref int pos, ref CustomOrderDefinition algo, DynamicOrderHelper dynamic_helper) {
+ var local_algo = algo;
+ IEnumerable<(Action assign_child, int field_pos)> children;
+ if (algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
+ var dyn_def = algo.Dynamic;
+ dyn_def.DynamicOrderType = dynamic_helper.dynamic_type_index.from_int(structure[pos++] ^ _dynamic_mask);
+ dynamic_helper.add_dynamic_params(ref dyn_def);
+ children = dyn_def.OrderParams
+ .Where(kv => kv.Value.ValueCase == DynamicOrderParam.ValueOneofCase.AsOrderDef)
+ .Select((kv, i) => (new Action(child_algo => kv.Value.AsOrderDef = child_algo), i));
+ } else {
+ children = OrderDataHelper.get_child_algo_data(algo)
+ .Select((c, i) => (new Action(child_algo => c.assign_child(local_algo, child_algo)), i));
+ }
+ using (var children_en = children.GetEnumerator()) {
+ while (pos < structure.Count && children_en.MoveNext()) {
+ (var assign_child, int field_pos) = children_en.Current;
+ int mask = _child_algo_mask(field_pos);
+ if ((structure[pos] & mask) == mask) {
+ var type = EnumMaskIndexInt32.from_int(structure[pos++] ^ mask);
+ var child_algo = OrderDataHelper.create_algo(type);
+ _build_def(structure, ref pos, ref child_algo, dynamic_helper);
+ assign_child(child_algo);
}
}
}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Model/Metadata/AlgoDefinitionMetadata.cs b/src/client/spark/Modules/Trading/AlgoStudio/Model/Metadata/AlgoDefinitionMetadata.cs
index 940b0aa92..aa536d1bf 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/Model/Metadata/AlgoDefinitionMetadata.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/Model/Metadata/AlgoDefinitionMetadata.cs
@@ -70,7 +70,7 @@ namespace mbts.spark {
is_hidden.GetHashCode(),
abbreviation == null ? 0 : abbreviation.GetHashCode(),
badge_color?.GetHashCode() ?? 0,
- EqualityComparer.aggregate_hash_limited(_favorite_templates));
+ _favorite_templates == null ? 0 : EqualityComparer.aggregate_hash_limited(_favorite_templates));
public static bool operator ==(AlgoDefinitionMetadata a, AlgoDefinitionMetadata b) => a.Equals(b);
public static bool operator !=(AlgoDefinitionMetadata a, AlgoDefinitionMetadata b) => !a.Equals(b);
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Utils/AlgoCollectionHelper.cs b/src/client/spark/Modules/Trading/AlgoStudio/Utils/AlgoCollectionHelper.cs
index 27b9a9756..b66b82839 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/Utils/AlgoCollectionHelper.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/Utils/AlgoCollectionHelper.cs
@@ -1,24 +1,37 @@
using bts.api.core;
+using bts.api.orderman;
using bts.utils;
using mbts.collections;
using mbts.ui.utilities;
using mbts.utils;
using System;
using System.Collections.Generic;
+using System.Linq;
namespace mbts.spark {
static class AlgoCollectionHelper {
public static readonly IComparer algo_definition_vm_comparer =
new ComparerBuilder(
- new [] {
- Comparer.Create(_CompareUtils.compare_modes),
+ new[] {
+ Comparer.Create(_CompareUtils.compare_groups),
Comparer.Create(_CompareUtils.compare_names)
}).to_comparer().to_safe();
+ public static readonly IComparer algo_data_comparer =
+ new ComparerBuilder(
+ new[] {
+ Comparer.Create(_CompareUtils.compare_groups),
+ Comparer.Create(_CompareUtils.compare_names)
+ }
+ ).to_comparer();
+
+ public static readonly IComparer algo_data_vm_comparer =
+ algo_data_comparer.wrap(vm => vm.data);
+
public static readonly IComparer algo_vm_comparer =
new ComparerBuilder(
- new [] {
- Comparer.Create(_CompareUtils.compare_modes),
+ new[] {
+ Comparer.Create(_CompareUtils.compare_groups),
Comparer.Create(_CompareUtils.compare_names)
}).to_comparer().to_safe();
@@ -34,29 +47,75 @@ namespace mbts.spark {
}
}
- static class _CompareUtils {
- public static int compare_modes(AlgoDefinitionVM a, AlgoDefinitionVM b) =>
- _compare_modes(a.key.mode, b.key.mode);
+ public static void update_persisted_definition_wrappers(IDictionary target, TableUpdate update, Func factory) {
+ foreach (var d in update.removed)
+ target.Remove(d.key);
+ foreach (var d in update.changed) {
+ var vm = target[d.key];
+ if (vm is AlgoVMWrapper wrapper) {
+ wrapper.value.load(d);
+ } else vm.load_from(d.value);
+ }
+ foreach (var d in update.added) {
+ if (target.TryGetValue(d.key, out IAlgoVM def)) {
+ def.load_from(d.value);
+ } else target.Add(d.key, new AlgoVMWrapper(factory(d)));
+ }
+ }
- public static int compare_modes(IAlgoVM a, IAlgoVM b) =>
- _compare_modes(a.id.mode, b.id.mode);
+ public static void commit_all(this IEnumerable algo_param_rows) =>
+ algo_param_rows.Select(r => r.param).commit_all();
+
+ public static void commit_all(this IEnumerable algo_params) {
+ foreach (var p in algo_params)
+ p.mark_committed();
+ }
+
+ public static void revert_all(this IEnumerable algo_param_rows) =>
+ algo_param_rows.Select(r => r.param).revert_all();
+
+ public static void revert_all(this IEnumerable algo_params) {
+ foreach (var p in algo_params)
+ p.revert();
+ }
+
+ public static AlgoDisplayGroup display_group(CustomOrderDefinition.CustomOneofCase order_type) => order_type.is_bts_algo_type() ? AlgoDisplayGroup.BTS : AlgoDisplayGroup.Exchange;
+
+ public static AlgoDisplayGroup display_group(this AlgoKey key) {
+ switch (key.mode) {
+ case AlgoKey.Mode.Factory: return display_group(key.factory.structure.order_type());
+ case AlgoKey.Mode.Unpersisted:
+ case AlgoKey.Mode.Persisted:
+ return AlgoDisplayGroup.Studio;
+ }
+ return AlgoDisplayGroup.BTS;
+ }
+
+ static class _CompareUtils {
+ static AlgoDisplayGroup[] _sorted_groups = new[] {
+ AlgoDisplayGroup.Exchange,
+ AlgoDisplayGroup.BTS,
+ AlgoDisplayGroup.Studio,
+ AlgoDisplayGroup.API
+ };
+
+ public static int compare_groups(AlgoDefinitionVM a, AlgoDefinitionVM b) =>
+ Array.IndexOf(_sorted_groups, a.group).CompareTo(Array.IndexOf(_sorted_groups, b.group));
+
+ public static int compare_groups(AlgoData a, AlgoData b) =>
+ Array.IndexOf(_sorted_groups, a.key.display_group()).CompareTo(Array.IndexOf(_sorted_groups, b.key.display_group()));
+
+ public static int compare_groups(IAlgoVM a, IAlgoVM b) =>
+ Array.IndexOf(_sorted_groups, a.group).CompareTo(Array.IndexOf(_sorted_groups, b.group));
public static int compare_names(AlgoDefinitionVM a, AlgoDefinitionVM b) =>
DisplayNameHelper.compare_alpha_numeric(a.name, b.name);
+ public static int compare_names(AlgoData a, AlgoData b) =>
+ DisplayNameHelper.compare_alpha_numeric(a.name, b.name);
+
public static int compare_names(IAlgoVM a, IAlgoVM b) =>
DisplayNameHelper.compare_alpha_numeric(a.display_name, b.display_name);
-
- static int _compare_modes(AlgoKey.Mode a, AlgoKey.Mode b) {
- // Factory mode is 'lowest', consider all other modes equivalent.
- if (a == AlgoKey.Mode.Factory) {
- if (b != AlgoKey.Mode.Factory)
- return -1;
- } else if (b == AlgoKey.Mode.Factory) {
- return 1;
- }
- return 0;
- }
}
}
-}
\ No newline at end of file
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoDefinitionVM.cs b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoDefinitionVM.cs
index a21904a6b..7ec794043 100644
--- a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoDefinitionVM.cs
+++ b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoDefinitionVM.cs
@@ -1,10 +1,12 @@
using bts.api.core;
using bts.api.orderman;
+using bts.collections;
using bts.proto;
using bts.utils;
using mbts.collections;
using mbts.spark.utilities;
using mbts.ui;
+using mbts.ui.controls;
using mbts.ui.controls.color_picker;
using mbts.ui.shell;
using mbts.ui.utility;
@@ -25,7 +27,8 @@ namespace mbts.spark {
None = 0,
Exchange = 1,
Spreader = 1 << 1,
- DefaultPlaceholder = 1 << 2
+ Attachable = 1 << 2,
+ DefaultPlaceholder = 1 << 3
}
class AlgoDefinitionVM : DisposableViewModelBase, IAlgoStudioContentVM, IAlgoSelector, IEquatable {
@@ -46,7 +49,8 @@ namespace mbts.spark {
readonly DeferrableActionWrapper _refresh_on_local_changes;
readonly ReactiveThresholdMonitor _any_templates_dirty_monitor = new ReactiveThresholdMonitor(t => t.observe_is_dirty());
readonly Property _selected_format;
- AlgoEditingPermissions _editing_permissions;
+ readonly EnumMaskInt32 _permissions_mask = new EnumMaskInt32();
+
int? _favorite_index;
Brush _badge_fill;
Snapshot? _committed;
@@ -54,29 +58,43 @@ namespace mbts.spark {
TableUpdateBuffer _template_update_buffer;
bool _connected;
- public static AlgoDefinitionVM create(OrdersModel model, AlgoData data, bool connect = false, AlgoFormats init_format = AlgoFormats.Exchange) {
- var rv = new AlgoDefinitionVM(model, data, init_format);
+ public static AlgoDefinitionVM create(OrdersModel model, AlgoData data, bool connect = false, AlgoFormats init_format = AlgoFormats.Exchange, AlgoEditingPermissions editing_permissions = (AlgoEditingPermissions)int.MaxValue) {
+ var rv = new AlgoDefinitionVM(model, data, init_format, editing_permissions);
if (connect)
rv.connect();
return rv;
}
public static AlgoDefinitionVM create_placeholder(OrdersModel model, CustomOrderDefinitionImmutable def, string name, AlgoFormats init_format) =>
- new AlgoDefinitionVM(model, new AlgoData(def, name, new AlgoKey(Guid.NewGuid())), init_format);
+ new AlgoDefinitionVM(model, new AlgoData(def, name, new AlgoKey(Guid.NewGuid())), init_format, (AlgoEditingPermissions)int.MaxValue);
- AlgoDefinitionVM(OrdersModel model, AlgoData def_data, AlgoFormats init_format = AlgoFormats.Exchange) {
+ AlgoDefinitionVM(OrdersModel model, AlgoData def_data, AlgoFormats init_format, AlgoEditingPermissions init_permissions) {
// init core data
_model = model;
+ _permissions_mask.mask = init_permissions;
+ _permissions_mask.raw = init_permissions;
+ var resources = new CompositeDisposable();
+ if (!model.algo_model.ui_configuration.can_modify_definition_values)
+ editing_permissions_mask ^= (AlgoEditingPermissions.AllowEditValues | AlgoEditingPermissions.AllowSaveValues);
+ if (!model.algo_model.ui_configuration.can_modify_definition_structure)
+ editing_permissions_mask ^= (AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowSaveStructure);
+ else if (model.algo_model.templates_enabled()) {
+ resources.Add(_templates.Subscribe((s, e) => {
+ if (_templates.Count == 0) {
+ editing_permissions_mask |= AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowSaveStructure;
+ } else {
+ editing_permissions_mask ^= (AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowSaveStructure);
+ }
+ }));
+ }
key = def_data.key;
algos_view = ObservableAutoWrapper.create_sorted_wrapper(_algo_roots, AlgoCollectionHelper.algo_vm_comparer);
_template_update_buffer = new TableUpdateBuffer(t => t.key);
_templates_with_custom = new ObservableAppendCollection(templates);
templates_view = (ListCollectionView)CollectionViewSource.GetDefaultView(_templates_with_custom);
custom_badge_color_palettes.AddRange(ColorPalette.all_presets(model.factory).Select(p => new ColorPaletteVM(p)));
- _editing_permissions = _get_permissions();
_version = new VersionContainer(_snapshot);
var conf = _model.algo_model.ui_configuration;
- var resources = new CompositeDisposable();
// init backing props
_name = backing(nameof(name), def_data.name);
_abbreviation = backing(nameof(abbreviation), string.Empty);
@@ -87,7 +105,7 @@ namespace mbts.spark {
_is_selected = backing(nameof(is_selected), true);
_is_dirty = backing(nameof(is_dirty), () => key.mode == AlgoKey.Mode.Unpersisted || !_committed.HasValue || !_committed.Value.Equals(_version.value));
var factory_def_data = def_data.key.mode == AlgoKey.Mode.Factory ? def_data : new AlgoData(def_data.value);
- _algo_root = backing(nameof(algo_root), _algo_roots.GetOrAdd(factory_def_data.key, _ => OrderTypeVMFactory.create(factory_def_data, _editing_permissions)));
+ _algo_root = backing(nameof(algo_root), _algo_roots.GetOrAdd(factory_def_data.key, _ => OrderTypeVMFactory.create(factory_def_data)));
_visible_algo_root = backing(nameof(visible_algo_root));
_can_redo = backing(nameof(can_redo), () => _edit_stack.get_can_redo(_version.value));
_can_undo = backing(nameof(can_undo), () => _edit_stack.get_can_undo(_version.value));
@@ -113,28 +131,16 @@ namespace mbts.spark {
as_demuxer().subscribe_many(_refresh_on_local_changes.execute, nameof(this.name), nameof(abbreviation), nameof(badge_fill)),
_edit_pane_vs_model.add_source(VisualStateNames.BadgeSelector.GroupName, custom_badge_color.observe_nullable(true).Select(t => t.HasValue ? VisualStateNames.BadgeSelector.Active : VisualStateNames.BadgeSelector.Inactive)),
_edit_pane_vs_model.add_source(VisualStateNames.Abbreviation.GroupName, _abbreviation.observe_current(true).Select(a => string.IsNullOrEmpty(a) ? VisualStateNames.Abbreviation.Unpopulated : VisualStateNames.Abbreviation.Populated)),
- templates.ObserveSelf().Select(_ => _get_permissions()).DistinctUntilChanged().OnDispatcher().Subscribe(on_editing_permissions),
- _algo_root.observe_current(true).SubscribeHookLatest(vm => {
- if (vm == null)
- return Disposable.empty;
- if (vm is ILazyAlgo la) {
- bool synced_with_loaded = false;
- return vm.subscribe_definition().Subscribe(_ => {
- if (la.is_loaded) {
- if (!synced_with_loaded) {
- synced_with_loaded = true;
+ _algo_root.observe_current(true).SubscribeEach(vm =>
+ vm == null ? null :
+ Disposable.Create(
+ vm.subscribe_is_dirty().Subscribe(v => {
+ if (!v) {
_version.increment_version();
_on_committed_changed();
- } else {
- _refresh_on_local_changes.execute();
}
- } else {
- synced_with_loaded = false;
- }
- });
- }
- return vm.subscribe_definition().Subscribe(_ => _refresh_on_local_changes.execute());
- }),
+ }),
+ vm.subscribe_definition().Subscribe(_ => _refresh_on_local_changes.execute()))),
ObservableAutoWrapper.connect_item_hooks(algo_roots, a => a as IDisposable ?? Disposable.empty, true),
ObservableAutoWrapper.connect_item_hooks(templates, t => new CompositeDisposable(_any_templates_dirty_monitor.join(t), t), true),
Disposable.Create(() => {
@@ -152,16 +158,23 @@ namespace mbts.spark {
_edit_pane_vs_model.set_state(VisualStateNames.Name.GroupName, VisualStateNames.Name.Inactive);
break;
}
- resources.Add(_selected_format.observe_current(true).SubscribeHookLatest(f => {
- using (_refresh_on_local_changes.defer_execution()) {
- var algo_data = model.factory.default_algos(f);
- var default_algo = new AlgoKey(OrderDataHelper.get_default_algo(f));
- return this.load_algo_data_recursive(algo_data, default_algo);
- }
- }));
+ var permission_src = _permissions_mask.observe_result();
+ resources.Add(_selected_format.observe_current(true).CombineLatest(permission_src, (fmt, perms) => (fmt, perms))
+ .SubscribeEach(t => {
+ if ((t.perms & AlgoEditingPermissions.AllowEditStructure) != 0) {
+ using (_refresh_on_local_changes.defer_execution()) {
+ var algo_data = model.factory.default_algos(t.fmt);
+ var default_algo = new AlgoKey(OrderDataHelper.get_default_algo(t.fmt));
+ return this.load_algo_data_recursive(algo_data, default_algo);
+ }
+ }
+ return Disposable.empty;
+ }));
+ resources.Add(permission_src.Subscribe(_ => RaisePropertyChanged(nameof(editing_permissions))));
+ resources.Add(this.connect_data(permission_src));
resources.Add(this.connect_data(Observable.Return(model)));
+ resources.Add(_algo_root.Subscribe(_ => RaisePropertyChanged(nameof(IAlgoSelector.selected_algo), nameof(IAlgoParamVM.value), nameof(group))));
_dispose = resources;
- on_editing_permissions(_get_permissions());
await algo_root.load_from_async(def_data.value);
_version.increment_version();
_edit_stack.reset(_version.value);
@@ -169,11 +182,6 @@ namespace mbts.spark {
}
}
// local methods
- void on_editing_permissions(AlgoEditingPermissions eps) {
- _editing_permissions = eps;
- foreach (var vm in algo_roots)
- vm.set_permissions(eps);
- }
void on_can_redo_changed(bool oldval, bool newval) => can_redo_changed?.Invoke();
void on_can_undo_changed(bool oldval, bool newval) => can_undo_changed?.Invoke();
void on_local_changed() {
@@ -194,6 +202,7 @@ namespace mbts.spark {
public string name { get => _name.Value; set => _name.set(value); }
public string abbreviation { get => _abbreviation.Value; set => _abbreviation.set(value); }
public ObservableCollection algo_roots => _algo_roots;
+ public IDictionary algo_roots_index => _algo_roots;
public IReadOnlyObservableCollection algos_view { get; }
public IAlgoVM algo_root { get => _algo_root.Value; set => _algo_root.set(value); }
public IAlgoVM visible_algo_root => _visible_algo_root.Value;
@@ -210,6 +219,20 @@ namespace mbts.spark {
public bool is_selected { get => _is_selected.Value; set => _is_selected.set(value); }
public bool is_dirty => _is_dirty.Value;
public bool is_factory_definition => key.mode == AlgoKey.Mode.Factory;
+ public AlgoDisplayGroup group {
+ get {
+ switch (key.mode) {
+ case AlgoKey.Mode.Factory:
+ if (algo_root != null)
+ return algo_root.group;
+ break;
+ case AlgoKey.Mode.Unpersisted:
+ case AlgoKey.Mode.Persisted:
+ return AlgoDisplayGroup.Studio;
+ }
+ return AlgoDisplayGroup.BTS;
+ }
+ }
public bool can_redo => _can_redo.Value;
public bool can_undo => _can_undo.Value;
public EnabledValueVM custom_badge_color { get; } = new EnabledValueVM();
@@ -230,13 +253,51 @@ namespace mbts.spark {
// visual states
public ObservableCollection edit_pane_visual_states => _edit_pane_vs_model.states;
public ObservableCollection tree_view_visual_states => _tree_view_vs_model.states;
+ // editing permissions
+ public AlgoEditingPermissions editing_permissions_mask { get => _permissions_mask.mask; set => _permissions_mask.mask = value; }
+ public AlgoEditingPermissions editing_permissions => _permissions_mask.result;
#region IAlgoSelector
- event PropertyChange IAlgoSelector.selected_algo_changed { add => algo_root_changed += value; remove => algo_root_changed -= value; }
+ event PropertyChange IAlgoSelector.selected_algo_changed {
+ add => algo_root_changed += value;
+ remove => algo_root_changed -= value;
+ }
+ event PropertyChange IAlgoParamVM.value_changed {
+ add => algo_root_changed += value;
+ remove => algo_root_changed -= value;
+ }
+ event PropertyChange IAlgoParamVM.permissions_changed { add { } remove { } }
+ event Action IAlgoParamVM.is_dirty_changed { add { } remove { } }
+
+ string IAlgoParamVM.id => key.ToString();
+ string IAlgoParamVM.display_name => "Algo";
+
ObservableKeyedCollection IAlgoSelector.algos => _algo_roots;
- IAlgoVM IAlgoSelector.selected_algo { get => algo_root; set => algo_root = value; }
+ IAlgoVM IAlgoSelector.selected_algo {
+ get => algo_root;
+ set => algo_root = value;
+ }
+ IAlgoVM IAlgoParamVM.value {
+ get => algo_root;
+ set => algo_root = value;
+ }
+ bool IAlgoParamVM.has_value => _algo_root != null;
+ bool IAlgoParamVM.is_enabled { get; set; } = true;
+ object IAlgoParamVM.value {
+ get => algo_root;
+ set => algo_root = (IAlgoVM)value;
+ }
+ AlgoParamPermissions _permissions = AlgoParamPermissions.ReadWrite;
+ AlgoParamPermissions IAlgoParamVM.permissions { get => _permissions; set => _permissions = value; }
+
void IAlgoSelector.load_algo_data(IReadOnlyDictionary algo_data, AlgoKey? default_algo) =>
- _load_algo_data(algo_data, default_algo);
+ _load_algo_data(algo_data, default_algo);
+
+ void IAlgoParamVM.revert() { }
+ void IAlgoParamVM.mark_committed() { }
+
+ IObservable IAlgoSelector.subscribe_selected_algo() =>
+ this.observe_algo_root();
#endregion
#region IObserver (algo data...)
@@ -248,7 +309,7 @@ namespace mbts.spark {
void _load_algo_data(IReadOnlyDictionary algo_data, AlgoKey? default_algo) {
var orig_algo = algo_root?.id;
- _algo_roots.SyncWithDictionary(algo_data, d => OrderTypeVMFactory.create(d, _editing_permissions, true));
+ _algo_roots.SyncWithDictionary(algo_data, d => OrderTypeVMFactory.create(d, is_expanded: true));
if (!try_select(orig_algo) && !try_select(default_algo))
algo_root = algo_roots.FirstOrDefault();
//
@@ -298,6 +359,47 @@ namespace mbts.spark {
public IDisposable buffer_updates() => _template_update_buffer.buffer_updates();
+ public void load_def(CustomOrderDefinitionImmutable def) {
+ var key = OrderDataHelper.get_shallow_factory_key(def);
+ if (algo_root?.id == key) {
+ algo_root.load_from(def);
+ } else if (_algo_roots.TryGetValue(key, out IAlgoVM vm)) {
+ vm.load_from(def);
+ algo_root = vm;
+ } else {
+ algo_roots.Add(vm = _mk_algo_root(def));
+ algo_root = vm;
+ }
+ }
+
+ public void load_many(IEnumerable defs) {
+ /// don't load composite algos; we don't support recursive composites ()
+ if (defs is IList def_list) {
+ def_list = def_list.WrapSelector(d => d.actual(), null);
+ } else {
+ def_list = defs.Select(d => d.actual()).ToList();
+ }
+ switch (def_list.Count) {
+ case 0: algo_root = null; break;
+ case 1: load_def(def_list[0]); break;
+ default:
+ var def = def_list[0];
+ var key = OrderDataHelper.get_shallow_factory_key(def);
+ if (algo_root?.id == key) {
+ algo_root.load_many(def_list);
+ } else if (_algo_roots.TryGetValue(key, out IAlgoVM vm)) {
+ vm.load_many(def_list);
+ algo_root = vm;
+ } else {
+ OrderTypeVMFactory.create(key, def.display_name(), def.CustomCase, is_expanded: true);
+ algo_roots.Add(vm = _mk_algo_root(def));
+ vm.load_many(def_list);
+ algo_root = vm;
+ }
+ break;
+ }
+ }
+
public void load(AlgoData data) {
_assert_can_load(data.key);
if (algo_root != null)
@@ -309,7 +411,7 @@ namespace mbts.spark {
// pass a copy of the persisted state - rather than use local values - because if something goes wrong, it is better to be in sync with data fresh from the server/api.
public AlgoDefinitionVM to_persisted(AlgoData def) =>
- new AlgoDefinitionVM(_model, def);
+ new AlgoDefinitionVM(_model, def, selected_format, editing_permissions_mask);
public AlgoData create_algo_def() =>
new AlgoData(algo_root.definition, name, key);
@@ -322,16 +424,6 @@ namespace mbts.spark {
public override int GetHashCode() => key.GetHashCode();
public override string ToString() => algo_root == null ? $"!:{name}" : $"{algo_root.order_type}:{name}";
- AlgoEditingPermissions _get_permissions() {
- var permissions = AlgoEditingPermissions.None;
- if (_model.algo_model.ui_configuration.can_modify_definition_values) {
- permissions |= AlgoEditingPermissions.AllowEditValues | AlgoEditingPermissions.AllowSaveValues;
- }
- if (_model.algo_model.ui_configuration.can_modify_definition_structure || (_model.algo_model.templates_enabled() && _templates.Count == 0))
- permissions |= AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowSaveStructure;
- return permissions;
- }
-
void _assert_can_load(AlgoKey data_key) {
if (key.mode != data_key.mode)
throw new InvalidOperationException($"{typeof(AlgoDefinitionVM)} '{nameof(key)}.{nameof(AlgoKey.mode)}' must be {data_key.mode} (actually {key.mode}), to load specified data.");
@@ -359,10 +451,14 @@ namespace mbts.spark {
_committed = _version.value;
_is_dirty.refresh();
_refresh_undo_redo();
+ RaisePropertyChanged(nameof(committed_value), nameof(current_value));
}
+ public Snapshot? committed_value => _committed;
+ public Snapshot current_value => _version.value;
+
IAlgoVM _mk_algo_root(CustomOrderDefinitionImmutable definition) =>
- OrderTypeVMFactory.create(new AlgoData(definition), editing_permissions: _editing_permissions, true);
+ OrderTypeVMFactory.create(new AlgoData(definition), is_expanded: true);
void _on_metadata(AlgoDefinitionMetadata metadata) {
using (_refresh_on_local_changes.supress_execution()) {
@@ -463,5 +559,17 @@ namespace mbts.spark {
public static bool operator ==(Snapshot a, Snapshot b) => a.Equals(b);
public static bool operator !=(Snapshot a, Snapshot b) => !a.Equals(b);
}
+
+ struct SnapshotTemplateEqualityComparer : IEqualityComparer {
+ public bool Equals(Snapshot x, Snapshot y) =>
+ x.abbreviation == y.abbreviation &&
+ x.custom_badge_color == y.custom_badge_color &&
+ x.format == y.format &&
+ x.data.key == y.data.key &&
+ x.data.name == y.data.name &&
+ x.data.value.Equals(y.data.value);
+
+ public int GetHashCode(Snapshot obj) => throw new NotImplementedException();
+ }
}
}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoParamRowVM.cs b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoParamRowVM.cs
new file mode 100644
index 000000000..e7ebaa288
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoParamRowVM.cs
@@ -0,0 +1,99 @@
+using bts.utils;
+using mbts.collections;
+using mbts.ui;
+using mbts.ui.controls;
+using mbts.ui.shell;
+using System;
+using System.ComponentModel;
+using System.Windows.Input;
+
+namespace mbts.spark {
+ class AlgoParamRowVM : DisposableViewModelBase, DIYGrid.IRowVM, IEditableObject, ITemplateSelectorKey, IEquatable {
+ bool _is_enabled;
+ string _template_key;
+ ICommand _set_value_cmd;
+
+ public AlgoParamRowVM(IAlgoVM algo, IAlgoParamVM param, AlgoParamRowVM parent, string template_key = null) {
+ this.param = param;
+ this.algo = algo;
+ this.parent = parent;
+ _template_key = template_key;
+ param.permissions_changed += on_permissions_changed;
+ _dispose = Disposable.Create(() => param.permissions_changed -= on_permissions_changed);
+ void on_permissions_changed(AlgoParamPermissions oldval, AlgoParamPermissions newval) => RaisePropertyChanged(nameof(permissions));
+ }
+
+ public event Action invalidated;
+
+ public IAlgoVM algo { get; set; }
+ public IAlgoParamVM param { get; }
+ public AlgoParamPermissions permissions => param.permissions;
+ public AlgoParamRowVM parent { get; }
+ public int level => parent == null ? 0 : parent.level + 1;
+ public string path_disambiguation {
+ get {
+ if (parent == null)
+ return string.Empty;
+ string pd = parent.path_disambiguation;
+ if (parent.algo.order_type == bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Cover) {
+ if (pd.Length > 0)
+ pd += ".";
+ pd += parent.param.display_name;
+ }
+ return pd;
+ }
+ }
+ public bool is_enabled { get => _is_enabled; set => Set(ref _is_enabled, value); }
+ public ICommand set_value_cmd {
+ get {
+ if (_set_value_cmd == null) {
+ var cmd = new DelegateCommand(v => {
+ var orig_val = param.value;
+ try {
+ param.value = v;
+ } catch (InvalidCastException) {
+ param.value = orig_val;
+ }
+ }, _ => param.permissions == AlgoParamPermissions.ReadWrite);
+ concated_disposable(param.subscribe_permissions().Subscribe(_ => cmd.RaiseCanExecuteChanged()));
+ _set_value_cmd = cmd;
+ }
+ return _set_value_cmd;
+ }
+ }
+ string ITemplateSelectorKey.key => _template_key;
+
+ public void raise_invalidated() => invalidated?.Invoke();
+
+ public bool Equals(AlgoParamRowVM other) =>
+ other != null &&
+ param.id == other.param.id &&
+ parent.safe_equals(other.parent);
+
+ public override bool Equals(object obj) =>
+ Equals(obj as AlgoParamRowVM);
+
+ public override int GetHashCode() =>
+ EqualityComparer.aggregate_hash(param.id.GetHashCode(), parent?.GetHashCode() ?? 0);
+
+ #region IEditableObject
+ object _committed_value;
+ void IEditableObject.BeginEdit() => _committed_value = param.value;
+ void IEditableObject.EndEdit() => _committed_value = null;
+ void IEditableObject.CancelEdit() {
+ if (_committed_value != null)
+ param.value = _committed_value;
+ _committed_value = null;
+ }
+ #endregion
+ }
+
+ class AlgoSelectorParamRowVM : AlgoParamRowVM {
+ readonly IAlgoSelector _selector;
+
+ public AlgoSelectorParamRowVM(IAlgoVM algo_vm, IAlgoSelector selector, AlgoParamRowVM parent) : base(algo_vm, selector, parent) =>
+ _selector = selector;
+
+ public ObservableKeyedCollection algos => _selector.algos;
+ }
+}
\ No newline at end of file
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs
new file mode 100644
index 000000000..aa97940d2
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/VM/AlgoVMWrapper.cs
@@ -0,0 +1,215 @@
+using bts.api;
+using bts.api.orderman;
+using bts.collections;
+using bts.spark;
+using mbts.spark.utilities;
+using mbts.ui;
+using mbts.ui.controls;
+using mbts.ui.shell;
+using mbts.utils;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace mbts.spark {
+ class AlgoVMWrapper : DisposableViewModelBase, IAlgoVM,
+ IObserver,
+ IObserver,
+ IObserver,
+ IObserver {
+ static readonly HashSet
+ _algo_root_echo_props = new HashSet {
+ nameof(is_expanded),
+ nameof(editing_permissions),
+ nameof(definition),
+ nameof(display_name)
+ };
+ static readonly IReadOnlyDictionary
+ _value_echo_props = new Dictionary {
+ { nameof(AlgoDefinitionVM.name), nameof(display_name) },
+ { nameof(AlgoDefinitionVM.abbreviation), nameof(abbreviation) },
+ { nameof(AlgoDefinitionVM.badge_fill), nameof(meta) }
+ };
+ readonly ObservableAggregateCollection _child_algo_selectors = new ObservableAggregateCollection();
+ readonly ObservableAggregateCollection _algo_params = new ObservableAggregateCollection();
+ readonly DisposableContainer _value_hooks = new DisposableContainer();
+ Action _definition_changed = () => { };
+ _ObservedData? _data_cache;
+ AlgoDefinitionVM _value;
+
+ public AlgoVMWrapper(AlgoDefinitionVM algo_definition_vm) {
+ value = algo_definition_vm;
+ _dispose = new CompositeDisposable(_value_hooks) {
+ _child_algo_selectors.clear_collections,
+ _algo_params.clear_collections,
+ () => _value?.Dispose()
+ };
+ }
+
+ public event Action definition_changed { add => _definition_changed += value; remove => _definition_changed -= value; }
+
+ public AlgoDefinitionVM value {
+ get => _value;
+ set {
+ if (_value != value) {
+ _value?.Dispose();
+ _value = value;
+ _value_hooks.replace(_set_hooks(value));
+ RaisePropertyChanged(nameof(value));
+ }
+ }
+ }
+ public AlgoKey id => _value.key;
+ public CustomOrderDefinition.CustomOneofCase order_type => _algo_root?.order_type ?? CustomOrderDefinition.CustomOneofCase.None;
+ public OrderMetadata meta {
+ get {
+ if (_value != null) {
+ if (_value.custom_badge_color.enabled)
+ return new OrderMetadata { Color = value.custom_badge_color.value.rgb_color(), KeyBinding = value.abbreviation.if_null_or_empty(value.name) };
+ else if (_value.algo_root != null)
+ return _value.algo_root.meta;
+ }
+ return OrderDataHelper.get_metadata(order_type);
+ }
+ }
+ public AlgoEditingPermissions editing_permissions => _value?.editing_permissions ?? AlgoEditingPermissions.None;
+ public bool can_expand => _algo_root?.can_expand ?? false;
+ public bool is_expanded {
+ get => _value.algo_root?.is_expanded ?? false;
+ set {
+ if (_value != null)
+ _value.is_expanded = value;
+ }
+ }
+ public string display_name => _value?.name ?? string.Empty;
+ public string abbreviation => _value?.abbreviation;
+ public AlgoDisplayGroup group => _value?.group ?? AlgoDisplayGroup.BTS;
+ public CustomOrderDefinitionImmutable definition => _algo_root?.definition ?? new CustomOrderDefinitionImmutable(new CustomOrderDefinition());
+ public ObservableCollection child_algo_selectors => _child_algo_selectors;
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public ObservableCollection child_algo_selectors_view {
+ get {
+ _value?.algo_root?.ensure_init();
+ return _child_algo_selectors;
+ }
+ }
+ public IReadOnlyObservableCollection algo_params => _algo_params;
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public dynamic children_vm => _algo_root?.children_vm;
+
+ IAlgoVM _algo_root => _value?.algo_root;
+
+ public void assign_to(CustomOrderDefinition value) => _algo_root?.assign_to(value);
+ public bool key_match(KeyEventArgs e) => _algo_root?.key_match(e) ?? false;
+ public void load_from(CustomOrderDefinitionImmutable value) => _algo_root?.load_from(value);
+ public void load_many(IEnumerable values) => _algo_root?.load_many(values);
+ public Task load_from_async(CustomOrderDefinitionImmutable definition) => _algo_root is IAlgoVM vm ? vm.load_from_async(definition) : Task.FromResult(null);
+ void IAlgoVM.ensure_init() => _value?.algo_root?.ensure_init();
+
+ IDisposable _set_hooks(AlgoDefinitionVM vm) {
+ var algo_root_subs = new DisposableContainer();
+ vm.PropertyChanged += on_value_prop_changed;
+ return new CompositeDisposable(
+ vm.observe_algo_root().Subscribe(r => {
+ algo_root_subs.replace(null);
+ _child_algo_selectors.clear_collections();
+ _algo_params.clear_collections();
+ if (r != null) {
+ if (_data_cache.HasValue) {
+ _data_cache.Value.forward_to(r);
+ }
+ _child_algo_selectors.add_collection(r.child_algo_selectors);
+ _algo_params.add_collection(r.algo_params);
+ ((INotifyPropertyChanged)r).PropertyChanged += on_algo_root_prop_changed;
+ algo_root_subs.replace(new CompositeDisposable(
+ r.subscribe_definition().Subscribe(_ => _definition_changed?.Invoke())) {
+ () => ((INotifyPropertyChanged)r).PropertyChanged -= on_algo_root_prop_changed
+ });
+ }
+ RaisePropertyChanged(nameof(group));
+ }),
+ algo_root_subs) {
+ () => vm.PropertyChanged -= on_value_prop_changed
+ };
+ void on_algo_root_prop_changed(object sender, PropertyChangedEventArgs e) {
+ if (_algo_root_echo_props.Contains(e.PropertyName))
+ RaisePropertyChanged(e.PropertyName);
+ }
+ void on_value_prop_changed(object sender, PropertyChangedEventArgs e) {
+ if (_value_echo_props.TryGetValue(e.PropertyName, out string wrapper_prop))
+ RaisePropertyChanged(wrapper_prop);
+ }
+ }
+
+ // permissions
+ void IObserver.OnNext(AlgoEditingPermissions value) {
+ _data_cache = _data_cache?.with(value) ?? new _ObservedData(value, default, default, default);
+ (_algo_root as IObserver)?.OnNext(value);
+ }
+ void IObserver.OnError(Exception error) { }
+ void IObserver.OnCompleted() { }
+ // model
+ void IObserver.OnNext(OrdersModel value) {
+ _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, value, default, default);
+ (_algo_root as IObserver)?.OnNext(value);
+ }
+ void IObserver.OnError(Exception error) { }
+ void IObserver.OnCompleted() { }
+ // security
+ void IObserver.OnNext(SecurityImmutable? value) {
+ _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, default, value, default);
+ (_algo_root as IObserver)?.OnNext(value);
+ }
+ void IObserver.OnError(Exception error) { }
+ void IObserver.OnCompleted() { }
+ // security md
+ void IObserver.OnNext(SecurityMD? value) {
+ _data_cache = _data_cache?.with(value) ?? new _ObservedData(default, default, default, value);
+ (_algo_root as IObserver)?.OnNext(value);
+ }
+ void IObserver.OnError(Exception error) { }
+ void IObserver.OnCompleted() { }
+
+ struct _ObservedData {
+ public readonly AlgoEditingPermissions permissions;
+ public readonly OrdersModel model;
+ public readonly SecurityImmutable? security;
+ public readonly SecurityMD? security_md;
+
+ public _ObservedData(AlgoEditingPermissions permissions, OrdersModel model, SecurityImmutable? security, SecurityMD? security_md) {
+ this.permissions = permissions;
+ this.model = model;
+ this.security = security;
+ this.security_md = security_md;
+ }
+
+ public void forward_to(IAlgoVM recipient) {
+ (recipient as IObserver)?.OnNext(permissions);
+ if (model != null)
+ (recipient as IObserver)?.OnNext(model);
+ if (security_md.HasValue)
+ (recipient as IObserver)?.OnNext(security_md);
+ if (security.HasValue)
+ (recipient as IObserver)?.OnNext(security);
+ }
+
+ public _ObservedData with(AlgoEditingPermissions? permissions) =>
+ new _ObservedData(permissions ?? this.permissions, model, security, security_md);
+
+ public _ObservedData with(OrdersModel model) =>
+ new _ObservedData(permissions, model, security, security_md);
+
+ public _ObservedData with(SecurityImmutable? security) =>
+ new _ObservedData(permissions, model, security, security_md);
+
+ public _ObservedData with(SecurityMD? security_md) =>
+ new _ObservedData(permissions, model, security, security_md);
+ }
+ }
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml
new file mode 100644
index 000000000..f74c7cb68
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml
@@ -0,0 +1,622 @@
+
+
+
+
+
+
+
+
+ 4
+ 8
+ 12
+ 4
+ 8
+ 12
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ None
+ ReadOnly
+
+
+
+
+
+
+
+
+
+
+
+ Show Strategy Params
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Best Bid Price (click to assign)
+
+
+ Hold a number key to cross the market by 'n' ticks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Best Ask Price (click to assign)
+
+
+ Hold a number key to cross the market by 'n' ticks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Algo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml.cs
new file mode 100644
index 000000000..c8dbb61a0
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoEditorGridView.xaml.cs
@@ -0,0 +1,207 @@
+using bts.collections;
+using bts.utils;
+using mbts.spark;
+using mbts.ui.controls;
+using mbts.ui.converters;
+using mbts.ui.utility;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+
+namespace mbts.ui.spark {
+ partial class AlgoEditorGridView : UserControl {
+ public static readonly IValueConverter
+ GeneralVisualStateConverter = ValueConverter.create(is_read_only => is_read_only ? VisualStateNames.General.ReadOnly : VisualStateNames.General.Normal),
+ AlgoRootVisualStateConverter = ValueConverter.create(show_bbo => show_bbo ? VisualStateNames.AlgoRoot.Active : VisualStateNames.AlgoRoot.Inactive),
+ AlgoRootComboBoxMarginConverter = ValueConverter.create(name_col_width => new Thickness(name_col_width + 8, 0, 0, 0)),
+ NullableEnumParamRowItemsSourceConverter = ValueConverter.create(param_row => {
+ if (param_row?.param != null) {
+ var tenum = param_row.param.GetType().GetInterfaceGenericArgument(AlgoParamTemplateSelector.generic_algo_param_itype);
+ if (tenum.IsNullable()) {
+ // .First() should be safe, since we know this is a Nullable.
+ tenum = tenum.GetGenericArguments().First();
+ }
+ if (tenum.IsEnum)
+ return Enum.GetValues(tenum);
+ }
+ return null;
+ });
+
+ public static readonly MouseButtonEventHandler PayupTicksMouseButtonHandler = (s, e) => {
+ if ((s as Hyperlink)?.Command is ICommand cmd) {
+ cmd.ExecuteIfCan(KeyboardExtensions.GetPressedNumber() ?? 0);
+ e.Handled = true;
+ }
+ };
+
+ readonly ObservableAggregateCollection _param_rows = new ObservableAggregateCollection();
+
+ public AlgoEditorGridView() {
+ InitializeComponent();
+ _set_value_column_width();
+ // AlgoRoots
+ AlgoRootsViewSource = new CollectionViewSource<_AlgoRootsCollectionView>();
+ BindingOperations.SetBinding(AlgoRootsViewSource, CollectionViewSource.SourceProperty, new Binding(nameof(AlgoRoots)) { Source = this });
+ AlgoRootsViewSource.GroupDescriptions.Add(new PropertyGroupDescription(nameof(IAlgoVM.group)));
+ // AlgoParamRows
+ AlgoParamRowsViewSource = new CollectionViewSource>();
+ BindingOperations.SetBinding(AlgoParamRowsViewSource, CollectionViewSource.SourceProperty, new Binding(nameof(AlgoParamRows)) { Source = this });
+ AlgoParamRowsViewSource.IsLiveFilteringRequested = true;
+ AlgoParamRowsViewSource.LiveFilteringProperties.Add(nameof(AlgoParamRowVM.permissions));
+ AlgoParamRowsViewSource.Filter += param_rows_filter;
+ DataGridEditHelper.set_hooks(this);
+ void param_rows_filter(object sender, FilterEventArgs e) =>
+ e.Accepted = e.Item is AlgoParamRowVM row && row.param.permissions != AlgoParamPermissions.None;
+ }
+
+ public enum Columns { ParamName, Value }
+
+ event Action CommitEditRequested, CancelEditRequested;
+
+ public CollectionViewSource AlgoRootsViewSource { get; }
+ public CollectionViewSource> AlgoParamRowsViewSource { get; }
+
+ bool _stretch_value_column = true;
+ public bool StretchValueColumn {
+ get => _stretch_value_column;
+ set {
+ if (_stretch_value_column != value) {
+ _stretch_value_column = value;
+ _set_value_column_width();
+ }
+ }
+ }
+
+ #region AnimateDirtyParams
+ public static readonly DependencyProperty AnimateDirtyProperty =
+ WPFHelper.create_dp(nameof(AnimateDirty), true);
+
+ public bool AnimateDirty {
+ get => (bool)GetValue(AnimateDirtyProperty);
+ set => SetValue(AnimateDirtyProperty, value);
+ }
+ #endregion
+
+ #region IsReadOnly
+ public static readonly DependencyProperty IsReadOnlyProperty =
+ WPFHelper.create_dp(nameof(IsReadOnly));
+
+ public bool IsReadOnly {
+ get => (bool)GetValue(IsReadOnlyProperty);
+ set => SetValue(IsReadOnlyProperty, value);
+ }
+ #endregion
+
+ #region CanUserChangeAlgoRoot
+ public static readonly DependencyProperty CanUserChangeAlgoRootProperty =
+ WPFHelper.create_dp(nameof(CanUserChangeAlgoRoot));
+
+ public bool CanUserChangeAlgoRoot {
+ get => (bool)GetValue(CanUserChangeAlgoRootProperty);
+ set => SetValue(CanUserChangeAlgoRootProperty, value);
+ }
+ #endregion
+
+ #region AlgoRoots
+ public static readonly DependencyProperty AlgoRootsProperty =
+ WPFHelper.create_dp, AlgoEditorGridView>(nameof(AlgoRoots));
+
+ public IReadOnlyObservableCollection AlgoRoots {
+ get => GetValue(AlgoRootsProperty) as IReadOnlyObservableCollection;
+ set => SetValue(AlgoRootsProperty, value);
+ }
+ #endregion
+
+ #region SelectedAlgoRoot
+ public static readonly DependencyProperty SelectedAlgoRootProperty =
+ WPFHelper.create_dp(nameof(SelectedAlgoRoot), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);
+
+ public IAlgoVM SelectedAlgoRoot {
+ get => GetValue(SelectedAlgoRootProperty) as IAlgoVM;
+ set => SetValue(SelectedAlgoRootProperty, value);
+ }
+ #endregion
+
+ #region AlgoParamRows
+ public static readonly DependencyProperty AlgoParamRowsProperty =
+ WPFHelper.create_dp, AlgoEditorGridView>(nameof(AlgoParamRows));
+
+ public IReadOnlyObservableCollection AlgoParamRows {
+ get => GetValue(AlgoParamRowsProperty) as IReadOnlyObservableCollection;
+ set => SetValue(AlgoParamRowsProperty, value);
+ }
+ #endregion
+
+ public static AlgoEditorGridView create_attach_view() =>
+ new AlgoEditorGridView {
+ Margin = new Thickness(6),
+ CanUserChangeAlgoRoot = true,
+ };
+
+ public void commit_edit() => CommitEditRequested?.Invoke();
+ public void cancel_edit() => CancelEditRequested?.Invoke();
+
+ void _set_value_column_width() {
+ foreach (var c in _param_grid?.Columns.empty_if_null())
+ c.Width = _stretch_value_column ? new DataGridLength(1, DataGridLengthUnitType.Star) : DataGridLength.Auto;
+ }
+
+ void _on_execution_strategy_toggle_click(object sender, RoutedEventArgs e) {
+ if (sender is Hyperlink hl && hl.try_find_ancestor_of_type(out DataGridRow row_view)) {
+ Visibility vis; string text;
+ if (row_view.DetailsVisibility == Visibility.Visible) {
+ vis = Visibility.Collapsed;
+ text = "Show Strategy Params";
+ } else {
+ vis = Visibility.Visible;
+ text = "Hide Strategy Params";
+ }
+ hl.Inlines.Clear();
+ hl.Inlines.Add(text);
+ row_view.SetCurrentValue(DataGridRow.DetailsVisibilityProperty, vis);
+ }
+ }
+
+ public static class VisualStateNames {
+ public static class General {
+ public const string GroupName = nameof(General);
+
+ public static readonly string
+ Normal = $"{GroupName}{nameof(Normal)}",
+ ReadOnly = $"{GroupName}{nameof(ReadOnly)}";
+ }
+
+ public static class AlgoRoot {
+ public const string GroupName = nameof(AlgoRoot);
+
+ public static readonly string
+ Active = $"{GroupName}{VisualStates.Active}",
+ Inactive = $"{GroupName}{VisualStates.Inactive}";
+ }
+ }
+
+ class _AlgoRootsCollectionView : ListCollectionView {
+ public _AlgoRootsCollectionView(IList list) : base(list) =>
+ CustomSort = AlgoCollectionHelper.algo_vm_comparer.to_non_generic();
+ }
+ }
+
+ class AlgoEditorGridRowStyleSelector : StyleSelector {
+ public Style DefaultStyle { get; set; }
+ public Style SpreaderStyle { get; set; }
+
+ public override Style SelectStyle(object item, DependencyObject container) {
+ if (item is AlgoParamRowVM row) {
+ if (row.param.id == nameof(bts.api.orderman.SpreaderOrderDefinition.ExecutionStrategy))
+ return SpreaderStyle;
+ }
+ return DefaultStyle;
+ }
+ }
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs
new file mode 100644
index 000000000..5f4d64a32
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs
@@ -0,0 +1,88 @@
+using bts.collections;
+using mbts.ui.controls;
+using mbts.ui.utility;
+using mbts.utils;
+using System;
+using System.Collections.ObjectModel;
+using System.Reactive.Linq;
+using System.Reactive.Disposables;
+
+namespace mbts.spark {
+ static class AlgoParamRowsHelper {
+ public static IDisposable connect(AlgoDefinitionVM algo, ObservableAggregateCollection rows, bool include_algo_type_rows) =>
+ algo == null ? null : new CompositeDisposable(algo.observe_algo_root().SubscribeEach(a => {
+ rows.clear_collections();
+ if (a == null)
+ return Disposable.empty;
+ var child_rows = new ObservableAggregateCollection();
+ /// Note: the order of operations here matters
+ /// has the potential to trigger a lot of CollectionChanged events (depending on how deep the algo-tree is).
+ /// There is no need to burden the aggregate 'rows' with echoing all of these events, if the child-row collection is finished changing when it is added to the aggregate.
+ var hook = _wrap_rows(a, null, child_rows, include_algo_type_rows);
+ rows.add_collection(child_rows.AsReadOnly());
+ return hook;
+ })) {
+ rows.clear_collections
+ };
+
+ public static IDisposable negate_is_dirty(IReadOnlyObservableCollection rows) {
+ return ObservableAutoWrapper.connect_item_hooks(rows, hook);
+ IDisposable hook(AlgoParamRowVM r) {
+ r.param.is_dirty_changed += negate;
+ return Disposable.Create(unhook);
+ void negate(bool is_dirty) {
+ if (is_dirty)
+ r.param.mark_committed();
+ }
+ void unhook() =>
+ r.param.is_dirty_changed -= negate;
+ }
+ }
+
+ static IDisposable _wrap_rows(AlgoDefinitionVM algo_def, ObservableAggregateCollection rows, bool include_algo_type_rows) {
+ AlgoParamRowVM root = null;
+ ObservableAggregateCollection algo_params;
+ if (include_algo_type_rows) {
+ // while normal params live and die with the selected algo-type (when the algo-type changes, they are removed, and replaced with params for the new algo type),
+ // the algo-type row is constant (it is the row with the algo-type dropdown, which the user may use to select different algos).
+ algo_params = new ObservableAggregateCollection();
+ rows.add_collection(new ObservableAppendCollection(algo_params, root = new AlgoSelectorParamRowVM(new AlgoVMWrapper(algo_def), algo_def, null)).AsReadOnly());
+ } else {
+ algo_params = rows;
+ }
+ return algo_def.observe_algo_root().SubscribeEach(a => {
+ algo_params.clear_collections();
+ if (a == null)
+ return Disposable.empty;
+ var child_rows = new ObservableAggregateCollection();
+ /// Note: the order of operations here matters
+ /// has the potential to trigger a lot of CollectionChanged events (depending on how deep the algo-tree is).
+ /// There is no need to burden the aggregate 'rows' with echoing all of these events, if the child-row collection is finished changing when it is added to the aggregate.
+ var hook = _wrap_rows(a, root, child_rows, include_algo_type_rows);
+ algo_params.add_collection(child_rows.AsReadOnly());
+ return hook;
+ });
+ }
+
+ static IDisposable _wrap_rows(IAlgoVM algo_root, AlgoParamRowVM parent, ObservableAggregateCollection all_rows, bool include_algo_type_rows) {
+ var wrapped_params = new ObservableAutoWrapper(algo_root.algo_params, pvm => new AlgoParamRowVM(algo_root, pvm, parent));
+ var selector_params = new ObservableCollection();
+ all_rows.add_collection(wrapped_params);
+ all_rows.add_collection(selector_params);
+ return ObservableAggregateCollection.connect(selector_params, algo_root.child_algo_selectors, new Func, IDisposable)>(hook_children));
+ (ObservableCollection, IDisposable) hook_children(IAlgoSelector s) {
+ var child_rows = new ObservableAggregateCollection();
+ var selector_wrapper = new AlgoSelectorParamRowVM(algo_root, s, parent);
+ return (
+ include_algo_type_rows ?
+ (ObservableCollection)new ObservableAppendCollection(child_rows, selector_wrapper) :
+ child_rows,
+ s.subscribe_selected_algo().SubscribeEach(a => {
+ s.value = a;
+ child_rows.clear_collections();
+ return _wrap_rows(a, selector_wrapper, child_rows, include_algo_type_rows);
+ }));
+ }
+ }
+ }
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs
new file mode 100644
index 000000000..11459e1bc
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs
@@ -0,0 +1,78 @@
+using bts.collections;
+using bts.spark;
+using mbts.spark;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Reflection;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace mbts.ui.spark {
+ static class AlgoParamTemplateKeys {
+ public const string
+ Price = nameof(Price),
+ Size = nameof(Size);
+ }
+
+ /// TODO: remove this class and just use a .
+ class AlgoParamTemplateSelector : DataTemplateSelector {
+ public static readonly Type generic_algo_param_itype = typeof(IAlgoParamVM<>);
+
+ KeyedCollection _keyed_templates = new KeyedCollection(tsk => tsk.Key);
+
+ public DataTemplate BoolTemplate { get; set; }
+ public DataTemplate NullableBoolTemplate { get; set; }
+ public DataTemplate IntTemplate { get; set; }
+ public DataTemplate NullableIntTemplate { get; set; }
+ public DataTemplate UIntTemplate { get; set; }
+ public DataTemplate NullableUIntTemplate { get; set; }
+ public DataTemplate DoubleTemplate { get; set; }
+ public DataTemplate EnumTemplate { get; set; }
+ public DataTemplate NullableEnumTemplate { get; set; }
+ public DataTemplate StringTemplate { get; set; }
+ public DataTemplate QuantityMeasureTemplate { get; set; }
+ public DataTemplate OrderDefTemplate { get; set; }
+ public DataTemplate ExecutionStrategyTemplate { get; set; }
+ public DataTemplate TimestampTemplate { get; set; }
+
+ /// is needed for the 'price' param. Price was formerly edited in a separate control, however now it is just another param row.
+ /// Before this, the generic type argument in the implementation was enough to determine the template.
+ /// Since 'price' is just a double, further specification was needed to associate it with a 'PriceEntryControl' template.
+ public IList KeyedTemplates => _keyed_templates;
+
+ public override DataTemplate SelectTemplate(object item, DependencyObject container) {
+ if (item is ITemplateSelectorKey tsk && tsk.key is string template_key && _keyed_templates.TryGetValue(template_key, out var tkv))
+ return tkv.Value;
+ IAlgoParamVM pvm = item as IAlgoParamVM ?? (item as AlgoParamRowVM)?.param;
+ if (pvm != null) {
+ if (pvm is IAlgoParamVM) return DoubleTemplate;
+ if (pvm is IAlgoParamVM) return IntTemplate;
+ if (pvm is IAlgoParamVM) return NullableIntTemplate;
+ if (pvm is IAlgoParamVM) return UIntTemplate;
+ if (pvm is IAlgoParamVM) return NullableUIntTemplate;
+ if (pvm is IAlgoParamVM) return NullableBoolTemplate;
+ if (pvm is IAlgoParamVM) return BoolTemplate;
+ if (pvm is IAlgoParamVM) return StringTemplate;
+ if (pvm is IAlgoParamVM) return OrderDefTemplate;
+ if (pvm is IAlgoParamVM) return QuantityMeasureTemplate;
+ if (pvm is IAlgoParamVM) return ExecutionStrategyTemplate;
+ if (pvm is IAlgoParamVM) return TimestampTemplate;
+ var targ = ReflectionHelper.GetGenericTypeArgs(pvm.GetType(), generic_algo_param_itype).FirstOrDefault();
+ if (targ != null) {
+ if (targ.IsEnum)
+ return EnumTemplate;
+ else if (targ.IsNullable()) {
+ targ = targ.GetGenericArguments()[0];
+ if (targ.IsEnum)
+ return NullableEnumTemplate;
+ }
+
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/DataGridEditHelper.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/DataGridEditHelper.cs
new file mode 100644
index 000000000..d232ab8c7
--- /dev/null
+++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/DataGridEditHelper.cs
@@ -0,0 +1,181 @@
+#define ENTER_BEHAVES_LIKE_TAB
+using bts;
+using mbts.ui.controls;
+using mbts.ui.extensions;
+using mbts.ui.spark.algo;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Input;
+
+namespace mbts.ui.spark {
+ partial class AlgoEditorGridView {
+ static class DataGridEditHelper {
+ public static IDisposable set_hooks(AlgoEditorGridView algo_editor) {
+ var grid = algo_editor._param_grid;
+ grid.PreviewKeyDown += on_preview_key_down;
+ grid.KeyDown += on_key_down;
+ grid.SelectionChanged += on_selection_changed;
+ grid.PreparingCellForEdit += on_preparing_cell_for_edit;
+ grid.CellEditEnding += on_cell_edit_ending;
+ grid.GotFocus += on_got_focus;
+ algo_editor.CommitEditRequested += on_commit_edit_requested;
+ algo_editor.CancelEditRequested += on_cancel_edit_requested;
+ return Disposable.Create(() => {
+ grid.PreviewKeyDown += on_preview_key_down;
+ grid.KeyDown -= on_key_down;
+ grid.SelectionChanged -= on_selection_changed;
+ grid.PreparingCellForEdit -= on_preparing_cell_for_edit;
+ grid.CellEditEnding -= on_cell_edit_ending;
+ grid.GotFocus -= on_got_focus;
+ algo_editor.CommitEditRequested -= on_commit_edit_requested;
+ algo_editor.CancelEditRequested -= on_cancel_edit_requested;
+ });
+ /// Handlers
+ // hooked up to PreviewKeyDown, instead of KeyDown, so the cells can't override this behavior
+ void on_preview_key_down(object sender, KeyEventArgs e) {
+ switch (e.Key) {
+ case Key.Escape: e.Handled = cancel_edit(); break;
+ case Key.Enter:
+ if (grid.TryGetCurrentRowView(out var row_view)) {
+ if (row_view.IsEditing) {
+ commit_edit();
+#if ENTER_BEHAVES_LIKE_TAB
+ NavigationHelper.keyboard_move_focus(FocusNavigationDirection.Down);
+#endif
+ } else grid.BeginEdit();
+ }
+ e.Handled = true;
+ break;
+ }
+ }
+
+ // hooked up to KeyDown, instead of PreviewKeyDown, so cells can implement custom Key/CommandBindings, or other key-based behavior without the DataGrid handling it in the PreviewKeyDown event.
+ // for ex: TickUpDown cells can do things like TickUp/Down when Ctrl+Up/Down arrow-key is pressed.
+ void on_key_down(object sender, KeyEventArgs e) {
+ switch (e.Key) {
+ case Key.Up: NavigationHelper.keyboard_move_focus(FocusNavigationDirection.Up); break;
+ case Key.Down: NavigationHelper.keyboard_move_focus(FocusNavigationDirection.Down); break;
+ default: return;
+ }
+ e.Handled = true;
+ }
+
+ void on_selection_changed(object sender, SelectionChangedEventArgs e) {
+ _commit(e.RemovedItems?.Cast