Merge branch 'SPARK-1944-attach/detach/update' of bitbucket.org:bluetradesys/spark into ice_exec3
This commit is contained in:
commit
98aa463b4e
138 files changed
+3698
-2005
No files matched your search
Vendored
+1
-1
@@ -215,7 +215,7 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
|
||||
"args": ["test", "[md]"],
|
||||
"args": ["test", "[mbo]"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server/",
|
||||
"environment": [],
|
||||
|
||||
@@ -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)
|
||||
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)
|
||||
@@ -7,7 +7,6 @@ zola_path=$(readlink -f "../../externals/linux/bin/zola/zola")
|
||||
|
||||
mkdir -p $temp_path
|
||||
cp -r ./* $temp_path
|
||||
cp -r ../../src/sdk/doc/* $temp_path/content/bts_spark_sdk/Server/
|
||||
|
||||
cd $temp_path
|
||||
$zola_path build -u '/docs/' -o $1 >$tmpfile 2>&1
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
+++
|
||||
title = "BTS Basic Algos"
|
||||
weight = 10
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
|
||||
|
||||
## Lean
|
||||
|
||||
The goal of the lean order is to watch the opposite-inside market size and cross when that size goes below the threshold (this also implies a cross if that size goes to zero and the market trades away from you) If the market trades toward you, you can opt into several different behaviors
|
||||
|
||||
##### Parameters
|
||||
* Cross Thresh - size thresh in absolute or ratio terms
|
||||
* Max Chase Ticks - max levels to pay up, in ticks
|
||||
|
||||
|
||||
## Join
|
||||
The goal of the join order is to watch the opposite-inside market and join when the market flips (that is, when the best offer becomes the best bid) and has at least threshold size.
|
||||
|
||||
##### Parameters
|
||||
* Join Thresh - size thresh in absolute or ratio terms
|
||||
|
||||
|
||||
## Top
|
||||
|
||||
The goal of the top order is to not trade by yourself, but the intent at the time of order entry is to get filled.If the order is on the market (say current bid price) AND the quantity on that bid price is below top thresh then cancel the order else remain working.
|
||||
|
||||
##### Parameters
|
||||
* Top Thresh - size thresh in absolute or ratio terms
|
||||
|
||||
|
||||
## Cover
|
||||
A Cover order’s purpose is to fire a hedge order (of any type) in response to fills from it’s child order on the opposite side of the market N ticks away
|
||||
|
||||
##### Parameters
|
||||
* Profit Ticks - ticks above or below fill price to place profit / cover order
|
||||
|
||||
|
||||
## OCO
|
||||
An OCO order creates a relationship between a child order and a 'stop' or 'other' order such that when one of these is cancelled, both cancel, or when one is filled, the other order's size is debited in the amount of the fill.
|
||||
|
||||
Composing this order with Cover simulates scalping functionality
|
||||
|
||||
##### Parameters
|
||||
* Stop Ticks - ticks below or above main order to place stop / other order
|
||||
@@ -1,6 +0,0 @@
|
||||
+++
|
||||
title = "Client"
|
||||
weight = 1
|
||||
sort_by = "weight"
|
||||
redirect_to = "bts_spark_sdk/Client/overview/"
|
||||
+++
|
||||
@@ -1,6 +0,0 @@
|
||||
+++
|
||||
title = "Server"
|
||||
weight = 2
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
@@ -1,6 +0,0 @@
|
||||
+++
|
||||
title = "BTS Spark SDK"
|
||||
weight = 2
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
@@ -4,6 +4,17 @@ weight = 3
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
## 1.6.0
|
||||
### User Visible Changes
|
||||
#### New Features
|
||||
- You can now view your order's position in queue in the ladder
|
||||
#### Bug Fixes
|
||||
- Fix a bug in the order popup in the ladder which could lead to a crash.
|
||||
|
||||
## 1.5.9
|
||||
### User Visible Changes
|
||||
- Fix for stunnel connections on Windows 7
|
||||
|
||||
## 1.5.8
|
||||
### User Visible Changes
|
||||
- Fixed a bug where it was possible to crash the UI by entering an order through the order ticket if Enter was used to dismiss the dialog.
|
||||
|
||||
+1
-1
Submodule externals updated: d0e8645b5e...67a79263ba.
@@ -75,6 +75,41 @@ namespace mbts.ui.shell
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
void start_stunnel(string path, uint job_error)
|
||||
{
|
||||
string config_error;
|
||||
if (!mbts.config.Configuration.try_initialize(out config_error))
|
||||
{
|
||||
_stunnel_process = Process.Start(path + "bin\\stunnel.exe");
|
||||
if (_stunnel_process != null)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (mbts.config.Configuration.try_initialize(out config_error))
|
||||
break;
|
||||
System.Threading.Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
stunnel_job_error = "Stunnel Job Error code: " + job_error +
|
||||
" could not start stunnel " + (config_error ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
void kill_stunnel()
|
||||
{
|
||||
try
|
||||
{
|
||||
Process[] ps = Process.GetProcessesByName("stunnel");
|
||||
ps.ForEach(p =>
|
||||
{
|
||||
try { p.Kill(); }
|
||||
catch {}
|
||||
});
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
Process _stunnel_process;
|
||||
static internal string stunnel_job_error { get; private set;}
|
||||
void init_stunnel(string[] argv)
|
||||
@@ -85,24 +120,10 @@ namespace mbts.ui.shell
|
||||
if (File.Exists(path + "config\\stunnel.conf"))
|
||||
{
|
||||
uint job_error = BTSUINativeMethods.setup_process_job_object();
|
||||
if(job_error == 0)
|
||||
{
|
||||
_stunnel_process = Process.Start(path + "bin\\stunnel.exe");
|
||||
string config_error; bool success = false;
|
||||
if(_stunnel_process != null)
|
||||
{
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
if(success = mbts.config.Configuration.try_initialize(out config_error))
|
||||
break;
|
||||
System.Threading.Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
stunnel_job_error = "Stunnel Job Error code: " + job_error + " could not start stunnel";
|
||||
}
|
||||
else
|
||||
stunnel_job_error = "Stunnel Job Error code: " + job_error;
|
||||
//if we can't put this process and stunnel into a job, try to stop stunnel then restart
|
||||
if(job_error != 0)
|
||||
kill_stunnel();
|
||||
start_stunnel(path, job_error);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
|
||||
@@ -6,6 +6,7 @@ using bts.api.persistence;
|
||||
using bts.api.position;
|
||||
using bts.api.synthetic;
|
||||
using bts.co2;
|
||||
using bts.md;
|
||||
using bts.metrics;
|
||||
using bts.support;
|
||||
using System.ComponentModel.Composition;
|
||||
@@ -50,6 +51,9 @@ namespace Spark {
|
||||
AlgoServiceWrapper _algo_service_wrapper;
|
||||
[Export]
|
||||
public AlgoServiceWrapper algo_service_wrapper => _algo_service_wrapper ?? (_algo_service_wrapper = new AlgoServiceWrapper(context));
|
||||
|
||||
[Export]
|
||||
public MBOService mbo_service => context.locate<MBOService>();
|
||||
}
|
||||
|
||||
class AlgoServiceWrapper {
|
||||
|
||||
@@ -38,6 +38,14 @@ namespace mbts.spark {
|
||||
font_weight = FontWeights.SemiBold.ToOpenTypeWeight()
|
||||
};
|
||||
|
||||
public static LadderColumnSettings DefaultPiqColumnSettings => new LadderColumnSettings {
|
||||
show = false,
|
||||
width = 50,
|
||||
font_family = "Segoe UI",
|
||||
font_size = 10,
|
||||
font_weight = FontWeights.SemiBold.ToOpenTypeWeight()
|
||||
};
|
||||
|
||||
[ProtoMember(1)]
|
||||
public bool show { get; set; }
|
||||
[ProtoMember(2)]
|
||||
@@ -249,7 +257,8 @@ namespace mbts.spark {
|
||||
bid_column = LadderColumnSettings.Default,
|
||||
ask_column = LadderColumnSettings.Default,
|
||||
price_column = LadderColumnSettings.Default,
|
||||
last_column = LadderColumnSettings.Default;
|
||||
last_column = LadderColumnSettings.Default,
|
||||
piq_column = LadderColumnSettings.DefaultPiqColumnSettings;
|
||||
orders_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
bid_column.foreground = 0xFFFFFF;
|
||||
bid_column.background = BTSColors.MarketData.bid;
|
||||
@@ -257,6 +266,7 @@ namespace mbts.spark {
|
||||
ask_column.background = BTSColors.MarketData.ask;
|
||||
price_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
last_column.background = 0xFFFFFF;
|
||||
piq_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
var rv = new LadderSettings {
|
||||
row_height = 22,
|
||||
grid_line_color = 0x535353,
|
||||
@@ -265,6 +275,7 @@ namespace mbts.spark {
|
||||
ask_column = ask_column,
|
||||
price_column = price_column,
|
||||
last_column = last_column,
|
||||
piq_column = piq_column,
|
||||
volume_column = VolumeColumnSettings.Default,
|
||||
calculator_buttons = new[] { 1, 5, 10, 25, 50, 100 },
|
||||
scroll_bar_visible = false,
|
||||
@@ -400,7 +411,7 @@ namespace mbts.spark {
|
||||
public bool clear_visible { get; set; }
|
||||
//
|
||||
[ProtoMember(43), DefaultValue(_default_order_entry_panel_width)]
|
||||
public double order_entry_panel_initial_width { get; set; }
|
||||
public double order_entry_panel_initial_width { get; set; }
|
||||
|
||||
[ProtoMember(44), DefaultValue(true)]
|
||||
public bool use_defaults { get; set; }
|
||||
@@ -419,6 +430,13 @@ namespace mbts.spark {
|
||||
[ProtoMember(48)]
|
||||
public NetChangeTerms net_change { get; set; }
|
||||
|
||||
[ProtoMember(49)]
|
||||
LadderColumnSettings _piq_column;
|
||||
public LadderColumnSettings piq_column {
|
||||
get => _piq_column ?? (_piq_column = LadderSettings.Default.piq_column);
|
||||
set => _piq_column = value;
|
||||
}
|
||||
|
||||
public bool Equals(LadderSettings other) =>
|
||||
other != null &&
|
||||
row_height == other.row_height &&
|
||||
@@ -428,6 +446,7 @@ namespace mbts.spark {
|
||||
ask_column.safe_equals(other.ask_column) &&
|
||||
price_column.safe_equals(other.price_column) &&
|
||||
last_column.safe_equals(other.last_column) &&
|
||||
piq_column.safe_equals(other.piq_column) &&
|
||||
calculator_buttons.safe_equals(other.calculator_buttons, (a, b) => a.SequenceEqual(b)) &&
|
||||
scroll_bar_visible == other.scroll_bar_visible &&
|
||||
default_order_type == other.default_order_type &&
|
||||
@@ -478,6 +497,7 @@ namespace mbts.spark {
|
||||
EqualityComparer.safe_get_hash_code(ask_column),
|
||||
EqualityComparer.safe_get_hash_code(price_column),
|
||||
EqualityComparer.safe_get_hash_code(last_column),
|
||||
EqualityComparer.safe_get_hash_code(piq_column),
|
||||
EqualityComparer.safe_get_hash_code(calculator_buttons),
|
||||
scroll_bar_visible.GetHashCode(),
|
||||
default_order_type.GetHashCode(),
|
||||
@@ -519,12 +539,12 @@ namespace mbts.spark {
|
||||
|
||||
public struct WindowSpecifics {
|
||||
public readonly double order_entry_panel_width, zoom_factor;
|
||||
public readonly uint orders_column_width, bid_column_width, price_column_width, ask_column_width, last_column_width, volume_column_width;
|
||||
public readonly uint orders_column_width, bid_column_width, price_column_width, ask_column_width, last_column_width, volume_column_width, piq_column_width;
|
||||
|
||||
public WindowSpecifics(LadderSettings s)
|
||||
: this(s.order_entry_panel_initial_width, s.orders_column.width, s.bid_column.width, s.price_column.width, s.ask_column.width, s.last_column.width, s.volume_column.general.width, s.zoom_factor) { }
|
||||
: this(s.order_entry_panel_initial_width, s.orders_column.width, s.bid_column.width, s.price_column.width, s.ask_column.width, s.last_column.width, s.volume_column.general.width, s.zoom_factor, s.piq_column.width) { }
|
||||
|
||||
public WindowSpecifics(double order_entry_panel_width, uint orders_column_width, uint bid_column_width, uint price_column_width, uint ask_column_width, uint last_column_width, uint volume_column_width, double zoom_factor) {
|
||||
public WindowSpecifics(double order_entry_panel_width, uint orders_column_width, uint bid_column_width, uint price_column_width, uint ask_column_width, uint last_column_width, uint volume_column_width, double zoom_factor, uint piq_column_width) {
|
||||
this.order_entry_panel_width = order_entry_panel_width;
|
||||
this.orders_column_width = orders_column_width;
|
||||
this.bid_column_width = bid_column_width;
|
||||
@@ -533,6 +553,7 @@ namespace mbts.spark {
|
||||
this.last_column_width = last_column_width;
|
||||
this.volume_column_width = volume_column_width;
|
||||
this.zoom_factor = zoom_factor;
|
||||
this.piq_column_width = piq_column_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,6 +566,7 @@ namespace mbts.spark {
|
||||
yield return settings.ask_column;
|
||||
yield return settings.volume_column.general;
|
||||
yield return settings.last_column;
|
||||
yield return settings.piq_column;
|
||||
}
|
||||
|
||||
public static IEnumerable<LadderColumnSettings> visible_columns(this LadderSettings settings) =>
|
||||
@@ -562,6 +584,7 @@ namespace mbts.spark {
|
||||
source.price_column.width = specifics.price_column_width;
|
||||
source.ask_column.width = specifics.ask_column_width;
|
||||
source.last_column.width = specifics.last_column_width;
|
||||
source.piq_column.width = specifics.piq_column_width;
|
||||
source.volume_column.general.width = specifics.volume_column_width;
|
||||
source.zoom_factor = specifics.zoom_factor;
|
||||
return source;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace mbts.spark {
|
||||
}
|
||||
#endregion
|
||||
|
||||
readonly LadderVM _parent;
|
||||
readonly LadderVM _owner;
|
||||
readonly IBus _bus;
|
||||
readonly Property<FontFamily> _font_family;
|
||||
readonly Property<FontWeight> _font_weight;
|
||||
@@ -37,32 +37,30 @@ namespace mbts.spark {
|
||||
readonly Property<Brush> _foreground, _background, _hoverbackground, _border;
|
||||
readonly Property<bool> _has_multiple_orders_at_same_level, _is_hedge_order;
|
||||
readonly Property<CustomOrderDefinition.CustomOneofCase> _algo_type;
|
||||
readonly Property<string> _summary;
|
||||
IObservable<LadderSettings.BadgeStyle> _bs;
|
||||
LadderSettings.BadgeStyle _current_badge_style;
|
||||
int _n_active_price_change_ops = 0;
|
||||
double _real_price = double.NaN, _phantom_price = double.NaN;
|
||||
uint filled, quantity;
|
||||
uint filled, quantity, num_root_orders;
|
||||
int working_quantity;
|
||||
|
||||
LadderModel model => _parent.model;
|
||||
Dictionary<uint, OrderRecordImmutable> _orders = new Dictionary<uint, OrderRecordImmutable>();
|
||||
LadderModel model => _owner.model;
|
||||
Dictionary<uint, (OrderRecordImmutable order, uint? p)> _orders = new Dictionary<uint, (OrderRecordImmutable order, uint? p)>();
|
||||
|
||||
public LadderOrderVM(OrderRecordImmutable o, double real_price, LadderVM parent, IBus bus, IObservable<LadderSettings.BadgeStyle> bs) {
|
||||
_parent = parent;
|
||||
public LadderOrderVM((OrderRecordImmutable, uint?) op, double real_price, LadderVM owner, IBus bus, IObservable<LadderSettings.BadgeStyle> bs) {
|
||||
_owner = owner;
|
||||
_bus = bus;
|
||||
_bs = bs;
|
||||
_real_price = real_price;
|
||||
// settings
|
||||
var fs = UserSettings.factory_defaults.ladder;
|
||||
_font_family = backing(nameof(font_family), parent.settings, get_font_family, get_font_family(fs));
|
||||
_font_weight = backing(nameof(font_weight), parent.settings, get_font_weight, get_font_weight(fs));
|
||||
_font_size = backing(nameof(font_size), parent.settings, get_font_size, get_font_size(fs));
|
||||
_foreground = backing(nameof(foreground), parent.settings, get_foreground, get_foreground(fs));
|
||||
_font_family = backing(nameof(font_family), owner.settings, get_font_family, get_font_family(fs));
|
||||
_font_weight = backing(nameof(font_weight), owner.settings, get_font_weight, get_font_weight(fs));
|
||||
_font_size = backing(nameof(font_size), owner.settings, get_font_size, get_font_size(fs));
|
||||
_foreground = backing(nameof(foreground), owner.settings, get_foreground, get_foreground(fs));
|
||||
_background = backing(nameof(background), _color_bg_brush);
|
||||
_hoverbackground = backing(nameof(hoverbackground), _color_bg_brush);
|
||||
_border = backing(nameof(border), _color_bg_brush);
|
||||
_summary = backing(nameof(summary), string.Empty);
|
||||
_has_multiple_orders_at_same_level = backing(nameof(has_multiple_orders_at_same_level), false);
|
||||
_is_hedge_order = backing(nameof(is_hedge_order), false);
|
||||
_algo_type = backing(nameof(algo_type), CustomOrderDefinition.CustomOneofCase.None);
|
||||
@@ -71,7 +69,7 @@ namespace mbts.spark {
|
||||
double get_font_size(LadderSettings s) => s.orders_column.font_size;
|
||||
Brush get_foreground(LadderSettings s) => s.orders_column.foreground.rgb_brush();
|
||||
//
|
||||
add_order(o);
|
||||
add_order(op);
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
_bs.Subscribe(badge => {
|
||||
@@ -98,10 +96,10 @@ namespace mbts.spark {
|
||||
background = buy_sell_background_fill_color;
|
||||
hoverbackground = mkbrush(dark, _darkbg, 0);
|
||||
|
||||
filled = 0;
|
||||
filled = quantity = num_root_orders = 0;
|
||||
working_quantity = 0;
|
||||
quantity = 0;
|
||||
foreach(var n in _root_nodes()) {
|
||||
num_root_orders++;
|
||||
filled += n.filled();
|
||||
working_quantity += n.working_quantity();
|
||||
quantity += n.quantity();
|
||||
@@ -109,9 +107,9 @@ namespace mbts.spark {
|
||||
|
||||
// if this badge only represents a single order, then is_exchange_order and the border (= algo color)
|
||||
// should be set appropriately
|
||||
if (_orders.Count == 1) {
|
||||
var single_order = _orders.Values.First();
|
||||
var single_order_metadata = _parent.model.order_gateway.factory.get_metadata(single_order);
|
||||
if (num_root_orders == 1) {
|
||||
var single_order = _root_nodes().First();
|
||||
var single_order_metadata = _owner.model.order_gateway.factory.get_metadata(single_order);
|
||||
border = single_order_metadata.Color.rgb_brush();
|
||||
if (single_order.order_type().is_bts_algo_type()) {
|
||||
algo_type = single_order.order_type();
|
||||
@@ -122,13 +120,9 @@ namespace mbts.spark {
|
||||
} else {
|
||||
border = new SolidColorBrush(color);
|
||||
}
|
||||
has_multiple_orders_at_same_level = _orders.Count > 1;
|
||||
is_hedge_order = _orders.Any(o => o.Value.sub_type() == OrderSubType.HedgingLeg);
|
||||
has_multiple_orders_at_same_level = num_root_orders > 1;
|
||||
is_hedge_order = _root_nodes().Any(o => o.sub_type() == OrderSubType.HedgingLeg);
|
||||
|
||||
if (_orders.Any()) {
|
||||
// This is only used in log messages vs the no-longer-existing badge popup, so simplify string
|
||||
summary = $"Badge containing orders: {string.Join(",", _orders.Keys)}";
|
||||
}
|
||||
_set_badge_text();
|
||||
|
||||
}
|
||||
@@ -138,8 +132,8 @@ namespace mbts.spark {
|
||||
RaisePropertyChanged(nameof(text_lines));
|
||||
}
|
||||
|
||||
public void add_order(OrderRecordImmutable new_order) {
|
||||
_orders[new_order.Key] = new_order;
|
||||
public void add_order((OrderRecordImmutable order, uint? p) new_op) {
|
||||
_orders[new_op.order.Key] = new_op;
|
||||
}
|
||||
|
||||
public void remove_order(uint order_key) {
|
||||
@@ -153,12 +147,13 @@ namespace mbts.spark {
|
||||
// }
|
||||
//}
|
||||
|
||||
public uint security_key => _parent.security.Id;
|
||||
public uint security_key => _owner.security.Id;
|
||||
public double price { get => double.IsNaN(_phantom_price) ? _real_price : _phantom_price; }
|
||||
public uint? min_piq => _orders.Select(op => op.Value.p).Where(piq => piq.HasValue).Min();
|
||||
public double real_price => _real_price;
|
||||
public Side side {
|
||||
get {
|
||||
var distinct_sides = _orders.Values.Select(o => o.side()).Distinct();
|
||||
var distinct_sides = _root_nodes().Select(o => o.side()).Distinct();
|
||||
if (distinct_sides.Count() > 1) {
|
||||
return Side.Undefined;
|
||||
}
|
||||
@@ -166,16 +161,14 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<OrderRecordImmutable> _root_nodes() => _orders.Values.Select(_parent.get_root_at_price).DistinctOn(OrderUtils.RecordKeySelector);
|
||||
IEnumerable<OrderRecordImmutable> _root_nodes() => _orders.Values.Select(_owner.get_root_at_price).DistinctOn(OrderUtils.RecordKeySelector);
|
||||
|
||||
public IReadOnlyList<string> text_lines { get; private set; }
|
||||
|
||||
public bool has_parent => _orders.Values.Any( order => order.has_parent());
|
||||
public bool has_phantom_price => !double.IsNaN(_phantom_price);
|
||||
|
||||
public ICommand detach_command => new DelegateCommand(() => _execute_command(_detach_order), () => !has_parent);
|
||||
public ICommand cancel_command => new DelegateCommand(() => _execute_command(_cancel_order));
|
||||
//public ICommand modify_command => new DelegateCommand(() => _execute_command(() => _bus.post(SparkTags.ShowModifyOrderTag, _order.Key)), () => !has_parent);
|
||||
|
||||
public event Action command_executed;
|
||||
void _execute_command(Action action) {
|
||||
action();
|
||||
@@ -189,24 +182,20 @@ namespace mbts.spark {
|
||||
public Brush background { get => _background.Value; private set => _background.Value = value; }
|
||||
public Brush hoverbackground { get => _hoverbackground.Value; private set => _hoverbackground.Value = value; }
|
||||
public Brush border { get => _border.Value; private set => _border.Value = value; }
|
||||
public string summary { get => _summary.Value; private set => _summary.Value = value; }
|
||||
public string summary => _root_nodes().Any() ? $"Badge containing root orders: {string.Join(",", _root_nodes().Select(o => o.Key))}" : string.Empty;
|
||||
public bool has_multiple_orders_at_same_level { get => _has_multiple_orders_at_same_level.Value; private set => _has_multiple_orders_at_same_level.Value = value; }
|
||||
public bool is_hedge_order { get => _is_hedge_order.Value; private set => _is_hedge_order.Value = value; }
|
||||
public CustomOrderDefinition.CustomOneofCase algo_type { get => _algo_type.Value; private set => _algo_type.Value = value; }
|
||||
|
||||
public IEnumerable<OrderRecordImmutable> orders => _orders.Values;
|
||||
public IReadOnlyList<uint> order_keys => _orders.Keys.ToReadOnlyList();
|
||||
public IEnumerable<OrderRecordImmutable> root_orders => _root_nodes();
|
||||
|
||||
void _cancel_order() {
|
||||
foreach (var order in _orders.Values) {
|
||||
foreach (var order in _root_nodes()) {
|
||||
model.order_gateway.cancel_order(order).ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void _detach_order() {
|
||||
var distinct_parent_keys = _orders.Values.Where(o => o.has_parent()).Select(x => x.ParentKey).Distinct();
|
||||
model.order_gateway.detach_orders(distinct_parent_keys).ignore();
|
||||
}
|
||||
|
||||
public async void try_set_price(OrderRecordImmutable order, double new_price) {
|
||||
// don't change stop or stop_limits => server crash
|
||||
if (order.order_type() == bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Stop || order.order_type() == bts.api.orderman.CustomOrderDefinition.CustomOneofCase.StopLimit) return;
|
||||
@@ -214,7 +203,7 @@ namespace mbts.spark {
|
||||
_phantom_price = new_price;
|
||||
RaisePropertyChanged(nameof(price));
|
||||
++_n_active_price_change_ops;
|
||||
if (await _parent.model.order_gateway.update_order(order, new_price, order.State.Quantity)) {
|
||||
if (await _owner.model.order_gateway.update_order(order, new_price, order.State.Quantity)) {
|
||||
// wait 3 secs, then give up if price change still hasn't taken effect
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
@@ -236,10 +225,10 @@ namespace mbts.spark {
|
||||
price_filter.minimum.value = real_price;
|
||||
price_filter.maximum.value = real_price;
|
||||
|
||||
var obvm = new OrderBookVM(null, _parent.bus, null, _parent.model.order_gateway, null, true);
|
||||
var obvm = new OrderBookVM(null, _owner.bus, null, _owner.model.order_gateway, null, true);
|
||||
var state = new bts.shell.orderbook.OrderBookStartupData(
|
||||
new bts.shell.orderbook.FilterStates {
|
||||
security_criteria = new SecurityCriteria(_parent.security),
|
||||
security_criteria = new SecurityCriteria(_owner.security),
|
||||
price = price_filter,
|
||||
statuses = new[] { OrderStatus.Working }
|
||||
},
|
||||
@@ -285,7 +274,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return $"Price: {this.price} Order Count: {this.orders.Count()}";
|
||||
return $"Price: {price} Order Count: {_orders.Values.Count()} Root Order Count: {_root_nodes().Count()} PIQ: {(this.min_piq.HasValue ? this.min_piq.Value.ToString() : "")}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ namespace mbts.spark {
|
||||
_bid = new LadderColumnSettingsVM("Bid"),
|
||||
_price = new LadderColumnSettingsVM("Price"),
|
||||
_ask = new LadderColumnSettingsVM("Ask"),
|
||||
_last = new LadderColumnSettingsVM("Last", true);
|
||||
_last = new LadderColumnSettingsVM("Last", true),
|
||||
_piq = new LadderColumnSettingsVM("PIQ", true);
|
||||
VolumeColumnVM _volume = new VolumeColumnVM();
|
||||
LadderMarketBreakLineVM
|
||||
_bid_mkt_line = new LadderMarketBreakLineVM("Bid"),
|
||||
@@ -83,6 +84,7 @@ namespace mbts.spark {
|
||||
_price.font_size_changed += on_font_size_changed;
|
||||
_ask.font_size_changed += on_font_size_changed;
|
||||
_last.font_size_changed += on_font_size_changed;
|
||||
_piq.font_size_changed += on_font_size_changed;
|
||||
|
||||
void on_font_size_changed(double oldval, double newval) => _row_height.refresh();
|
||||
}
|
||||
@@ -121,6 +123,7 @@ namespace mbts.spark {
|
||||
if (!is_synthetic) {
|
||||
yield return _volume.general;
|
||||
yield return _last;
|
||||
yield return _piq;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +134,7 @@ namespace mbts.spark {
|
||||
public LadderColumnSettingsVM ask_column => _ask;
|
||||
public LadderColumnSettingsVM volume_column => _volume.general;
|
||||
public LadderColumnSettingsVM last_column => _last;
|
||||
public LadderColumnSettingsVM piq_column => _piq;
|
||||
public VolumeColumnVM volume => _volume;
|
||||
public LadderMarketBreakLineVM session_range_fill => _session_range_fill;
|
||||
public ObservableEditableCollection<IMutableValueWrapperVM<uint>> size_presets { get; }
|
||||
@@ -195,7 +199,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
|
||||
public string key => GridOrLadderSettingsSelectorKeys.Ladder;
|
||||
public string key => GridSettingsTemplateKeys.Ladder;
|
||||
|
||||
public void load(LadderSettings settings) {
|
||||
_current = settings;
|
||||
@@ -210,6 +214,7 @@ namespace mbts.spark {
|
||||
_price.assign_from(_current.price_column);
|
||||
_volume.assign_from(_current.volume_column);
|
||||
_last.assign_from(_current.last_column);
|
||||
_piq.assign_from(_current.piq_column);
|
||||
_bid_mkt_line.assign_from(_current.bid_break_line);
|
||||
_ask_mkt_line.assign_from(_current.ask_break_line);
|
||||
_mid_mkt_line.assign_from(_current.mid_break_line);
|
||||
@@ -255,6 +260,7 @@ namespace mbts.spark {
|
||||
clone.ask_column = _ask.get_settings();
|
||||
clone.volume_column = _volume.get_settings();
|
||||
clone.last_column = _last.get_settings();
|
||||
clone.piq_column = _piq.get_settings();
|
||||
clone.bid_break_line = _bid_mkt_line.get_settings();
|
||||
clone.ask_break_line = _ask_mkt_line.get_settings();
|
||||
clone.mid_break_line = _mid_mkt_line.get_settings();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace mbts.spark {
|
||||
readonly LadderModel _model;
|
||||
readonly Property<double> _high, _low, _change, _open, _settlement, _position, _left_panel_width, _zoom_factor;
|
||||
//readonly Property<double> _window_width, _window_height;
|
||||
readonly Property<uint> _orders_column_width, _bid_column_width, _price_column_width, _ask_column_width, _last_column_width, _volume_column_width;
|
||||
readonly Property<uint> _orders_column_width, _bid_column_width, _price_column_width, _ask_column_width, _last_column_width, _volume_column_width, _piq_column_width;
|
||||
readonly Property<ulong> _volume;
|
||||
readonly Property<bool> _auto_clear, _show_day, _show_high, _show_low, _show_open, _show_settle, _show_volume, _show_account,
|
||||
_show_tif, _show_order_type, _show_account_position, _show_size_preset, _show_auto_clear, _show_clear, _show_cancel_buys,
|
||||
@@ -38,7 +38,7 @@ namespace mbts.spark {
|
||||
ulong _last_trade_time = 0;
|
||||
IEqualityComparer<double> _equality;
|
||||
Dictionary<double, LadderOrderVM> _slot_price_vs_orders;
|
||||
IReadOnlyDictionary<uint, OrderRecordImmutable> _cache = DictionaryHelper.empty<uint, OrderRecordImmutable>();
|
||||
IReadOnlyDictionary<uint, OrderSecurity> _cache = DictionaryHelper.empty<uint, OrderSecurity>();
|
||||
|
||||
public static LadderVM create(IBus bus, LadderModel model, IWindowSettingsManager<LadderSettings> settings_manager, LadderSettings init) {
|
||||
var non_shared_wsm = settings_manager.as_non_shared();
|
||||
@@ -72,6 +72,7 @@ namespace mbts.spark {
|
||||
_price_column_width = backing(nameof(price_column_width), ws.price_column_width);
|
||||
_ask_column_width = backing(nameof(ask_column_width), ws.ask_column_width);
|
||||
_last_column_width = backing(nameof(last_column_width), ws.last_column_width);
|
||||
_piq_column_width = backing(nameof(piq_column_width), ws.piq_column_width);
|
||||
_volume_column_width = backing(nameof(volume_column_width), ws.volume_column_width);
|
||||
_left_panel_width = backing(nameof(left_panel_width), ws.order_entry_panel_width);
|
||||
_zoom_factor = backing(nameof(zoom_factor), ws.zoom_factor);
|
||||
@@ -144,13 +145,13 @@ namespace mbts.spark {
|
||||
account_positions,
|
||||
size_calculator = new CalculatorLogic(0, _settings_manager.subscribe_current().Select(s => s.calculator_buttons)),
|
||||
bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update),
|
||||
model.orders.OnDispatcher().Subscribe(working => {
|
||||
model.order_gateway.working_orders_with_piq.OnDispatcher().Subscribe(working => {
|
||||
// Here we manage N orders to 1 price slot in the ladder
|
||||
Dictionary<double, HashSet<uint>> orders_used_in_this_update = new Dictionary<double, HashSet<uint>>(_equality);
|
||||
_cache = working.state;
|
||||
_cache = working;
|
||||
|
||||
|
||||
foreach (var wo in _cache.Values) {
|
||||
foreach (var os in _cache.Values) {
|
||||
var wo = os.order;
|
||||
var slot_price_target = wo.price();
|
||||
var order_type = wo.order_type();
|
||||
var filled = wo.filled();
|
||||
@@ -164,9 +165,9 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
if (_slot_price_vs_orders.TryGetValue(slot_price_target, out LadderOrderVM slot_vm)) {
|
||||
slot_vm.add_order(wo);
|
||||
slot_vm.add_order((wo, os.piq));
|
||||
} else {
|
||||
slot_vm = new LadderOrderVM(wo, slot_price_target, this, _bus, _settings_manager.subscribe_current().Select(s => s.badge_style));
|
||||
slot_vm = new LadderOrderVM((wo, os.piq), slot_price_target, this, _bus, _settings_manager.subscribe_current().Select(s => s.badge_style));
|
||||
_slot_price_vs_orders[slot_price_target] = slot_vm;
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ namespace mbts.spark {
|
||||
// remove any orders from the lovm that aren't in here
|
||||
foreach(var kvp in orders_used_in_this_update) {
|
||||
var slot_vm = _slot_price_vs_orders[kvp.Key];
|
||||
foreach(var existing_order_key in slot_vm.orders.Select(o => o.Key).ToList()) {
|
||||
foreach(var existing_order_key in slot_vm.order_keys) {
|
||||
if (!kvp.Value.Contains(existing_order_key)) {
|
||||
slot_vm.remove_order(existing_order_key);
|
||||
}
|
||||
@@ -227,6 +228,10 @@ namespace mbts.spark {
|
||||
public event Action on_tick;
|
||||
|
||||
public MDConsumerHandle md => _model.md;
|
||||
// we return only entries who have piqs and whose piqs are not uint.Max
|
||||
// uint.Max happens when the server is restarted but the client is still up
|
||||
// maybe long term we don't show this data while the exchange connection is down
|
||||
public IEnumerable<(double, uint)> price_vs_piq => _slot_price_vs_orders.Values.Where(result => result.min_piq.HasValue && result.min_piq.Value != uint.MaxValue).Select(o => (o.price, o.min_piq.Value));
|
||||
public bool is_synthetic => _model.security.ContractCase == Security.ContractOneofCase.Synthetic;
|
||||
|
||||
Property<string> _status;
|
||||
@@ -302,10 +307,12 @@ namespace mbts.spark {
|
||||
public uint price_column_width { get => _price_column_width.Value; set => _price_column_width.set(value); }
|
||||
public uint ask_column_width { get => _ask_column_width.Value; set => _ask_column_width.set(value); }
|
||||
public uint last_column_width { get => _last_column_width.Value; set => _last_column_width.set(value); }
|
||||
public uint piq_column_width { get => _piq_column_width.Value; set => _piq_column_width.set(value); }
|
||||
public uint volume_column_width { get => _volume_column_width.Value; set => _volume_column_width.set(value); }
|
||||
internal LadderModel model => _model;
|
||||
internal IObservable<LadderSettings> settings => _settings_manager.subscribe_current();
|
||||
internal OrderRecordImmutable get_root_at_price(OrderRecordImmutable order) {
|
||||
internal OrderRecordImmutable get_root_at_price((OrderRecordImmutable order, uint? _) op) {
|
||||
var order = op.order;
|
||||
double p = order.price();
|
||||
foreach (var o in lineage(order.ParentKey)) {
|
||||
if (_equality.Equals(p, o.price()))
|
||||
@@ -315,15 +322,15 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
internal IEnumerable<OrderRecordImmutable> lineage(uint key) {
|
||||
while (key != 0 && _cache.TryGetValue(key, out var order)) {
|
||||
yield return order;
|
||||
key = order.ParentKey;
|
||||
while (key != 0 && _cache.TryGetValue(key, out var op)) {
|
||||
yield return op.order;
|
||||
key = op.order.ParentKey;
|
||||
}
|
||||
}
|
||||
|
||||
public LadderSettings get_save_state() {
|
||||
var state = _settings_manager.current_settings();
|
||||
state = state.with_window_specifics(new LadderSettings.WindowSpecifics(left_panel_width, orders_column_width, bid_column_width, price_column_width, ask_column_width, last_column_width, volume_column_width, zoom_factor));
|
||||
state = state.with_window_specifics(new LadderSettings.WindowSpecifics(left_panel_width, orders_column_width, bid_column_width, price_column_width, ask_column_width, last_column_width, volume_column_width, zoom_factor, piq_column_width));
|
||||
state.use_defaults = _settings_manager.instance_settings == null;
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace mbts.spark {
|
||||
_ask_vis_tup = new VisualGlyphTuple(),
|
||||
_price_vis_tup = new VisualGlyphTuple(),
|
||||
_last_vis_tup = new VisualGlyphTuple(),
|
||||
_volume_vis_tup = new VisualGlyphTuple();
|
||||
_volume_vis_tup = new VisualGlyphTuple(),
|
||||
_piq_vis_tup = new VisualGlyphTuple();
|
||||
|
||||
readonly RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>> _volume_container =
|
||||
new RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>>();
|
||||
@@ -94,11 +95,11 @@ namespace mbts.spark {
|
||||
};
|
||||
}
|
||||
|
||||
public enum ColumnType { Order, Bid, Price, Ask, Last, Volume, None }
|
||||
public enum ColumnType { Order, Bid, Price, Ask, Last, Volume, None, PIQ }
|
||||
|
||||
public event Action visible_columns_changed;
|
||||
|
||||
public IEnumerable<ColumnType> visible_columns =>
|
||||
public IEnumerable<ColumnType> visible_column_types =>
|
||||
columns.Where(c => c.settings.show)
|
||||
.Select(c => c.column_type);
|
||||
|
||||
@@ -194,6 +195,19 @@ namespace mbts.spark {
|
||||
set => SetValue(LastColumnWidthProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PIQColumnWidthProperty =
|
||||
WPFHelper.create_dp<uint, LadderGridHost>(
|
||||
nameof(PIQColumnWidth),
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, oldval, newval) => o._adjust_column_width(o.columns.FirstOrDefault(c => c.column_type == ColumnType.PIQ), (double)newval - (double)oldval),
|
||||
50u);
|
||||
|
||||
public uint PIQColumnWidth {
|
||||
get => (uint)GetValue(PIQColumnWidthProperty);
|
||||
set => SetValue(PIQColumnWidthProperty, value);
|
||||
}
|
||||
|
||||
|
||||
#region CanUserSendOrders
|
||||
public static readonly DependencyProperty CanUserSendOrdersProperty =
|
||||
DependencyProperty.Register(
|
||||
@@ -261,6 +275,7 @@ namespace mbts.spark {
|
||||
#endregion
|
||||
|
||||
Column[] columns { get; set; } = new Column[0];
|
||||
IEnumerable<Column> _visible_columns => columns.Where(c => c.settings.show);
|
||||
|
||||
public void drag_out_of_bounds() =>
|
||||
_tactile_adorner?.drag_out_of_bounds();
|
||||
@@ -358,7 +373,7 @@ namespace mbts.spark {
|
||||
|
||||
#region Column Utility Methods
|
||||
Column _column_for_point(Point point) =>
|
||||
columns.FirstOrDefault(c => c.x_right > point.X, columns.Length > 0 ? columns[columns.Length - 1] : Column.Empty);
|
||||
_visible_columns.FirstOrDefault(c => c.x_right > point.X, columns.Length > 0 ? columns[columns.Length - 1] : Column.Empty);
|
||||
|
||||
double _column_start(ColumnType col_type) =>
|
||||
columns.TakeWhile(c => c.column_type != col_type).Sum(c => c.settings.width);
|
||||
@@ -445,7 +460,8 @@ namespace mbts.spark {
|
||||
double x = 0;
|
||||
var col_list = new List<Column> {
|
||||
new Column(_settings.orders_column, ColumnType.Order, null, x),
|
||||
new Column(_settings.bid_column, ColumnType.Bid, _bid_vis_tup, (x += _settings.orders_column.show ? _settings.orders_column.width : 0)),
|
||||
new Column(_settings.piq_column, ColumnType.PIQ, _piq_vis_tup, (x += _settings.orders_column.show ? _settings.orders_column.width : 0)),
|
||||
new Column(_settings.bid_column, ColumnType.Bid, _bid_vis_tup, (x += _settings.piq_column.show ? _settings.piq_column.width : 0)),
|
||||
(_price_column = new Column(_settings.price_column, ColumnType.Price, _price_vis_tup, (x += _settings.bid_column.show ? _settings.bid_column.width : 0))),
|
||||
new Column(_settings.ask_column, ColumnType.Ask, _ask_vis_tup, (x += _settings.price_column.show ? _settings.price_column.width : 0))
|
||||
};
|
||||
@@ -564,6 +580,8 @@ namespace mbts.spark {
|
||||
if (depth_changed)
|
||||
_refresh_sizes();
|
||||
}
|
||||
// TODO - detect changes in PIQ to selectively redraw
|
||||
_refresh_piq();
|
||||
_refresh_volume_at_price();
|
||||
_last_origin_price = _mkt_break_lines.origin;
|
||||
_price_dirty = false;
|
||||
@@ -600,6 +618,14 @@ namespace mbts.spark {
|
||||
LadderRender.render_last(_last_vis_tup.visual, _last_vis_tup.glyph_context, _last_trade, last_index, _settings.row_height, _settings.last_column);
|
||||
}
|
||||
|
||||
void _refresh_piq() {
|
||||
if (!_settings.piq_column.show)
|
||||
return;
|
||||
int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer);
|
||||
var piq_list = _vm.price_vs_piq;
|
||||
LadderRender.render_piqs(_piq_vis_tup.visual, _last_vis_tup.glyph_context, origin_index, _price_list, piq_list.ToArray(), _settings.row_height, security.ContractSpec, _settings.piq_column);
|
||||
}
|
||||
|
||||
void _refresh_sizes() {
|
||||
Log.assert_d(_price_list != null);
|
||||
int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer);
|
||||
@@ -768,6 +794,7 @@ namespace mbts.spark {
|
||||
_ask_vis_tup.glyph_context = glyph_context(s.ask_column);
|
||||
_price_vis_tup.glyph_context = glyph_context(s.price_column);
|
||||
_last_vis_tup.glyph_context = glyph_context(s.last_column);
|
||||
_piq_vis_tup.glyph_context = glyph_context(s.piq_column);
|
||||
_volume_vis_tup.glyph_context = glyph_context(s.volume_column.general);
|
||||
|
||||
GlyphContext glyph_context(LadderColumnSettings cs) =>
|
||||
@@ -795,6 +822,7 @@ namespace mbts.spark {
|
||||
case ColumnType.Price: SetCurrentValue(price_column_widthProperty, col.settings.width); break;
|
||||
case ColumnType.Ask: SetCurrentValue(ask_column_widthProperty, col.settings.width); break;
|
||||
case ColumnType.Last: SetCurrentValue(LastColumnWidthProperty, col.settings.width); break;
|
||||
case ColumnType.PIQ: SetCurrentValue(PIQColumnWidthProperty, col.settings.width); break;
|
||||
case ColumnType.Volume:
|
||||
SetCurrentValue(VolumeColumnWidthProperty, col.settings.width);
|
||||
_volume_container.mark_dirty();
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace mbts.spark {
|
||||
Log.Ui.info("Drop - " + vm.summary);
|
||||
double price = _parent.price_for_point(e.GetPosition(_parent));
|
||||
if (price != vm.price) {
|
||||
foreach (var order in vm.orders) {
|
||||
foreach (var order in vm.root_orders) {
|
||||
vm.try_set_price(order, price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +287,30 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
// this is basically a copy of redner_sizes up above
|
||||
internal static void render_piqs(DrawingVisual dv, GlyphContext glyph_context, int origin_index, double[] prices, (double price, uint piq)[] piqs, double row_height, ContractSpecificationImmutable spec, LadderColumnSettings settings) {
|
||||
using (var dc = dv.RenderOpen()) {
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Length)) {
|
||||
if (!prices.within_range(origin_index) || piqs.is_null_or_empty())
|
||||
return;
|
||||
var foreground = settings.foreground.rgb_brush();
|
||||
int curr_index = origin_index;
|
||||
double curr_price = prices[curr_index];
|
||||
for (int i = 0; i < piqs.Length; i++) {
|
||||
double price = piqs[i].price;
|
||||
// prices are in descending order, so get diff from curr_price - price
|
||||
int tick_diff = spec.tickdiff_unchecked(curr_price, price);
|
||||
curr_index += tick_diff;
|
||||
curr_price = price;
|
||||
if (curr_index >= 0 && curr_index < prices.Length) {
|
||||
var gr = format_text(piqs[i].piq.ToString(), curr_index, row_height, settings, glyph_context);
|
||||
dc.DrawGlyphRun(foreground, gr);
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void render_mkt_break(DrawingVisual dv, int index, double row_height, uint color) =>
|
||||
render_single_grid_line(dv, index, row_height, color, 0, SystemParameters.FullPrimaryScreenWidth);
|
||||
|
||||
|
||||
@@ -541,6 +541,7 @@
|
||||
price_column_width="{Binding price_column_width, Mode=TwoWay}"
|
||||
ask_column_width="{Binding ask_column_width, Mode=TwoWay}"
|
||||
LastColumnWidth="{Binding last_column_width, Mode=TwoWay}"
|
||||
PIQColumnWidth="{Binding piq_column_width, Mode=TwoWay}"
|
||||
VolumeColumnWidth="{Binding volume_column_width, Mode=TwoWay}"
|
||||
>
|
||||
<spark:LadderGridHost.Resources>
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace mbts.spark {
|
||||
InitializeComponent();
|
||||
_column_headers_presenter.Columns = new GridViewColumnCollection();
|
||||
_ladder.visible_columns_changed += () => _column_headers_presenter.Columns.SetItems(
|
||||
_ladder.visible_columns.Select(t => ColumnFactory.create(_ladder, t)));
|
||||
_ladder.visible_column_types.Select(t => ColumnFactory.create(_ladder, t)));
|
||||
this.vm = vm;
|
||||
DataContext = vm;
|
||||
DataContextChanged += datacontext_changed;
|
||||
@@ -140,6 +140,10 @@ namespace mbts.spark {
|
||||
header = "Last";
|
||||
width_prop = nameof(LadderVM.last_column_width);
|
||||
break;
|
||||
case LadderGridHost.ColumnType.PIQ:
|
||||
header = "PIQ";
|
||||
width_prop = nameof(LadderVM.piq_column_width);
|
||||
break;
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(type, nameof(type));
|
||||
}
|
||||
return _create(host, header, $"DataContext.{width_prop}");
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="{x:Static sp:MiniOrderBookView.RowStyleKey}" TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<!--
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
@@ -60,6 +61,7 @@
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
-->
|
||||
</Style>
|
||||
<DataTemplate x:Key="{x:Static sp:MiniOrderBookView.RowTemplateKey}">
|
||||
<sp:MiniOrderBookRowView/>
|
||||
|
||||
@@ -28,12 +28,6 @@ using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using _GridSettingsManager =
|
||||
mbts.ui.GridSettingsManager<
|
||||
mbts.spark.OrderBookRowVM,
|
||||
bts.api.orderman.OrderSecurity,
|
||||
mbts.OrderRecordTuplePredicate,
|
||||
bts.shell.orderbook.OrderBookGridSettings>;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
|
||||
namespace mbts.spark {
|
||||
@@ -68,6 +62,7 @@ namespace mbts.spark {
|
||||
HashSet<uint>
|
||||
_attachable_selected_orders = new HashSet<uint>(),
|
||||
_detachable_selected_orders = new HashSet<uint>();
|
||||
FilterData _cached_filter_data;
|
||||
|
||||
public OrderBookVM(IObservable<string> owner_title, IBus bus, INotificationService notification_service, OrdersModel model, IWindowSettingsManager<OrderBookGridSettings> settings_manager, bool rows_are_initially_expanded = false) {
|
||||
_bus = bus;
|
||||
@@ -139,7 +134,8 @@ namespace mbts.spark {
|
||||
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
}));
|
||||
grid_settings_manager = _create_grid_settings_manager(owner_title, bus, notification_service, model, rows, core_columns);
|
||||
grid_settings_manager = new OrderBookGridSettingsManager(owner_title, bus, notification_service, model, rows, columns);
|
||||
grid_settings_manager.algo_tree_display_mode_changed += _on_filter_changed;
|
||||
IDisposable attach_vm_hooks = null;
|
||||
begin_attaching += on_begin_attaching;
|
||||
end_attaching += on_end_attaching;
|
||||
@@ -164,9 +160,9 @@ namespace mbts.spark {
|
||||
security_plurality = p;
|
||||
RaisePropertyChanged(nameof(security_plurality));
|
||||
}),
|
||||
model.on_order_tuples.FilterWithRaw(subscribe_orders_filter(), o => o.order.Key, null).OnDispatcher().Subscribe(t => {
|
||||
_cached_orders = t.raw.state;
|
||||
_row_collection.update(t.filtered.added, t.filtered.changed, t.filtered.removed.Select(o => o.order.Key));
|
||||
model.on_order_tuples.OnDispatcher().Subscribe(t => {
|
||||
_cached_orders = t.state;
|
||||
_row_collection.update(t.added, t.changed, t.removed.Select(o => o.order.Key));
|
||||
}),
|
||||
model.on_orders_can_attach.OnDispatcher().Subscribe(table => {
|
||||
_cached_attachable = new MappedDictionary<uint, KeyValuePair<uint, bool>, bool>(table.state, kv => kv.Value);
|
||||
@@ -214,6 +210,7 @@ namespace mbts.spark {
|
||||
}),
|
||||
Disposable.Create(() => {
|
||||
_columns.filter_changed -= _on_filter_changed;
|
||||
grid_settings_manager.algo_tree_display_mode_changed -= _on_filter_changed;
|
||||
_row_collection.CollectionChanged -= _row_collection_CollectionChanged;
|
||||
begin_attaching -= on_begin_attaching;
|
||||
end_attaching -= on_end_attaching;
|
||||
@@ -232,12 +229,6 @@ namespace mbts.spark {
|
||||
o.OnNext(new Func<FillTuple, bool>(ft => keys.Contains(ft.fill.OrderKey)));
|
||||
}
|
||||
});
|
||||
IObservable<Func<OrderSecurityAlgoMeta, bool>> subscribe_orders_filter() =>
|
||||
Observable.Create<Func<OrderSecurityAlgoMeta, bool>>(o => {
|
||||
o.OnNext(_columns.create_filter_states().build_predicate());
|
||||
_filter_changed += o.OnNext;
|
||||
return Disposable.Create(() => _filter_changed -= o.OnNext);
|
||||
});
|
||||
|
||||
void on_all_selected_orders_active_changed(bool newval) {
|
||||
order_mod_vm.on_all_active_changed();
|
||||
@@ -252,11 +243,22 @@ namespace mbts.spark {
|
||||
is_attaching_orders = false;
|
||||
try {
|
||||
double price = attach_vm.price;
|
||||
uint size = attach_vm.size ?? 0;
|
||||
var algo = attach_vm.algo_vm.algo_root.created_assigned();
|
||||
var order_tups = selected_rows.Select(r => r.order_tuple);
|
||||
uint? algo_template_key = attach_vm.algo_vm.algo_root.id.is_persisted ? attach_vm.algo_vm.algo_root.id.persisted.id_uint : (uint?)null;
|
||||
await Task.WhenAll(order_tups.Select(t => _model.send_order(t.order.Def.with(attach_target_order_key: t.order.Key, custom_def: algo, algo_template_key: algo_template_key), price, size)));
|
||||
uint? size = attach_vm.size;
|
||||
uint algo_template_key = attach_vm.algo_vm.algo_root.id.is_persisted ? attach_vm.algo_vm.algo_root.id.persisted.id_uint : 0u;
|
||||
var order_tups = selected_rows.Select(r => r.order_tuple).ToList();
|
||||
var mod_algo_vm = attach_vm.algo_vm.algo_root;
|
||||
await Task.WhenAll(order_tups.Select(t => {
|
||||
var algo = t.order.Def.CustomDef.CloneToMutable();
|
||||
mod_algo_vm.assign_to(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
|
||||
),
|
||||
double.IsNaN(price) ? t.order.price() : price,
|
||||
size ?? t.order.quantity());
|
||||
}));
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Error sending attached orders: {ex}.");
|
||||
}
|
||||
@@ -266,6 +268,21 @@ namespace mbts.spark {
|
||||
Disposable.replace(ref attach_vm_hooks,
|
||||
Disposable.Create(
|
||||
connect_common_selected_params(attach_vm),
|
||||
_selected_params_mon.subscribe_algos().Subscribe(algos => {
|
||||
bool show_price, show_size;
|
||||
using (var en = algos.Select(a => a.CustomCase).Distinct().GetEnumerator()) {
|
||||
if (show_price = show_size = en.MoveNext()) {
|
||||
do {
|
||||
if (show_price) show_price = AttachConf.show_price(en.Current);
|
||||
if (show_size) show_size = AttachConf.show_size(en.Current);
|
||||
} while ((show_price || show_size) && en.MoveNext());
|
||||
}
|
||||
}
|
||||
attach_vm.price_permissions = bool_to_perm(show_price);
|
||||
attach_vm.size_permissions = bool_to_perm(show_size);
|
||||
AlgoParamPermissions bool_to_perm(bool b) =>
|
||||
b ? AlgoParamPermissions.ReadWrite : AlgoParamPermissions.None;
|
||||
}),
|
||||
// custom templates (created by user)
|
||||
_model.algo_model.definitions.OnDispatcher().Subscribe(u =>
|
||||
AlgoCollectionHelper.update_persisted_definition_wrappers(attach_vm.algo_vm.algo_roots as ObservableKeyedCollection<IAlgoVM, AlgoKey>, u, mk_factory(true)))));
|
||||
@@ -302,7 +319,6 @@ namespace mbts.spark {
|
||||
|
||||
public event Action<OrderRecordImmutable?> selected_order_changed;
|
||||
public event Action begin_attaching, end_attaching;
|
||||
event Action<Func<OrderSecurityAlgoMeta, bool>> _filter_changed;
|
||||
|
||||
public ObservableAppendCollection<DIYGrid.ColumnBase> columns { get; }
|
||||
public ObservableCollection<DIYGrid.ColumnBase> core_columns => _columns;
|
||||
@@ -328,7 +344,7 @@ namespace mbts.spark {
|
||||
public ObservableCollection<OrderBookRowVM> selected_rows { get; } = new ObservableCollection<OrderBookRowVM>();
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => selected_rows.Select(r => r.order);
|
||||
public IEnumerable<OrderBookRowVM> selected_hierarchical_rows => selected_rows.SelectMany(r => new[] { r }.Concat(_row_collection.get_descendent_rows(r.order_key)));
|
||||
public _GridSettingsManager grid_settings_manager { get; }
|
||||
public OrderBookGridSettingsManager grid_settings_manager { get; }
|
||||
public bool is_attaching_orders {
|
||||
get => _is_attaching_orders;
|
||||
set {
|
||||
@@ -427,15 +443,14 @@ namespace mbts.spark {
|
||||
|
||||
public OrderBookStartupData create() {
|
||||
var (filters, sorting) = _columns.create();
|
||||
var gs = grid_settings_manager.create();
|
||||
var gs = grid_settings_manager.create(sorting);
|
||||
var rv = new OrderBookStartupData(
|
||||
filters,
|
||||
gs.general.with(sorting_criterion: sorting),
|
||||
gs,
|
||||
_show_right_panel,
|
||||
_raw_right_panel_width,
|
||||
_fills_height,
|
||||
show_fills,
|
||||
gs.predicate_animations,
|
||||
use_defaults: _settings_manager.instance_settings == null) {
|
||||
order_params_height = order_params_height,
|
||||
show_ladder = show_ladder,
|
||||
@@ -476,16 +491,28 @@ namespace mbts.spark {
|
||||
(var old_filter, var old_sort) = _columns.create();
|
||||
// suspend column filter updates
|
||||
_columns.filter_changed -= _on_filter_changed;
|
||||
grid_settings_manager.algo_tree_display_mode_changed -= _on_filter_changed;
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
_columns.load_from((state.filters, (state.grid ?? OrderBookStartupData.Default.grid).sorting_criterion));
|
||||
_columns.load_from((state.filters, (state.orderbook_grid?.general ?? OrderBookStartupData.DefaultGrid.general).sorting_criterion));
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
// resume column filter updates
|
||||
_columns.filter_changed += _on_filter_changed;
|
||||
(var new_filter, var new_sort) = _columns.create();
|
||||
if (!new_sort.Equals(old_sort))
|
||||
_row_collection.comparer = _columns.get_sorting_data().comparer;
|
||||
if (!new_filter.Equals(old_filter))
|
||||
_on_filter_changed();
|
||||
grid_settings_manager.algo_tree_display_mode_changed += _on_filter_changed;
|
||||
var new_filter = new FilterData(grid_settings_manager.algo_tree_display_mode, _columns.create_filter_states());
|
||||
var new_sort = _columns.get_sorting_data();
|
||||
if (!new_filter.Equals(_cached_filter_data)) {
|
||||
_cached_filter_data = new_filter;
|
||||
if (!new_sort.Equals(old_sort)) {
|
||||
/// Both filter and sort have changed, use <see cref="OperableHierarchicalCollection{TRow, T, TKey}.defer_refresh"/> to avoid syncing twice.
|
||||
using (_row_collection.defer_refresh()) {
|
||||
_row_collection.filter = new_filter.build_predicate();
|
||||
_row_collection.comparer = new_sort.comparer;
|
||||
}
|
||||
} else {
|
||||
_row_collection.filter = new_filter.build_predicate();
|
||||
}
|
||||
} else if (!new_sort.Equals(old_sort))
|
||||
_row_collection.comparer = new_sort.comparer;
|
||||
}
|
||||
|
||||
public void on_sorting(object sender, DIYGridSortingEventArgs e) {
|
||||
@@ -535,22 +562,12 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
void _on_filter_changed() => _filter_changed?.Invoke(_columns.create_filter_states().build_predicate());
|
||||
|
||||
async Task _attach_orders(IReadOnlyList<OrderBookRowVM> rows, OrderBookRowVM target) {
|
||||
Log.Ui.info($"{nameof(OrderBookVM)} begin attaching orders ({rows.Count} total)...");
|
||||
try {
|
||||
await Task.WhenAll(rows.Select(r => _model.cancel_order(r.order_key)));
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Error canceling orders, in advance of attachment: {ex}.");
|
||||
void _on_filter_changed() {
|
||||
var fd = new FilterData(grid_settings_manager.algo_tree_display_mode, _columns.create_filter_states());
|
||||
if (!fd.Equals(_cached_filter_data)) {
|
||||
_cached_filter_data = fd;
|
||||
_row_collection.filter = fd.build_predicate();
|
||||
}
|
||||
Log.Ui.info($"{nameof(OrderBookVM)} succesfully canceled orders ({rows.Count} total), in advance of attachment. Begin sending attached orders ({rows.Count} total)...");
|
||||
try {
|
||||
await Task.WhenAll(rows.Select(r => _model.send_order(r.order.Def.with(attach_target_order_key: target.order_key), r.order.State.Price, (uint)r.order.working_quantity())));
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Error sending attached orders: {ex}.");
|
||||
}
|
||||
Log.Ui.info($"{nameof(OrderBookVM)} succesfully sent attached orders ({rows.Count} total).");
|
||||
}
|
||||
|
||||
async Task _detach_orders_async(IEnumerable<OrderBookRowVM> detach_candidates) =>
|
||||
@@ -599,40 +616,6 @@ namespace mbts.spark {
|
||||
general = fills_vm.grid_settings_manager.create()
|
||||
};
|
||||
|
||||
static _GridSettingsManager _create_grid_settings_manager(
|
||||
IObservable<string> owner_title, IBus bus, INotificationService notification_service, OrdersModel model, IReadOnlyObservableCollection<OrderBookRowVM> rows, ObservableCollection<DIYGrid.ColumnBase> columns) {
|
||||
// make font-weight immutable for all columns (the font-weight rule is hard-coded: Regular for root-orders, Light for all others)
|
||||
// TODO: Remove the immutable font-weight flags when cell animation is ready
|
||||
var col_settings_flags = EnumHelper.get_values<Columns>().ToDictionary(
|
||||
c => c.ToString(), c => GridColumnSettingsFeatureFlags.ImmutableFontWeight);
|
||||
// make font-color immutable for Side, Size, and Filled columns (the font-color rule is hard-coded: MarketData.bid for Buy orders, MarketData.ask for Sells)
|
||||
// TODO: Remove the immutable font-color flags when cell animation is ready
|
||||
foreach (var c in new[] { Columns.Side, Columns.Size, Columns.Filled }) {
|
||||
col_settings_flags[c.ToString()] = GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableFontWeight;
|
||||
}
|
||||
return new _GridSettingsManager(
|
||||
owner_title, bus, model, rows, columns,
|
||||
() => new OrderRecordTuplePredicate(),
|
||||
() => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = pvm.predicate_types.FirstOrDefault();
|
||||
return pvm;
|
||||
},
|
||||
col_id => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = _corresponding_predicate_type(EnumHelper.parse_or_default<Columns>(col_id));
|
||||
return pvm;
|
||||
},
|
||||
(gen, anims) => new OrderBookGridSettings(gen, anims.Select(a => new OrderRecordTuplePredicateAnimations(a.predicate_data, a.cell_animations, a.row_animations, a.sound_notifications))),
|
||||
p => p.create_predicate(notification_service.data_cache),
|
||||
p => p.create_notification_predicate(notification_service.data_cache),
|
||||
notification_service == null ? new Func<IPredicate<OrderSecurity>, SoundNotification, IDisposable>((p, sn) => Disposable.empty) : notification_service.link_to_order,
|
||||
notification_service == null ? new Func<INotificationPredicate<OrderSecurity>, IDisposable>(t => Disposable.empty) : notification_service.link_to_order,
|
||||
col_settings_flags);
|
||||
}
|
||||
|
||||
static OrderRecordTuplePredicate.PredicateTypeOneofCase _corresponding_predicate_type(Columns col) {
|
||||
switch (col) {
|
||||
case Columns.Security: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Security;
|
||||
@@ -713,6 +696,9 @@ namespace mbts.spark {
|
||||
IRaiseCanExecuteChangedCommand _payup_bid_cmd, _payup_ask_cmd;
|
||||
IAlgoParamVM<double> _price_param;
|
||||
IAlgoParamVM<uint?> _size_param;
|
||||
AlgoParamPermissions
|
||||
_price_permissions = AlgoParamPermissions.ReadOnly | AlgoParamPermissions.Write,
|
||||
_size_permissions = AlgoParamPermissions.ReadOnly | AlgoParamPermissions.Write;
|
||||
HashSet<uint> _selected_order_tree = new HashSet<uint>();
|
||||
LadderVM _ladder_vm;
|
||||
SecurityMD? _security_md;
|
||||
@@ -751,8 +737,12 @@ namespace mbts.spark {
|
||||
_price_param = null;
|
||||
_size_param = null;
|
||||
} else {
|
||||
_size_param = new AlgoParamVM<uint?>("size", "Size", owner._selected_params_mon.size) { permissions = _param_permissions };
|
||||
var price_param = new AlgoParamVM<double>("price", "Price", owner._selected_params_mon.price, spec?.tick_equality_comparer() ?? MathUtils.epsilon_comparer) { permissions = _param_permissions };
|
||||
_size_param = new AlgoParamVM<uint?>("size", "Size", owner._selected_params_mon.size) {
|
||||
permissions = _size_permissions & _param_permissions
|
||||
};
|
||||
var price_param = new AlgoParamVM<double>("price", "Price", owner._selected_params_mon.price, spec?.tick_equality_comparer() ?? MathUtils.epsilon_comparer) {
|
||||
permissions = _price_permissions & _param_permissions
|
||||
};
|
||||
_price_param = price_param;
|
||||
_price_param.value_changed += on_price_changed;
|
||||
void on_price_changed(double oldval, double newval) =>
|
||||
@@ -779,6 +769,14 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public bool is_dirty => _is_dirty.Value;
|
||||
public AlgoParamPermissions price_permissions {
|
||||
get => _price_permissions;
|
||||
set => _assign_param_permissions(_price_param, ref _price_permissions, value);
|
||||
}
|
||||
public AlgoParamPermissions size_permissions {
|
||||
get => _size_permissions;
|
||||
set => _assign_param_permissions(_size_param, ref _size_permissions, value);
|
||||
}
|
||||
|
||||
public ReadOnlyObservableCollection<AccountTuple> accounts => _accounts.items;
|
||||
public AccountTuple? selected_account { get => _accounts.selected_item; set => _accounts.selected_item = value; }
|
||||
@@ -857,6 +855,50 @@ namespace mbts.spark {
|
||||
null);
|
||||
RaisePropertyChanged(nameof(ladder_vm));
|
||||
}
|
||||
void _assign_param_permissions<T>(IAlgoParamVM<T> param, ref AlgoParamPermissions permissions_backing, AlgoParamPermissions permissions) {
|
||||
if (permissions_backing != permissions) {
|
||||
permissions_backing = permissions;
|
||||
if (param != null)
|
||||
param.permissions = permissions & _param_permissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FilterData : IEquatable<FilterData> {
|
||||
public readonly AlgoTreeDisplayMode algo_tree_display_mode;
|
||||
public readonly FilterStates column_filters;
|
||||
|
||||
public FilterData(AlgoTreeDisplayMode algo_tree_display_mode, FilterStates column_filters) {
|
||||
this.algo_tree_display_mode = algo_tree_display_mode;
|
||||
this.column_filters = column_filters;
|
||||
}
|
||||
|
||||
public Func<OrderSecurityAlgoMeta, bool> build_predicate() {
|
||||
var pred = column_filters.build_predicate();
|
||||
if (algo_tree_display_mode == AlgoTreeDisplayMode.RootAndLeafNodes) {
|
||||
if (pred == null) {
|
||||
pred = tree_disp_pred;
|
||||
} else {
|
||||
var col_pred = pred;
|
||||
pred = o => tree_disp_pred(o) && col_pred(o);
|
||||
}
|
||||
bool tree_disp_pred(OrderSecurityAlgoMeta o) =>
|
||||
!o.order.has_parent() ||
|
||||
o.order.is_exchange_order() ||
|
||||
o.order.order_type() == CustomOrderDefinition.CustomOneofCase.Spreader;
|
||||
}
|
||||
return pred;
|
||||
}
|
||||
|
||||
public bool Equals(FilterData other) =>
|
||||
algo_tree_display_mode == other.algo_tree_display_mode &&
|
||||
column_filters.safe_equals(other.column_filters);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is FilterData fd && Equals(fd);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.aggregate_hash((int)algo_tree_display_mode, column_filters?.GetHashCode() ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1038,5 +1080,28 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class AttachConf {
|
||||
static readonly IReadOnlyDictionary<CustomOrderDefinition.CustomOneofCase, (bool show_price, bool show_size)> _algo_type_conf;
|
||||
|
||||
static AttachConf() {
|
||||
var cover = config.Configuration.get<bts.config.CoverAttachUIOptions>();
|
||||
var join = config.Configuration.get<bts.config.JoinAttachUIOptions>();
|
||||
var lean = config.Configuration.get<bts.config.LeanAttachUIOptions>();
|
||||
var top = config.Configuration.get<bts.config.TopAttachUIOptions>();
|
||||
_algo_type_conf = new Dictionary<CustomOrderDefinition.CustomOneofCase, (bool, bool)> {
|
||||
{ CustomOrderDefinition.CustomOneofCase.Cover, (cover.show_price, cover.show_quantity) },
|
||||
{ CustomOrderDefinition.CustomOneofCase.Join, (join.show_price, join.show_quantity) },
|
||||
{ CustomOrderDefinition.CustomOneofCase.Lean, (lean.show_price, lean.show_quantity) },
|
||||
{ CustomOrderDefinition.CustomOneofCase.Top, (top.show_price, top.show_quantity) }
|
||||
};
|
||||
}
|
||||
|
||||
public static bool show_price(CustomOrderDefinition.CustomOneofCase algo_type) =>
|
||||
!_algo_type_conf.TryGetValue(algo_type, out var result) || result.show_price;
|
||||
|
||||
public static bool show_size(CustomOrderDefinition.CustomOneofCase algo_type) =>
|
||||
!_algo_type_conf.TryGetValue(algo_type, out var result) || result.show_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,19 +160,17 @@ namespace mbts.spark {
|
||||
toggle_expand_all_command.group = CommandGroups.Auxiliary;
|
||||
|
||||
var show_grid_settings_command = SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var gs_vm = new WindowSettingsDialogVM<OrderBookGridSettings, OrderBookGridSettingsVM>(
|
||||
var gs_vm = new WindowSettingsDialogVM<OrderBookGridSettings, OrderBookSettingsVM>(
|
||||
_settings_manager,
|
||||
us => us.order_book_grid,
|
||||
UserSettings.FileExtensions.GRID,
|
||||
s => {
|
||||
if (s.general is null)
|
||||
s = OrderBookStartupData.DefaultGrid;
|
||||
return _vm.grid_settings_manager.create_vm(
|
||||
// we need to get the most up to date GridSettings when launching b/c users may
|
||||
// have changed some settings on the grid directly, like column widths.
|
||||
s.general.with(_vm.core_columns.Select(c => c.create())),
|
||||
this.observe_title()
|
||||
);
|
||||
// we need to get the most up to date GridSettings when launching b/c users may
|
||||
// have changed some settings on the grid directly, like column widths.
|
||||
s.general = s.general.with(_vm.core_columns.Select(c => c.create()));
|
||||
return _vm.grid_settings_manager.create_vm(s, this.observe_title());
|
||||
}
|
||||
);
|
||||
// TODO: bind to main window's Title
|
||||
|
||||
@@ -9,15 +9,26 @@ using System.Collections.Generic;
|
||||
using GridSettings = mbts.ui.settings.GridSettings;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
enum AlgoTreeDisplayMode {
|
||||
FullTree,
|
||||
RootAndLeafNodes
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class OrderBookGridSettings : IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>, IEquatable<OrderBookGridSettings> {
|
||||
// general
|
||||
[ProtoMember(1)]
|
||||
public GridSettings general { get; set; }
|
||||
// predicate animations
|
||||
[ProtoMember(2)]
|
||||
List<OrderRecordTuplePredicateAnimations> _predicate_animations;
|
||||
// algo tree display mode
|
||||
[ProtoMember(3)]
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode { get; set; }
|
||||
|
||||
public OrderBookGridSettings() { }
|
||||
public OrderBookGridSettings(GridSettings general = default, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, double right_panel_width = double.NaN) {
|
||||
|
||||
public OrderBookGridSettings(GridSettings general = default, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null) {
|
||||
this.general = general;
|
||||
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
|
||||
if (predicate_animations != null)
|
||||
@@ -32,6 +43,7 @@ namespace bts.shell.orderbook {
|
||||
|
||||
public bool Equals(OrderBookGridSettings other) =>
|
||||
other != null &&
|
||||
algo_tree_display_mode == other.algo_tree_display_mode &&
|
||||
EqualityComparer.null_check_equals(general, other.general) &&
|
||||
EqualityComparer.safe_sequence_equals(predicate_animations, other.predicate_animations);
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
class OrderBookGridSettingsManager : IDisposable, IObserver<OrderBookGridSettings> {
|
||||
readonly IObserver<OrderBookGridSettings> _core_man_as_observer;
|
||||
AlgoTreeDisplayMode _algo_tree_display_mode;
|
||||
|
||||
public OrderBookGridSettingsManager(
|
||||
IObservable<string> owner_title,
|
||||
IBus bus,
|
||||
INotificationService notification_service,
|
||||
OrdersModel model,
|
||||
IEnumerable<OrderBookRowVM> rows,
|
||||
ObservableCollection<DIYGrid.ColumnBase> columns) {
|
||||
// make font-weight immutable for all columns (the font-weight rule is hard-coded: Regular for root-orders, Light for all others)
|
||||
// TODO: Remove the immutable font-weight flags when cell animation is ready
|
||||
var col_settings_flags = EnumHelper.get_values<Columns>().ToDictionary(
|
||||
c => c.ToString(), c => GridColumnSettingsFeatureFlags.ImmutableFontWeight);
|
||||
// make font-color immutable for Side, Size, and Filled columns (the font-color rule is hard-coded: MarketData.bid for Buy orders, MarketData.ask for Sells)
|
||||
// TODO: Remove the immutable font-color flags when cell animation is ready
|
||||
foreach (var c in new[] { Columns.Side, Columns.Size, Columns.Filled }) {
|
||||
col_settings_flags[c.ToString()] = GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableFontWeight;
|
||||
}
|
||||
core_manager = new GridSettingsManager<OrderBookRowVM, OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
|
||||
owner_title, bus, model, rows, columns,
|
||||
() => new OrderRecordTuplePredicate(),
|
||||
() => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = pvm.predicate_types.FirstOrDefault();
|
||||
return pvm;
|
||||
},
|
||||
col_id => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = _corresponding_predicate_type(EnumHelper.parse_or_default<Columns>(col_id));
|
||||
return pvm;
|
||||
},
|
||||
(gen, anims) => new OrderBookGridSettings(gen, anims.Select(a => new OrderRecordTuplePredicateAnimations(a.predicate_data, a.cell_animations, a.row_animations, a.sound_notifications))) { algo_tree_display_mode = _algo_tree_display_mode },
|
||||
p => p.create_predicate(notification_service.data_cache),
|
||||
p => p.create_notification_predicate(notification_service.data_cache),
|
||||
notification_service == null ? new Func<IPredicate<OrderSecurity>, SoundNotification, IDisposable>((p, sn) => Disposable.empty) : notification_service.link_to_order,
|
||||
notification_service == null ? new Func<INotificationPredicate<OrderSecurity>, IDisposable>(t => Disposable.empty) : notification_service.link_to_order,
|
||||
col_settings_flags);
|
||||
_core_man_as_observer = core_manager;
|
||||
}
|
||||
|
||||
public event Action algo_tree_display_mode_changed;
|
||||
|
||||
public GridSettingsManager<OrderBookRowVM, OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_manager { get; }
|
||||
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode {
|
||||
get => _algo_tree_display_mode;
|
||||
set {
|
||||
if (_algo_tree_display_mode != value) {
|
||||
_algo_tree_display_mode = value;
|
||||
algo_tree_display_mode_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void load_from(OrderBookGridSettings gs) {
|
||||
core_manager.load_from(gs);
|
||||
algo_tree_display_mode = gs.algo_tree_display_mode;
|
||||
}
|
||||
|
||||
public OrderBookGridSettings create(IEnumerable<SortingCriteria> sorting_criterion) {
|
||||
var gs = core_manager.create();
|
||||
gs.general = gs.general.with(sorting_criterion: sorting_criterion);
|
||||
gs.algo_tree_display_mode = _algo_tree_display_mode;
|
||||
return gs;
|
||||
}
|
||||
|
||||
public OrderBookSettingsVM create_vm(OrderBookGridSettings gs, IObservable<string> owner_title) =>
|
||||
new OrderBookSettingsVM(core_manager.create_vm(gs.general, owner_title)) {
|
||||
algo_tree_display_mode = gs.algo_tree_display_mode
|
||||
};
|
||||
|
||||
public void Dispose() => core_manager.Dispose();
|
||||
|
||||
static OrderRecordTuplePredicate.PredicateTypeOneofCase _corresponding_predicate_type(Columns col) {
|
||||
switch (col) {
|
||||
case Columns.Security: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Security;
|
||||
case Columns.Time: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Time;
|
||||
case Columns.LastChange: return OrderRecordTuplePredicate.PredicateTypeOneofCase.LastChange;
|
||||
case Columns.User: return OrderRecordTuplePredicate.PredicateTypeOneofCase.User;
|
||||
case Columns.Account: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Account;
|
||||
case Columns.Exchange: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Exchange;
|
||||
case Columns.TimeInForce: return OrderRecordTuplePredicate.PredicateTypeOneofCase.TimeInForce;
|
||||
case Columns.OrderType: return OrderRecordTuplePredicate.PredicateTypeOneofCase.OrderType;
|
||||
case Columns.SubType: return OrderRecordTuplePredicate.PredicateTypeOneofCase.SubType;
|
||||
case Columns.Side: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Side;
|
||||
case Columns.Size: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Size;
|
||||
case Columns.Price: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Price;
|
||||
case Columns.Filled: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Filled;
|
||||
case Columns.AvgFilled: return OrderRecordTuplePredicate.PredicateTypeOneofCase.AvgFilled;
|
||||
case Columns.LastPrice: return OrderRecordTuplePredicate.PredicateTypeOneofCase.LastPrice;
|
||||
case Columns.Status: return OrderRecordTuplePredicate.PredicateTypeOneofCase.Status;
|
||||
case Columns.LastMessage: return OrderRecordTuplePredicate.PredicateTypeOneofCase.LastMessage;
|
||||
case Columns.SecurityKey: return OrderRecordTuplePredicate.PredicateTypeOneofCase.SecurityKey;
|
||||
case Columns.OrderKey: return OrderRecordTuplePredicate.PredicateTypeOneofCase.OrderKey;
|
||||
case Columns.ParentKey: return OrderRecordTuplePredicate.PredicateTypeOneofCase.ParentKey;
|
||||
case Columns.AttachedTargetOrderKey: return OrderRecordTuplePredicate.PredicateTypeOneofCase.AttachedTargetOrderKey;
|
||||
default: return default;
|
||||
}
|
||||
}
|
||||
|
||||
void IObserver<OrderBookGridSettings>.OnNext(OrderBookGridSettings value) {
|
||||
_core_man_as_observer.OnNext(value);
|
||||
algo_tree_display_mode = value.algo_tree_display_mode;
|
||||
}
|
||||
void IObserver<OrderBookGridSettings>.OnError(Exception error) => _core_man_as_observer.OnError(error);
|
||||
void IObserver<OrderBookGridSettings>.OnCompleted() => _core_man_as_observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ namespace bts.shell.orderbook {
|
||||
/// TODO: remove properties below, and redirect callers to <see cref="right_panel"/>
|
||||
// right panel (host)
|
||||
public bool show_right_panel { get => right_panel.show; set => right_panel.show = value; }
|
||||
public double right_panel_width { get; set; }
|
||||
public double right_panel_width { get => right_panel.width; set => right_panel.width = value; }
|
||||
// order params
|
||||
public bool show_order_params { get => right_panel.stack.show_order_params; set => right_panel.stack.show_order_params = value; }
|
||||
public double order_params_height { get; set; }
|
||||
@@ -50,7 +50,10 @@ namespace bts.shell.orderbook {
|
||||
// grid
|
||||
[ProtoMember(15)]
|
||||
[Obsolete]
|
||||
public GridSettings grid;
|
||||
public GridSettings grid { get; set; }
|
||||
// orderbook grid
|
||||
[ProtoMember(17)]
|
||||
public OrderBookGridSettings orderbook_grid { get; set; }
|
||||
// fills settings
|
||||
[ProtoMember(26)]
|
||||
public OrderBookFillsGridSettings fills_settings { get; set; }
|
||||
@@ -71,15 +74,15 @@ namespace bts.shell.orderbook {
|
||||
ladder_height = _default_ladder_height;
|
||||
}
|
||||
|
||||
public OrderBookStartupData(FilterStates filters, GridSettings grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, bool use_defaults = false) {
|
||||
public OrderBookStartupData(FilterStates filters, OrderBookGridSettings orderbook_grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_height = 0, bool show_fills = false, bool use_defaults = false) {
|
||||
this.filters = filters;
|
||||
this.use_defaults = use_defaults;
|
||||
this.show_right_panel = show_right_panel;
|
||||
this.right_panel_width = right_panel_width;
|
||||
this.fills_height = fills_height;
|
||||
this.show_fills = show_fills;
|
||||
this.orderbook_grid = orderbook_grid;
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
this.grid = grid;
|
||||
_predicate_animations = new List<OrderRecordTuplePredicateAnimations>();
|
||||
if (predicate_animations != null)
|
||||
_predicate_animations.AddRange(predicate_animations);
|
||||
@@ -89,13 +92,19 @@ namespace bts.shell.orderbook {
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
[Obsolete]
|
||||
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
|
||||
public OrderBookGridSettings grid_settings_wrapper() => use_defaults ? null : new OrderBookGridSettings(grid, predicate_animations);
|
||||
public OrderBookGridSettings grid_settings_wrapper() {
|
||||
if (use_defaults)
|
||||
return null;
|
||||
if (orderbook_grid == null)
|
||||
orderbook_grid = new OrderBookGridSettings(grid.clone(), _predicate_animations);
|
||||
return orderbook_grid;
|
||||
}
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
|
||||
public static OrderBookStartupData Default =>
|
||||
new OrderBookStartupData(
|
||||
new FilterStates { statuses = new[] { OrderStatus.Working } },
|
||||
_default_general_grid,
|
||||
DefaultGrid,
|
||||
_default_show_right_panel,
|
||||
_default_right_panel_width,
|
||||
_default_fills_height,
|
||||
@@ -118,7 +127,7 @@ namespace bts.shell.orderbook {
|
||||
}
|
||||
}
|
||||
static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.sorting_criterion);
|
||||
public static GridSettings default_mini_grid => GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion);
|
||||
public static OrderBookGridSettings default_mini_grid => new OrderBookGridSettings(GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion));
|
||||
|
||||
static class DefaultColumns {
|
||||
public static GridColumnSettings security => new GridColumnSettings(Columns.Security.ToString(), DIYGrid.DefaultColumnHeaders.Security, width: DIYGrid.DefaultColumnWidths.Security);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
class OrderBookSettingsVM : DisposableViewModelBase, IWindowSettingsVM<OrderBookGridSettings>, ITemplateSelectorKey {
|
||||
AlgoTreeDisplayMode _algo_tree_display_mode;
|
||||
|
||||
public OrderBookSettingsVM(GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_settings_vm) =>
|
||||
this.core_settings_vm = core_settings_vm;
|
||||
|
||||
public OrderBookSettingsVM(
|
||||
IObservable<string> owner_title, IBus bus, OrdersModel orders_model,
|
||||
Func<OrderRecordTuplePredicate> predicate_data_factory,
|
||||
Func<OrderRecordTuplePredicate, INotificationPredicate<OrderSecurity>> notification_predicate_factory,
|
||||
Func<IPropertyWrapperVM<OrderRecordTuplePredicate>> create_predicate_vm,
|
||||
Func<string, IPropertyWrapperVM<OrderRecordTuplePredicate>> create_column_predicate_vm,
|
||||
Func<GridSettings, IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>>, OrderBookGridSettings> create_settings_obj,
|
||||
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
|
||||
core_settings_vm = new GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
|
||||
owner_title, bus, orders_model, predicate_data_factory, notification_predicate_factory, create_predicate_vm, create_column_predicate_vm, create_settings_obj, column_flags);
|
||||
}
|
||||
|
||||
public GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_settings_vm { get; }
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode { get => _algo_tree_display_mode; set => Set(ref _algo_tree_display_mode, value); }
|
||||
string ITemplateSelectorKey.key => GridSettingsTemplateKeys.OrderBook;
|
||||
|
||||
public void load(OrderBookGridSettings grid_settings) {
|
||||
core_settings_vm.load(grid_settings);
|
||||
algo_tree_display_mode = grid_settings.algo_tree_display_mode;
|
||||
}
|
||||
public OrderBookGridSettings get_result() {
|
||||
var gs = core_settings_vm.get_result();
|
||||
gs.algo_tree_display_mode = algo_tree_display_mode;
|
||||
return gs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,7 @@
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.RowStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<!--
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
@@ -122,6 +123,7 @@
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
-->
|
||||
</Style>
|
||||
</c:DIYGrid.RowStyle>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
|
||||
@@ -171,7 +171,7 @@
|
||||
Columns="{Binding columns}"
|
||||
CurrentRow="{Binding current_row, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Rows="{Binding rows}"
|
||||
SelectionHighlight="{Binding grid_settings_manager.selection_highlight, Mode=OneWay}"
|
||||
SelectionHighlight="{Binding grid_settings_manager.core_manager.selection_highlight, Mode=OneWay}"
|
||||
>
|
||||
<FrameworkElement.Margin>
|
||||
<Binding Source="{StaticResource GridSplitterWidth}">
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace bts.shell {
|
||||
void _on_activity(Activity activity) =>
|
||||
_activity_notifications.process_item(activity);
|
||||
|
||||
void _on_orders(TableUpdate<(SecurityImmutable?,OrderRecordImmutable),uint> update) {
|
||||
void _on_orders(TableUpdate<(SecurityImmutable? sec, OrderRecordImmutable order), uint> update) {
|
||||
// must update notification_service_data_cache first, some of the predicate/triggers (esp. ToastNotifications) will use the notification_service_data_cache to lookup order-history
|
||||
_data_cache.update(update.as_iincremental());
|
||||
foreach (var o in update.added.Concat(update.changed))
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using bts.collections;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace mbts.spark {
|
||||
class AlgoParamVM<T> : DisposableViewModelBase, IAlgoParamVM<T> {
|
||||
class AlgoParamVM<T> : IAlgoParamVM<T>, INotifyPropertyChanged {
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
AlgoParamPermissions _permissions;
|
||||
bool _is_enabled, _has_value;
|
||||
@@ -25,6 +26,7 @@ namespace mbts.spark {
|
||||
_comparer = comparer;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChange<T> value_changed;
|
||||
public event PropertyChange<AlgoParamPermissions> permissions_changed;
|
||||
public event Action<bool> is_dirty_changed;
|
||||
@@ -41,19 +43,18 @@ namespace mbts.spark {
|
||||
public AlgoParamPermissions permissions {
|
||||
get => _permissions;
|
||||
set {
|
||||
if (Set(ref _permissions, value, out var oldval))
|
||||
if (_set(ref _permissions, value, out var oldval))
|
||||
permissions_changed?.Invoke(oldval, value);
|
||||
}
|
||||
}
|
||||
public bool is_enabled { get => _is_enabled; set => Set(ref _is_enabled, value); }
|
||||
public bool has_value { get => _has_value; set => Set(ref _has_value, value); }
|
||||
public bool is_enabled { get => _is_enabled; set => _set(ref _is_enabled, value); }
|
||||
public bool has_value { get => _has_value; set => _set(ref _has_value, value); }
|
||||
public bool is_dirty { get; private set; }
|
||||
object IAlgoParamVM.value { get => value; set => this.value = (T)value; }
|
||||
|
||||
public void revert() {
|
||||
if (is_dirty) {
|
||||
_value = _committed_value;
|
||||
RaisePropertyChanged(nameof(value));
|
||||
_set_value_core(_committed_value);
|
||||
_toggle_is_dirty();
|
||||
}
|
||||
}
|
||||
@@ -74,21 +75,45 @@ namespace mbts.spark {
|
||||
_toggle_is_dirty();
|
||||
}
|
||||
|
||||
bool _set<TValue>(ref TValue backing, TValue new_value, [CallerMemberName]string prop = "") =>
|
||||
_set(ref backing, new_value, EqualityComparer<TValue>.Default, prop);
|
||||
|
||||
bool _set<TValue>(ref TValue backing, TValue new_value, out TValue old_value, [CallerMemberName]string prop = "") =>
|
||||
_set(ref backing, new_value, out old_value, EqualityComparer<TValue>.Default, prop);
|
||||
|
||||
bool _set<TValue>(ref TValue backing, TValue new_value, out TValue old_value, IEqualityComparer<TValue> comparer, [CallerMemberName]string prop = "") {
|
||||
old_value = backing;
|
||||
return _set(ref backing, new_value, comparer, prop);
|
||||
}
|
||||
|
||||
bool _set<TValue>(ref TValue backing, TValue new_value, IEqualityComparer<TValue> comparer, [CallerMemberName]string prop = "") {
|
||||
if (comparer.Equals(backing, new_value))
|
||||
return false;
|
||||
backing = new_value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _set_value(T new_value) {
|
||||
if (!_comparer.Equals(new_value, _value)) {
|
||||
T oldval = _value;
|
||||
if (_comparer.Equals(new_value, _value))
|
||||
return false;
|
||||
_set_value_core(new_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
void _set_value_core(T new_value) {
|
||||
if (value_changed == null) {
|
||||
_value = new_value;
|
||||
value_changed?.Invoke(oldval, new_value);
|
||||
RaisePropertyChanged(nameof(value));
|
||||
return true;
|
||||
} else {
|
||||
value_changed(_value, _value = new_value);
|
||||
}
|
||||
return false;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(value)));
|
||||
}
|
||||
|
||||
void _toggle_is_dirty() {
|
||||
is_dirty = !is_dirty;
|
||||
is_dirty_changed?.Invoke(is_dirty);
|
||||
RaisePropertyChanged(nameof(is_dirty));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(is_dirty)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace bts.spark {
|
||||
static readonly IEqualityComparer<OrderRecordImmutable> _id_comparer =
|
||||
bts.utils.EqualityComparer.Create<OrderRecordImmutable, uint>(a => a.Key);
|
||||
|
||||
public OrderActivitySummarizer(IBus bus, IObservable<TableUpdate<(SecurityImmutable? sec,OrderRecordImmutable order), uint>> orders) {
|
||||
public OrderActivitySummarizer(IBus bus, IObservable<TableUpdate<(SecurityImmutable? sec, OrderRecordImmutable order), uint>> orders) {
|
||||
_bus = bus;
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(sec => _security = sec),
|
||||
|
||||
@@ -7,18 +7,31 @@ namespace bts.api.orderman {
|
||||
public OrderSecurity(SecurityImmutable? sec, OrderRecordImmutable order) {
|
||||
this.security = sec;
|
||||
this.order = order;
|
||||
piq = null;
|
||||
}
|
||||
public OrderSecurity((SecurityImmutable? sec, OrderRecordImmutable order) t) {
|
||||
security = t.sec;
|
||||
order = t.order;
|
||||
piq = null;
|
||||
}
|
||||
public OrderSecurity(SecurityImmutable? sec, OrderRecordImmutable order, uint? piq) {
|
||||
this.security = sec;
|
||||
this.order = order;
|
||||
this.piq = piq;
|
||||
}
|
||||
//public OrderSecurity(OrderSecurity t) {
|
||||
// security = t.security;
|
||||
// order = t.order;
|
||||
// piq = t.piq;
|
||||
//}
|
||||
public static implicit operator OrderSecurity(ValueTuple<SecurityImmutable?, OrderRecordImmutable> x) => new OrderSecurity(x);
|
||||
public SecurityImmutable? security { get; }
|
||||
public OrderRecordImmutable order { get; }
|
||||
public uint? piq { get; }
|
||||
|
||||
public override bool Equals(object obj) => (obj is OrderSecurity os) && Equals(os);
|
||||
public bool Equals(OrderSecurity other) => order.Equals(other.order) && security == other.security;
|
||||
public override int GetHashCode() => (security, order).GetHashCode();
|
||||
public bool Equals(OrderSecurity other) => order.Equals(other.order) && security == other.security && piq == other.piq;
|
||||
public override int GetHashCode() => (security, order, piq).GetHashCode();
|
||||
|
||||
public static bool operator == (OrderSecurity left, OrderSecurity right) => left.Equals(right);
|
||||
public static bool operator != (OrderSecurity left, OrderSecurity right) => !left.Equals(right);
|
||||
|
||||
@@ -20,9 +20,11 @@ using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
enum AlgoParamPermissions {
|
||||
None, // Hidden from user (i.e. implicit properties, such as TriggerOrderDefinition.Security)
|
||||
ReadOnly,
|
||||
ReadWrite
|
||||
None = 0, // Hidden from user (i.e. implicit properties, such as TriggerOrderDefinition.Security)
|
||||
ReadOnly = 1,
|
||||
Write = (1 << 1),
|
||||
// TODO: refactor 'ReadWrite' references to 'Read | Write'
|
||||
ReadWrite = 1 | (1 << 1)
|
||||
}
|
||||
|
||||
enum AlgoDisplayGroup { Exchange, BTS, Studio, API }
|
||||
@@ -160,4 +162,4 @@ namespace mbts.spark {
|
||||
void dispose() =>param_vm.permissions_changed -= on_permissions_changed;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -411,7 +411,7 @@ namespace mbts.spark {
|
||||
if (avm != param.value)
|
||||
param.value = avm;
|
||||
}),
|
||||
param.as_demuxer().subscribe<IAlgoVM>(nameof(IAlgoParamVM.value)).Subscribe(child_vm => rv.selected_algo = child_vm));
|
||||
param.subscribe_value().Subscribe(child_vm => rv.selected_algo = child_vm));
|
||||
_child_algo_selector_data[prop_name] = new AlgoSelectorData(prop_name, rv, get_mutable_from_impl, get_order, set_order, hook);
|
||||
_child_algo_params.Add(param);
|
||||
return rv;
|
||||
|
||||
@@ -4,8 +4,10 @@ using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.md;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using mbts.config;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
@@ -16,8 +18,10 @@ using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using OrderUpdate = bts.api.core.TableUpdate<(bts.api.SecurityImmutable? sec, bts.api.orderman.OrderRecordImmutable order), uint>;
|
||||
using OrderUpdatePiq = bts.api.core.TableUpdate<bts.api.orderman.OrderSecurity, uint>;
|
||||
|
||||
namespace mbts.spark {
|
||||
[Export]
|
||||
@@ -28,21 +32,26 @@ namespace mbts.spark {
|
||||
readonly OrderFactory _factory;
|
||||
readonly OrderService _service;
|
||||
readonly PositionService _position_service;
|
||||
readonly MBOService _mbo_service;
|
||||
readonly SpreaderModel _spreader;
|
||||
readonly ErrorReporter _error;
|
||||
readonly DynamicOrderHelper _dynamic_helper;
|
||||
readonly OrderActivitySummarizer _activity;
|
||||
readonly TableUpdateDemuxer<OrderRecordImmutable, uint, uint> _security_orders_demuxer, _security_working_orders_demuxer;
|
||||
// we need a new one of these for the time being since the ladder is subscribing to orders with piq
|
||||
readonly TableUpdateDemuxer<OrderRecordImmutable, uint, uint> _security_orders_piq_demuxer;
|
||||
readonly TableUpdateDemuxer<PositionUnitImmutable, int, uint> _security_positions_demuxer;
|
||||
IDisposable _dispose;
|
||||
static readonly bool _piq_enabled = Configuration.get<bts.config.toggles.PlacementInQueue>().enabled;
|
||||
|
||||
[ImportingConstructor]
|
||||
OrdersModel(IBus bus, OrderFactory factory, OrderService service, PositionService position_service,
|
||||
OrdersModel(IBus bus, OrderFactory factory, OrderService service, PositionService position_service, MBOService mbo_service,
|
||||
SpreaderModel spreader, DynamicOrderHelper dynamic_helper, AdminModel admin_model, IAlgoStudioModel algo_model, MarketDataAuxiliaryModel md_auxiliary_model, SecurityStore sstore, ErrorReporter error) {
|
||||
_bus = bus;
|
||||
_factory = factory;
|
||||
_service = service;
|
||||
_position_service = position_service;
|
||||
_mbo_service = mbo_service;
|
||||
_spreader = spreader;
|
||||
_error = error;
|
||||
_dynamic_helper = dynamic_helper;
|
||||
@@ -51,13 +60,33 @@ namespace mbts.spark {
|
||||
this.md_auxiliary_model = md_auxiliary_model;
|
||||
var scheduler = ThreadPoolScheduler.Instance;
|
||||
var interval = TimeSpan.FromMilliseconds(100);
|
||||
on_orders =
|
||||
on_orders =
|
||||
_service
|
||||
.subscribei_orders()
|
||||
.Naggle(interval, scheduler)
|
||||
.PermissionFilter(admin_model.on_admin_data)
|
||||
.join(sstore, order => order.security_key())
|
||||
.Table().Cache();
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
if (_piq_enabled) {
|
||||
on_orders_with_piq = on_orders
|
||||
.LeftJoin<
|
||||
(SecurityImmutable?, OrderRecordImmutable),
|
||||
OrderPIQImmutable,
|
||||
OrderSecurity,
|
||||
uint
|
||||
>(mbo_service.subscribei_piq().Table(),
|
||||
si_ort => si_ort.Item2.Key,
|
||||
p => p.OrderId,
|
||||
(si_ort, r, p) => new OrderSecurity(si_ort.Item1, si_ort.Item2, p.Position),
|
||||
(si_ort, r) => new OrderSecurity(si_ort.Item1, si_ort.Item2, null),
|
||||
osp => osp.order.Key);
|
||||
} else {
|
||||
on_orders_with_piq = on_orders
|
||||
.Select((ft) => new OrderSecurity(ft.Item1, ft.Item2, null), os => os.order.Key);
|
||||
}
|
||||
|
||||
on_positions = _position_service.subscribei_position_data().Naggle(interval, scheduler).PermissionFilter(admin_model.on_admin_data).Table().Cache();
|
||||
working_orders =
|
||||
on_orders.Scan(
|
||||
@@ -65,6 +94,13 @@ namespace mbts.spark {
|
||||
(workers, table) => _update_working_orders(workers, table))
|
||||
.Replay(1).RefCount();
|
||||
|
||||
working_orders_with_piq =
|
||||
on_orders_with_piq.Scan(
|
||||
ImmutableDictionary<uint, OrderSecurity>.Empty,
|
||||
(workers, table) => _update_working_orders(workers, table))
|
||||
.Replay(1).RefCount();
|
||||
|
||||
|
||||
on_order_securities =
|
||||
on_orders
|
||||
.as_iincremental()
|
||||
@@ -73,6 +109,7 @@ namespace mbts.spark {
|
||||
|
||||
_activity = new OrderActivitySummarizer(bus, on_orders);
|
||||
_security_orders_demuxer = new TableUpdateDemuxer<OrderRecordImmutable, uint, uint>(o => o.Key, o => o.security_key());
|
||||
_security_orders_piq_demuxer = new TableUpdateDemuxer<OrderRecordImmutable, uint, uint>(o => o.Key, o => o.security_key());
|
||||
_security_working_orders_demuxer = new TableUpdateDemuxer<OrderRecordImmutable, uint, uint>(o => o.Key, o => o.security_key());
|
||||
_security_positions_demuxer = new TableUpdateDemuxer<PositionUnitImmutable, int, uint>(o => o.RecordId, p => p.SecurityId);
|
||||
var algo_meta_join = algo_model.definitions.LeftJoin<AlgoData, AlgoDefinitionMetadata, (AlgoData algo, AlgoDefinitionMetadata? meta), AlgoKey>(
|
||||
@@ -122,6 +159,7 @@ namespace mbts.spark {
|
||||
.Cache();
|
||||
_dispose = Disposable.Create(
|
||||
on_orders.Select(t => t.order, o => o.Key).Subscribe(_security_orders_demuxer),
|
||||
on_orders_with_piq.Select(t => t.order, o => o.Key).Subscribe(_security_orders_piq_demuxer),
|
||||
on_orders
|
||||
.Filter(order => order.order.is_active() && order.order.HasState && order.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible, key => key.order.Key)
|
||||
.Select(t => t.order, o => o.Key)
|
||||
@@ -140,13 +178,16 @@ namespace mbts.spark {
|
||||
public SpreaderModel spreader => _spreader;
|
||||
public DynamicOrderHelper dynamic_helper => _dynamic_helper;
|
||||
public IObservable<OrderUpdate> on_orders { get; }
|
||||
public IObservable<OrderUpdatePiq> on_orders_with_piq { get; }
|
||||
public IObservable<TableUpdate<OrderSecurityAlgoMeta, uint>> on_order_tuples { get; }
|
||||
public IObservable<TableUpdate<KeyValuePair<uint, bool>, uint>> on_orders_can_detach { get; }
|
||||
public IObservable<TableUpdate<KeyValuePair<uint, bool>, uint>> on_orders_can_attach { get; }
|
||||
public IObservable<IIncrementalUpdate<SecurityImmutable, uint>> on_order_securities { get; }
|
||||
public IObservable<TableUpdate<FillTuple, string>> on_fill_tuples { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint,OrderSecurity>> working_orders { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint, OrderSecurity>> working_orders_with_piq { get; }
|
||||
public IObservable<TableUpdate<PositionUnitImmutable, int>> on_positions { get; }
|
||||
|
||||
public AdminModel admin_model { get; }
|
||||
public IAlgoStudioModel algo_model { get; }
|
||||
|
||||
@@ -231,8 +272,30 @@ namespace mbts.spark {
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
|
||||
static ImmutableDictionary<uint, OrderSecurity>
|
||||
_update_working_orders(ImmutableDictionary<uint, OrderSecurity> target, OrderUpdate table) {
|
||||
static ImmutableDictionary<uint, OrderSecurity> _update_working_orders(ImmutableDictionary<uint, OrderSecurity> target, OrderUpdate table) {
|
||||
var clone = target.ToBuilder();
|
||||
foreach (var o in table.removed) {
|
||||
if (o.order.is_active()) {
|
||||
clone.Remove(o.order.Key);
|
||||
}
|
||||
}
|
||||
foreach (var o in table.changes) {
|
||||
if (o.Old.order.is_active()) {
|
||||
clone.Remove(o.Old.order.Key);
|
||||
}
|
||||
if (o.New.order.is_active()) {
|
||||
clone.Add(o.New.order.Key, o.New);
|
||||
}
|
||||
}
|
||||
foreach (var o in table.added) {
|
||||
if (o.order.is_active()) {
|
||||
clone.Add(o.order.Key, o);
|
||||
}
|
||||
}
|
||||
return clone.ToImmutableDictionary();
|
||||
}
|
||||
|
||||
static ImmutableDictionary<uint, OrderSecurity> _update_working_orders(ImmutableDictionary<uint, OrderSecurity> target, OrderUpdatePiq table) {
|
||||
var clone = target.ToBuilder();
|
||||
foreach (var o in table.removed) {
|
||||
if (o.order.is_active()) {
|
||||
@@ -256,6 +319,7 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// usinig new OrdersModel extensions to reduce the amount of code change needed to switch uis over to the new OrdersModel,
|
||||
// without changing any code in the actual new OrdersModel class.
|
||||
static class OrdersModelExtensions {
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace mbts {
|
||||
// old order will be a copy of new order, except with filledQuantity set to 0
|
||||
var old_state = ort.order.State.CloneToMutable();
|
||||
old_state.FilledQuantity = 0;
|
||||
return (new OrderSecurity(ort.security, ort.order.with(state: old_state)), ort);
|
||||
return (new OrderSecurity(ort.security, ort.order.with(state: old_state), ort.piq), ort);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
<Authors>Blue Trading Systems</Authors>
|
||||
<Company>Blue Trading Systems</Company>
|
||||
<Product>Spark</Product>
|
||||
<Description>The game has changed. Make your Move.</Description>
|
||||
<Description>Advanced Derivatives Trading</Description>
|
||||
<ApplicationManifest>spark.manifest</ApplicationManifest>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace mbts.ui.controls {
|
||||
var a_glyph_context = _gcr.glyph_context;
|
||||
var a_glyph_run = a_glyph_context.get_glyph_run(
|
||||
_hedge_indicator,
|
||||
12,
|
||||
FontSize,
|
||||
_gcr.layout_size.Width,
|
||||
_gcr.layout_size.Height,
|
||||
HorizontalAlignment.Right,
|
||||
@@ -318,7 +318,7 @@ namespace mbts.ui.controls {
|
||||
var a_glyph_context = _gcr.glyph_context;
|
||||
var a_glyph_run = a_glyph_context.get_glyph_run(
|
||||
mbts.spark.utilities.OrderDataHelper.abbreviate_algo_type(AlgoType),
|
||||
12,
|
||||
FontSize,
|
||||
_gcr.layout_size.Width,
|
||||
_gcr.layout_size.Height,
|
||||
HorizontalAlignment.Left,
|
||||
|
||||
@@ -115,7 +115,8 @@ namespace mbts.ui.controls {
|
||||
ProductDescription = "Product Description",
|
||||
HubAlias = "Hub Alias",
|
||||
StripName = "Strip Name",
|
||||
MicCode = "Mic Code"
|
||||
MicCode = "Mic Code",
|
||||
PositionInQueue = "PIQ"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -266,4 +267,4 @@ namespace mbts.ui.controls {
|
||||
public TColKey key { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ namespace mbts.spark {
|
||||
new DialogSkirtItem("Apply", new DelegateCommand(() => committed?.Invoke()))
|
||||
};
|
||||
|
||||
public string key => ui.spark.GridOrLadderSettingsSelectorKeys.SimpleGrid;
|
||||
public string key => ui.spark.GridSettingsTemplateKeys.SimpleGrid;
|
||||
|
||||
public TSettingsData get_result() {
|
||||
var animation_map = predicate_animations
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
<sys:Double x:Key="HorizontalGap">16.0</sys:Double>
|
||||
<sys:Double x:Key="ControlNormalWidth">140</sys:Double>
|
||||
<sys:Double x:Key="PredicateRootColumnWidth">176</sys:Double>
|
||||
<sys:Double x:Key="ControlLongWidth">240</sys:Double>
|
||||
<sys:Double x:Key="ComboBoxShortWidth">70</sys:Double>
|
||||
<sys:Double x:Key="ComboBoxNormalWidth">88</sys:Double>
|
||||
<sys:Double x:Key="ComboBoxLongWidth">140</sys:Double>
|
||||
@@ -109,9 +108,6 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<DataTemplate x:Key="FontPickerPopupHeaderTemplate">
|
||||
<TextBlock FontFamily="{Binding font_family}" FontSize="{Binding font_size}" FontWeight="{Binding font_weight}" Margin="4,0" Text="{Binding font_display_name}" />
|
||||
</DataTemplate>
|
||||
<cv:ValueMap x:Key="PredicateCategoryToFontStyleConverter" Default="{u:FontStyle Normal}">
|
||||
<cv:KeyValue Key="{u:Enum Event, Type=m:PredicateCategory}" Value="{u:FontStyle Italic}"/>
|
||||
</cv:ValueMap>
|
||||
@@ -311,7 +307,10 @@
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSplit}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<GroupBox>
|
||||
<GroupBox
|
||||
Content="{Binding GridSectionContent, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
ContentTemplate="{Binding GridSectionContentTemplate, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
>
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
@@ -327,32 +326,6 @@
|
||||
Grid
|
||||
</c:ExpanderToggleButton>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalSplit}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Font</TextBlock>
|
||||
<Grid Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}">
|
||||
<c:PopupControl HorizontalAlignment="Stretch" Header="{Binding}" HeaderTemplate="{StaticResource FontPickerPopupHeaderTemplate}" Background="{StaticResource ComboBox.Static.Background}">
|
||||
<c:FontPicker SelectedFontFamily="{Binding font_family}" SelectedFontSize="{Binding font_size}" SelectedFontWeight="{Binding font_weight}"/>
|
||||
</c:PopupControl>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="2">Font Color (default)</TextBlock>
|
||||
<c:ColorPickerPopupWithOpacitySlider Grid.Row="2" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding font_color}" CanUserEditOpacity="False"/>
|
||||
<TextBlock Grid.Row="4">Selection Highlight</TextBlock>
|
||||
<c:ColorPickerPopupWithOpacitySlider Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding selection_highlight}"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="2" Grid.IsSharedSizeScope="True" VerticalAlignment="Top">
|
||||
<GroupBox.Style>
|
||||
@@ -754,4 +727,4 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -14,6 +14,26 @@ namespace mbts.ui.spark {
|
||||
public GridSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
#region GridSectionContent
|
||||
public static readonly DependencyProperty GridSectionContentProperty =
|
||||
WPFHelper.create_dp<object, GridSettingsView>(nameof(GridSectionContent));
|
||||
|
||||
public object GridSectionContent {
|
||||
get => GetValue(GridSectionContentProperty) as object;
|
||||
set => SetValue(GridSectionContentProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GridSectionContentTemplate
|
||||
public static readonly DependencyProperty GridSectionContentTemplateProperty =
|
||||
WPFHelper.create_dp<DataTemplate, GridSettingsView>(nameof(GridSectionContentTemplate));
|
||||
|
||||
public DataTemplate GridSectionContentTemplate {
|
||||
get => GetValue(GridSectionContentTemplateProperty) as DataTemplate;
|
||||
set => SetValue(GridSectionContentTemplateProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static IMultiValueConverter ColumnDisplayNameVisibilityConverter =>
|
||||
ValueConverter.create<string, string, Visibility>((id, header) => id == header ? Visibility.Collapsed : Visibility.Visible);
|
||||
|
||||
@@ -48,4 +68,4 @@ namespace mbts.ui.spark {
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,57 +2,61 @@
|
||||
x:Class="mbts.ui.spark.SimpleGridSettingsDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:orderbook="clr-namespace:bts.shell.orderbook"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
SizeToContent="WidthAndHeight"
|
||||
Style="{StaticResource BTSDialog}"
|
||||
>
|
||||
<Window.Resources>
|
||||
<!--Primitive Constants-->
|
||||
<sys:Double x:Key="VerticalPush1">4</sys:Double>
|
||||
<sys:Double x:Key="HorizontalPush2">8</sys:Double>
|
||||
<sys:Double x:Key="ControlLongWidth">240</sys:Double>
|
||||
<!--Converters-->
|
||||
<cv:BooleanToVisibilityConverter x:Key="DefaultTabVisibilityConverter" VisibilityForTrue="Visible" VisibilityForFalse="Hidden"/>
|
||||
<cv:BooleanToVisibilityConverter x:Key="CustomTabVisibilityConverter" VisibilityForTrue="Hidden" VisibilityForFalse="Visible"/>
|
||||
<cv:ValueMap x:Key="TabHeaderFontWeightConverter" Default="{u:FontWeight Normal}">
|
||||
<cv:KeyValue Key="{u:True}" Value="{u:FontWeight Bold}"/>
|
||||
</cv:ValueMap>
|
||||
<Style TargetType="RadioButton">
|
||||
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
<Setter Property="Padding" Value="6,3"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="RadioButton">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
>
|
||||
<ContentPresenter/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Padding" Value="6,4,6,6"/>
|
||||
<Setter Property="BorderThickness" Value="1,1,1,0"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="False"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" Value="{u:BTSColor UI.Button.mouseover_background}"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{u:BTSColor UI.Button.disabled_foreground}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!--DataTemplates-->
|
||||
<DataTemplate x:Key="GridSectionCoreContentTemplate">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="name_col"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush2}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Font</TextBlock>
|
||||
<Grid Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}">
|
||||
<c:PopupControl HorizontalAlignment="Stretch" Header="{Binding}" Background="{StaticResource ComboBox.Static.Background}">
|
||||
<c:PopupControl.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontFamily="{Binding font_family}" FontSize="{Binding font_size}" FontWeight="{Binding font_weight}" Margin="4,0" Text="{Binding font_display_name}" />
|
||||
</DataTemplate>
|
||||
</c:PopupControl.HeaderTemplate>
|
||||
<c:FontPicker SelectedFontFamily="{Binding font_family}" SelectedFontSize="{Binding font_size}" SelectedFontWeight="{Binding font_weight}"/>
|
||||
</c:PopupControl>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="2">Font Color (default)</TextBlock>
|
||||
<c:ColorPickerPopupWithOpacitySlider Grid.Row="2" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding font_color}" CanUserEditOpacity="False"/>
|
||||
<TextBlock Grid.Row="4">Selection Highlight</TextBlock>
|
||||
<c:ColorPickerPopupWithOpacitySlider Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding selection_highlight}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<!--StyleSelectors-->
|
||||
<u:KeyedStyleSelector x:Key="LeftButtonStyleSelector">
|
||||
<u:StyleSelectorKeyValue Key="{x:Static usp:SimpleGridSettingsDialog.ResetToFactoryKey}">
|
||||
<Style TargetType="Button" BasedOn="{StaticResource DialogSkirtButtonStyle}">
|
||||
@@ -65,17 +69,44 @@
|
||||
</Style>
|
||||
</u:StyleSelectorKeyValue>
|
||||
</u:KeyedStyleSelector>
|
||||
<u:KeyedTemplateSelector x:Key="GridOrLadderSettingsSelector">
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridOrLadderSettingsSelectorKeys.SimpleGrid}">
|
||||
<u:KeyedTemplateSelector x:Key="GridSettingsTemplateSelector">
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridSettingsTemplateKeys.SimpleGrid}">
|
||||
<DataTemplate>
|
||||
<usp:GridSettingsView Margin="8,-8,8,8"/>
|
||||
<usp:GridSettingsView Margin="8,-8,8,8" GridSectionContent="{Binding}" GridSectionContentTemplate="{StaticResource GridSectionCoreContentTemplate}"/>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridOrLadderSettingsSelectorKeys.Ladder}">
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridSettingsTemplateKeys.Ladder}">
|
||||
<DataTemplate>
|
||||
<usp:LadderSettingsView Margin="0,4,0,0"/>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridSettingsTemplateKeys.OrderBook}">
|
||||
<DataTemplate>
|
||||
<usp:GridSettingsView Margin="8,-8,8,8" DataContext="{Binding core_settings_vm}" GridSectionContent="{Binding DataContext.instance_vm, RelativeSource={RelativeSource AncestorType=usp:SimpleGridSettingsDialog}}">
|
||||
<usp:GridSettingsView.GridSectionContentTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Grid.IsSharedSizeScope="True">
|
||||
<ContentControl Content="{Binding core_settings_vm}" ContentTemplate="{StaticResource GridSectionCoreContentTemplate}"/>
|
||||
<CheckBox Content="Show Full Algo Tree">
|
||||
<CheckBox.Margin>
|
||||
<Thickness Top="{StaticResource VerticalPush1}"/>
|
||||
</CheckBox.Margin>
|
||||
<CheckBox.IsChecked>
|
||||
<Binding Path="(orderbook:OrderBookSettingsVM.algo_tree_display_mode)">
|
||||
<Binding.Converter>
|
||||
<cv:ReverseConverter>
|
||||
<cv:BooleanToObjectConverter ValueForFalse="{x:Static orderbook:AlgoTreeDisplayMode.RootAndLeafNodes}" ValueForTrue="{x:Static orderbook:AlgoTreeDisplayMode.FullTree}"/>
|
||||
</cv:ReverseConverter>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</CheckBox.IsChecked>
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</usp:GridSettingsView.GridSectionContentTemplate>
|
||||
</usp:GridSettingsView>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
</u:KeyedTemplateSelector>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
@@ -89,7 +120,7 @@
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
Content="{Binding instance_vm}"
|
||||
ContentTemplateSelector="{StaticResource GridOrLadderSettingsSelector}"
|
||||
ContentTemplateSelector="{StaticResource GridSettingsTemplateSelector}"
|
||||
/>
|
||||
<c:DialogSkirt
|
||||
Grid.Row="2"
|
||||
|
||||
@@ -11,9 +11,10 @@ namespace mbts.ui.spark {
|
||||
public const string ResetToFactoryKey = "Reset", CopyFromOtherKey = "Copy";
|
||||
}
|
||||
|
||||
static class GridOrLadderSettingsSelectorKeys {
|
||||
static class GridSettingsTemplateKeys {
|
||||
public const string
|
||||
SimpleGrid = nameof(SimpleGrid),
|
||||
Ladder = nameof(Ladder);
|
||||
Ladder = nameof(Ladder),
|
||||
OrderBook = nameof(OrderBook);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace mbts.spark {
|
||||
new DialogSkirtItem("Apply", new DelegateCommand(() => committed?.Invoke()))
|
||||
};
|
||||
|
||||
public string key => ui.spark.GridOrLadderSettingsSelectorKeys.SimpleGrid;
|
||||
public string key => ui.spark.GridSettingsTemplateKeys.SimpleGrid;
|
||||
|
||||
public GridSettings create() =>
|
||||
new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()));
|
||||
|
||||
@@ -19,10 +19,8 @@ namespace mbts.ui.converters {
|
||||
return flag ? ValueForTrue : ValueForFalse;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value == ValueForTrue) return true;
|
||||
return false;
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
Equals(ValueForTrue, value);
|
||||
}
|
||||
|
||||
class AnyToObjectConverter : IMultiValueConverter {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
[ContentProperty(nameof(Converter))]
|
||||
class ReverseConverter : IValueConverter {
|
||||
public IValueConverter Converter { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
_assert_converter().ConvertBack(value, targetType, parameter, culture);
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
_assert_converter().Convert(value, targetType, parameter, culture);
|
||||
|
||||
IValueConverter _assert_converter() =>
|
||||
Converter ?? throw new InvalidOperationException($"{nameof(Converter)} is null.");
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ namespace mbts.co2
|
||||
public readonly IntPtr hot;
|
||||
public readonly IntPtr cold_data;
|
||||
public readonly IntPtr cold_header;
|
||||
private readonly IntPtr unused_mbo;
|
||||
}
|
||||
|
||||
[DllImport("libspark")]
|
||||
|
||||
@@ -110,19 +110,21 @@ namespace bts.api.core {
|
||||
the_update.Clear();
|
||||
try {
|
||||
if (event_type == ApiNativeMethods.EventType.TABLE_UPDATED) {
|
||||
foreach (var change in changes) {
|
||||
switch (change.type) {
|
||||
case ApiNativeMethods.ChangeType.REMOVE:
|
||||
the_update.removed_keys.Add(change.key);
|
||||
break;
|
||||
case ApiNativeMethods.ChangeType.REPLACE:
|
||||
the_update.changed_items.Add(converter(parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len))));
|
||||
the_update.changed_keys.Add(change.key);
|
||||
break;
|
||||
case ApiNativeMethods.ChangeType.CREATE:
|
||||
the_update.added_items.Add(converter(parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len))));
|
||||
the_update.added_keys.Add(change.key);
|
||||
break;
|
||||
if (changes != null) {
|
||||
foreach (var change in changes) {
|
||||
switch (change.type) {
|
||||
case ApiNativeMethods.ChangeType.REMOVE:
|
||||
the_update.removed_keys.Add(change.key);
|
||||
break;
|
||||
case ApiNativeMethods.ChangeType.REPLACE:
|
||||
the_update.changed_items.Add(converter(parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len))));
|
||||
the_update.changed_keys.Add(change.key);
|
||||
break;
|
||||
case ApiNativeMethods.ChangeType.CREATE:
|
||||
the_update.added_items.Add(converter(parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len))));
|
||||
the_update.added_keys.Add(change.key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
observer.OnNext(the_update);
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace bts.collections {
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
public static void InsertSorted<T>(this List<T> list, T value, IComparer<T> comparer) {
|
||||
int i = list.BinarySearch(value, comparer);
|
||||
list.Insert(i < 0 ? ~i : i, value);
|
||||
}
|
||||
|
||||
public static T Pop<T>(this IList<T> list, int index) {
|
||||
T rv = list.ElementAt(index);
|
||||
list.RemoveAt(index);
|
||||
|
||||
+9
@@ -20,6 +20,7 @@ namespace bts.collections {
|
||||
readonly DeferrableActionWrapper _refresh;
|
||||
List<TRow> _rows = new List<TRow>();
|
||||
OperableHierarchicalCollectionModel<TRow, T, TKey> _tree;
|
||||
Func<T, bool> _filter;
|
||||
|
||||
public OperableHierarchicalCollection(Func<T, TRow> row_factory, Func<T, TKey> key, Func<T, TKey> parent_key, IComparer<TRow> comparer, TKey no_parent_key = default) {
|
||||
_key = key;
|
||||
@@ -60,6 +61,14 @@ namespace bts.collections {
|
||||
_reset();
|
||||
}
|
||||
}
|
||||
public Func<T, bool> filter {
|
||||
get => _filter;
|
||||
set {
|
||||
_filter = value;
|
||||
_tree.filter = value == null ? null : new Func<TRow, bool>(r => filter(r.value));
|
||||
_reset();
|
||||
}
|
||||
}
|
||||
public int Count => _rows.Count;
|
||||
public int total_row_count => _tree.total_row_count;
|
||||
|
||||
|
||||
+25
-5
@@ -8,6 +8,8 @@ namespace bts.collections {
|
||||
readonly Func<T, TKey> _key;
|
||||
SortedTree<TRow, TKey> _tree;
|
||||
IComparer<TRow> _comparer;
|
||||
Func<TRow, bool> _filter;
|
||||
List<INode<TRow>> _cached_filtered = new List<INode<TRow>>();
|
||||
|
||||
public OperableHierarchicalCollectionModel(Func<T, TRow> row_factory, Func<T, TKey> key, Func<T, TKey> parent_key, TKey no_parent_key, IComparer<TRow> comparer) {
|
||||
_row_factory = row_factory;
|
||||
@@ -17,11 +19,22 @@ namespace bts.collections {
|
||||
|
||||
public IComparer<TRow> comparer {
|
||||
get => _comparer;
|
||||
set => _tree = _tree.Resort(_comparer = value);
|
||||
set {
|
||||
_tree = _tree.Resort(_comparer = value);
|
||||
_cached_filtered = null;
|
||||
}
|
||||
}
|
||||
public Func<TRow, bool> filter {
|
||||
get => _filter;
|
||||
set {
|
||||
_filter = value;
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
}
|
||||
public IEnumerable<TRow> rows {
|
||||
get {
|
||||
return _tree.RootNodes.SelectMany(impl);
|
||||
return _root_nodes.SelectMany(impl);
|
||||
IEnumerable<TRow> impl(INode<TRow> n) {
|
||||
yield return n.value;
|
||||
if (n.value.is_expanded) {
|
||||
@@ -33,6 +46,9 @@ namespace bts.collections {
|
||||
}
|
||||
public int total_row_count { get; private set; }
|
||||
|
||||
IEnumerable<INode<TRow>> _root_nodes =>
|
||||
_filter == null ? _tree.RootNodes : _cached_filtered ?? (_cached_filtered = _tree.RootNodes.filtered(_filter).sorted_hard(_comparer));
|
||||
|
||||
// collapse
|
||||
public void collapse_row(TKey key) => _toggle_is_expanded(key, false);
|
||||
public void collapse_all() => _toggle_is_expanded(false);
|
||||
@@ -49,7 +65,6 @@ namespace bts.collections {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public TRow get_parent(TKey key) =>
|
||||
_tree.TryGetNode(key, out var n) ? n.value : default;
|
||||
|
||||
@@ -73,7 +88,12 @@ namespace bts.collections {
|
||||
if (_tree.Insert(_row_factory(v)))
|
||||
total_row_count++;
|
||||
}
|
||||
foreach (var n in _tree.RootNodes)
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
|
||||
void _refresh_hierarchical_props() {
|
||||
foreach (var n in _root_nodes)
|
||||
impl(n, 0);
|
||||
void impl(INode<TRow> n, int depth_level) {
|
||||
if (n.value.depth_level != depth_level) {
|
||||
@@ -107,4 +127,4 @@ namespace bts.collections {
|
||||
|
||||
T _value_selector(TRow row) => row.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using mbts.utils;
|
||||
using bts.utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.collections {
|
||||
public interface INode<T> {
|
||||
public interface INode<out T> {
|
||||
T value { get; }
|
||||
IEnumerable<INode<T>> inner { get; }
|
||||
}
|
||||
@@ -18,6 +18,44 @@ namespace bts.collections {
|
||||
yield return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<INode<T>> filtered<T>(this IEnumerable<INode<T>> root_nodes, Func<T, bool> filter) {
|
||||
return impl(root_nodes);
|
||||
IEnumerable<INode<T>> impl(IEnumerable<INode<T>> nodes) {
|
||||
foreach (var n in nodes) {
|
||||
if (filter(n.value)) {
|
||||
yield return new Node<T>(n.value, impl(n.inner));
|
||||
} else {
|
||||
foreach (var _n in impl(n.inner))
|
||||
yield return _n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<INode<T>> sorted_hard<T>(this IEnumerable<INode<T>> root_nodes, IComparer<T> comparer) {
|
||||
var node_comp = comparer.wrap<T, INode<T>>(n => n.value);
|
||||
var result = new List<INode<T>>(impl(root_nodes));
|
||||
result.Sort(node_comp);
|
||||
return result;
|
||||
IEnumerable<INode<T>> impl(IEnumerable<INode<T>> nodes) {
|
||||
foreach (var n in nodes) {
|
||||
var inner = new List<INode<T>>(impl(n.inner));
|
||||
inner.Sort(node_comp);
|
||||
yield return new Node<T>(n.value, inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Node<T> : INode<T> {
|
||||
public Node(T value, IEnumerable<INode<T>> inner) {
|
||||
this.value = value;
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
public T value { get; }
|
||||
public IEnumerable<INode<T>> inner { get; }
|
||||
}
|
||||
}
|
||||
|
||||
public class SortedTree<T, TKey> : IEnumerable<T> where TKey : IEquatable<TKey> {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace bts.api.orderman {
|
||||
|
||||
public static class OrderUtilities {
|
||||
public static NativeOrderStateImmutable? native_order_state(this OrderStateImmutable order) {
|
||||
switch(order.CustomCase) {
|
||||
case OrderState.CustomOneofCase.Market:
|
||||
return order.Market.NativeState;
|
||||
case OrderState.CustomOneofCase.Limit:
|
||||
return order.Limit.NativeState;
|
||||
case OrderState.CustomOneofCase.Stop:
|
||||
return order.Stop.NativeState;
|
||||
case OrderState.CustomOneofCase.StopLimit:
|
||||
return order.StopLimit.NativeState;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -78,7 +78,7 @@ namespace bts.tests
|
||||
return securities;
|
||||
}
|
||||
|
||||
[Test(Timeout = 30)]
|
||||
[Test(Timeout = 30)]
|
||||
public async Task test_position_limits() {
|
||||
string test_symbol = "CL";
|
||||
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
using ManyConsole;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CommandLine;
|
||||
|
||||
namespace bts {
|
||||
public class Configcheck : ConsoleCommand {
|
||||
public Configcheck() {
|
||||
IsCommand("configcheck", "Ye olde Configcheck");
|
||||
HasAdditionalArguments(null, " [Keys to check]");
|
||||
}
|
||||
public override int Run(string[] args) {
|
||||
mbts.config.Configuration.configcheck(args.Length, args.ToArray());
|
||||
|
||||
[Verb("configcheck", HelpText="Ye olde Configcheck")]
|
||||
public class ConfigcheckOptions {
|
||||
[Value(0, MetaName="keys", HelpText="Keys to print")]
|
||||
public IEnumerable<string> keys { get; set; }
|
||||
}
|
||||
public class Configcheck {
|
||||
public static int Run(ConfigcheckOptions options) {
|
||||
var keys = options.keys.ToArray();
|
||||
mbts.config.Configuration.configcheck(keys.Length, keys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ManyConsole {
|
||||
public static class ConsoleCommandEx {
|
||||
public static string get_argument(this ConsoleCommand _, string arg_name) {
|
||||
var arg = Environment.GetCommandLineArgs().FirstOrDefault(str => str.StartsWith("--"+arg_name));
|
||||
if (arg != null) {
|
||||
var parts = arg.Split(new[] { '=' }, 2);
|
||||
if (parts.Length > 1) {
|
||||
return parts[1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.co2;
|
||||
using bts.test;
|
||||
using CommandLine;
|
||||
using mbts.co2;
|
||||
using mbts.config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts {
|
||||
|
||||
[Verb("orderstress", HelpText = "Create a bunch of orders")]
|
||||
public class OrderStressOptions {
|
||||
// Maybe options to create fewer orders or sleep
|
||||
|
||||
[Option('s', "sleep", HelpText = "Sleep ms between order submission", Default = 100)]
|
||||
public int sleep { get; set; }
|
||||
|
||||
[Option('d', "depth", HelpText = "How many orders per side", Default = 10u)]
|
||||
public uint depth { get; set; }
|
||||
|
||||
[Option('q', "quanityt", HelpText = "Order quantity", Default = 1u)]
|
||||
public uint quantity { get; set; }
|
||||
};
|
||||
|
||||
public struct Market {
|
||||
public SecurityImmutable security;
|
||||
public IntPrice? bid;
|
||||
public IntPrice? ask;
|
||||
}
|
||||
|
||||
public static class OrderStress {
|
||||
static IEnumerable<Market> all_markets(ServiceContext ctx) {
|
||||
var channels =
|
||||
UserSymbol.get_all()
|
||||
.Select(u =>
|
||||
new SecurityChannel() {
|
||||
Time = 0,
|
||||
Flags = (int)(MDRequest.Types.Flags.Direct | MDRequest.Types.Flags.Implied),
|
||||
Type = u.type,
|
||||
Symbol = u.symbol,
|
||||
Exchange = u.exchange
|
||||
}
|
||||
);
|
||||
var request = new MDRequest() { Host = "system_test" };
|
||||
request.Channels.AddRange(channels);
|
||||
|
||||
var relay = ctx.locate<MarketDataRelay>();
|
||||
System.Threading.Thread.Sleep(100);
|
||||
var result = relay.requestmd(request);
|
||||
|
||||
foreach (var ch in result.Channels) {
|
||||
foreach (var update in ch.Updates) {
|
||||
if (update.Security != null) {
|
||||
var m = new Market() {
|
||||
security = new SecurityImmutable(update.Security),
|
||||
bid = best(
|
||||
(a,b) => a > b ? a : b,
|
||||
update.Direct?.Bids?.FirstOrDefault(), update.Implied?.Bids?.FirstOrDefault()),
|
||||
ask = best(
|
||||
(a,b) => a < b ? a : b,
|
||||
update.Direct?.Asks?.FirstOrDefault(), update.Implied?.Asks?.FirstOrDefault())
|
||||
};
|
||||
if (m.bid.HasValue || m.ask.HasValue) {
|
||||
yield return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPrice? best(Func<IntPrice, IntPrice,IntPrice> comp, params PriceSizeMessage[] ps) {
|
||||
IntPrice? result = null;
|
||||
foreach (var p in ps) {
|
||||
if (p != null) {
|
||||
var ip = new IntPrice(p.Mantissa, (sbyte)p.Exponent);
|
||||
if (result == null) {
|
||||
result = ip;
|
||||
}
|
||||
else {
|
||||
result = comp(result.Value, ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Create mkorder(uint security, double price, uint size, Side side) {
|
||||
return new Create {
|
||||
Price = price,
|
||||
Quantity = size,
|
||||
NewOrder = new OrderDefinition {
|
||||
SecurityKey = security,
|
||||
Side = side,
|
||||
TimeInForce = TimeInForce.Day,
|
||||
ManualOrderIndicator = ManualOrderIndicator.Yes,
|
||||
CtiCode = CTICode.CtiCode1,
|
||||
CustomerOrFirm = CustomerOrFirm.Firm,
|
||||
AccountId = 1,
|
||||
UserId = 1,
|
||||
CustomDef = new CustomOrderDefinition {
|
||||
Limit = new LimitOrderDefinition()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static int Run(OrderStressOptions o) {
|
||||
|
||||
var ctx = new ServiceContext();
|
||||
ConsoleEx.WriteLine("Please log in to Spark", ConsoleColor.Yellow);
|
||||
ConsoleEx.Write("Username: ", ConsoleColor.Yellow);
|
||||
var name = Console.ReadLine();
|
||||
ConsoleEx.Write("Password: ", ConsoleColor.Yellow);
|
||||
var pw = Console.ReadLine();
|
||||
|
||||
var login_result = ctx.login(name, pw);
|
||||
if (!login_result.Result.success) {
|
||||
ConsoleEx.WriteLine("Invalid Credentials", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
if (Configuration.get<config.DeploymentType>().type.ToUpper() == "PROD") {
|
||||
ConsoleEx.WriteLine("Refusing to run on production system", ConsoleColor.Red);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var orders = ctx.locate<OrderService>();
|
||||
foreach (var m in all_markets(ctx)) {
|
||||
ConsoleEx.WriteLine(m.security.security_desc(), ConsoleColor.White);
|
||||
var tick = m.security.ContractSpec.LowTick;
|
||||
if (m.bid.HasValue) {
|
||||
// start at bid and place 1 order at 10 levels
|
||||
for (var x=0; x < o.depth; ++x) {
|
||||
var price = m.bid.Value.price() - (tick * x);
|
||||
ConsoleEx.WriteLine($"Buy {o.quantity} at {price}", ConsoleColor.Blue);
|
||||
orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Buy));
|
||||
System.Threading.Thread.Sleep(o.sleep);
|
||||
}
|
||||
}
|
||||
if (m.ask.HasValue) {
|
||||
for (var x = 0; x < o.depth; ++x) {
|
||||
var price = m.ask.Value.price() + (tick * x);
|
||||
ConsoleEx.WriteLine($"Sell {o.quantity} at {price}", ConsoleColor.Red);
|
||||
orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Sell));
|
||||
System.Threading.Thread.Sleep(o.sleep);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,32 +6,33 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive;
|
||||
using ManyConsole;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
|
||||
namespace sparkcmd {
|
||||
public class ScriptClientCommand : ConsoleCommand {
|
||||
bool _server = false;
|
||||
string _host;
|
||||
string _logfile;
|
||||
[Verb("script", HelpText="Remote control for shell diagnostic host")]
|
||||
public class ScriptClientOptions {
|
||||
[Option('s', "server", HelpText="Run a script server for testing.")]
|
||||
public bool server { get; set; }
|
||||
|
||||
public ScriptClientCommand() {
|
||||
IsCommand("script", "Remote control for shell diagnostic host");
|
||||
HasOption("s|server", "Run a script server for testing.", x => _server = true);
|
||||
HasOption("h|host", "Connect to {host}", h => _host = h);
|
||||
HasOption("f|fromfile", "Read commands from file instead of stdin", f => _logfile = f);
|
||||
}
|
||||
public override int Run(string[] args) {
|
||||
if (_server) {
|
||||
[Option('h', "host", HelpText="Connect to {host}")]
|
||||
public string host { get; set; }
|
||||
|
||||
[Option('f', "fromfile", HelpText="Read commands from file instead of stdin")]
|
||||
public string file { get; set; }
|
||||
|
||||
}
|
||||
public class ScriptClientCommand {
|
||||
public static int Run(ScriptClientOptions o) {
|
||||
if (o.server) {
|
||||
ScriptClient.runserver();
|
||||
}
|
||||
else {
|
||||
var host = string.IsNullOrEmpty(_host) ? args.First() : _host;
|
||||
if (string.IsNullOrEmpty(_logfile) && File.Exists(_logfile)) {
|
||||
ScriptClient.start(host, File.OpenRead(_logfile));
|
||||
if (string.IsNullOrEmpty(o.file) && File.Exists(o.file)) {
|
||||
ScriptClient.start(o.host, File.OpenRead(o.file));
|
||||
}
|
||||
else {
|
||||
ScriptClient.start(host, Console.OpenStandardInput());
|
||||
ScriptClient.start(o.host, Console.OpenStandardInput());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using bts.api.core;
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using CommandLine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,26 +8,44 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts {
|
||||
class TailService : ConsoleCommand {
|
||||
|
||||
enum PrintFormat {
|
||||
ToString,
|
||||
Json
|
||||
}
|
||||
[Verb("tail", HelpText="'console dsqa'")]
|
||||
class TailServiceOptions {
|
||||
[Option('m', "method", Required=true, HelpText = "'[ServiceName].[Method]' to call")]
|
||||
public string method { get;set; }
|
||||
|
||||
[Option('t', "time", HelpText="Include timestamp")]
|
||||
public bool time { get; set; }
|
||||
|
||||
[Option('p', "path", HelpText="Path inside the row to use for display. Ex: 'Id' or 'Name' ")]
|
||||
public string path { get; set; }
|
||||
|
||||
[Option('a', "all", HelpText="Include 'all' rows on every print")]
|
||||
public bool all { get; set; }
|
||||
|
||||
[Option('j', "json", HelpText="Format rows as json")]
|
||||
public bool json { get; set; }
|
||||
}
|
||||
class TailService {
|
||||
static bool _all = false;
|
||||
static PrintFormat _format = PrintFormat.ToString;
|
||||
|
||||
static bool _timestamp = false;
|
||||
public TailService() {
|
||||
void ignore(string _) { }
|
||||
IsCommand("tailservice", "Tail updates to named service api. Ex: tail --method=SyntheticSecurityService.metadata");
|
||||
HasRequiredOption("method", "Service.method to tail", ignore);
|
||||
HasOption("time", "Include timestamp", _ => _timestamp = true);
|
||||
// The following are not implemented. If you need them get to work.
|
||||
HasOption("path", "Path inside the row to use for display. Ex: 'Id' or 'Name' ", ignore);
|
||||
HasOption("all", "Invlude 'all' rows on every print", _ => _all = true);
|
||||
HasAdditionalArguments(null, " [nothing]");
|
||||
}
|
||||
public override int Run(string[] remainingArguments) {
|
||||
var arg = this.get_argument("method");
|
||||
var split = arg.Split('.');
|
||||
public static int Run(TailServiceOptions o) {
|
||||
var split = o.method.Split('.');
|
||||
if (split.Length != 2) {
|
||||
Console.WriteLine("Try --method=[ServiceName].[Method]");
|
||||
Console.WriteLine("Try --method [ServiceName].[Method]");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (o.json) {
|
||||
_format = PrintFormat.Json;
|
||||
}
|
||||
|
||||
tail(split[0], split[1]);
|
||||
return 0;
|
||||
}
|
||||
@@ -46,7 +64,17 @@ namespace bts {
|
||||
Console.Write(" ");
|
||||
}
|
||||
if (_all) { }
|
||||
Console.WriteLine(value);
|
||||
|
||||
switch(_format) {
|
||||
case PrintFormat.Json:
|
||||
dynamic dv = value;
|
||||
var json = Newtonsoft.Json.JsonConvert.SerializeObject(new { dv.added, dv.removed, dv.changed });
|
||||
Console.WriteLine(json);
|
||||
break;
|
||||
case PrintFormat.ToString:
|
||||
Console.WriteLine(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void tail(string service_name, string method_name) {
|
||||
|
||||
@@ -2,35 +2,74 @@ using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.synthetic;
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using bts.md;
|
||||
using CommandLine;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace bts {
|
||||
public class ServiceTest : ConsoleCommand {
|
||||
bool _synthetic;
|
||||
bool _user;
|
||||
bool _admin;
|
||||
|
||||
public ServiceTest() {
|
||||
IsCommand("service", "Put code here for testing during service development");
|
||||
HasOption("synthetic", "Run synthetic test", _ => _synthetic = true);
|
||||
HasOption("user", "user test", _ => _user = true);
|
||||
HasOption("admin", "admin test", _ => _admin = true);
|
||||
}
|
||||
public override int Run(string[] remainingArguments) {
|
||||
if (_synthetic) {
|
||||
public class ServiceTestOptions {
|
||||
[Option(nameof(synthetic))]
|
||||
public bool synthetic { get; set; }
|
||||
[Option(nameof(user))]
|
||||
public bool user { get; set; }
|
||||
[Option(nameof(admin))]
|
||||
public bool admin { get; set; }
|
||||
|
||||
[Option(nameof(mbo))]
|
||||
public bool mbo { get; set; }
|
||||
|
||||
[Option("key")]
|
||||
public UInt32 key { get; set; }
|
||||
|
||||
[Option("side")]
|
||||
public api.Side side { get; set; }
|
||||
}
|
||||
|
||||
public class ServiceTest {
|
||||
public static int Run(ServiceTestOptions o) {
|
||||
if (o.synthetic) {
|
||||
synthetic_test();
|
||||
}
|
||||
if (_user) {
|
||||
if (o.user) {
|
||||
user_test();
|
||||
}
|
||||
if (_admin) {
|
||||
if (o.admin) {
|
||||
admin_test();
|
||||
}
|
||||
if (o.mbo) {
|
||||
mbo_test(o);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static string try_get(string[] args, int index) {
|
||||
if (args.Length < index) {
|
||||
return args[index];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static void mbo_test(ServiceTestOptions o) {
|
||||
var key = o.key;
|
||||
var side = o.side;
|
||||
using (var ctx = new ServiceContext()) {
|
||||
var mbo = ctx.locate<MBOService>();
|
||||
var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key });
|
||||
|
||||
Console.WriteLine($"Order data for {data.SecurityId}");
|
||||
var vector = side == api.Side.Buy ? data.Bid : data.Ask;
|
||||
var price = 0.0;
|
||||
foreach(var e in vector) {
|
||||
if (e.Price != price) {
|
||||
price = e.Price;
|
||||
Console.WriteLine("================");
|
||||
}
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void synthetic_test() {
|
||||
using (var ctx = new ServiceContext()) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using ManyConsole;
|
||||
using System.Reflection;
|
||||
using CommandLine;
|
||||
|
||||
namespace bts {
|
||||
|
||||
public class SettinsManagerCommand : ConsoleCommand {
|
||||
public SettinsManagerCommand() {
|
||||
IsCommand("SettingsManager", "Copy workspaces around");
|
||||
}
|
||||
[Verb("settingsmanager", HelpText="Copy workspaces around")]
|
||||
public class SettingsManagerOptions { }
|
||||
|
||||
public override int Run(string[] remainingArguments) {
|
||||
public class SettingsManagerCommand {
|
||||
public static int Run(SettingsManagerOptions _) {
|
||||
var asm = Assembly.Load("spark");
|
||||
var type = asm.GetType("bts.settings.SettingsManagerTool");
|
||||
var run = type.GetMethod("run", BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using System;
|
||||
using mbts;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,64 +7,73 @@ using bts.api.test;
|
||||
using System.Threading.Tasks;
|
||||
using mbts.config;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace sparkcmd {
|
||||
public class TestCommand : ConsoleCommand {
|
||||
uint _timeout = 0;
|
||||
uint _parallel = 1;
|
||||
bool _list;
|
||||
|
||||
TestType test_type = TestType.Unit;
|
||||
[Verb("test", HelpText="Run Tests")]
|
||||
public class TestCommandOptions {
|
||||
|
||||
bool self_contained = false;
|
||||
[Option('t', "timeout", HelpText="Timeout unit tets", Default=0u)]
|
||||
public uint timeout { get; set; }
|
||||
[Option('l', "list", HelpText="List tests")]
|
||||
public bool list { get; set; }
|
||||
[Option('i', "insular", HelpText="Tests run sparkd and use their own config (if specified)")]
|
||||
public bool self_contained { get; set; }
|
||||
|
||||
public TestCommand() {
|
||||
IsCommand("test", "Run managed unit tests");
|
||||
// i comes thorugh as "t" which seems daft.
|
||||
HasOption("t|timeout", "Timeout unit tests", i => _timeout = 10);
|
||||
HasOption<uint>("n|parallel", "How many tests to run in parallel", i => _parallel = i);
|
||||
HasOption("l|list", "List all tests", _ => _list = true);
|
||||
HasOption("unit","Run unit tests", _ => test_type = TestType.Unit);
|
||||
HasOption("system","Run system tests", _ => test_type = TestType.System);
|
||||
HasOption("shell","Run shell tests", _ => test_type = TestType.Shell);
|
||||
HasOption("i|insular|selfcontained", "Tests run sparkd and use their own config (if specified)", _ => self_contained = true);
|
||||
HasAdditionalArguments(null, " [Test List]");
|
||||
[Option("type", HelpText ="Run all tests of type [Unit|System|Shell]")]
|
||||
public TestType type { get; set; }
|
||||
|
||||
|
||||
[Value(1, MetaName="Tests", HelpText="Test list")]
|
||||
public IEnumerable<string> tests { get; set; }
|
||||
|
||||
}
|
||||
public static class TestCommand {
|
||||
static TestType test_type(string t) {
|
||||
switch(t.ToLower()) {
|
||||
case "unit": return TestType.Unit;
|
||||
case "system": return TestType.System;
|
||||
case "shell": return TestType.Shell;
|
||||
}
|
||||
return TestType.Unit;
|
||||
}
|
||||
|
||||
public override int Run(string[] tests) {
|
||||
if (_list) {
|
||||
list_tests();
|
||||
public static int Run(TestCommandOptions o) {
|
||||
Console.WriteLine(JsonConvert.SerializeObject(o));
|
||||
|
||||
if (o.list) {
|
||||
list_tests((o.type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Configuration.initialize_for_test();
|
||||
|
||||
if (_timeout == 0 && tests.Length == 1 && !self_contained) {
|
||||
if (o.timeout == 0 && o.tests.Count() == 1 && !o.self_contained) {
|
||||
//System.Threading.Thread.Sleep(5000);
|
||||
using (var trr = new TestResultReceiver(true)) {
|
||||
InProcessTestRunner.run_test_synchronously(tests[0], Enumerator, trr.get_reporter());
|
||||
InProcessTestRunner.run_test_synchronously(o.tests.First(), Enumerator, trr.get_reporter());
|
||||
trr.print_summary();
|
||||
return trr.ErrorCount;
|
||||
}
|
||||
}
|
||||
else if (tests.Length > 0) {
|
||||
return run_tests(Enumerator.match(tests));
|
||||
else if (o.tests.Count() > 0) {
|
||||
return run_tests(o, Enumerator.match(o.tests));
|
||||
}
|
||||
else {
|
||||
return run_tests(Enumerator.get_of_type(test_type));
|
||||
return run_tests(o, Enumerator.get_of_type(o.type));
|
||||
}
|
||||
}
|
||||
|
||||
Lazy<TestEnumerator> _enumerator = new Lazy<TestEnumerator>(() => new TestEnumerator("spark_test"));
|
||||
TestEnumerator Enumerator => _enumerator.Value;
|
||||
static Lazy<TestEnumerator> _enumerator = new Lazy<TestEnumerator>(() => new TestEnumerator("spark_test"));
|
||||
static TestEnumerator Enumerator => _enumerator.Value;
|
||||
|
||||
int run_tests(IEnumerable<TestMethod> tests) {
|
||||
static int run_tests(TestCommandOptions o, IEnumerable<TestMethod> tests) {
|
||||
var runner = new TestRunner();
|
||||
// waits for all child processes to exit or time out
|
||||
return runner.run_tests(tests, _timeout, self_contained);
|
||||
return runner.run_tests(tests, o.timeout, o.self_contained);
|
||||
}
|
||||
|
||||
void list_tests() {
|
||||
static void list_tests(TestType test_type) {
|
||||
Console.WriteLine("All tests: ");
|
||||
foreach (var t in Enumerator.get_groups_of_type(test_type)) {
|
||||
ConsoleEx.WriteLine(t.name, ConsoleColor.Green);
|
||||
|
||||
@@ -2,16 +2,40 @@
|
||||
using bts.api.core;
|
||||
using bts.api.synthetic;
|
||||
using bts.api.test;
|
||||
using ManyConsole;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
using bts;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace sparkcmd {
|
||||
class Program {
|
||||
|
||||
// static object option<T>(Func<T,int> run) {return run;}
|
||||
// static Type argType(object arg) {
|
||||
// return arg.GetType().GetGenericArguments().First();
|
||||
// }
|
||||
// static int Run(Func<IEnumerable<Error>,int> on_error, params object[] args) {
|
||||
// var types = args.Select(argType).ToArray();
|
||||
// var parse = CommandLine.Parser.Default.GetType().GetMethod("ParseArguments", BindingFlags.Public).MakeGenericMethod(types);
|
||||
// return 3;
|
||||
// }
|
||||
static int Main(string[] args) {
|
||||
mbts.config.Configuration.initialize();
|
||||
var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
|
||||
return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
|
||||
mbts.utils.BTSNativeMethods.provide_command_line(args, args.Length);
|
||||
// note: this can be made to infer the options type list from the list of delegates
|
||||
return Parser.Default
|
||||
.ParseArguments<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions,OrderStressOptions >(args)
|
||||
.MapResult<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions,OrderStressOptions,int>(
|
||||
Configcheck.Run,
|
||||
ScriptClientCommand.Run,
|
||||
TailService.Run,
|
||||
ServiceTest.Run,
|
||||
SettingsManagerCommand.Run,
|
||||
TestCommand.Run,
|
||||
OrderStress.Run,
|
||||
errors => 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net471;netcoreapp2.1</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win7-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
|
||||
<Authors>Blue Trading Systems</Authors>
|
||||
<Company>Blue Trading Systems</Company>
|
||||
<Product>Spark</Product>
|
||||
<Platform>x64</Platform>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../spark_api/spark_api.csproj" />
|
||||
<!--<ProjectReference Include="..\spark\Spark.csproj" />-->
|
||||
<ProjectReference Include="..\spark_core\spark_core.csproj" />
|
||||
<ProjectReference Include="..\spark_test\spark_test.csproj" />
|
||||
<!--<Proto3 Include="**/*.proto" />-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ManyConsole" Version="1.0.0.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net471;netcoreapp2.1</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win7-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
|
||||
<Authors>Blue Trading Systems</Authors>
|
||||
<Company>Blue Trading Systems</Company>
|
||||
<Product>Spark</Product>
|
||||
<Platform>x64</Platform>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../spark_api/spark_api.csproj" />
|
||||
<!--<ProjectReference Include="..\spark\Spark.csproj" />-->
|
||||
<ProjectReference Include="..\spark_core\spark_core.csproj" />
|
||||
<ProjectReference Include="..\spark_test\spark_test.csproj" />
|
||||
<!--<Proto3 Include="**/*.proto" />-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServices.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/core/IOrderServices.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderLine truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServices.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/core/IOrderServices.cLine truncated
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/tests/AuthTokenTests.cpp;utils/thread_manager.cpp)
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/tests/AuthTokenTests.cpp;utils/thread_manager.cpp)
|
||||
@@ -176,7 +176,7 @@ void safe_call_subscription_callback(raw_subscription_callback cb, EventType typ
|
||||
if (updates.size() > 0)
|
||||
cb(type, &updates[0], updates.size(), extra);
|
||||
else
|
||||
cb(type, nullptr, updates.size(), extra);
|
||||
cb(type, nullptr, 0, extra);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "ApiException.h"
|
||||
#include "RawUpdate.h"
|
||||
#include "ServiceContext.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
#include <rxcpp/rx.hpp>
|
||||
#include <functional>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||
@@ -12,6 +14,17 @@
|
||||
namespace bts {
|
||||
namespace api {
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> deserialize(const char* buffer, size_t length) {
|
||||
google::protobuf::io::ArrayInputStream stream(buffer, length);
|
||||
auto item = std::make_shared<T>();
|
||||
if (item->ParseFromZeroCopyStream(&stream)) {
|
||||
return item;
|
||||
}
|
||||
LOG(Api,Error,"Failed to deserialize proto from api stream. This is likely fatal.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
class ClientChannel
|
||||
{
|
||||
int _id;
|
||||
@@ -80,29 +93,29 @@ public:
|
||||
}
|
||||
else {
|
||||
bool first_update = true;
|
||||
auto cb = [observer, first_update](EventType event_type, const StreamUpdate* changes, int change_count) mutable {
|
||||
auto cb = [observer, first_update, qualifier](EventType event_type, const StreamUpdate* changes, int change_count) mutable {
|
||||
if (event_type == EventType::TABLE_UPDATED) {
|
||||
std::vector<std::shared_ptr<const T>> added_items;
|
||||
std::vector<std::shared_ptr<const T>> added_items, changed_items;
|
||||
std::vector<int> added_keys,
|
||||
removed_keys;
|
||||
changed_keys,
|
||||
removed_keys;
|
||||
for (size_t x = 0; x < change_count; ++x) {
|
||||
const StreamUpdate& change = changes[x];
|
||||
if (change.type != StreamUpdate::REMOVE) {
|
||||
added_keys.reserve(change_count);
|
||||
added_items.reserve(change_count);
|
||||
added_keys.push_back(change.key);
|
||||
google::protobuf::io::ArrayInputStream stream(change.buffer, change.buffer_len);
|
||||
auto item = std::make_shared<T>();
|
||||
if (item->ParseFromZeroCopyStream(&stream)) {
|
||||
added_items.push_back(move(item));
|
||||
}
|
||||
}
|
||||
if (change.type != StreamUpdate::CREATE) {
|
||||
removed_keys.reserve(change_count);
|
||||
removed_keys.push_back(change.key);
|
||||
switch(change.type) {
|
||||
case StreamUpdate::REMOVE:
|
||||
removed_keys.push_back(change.key);
|
||||
break;
|
||||
case StreamUpdate::REPLACE:
|
||||
changed_items.push_back(deserialize<T>(change.buffer, change.buffer_len));
|
||||
changed_keys.push_back(change.key);
|
||||
break;
|
||||
case StreamUpdate::CREATE:
|
||||
added_items.push_back(deserialize<T>(change.buffer, change.buffer_len));
|
||||
added_keys.push_back(change.key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
observer.on_next(RawUpdate<std::shared_ptr<const T>>(added_items, added_keys, removed_keys));
|
||||
observer.on_next(RawUpdate<std::shared_ptr<const T>>(added_items, added_keys, changed_items, changed_keys, removed_keys));
|
||||
}
|
||||
else if (event_type == EventType::TABLE_CREATED) {
|
||||
if (!first_update) {
|
||||
|
||||
@@ -6,10 +6,16 @@ namespace api {
|
||||
|
||||
template <typename T>
|
||||
struct RawUpdate {
|
||||
RawUpdate(std::vector<T>& added_items, std::vector<int>& added_keys, std::vector<int>& removed_keys) :
|
||||
RawUpdate(std::vector<T>& added_items,
|
||||
std::vector<int>& added_keys,
|
||||
std::vector<T>& changed_items,
|
||||
std::vector<int>& changed_keys,
|
||||
std::vector<int>& removed_keys) :
|
||||
is_reset(false),
|
||||
added_items(std::move(added_items)),
|
||||
added_keys(std::move(added_keys)),
|
||||
changed_items(std::move(changed_items)),
|
||||
changed_keys(std::move(changed_keys)),
|
||||
removed_keys(std::move(removed_keys))
|
||||
{}
|
||||
|
||||
@@ -20,12 +26,16 @@ namespace api {
|
||||
bool is_reset;
|
||||
std::vector<T> added_items;
|
||||
std::vector<int> added_keys;
|
||||
|
||||
std::vector<T> changed_items;
|
||||
std::vector<int> changed_keys;
|
||||
|
||||
std::vector<int> removed_keys;
|
||||
|
||||
private:
|
||||
RawUpdate() :
|
||||
is_reset(true),
|
||||
added_items(), added_keys(), removed_keys()
|
||||
added_items(), added_keys(), changed_items(), changed_keys(), removed_keys()
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,12 +9,21 @@
|
||||
namespace bts {
|
||||
namespace api {
|
||||
|
||||
template <typename T>
|
||||
class Change {
|
||||
T _old, _new;
|
||||
public:
|
||||
Change(const T& old_value, const T& new_value) : _old(old_value), _new(new_value) { }
|
||||
const T& previous() const { return _old; }
|
||||
const T& current() const { return _new; }
|
||||
};
|
||||
|
||||
template <typename T, typename TKey, typename ServiceType>
|
||||
struct Update {
|
||||
Update(std::vector<T>& all, std::vector<T>& added, std::vector<T>& removed) :
|
||||
Update(std::vector<T>& all, std::vector<T>& added, std::vector<Change<T>> changed, std::vector<T>& removed) :
|
||||
_all_items(std::move(all)),
|
||||
_added_items(std::move(added)),
|
||||
_changed_items(std::move(changed)),
|
||||
_removed_items(std::move(removed))
|
||||
{}
|
||||
|
||||
@@ -22,17 +31,20 @@ namespace api {
|
||||
Update(Update&& other) :
|
||||
_all_items(std::move(other._all_items)),
|
||||
_added_items(std::move(other._added_items)),
|
||||
_changed_items(std::move(other._changed_items)),
|
||||
_removed_items(std::move(other._removed_items))
|
||||
{}
|
||||
|
||||
TKey key(const T& t) const { return ServiceType::key(t); }
|
||||
const std::vector<T>& all() const { return _all_items; }
|
||||
const std::vector<T>& added() const { return _added_items; }
|
||||
const std::vector<Change<T>>& changed() const { return _changed_items; }
|
||||
const std::vector<T>& removed() const { return _removed_items; }
|
||||
|
||||
private:
|
||||
std::vector<T> _all_items;
|
||||
std::vector<T> _added_items;
|
||||
std::vector<Change<T>> _changed_items;
|
||||
std::vector<T> _removed_items;
|
||||
};
|
||||
|
||||
@@ -49,9 +61,12 @@ namespace api {
|
||||
}
|
||||
state->clear();
|
||||
std::vector<T> all, added;
|
||||
return Update<T, TKey, ServiceType>(all, added, removed);
|
||||
std::vector<Change<T>> changed;
|
||||
return Update<T, TKey, ServiceType>(all, added, changed, removed);
|
||||
}
|
||||
else {
|
||||
//
|
||||
// Remove
|
||||
std::vector<T> removed;
|
||||
removed.reserve(raw.removed_keys.size());
|
||||
for (int key : raw.removed_keys) {
|
||||
@@ -61,15 +76,28 @@ namespace api {
|
||||
state->erase(iter);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Add
|
||||
for (size_t x = 0; x < raw.added_keys.size(); ++x) {
|
||||
(*state)[raw.added_keys[x]] = raw.added_items[x];
|
||||
}
|
||||
//
|
||||
// Change
|
||||
std::vector<Change<T>> changed;
|
||||
changed.reserve(raw.changed_keys.size());
|
||||
for (size_t x = 0; x < raw.changed_keys.size(); ++x) {
|
||||
changed.push_back(Change<T>{(*state)[raw.changed_keys[x]], raw.changed_items[x]});
|
||||
(*state)[raw.changed_keys[x]] = raw.changed_items[x];
|
||||
}
|
||||
//
|
||||
// All
|
||||
std::vector<T> all;
|
||||
all.reserve(state->size());
|
||||
for (const auto& item : *state) {
|
||||
all.push_back(item.second);
|
||||
}
|
||||
return Update<T, TKey, ServiceType>(all, raw.added_items, removed);
|
||||
|
||||
return Update<T, TKey, ServiceType>(all, raw.added_items, changed, removed);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
syntax="proto3";
|
||||
package bts.md;
|
||||
option csharp_namespace="bts.md";
|
||||
option cc_enable_arenas=true;
|
||||
import "lib/api/apioptions.proto";
|
||||
import "lib/api/apicore.proto";
|
||||
|
||||
message OrderPIQ {
|
||||
uint32 order_id = 1 [(bts.api.key)=true];
|
||||
uint32 position = 2;
|
||||
}
|
||||
|
||||
message OrderPosition {
|
||||
uint64 exchange_id = 1;
|
||||
uint32 order_id = 2;
|
||||
float price = 10;
|
||||
int32 size = 11;
|
||||
}
|
||||
message PositionData {
|
||||
uint32 security_id = 1;
|
||||
repeated OrderPosition bid = 10;
|
||||
repeated OrderPosition ask = 20;
|
||||
}
|
||||
message MBOSecurityQuery {
|
||||
uint32 security_id = 1;
|
||||
}
|
||||
|
||||
service MBOService {
|
||||
rpc piq (bts.api.VoidMessage) returns (stream OrderPIQ);
|
||||
rpc get_orders_for_security (MBOSecurityQuery) returns (PositionData);
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ message ExpirationNameList {
|
||||
message ExpirationNameListReply {
|
||||
repeated ExpirationNameList securities = 2;
|
||||
}
|
||||
|
||||
message SecurityKeyList {
|
||||
repeated uint32 keys = 1;
|
||||
}
|
||||
@@ -28,6 +27,5 @@ service MarketDataRelay {
|
||||
|
||||
rpc request_products(bts.api.VoidMessage) returns (ProductListReply);
|
||||
rpc request_names(bts.api.VoidMessage) returns (ExpirationNameListReply);
|
||||
|
||||
rpc get_securities(SecurityKeyList) returns (bts.api.SecurityList);
|
||||
}
|
||||
@@ -96,6 +96,7 @@ message CustomOrderDefinition
|
||||
OffsetOrderDefinition offset = 24;
|
||||
OCOOrderDefinition oco = 25;
|
||||
PricerOrderDefinition pricer = 26;
|
||||
CompositeOrderDefinition composite = 27;
|
||||
|
||||
DynamicOrderDefinition dynamic = 1000;
|
||||
}
|
||||
@@ -182,6 +183,10 @@ message PricerOrderDefinition {
|
||||
double price_factor = 2;
|
||||
CustomOrderDefinition child = 3;
|
||||
}
|
||||
message CompositeOrderDefinition {
|
||||
string name = 1;
|
||||
CustomOrderDefinition definition = 2;
|
||||
}
|
||||
message DynamicOrderDefinition {
|
||||
string dynamic_order_type = 1;
|
||||
map<string, DynamicOrderParam> order_params = 2;
|
||||
|
||||
@@ -123,7 +123,8 @@ message CMEOptions
|
||||
|
||||
optional bool load_security_db = 33 [default = true];
|
||||
reserved 34;
|
||||
// optional BookType book_type = 34 [default = BOOKTYPE_CONSOLIDATED];
|
||||
// optional BookType book_type = 34 [default = BOOKTYPE_CONSOLIDATED];
|
||||
optional bool validate_mbo = 35 [default = false];
|
||||
|
||||
}
|
||||
optional string onixs_license = 1 [default = "{default}"];
|
||||
|
||||
@@ -111,4 +111,25 @@ message AlgoStudioOptions {
|
||||
|
||||
message AlgoStudioFlatDefinitionModelOptions {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
// TODO: The following algo-type specific attach ui messages should be consolidated into a single location, along with other algo-type metadata.
|
||||
message CoverAttachUIOptions {
|
||||
optional bool show_price = 1 [default = false];
|
||||
optional bool show_quantity = 2 [default = false];
|
||||
}
|
||||
|
||||
message JoinAttachUIOptions {
|
||||
optional bool show_price = 1 [default = false];
|
||||
optional bool show_quantity = 2 [default = false];
|
||||
}
|
||||
|
||||
message LeanAttachUIOptions {
|
||||
optional bool show_price = 1 [default = false];
|
||||
optional bool show_quantity = 2 [default = false];
|
||||
}
|
||||
|
||||
message TopAttachUIOptions {
|
||||
optional bool show_price = 1 [default = false];
|
||||
optional bool show_quantity = 2 [default = false];
|
||||
}
|
||||
@@ -32,6 +32,12 @@ message VolumeAtPrice{
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
message MBOStats {
|
||||
optional bool enabled = 1 [default = false];
|
||||
}
|
||||
message PlacementInQueue {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
message FixNestedScrolling {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ inline Price improve_price(api::Side side, Price p, Price offset) {
|
||||
return Price(0);
|
||||
}
|
||||
|
||||
inline Price worsen_price(api::Side side, Price p,
|
||||
double tick_size,uint32_t offset_ticks) {
|
||||
return improve_price(side, p, Price(tick_size*offset_ticks));
|
||||
}
|
||||
|
||||
inline Price worsen_price(api::Side side, Price p, Price offset) {
|
||||
return improve_price(other_side(side), p, offset);
|
||||
}
|
||||
@@ -167,6 +172,10 @@ inline bool test_price_equality(double price_1, double price_2,
|
||||
inline bool gr_than_eq(double p1, double p2, double tick_size) {
|
||||
return test_price_equality(p1, p2, tick_size) || p1 >= p2;
|
||||
}
|
||||
inline bool gr_than(double p1, double p2, double tick_size) {
|
||||
return gr_than_eq(p1, p2, tick_size) &&
|
||||
!test_price_equality(p1,p2,tick_size);
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -160,7 +160,7 @@ void run_periodic_dumper(const std::set<UserSymbol>& symbols, uint32_t seq_mod,
|
||||
threading::configure_current_thread(thread_name);
|
||||
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols);
|
||||
|
||||
// read all securities into a vector
|
||||
std::vector<Entry> entries;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
namespace bts {
|
||||
namespace md {
|
||||
using ExchangeOrderKey = utils::ValueWrapper<struct ExchangeOrderKeyTag,uint64_t>;
|
||||
using SparkOrderKey = utils::ValueWrapper<struct SparkOrderKeyTag,uint64_t>;
|
||||
} }
|
||||
+10
-2
@@ -54,9 +54,18 @@ class IntPrice {
|
||||
return _mantissa < other._mantissa;
|
||||
}
|
||||
else {
|
||||
return price() < other.price();
|
||||
// avoiding conversion to double is 4-5% faster
|
||||
// return price() < other.price();
|
||||
auto delta = *this - other;
|
||||
return delta.mantissa() < 0;
|
||||
}
|
||||
}
|
||||
bool operator <=(const IntPrice& other) {
|
||||
return *this == other || *this < other;
|
||||
}
|
||||
bool operator >=(const IntPrice& other) {
|
||||
return !(*this < other);
|
||||
}
|
||||
IntPrice operator - (const IntPrice& o) const {
|
||||
return op(o, [](int64_t m1, int64_t m2) { return m1 - m2; });
|
||||
}
|
||||
@@ -169,7 +178,6 @@ inline md::IntPrice round_to_quote_price(const IntPrice& tick, const IntPrice& p
|
||||
return price;
|
||||
}
|
||||
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const IntPrice& p) {
|
||||
os << p.price();
|
||||
return os;
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
#include "MBOProcessor.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/ConcurrentPool.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/toggles.pb.h"
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct SecurityKeyHashCompare {
|
||||
static size_t hash(const SecurityKey& k) {
|
||||
return k.value();
|
||||
}
|
||||
static bool equal(const SecurityKey& a, const SecurityKey& b) {
|
||||
return a.value() == b.value();
|
||||
}
|
||||
};
|
||||
|
||||
void print_pool_stats(const utils::ConcurrentPool<MBOSnapshot>& pool) {
|
||||
size_t count = 0;
|
||||
std::vector<int> bid_sz,ask_sz;
|
||||
pool.unsafe_iterate([&](const MBOSnapshot& s) {
|
||||
if (s.bids.size() > 0 || s.asks.size() > 0) {
|
||||
count++;
|
||||
bid_sz.push_back(s.bids.size());
|
||||
ask_sz.push_back(s.asks.size());
|
||||
}
|
||||
});
|
||||
|
||||
if (count == 0) return;
|
||||
|
||||
std::sort(bid_sz.begin(), bid_sz.end());
|
||||
std::sort(ask_sz.begin(), ask_sz.end());
|
||||
size_t bid_tot =0, ask_tot = 0;
|
||||
for(size_t i : bid_sz) { bid_tot += i; }
|
||||
for(size_t i : ask_sz) { ask_tot += i; }
|
||||
|
||||
std::stringstream bid_percentiles, ask_percentiles;
|
||||
for (double x : { 0.5, 0.75, 0.9, 0.95, 0.99 }) {
|
||||
size_t index = count * x;
|
||||
bid_percentiles << bid_sz[index] << " ";
|
||||
ask_percentiles << ask_sz[index] << " ";
|
||||
}
|
||||
bid_percentiles << bid_sz[count-1] << " ";
|
||||
ask_percentiles << ask_sz[count-1] << " ";
|
||||
LOG(md,Info,
|
||||
"MBO statistics: count: {} - %[50,75,90,95,99,100] bid: [{}] - ask: [{}]",
|
||||
count, bid_percentiles.str(), ask_percentiles.str());
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_hash_map<SecurityKey, MBOSnapshot*, SecurityKeyHashCompare> MapType;
|
||||
struct MBOProcessorImpl {
|
||||
utils::ConcurrentPool<MBOSnapshot> pool;
|
||||
MapType snapshots;
|
||||
utils::Dispatcher& dispatcher;
|
||||
utils::DispatcherTimer timer;
|
||||
MBOProcessorImpl(utils::Dispatcher& d) :
|
||||
pool(2048,512),
|
||||
snapshots(),
|
||||
dispatcher(d),
|
||||
timer(d, 600*1000, [&]() { print_pool_stats(pool); })
|
||||
{
|
||||
if (config::get<config::toggles::MBOStats>().enabled()) {
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Processor
|
||||
|
||||
MBOProcessor::MBOProcessor(utils::Dispatcher* d) :
|
||||
_me(std::make_shared<MBOProcessorImpl>(d == nullptr ? utils::Dispatcher::background() : *d)),
|
||||
_producer(_me),
|
||||
_consumer(_me)
|
||||
{}
|
||||
|
||||
MBOWriter& MBOProcessor::writer() { return _producer;}
|
||||
MBOReader& MBOProcessor::reader() { return _consumer; }
|
||||
|
||||
//
|
||||
// Writer
|
||||
|
||||
MBOWriter::MBOWriter(std::shared_ptr<MBOProcessorImpl>& me): _me(me) { }
|
||||
MBOWriter::~MBOWriter() { }
|
||||
MBOSnapshot* MBOWriter::allocate_snapshot(size_t, size_t) {
|
||||
return _me->pool.allocate();
|
||||
}
|
||||
void MBOWriter::release_snapshot(MBOSnapshot** s) {
|
||||
_me->pool.release(s);
|
||||
}
|
||||
void MBOWriter::publish_snapshot(SecurityKey key, MBOSnapshot** snapshot) {
|
||||
bts_assert(*snapshot != nullptr);
|
||||
MapType::accessor accessor;
|
||||
_me->snapshots.insert(accessor, key);
|
||||
std::swap(accessor->second, *snapshot);
|
||||
if (*snapshot != nullptr) {
|
||||
// Note: relase() must happen inside accessor lifetime to ensure correctness
|
||||
_me->pool.release(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
bool MBOWriter::validate_snapshot(uint32_t exchid, SecurityKey key, MBOSnapshot* control) {
|
||||
// bts_assert_msg(false, "TO USE THIS VALIDATION YOU MUST MAKE enqueue_incremental SYNCRONOUS");
|
||||
#define REQUIRE(a,b,y) \
|
||||
if ((a) != (b)) { \
|
||||
LOG(md,Error, "Validation error exch:{} sec:{} {}!={} other:{}", exchid, key.value(), a, b, y); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
// retrieve current snapshot and check they are equal
|
||||
_me->dispatcher.post([this,exchid,key,control]() {
|
||||
MBOReader reader(_me);
|
||||
auto snap = reader.acquire_snapshot(key);
|
||||
if (snap) {
|
||||
REQUIRE (snap->bids.size(), control->bids.size(), '!');
|
||||
REQUIRE (snap->asks.size(), control->asks.size(), '!');
|
||||
for (size_t x = 0; x < snap->bids.size(); ++x) {
|
||||
REQUIRE (snap->bids[x].id, control->bids[x].id, x);
|
||||
REQUIRE (snap->bids[x].size, control->bids[x].size, x);
|
||||
}
|
||||
for (size_t x = 0; x < snap->asks.size(); ++x) {
|
||||
REQUIRE (snap->asks[x].id, control->asks[x].id, x);
|
||||
REQUIRE (snap->asks[x].size, control->asks[x].size, x);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
#undef REQUIRE
|
||||
return true;
|
||||
}
|
||||
|
||||
void MBOWriter::enqueue_incremental(MBOWorkingState& state, const inc::Update& update) {
|
||||
LOG(md,Diag, "sec:{} : {}", state.handle.key(), update);
|
||||
|
||||
_me->dispatcher.post([this,&state,update]() {
|
||||
// fast part
|
||||
apply_incremental(state,update);
|
||||
// slow part
|
||||
publish_incremental(state);
|
||||
});
|
||||
}
|
||||
void MBOWriter::publish_incremental(MBOWorkingState& state) {
|
||||
// determine if we need to publish
|
||||
auto key = SecurityKey(state.handle.key());
|
||||
if (key.value() != invalid_security_key) {
|
||||
auto snap = allocate_snapshot(state.bid.size(), state.ask.size());
|
||||
copy_to_snapshot(state, snap);
|
||||
publish_snapshot(key, &snap);
|
||||
}
|
||||
}
|
||||
|
||||
void copy_to_snapshot(MBOWorkingState& state, MBOSnapshot* dest) {
|
||||
if (dest == nullptr) return;
|
||||
// copy working state to snapshot
|
||||
dest->updated = state.updated;
|
||||
auto type_map = [](auto pair) {
|
||||
return SnapshotOrder { pair.second.id, std::get<IntPrice>(pair.first), pair.second.size };
|
||||
};
|
||||
std::transform(state.bid.begin(), state.bid.end(), std::back_inserter(dest->bids), type_map);
|
||||
std::transform(state.ask.begin(), state.ask.end(), std::back_inserter(dest->asks), type_map);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void apply_incremental(uint32_t security_key, C& collection, std::unordered_map<ExchangeOrderKey, MBOWorkingState::key_t>& index, const inc::Update& update) {
|
||||
auto key = std::make_tuple(update.price, update.priority);
|
||||
switch(update.action) {
|
||||
case inc::UpdateAction::New:
|
||||
collection.insert(std::make_pair(key, MBOWorkingState::Data { update.order_id, update.size }));
|
||||
index[update.order_id] = key;
|
||||
break;
|
||||
case inc::UpdateAction::Change: {
|
||||
// look up old key
|
||||
auto r = index.find(update.order_id);
|
||||
if (r != index.end()) {
|
||||
auto oldkey = r->second;
|
||||
collection.erase(oldkey);
|
||||
index.erase(r);
|
||||
}
|
||||
else {
|
||||
LOG(md,Warn, "MBO Update w/out Add for: sec:{} {}", security_key, update);
|
||||
}
|
||||
collection.insert(std::make_pair(key, MBOWorkingState::Data { update.order_id, update.size }));
|
||||
index[update.order_id] = key;
|
||||
}
|
||||
break;
|
||||
case inc::UpdateAction::Delete:
|
||||
collection.erase(key);
|
||||
index.erase(update.order_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void apply_incremental(MBOWorkingState& state, const inc::Update& update) {
|
||||
// apply the update to the working state
|
||||
if (update.type == inc::UpdateType::Bid) {
|
||||
apply_incremental(state.handle.key(), state.bid, state.orderid_index, update);
|
||||
}
|
||||
else {
|
||||
apply_incremental(state.handle.key(),state.ask, state.orderid_index, update);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Reader
|
||||
|
||||
MBOReader::MBOReader(std::shared_ptr<MBOProcessorImpl>& me): _me(me) { }
|
||||
MBOReader::~MBOReader() { }
|
||||
MBOSnapshot* MBOReader::acquire_snapshot(SecurityKey key) const {
|
||||
// get a result eagerly so we don't have to do it while accessor has the entry locked
|
||||
auto result = _me->pool.allocate();
|
||||
MapType::const_accessor accessor;
|
||||
if (_me->snapshots.find(accessor, key) && accessor->second != nullptr) {
|
||||
result->copy_from(*accessor->second);
|
||||
}
|
||||
else {
|
||||
release_snapshot(&result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void MBOReader::release_snapshot(MBOSnapshot**s) const {
|
||||
_me->pool.release(s);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
namespace std {
|
||||
using namespace bts;
|
||||
using namespace bts::md;
|
||||
|
||||
ostream& operator<<(ostream& os, const inc::Update& update) {
|
||||
os << "Update: { "
|
||||
<< "id:" << update.order_id.value() << " "
|
||||
<< "pri:" << update.priority << " "
|
||||
<< update.price.price() << " "
|
||||
<< update.size << " ";
|
||||
|
||||
switch(update.type) {
|
||||
case inc::UpdateType::Bid:
|
||||
os << "B ";
|
||||
break;
|
||||
case inc::UpdateType::Ask:
|
||||
os << "A ";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(update.action) {
|
||||
case inc::UpdateAction::New:
|
||||
os << "+";
|
||||
break;
|
||||
case inc::UpdateAction::Change:
|
||||
os << "C";
|
||||
break;
|
||||
case inc::UpdateAction::Delete:
|
||||
os << "-";
|
||||
break;
|
||||
}
|
||||
|
||||
os << "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
#include "lib/domain_model/SecurityKey.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "IntPrice.h"
|
||||
#include "ExchangeOrderKey.h"
|
||||
#include "MDProducerHandle.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include "google/btree/btree_map.h"
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct SnapshotOrder {
|
||||
ExchangeOrderKey id;
|
||||
IntPrice price;
|
||||
int32_t size;
|
||||
};
|
||||
struct MBOSnapshot {
|
||||
MBOSnapshot() = default;
|
||||
MBOSnapshot(const MBOSnapshot&) = delete;
|
||||
MBOSnapshot(MBOSnapshot&& other) = delete;
|
||||
|
||||
utils::TimeStamp updated;
|
||||
std::vector<SnapshotOrder> bids;
|
||||
std::vector<SnapshotOrder> asks;
|
||||
|
||||
void copy_from(const MBOSnapshot& src) {
|
||||
bids = src.bids;
|
||||
asks = src.asks;
|
||||
updated = src.updated;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
updated = utils::TimeStamp();
|
||||
constexpr int max = 256;
|
||||
if (bids.size() > max) {
|
||||
bids.resize(max);
|
||||
}
|
||||
if (asks.size() > max) {
|
||||
asks.resize(max);
|
||||
}
|
||||
bids.clear();
|
||||
asks.clear();
|
||||
}
|
||||
};
|
||||
|
||||
namespace inc {
|
||||
|
||||
// according to this link MBO book only has these updates types
|
||||
// https://www.cmegroup.com/confluence/display/EPICSANDBOX/MDP+3.0+-+Market+Data+Snapshot+Full+Refresh#MDP3.0-MarketDataSnapshotFullRefresh-MarketbyOrder(MBO)DataBlock
|
||||
enum class UpdateType {
|
||||
Bid = 0,
|
||||
Ask = 1,
|
||||
// ImpliedBid, // 'E'
|
||||
// ImpliedAsk, // 'F'
|
||||
// BookReset // 'J'
|
||||
};
|
||||
|
||||
// OrderUpdateAction=37708
|
||||
enum class UpdateAction {
|
||||
New = 0,
|
||||
Change = 1,
|
||||
Delete = 2
|
||||
};
|
||||
|
||||
typedef uint64_t Priority;
|
||||
struct Update {
|
||||
ExchangeOrderKey order_id;
|
||||
Priority priority;
|
||||
IntPrice price;
|
||||
int32_t size;
|
||||
UpdateType type;
|
||||
UpdateAction action;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
struct MBOWorkingState {
|
||||
typedef std::tuple<IntPrice,inc::Priority> key_t;
|
||||
struct Data {
|
||||
ExchangeOrderKey id;
|
||||
int32_t size;
|
||||
};
|
||||
struct LessBid {
|
||||
bool operator()(const key_t& left, const key_t& right) const {
|
||||
const auto& left_price = std::get<IntPrice>(left);
|
||||
const auto& right_price = std::get<IntPrice>(right);
|
||||
if (left_price == right_price) {
|
||||
return
|
||||
std::get<inc::Priority>(left) <
|
||||
std::get<inc::Priority>(right);
|
||||
}
|
||||
return !(left_price < right_price);
|
||||
}
|
||||
};
|
||||
|
||||
MBOWorkingState(MDProducerHandle& h) : handle(h), updated(), bid(),ask() {}
|
||||
|
||||
MDProducerHandle handle;
|
||||
utils::TimeStamp updated;
|
||||
// Used for 'change' messages which update price
|
||||
std::unordered_map<ExchangeOrderKey, key_t> orderid_index;
|
||||
|
||||
#ifdef _WIN32
|
||||
std::map<key_t,Data,LessBid> bid;
|
||||
std::map<key_t,Data> ask;
|
||||
#else
|
||||
btree::btree_map<key_t,Data,LessBid> bid;
|
||||
btree::btree_map<key_t,Data> ask;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
void copy_to_snapshot(MBOWorkingState& state, MBOSnapshot* destination);
|
||||
void apply_incremental(MBOWorkingState&, const inc::Update&);
|
||||
|
||||
template <class V>
|
||||
void apply_incremental(MBOWorkingState& state, const V& vec) {
|
||||
for (const auto& update : vec) {
|
||||
apply_incremental(state, update);
|
||||
}
|
||||
}
|
||||
|
||||
struct MBOProcessorImpl;
|
||||
class MBOProcessor;
|
||||
|
||||
class MBOWriter {
|
||||
std::shared_ptr<MBOProcessorImpl> _me;
|
||||
friend class MBOProcessor;
|
||||
MBOWriter(std::shared_ptr<MBOProcessorImpl>&);
|
||||
~MBOWriter();
|
||||
|
||||
public:
|
||||
//
|
||||
// Snapshot api
|
||||
MBOSnapshot* allocate_snapshot(size_t bid_count=0, size_t ask_count=0);
|
||||
void release_snapshot(MBOSnapshot**);
|
||||
void publish_snapshot(SecurityKey, MBOSnapshot**);
|
||||
bool validate_snapshot(uint32_t, SecurityKey, MBOSnapshot*);
|
||||
|
||||
//
|
||||
// Incremental api
|
||||
|
||||
// Enqueue the update to the mbo work queue.
|
||||
void enqueue_incremental(MBOWorkingState&, const inc::Update&);
|
||||
// Update working state and publish directly.
|
||||
void publish_incremental(MBOWorkingState&);
|
||||
};
|
||||
|
||||
class MBOReader {
|
||||
std::shared_ptr<MBOProcessorImpl> _me;
|
||||
friend class MBOProcessor;
|
||||
friend class MBOWriter;
|
||||
MBOReader(std::shared_ptr<MBOProcessorImpl>&);
|
||||
~MBOReader();
|
||||
public:
|
||||
MBOSnapshot* acquire_snapshot(SecurityKey key) const;
|
||||
void release_snapshot(MBOSnapshot**) const;
|
||||
};
|
||||
|
||||
class MBOProcessor {
|
||||
std::shared_ptr<MBOProcessorImpl> _me;
|
||||
MBOWriter _producer;
|
||||
MBOReader _consumer;
|
||||
|
||||
public:
|
||||
MBOProcessor(utils::Dispatcher* _=nullptr);
|
||||
MBOWriter& writer();
|
||||
MBOReader& reader();
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
namespace std {
|
||||
std::ostream& operator<<(std::ostream& os, const bts::md::inc::Update&);
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
#ifndef _WIN32
|
||||
#include "MBOServiceServer.h"
|
||||
|
||||
#include "lib/api/services/OrderService.client.pb.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "MDClient.h"
|
||||
#include "ExchangeOrderKey.h"
|
||||
#include "MBOProcessor.h"
|
||||
|
||||
#include "lib/utils/LockBox.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
//
|
||||
// Simple class to handle MD recovery and maintain an index of SecurityKey=>MDConsumerHandle
|
||||
|
||||
class HandleIndex {
|
||||
MDClient& _client;
|
||||
int _sub;
|
||||
std::optional<MDConsumer> _consumer;
|
||||
|
||||
public:
|
||||
utils::LockBox<std::unordered_map<SecurityKey,MDConsumerHandle>> index;
|
||||
|
||||
HandleIndex(md::MDClient& client):
|
||||
_client(client),
|
||||
_sub(0),
|
||||
_consumer(std::nullopt),
|
||||
index() {
|
||||
_sub = _client.on_consumer().subscribe([=](const MDConsumer& c) { on_consumer(c); });
|
||||
on_consumer(_client.current_consumer());
|
||||
}
|
||||
|
||||
~HandleIndex() { _client.on_consumer().unsubscribe(_sub); }
|
||||
|
||||
|
||||
private:
|
||||
void on_consumer(const MDConsumer& c) {
|
||||
MDConsumer temp(c);
|
||||
if (temp.all_heartbeats_ok()) {
|
||||
auto existing = _consumer ? _consumer->id() : 0;
|
||||
LOG(md,Info, "Updateing MBOService MDConsumer. Old {} new {}", existing, temp.id());
|
||||
// clear the index
|
||||
index.lock([](auto& index) { index.clear(); });
|
||||
// Swap to new consumer
|
||||
if (_consumer) {
|
||||
_consumer->swap(temp);
|
||||
}
|
||||
else { _consumer = temp; }
|
||||
// Subscribe to on_security
|
||||
auto id = _consumer->id();
|
||||
_consumer->on_security([this,id](const SecurityPtr&, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto& index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ActiveOrder {
|
||||
SecurityKey _security;
|
||||
SparkOrderKey _id;
|
||||
ExchangeOrderKey _ex_id;
|
||||
int32_t _position;
|
||||
|
||||
public:
|
||||
// empty constructor needed for unordered map operator[]
|
||||
// ActiveOrder(): _security(), _id(), _ex_id(), _position(-1) { bts_assert(false); }
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, ExchangeOrderKey ex): _security(sec), _id(s), _ex_id(ex), _position(-1) {}
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, const std::string& ex): _security(sec), _id(s), _ex_id(), _position(-1) {
|
||||
_ex_id = ExchangeOrderKey(std::stoul(ex));
|
||||
}
|
||||
|
||||
SecurityKey security_id() const { return _security; }
|
||||
SparkOrderKey id() const { return _id; }
|
||||
ExchangeOrderKey exchange_id() const { return _ex_id; }
|
||||
int32_t& position() { return _position; };
|
||||
int32_t position() const { return _position; };
|
||||
bool set_position(int32_t pos) {
|
||||
if (pos != _position) {
|
||||
_position = pos;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
OrderPIQ to_piq() const {
|
||||
OrderPIQ result;
|
||||
result.set_order_id(_id.value());
|
||||
result.set_position(_position);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// MBOService
|
||||
|
||||
struct MBOServiceImpl {
|
||||
MBOServiceImpl(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c,
|
||||
MBOServiceBase::PiqPublisher&& pub
|
||||
):
|
||||
dispatcher(d),
|
||||
client(c),
|
||||
orders(ctx.locate<api::orderman::OrderService>()),
|
||||
handle_index(c),
|
||||
publish(pub),
|
||||
timer(d, 200, [&]() {timer_tick();}),
|
||||
orders_sub()
|
||||
{}
|
||||
|
||||
utils::Dispatcher& dispatcher;
|
||||
md::MDClient& client;
|
||||
OrderService orders;
|
||||
|
||||
HandleIndex handle_index;
|
||||
MBOServiceBase::PiqPublisher publish;
|
||||
utils::DispatcherTimer timer;
|
||||
|
||||
rxcpp::composite_subscription orders_sub;
|
||||
std::unordered_map<SparkOrderKey, ActiveOrder> active;
|
||||
|
||||
void timer_tick();
|
||||
void flush();
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////
|
||||
|
||||
std::optional<uint32_t> search_orders(const ExchangeOrderKey oid, const std::vector<SnapshotOrder>& orders) {
|
||||
IntPrice price = {};
|
||||
size_t position = 0;
|
||||
for (size_t x = 0; x < orders.size(); ++x) {
|
||||
const auto& oo = orders[x];
|
||||
if (oo.id == oid) {
|
||||
if (oo.price == price) return { position };
|
||||
else return 0;
|
||||
}
|
||||
else if (price == oo.price) {
|
||||
position += oo.size;
|
||||
}
|
||||
else {
|
||||
price = oo.price;
|
||||
position = oo.size;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool update_position(const HandleIndex& handles, ActiveOrder& order) {
|
||||
const auto& index = handles.index;
|
||||
auto handle = index.lock([id=order.security_id()](const auto& index) {
|
||||
auto iter = index.find(id);
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
});
|
||||
|
||||
if (handle.is_initialized()) {
|
||||
auto mbo = handle.get_mbo();
|
||||
if (mbo) {
|
||||
auto search_result = search_orders(order.exchange_id(), mbo->bids);
|
||||
if (!search_result) {
|
||||
search_result = search_orders(order.exchange_id(), mbo->asks);
|
||||
}
|
||||
if (search_result) {
|
||||
return order.set_position(search_result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MBOServiceImpl::timer_tick() {
|
||||
//Dispatcher thread
|
||||
std::vector<OrderPIQ> rows;
|
||||
for (auto& pair : active) {
|
||||
if (update_position(handle_index, pair.second)) {
|
||||
rows.push_back(pair.second.to_piq());
|
||||
}
|
||||
}
|
||||
if (!rows.empty()) {
|
||||
publish(nullptr, &rows, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
const NativeOrderState* native_order_state(const OrderRecord& record) {
|
||||
switch(record.state().custom_case()) {
|
||||
case OrderState::kMarket:
|
||||
return &record.state().market().native_state();
|
||||
case OrderState::kLimit:
|
||||
return &record.state().limit().native_state();
|
||||
case OrderState::kStop:
|
||||
return &record.state().stop().native_state();
|
||||
case OrderState::kStopLimit:
|
||||
return &record.state().stop_limit().native_state();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_active_exchange_order(const OrderRecord& record) {
|
||||
return record.state().status() == ORDER_STATUS_WORKING &&
|
||||
native_order_state(record) != nullptr;
|
||||
}
|
||||
|
||||
void try_remove(MBOServiceImpl& me, std::set<uint32_t>& to_remove, const OrderRecord& record) {
|
||||
auto key = SparkOrderKey(record.key());
|
||||
auto iter = me.active.find(key);
|
||||
if (iter != me.active.end()) {
|
||||
me.active.erase(key);
|
||||
to_remove.insert(key.value());
|
||||
}
|
||||
}
|
||||
void try_add(MBOServiceImpl& me, std::vector<OrderPIQ>& to_add, const OrderRecord& record) {
|
||||
if (is_active_exchange_order(record)) {
|
||||
auto native = native_order_state(record);
|
||||
bts_assert(native);
|
||||
ActiveOrder order(
|
||||
SecurityKey(record.def().security_key()),
|
||||
SparkOrderKey(record.key()),
|
||||
native->exchange_order_id());
|
||||
update_position(me.handle_index, order);
|
||||
to_add.push_back(order.to_piq());
|
||||
me.active.insert(std::make_pair(order.id(), order));
|
||||
}
|
||||
}
|
||||
|
||||
MBOServiceServer::MBOServiceServer(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c
|
||||
) :
|
||||
MBOServiceBase(ctx),
|
||||
_me(new MBOServiceImpl(ctx,d,c,make_piq_publisher()))
|
||||
{
|
||||
// subscribe to mdclient ✔
|
||||
// make publishers ✔
|
||||
// subscribe to orders => stash active orders dict
|
||||
_me->orders_sub =
|
||||
_me->orders.subscribe_orders().subscribe([=](const auto& update) {
|
||||
// api thread
|
||||
const auto& added = update.added();
|
||||
const auto& changed = update.changed();
|
||||
const auto& removed = update.removed();
|
||||
_me->dispatcher.post([this,added,changed,removed]() {
|
||||
// dispatcher thread
|
||||
std::vector<OrderPIQ> to_add, to_change;
|
||||
std::set<uint32_t> to_remove;
|
||||
|
||||
// Remove
|
||||
for(const auto& r : removed) {
|
||||
// If it was active remove it and add to to_remove
|
||||
try_remove(*_me, to_remove, *r);
|
||||
}
|
||||
// Added
|
||||
for(const auto& add : added) {
|
||||
// If active add look up the position and add to the state
|
||||
try_add(*_me, to_add, *add);
|
||||
}
|
||||
// Changed
|
||||
for(const auto& ch : changed) {
|
||||
// new order is active and old is not look up piq and add to state
|
||||
bool is_active = is_active_exchange_order(*ch.current());
|
||||
bool was_active = is_active_exchange_order(*ch.previous());
|
||||
if (is_active && !was_active) {
|
||||
try_add(*_me, to_add, *ch.current());
|
||||
}
|
||||
else if (was_active && !is_active) {
|
||||
try_remove(*_me, to_remove, *ch.current());
|
||||
}
|
||||
// is_active && was_active => don't care
|
||||
// !is_active && !was_active => don't care
|
||||
}
|
||||
|
||||
_me->publish(&to_add, &to_change, &to_remove);
|
||||
if (!_me->timer.running()) _me->timer.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
MBOServiceServer::~MBOServiceServer() { }
|
||||
|
||||
|
||||
void MBOServiceServer::get_orders_for_security(const MBOSecurityQuery& request, const api::Response<PositionData>& reply) {
|
||||
PositionData response;
|
||||
response.set_security_id(request.security_id());
|
||||
auto handle = _me->handle_index.index.lock([id=request.security_id()](const auto& index) {
|
||||
auto iter = index.find(SecurityKey(id));
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
});
|
||||
|
||||
std::unordered_map<ExchangeOrderKey, SparkOrderKey> reverse;
|
||||
for (const auto& pair : _me->active) {
|
||||
reverse.insert(std::make_pair(pair.second.exchange_id(), pair.first));
|
||||
}
|
||||
|
||||
if(handle.is_initialized()) {
|
||||
auto mbo = handle.get_mbo();
|
||||
if (mbo) {
|
||||
for (const auto& o : mbo->bids) {
|
||||
auto* entry = response.add_bid();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
entry->set_price(o.price.price());
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
entry->set_order_id(iter->second.value());
|
||||
}
|
||||
}
|
||||
for (const auto& o : mbo->asks) {
|
||||
auto* entry = response.add_ask();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
entry->set_price(o.price.price());
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
entry->set_order_id(iter->second.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reply(response);
|
||||
}
|
||||
|
||||
}} //namespace
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "lib/api/public/ServiceContext.h"
|
||||
#include "lib/api/services/MBOService.server.pb.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace bts {
|
||||
namespace utils { class Dispatcher; }
|
||||
namespace api { namespace orderman { class OrderService; } }
|
||||
namespace md {
|
||||
|
||||
class MDClient;
|
||||
|
||||
struct MBOServiceImpl;
|
||||
class MBOServiceServer : public MBOServiceBase {
|
||||
std::unique_ptr<MBOServiceImpl> _me;
|
||||
public:
|
||||
MBOServiceServer(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher&,
|
||||
md::MDClient&);
|
||||
~MBOServiceServer();
|
||||
|
||||
void get_orders_for_security(const MBOSecurityQuery&, const api::Response<PositionData>&) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}} //namespace
|
||||
+10
-5
@@ -3,6 +3,7 @@
|
||||
#include "SecurityCache.h"
|
||||
#include "SecurityOracle.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "MBOProcessor.h"
|
||||
#include <set>
|
||||
|
||||
namespace bts {
|
||||
@@ -15,19 +16,22 @@ struct MDClientImpl{
|
||||
std::unique_ptr<utils::DispatcherTimer> _security_timer;
|
||||
std::unique_ptr<utils::DispatcherTimer> _recovery_timer;
|
||||
std::set<UserSymbol> _symbols;
|
||||
MBOReader* _mbo;
|
||||
MDConsumer _consumer;
|
||||
utils::Event<MDConsumer> _event;
|
||||
|
||||
MDClientImpl(
|
||||
utils::Dispatcher* d,
|
||||
api::ISyntheticSecurityService* s,
|
||||
MBOReader* mbo,
|
||||
const std::set<UserSymbol>* symbols):
|
||||
_dispatcher(d),
|
||||
_ss(s),
|
||||
_security_timer(),
|
||||
_recovery_timer(),
|
||||
_symbols(symbols ? *symbols : get_system_md_symbols()),
|
||||
_consumer(_cache, _ss, &_symbols),
|
||||
_mbo(mbo),
|
||||
_consumer(_cache, _ss, mbo, &_symbols),
|
||||
_event()
|
||||
{
|
||||
if (d) {
|
||||
@@ -42,7 +46,7 @@ struct MDClientImpl{
|
||||
|
||||
void check_heartbeats() {
|
||||
if (!_consumer.all_heartbeats_ok()) {
|
||||
MDConsumer temp(_cache,_ss);
|
||||
MDConsumer temp(_cache,_ss,_mbo,&_symbols);
|
||||
if (temp.all_heartbeats_ok()) {
|
||||
_consumer.swap(temp);
|
||||
LOG(md,Info, "Recovering from bad MD. Old consumer {} new consumer {}", _consumer.id(), temp.id());
|
||||
@@ -71,11 +75,12 @@ struct MDClientImpl{
|
||||
MDClient::MDClient(
|
||||
utils::Dispatcher* d,
|
||||
api::ISyntheticSecurityService* s,
|
||||
MBOReader* mbo,
|
||||
const std::set<UserSymbol>* symbols) :
|
||||
_self(new MDClientImpl(d,s, symbols))
|
||||
_self(new MDClientImpl(d,s,mbo,symbols))
|
||||
{ }
|
||||
MDClient::~MDClient() {
|
||||
}
|
||||
|
||||
MDClient::~MDClient() { }
|
||||
|
||||
size_t MDClient::scan_securities() { return _self->scan_securities(); }
|
||||
void MDClient::check_heartbeats() { return _self->check_heartbeats(); }
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
class SecurityOracle;
|
||||
class MBOReader;
|
||||
struct MDClientImpl;
|
||||
|
||||
class MDClient {
|
||||
std::unique_ptr<MDClientImpl> _self;
|
||||
|
||||
@@ -20,6 +22,7 @@ public:
|
||||
MDClient(
|
||||
utils::Dispatcher* d=nullptr,
|
||||
api::ISyntheticSecurityService* ss=nullptr,
|
||||
MBOReader* mbo=nullptr,
|
||||
const std::set<UserSymbol>* s=nullptr);
|
||||
~MDClient();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "MemorySegmentUtils.h"
|
||||
#include "PlatformLoader.h"
|
||||
#include "SecurityCache.h"
|
||||
#include "MBOProcessor.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/utils/SharedList.h"
|
||||
#include "lib/utils/WaitFreeQueue.h"
|
||||
@@ -535,6 +536,7 @@ class MDConsumerImpl {
|
||||
Mutex _workmutex;
|
||||
vector<shared_ptr<MDConsumerInst>> _instances;
|
||||
std::shared_ptr<SyntheticConsumerInst> _sci;
|
||||
MBOReader* _mbo;
|
||||
map<security_key, shared_ptr<MDConsumerHandle>> _deferred_handles;
|
||||
vector<SecurityCallback> _callbacks;
|
||||
mutable SecurityCache _cache;
|
||||
@@ -545,10 +547,12 @@ public:
|
||||
const set<UserSymbol>& symbols,
|
||||
SecurityCache& cache,
|
||||
api::ISyntheticSecurityService* ss,
|
||||
MBOReader* mbo,
|
||||
bool shared, co2::Platform platform) :
|
||||
_workmutex(),
|
||||
_instances(),
|
||||
_sci(),
|
||||
_mbo(mbo),
|
||||
_deferred_handles(),
|
||||
_callbacks(),
|
||||
_cache(cache)
|
||||
@@ -625,7 +629,7 @@ public:
|
||||
for (auto& inst : _instances) {
|
||||
if (inst->find_handle(key, &cold, &hot)) {
|
||||
MDConsumerHandle handle;
|
||||
handle.init(inst->cold_header(), *cold, hot);
|
||||
handle.init(inst->cold_header(), *cold, hot, _mbo);
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
@@ -657,9 +661,15 @@ public:
|
||||
}
|
||||
|
||||
// Erase anything that wasn't found from the resulting map
|
||||
// Set the mbo pointer on anything else
|
||||
for (auto it = result.begin(); it != result.end(); ) {
|
||||
if (!it->second.is_initialized()) it = result.erase(it);
|
||||
else ++it;
|
||||
if (!it->second.is_initialized()) {
|
||||
it = result.erase(it);
|
||||
}
|
||||
else {
|
||||
it->second.set_mbo(_mbo);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -910,6 +920,7 @@ public:
|
||||
MDConsumer::MDConsumer(
|
||||
SecurityCache& cache,
|
||||
api::ISyntheticSecurityService* ss,
|
||||
MBOReader* mbo,
|
||||
const std::set<UserSymbol>* symbols,
|
||||
bool shared,
|
||||
co2::Platform platform) : _pimpl() {
|
||||
@@ -920,7 +931,7 @@ MDConsumer::MDConsumer(
|
||||
symbols = &all_symbols;
|
||||
}
|
||||
|
||||
_pimpl.reset(new MDConsumerImpl(*symbols, cache, ss, shared, platform));
|
||||
_pimpl.reset(new MDConsumerImpl(*symbols, cache, ss, mbo, shared, platform));
|
||||
}
|
||||
|
||||
MDConsumer::~MDConsumer() {}
|
||||
|
||||
@@ -26,6 +26,7 @@ class MDConsumerImpl;
|
||||
class MDConsumerInst;
|
||||
class MDConsumerChannel;
|
||||
class SecurityCache;
|
||||
class MBOReader;
|
||||
|
||||
class MDConsumer
|
||||
{
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
MDConsumer(
|
||||
SecurityCache&,
|
||||
api::ISyntheticSecurityService* ss,
|
||||
MBOReader* mbo=nullptr,
|
||||
const std::set<UserSymbol>* sym = nullptr,
|
||||
bool shared=true,
|
||||
co2::Platform platform=co2::PLATFORM_UNSET);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#ifndef NO_CPP0X
|
||||
#include "MDConsumerHandle.h"
|
||||
#include "MBOProcessor.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
@@ -14,7 +15,7 @@ namespace md {
|
||||
MDConsumerHandle::MDConsumerHandle() {
|
||||
memset(this, 0, sizeof(MDConsumerHandle));
|
||||
_type = HANDLETYPE_VOID;
|
||||
static_assert(sizeof(MDConsumerHandle) <= 32, "");
|
||||
static_assert(sizeof(MDConsumerHandle) <= 40, "");
|
||||
}
|
||||
MDConsumerHandle::MDConsumerHandle(const std::shared_ptr<const SyntheticStrategy>& def) {
|
||||
memset(this, 0, sizeof(MDConsumerHandle));
|
||||
@@ -33,9 +34,10 @@ MDConsumerHandle::MDConsumerHandle(const MDConsumerHandle& other) {
|
||||
|
||||
MDConsumerHandle::~MDConsumerHandle() {}
|
||||
|
||||
void MDConsumerHandle::init(const ColdHeader& cheader, const ColdEntry& centry, const void* pvhot) {
|
||||
void MDConsumerHandle::init(const ColdHeader& cheader, const ColdEntry& centry, const void* pvhot, const MBOReader* mbo) {
|
||||
set_cold(&cheader, ¢ry);
|
||||
set_hot(pvhot);
|
||||
set_mbo(mbo);
|
||||
}
|
||||
|
||||
TimeStamp copy_bbo(const HotEntry& hot, PriceSize& out_bid, PriceSize& out_ask) {
|
||||
@@ -371,6 +373,16 @@ CoconutSecurityStatus MDConsumerHandle::status() const {
|
||||
never;
|
||||
}
|
||||
|
||||
std::unique_ptr<MBOSnapshot,std::function<void(MBOSnapshot*)>> MDConsumerHandle::get_mbo() const {
|
||||
if (_type == HANDLETYPE_DEPTH) {
|
||||
MBOSnapshot* snapshot = book.mbo->acquire_snapshot(SecurityKey(key()));
|
||||
if (snapshot != nullptr) {
|
||||
return {snapshot,[mbo=book.mbo](auto* s) { mbo->release_snapshot(&s); }};
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
class MDConsumerHandle;
|
||||
class MBOReader;
|
||||
struct MBOSnapshot;
|
||||
|
||||
struct SyntheticStrategy {
|
||||
std::unique_ptr<spark::ExecutionStrategy> strategy;
|
||||
api::Security security;
|
||||
@@ -141,6 +144,9 @@ TimeStamp optimistic_copy(
|
||||
return t;
|
||||
}
|
||||
|
||||
//
|
||||
// MDConsumerHandle
|
||||
//
|
||||
|
||||
// Can be an invalid handle if you request a security which has not been discovered yet.
|
||||
class BTS_EXPORT MDConsumerHandle
|
||||
@@ -151,7 +157,7 @@ public:
|
||||
~MDConsumerHandle();
|
||||
MDConsumerHandle(const MDConsumerHandle& other);
|
||||
|
||||
void init(const ColdHeader&, const ColdEntry&, const void* hot);
|
||||
void init(const ColdHeader&, const ColdEntry&, const void* hot, const MBOReader*);
|
||||
|
||||
bool is_initialized() const { return _type != HANDLETYPE_VOID; }
|
||||
bool is_synthetic() const { return _type == HANDLETYPE_SYNTHETIC; }
|
||||
@@ -267,8 +273,11 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<MBOSnapshot,std::function<void(MBOSnapshot*)>> get_mbo() const;
|
||||
|
||||
private:
|
||||
friend class MDConsumerInst;
|
||||
friend class MDConsumerImpl;
|
||||
|
||||
template <class Read>
|
||||
HandleReadResult get_book(Read read, TimeStamp& time, uint32_t copydepth, PriceSize* bids, PriceSize* asks) const {
|
||||
@@ -326,6 +335,19 @@ private:
|
||||
_type = HANDLETYPE_BBO;
|
||||
}
|
||||
}
|
||||
void set_mbo(const MBOReader* mbo) {
|
||||
switch(_type) {
|
||||
case HANDLETYPE_DEPTH:
|
||||
book.mbo = mbo;
|
||||
break;
|
||||
case HANDLETYPE_BBO:
|
||||
bbo.mbo = mbo;
|
||||
break;
|
||||
default:
|
||||
//ok
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enum HandleType : uint8_t {
|
||||
HANDLETYPE_VOID,
|
||||
@@ -337,11 +359,13 @@ private:
|
||||
const HotDepthEntry* hot;
|
||||
const ColdEntry* cdata;
|
||||
const ColdHeader* cheader;
|
||||
const MBOReader* mbo;
|
||||
};
|
||||
struct BBOHandle {
|
||||
const HotEntry* hot;
|
||||
const ColdEntry* cdata;
|
||||
const ColdHeader* cheader;
|
||||
const MBOReader* mbo;
|
||||
};
|
||||
struct SyntheticHandle {
|
||||
std::shared_ptr<const SyntheticStrategy> def;
|
||||
|
||||
@@ -32,7 +32,7 @@ CAPI MDConsumer* create_md_consumer(BlitUserSymbol* usersymbols, uint32_t count,
|
||||
for (size_t x = 0; x < count; ++x) {
|
||||
symbols.insert(UserSymbol(usersymbols[x].symbol, usersymbols[x].exchange, usersymbols[x].type));
|
||||
}
|
||||
return new MDConsumer(cache, nullptr/*synthetics*/, &symbols, shared);
|
||||
return new MDConsumer(cache, nullptr/*synthetics*/, nullptr /*mbo*/, &symbols, shared);
|
||||
}
|
||||
|
||||
CAPI void destroy_md_consumer(MDConsumer* consumer) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifndef NO_CPP0X
|
||||
#ifndef _WIN32
|
||||
#include "QueryServer.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../MDConsumer.h"
|
||||
#include "../MDClient.h"
|
||||
#include "../PlatformLoader.h"
|
||||
#include "../MBOProcessor.h"
|
||||
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
@@ -30,6 +31,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <optional>
|
||||
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
@@ -129,7 +131,6 @@ struct MDConsumerGroup {
|
||||
|
||||
};
|
||||
|
||||
|
||||
void convert(PriceSize ps, PriceSizeMessage* pps) {
|
||||
pps->set_mantissa(ps.mantissa());
|
||||
pps->set_exponent(ps.exponent());
|
||||
@@ -211,6 +212,7 @@ public:
|
||||
for (auto& pair : _groups) {
|
||||
pair.second->set_consumer(_consumer);
|
||||
}
|
||||
// _handle_index.clear();
|
||||
subscribe_securities();
|
||||
utils::Dispatcher::background().post([temp]() { LOG(md,Info,"QServer destroying consumer {}", temp.id()); }, 60000);
|
||||
}
|
||||
@@ -396,7 +398,6 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct MDRelayServer : bts::co2::AuthenticatedMarketDataRelayBase {
|
||||
@@ -494,6 +495,7 @@ struct MDRelayServer : bts::co2::AuthenticatedMarketDataRelayBase {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct QueryServer {
|
||||
QueryServer(utils::Dispatcher& threadpool,
|
||||
const bts::api::ServiceContext& ctx,
|
||||
|
||||
@@ -26,7 +26,7 @@ extern "C" BTS_EXPORT void co2_get_1234_handle(size_t& size, MDConsumerHandle&
|
||||
auto pheader = reinterpret_cast<ColdHeader*>(&buffer[0]);
|
||||
pheader->has_depth = false;
|
||||
size = sizeof(MDConsumerHandle);
|
||||
handle.init(*pheader, *pcold, phot.get());
|
||||
handle.init(*pheader, *pcold, phot.get(), nullptr);
|
||||
// Copy the addresses for comparison
|
||||
*hotaddr = (uintptr_t)phot.get();
|
||||
*coldaddr = (uintptr_t)pcold.get();
|
||||
|
||||
@@ -43,7 +43,7 @@ MDProducerHandle Co2TestInstrument::producer() {
|
||||
|
||||
MDConsumerHandle Co2TestInstrument::consumer() {
|
||||
MDConsumerHandle handle;
|
||||
handle.init(*_cheader, *_cold, _hot.get());
|
||||
handle.init(*_cheader, *_cold, _hot.get(), nullptr/*mbo*/);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
#ifndef _WIN32
|
||||
#include "catch/catch.hpp"
|
||||
#include "../IntPrice.h"
|
||||
#include "../MBOProcessor.h"
|
||||
#include "Co2TestInstrument.h"
|
||||
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
// fwd declare from MBOServiceServer.cpp
|
||||
std::optional<uint32_t> search_orders(const ExchangeOrderKey oid, const std::vector<SnapshotOrder>& orders);
|
||||
|
||||
namespace test {
|
||||
int mbo_tests = 0;
|
||||
|
||||
TEST_CASE("MBO publish snapshot", "[md][mbo]") {
|
||||
MBOProcessor p;
|
||||
// publish a snapshot
|
||||
auto sec = SecurityKey(99);
|
||||
{
|
||||
auto s = p.writer().allocate_snapshot();
|
||||
s->bids.push_back({ ExchangeOrderKey(1), { 100, 0 }, 42 });
|
||||
p.writer().publish_snapshot(sec, &s);
|
||||
}
|
||||
|
||||
auto s = p.reader().acquire_snapshot(sec);
|
||||
REQUIRE(s);
|
||||
REQUIRE(s->bids.size() == 1);
|
||||
REQUIRE(s->bids[0].id.value() == 1);
|
||||
REQUIRE(s->asks.size() == 0);
|
||||
}
|
||||
|
||||
std::vector<inc::Update> gen_test_orders(uint64_t id=100, inc::UpdateType type=inc::UpdateType::Bid) {
|
||||
std::vector<inc::Update> result;
|
||||
inc::Priority priority = 10000;
|
||||
for (int p = 100; p < 501; p+=100) {
|
||||
// 6 sizes
|
||||
for (int32_t s = 1; s <= 5; ++s) {
|
||||
IntPrice price { p + 5 , -2};
|
||||
auto order_id = ExchangeOrderKey(++id);
|
||||
auto size = s;
|
||||
priority++;
|
||||
result.push_back( inc::Update {
|
||||
order_id,
|
||||
priority,
|
||||
price,
|
||||
size,
|
||||
type,
|
||||
inc::UpdateAction::New
|
||||
});
|
||||
// std::cout << std::endl << order_id.value() << ": " << price.price() << "-" << size;
|
||||
}
|
||||
}
|
||||
std::random_shuffle(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST_CASE("MBO state to snapshot", "[md][mbo]") {
|
||||
// convert state to snapshot
|
||||
Co2TestInstrument instr { "MBO", api::SECURITYTYPE_FUTURE };
|
||||
auto handle = instr.producer();
|
||||
MBOWorkingState state(handle);
|
||||
|
||||
state.updated = utils::TimeStamp::now();
|
||||
|
||||
auto bids = gen_test_orders(1000, inc::UpdateType::Bid);
|
||||
apply_incremental(state, bids);
|
||||
auto asks = gen_test_orders(2000, inc::UpdateType::Ask);
|
||||
apply_incremental(state, asks);
|
||||
|
||||
MBOSnapshot result;
|
||||
copy_to_snapshot(state, &result);
|
||||
|
||||
REQUIRE(result.updated == state.updated);
|
||||
REQUIRE(result.bids.size() == state.bid.size());
|
||||
REQUIRE(result.asks.size() == state.ask.size());
|
||||
REQUIRE(bids.size() == result.bids.size());
|
||||
REQUIRE(asks.size() == result.asks.size());
|
||||
for (size_t x = 0; x < result.bids.size() - 1; ++x) {
|
||||
REQUIRE(result.bids[x].price >= result.bids[x+1].price);
|
||||
}
|
||||
for (size_t x = 0; x < result.asks.size() - 1; ++x) {
|
||||
REQUIRE(result.asks[x].price <= result.asks[x+1].price);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::vector<T> concat(const std::vector<T>& a, const std::vector<T>& b) {
|
||||
std::vector<T> res;
|
||||
std::copy(a.begin(), a.end(), std::back_inserter(res));
|
||||
std::copy(b.begin(), b.end(), std::back_inserter(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
TEST_CASE("MBO incremental", "[md][mbo]") {
|
||||
// basic incremental test
|
||||
Co2TestInstrument instr { "MBO", api::SECURITYTYPE_FUTURE };
|
||||
auto handle = instr.producer();
|
||||
MBOWorkingState state(handle);
|
||||
|
||||
auto orders =
|
||||
concat( gen_test_orders(128, inc::UpdateType::Bid),
|
||||
gen_test_orders(256, inc::UpdateType::Ask));
|
||||
|
||||
std::random_shuffle(orders.begin(), orders.end());
|
||||
apply_incremental(state, orders);
|
||||
|
||||
REQUIRE(state.bid.size() + state.ask.size() == orders.size());
|
||||
|
||||
// generate some updates/deletes
|
||||
std::vector<inc::Update> updates;
|
||||
// - change all size=2 to size=6
|
||||
// - delete all size=3
|
||||
size_t removed = 0;
|
||||
for (const auto& e : orders) {
|
||||
if (e.size == 2) {
|
||||
updates.push_back( inc::Update {
|
||||
e.order_id,
|
||||
e.priority,
|
||||
e.price,
|
||||
6,
|
||||
e.type,
|
||||
inc::UpdateAction::Change
|
||||
});
|
||||
}
|
||||
else if (e.size == 3) {
|
||||
++removed;
|
||||
updates.push_back( inc::Update {
|
||||
e.order_id,
|
||||
e.priority,
|
||||
e.price,
|
||||
e.size,
|
||||
e.type,
|
||||
inc::UpdateAction::Delete
|
||||
});
|
||||
}
|
||||
}
|
||||
apply_incremental(state,updates);
|
||||
|
||||
REQUIRE(state.bid.size() + state.ask.size() == (orders.size() - removed));
|
||||
|
||||
MBOSnapshot result;
|
||||
copy_to_snapshot(state, &result);
|
||||
|
||||
auto all = concat (result.bids, result.asks);
|
||||
std::map<int,int> counts;
|
||||
for (const auto& order : all) {
|
||||
REQUIRE(order.size != 3);
|
||||
REQUIRE(order.size != 2);
|
||||
counts[order.size] ++;
|
||||
}
|
||||
REQUIRE(counts[6] > 0);
|
||||
REQUIRE(counts[6] == counts[1]);
|
||||
REQUIRE(counts[5] == counts[4]);
|
||||
REQUIRE(counts[6] == counts[5]);
|
||||
}
|
||||
|
||||
TEST_CASE("MBO sort order", "[md][mbo]") {
|
||||
Co2TestInstrument instr { "MBO", api::SECURITYTYPE_FUTURE };
|
||||
auto handle = instr.producer();
|
||||
MBOWorkingState state(handle);
|
||||
|
||||
std::vector<inc::Update> updates;
|
||||
// multiple updates at the same price
|
||||
for (unsigned x=0; x < 100; ++x) {
|
||||
// bid
|
||||
auto p = 1000 + x;
|
||||
updates.push_back( inc::Update {
|
||||
ExchangeOrderKey(1000 + x),
|
||||
1000 + x,
|
||||
{ 1000, -1 },
|
||||
(int)x+1,
|
||||
inc::UpdateType::Bid,
|
||||
inc::UpdateAction::New
|
||||
});
|
||||
// ask
|
||||
if (x < 75) { // ensure bid.size != ask.size
|
||||
updates.push_back( inc::Update {
|
||||
ExchangeOrderKey(2000 + x),
|
||||
2000 + x,
|
||||
{ 2000, -1 },
|
||||
(int)x+1,
|
||||
inc::UpdateType::Ask,
|
||||
inc::UpdateAction::New
|
||||
});
|
||||
}
|
||||
}
|
||||
std::random_shuffle(updates.begin(), updates.end());
|
||||
|
||||
apply_incremental(state, updates);
|
||||
|
||||
MBOSnapshot result;
|
||||
copy_to_snapshot(state, &result);
|
||||
|
||||
// Since all orders are at the same price we can assert they are in priority order
|
||||
// Since priority is not explicit in the shapshot we set order_id to the same value
|
||||
|
||||
for (size_t x = 0; x < result.bids.size() - 1; ++x) {
|
||||
REQUIRE(result.bids[x].id.value() < result.bids[x+1].id.value());
|
||||
}
|
||||
for (size_t x = 0; x < result.asks.size() - 1; ++x) {
|
||||
REQUIRE(result.asks[x].id.value() < result.asks[x+1].id.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("MBO change price and size", "[md][mbo]") {
|
||||
// When an order's size goes up it gets a new priority
|
||||
Co2TestInstrument instr { "MBO", api::SECURITYTYPE_FUTURE };
|
||||
auto handle = instr.producer();
|
||||
MBOWorkingState state(handle);
|
||||
|
||||
constexpr auto bid = inc::UpdateType::Bid;
|
||||
constexpr auto ask = inc::UpdateType::Ask;
|
||||
constexpr auto add = inc::UpdateAction::New;
|
||||
constexpr auto remove = inc::UpdateAction::Delete;
|
||||
constexpr auto change = inc::UpdateAction::Change;
|
||||
auto p = [](double price) -> IntPrice { return IntPrice(price * 1000, -3); };
|
||||
|
||||
// snapshot
|
||||
std::vector<inc::Update> snapshot = {
|
||||
{ ExchangeOrderKey(701267154552), 1160179309, p(2.975), 1, ask, add},
|
||||
{ ExchangeOrderKey(701267991871), 1161068569, p(2.925), 9, bid, add},
|
||||
{ ExchangeOrderKey(701267963307), 1161037482, p(2.975), 1, ask, add},
|
||||
{ ExchangeOrderKey(701267991967), 1161068670, p(2.900), 1, bid, add},
|
||||
{ ExchangeOrderKey(701267928346), 1160999982, p(3.000), 1, ask, add},
|
||||
{ ExchangeOrderKey(701267993125), 1161069878, p(2.900), 3, bid, add},
|
||||
{ ExchangeOrderKey(701267037972), 1160052467, p(2.875), 1, bid, add},
|
||||
{ ExchangeOrderKey(701267099137), 1160119020, p(2.875), 5, bid, add},
|
||||
{ ExchangeOrderKey(701267299079), 1160330214, p(2.875), 1, bid, add},
|
||||
{ ExchangeOrderKey(701267308619), 1160340068, p(2.875), 5, bid, add},
|
||||
{ ExchangeOrderKey(701267310436), 1160341952, p(2.875), 3, bid, add},
|
||||
{ ExchangeOrderKey(701267872642), 1160939720, p(2.875), 1, bid, add},
|
||||
{ ExchangeOrderKey(701267895533), 1160964252, p(2.875), 1, bid, add},
|
||||
{ ExchangeOrderKey(701267953989), 1161027476, p(2.875), 3, bid, add},
|
||||
{ ExchangeOrderKey(701267993135), 1161069890, p(2.875), 2, bid, add},
|
||||
{ ExchangeOrderKey(701266410447), 1159379621, p(2.850), 3, bid, add},
|
||||
{ ExchangeOrderKey(701267324626), 1160356597, p(2.850), 3, bid, add},
|
||||
{ ExchangeOrderKey(701267992564), 1161069297, p(2.850), 1, bid, add},
|
||||
{ ExchangeOrderKey(701266420294), 1159389827, p(2.775), 5, bid, add},
|
||||
{ ExchangeOrderKey(701267334462), 1160366796, p(2.775), 5, bid, add},
|
||||
{ ExchangeOrderKey(701266411103), 1159380297, p(2.625), 5, bid, add},
|
||||
{ ExchangeOrderKey(701267325284), 1160357275, p(2.625), 5, bid, add},
|
||||
};
|
||||
|
||||
apply_incremental(state, snapshot);
|
||||
REQUIRE(state.bid.size() == 19);
|
||||
REQUIRE(state.ask.size() == 3);
|
||||
|
||||
std::vector<inc::Update> incremental = {
|
||||
{ ExchangeOrderKey(701267993738), 1161070510, p(2.925), 2, bid, add},
|
||||
{ ExchangeOrderKey(701267993759), 1161070532, p(2.975), 3, ask, add},
|
||||
{ ExchangeOrderKey(701267993884), 1161070662, p(2.950), 3, ask, add},
|
||||
{ ExchangeOrderKey(701267994228), 1161071029, p(2.925), 2, bid, add},
|
||||
{ ExchangeOrderKey(701267994243), 1161071044, p(2.925), 4, bid, add},
|
||||
{ ExchangeOrderKey(701267994228), 1161071029, p(2.925), 2, bid, remove},
|
||||
{ ExchangeOrderKey(701267993135), 1161071281, p(2.875), 3, bid, change},
|
||||
};
|
||||
apply_incremental(state, incremental);
|
||||
REQUIRE(state.bid.size() == 21);
|
||||
REQUIRE(state.ask.size() == 5);
|
||||
|
||||
{
|
||||
auto iter = state.bid.begin();
|
||||
auto next = state.bid.begin();
|
||||
next++;
|
||||
for (; next != state.bid.end(); ++iter, ++next) {
|
||||
auto cur_price = std::get<IntPrice>(iter->first);
|
||||
auto cur_prio = std::get<1>(iter->first);
|
||||
auto next_price = std::get<IntPrice>(next->first);
|
||||
auto next_prio = std::get<1>(next->first);
|
||||
REQUIRE(cur_price >= next_price);
|
||||
if (cur_price == next_price) {
|
||||
REQUIRE(cur_prio < next_prio);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
auto iter = state.ask.begin();
|
||||
auto next = state.ask.begin();
|
||||
next++;
|
||||
for (; next != state.ask.end(); ++iter, ++next) {
|
||||
auto cur_price = std::get<IntPrice>(iter->first);
|
||||
auto cur_prio = std::get<1>(iter->first);
|
||||
auto next_price = std::get<IntPrice>(next->first);
|
||||
auto next_prio = std::get<1>(next->first);
|
||||
REQUIRE(cur_price <= next_price);
|
||||
if (cur_price == next_price) {
|
||||
REQUIRE(cur_prio < next_prio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do some tests on the snapshot
|
||||
MBOSnapshot result;
|
||||
copy_to_snapshot(state, &result);
|
||||
|
||||
auto ask30 = search_orders(ExchangeOrderKey(701267928346), result.asks);
|
||||
REQUIRE(ask30);
|
||||
REQUIRE(*ask30 == 0);
|
||||
|
||||
auto bid2875 = search_orders(ExchangeOrderKey(701267993135), result.bids);
|
||||
REQUIRE(bid2875);
|
||||
REQUIRE(*bid2875 == 20);
|
||||
|
||||
bid2875 = search_orders(ExchangeOrderKey(701267299079), result.bids);
|
||||
REQUIRE(bid2875);
|
||||
REQUIRE(*bid2875 == 6);
|
||||
|
||||
auto not_bid = search_orders(ExchangeOrderKey(701967299879), result.bids);
|
||||
auto not_ask = search_orders(ExchangeOrderKey(701967299879), result.asks);
|
||||
REQUIRE(!not_bid);
|
||||
REQUIRE(!not_ask);
|
||||
}
|
||||
|
||||
}}}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifndef _WIN32
|
||||
#include "catch/catch.hpp"
|
||||
#include "../SettlementRecorder.h"
|
||||
#include "../coconut2.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/utils/Sqlite_utils.h"
|
||||
#include "md_test_utils.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -55,29 +57,8 @@ Platform TEST_PLATFORM = PLATFORM_SIM;
|
||||
//
|
||||
// Helper functions for Producer/Consumer tests
|
||||
//
|
||||
vector<MDProducerHandle> create_test_securities(MDProducer& producer, const char* postfix ="") {
|
||||
FixedFutureSecurity ffs;
|
||||
FixedOptionSecurity fos;
|
||||
ffs.symbol("FOO"+string(postfix));
|
||||
fos.symbol("FOOX"+string(postfix));
|
||||
ffs.exchange = VENUE_BTS;
|
||||
fos.exchange = VENUE_BTS;
|
||||
ffs.key = invalid_security_key;
|
||||
fos.key = invalid_security_key;
|
||||
ffs.expiration_year = fos.expiration_year = 2015;
|
||||
ffs.expiration_day = fos.expiration_day = 27;
|
||||
fos.strike = 1000;
|
||||
fos.call_put = PUTORCALL_CALL;
|
||||
// Add 12 expirations to 2 different shared memory regions
|
||||
vector<MDProducerHandle> result;
|
||||
for (uint32_t x = 1; x <= 12; ++x) {
|
||||
ffs.expiration_month = fos.expiration_month = x;
|
||||
result.push_back(producer.add_security(ffs));
|
||||
result.push_back(producer.add_security(fos));
|
||||
// In a real app these securities would now be passed to the SecurityIDRecorder
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<MDProducerHandle> create_test_securities(MDProducer& producer, const char* postfix = "");
|
||||
|
||||
set<UserSymbol> get_test_symbols(const char* postfix="") {
|
||||
set<UserSymbol> symbols;
|
||||
@@ -146,12 +127,6 @@ Security mkspread(string symbol, security_key key, Security leg1, Security leg2,
|
||||
return mkspread(symbol, key, vlegs);
|
||||
}
|
||||
|
||||
void assign_ids(vector<MDProducerHandle>::iterator begin, vector<MDProducerHandle>::iterator end, security_key start_key = 1000) {
|
||||
for (; begin != end; ++begin) {
|
||||
(*begin).set_key(++start_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Co2Tests
|
||||
{
|
||||
@@ -370,7 +345,7 @@ public:
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
vector<Security> consumer_securities;
|
||||
// Poll for security list - none visible until they have keys
|
||||
@@ -441,7 +416,7 @@ public:
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
// Add the on_security callback
|
||||
vector<Security> securities;
|
||||
@@ -481,7 +456,7 @@ public:
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
// Get a handle to 24 consumers which haven't been created yet
|
||||
vector<MDConsumerHandle> consumers;
|
||||
@@ -539,7 +514,7 @@ public:
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
// Get a handle to 24 consumers which haven't been created yet
|
||||
vector<MDConsumerHandle> consumers;
|
||||
@@ -600,7 +575,7 @@ public:
|
||||
// Symbol list for the consumer
|
||||
auto symbols = get_test_symbols();
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
// Add the on_security callback - callback fires for existing securities
|
||||
vector<Security> securities;
|
||||
@@ -628,7 +603,7 @@ public:
|
||||
// Symbol list for the consumer
|
||||
SecurityCache cache;
|
||||
auto symbols = get_test_symbols();
|
||||
MDClient client(nullptr, nullptr, &symbols);
|
||||
MDClient client(nullptr, nullptr, nullptr, &symbols);
|
||||
MDConsumer consumer = client.current_consumer();
|
||||
map<security_key, MDConsumerHandle> products;
|
||||
consumer.on_security([&](const SecurityPtr& security, MDConsumerHandle handle) {
|
||||
@@ -761,7 +736,7 @@ public:
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols, true, TEST_PLATFORM);
|
||||
|
||||
set<security_key> keys;
|
||||
consumer.walk_security_list([&](const SecurityPtr& security, MDConsumerHandle) { keys.insert(security->id()); });
|
||||
@@ -806,7 +781,7 @@ public:
|
||||
csymbols.insert(UserSymbol("S3", VENUE_BTS, SECURITYTYPE_SPREAD));
|
||||
csymbols.insert(UserSymbol("S4", VENUE_BTS, SECURITYTYPE_SPREAD));
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &csymbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &csymbols, true, TEST_PLATFORM);
|
||||
|
||||
auto check_sec = [&](const SecurityPtr& security, MDConsumerHandle handle) {
|
||||
REQUIRE(security->id() == handle.key());
|
||||
@@ -853,7 +828,7 @@ public:
|
||||
csymbols.insert(UserSymbol("OO", VENUE_BTS, SECURITYTYPE_OPTION));
|
||||
csymbols.insert(UserSymbol("SS", VENUE_BTS, SECURITYTYPE_SPREAD));
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &csymbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &csymbols, true, TEST_PLATFORM);
|
||||
|
||||
auto check_sec = [&](const SecurityPtr& security, MDConsumerHandle handle) {
|
||||
REQUIRE(security->id() == handle.key());
|
||||
@@ -905,7 +880,7 @@ public:
|
||||
consumer_symbols.insert(UserSymbol("OO", VENUE_BTS, SECURITYTYPE_OPTION));
|
||||
consumer_symbols.insert(UserSymbol("SS", VENUE_BTS, SECURITYTYPE_SPREAD));
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &consumer_symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &consumer_symbols, true, TEST_PLATFORM);
|
||||
|
||||
size_t security_count = 0;
|
||||
// Indirection for check function
|
||||
@@ -974,7 +949,7 @@ public:
|
||||
set<UserSymbol> consumer_symbols;
|
||||
consumer_symbols.insert(UserSymbol("OO", VENUE_BTS, SECURITYTYPE_OPTION));
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &consumer_symbols, true, TEST_PLATFORM);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &consumer_symbols, true, TEST_PLATFORM);
|
||||
auto h1 = consumer.get_handle(k1);
|
||||
REQUIRE(h1.is_initialized());
|
||||
auto h2 = consumer.get_handle(k2);
|
||||
@@ -1260,7 +1235,7 @@ struct Co2RelayTests {
|
||||
UserSymbol option_symbol("FOOX", VENUE_BTS, SECURITYTYPE_OPTION);
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols);
|
||||
return consumer;
|
||||
}
|
||||
|
||||
@@ -1327,7 +1302,7 @@ struct Co2RelayTests {
|
||||
// todo: setup_query_server should use client.symbols() instead of it's own list
|
||||
//
|
||||
const auto symbols = setup_symbols();
|
||||
MDClient client(nullptr, nullptr, &symbols);
|
||||
MDClient client(nullptr, nullptr, nullptr, &symbols);
|
||||
auto server = setup_query_server(client, producer, &entitlements, &producers);
|
||||
|
||||
// assign prices
|
||||
@@ -1460,7 +1435,7 @@ struct Co2RelayTests {
|
||||
vector<MDProducerHandle> producers;
|
||||
Entitlements entitlements;
|
||||
const auto symbols = setup_symbols();
|
||||
MDClient client(nullptr, nullptr, &symbols);
|
||||
MDClient client(nullptr, nullptr, nullptr, &symbols);
|
||||
auto server = setup_query_server(client, producer, &entitlements, &producers);
|
||||
|
||||
// assign prices to all levels
|
||||
@@ -1638,7 +1613,7 @@ namespace ImpliedTests {
|
||||
UserSymbol option_symbol( "FOOX", VENUE_BTS, SECURITYTYPE_OPTION );
|
||||
symbols.insert(option_symbol);
|
||||
SecurityCache cache;
|
||||
MDConsumer consumer(cache, nullptr, &symbols);
|
||||
MDConsumer consumer(cache, nullptr, nullptr, &symbols);
|
||||
vector<Security> consumer_securities;
|
||||
// Poll for security list - none visible until they have keys
|
||||
size_t count = consumer.walk_security_list([&](const SecurityPtr& security, MDConsumerHandle) {consumer_securities.push_back(*security);});
|
||||
@@ -2417,3 +2392,4 @@ TEST_CASE("IntPrice", "[md]") {
|
||||
|
||||
|
||||
}}}
|
||||
#endif
|
||||
Loaded 100 of 138 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user