OrdersModel blocks GlbxIceberg orders from going out to non-glbx exchange
This commit is contained in:
1 parent
33c201b395
commit
1eb8352b6b
5 files changed
+43
-8
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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: <see cref="OrdersModel.send_order(SecurityImmutable, OrderDefinitionImmutable?, double, uint)"/>
|
||||
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
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace mbts.spark {
|
||||
send_order = new DelegateCommand<Side>(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());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -286,13 +286,33 @@ namespace mbts.spark {
|
||||
#endregion
|
||||
|
||||
#region Input
|
||||
public async Task<uint?> 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<uint?> 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<uint?>(null);
|
||||
}
|
||||
}
|
||||
return send_order(order.Value, price, size);
|
||||
}
|
||||
return 0;
|
||||
return Task.FromResult<uint?>(null);
|
||||
}
|
||||
|
||||
/// Note: this method is private to force outside callers to use this overload <see cref="send_order(SecurityImmutable, OrderDefinitionImmutable?, double, uint)"/>.
|
||||
/// 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<uint?> 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) {
|
||||
|
||||
Reference in new issue
Block a user