diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
index f72d2cc1c..d5d1c38da 100644
--- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
+++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs
@@ -451,7 +451,7 @@ namespace mbts.spark {
price = temp_price;
}
}
- await _model.order_gateway.send_order(order, price, size);
+ await _model.order_gateway.send_order(security, order, price, size);
if (auto_clear)
size_calculator.value = 0;
var fav_algo = order_properties_vm.selected_favorite_algo_definition;
diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
index 54ffe800c..40990a269 100644
--- a/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
+++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookVM.cs
@@ -288,7 +288,14 @@ namespace mbts.spark {
double price = attach_vm.price;
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 : 0u;
- var order_tups = selected_rows.Select(r => r.order_tuple).ToList();
+ // Don't pass any order tuples that don't have a security defined.
+ // The actual security is passed to the OrdersModel - instead of just the security key -
+ // so it can prevent GlbxIceberg orders from being sent to a non-glbx exchange (such as Ice).
+ /// Impl details:
+ var order_tups = selected_rows
+ .Select(r => r.order_tuple)
+ .Where(ot => ot.order.security.HasValue)
+ .ToList();
var mod_algo_vm = attach_vm.algo_vm.algo_root;
await Task.WhenAll(order_tups.Select(t => {
var algo = t.order.order.Def.CustomDef.actual().CloneToMutable();
@@ -302,6 +309,7 @@ namespace mbts.spark {
};
}
return _model.send_order(
+ t.order.security.Value,
t.order.order.Def.with(
attach_target_order_key: t.order.order.Key,
custom_def: algo
diff --git a/src/client/spark/Orders/NewOrderTicketVM.cs b/src/client/spark/Orders/NewOrderTicketVM.cs
index f9945b649..4e5b36122 100644
--- a/src/client/spark/Orders/NewOrderTicketVM.cs
+++ b/src/client/spark/Orders/NewOrderTicketVM.cs
@@ -53,7 +53,7 @@ namespace mbts.spark {
send_order = new DelegateCommand(side => {
bool price_valid = _validate_price(), size_valid = size_calculator.validate();
if (price_valid && size_valid && !HasErrors && !properties_vm.HasErrors) {
- model.send_order(properties_vm.create(side), price, size_calculator.value.Value).ignore();
+ model.send_order(security, properties_vm.create(side), price, size_calculator.value.Value).ignore();
RequestClose?.Invoke(this, new EventArgs());
}
});
diff --git a/src/client/spark/Orders/OrderUtils.cs b/src/client/spark/Orders/OrderUtils.cs
index 6bc4cc7c6..2b4773a67 100644
--- a/src/client/spark/Orders/OrderUtils.cs
+++ b/src/client/spark/Orders/OrderUtils.cs
@@ -200,6 +200,13 @@ namespace mbts.spark {
public static string short_description(this OrderRecordImmutable order, ContractSpecificationImmutable? spec) =>
$"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{spec.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}";
+ public static string short_description(SecurityImmutable security, Side side, double price, uint quantity) =>
+ new StringBuilderEx(
+ security.ToString(), " ",
+ side.ToString(), " ",
+ price_quantity_description(price, quantity, security.spec_or_default())
+ ).ToString();
+
public static string short_description(this OrderRecordImmutable order, SecurityImmutable? security) {
var spec = security.spec_or_default();
return new StringBuilderEx(
diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs
index 8ef3241c9..278324bcb 100644
--- a/src/client/spark/Orders/OrdersModel.cs
+++ b/src/client/spark/Orders/OrdersModel.cs
@@ -286,13 +286,33 @@ namespace mbts.spark {
#endregion
#region Input
- public async Task send_order(OrderDefinitionImmutable? order, double price, uint size) {
+ // the security arg is needed for a temporary hack to prevent GlbxIceberg orders from going out in non-glbx exchanges (like Ice)
+ // eventually, we'll need an algo type model to handle this stuff.
+ // This hack leverages the fact that every place that calls 'send_order' already has the security handy (not just the sec id).
+ public Task send_order(SecurityImmutable security, OrderDefinitionImmutable? order, double price, uint size) {
if (order.HasValue) {
- var result = (await send_order_get_error(order.Value, price, size));
- _activity.on_send_order(order.Value, price, size, result.key, result.error);
- return result.key;
+#if DEBUG
+ if (security.Exchange != Venue.Glbx && security.Exchange != Venue.Sim) {
+#else
+ if (security.Exchange != Venue.Glbx) {
+#endif
+ var algo_structure = OrderDataHelper.enumerate_algo_structure(order.Value.CustomDef);
+ if (algo_structure.Any(t => t.type == CustomOrderDefinition.CustomOneofCase.GlbxIceberg)) {
+ Log.Ui.info($"OrdersModel prevented a GlbxIceberg order from going out to a non-glbx exchange ({OrderUtils.short_description(security, order.Value.Side, price, size)}).");
+ return Task.FromResult(null);
+ }
+ }
+ return send_order(order.Value, price, size);
}
- return 0;
+ return Task.FromResult(null);
+ }
+
+ /// Note: this method is private to force outside callers to use this overload .
+ /// This allows us to control which orders can be sent to which security/exchange (e.g., GlbxIceberg orders are only permitted for securities on the Glbx exchange).
+ async Task send_order(OrderDefinitionImmutable order, double price, uint size) {
+ var result = (await send_order_get_error(order, price, size));
+ _activity.on_send_order(order, price, size, result.key, result.error);
+ return result.key;
}
async Task<(uint? key, string error)> send_order_get_error(OrderDefinitionImmutable order, double price, uint size) {