commit
83adfb8361
31 files changed
+1796
-59
No files matched your search
@@ -33,3 +33,4 @@ trace_data/
|
||||
/src/lib/orderman/perf_analysis/log.csv
|
||||
/doc/user/public/*
|
||||
.ionide/*
|
||||
src/web/ui/.ionide/symbolCache.db
|
||||
@@ -51,6 +51,9 @@ namespace mbts.spark {
|
||||
readonly Property<AlgoFormats> _selected_format;
|
||||
readonly EnumMaskInt32<AlgoEditingPermissions> _permissions_mask = new EnumMaskInt32<AlgoEditingPermissions>();
|
||||
|
||||
mbts.ui.spark.AlgoContentTemplateSelector.OrderKind IAlgoSelector.order_kind =>
|
||||
new mbts.ui.spark.AlgoContentTemplateSelector.OrderKind(string.Empty, string.Empty);
|
||||
|
||||
int? _favorite_index;
|
||||
Brush _badge_fill;
|
||||
Snapshot? _committed;
|
||||
|
||||
@@ -26,7 +26,11 @@ namespace mbts.spark.utilities {
|
||||
public readonly Func<CustomOrderDefinition, CustomOrderDefinition> get_child;
|
||||
public readonly Action<CustomOrderDefinition, CustomOrderDefinition> assign_child;
|
||||
|
||||
public ChildAlgoData(string name, Func<IMessage, CustomOrderDefinition> get_child_from_impl, Action<IMessage, CustomOrderDefinition> assign_child_to_impl, Func<CustomOrderDefinition, CustomOrderDefinition> get_child, Action<CustomOrderDefinition, CustomOrderDefinition> assign_child) {
|
||||
public ChildAlgoData(string name, Func<IMessage, CustomOrderDefinition> get_child_from_impl,
|
||||
Action<IMessage, CustomOrderDefinition> assign_child_to_impl,
|
||||
Func<CustomOrderDefinition, CustomOrderDefinition> get_child,
|
||||
Action<CustomOrderDefinition, CustomOrderDefinition> assign_child)
|
||||
{
|
||||
this.name = name;
|
||||
this.get_child = get_child;
|
||||
this.assign_child = assign_child;
|
||||
@@ -246,6 +250,9 @@ namespace mbts.spark.utilities {
|
||||
case CustomOrderDefinition.CustomOneofCase.Splitter: rv.Splitter = splitter_order(); break;
|
||||
case CustomOrderDefinition.CustomOneofCase.Dynamic: rv.Dynamic = dynamic_order(); break;
|
||||
//case CustomOrderDefinition.CustomOneofCase.QueueHolder: rv.QueueHolder = queue_holder_order(); break;
|
||||
default:
|
||||
OrderTypeVMFactory.GenericOrderFactory.setup_generic_custom_order(rv, order_type);
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -592,9 +599,6 @@ namespace mbts.spark.utilities {
|
||||
new AlgoStructureKey(defi.CustomCase)));
|
||||
|
||||
public static readonly CustomOrderDefinition.CustomOneofCase[]
|
||||
// The following standard types are not yet ready for production use:
|
||||
// CustomOrderDefinition.CustomOneofCase.Tick,
|
||||
// CustomOrderDefinition.CustomOneofCase.Dynamic,
|
||||
|
||||
// exchange_order_types are the types which can be submitted on an exchange security
|
||||
exchange_order_types = new[] {
|
||||
@@ -610,17 +614,19 @@ namespace mbts.spark.utilities {
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Offset,
|
||||
CustomOrderDefinition.CustomOneofCase.Splitter,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
// The following spreader types are not yet ready for production use:
|
||||
// CustomOrderDefinition.CustomOneofCase.Dynamic,
|
||||
spreader_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Spreader,
|
||||
CustomOrderDefinition.CustomOneofCase.Iceberg,
|
||||
CustomOrderDefinition.CustomOneofCase.Lean,
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Splitter,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
attachable_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Iceberg,
|
||||
@@ -628,7 +634,9 @@ namespace mbts.spark.utilities {
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Offset
|
||||
CustomOrderDefinition.CustomOneofCase.Offset,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
outright_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Market,
|
||||
@@ -1014,6 +1022,9 @@ namespace mbts.spark.utilities {
|
||||
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Trigger: rv.Trigger = TriggerOrderDefinition(); break;
|
||||
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Spreader: rv.Spreader = SpreaderOrderDefinition(); break;
|
||||
case bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Dynamic: rv.Dynamic = DynamicOrderDefinition(); break;
|
||||
default:
|
||||
OrderTypeVMFactory.GenericOrderFactory.setup_generic_custom_order(rv, order_type);
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -1043,4 +1054,5 @@ namespace mbts.spark.utilities {
|
||||
public static SplitterOrderDefinition SplitterOrderDefinition() => new SplitterOrderDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,6 +71,7 @@ namespace mbts.spark {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveOrderDef: param.AsOrderDef = new CustomOrderDefinition(); break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: param.AsString = string.Empty; break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: param.AsUint32 = 0u; break;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveQuantity: param.AsQuantity = new bts.spark.QuantityMeasure(); break;
|
||||
}
|
||||
break;
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Structure: param.AsStruct = new DynamicOrderStruct(); break;
|
||||
@@ -87,5 +88,16 @@ namespace mbts.spark {
|
||||
}
|
||||
param.AsEnumerated.EnumValue = value ?? string.Empty;
|
||||
}
|
||||
|
||||
internal static bts.spark.QuantityMeasureImmutable? get_quantity_value(DynamicOrderParam param)
|
||||
{
|
||||
return new bts.spark.QuantityMeasureImmutable(param?.AsQuantity);
|
||||
}
|
||||
internal static void set_quantity_value(DynamicOrderParam param, bts.spark.QuantityMeasureImmutable? value)
|
||||
{
|
||||
if (param == null)
|
||||
return;
|
||||
param.AsQuantity = value?.CloneToMutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts.api.orderman;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.ui.shell;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -25,7 +26,7 @@ namespace mbts.spark {
|
||||
protected DynamicOrderParamVM(DynamicOrderParamDescriptor descriptor)
|
||||
: this(descriptor, DynamicOrderHelper.init_param(descriptor)) { }
|
||||
|
||||
protected DynamicOrderParamVM(DynamicOrderParamDescriptor descriptor, DynamicOrderParam param) {
|
||||
private DynamicOrderParamVM(DynamicOrderParamDescriptor descriptor, DynamicOrderParam param) {
|
||||
this.descriptor = descriptor;
|
||||
_param = param;
|
||||
}
|
||||
@@ -116,4 +117,41 @@ namespace mbts.spark {
|
||||
void _sync_elements() =>
|
||||
elements.sync_with(_get_elements(descriptor));
|
||||
}
|
||||
|
||||
|
||||
class DynamicOrderQuantityVM : DynamicOrderParamVM, IDynamicOrderParamVM<QuantityMeasureImmutable?>
|
||||
{
|
||||
static readonly FieldDescriptor _field_desc = DynamicOrderParam.Descriptor.FindFieldByNumber(DynamicOrderParam.AsQuantityFieldNumber);
|
||||
public DynamicOrderQuantityVM(DynamicOrderParamDescriptor descriptor)
|
||||
: base(descriptor) { }
|
||||
|
||||
QuantityMeasureImmutable? IDynamicOrderParamVM<QuantityMeasureImmutable?>.value { get => quantity; set => quantity= value; }
|
||||
public QuantityMeasureImmutable? quantity
|
||||
{
|
||||
get => DynamicOrderHelper.get_quantity_value(param);
|
||||
set
|
||||
{
|
||||
var orig = quantity;
|
||||
DynamicOrderHelper.set_quantity_value(param, value);
|
||||
if (quantity != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<QuantityMeasureImmutable?> subscribe_value()
|
||||
{
|
||||
return Observable.Create<QuantityMeasureImmutable?>(o =>
|
||||
{
|
||||
PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => PropertyChanged -= on_prop_changed);
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) =>
|
||||
o.OnNext(quantity);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
RaisePropertyChanged(nameof(quantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ namespace mbts.ui.spark
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
public DataTemplate StringTemplate { get; set; }
|
||||
public DataTemplate OrderDefTemplate { get; set; }
|
||||
public DataTemplate QuantityMeasureTemplate { get; set; }
|
||||
|
||||
public DataTemplate EnumTemplate { get; set; }
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace mbts.ui.spark
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: return UIntTemplate;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: return StringTemplate;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveOrderDef: return OrderDefTemplate;
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveQuantity: return QuantityMeasureTemplate;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -46,10 +47,13 @@ namespace mbts.spark {
|
||||
protected override void on_model_internal() =>
|
||||
_sync_dynamic_params();
|
||||
|
||||
protected override IEnumerable<ChildAlgoData> get_selector_datum() =>
|
||||
OrderDataHelper.get_child_algo_data(new CustomOrderDefinition {
|
||||
protected override IEnumerable<ChildAlgoData> get_selector_datum()
|
||||
{
|
||||
var data = OrderDataHelper.get_child_algo_data(new CustomOrderDefinition {
|
||||
Dynamic = model?.dynamic_helper?.create_def(dyn_type) ?? new DynamicOrderDefinition()
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
void _sync_dynamic_params() {
|
||||
if (model != null) {
|
||||
@@ -70,9 +74,14 @@ namespace mbts.spark {
|
||||
switch (descriptor.ParamType.Primitive) {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveBool: return mk<bool?, bool>(DynamicOrderParam.AsBoolFieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveDouble: return mk<double, double>(DynamicOrderParam.AsDoubleFieldNumber, v => v, v => v, double.NaN);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveInt: return mk<uint?, uint>(DynamicOrderParam.AsInt32FieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveInt: return mk<int?, int>(DynamicOrderParam.AsInt32FieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: return mk<uint?, uint>(DynamicOrderParam.AsUint32FieldNumber, v => v, v => v.GetValueOrDefault());
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: return mk<string, string>(DynamicOrderParam.AsStringFieldNumber, v => v, v => v);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveQuantity:
|
||||
{
|
||||
var qm = new DynamicOrderQuantityVM(descriptor);
|
||||
return attached(qm, DynamicOrderHelper.get_quantity_value, DynamicOrderHelper.set_quantity_value, new QuantityMeasure { Ratio = 1.0, Absolute = 1 });
|
||||
}
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.Primitive, nameof(descriptor));
|
||||
}
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Enumerated:
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
[Export]
|
||||
class GenericOrderHelper
|
||||
{
|
||||
[ImportingConstructor]
|
||||
private GenericOrderHelper(OrderService order_service)
|
||||
{
|
||||
}
|
||||
|
||||
internal static string get_enumerated_value(IMessage message, FieldDescriptor fd)
|
||||
{
|
||||
var ev = fd.Accessor.GetValue(message);
|
||||
return ev.ToString();
|
||||
}
|
||||
internal static void set_enumerated_value(IMessage message, FieldDescriptor fd, string value)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var ev = fd.EnumType.Values.First(x => x.Name == value)?.Number;
|
||||
if(ev.HasValue)
|
||||
fd.Accessor.SetValue(message, ev.Value);
|
||||
}
|
||||
|
||||
internal static bts.spark.QuantityMeasureImmutable? get_quantity_value(IMessage message, FieldDescriptor fd)
|
||||
{
|
||||
var qm = (bts.spark.QuantityMeasure)fd.Accessor.GetValue(message);
|
||||
if(qm != null)
|
||||
return new bts.spark.QuantityMeasureImmutable(qm);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
internal static void set_quantity_value(IMessage message, FieldDescriptor fd, bts.spark.QuantityMeasureImmutable? value)
|
||||
{
|
||||
if (message == null)
|
||||
return;
|
||||
fd.Accessor.SetValue(message, value?.CloneToMutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
using bts.api.orderman;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.ui.shell;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
interface IGenericOrderParamVM
|
||||
{
|
||||
FieldDescriptor descriptor { get; }
|
||||
Google.Protobuf.IMessage message { get; set; }
|
||||
}
|
||||
|
||||
interface IGenericOrderParamVM<T> : IGenericOrderParamVM
|
||||
{
|
||||
T value { get; set; }
|
||||
IObservable<T> subscribe_value();
|
||||
}
|
||||
|
||||
abstract class GenericOrderParamVM<TMutable> : DisposableViewModelBase, IGenericOrderParamVM
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
TMutable _message;
|
||||
|
||||
protected GenericOrderParamVM(FieldDescriptor descriptor)
|
||||
{
|
||||
_message = new TMutable();
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
public FieldDescriptor descriptor { get; set; }
|
||||
public Google.Protobuf.IMessage message
|
||||
{
|
||||
get => _message;
|
||||
set
|
||||
{
|
||||
_message = (TMutable)value;
|
||||
on_param_changed();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void on_param_changed();
|
||||
}
|
||||
|
||||
class GenericOrderParamVM<TMutable, TView, TModel> : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<TView>
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
readonly Func<TModel, TView> _convert;
|
||||
readonly Func<TView, TModel> _convert_back;
|
||||
TView _value;
|
||||
|
||||
public GenericOrderParamVM(FieldDescriptor field_descriptor, Func<TModel, TView> convert, Func<TView, TModel> convert_back) :
|
||||
base(field_descriptor)
|
||||
{
|
||||
_convert = convert;
|
||||
_convert_back = convert_back;
|
||||
}
|
||||
|
||||
public TView value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
this.descriptor.Accessor.SetValue(this.message, _convert_back(_value = value));
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<TView> subscribe_value() =>
|
||||
Observable.Create<TView>(o =>
|
||||
{
|
||||
PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => PropertyChanged -= on_prop_changed);
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) =>
|
||||
o.OnNext(value);
|
||||
});
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
_value = _convert(ConvertUtils.try_convert<TModel>(this.descriptor.Accessor.GetValue(this.message)));
|
||||
RaisePropertyChanged(nameof(value));
|
||||
}
|
||||
}
|
||||
|
||||
class GenericOrderEnumeratedVM<TMutable> : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<string>
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
public GenericOrderEnumeratedVM(FieldDescriptor descriptor)
|
||||
: base(descriptor)
|
||||
{
|
||||
elements = new ObservableCollection<string>(_get_elements(descriptor));
|
||||
}
|
||||
|
||||
public ObservableCollection<string> elements { get; }
|
||||
|
||||
public string selected_element
|
||||
{
|
||||
get => GenericOrderHelper.get_enumerated_value(message, descriptor);
|
||||
set
|
||||
{
|
||||
var orig = selected_element;
|
||||
GenericOrderHelper.set_enumerated_value(message, descriptor, value);
|
||||
if (selected_element != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
string IGenericOrderParamVM<string>.value { get => selected_element; set => selected_element = value; }
|
||||
|
||||
IObservable<string> IGenericOrderParamVM<string>.subscribe_value() =>
|
||||
Observable.Create<string>(o =>
|
||||
{
|
||||
PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => PropertyChanged -= on_prop_changed);
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) =>
|
||||
o.OnNext(selected_element);
|
||||
});
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
_sync_elements();
|
||||
RaisePropertyChanged(nameof(selected_element));
|
||||
}
|
||||
|
||||
static IEnumerable<string> _get_elements(FieldDescriptor descriptor)
|
||||
{
|
||||
if(descriptor.FieldType == Google.Protobuf.Reflection.FieldType.Enum)
|
||||
{
|
||||
return descriptor.EnumType.Values.Select(x => x.Name);
|
||||
}
|
||||
else
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
void _sync_elements()
|
||||
{
|
||||
elements.sync_with(_get_elements(descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GenericOrderQuantityVM<TMutable> : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<QuantityMeasureImmutable?>
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
public GenericOrderQuantityVM(FieldDescriptor descriptor)
|
||||
: base(descriptor) { }
|
||||
|
||||
QuantityMeasureImmutable? IGenericOrderParamVM<QuantityMeasureImmutable?>.value { get => quantity; set => quantity= value; }
|
||||
public QuantityMeasureImmutable? quantity
|
||||
{
|
||||
get => GenericOrderHelper.get_quantity_value(message, descriptor);
|
||||
set
|
||||
{
|
||||
var orig = quantity;
|
||||
GenericOrderHelper.set_quantity_value(message, descriptor, value);
|
||||
if (quantity != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<QuantityMeasureImmutable?> subscribe_value()
|
||||
{
|
||||
return Observable.Create<QuantityMeasureImmutable?>(o =>
|
||||
{
|
||||
PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => PropertyChanged -= on_prop_changed);
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) =>
|
||||
o.OnNext(quantity);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
RaisePropertyChanged(nameof(quantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
using bts.api.orderman;
|
||||
using mbts.spark;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.utilities;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
class GenericOrderParamTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public DataTemplate BoolTemplate { get; set; }
|
||||
public DataTemplate DoubleTemplate { get; set; }
|
||||
public DataTemplate IntTemplate { get; set; }
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
public DataTemplate StringTemplate { get; set; }
|
||||
public DataTemplate OrderDefTemplate { get; set; }
|
||||
public DataTemplate QuantityMeasureTemplate { get; set; }
|
||||
|
||||
public DataTemplate EnumTemplate { get; set; }
|
||||
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
||||
{
|
||||
var vm = item as IGenericOrderParamVM;
|
||||
if (vm != null)
|
||||
return select_template(vm.descriptor);
|
||||
return null;
|
||||
}
|
||||
|
||||
public DataTemplate select_template(Google.Protobuf.Reflection.FieldDescriptor descriptor)
|
||||
{
|
||||
switch (descriptor.FieldType)
|
||||
{
|
||||
case Google.Protobuf.Reflection.FieldType.Bool:
|
||||
return BoolTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.Float:
|
||||
case Google.Protobuf.Reflection.FieldType.Double:
|
||||
return DoubleTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.Int32:
|
||||
case Google.Protobuf.Reflection.FieldType.Int64:
|
||||
return IntTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.UInt32:
|
||||
case Google.Protobuf.Reflection.FieldType.UInt64:
|
||||
return UIntTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.String:
|
||||
return StringTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.Enum:
|
||||
return EnumTemplate;
|
||||
case Google.Protobuf.Reflection.FieldType.Message:
|
||||
{
|
||||
if(descriptor.MessageType.FullName == typeof(bts.spark.QuantityMeasure).FullName)
|
||||
return QuantityMeasureTemplate;
|
||||
else if (descriptor.MessageType.FullName == typeof(bts.api.orderman.CustomOrderDefinition).FullName)
|
||||
return OrderDefTemplate;
|
||||
}
|
||||
break;
|
||||
default: return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
using bts;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using bts.api;
|
||||
using AlgoType = bts.api.orderman.CustomOrderDefinition.CustomOneofCase;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
static partial class OrderTypeVMFactory
|
||||
{
|
||||
internal class GenericOrderFactory
|
||||
{
|
||||
static public IAlgoVM create_vm(AlgoKey key, AlgoType algo_type, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
{
|
||||
var prop = typeof(CustomOrderDefinition).GetProperty(algo_type.ToString(),
|
||||
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
|
||||
var rt = prop.PropertyType;
|
||||
|
||||
var propi = typeof(CustomOrderDefinitionImmutable).GetProperty(algo_type.ToString(),
|
||||
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
|
||||
var rti = propi.PropertyType;
|
||||
|
||||
var vmt = typeof(GenericOrderVM<,>);
|
||||
Type[] typeargs = { rt, rti };
|
||||
var makevm = vmt.MakeGenericType(typeargs);
|
||||
object vm = Activator.CreateInstance(makevm, key, algo_type, display_name, editing_permissions);
|
||||
return (IAlgoVM)vm;
|
||||
}
|
||||
static public void setup_generic_custom_order(CustomOrderDefinition custom, CustomOrderDefinition.CustomOneofCase type)
|
||||
{
|
||||
var prop = typeof(CustomOrderDefinition).GetProperty(type.ToString(),
|
||||
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
|
||||
var rt = prop.PropertyType;
|
||||
var rtt = Activator.CreateInstance(rt);
|
||||
|
||||
var ci = rt.GetProperties().Where(x => x.PropertyType == typeof(CustomOrderDefinition));
|
||||
foreach(var cid in ci)
|
||||
cid.SetValue(rtt, new CustomOrderDefinition { Limit = new LimitOrderDefinition() });
|
||||
prop.SetValue(custom, rtt);
|
||||
}
|
||||
}
|
||||
|
||||
class GenericOrderVM<TMutable, TImmutable> : OrderTypeVMBase<TMutable, TImmutable>
|
||||
where TMutable : class, IMessage, new() where TImmutable : struct, IImmutableMessage
|
||||
{
|
||||
readonly ObservableKeyedCollection<GenericOrderParamVM<TMutable>, string> _parameters =
|
||||
new ObservableKeyedCollection<GenericOrderParamVM<TMutable>, string>(vm => vm.descriptor.Name);
|
||||
readonly AlgoType _algo_type;
|
||||
|
||||
public GenericOrderVM(AlgoKey key, AlgoType algo_type, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
: base(key, display_name, editing_permissions)
|
||||
{
|
||||
_algo_type = algo_type;
|
||||
_parameters = new ObservableKeyedCollection<GenericOrderParamVM<TMutable>, string>(vm => vm.descriptor.Name);
|
||||
_resources.AddRange(
|
||||
ObservableAutoWrapper.connect_item_hooks(_parameters, p =>
|
||||
{
|
||||
p.PropertyChanged += on_param_prop_changed;
|
||||
return Disposable.Create(() =>
|
||||
{
|
||||
p.PropertyChanged -= on_param_prop_changed;
|
||||
remove_property(p.descriptor.Name);
|
||||
p.Dispose();
|
||||
});
|
||||
}, true));
|
||||
void on_param_prop_changed(object sender, PropertyChangedEventArgs e) => raise_definition_changed();
|
||||
_sync_generic_params();
|
||||
sync_selectors();
|
||||
}
|
||||
|
||||
public string algo_type => _algo_type.ToString();
|
||||
public override string abbreviation =>
|
||||
model == null ? display_name : model.factory.abbreviate_algo(new OneOf<CustomOrderDefinition.CustomOneofCase, string>(_algo_type));
|
||||
public override AlgoDisplayGroup group => AlgoDisplayGroup.API;
|
||||
public ObservableCollection<GenericOrderParamVM<TMutable>> parameters => _parameters;
|
||||
|
||||
protected override void on_model_internal()
|
||||
{
|
||||
_sync_generic_params();
|
||||
}
|
||||
|
||||
void _sync_generic_params()
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
Google.Protobuf.Reflection.MessageDescriptor desc = new TMutable().Descriptor;
|
||||
_parameters.SyncWithDictionary(
|
||||
desc.Fields.InDeclarationOrder().Where(_is_value_param_desc).ToDictionary(p => p.Name), _mk_param_vm);
|
||||
}
|
||||
}
|
||||
static bool _is_value_param_desc(FieldDescriptor desc)
|
||||
{
|
||||
return (desc.FieldType != Google.Protobuf.Reflection.FieldType.Message ||
|
||||
_is_quantity_measure_desc(desc));
|
||||
}
|
||||
|
||||
static bool _is_quantity_measure_desc(FieldDescriptor desc)
|
||||
{
|
||||
return desc.FieldType == Google.Protobuf.Reflection.FieldType.Message &&
|
||||
desc.MessageType.FullName == typeof(bts.spark.QuantityMeasure).FullName;
|
||||
}
|
||||
|
||||
protected override IEnumerable<ChildAlgoData> get_selector_datum()
|
||||
{
|
||||
var v = OrderDataHelper.get_child_algo_data(_algo_type);
|
||||
return v;
|
||||
}
|
||||
|
||||
GenericOrderParamVM<TMutable> _mk_param_vm(FieldDescriptor descriptor)
|
||||
{
|
||||
ExceptionAssert.Argument.NotNull(descriptor, nameof(descriptor));
|
||||
|
||||
if (descriptor.FieldType == FieldType.Message &&
|
||||
descriptor.MessageType.FullName == typeof(bts.spark.QuantityMeasure).FullName)
|
||||
{
|
||||
var qm = new GenericOrderQuantityVM<TMutable>(descriptor);
|
||||
return attached(qm, GenericOrderHelper.get_quantity_value, GenericOrderHelper.set_quantity_value, new QuantityMeasure { Ratio = 1.0, Absolute = 1 });
|
||||
}
|
||||
else if(descriptor.FieldType == FieldType.Enum)
|
||||
{
|
||||
var pvm = new GenericOrderEnumeratedVM<TMutable>(descriptor);
|
||||
attached(pvm, GenericOrderHelper.get_enumerated_value, GenericOrderHelper.set_enumerated_value);
|
||||
return pvm;
|
||||
}
|
||||
else if (descriptor.FieldType == FieldType.Bool)
|
||||
return mk<bool?, bool>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
else if (descriptor.FieldType == FieldType.Double || descriptor.FieldType == FieldType.Float)
|
||||
return mk<double, double>(descriptor, v => v, v => v, double.NaN);
|
||||
else if (descriptor.FieldType == FieldType.Int32)
|
||||
return mk<int?, int>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
else if (descriptor.FieldType == FieldType.UInt32)
|
||||
return mk<uint?, uint>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
else if (descriptor.FieldType == FieldType.String)
|
||||
return mk<string, string>(descriptor, v => v, v => v);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
GenericOrderParamVM<TMutable, TView, TModel> mk<TView, TModel>(FieldDescriptor fdesc, Func<TModel, TView> convert, Func<TView, TModel> convert_back, TView default_value = default)
|
||||
{
|
||||
var pvm = new GenericOrderParamVM<TMutable, TView, TModel>(fdesc, convert, convert_back);
|
||||
return attached<TView, GenericOrderParamVM<TMutable, TView, TModel>>(pvm, get_from_param, assign_to_param, default_value);
|
||||
|
||||
TView get_from_param(IMessage param, FieldDescriptor fd) => convert(ConvertUtils.try_convert<TModel>(fdesc.Accessor.GetValue(param)));
|
||||
void assign_to_param(IMessage param, FieldDescriptor fd, TView value) => fdesc.Accessor.SetValue(param, convert_back(value));
|
||||
}
|
||||
|
||||
TParam attached<T, TParam>(TParam pvm, Func<IMessage, FieldDescriptor, T> selector, Action<IMessage, FieldDescriptor, T> assign_to_param, T default_value = default) where TParam : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<T>
|
||||
{
|
||||
add_property<T>(
|
||||
pvm.descriptor.Name,
|
||||
mdef => mdef != null ? selector(mdef, pvm.descriptor) : default_value,
|
||||
(mdef, v) => assign_to_param(mdef, pvm.descriptor, v),
|
||||
() => pvm.value,
|
||||
v => pvm.value = v,
|
||||
pvm.subscribe_value(),
|
||||
default_value);
|
||||
return pvm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,7 @@ namespace mbts.spark {
|
||||
IReadOnlyObservableCollection<IAlgoVM> algos_view { get; }
|
||||
IAlgoVM selected_algo { get; set; }
|
||||
void load_algo_data(IReadOnlyDictionary<AlgoKey, AlgoData> algo_data, AlgoKey? default_algo);
|
||||
mbts.ui.spark.AlgoContentTemplateSelector.OrderKind order_kind {get;}
|
||||
}
|
||||
|
||||
static class OrderTypeVMExtensions {
|
||||
|
||||
@@ -59,6 +59,12 @@ namespace mbts.spark {
|
||||
public static IAlgoVM dynamic(AlgoKey key, string display_name, string dynamic_type, AlgoEditingPermissions editing_permissions) => new DynamicOrderVM(key, dynamic_type, display_name, editing_permissions);
|
||||
public static IAlgoVM splitter(AlgoKey key, string display_name, AlgoEditingPermissions permissions) =>
|
||||
new SplitterAlgoVM(key, display_name, permissions);
|
||||
|
||||
public static IAlgoVM generic(AlgoKey key, string display_name,
|
||||
AlgoType algo_type, AlgoEditingPermissions editing_permissions)
|
||||
{
|
||||
return GenericOrderFactory.create_vm(key, algo_type, display_name, editing_permissions);
|
||||
}
|
||||
|
||||
public static IAlgoVM create(AlgoData def_data, AlgoEditingPermissions editing_permissions = default_editing_permissions, bool is_expanded = false) {
|
||||
if (def_data.value.CustomCase == AlgoType.Composite) {
|
||||
@@ -92,7 +98,7 @@ namespace mbts.spark {
|
||||
case AlgoType.Dynamic: vm = dynamic(key, name, name, editing_permissions); break;
|
||||
case AlgoType.Splitter: vm = splitter(key,name,editing_permissions); break;
|
||||
case AlgoType.None: vm = new DefaultAlgoVM(); break;
|
||||
default: throw new NotImplementedException();
|
||||
default: vm = generic(key, name, algo_type, editing_permissions); break;
|
||||
}
|
||||
vm.is_expanded = is_expanded && vm.can_expand;
|
||||
return vm;
|
||||
@@ -953,6 +959,8 @@ namespace mbts.spark {
|
||||
|
||||
public string id { get; }
|
||||
public string display_name { get; }
|
||||
public mbts.ui.spark .AlgoContentTemplateSelector.OrderKind order_kind =>
|
||||
new mbts.ui.spark.AlgoContentTemplateSelector.OrderKind(display_name, string.Empty);
|
||||
public bool is_enabled { get; set; } = true;
|
||||
|
||||
public bool initialized { get; private set; }
|
||||
|
||||
@@ -1171,6 +1171,30 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:DynamicOrderParamTemplateSelector.EnumTemplate>
|
||||
<usp:DynamicOrderParamTemplateSelector.QuantityMeasureTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center"
|
||||
Text="{Binding descriptor.ParamName, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<uag:QuantityMeasureControl
|
||||
Grid.Column="2" Focusable="False" HorizontalAlignment="Stretch"
|
||||
QuantityMeasure="{Binding quantity, UpdateSourceTrigger=PropertyChanged}" ArrowKeyTickModifiers="Ctrl">
|
||||
<uag:QuantityMeasureControl.CommandBindings>
|
||||
<CommandBinding Command="{x:Static u:NavigationHelper.MoveFocusCommand}" Executed="{x:Static u:NavigationHelper.KeyboardMoveFocusExecuted}"/>
|
||||
</uag:QuantityMeasureControl.CommandBindings>
|
||||
<uag:QuantityMeasureControl.InputBindings>
|
||||
<KeyBinding Key="Up" Command="{x:Static u:NavigationHelper.MoveFocusCommand}" CommandParameter="{x:Static FocusNavigationDirection.Up}"/>
|
||||
<KeyBinding Key="Down" Command="{x:Static u:NavigationHelper.MoveFocusCommand}" CommandParameter="{x:Static FocusNavigationDirection.Down}"/>
|
||||
</uag:QuantityMeasureControl.InputBindings>
|
||||
</uag:QuantityMeasureControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:DynamicOrderParamTemplateSelector.QuantityMeasureTemplate>
|
||||
</usp:DynamicOrderParamTemplateSelector>
|
||||
</ItemsControl.ItemTemplateSelector>
|
||||
</ItemsControl>
|
||||
@@ -1191,5 +1215,175 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:AlgoContentTemplateSelector.DynamicOrderTemplate>
|
||||
<usp:AlgoContentTemplateSelector.GenericOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush3}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ItemsControl Grid.ColumnSpan="3" ItemsSource="{Binding parameters}" IsTabStop="False">
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style>
|
||||
<Setter Property="Control.Margin" Value="{StaticResource Margin.TP1}"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplateSelector>
|
||||
<usp:GenericOrderParamTemplateSelector>
|
||||
<usp:GenericOrderParamTemplateSelector.BoolTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<CheckBox
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
IsChecked="{Binding value, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.BoolTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.DoubleTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<c:TickUpDownDouble
|
||||
Grid.Column="2"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
Value="{Binding value, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.DoubleTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.IntTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<c:TickUpDownInt
|
||||
Grid.Column="2"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
Value="{Binding value, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.IntTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<c:TickUpDownUInt
|
||||
Grid.Column="2"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
Value="{Binding value, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.UIntTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.StringTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<TextBox
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
Text="{Binding value, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.StringTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.EnumTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<ComboBox
|
||||
Grid.Column="2"
|
||||
IsEnabled="{Binding DataContext.editing_permissions, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource CanEditValuesConverter}}"
|
||||
ItemsSource="{Binding elements}"
|
||||
SelectedItem="{Binding selected_element}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.EnumTemplate>
|
||||
<usp:GenericOrderParamTemplateSelector.QuantityMeasureTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush3}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center"
|
||||
Text="{Binding descriptor.Name, Converter={x:Static ut:DisplayNameHelper.SnakeToTitleCaseConverter}}"/>
|
||||
<uag:QuantityMeasureControl
|
||||
Grid.Column="2" Focusable="False" HorizontalAlignment="Stretch"
|
||||
QuantityMeasure="{Binding quantity, UpdateSourceTrigger=PropertyChanged}" ArrowKeyTickModifiers="Ctrl">
|
||||
<uag:QuantityMeasureControl.CommandBindings>
|
||||
<CommandBinding Command="{x:Static u:NavigationHelper.MoveFocusCommand}" Executed="{x:Static u:NavigationHelper.KeyboardMoveFocusExecuted}"/>
|
||||
</uag:QuantityMeasureControl.CommandBindings>
|
||||
<uag:QuantityMeasureControl.InputBindings>
|
||||
<KeyBinding Key="Up" Command="{x:Static u:NavigationHelper.MoveFocusCommand}" CommandParameter="{x:Static FocusNavigationDirection.Up}"/>
|
||||
<KeyBinding Key="Down" Command="{x:Static u:NavigationHelper.MoveFocusCommand}" CommandParameter="{x:Static FocusNavigationDirection.Down}"/>
|
||||
</uag:QuantityMeasureControl.InputBindings>
|
||||
</uag:QuantityMeasureControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector.QuantityMeasureTemplate>
|
||||
</usp:GenericOrderParamTemplateSelector>
|
||||
</ItemsControl.ItemTemplateSelector>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Row="2" Grid.ColumnSpan="3" ItemsSource="{Binding child_algo_selectors_view}" IsTabStop="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<uag:AlgoPickerNodeView
|
||||
ItemsSource="{Binding algos_view}"
|
||||
SelectedItem="{Binding selected_algo}"
|
||||
CanEditStructure="{Binding DataContext.editing_permissions, Converter={StaticResource CanEditStructureConverter}, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
ContentTemplateSelector="{DynamicResource AlgoTemplateSelector}"
|
||||
OrderKind="{Binding order_kind}"
|
||||
OrderKindTemplate="{StaticResource OrderKindTemplate}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:AlgoContentTemplateSelector.GenericOrderTemplate>
|
||||
</usp:AlgoContentTemplateSelector>
|
||||
</ResourceDictionary>
|
||||
@@ -46,6 +46,7 @@ namespace mbts.ui.spark {
|
||||
public DataTemplate SplitterTemplate { get; set; }
|
||||
public DataTemplate DynamicOrderTemplate { get; set; }
|
||||
public DataTemplate DefaultOrderTemplate { get; set; }
|
||||
public DataTemplate GenericOrderTemplate { get; set; }
|
||||
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
||||
if (item is IDynamicAlgoVMImpl) {
|
||||
@@ -69,6 +70,7 @@ namespace mbts.ui.spark {
|
||||
case CustomOrderDefinition.CustomOneofCase.Spreader: return SpreaderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Splitter: return SplitterTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Dynamic: return DynamicOrderTemplate;
|
||||
default: return GenericOrderTemplate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -102,6 +102,8 @@ message CustomOrderDefinition
|
||||
PricerOrderDefinition pricer = 26;
|
||||
CompositeOrderDefinition composite = 27;
|
||||
SplitterOrderDefinition splitter = 29;
|
||||
ScratchOrderDefinition scratch = 31;
|
||||
ProRataOrderDefinition prorata = 32;
|
||||
|
||||
DynamicOrderDefinition dynamic = 1000;
|
||||
}
|
||||
@@ -211,6 +213,23 @@ message SplitterOrderDefinition {
|
||||
// uint32 target_qty = 3;
|
||||
CustomOrderDefinition child = 10;
|
||||
}
|
||||
message ScratchOrderDefinition {
|
||||
spark.QuantityMeasure scratch_threshold = 1;
|
||||
uint32 chase_ticks = 2;
|
||||
CustomOrderDefinition child = 10;
|
||||
}
|
||||
message ProRataOrderDefinition {
|
||||
uint32 hedge_ticks = 1;
|
||||
uint32 chase_ticks = 2;
|
||||
spark.QuantityMeasure fill_limit = 5;
|
||||
spark.QuantityMeasure stay_in_threshold = 6;
|
||||
bool enable_scratch_on_overfill = 7;
|
||||
bool enable_stay_in = 8;
|
||||
|
||||
CustomOrderDefinition child = 10;
|
||||
CustomOrderDefinition hedge = 20;
|
||||
CustomOrderDefinition overfill_hedge = 30;
|
||||
}
|
||||
message DynamicOrderDefinition {
|
||||
string dynamic_order_type = 1;
|
||||
map<string, DynamicOrderParam> order_params = 2;
|
||||
@@ -264,6 +283,8 @@ message OrderState {
|
||||
PricerOrderState pricer = 26;
|
||||
QueueHolderState queue_holder = 30;
|
||||
SplitterOrderState splitter = 31;
|
||||
ScratchOrderState scratch = 32;
|
||||
ProRataOrderState prorata = 33;
|
||||
|
||||
DynamicOrderState dynamic = 255; // do not use anything bigger than 255, or things will break
|
||||
}
|
||||
@@ -340,6 +361,8 @@ message CoverOrderState {}
|
||||
message OffsetOrderState {}
|
||||
message OCOOrderState {}
|
||||
message PricerOrderState {}
|
||||
message ScratchOrderState {}
|
||||
message ProRataOrderState {}
|
||||
message DynamicOrderState {}
|
||||
message QueueHolderState {}
|
||||
message SplitterOrderState {}
|
||||
@@ -560,6 +583,7 @@ enum DynamicOrderPrimitiveDescriptor {
|
||||
DYNAMIC_ORDER_PRIMITIVE_STRING = 3;
|
||||
DYNAMIC_ORDER_PRIMITIVE_BOOL = 4;
|
||||
DYNAMIC_ORDER_PRIMITIVE_ORDER_DEF = 5;
|
||||
DYNAMIC_ORDER_PRIMITIVE_QUANTITY = 6;
|
||||
}
|
||||
|
||||
message DynamicOrderTypeDescriptor {
|
||||
@@ -608,6 +632,7 @@ message DynamicOrderParam {
|
||||
DynamicOrderArray as_array = 7;
|
||||
DynamicOrderStruct as_struct = 8;
|
||||
DynamicOrderEnumerated as_enumerated = 9;
|
||||
spark.QuantityMeasure as_quantity = 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,12 @@ class OrderStateUpdateEvent : public mercury::Event<OrderStateUpdateEvent> {
|
||||
case api::orderman::OrderState::kPricer:
|
||||
result.mutable_pricer();
|
||||
break;
|
||||
case api::orderman::OrderState::kScratch:
|
||||
result.mutable_scratch();
|
||||
break;
|
||||
case api::orderman::OrderState::kProrata:
|
||||
result.mutable_prorata();
|
||||
break;
|
||||
case api::orderman::OrderState::kDynamic:
|
||||
result.mutable_dynamic();
|
||||
break;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "lib/orderman/orders/algo/algo_orders/LeanAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/SplitterAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/OffsetAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/ScratchAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/ProRataAlgo.h"
|
||||
#include "lib/orderman/orders/book_algos/OCOOrder.h"
|
||||
#include "lib/orderman/orders/book_algos/PricerOrder.h"
|
||||
#include "lib/orderman/orders/spreader_orders/SpreaderOrder.h"
|
||||
@@ -195,6 +197,14 @@ Order &OrderFactory::allocate(OrderKey k, OrderKey pk,
|
||||
case CustomOrderDefinition::kPricer:
|
||||
order_ptr.reset(new orderman::PricerOrder());
|
||||
break;
|
||||
case CustomOrderDefinition::kScratch:
|
||||
order_ptr.reset(
|
||||
new orderman::AlgoWrapperOrder(std::make_unique<ScratchAlgo>()));
|
||||
break;
|
||||
case CustomOrderDefinition::kProrata:
|
||||
order_ptr.reset(
|
||||
new orderman::AlgoWrapperOrder(std::make_unique<ProRataAlgo>()));
|
||||
break;
|
||||
case CustomOrderDefinition::kDynamic: {
|
||||
order_ptr = me->dynamic_order_registry.build(
|
||||
def.custom_def().dynamic().dynamic_order_type());
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "DynamicHelpers.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
template<>
|
||||
bool has_custom<api::orderman::Update>(const api::orderman::Update& orig)
|
||||
{
|
||||
return orig.has_custom();
|
||||
}
|
||||
|
||||
template<>
|
||||
const api::orderman::CustomOrderDefinition& custom<api::orderman::Update>(const api::orderman::Update& orig)
|
||||
{
|
||||
return orig.custom();
|
||||
}
|
||||
|
||||
template<>
|
||||
api::orderman::CustomOrderDefinition& mutable_custom<api::orderman::Update>(api::orderman::Update& orig)
|
||||
{
|
||||
return *orig.mutable_custom();
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
template<typename T>
|
||||
bool has_custom(const T& orig)
|
||||
{
|
||||
return orig.has_custom_def();
|
||||
}
|
||||
template<>
|
||||
bool has_custom(const api::orderman::Update& orig);
|
||||
|
||||
template<typename T>
|
||||
const api::orderman::CustomOrderDefinition& custom(const T& orig)
|
||||
{
|
||||
return orig.custom_def();
|
||||
}
|
||||
template<>
|
||||
const api::orderman::CustomOrderDefinition& custom<api::orderman::Update>(const api::orderman::Update& orig);
|
||||
|
||||
template<typename T>
|
||||
api::orderman::CustomOrderDefinition& mutable_custom(T& orig)
|
||||
{
|
||||
return *orig.mutable_custom_def();
|
||||
}
|
||||
template<>
|
||||
api::orderman::CustomOrderDefinition& mutable_custom<api::orderman::Update>(api::orderman::Update& orig);
|
||||
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,390 @@
|
||||
#include "lib/orderman/orders/algo/algo_orders/ProRataAlgo.h"
|
||||
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/orderman/order_factory/IOrderFactory.h"
|
||||
#include "lib/orderman/orders/algo/IAlgoServices.h"
|
||||
#include "lib/orderman/orders/algo/DynamicHelpers.h"
|
||||
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
enum class ProRataAlgo::Status { WAITING_FOR_MD, WORKING, DONE_WORKING, GETTING_OUT }; //this is for the child
|
||||
const char *ProRataAlgo::status_name(Status st)
|
||||
{
|
||||
switch (st)
|
||||
{
|
||||
case Status::WAITING_FOR_MD:
|
||||
return "WAITING_FOR_MD";
|
||||
case Status::WORKING:
|
||||
return "WORKING";
|
||||
case Status::DONE_WORKING:
|
||||
return "DONE_WORKING";
|
||||
case Status::GETTING_OUT:
|
||||
return "GETTING_OUT";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
struct ProRataAlgo::PImpl
|
||||
{
|
||||
PImpl() :
|
||||
is_overfilled(false)
|
||||
{
|
||||
}
|
||||
IAlgoServices *algo;
|
||||
OrderKey child_key = null_order_key();
|
||||
|
||||
Price hedge_price_diff;
|
||||
Price chase_diff;
|
||||
Quantity fill_limit;
|
||||
Quantity stay_in_threshold;
|
||||
bool enable_scratch_on_overfill;
|
||||
bool enable_stay_in;
|
||||
|
||||
ChildTemplate *child_template = nullptr;
|
||||
ChildTemplate *hedge_template = nullptr;
|
||||
ChildTemplate *overfill_hedge_template = nullptr;
|
||||
|
||||
Quantity hedged_fills = Quantity(0);
|
||||
Status status = Status::WAITING_FOR_MD;
|
||||
std::vector<OrderKey> hedges;
|
||||
std::map<OrderKey, Quantity> overfill_hedges;
|
||||
|
||||
Book last_book;
|
||||
Book book_at_inception;
|
||||
bool is_overfilled;
|
||||
};
|
||||
|
||||
ProRataAlgo::ProRataAlgo() : me(new PImpl()) {}
|
||||
ProRataAlgo::~ProRataAlgo() {}
|
||||
IAlgoServices &ProRataAlgo::algo() const { return *me->algo; }
|
||||
|
||||
|
||||
OrderOpResult ProRataAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
|
||||
{
|
||||
const api::orderman::OrderDefinition& def = serv.definition();
|
||||
bts_assert(def.has_custom_def());
|
||||
bts_assert(def.custom_def().has_prorata());
|
||||
|
||||
// Validate the prorata part of the definition
|
||||
auto &prorata = def.custom_def().prorata();
|
||||
if (!prorata.has_child() && OrderKey(def.attach_target_order_key()) == null_order_key())
|
||||
{
|
||||
return OrderOpResult{ ORDER_ERROR_INVALID_ORDER_DEFINITON,
|
||||
"ProRata order must have either a child order definition or an order to attach to"};
|
||||
}
|
||||
|
||||
if (!prorata.has_hedge())
|
||||
return OrderOpResult{ORDER_ERROR_INVALID_ORDER_DEFINITON, "ProRata order must have a hedge order definition"};
|
||||
if (!serv.is_attaching())
|
||||
{
|
||||
// if we are not attaching create a child template so we can
|
||||
// quickly launch our child when the time comes.
|
||||
auto child_def = def;
|
||||
*child_def.mutable_custom_def() = def.custom_def().prorata().child();
|
||||
me->child_template = &(serv.make_child_template(child_def));
|
||||
}
|
||||
|
||||
init_hedge_template(serv, prorata.hedge(), false);
|
||||
init_hedge_template(serv, prorata.overfill_hedge(), true);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void ProRataAlgo::do_launch(IAlgoServices &algo)
|
||||
{
|
||||
me->algo = &algo;
|
||||
set_parameters(algo, algo.definition().custom_def().prorata());
|
||||
LOG(OrderMan, Diag, "Starting ProRataAlgo {}, {} {}@{}. Will cover {} ticks",
|
||||
algo.order_key().value(),
|
||||
securities::side_name(algo.definition().side()), algo.quantity().value(),
|
||||
algo.price().value(),
|
||||
algo.definition().custom_def().prorata().hedge_ticks());
|
||||
|
||||
LOG(OrderMan, Diag, "ProRataAlgo {} launching child", algo.order_key().value());
|
||||
me->child_key = algo.launch_child(*me->child_template, algo.price(), algo.quantity());
|
||||
algo.subscribe_book(SecurityKey(algo.security().id()));
|
||||
}
|
||||
|
||||
void ProRataAlgo::do_launch_attached(IAlgoServices &algo, OrderKey k, ChildState st)
|
||||
{
|
||||
me->algo = &algo;
|
||||
set_parameters(algo, algo.definition().custom_def().prorata());
|
||||
me->child_key = k;
|
||||
me->hedged_fills = st.total_fills;
|
||||
algo.subscribe_book(SecurityKey(algo.security().id()));
|
||||
on_child_change(k, st);
|
||||
}
|
||||
|
||||
void ProRataAlgo::on_book(SecurityKey, const Book& b)
|
||||
{
|
||||
me->last_book = b;
|
||||
|
||||
LOG(OrderMan, Diag, "ProRataAlgo order {} on book. BID: {}@{} ASK: {}@{}",
|
||||
algo().order_key().value(), b.side(api::SIDE_BUY)[0].size(),
|
||||
b.side(api::SIDE_BUY)[0].price(), b.side(api::SIDE_SELL)[0].size(),
|
||||
b.side(api::SIDE_SELL)[0].price());
|
||||
|
||||
switch (me->status)
|
||||
{
|
||||
case Status::WAITING_FOR_MD:
|
||||
{
|
||||
auto other_side = securities::other_side(algo().definition().side());
|
||||
auto &other_side_top = me->last_book.side(other_side)[0];
|
||||
|
||||
if (other_side_top.size() > 0)
|
||||
{
|
||||
me->status = Status::WORKING;
|
||||
me->book_at_inception = b;
|
||||
LOG(OrderMan, Diag,
|
||||
"ProRataAlgo order {} receiving first book: {} Target: {}",
|
||||
algo().order_key().value(), me->fill_limit.value(),
|
||||
other_side_top.price());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Status::WORKING:
|
||||
check_overfill();
|
||||
break;
|
||||
case Status::DONE_WORKING:
|
||||
check_overfill();
|
||||
break;
|
||||
case Status::GETTING_OUT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProRataAlgo::check_overfill()
|
||||
{
|
||||
if(me->is_overfilled && me->status != Status::GETTING_OUT)
|
||||
{
|
||||
if(me->enable_stay_in)
|
||||
{
|
||||
auto my_side = algo().definition().side();
|
||||
auto other_side = securities::other_side(my_side);
|
||||
|
||||
auto &my_side_psz = me->last_book.side(my_side)[0];
|
||||
auto &other_side_psz = me->last_book.side(other_side)[0];
|
||||
bool market_moved = !securities::is_equal_or_better(other_side,
|
||||
Price(other_side_psz.price()), Price(me->book_at_inception.side(other_side)[0].price()));
|
||||
bool on_market = securities::is_same(Price(my_side_psz.price()), Price(algo().price()));
|
||||
|
||||
if (market_moved || (on_market && my_side_psz.size() <= me->stay_in_threshold.value()) )
|
||||
get_out();
|
||||
}
|
||||
else
|
||||
get_out();
|
||||
}
|
||||
}
|
||||
|
||||
void ProRataAlgo::scratch(std::pair<const OrderKey, Quantity> kk)
|
||||
{
|
||||
auto cross_side = algo().definition().side();
|
||||
Price scratch_price;
|
||||
Quantity scratch_quan;
|
||||
SpreaderUtils::traverse_depth_for_quantity(me->last_book, cross_side, kk.second, scratch_price, scratch_quan);
|
||||
//Quantity scratch_quan = Price(me->book_at_inception.side(other_side)[0].price())
|
||||
scratch_price = securities::worsen_price(cross_side, scratch_price, me->chase_diff);
|
||||
|
||||
Update update;
|
||||
update.set_price(scratch_price.value());
|
||||
update.set_quantity(kk.second.value());
|
||||
algo().update_child(kk.first, update);
|
||||
}
|
||||
|
||||
void ProRataAlgo::get_out()
|
||||
{
|
||||
if(me->status != Status::GETTING_OUT)
|
||||
{
|
||||
me->status = Status::GETTING_OUT;
|
||||
algo().cancel_child(me->child_key);
|
||||
if(me->enable_scratch_on_overfill)
|
||||
{
|
||||
for(auto& h : me->overfill_hedges)
|
||||
scratch(h);
|
||||
}
|
||||
check_terminate();
|
||||
}
|
||||
}
|
||||
|
||||
void ProRataAlgo::standard_hedge(Price hedge_price, Quantity hedge_qty)
|
||||
{
|
||||
auto hedge = algo().launch_child(*me->hedge_template, hedge_price, hedge_qty);
|
||||
me->hedges.push_back(hedge);
|
||||
LOG(OrderMan, Diag,
|
||||
"ProRataAlgo {}, launched new hedge in response to child fill. "
|
||||
"Hedge: {} {}@{}",
|
||||
algo().order_key().value(),
|
||||
securities::side_name(algo().definition().side()),
|
||||
hedge_qty.value(), hedge_price.value());
|
||||
}
|
||||
|
||||
void ProRataAlgo::overfill_hedge(Price hedge_price, Quantity hedge_qty)
|
||||
{
|
||||
auto hedge = algo().launch_child(*me->overfill_hedge_template, hedge_price, hedge_qty);
|
||||
me->overfill_hedges[hedge] = hedge_qty;
|
||||
LOG(OrderMan, Diag,
|
||||
"ProRataAlgo {}, launched new OVERFILL hedge in response to child fill. "
|
||||
"Hedge: {} {}@{}",
|
||||
algo().order_key().value(),
|
||||
securities::side_name(algo().definition().side()),
|
||||
hedge_qty.value(), hedge_price.value());
|
||||
me->is_overfilled = true;
|
||||
check_overfill();
|
||||
}
|
||||
|
||||
void ProRataAlgo::on_child_change(OrderKey k, const ChildState& st)
|
||||
{
|
||||
if (k == me->child_key)
|
||||
{
|
||||
if (st.total_fills.value() > me->hedged_fills.value() && me->status == Status::WORKING)
|
||||
{
|
||||
auto hedge_qty = Quantity(st.total_fills.value() - me->hedged_fills.value());
|
||||
auto hedge_price = securities::improve_price(algo().definition().side(), st.last_price, me->hedge_price_diff);
|
||||
if( me->hedged_fills.value() + hedge_qty.value() <= me->fill_limit.value() )
|
||||
standard_hedge(hedge_price, hedge_qty);
|
||||
else
|
||||
{
|
||||
auto over = me->hedged_fills.value() + hedge_qty.value() - me->fill_limit.value();
|
||||
if(over < hedge_qty.value())
|
||||
{
|
||||
standard_hedge(hedge_price, Quantity(hedge_qty.value() - over));
|
||||
overfill_hedge(hedge_price, Quantity(over));
|
||||
}
|
||||
else
|
||||
overfill_hedge(hedge_price, hedge_qty);
|
||||
}
|
||||
me->hedged_fills = Quantity(hedge_qty.value() + me->hedged_fills.value());
|
||||
}
|
||||
algo().update_fill_state(st.total_fills, st.last_price);
|
||||
switch (st.status)
|
||||
{
|
||||
case ChildStatus::WORKING:
|
||||
break;
|
||||
case ChildStatus::COMPLETED:
|
||||
LOG(OrderMan, Info, "ProRataAlgo {}. Child is completed, waiting for hedges ", algo().order_key().value());
|
||||
me->status = Status::DONE_WORKING;
|
||||
break;
|
||||
case ChildStatus::CANCELED:
|
||||
LOG(OrderMan, Info, "ProRataAlgo {}. Child was canceled, waiting on hedges", algo().order_key().value());
|
||||
me->status = Status::DONE_WORKING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else //it's a hedge
|
||||
{
|
||||
switch (st.status)
|
||||
{
|
||||
case ChildStatus::WORKING:
|
||||
break;
|
||||
case ChildStatus::CANCELED:
|
||||
case ChildStatus::COMPLETED:
|
||||
if (auto it = std::find(me->hedges.begin(), me->hedges.end(), k); it != me->hedges.end())
|
||||
me->hedges.erase(it);
|
||||
if(me->overfill_hedges.find(k) != me->overfill_hedges.end())
|
||||
me->overfill_hedges.erase(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
check_terminate();
|
||||
}
|
||||
|
||||
void ProRataAlgo::do_update(const api::orderman::Update& update)
|
||||
{
|
||||
if (me->status != Status::DONE_WORKING)
|
||||
{
|
||||
LOG(OrderMan, Diag, "ProRataAlgo order {} receiving update: {}",
|
||||
algo().order_key().value(), utils::pb::to_string(update));
|
||||
|
||||
if (update.has_custom() && !update.custom().has_prorata())
|
||||
{
|
||||
algo().terminate_error("Invalid update");
|
||||
return;
|
||||
}
|
||||
|
||||
Update child_update;
|
||||
child_update.set_price(update.price());
|
||||
child_update.set_quantity(update.quantity());
|
||||
|
||||
// process custom part of the udpate if any
|
||||
if (update.has_custom())
|
||||
{
|
||||
auto &prorata_update = update.custom().prorata();
|
||||
set_parameters(algo(), prorata_update);
|
||||
|
||||
if(prorata_update.has_child())
|
||||
*child_update.mutable_custom() = prorata_update.child();
|
||||
if(prorata_update.has_hedge())
|
||||
init_hedge_template(algo(), prorata_update.hedge(), false);
|
||||
if(prorata_update.has_overfill_hedge())
|
||||
init_hedge_template(algo(), prorata_update.overfill_hedge(), true);
|
||||
}
|
||||
algo().update_child(me->child_key, child_update);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(OrderMan, Info,
|
||||
"ProRataAlgo {}. Received update after child has completed. Ignoring it.",
|
||||
algo().order_key().value());
|
||||
}
|
||||
}
|
||||
|
||||
void orderman::ProRataAlgo::init_hedge_template(IBeforeLaunchAlgoServices &algo,
|
||||
const api::orderman::CustomOrderDefinition& hedge_cdef, bool overfill)
|
||||
{
|
||||
api::orderman::OrderDefinition hedge_def;
|
||||
hedge_def.CopyFrom(algo.definition());
|
||||
|
||||
hedge_def.set_side(securities::other_side(algo.definition().side()));
|
||||
hedge_def.set_sub_type(ORDER_SUB_TYPE_HEDGING_LEG);
|
||||
hedge_def.clear_attach_target_order_key();
|
||||
*hedge_def.mutable_custom_def() = hedge_cdef;
|
||||
if(!overfill)
|
||||
me->hedge_template = &(algo.make_child_template(hedge_def));
|
||||
else
|
||||
me->overfill_hedge_template = &(algo.make_child_template(hedge_def));
|
||||
}
|
||||
|
||||
void ProRataAlgo::set_parameters(IBeforeLaunchAlgoServices &serv, const api::orderman::ProRataOrderDefinition& prorata)
|
||||
{
|
||||
me->hedge_price_diff = Price(securities::tick_size(serv.security()).value() * prorata.hedge_ticks());
|
||||
me->chase_diff = Price(securities::tick_size(serv.security()).value() * prorata.chase_ticks());
|
||||
|
||||
if (!prorata.has_fill_limit() || prorata.fill_limit().quantity_case() ==
|
||||
bts::spark::QuantityMeasure::QuantityCase::QUANTITY_NOT_SET)
|
||||
{
|
||||
algo().terminate_error("Invalid fill limit quantity, terminating");
|
||||
return;
|
||||
}
|
||||
me->fill_limit = SpreaderUtils::_quantity_threshold(prorata.fill_limit(), algo().quantity());
|
||||
|
||||
if (!prorata.has_stay_in_threshold() || prorata.stay_in_threshold().quantity_case() ==
|
||||
bts::spark::QuantityMeasure::QuantityCase::QUANTITY_NOT_SET)
|
||||
{
|
||||
algo().terminate_error("Invalid stay_in_threshold quantity, terminating");
|
||||
return;
|
||||
}
|
||||
me->stay_in_threshold = SpreaderUtils::_quantity_threshold(prorata.stay_in_threshold(), algo().quantity());
|
||||
me->enable_scratch_on_overfill = prorata.enable_scratch_on_overfill();
|
||||
me->enable_stay_in = prorata.enable_stay_in();
|
||||
}
|
||||
|
||||
void ProRataAlgo::check_terminate()
|
||||
{
|
||||
LOG(OrderMan, Diag,
|
||||
"ProRataAlgo {} check_terminate. State: {} Hedge count: {}",
|
||||
algo().order_key(), log::CharPtrWrapper{status_name(me->status)}, me->hedges.size());
|
||||
|
||||
if (me->status == Status::DONE_WORKING && me->hedges.empty() && me->overfill_hedges.empty())
|
||||
{
|
||||
LOG(OrderMan, Info, "ProRataAlgo {}. Last hedge completed, terminating", algo().order_key().value());
|
||||
algo().complete();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/algo/IAlgoOrder.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
// ProRata initializes the child order as normal. Fills trigger one type of hedge, overfills (fills > limit) trigger another
|
||||
// type of hedge. Overfills also optionally trigger overfill_hedge scratching and cancelling children dependent on book state
|
||||
|
||||
class ProRataAlgo : public IAlgoOrder
|
||||
{
|
||||
public:
|
||||
ProRataAlgo();
|
||||
~ProRataAlgo();
|
||||
|
||||
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
|
||||
void do_launch(IAlgoServices &) override;
|
||||
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
|
||||
void do_update(const api::orderman::Update&) override;
|
||||
void on_book(SecurityKey, const Book&) override;
|
||||
void on_child_change(OrderKey, const ChildState&) override;
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
enum class Status;
|
||||
std::unique_ptr<PImpl> me;
|
||||
IAlgoServices &algo() const;
|
||||
void set_parameters(IBeforeLaunchAlgoServices &, const api::orderman::ProRataOrderDefinition&);
|
||||
void init_hedge_template(IBeforeLaunchAlgoServices &, const api::orderman::CustomOrderDefinition&, bool);
|
||||
void scratch(std::pair<const OrderKey, Quantity> kk);
|
||||
void get_out();
|
||||
void standard_hedge(Price hedge_price, Quantity hedge_qty);
|
||||
void overfill_hedge(Price hedge_price, Quantity hedge_qty);
|
||||
void check_overfill();
|
||||
void check_terminate();
|
||||
const char *status_name(Status st);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,227 @@
|
||||
#include "lib/orderman/orders/algo/algo_orders/ScratchAlgo.h"
|
||||
#include "lib/orderman/orders/algo/IAlgoServices.h"
|
||||
#include "lib/orderman/orders/algo/DynamicHelpers.h"
|
||||
|
||||
#include "lib/orderman/order_factory/IOrderFactory.h"
|
||||
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
|
||||
enum class ScratchAlgo::Status { WAITING_FOR_MD, WAITING_TO_SCRATCH, SCRATCHED };
|
||||
|
||||
struct ScratchAlgo::PImpl
|
||||
{
|
||||
IAlgoServices *algo;
|
||||
OrderDefinition definition;
|
||||
|
||||
Quantity scratch_threshold;
|
||||
Price chase_diff;
|
||||
Status status = Status::WAITING_FOR_MD;
|
||||
OrderKey child_key = null_order_key();
|
||||
ChildTemplate *child_template = nullptr;
|
||||
Book last_book;
|
||||
Book book_at_inception;
|
||||
Price scratch_price=Price(os::nan());
|
||||
};
|
||||
|
||||
ScratchAlgo::ScratchAlgo() : me(new PImpl()) {}
|
||||
ScratchAlgo::~ScratchAlgo() {}
|
||||
IAlgoServices &ScratchAlgo::algo() const { return *me->algo; }
|
||||
|
||||
OrderOpResult ScratchAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
|
||||
{
|
||||
const auto& def = serv.definition();
|
||||
bts_assert(def.has_custom_def());
|
||||
bts_assert(def.custom_def().has_scratch());
|
||||
// Validate the scratch part of the definition
|
||||
auto &scratch = def.custom_def().scratch();
|
||||
if (!scratch.has_child() && OrderKey(def.attach_target_order_key()) == null_order_key())
|
||||
{
|
||||
return OrderOpResult{ ORDER_ERROR_INVALID_ORDER_DEFINITON,
|
||||
"Scratch order must have either a child order definition or an order to attach to"};
|
||||
}
|
||||
if (!serv.is_attaching())
|
||||
{
|
||||
// if we are not attaching create a child template so we can
|
||||
// quickly launch our child when the time comes.
|
||||
auto child_def = def;
|
||||
*child_def.mutable_custom_def() = def.custom_def().scratch().child();
|
||||
me->child_template = &(serv.make_child_template(child_def));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void ScratchAlgo::do_launch(IAlgoServices &algo)
|
||||
{
|
||||
me->algo = &algo;
|
||||
update_scratch_threshold();
|
||||
bts_assert(me->child_template);
|
||||
me->child_key = algo.launch_child(*me->child_template, algo.price(), algo.quantity());
|
||||
algo.subscribe_book(SecurityKey(algo.security().id()));
|
||||
}
|
||||
|
||||
void ScratchAlgo::do_launch_attached(IAlgoServices &algo, OrderKey k, ChildState st)
|
||||
{
|
||||
me->algo = &algo;
|
||||
update_scratch_threshold();
|
||||
me->child_key = k;
|
||||
algo.subscribe_book(SecurityKey(algo.security().id()));
|
||||
on_child_change(k, st);
|
||||
}
|
||||
|
||||
void ScratchAlgo::do_update(api::orderman::Update const &update)
|
||||
{
|
||||
LOG(OrderMan, Diag, "ScratchOrder order {} receiving update: {}", algo().order_key().value(), utils::pb::to_string(update));
|
||||
|
||||
if (update.has_custom() && !update.custom().has_scratch())
|
||||
{
|
||||
algo().terminate_error("Invalid update");
|
||||
return;
|
||||
}
|
||||
|
||||
Update child_update;
|
||||
Price price_to_pass = get_price_to_pass(Price(update.price()));
|
||||
child_update.set_price(price_to_pass.value());
|
||||
child_update.set_quantity(update.quantity());
|
||||
if (update.has_custom())
|
||||
{
|
||||
update_scratch_threshold();
|
||||
auto &scratch_update = update.custom().scratch();
|
||||
*child_update.mutable_custom() = scratch_update.child();
|
||||
}
|
||||
algo().update_child(me->child_key, child_update);
|
||||
|
||||
// If we were not yet scratched it is possible we now can, since we
|
||||
// could have changed the scratch_threshold
|
||||
if (me->status == Status::WAITING_TO_SCRATCH)
|
||||
try_to_scratch();
|
||||
}
|
||||
|
||||
void ScratchAlgo::on_book(SecurityKey, Book const &b)
|
||||
{
|
||||
me->last_book = b;
|
||||
|
||||
LOG(OrderMan, Diag, "ScratchOrder order {} on book. BID: {}@{} ASK: {}@{}",
|
||||
algo().order_key().value(), b.side(api::SIDE_BUY)[0].size(),
|
||||
b.side(api::SIDE_BUY)[0].price(), b.side(api::SIDE_SELL)[0].size(),
|
||||
b.side(api::SIDE_SELL)[0].price());
|
||||
|
||||
switch (me->status)
|
||||
{
|
||||
case Status::WAITING_FOR_MD:
|
||||
{
|
||||
auto other_side = securities::other_side(algo().definition().side());
|
||||
auto &other_side_top = me->last_book.side(other_side)[0];
|
||||
|
||||
if (other_side_top.size() > 0)
|
||||
{
|
||||
me->status = Status::WAITING_TO_SCRATCH;
|
||||
me->book_at_inception = b;
|
||||
LOG(OrderMan, Diag,
|
||||
"ScratchOrder order {} receiving first book: {} Target: {}",
|
||||
algo().order_key().value(), me->scratch_threshold.value(),
|
||||
other_side_top.price());
|
||||
try_to_scratch();
|
||||
}
|
||||
} break;
|
||||
case Status::SCRATCHED:
|
||||
break;
|
||||
case Status::WAITING_TO_SCRATCH:
|
||||
try_to_scratch();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ScratchAlgo::try_to_scratch()
|
||||
{
|
||||
bts_assert(me->status == Status::WAITING_TO_SCRATCH);
|
||||
auto my_side = algo().definition().side();
|
||||
auto other_side = securities::other_side(my_side);
|
||||
|
||||
Quantity my_quan;
|
||||
auto &my_side_psz = me->last_book.side(my_side)[0];
|
||||
auto &other_side_psz = me->last_book.side(other_side)[0];
|
||||
auto other_side_price = Price(other_side_psz.price());
|
||||
auto inception_other_side_price = Price(me->book_at_inception.side(other_side)[0].price());
|
||||
|
||||
bool market_moved = !securities::is_equal_or_better(other_side, other_side_price, inception_other_side_price);
|
||||
bool on_market = securities::is_same(Price(my_side_psz.price()), Price(algo().price()));
|
||||
if (market_moved || (on_market && my_side_psz.size() <= me->scratch_threshold.value()) )
|
||||
{
|
||||
Price scratch_price = securities::worsen_price(other_side, inception_other_side_price, me->chase_diff);
|
||||
LOG(OrderMan, Diag, "ScratchOrder order {} scratching: {}@{}",
|
||||
algo().order_key().value(), algo().quantity().value(), scratch_price);
|
||||
|
||||
// Time to scratch
|
||||
Update child_update;
|
||||
me->scratch_price = scratch_price;
|
||||
child_update.set_price(scratch_price.value());
|
||||
//we still want to try to scratch all of it
|
||||
child_update.set_quantity(algo().quantity().value());
|
||||
algo().update_child(me->child_key, child_update);
|
||||
me->status = Status::SCRATCHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(OrderMan, Diag,
|
||||
"ScratchOrder order {} still waiting to scratch. Order: {}@{} "
|
||||
"My side: {}@{}"
|
||||
"Thresh : {}@{}",
|
||||
algo().order_key().value(), algo().quantity().value(), algo().price().value(),
|
||||
my_side_psz.size(), my_side_psz.price(),
|
||||
me->scratch_threshold.value(), my_quan);
|
||||
}
|
||||
}
|
||||
|
||||
Price ScratchAlgo::get_price_to_pass (Price price) const
|
||||
{
|
||||
Price rv;
|
||||
switch (me->status) {
|
||||
case Status::WAITING_FOR_MD:
|
||||
case Status::WAITING_TO_SCRATCH:
|
||||
rv = price;
|
||||
break;
|
||||
case Status::SCRATCHED:
|
||||
rv = me->scratch_price;
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ScratchAlgo::update_scratch_threshold()
|
||||
{
|
||||
if (algo().definition().custom_def().scratch().scratch_threshold().quantity_case() ==
|
||||
bts::spark::QuantityMeasure::QuantityCase::QUANTITY_NOT_SET)
|
||||
{
|
||||
algo().terminate_error("Invalid quantity, terminating");
|
||||
return;
|
||||
}
|
||||
me->scratch_threshold = SpreaderUtils::_quantity_threshold(
|
||||
algo().definition().custom_def().scratch().scratch_threshold(), algo().quantity());
|
||||
me->chase_diff = Price(securities::tick_size(
|
||||
algo().security()).value() * algo().definition().custom_def().scratch().chase_ticks());
|
||||
}
|
||||
|
||||
void ScratchAlgo::on_child_change(OrderKey, ChildState const &st)
|
||||
{
|
||||
algo().update_fill_state(st.total_fills, st.last_price);
|
||||
switch (st.status)
|
||||
{
|
||||
case ChildStatus::WORKING:
|
||||
return;
|
||||
case ChildStatus::COMPLETED:
|
||||
algo().complete();
|
||||
return;
|
||||
case ChildStatus::CANCELED:
|
||||
algo().cancel("Unexpected child cancel");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/algo/IAlgoOrder.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
// Scratch monitors the cumulative size on the same side of the market of it's child
|
||||
// if that size falls below the threshold it will cross the market, paying through enough levels to do all of it's size
|
||||
|
||||
class ScratchAlgo : public IAlgoOrder
|
||||
{
|
||||
public:
|
||||
ScratchAlgo();
|
||||
~ScratchAlgo();
|
||||
|
||||
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices&) override;
|
||||
void do_launch(IAlgoServices &) override;
|
||||
void do_launch_attached(IAlgoServices&,OrderKey, ChildState) override;
|
||||
void do_update(api::orderman::Update const &) override;
|
||||
void on_book(SecurityKey, Book const &) override;
|
||||
void on_child_change(OrderKey, ChildState const &) override;
|
||||
|
||||
private:
|
||||
enum class Status;
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
IAlgoServices& algo() const;
|
||||
|
||||
void update_scratch_threshold();
|
||||
void try_to_scratch();
|
||||
Price get_price_to_pass (Price price) const;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -35,6 +35,10 @@
|
||||
#include "server/sparkd/user/AdminServiceServer.h"
|
||||
#include "server/sparkd/user/AuthServiceServer.h"
|
||||
#include "server/sparkd/algo/AlgoDefinitionServiceServer.h"
|
||||
|
||||
#include "lib/orderman/orders/algo/algo_orders/ScratchAlgo.h"
|
||||
#include "lib/orderman/orders/algo/algo_orders/ProRataAlgo.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace bts {
|
||||
@@ -77,7 +81,7 @@ int Run::execute(std::vector<std::string> const &) {
|
||||
SparkServices plugin_services(dyn_order_registry);
|
||||
plugin::init_plugins(plugin_services);
|
||||
// finished initializing order plugins
|
||||
|
||||
|
||||
orderman::OrderServiceServer order_service_server(
|
||||
sc, mdclient, dyn_order_registry, stats, perf_log);
|
||||
support::ErrorReportServer error_report_service(sc);
|
||||
|
||||
Generated
+68
-23
@@ -132,6 +132,7 @@
|
||||
"resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz",
|
||||
"integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"kind-of": "^3.0.2",
|
||||
"longest": "^1.0.1",
|
||||
@@ -1832,7 +1833,8 @@
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.1.1",
|
||||
@@ -1883,7 +1885,8 @@
|
||||
"balanced-match": {
|
||||
"version": "0.4.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.1",
|
||||
@@ -1898,6 +1901,7 @@
|
||||
"version": "0.0.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"inherits": "~2.0.0"
|
||||
}
|
||||
@@ -1906,6 +1910,7 @@
|
||||
"version": "2.10.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"hoek": "2.x.x"
|
||||
}
|
||||
@@ -1914,6 +1919,7 @@
|
||||
"version": "1.1.7",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^0.4.1",
|
||||
"concat-map": "0.0.1"
|
||||
@@ -1922,7 +1928,8 @@
|
||||
"buffer-shims": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
@@ -1939,12 +1946,14 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
@@ -1952,22 +1961,26 @@
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"cryptiles": {
|
||||
"version": "2.0.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"boom": "2.x.x"
|
||||
}
|
||||
@@ -2007,7 +2020,8 @@
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"delegates": {
|
||||
"version": "1.0.0",
|
||||
@@ -2039,7 +2053,8 @@
|
||||
"extsprintf": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
@@ -2061,12 +2076,14 @@
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"fstream": {
|
||||
"version": "1.0.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"inherits": "~2.0.0",
|
||||
@@ -2122,6 +2139,7 @@
|
||||
"version": "7.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
@@ -2134,7 +2152,8 @@
|
||||
"graceful-fs": {
|
||||
"version": "4.1.11",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"har-schema": {
|
||||
"version": "1.0.5",
|
||||
@@ -2162,6 +2181,7 @@
|
||||
"version": "3.1.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"boom": "2.x.x",
|
||||
"cryptiles": "2.x.x",
|
||||
@@ -2172,7 +2192,8 @@
|
||||
"hoek": {
|
||||
"version": "2.16.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"http-signature": {
|
||||
"version": "1.1.1",
|
||||
@@ -2189,6 +2210,7 @@
|
||||
"version": "1.0.6",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
@@ -2197,7 +2219,8 @@
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.4",
|
||||
@@ -2209,6 +2232,7 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "1.0.1"
|
||||
}
|
||||
@@ -2222,7 +2246,8 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"isstream": {
|
||||
"version": "0.1.2",
|
||||
@@ -2295,12 +2320,14 @@
|
||||
"mime-db": {
|
||||
"version": "1.27.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.15",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"mime-db": "1.27.0"
|
||||
}
|
||||
@@ -2309,6 +2336,7 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "1.1.7"
|
||||
}
|
||||
@@ -2316,12 +2344,14 @@
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@@ -2376,7 +2406,8 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.8.2",
|
||||
@@ -2394,6 +2425,7 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@@ -2423,7 +2455,8 @@
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"performance-now": {
|
||||
"version": "0.2.0",
|
||||
@@ -2434,7 +2467,8 @@
|
||||
"process-nextick-args": {
|
||||
"version": "1.0.7",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"punycode": {
|
||||
"version": "1.4.1",
|
||||
@@ -2472,6 +2506,7 @@
|
||||
"version": "2.2.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"buffer-shims": "~1.0.0",
|
||||
"core-util-is": "~1.0.0",
|
||||
@@ -2516,6 +2551,7 @@
|
||||
"version": "2.6.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"glob": "^7.0.5"
|
||||
}
|
||||
@@ -2523,7 +2559,8 @@
|
||||
"safe-buffer": {
|
||||
"version": "5.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.3.0",
|
||||
@@ -2547,6 +2584,7 @@
|
||||
"version": "1.0.9",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"hoek": "2.x.x"
|
||||
}
|
||||
@@ -2580,6 +2618,7 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@@ -2590,6 +2629,7 @@
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
@@ -2604,6 +2644,7 @@
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
@@ -2618,6 +2659,7 @@
|
||||
"version": "2.2.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"block-stream": "*",
|
||||
"fstream": "^1.0.2",
|
||||
@@ -2673,7 +2715,8 @@
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"uuid": {
|
||||
"version": "3.0.1",
|
||||
@@ -2702,7 +2745,8 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -4011,7 +4055,8 @@
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
|
||||
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=",
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.3.1",
|
||||
|
||||
+10
-13
@@ -111,19 +111,17 @@ module Accounts =
|
||||
}
|
||||
}
|
||||
riskLimitEnforcement =
|
||||
{ productLimitInNetTerms = true
|
||||
}
|
||||
accountLossLimit =
|
||||
{
|
||||
enforce = false
|
||||
totalLossLimit = 0u
|
||||
}
|
||||
{ productLimitInNetTerms = true }
|
||||
accountLossLimit =
|
||||
{ enforce = false
|
||||
totalLossLimit = 0u }
|
||||
}
|
||||
|
||||
let emptyMargin : ExcessLiquidityReport = {
|
||||
account = "ERROR NO DATA"
|
||||
accountId = 0u
|
||||
marginResult = {
|
||||
marginResult =
|
||||
{
|
||||
account = "ERROR NO DATA"
|
||||
status = bts.api.position.MarginResult.ResultStatus.Error
|
||||
portfolioId = ""
|
||||
@@ -139,11 +137,10 @@ module Accounts =
|
||||
shouldEnforceMargin = false
|
||||
leverageFactor = 0.0
|
||||
cashBalance = 0.0
|
||||
accountPnl = {
|
||||
accountId = 0u
|
||||
accountName = ""
|
||||
dayPnl = 0.0
|
||||
}
|
||||
accountPnl =
|
||||
{ accountId = 0u
|
||||
accountName = ""
|
||||
dayPnl = 0.0 }
|
||||
excessLiquidity = 0.0
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ type Msg =
|
||||
| SelectAccount of BTSAccount
|
||||
| DeleteAccount of BTSAccount
|
||||
| AddAccount
|
||||
| SaveLeverageFactor
|
||||
| SaveCashBalance
|
||||
| SaveScratch
|
||||
|
||||
| ErrorOccured of obj
|
||||
|
||||
@@ -39,7 +39,7 @@ let isDirty model =
|
||||
marginDirty
|
||||
| None -> false
|
||||
|
||||
let saveButton model dispatch =
|
||||
let saveButton (model:Model) dispatch =
|
||||
let isNew = isNewAccount model.scratch
|
||||
let buttonText = if isNew then "Create" else "Save"
|
||||
let dirty = isDirty model || isNew
|
||||
@@ -61,7 +61,7 @@ let accountControls model (dispatch:Msg->unit) =
|
||||
//
|
||||
// General
|
||||
//
|
||||
let generalView model dispatch =
|
||||
let generalView (model:Model) dispatch =
|
||||
let account = model.scratch
|
||||
|
||||
|
||||
@@ -611,7 +611,7 @@ let lazyProductLimitsView model dispatch =
|
||||
productLimits
|
||||
model dispatch
|
||||
|
||||
let lossLimitView model dispatch =
|
||||
let lossLimitView (model:Model) dispatch =
|
||||
div [] [
|
||||
div [ ClassName "columns" ][
|
||||
h1 [ ClassName "is-size-3 column is-narrow" ][str "Loss Limit" ]
|
||||
@@ -624,7 +624,7 @@ let lossLimitView model dispatch =
|
||||
]
|
||||
]
|
||||
|
||||
let securityLimitsView model dispatch =
|
||||
let securityLimitsView (model:Model) dispatch =
|
||||
let headerRow:TableControl.row =
|
||||
{
|
||||
cells =
|
||||
@@ -740,7 +740,7 @@ let securityLimitsView model dispatch =
|
||||
TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow)
|
||||
]
|
||||
|
||||
let LimitsView model dispatch =
|
||||
let LimitsView (model:Model) dispatch =
|
||||
div [ Class "limits-container"] [
|
||||
lossLimitView model dispatch
|
||||
br []
|
||||
@@ -813,7 +813,7 @@ let ConnectionsView (model:Accounts.Types.Model) dispatch =
|
||||
|
||||
let creditLimitsView model dispatch = div [] [str "lorem ipsum"]
|
||||
|
||||
let exchangeSettings model dispatch =
|
||||
let exchangeSettings (model:Model) dispatch =
|
||||
let cme = model.scratch.exchangeAccountData.cmeAccountData
|
||||
let sim = model.scratch.exchangeAccountData.simAccountData
|
||||
let send = UpdateCME>>dispatch
|
||||
@@ -836,7 +836,7 @@ let exchangeSettings model dispatch =
|
||||
accountControls model dispatch
|
||||
]
|
||||
|
||||
let tabContent model dispatch =
|
||||
let tabContent (model:Model) dispatch =
|
||||
div [Key (string model.scratch.id); ClassName "is-tab-content"] [
|
||||
// (match model.tab with
|
||||
(match model.tab, (accountIsSelected model.scratch Access.Accounts.empty) with
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
Test Author: Kevin
|
||||
If it breaks: Kevin
|
||||
|
||||
When the prorata order is placed, it acts as a slightly more complex hedging algorithm than Cover.
|
||||
It will:
|
||||
- Classify each fill as a normal fill or an 'overfill' according to "Fill Limit" parameters
|
||||
- Standard fills are hedged with the "Hedge" child order
|
||||
- Over fills are hedge with the "Overfill Hedge" child order
|
||||
|
||||
The prorata order works the child until the Fill Limit is breached.
|
||||
Once the fill limit is breached, the algo will begin the 'get out process'
|
||||
Unless:
|
||||
- If "Enable Stay In" is checked, AND
|
||||
a) The opposite inside market (at inception) doesn't move against us AND
|
||||
b) The same side quantity remains ABOVE the "Stay in Threshold"
|
||||
If "Enable Stay In" is not checked, 'get out process' begins right away
|
||||
|
||||
"Get Out Process" means
|
||||
1) Cancel the child order
|
||||
2) Scratch the overfill hedges if and only if the "Enable Scratch on Overfill" is checked
|
||||
-Scratches are done "Chase Ticks" through the original opposite market
|
||||
|
||||
|
||||
0. This needs sim market data **not** to be merged with replay (or
|
||||
cert), so we can create our own markets. Use the following key to set
|
||||
market data up:
|
||||
|
||||
ExchangeSim {
|
||||
value {
|
||||
merge_with_md: false
|
||||
}
|
||||
}
|
||||
|
||||
1. Bring up a ladder, lets say in SIM:ESU9 (does not matter which security)
|
||||
|
||||
2. Create the ask side of the market by sending 50 lot sell limit orders at 2833.25 through 2832.25
|
||||
(if there are no markets use the M View and the ticket to enter, if you already had left over
|
||||
orders cancel them)
|
||||
|
||||
2. Create the bid side of the market by sending 50 lot buy limit orders at 2830.75 through 2831.50.
|
||||
You should have no orders at 2831.50, 2831.75 and 2832.
|
||||
|
||||
Basics:
|
||||
3. Enter a 20 lot buy prorata order at 2831.50 with the following parameters
|
||||
|
||||
Hedge Ticks = 1
|
||||
Chase Ticks = 1
|
||||
Fill Limit = Absolute:5
|
||||
Stay in Threshold = Absolute:21
|
||||
Enable Scratch on Overfill = true
|
||||
Enable Stay In = true
|
||||
|
||||
Verify that the Prorata order along with the Child order shows up.
|
||||
|
||||
Next put a 50 lot buy limit order on top of your prorata at 2831.50
|
||||
|
||||
|
||||
4) Using 1 lot limit sells, fill 5 of your prorata order. Verify that you see covers going in 1 tick better
|
||||
|
||||
5) Cancel the 50 lot limit at 2831.50. Nothing should happen. Put the 50 lot back.
|
||||
|
||||
6) Fill one more 1 lot.
|
||||
|
||||
7) Again cancel the 50 lot limit at 2831.50. You should see:
|
||||
- The remainder of the 20 lot should cancel
|
||||
- 1 lot of your hedges should scratch to sell at 2831.25
|
||||
- The parent order should stay in
|
||||
- You should still be working 5 sales for hedges
|
||||
|
||||
8) Fill the 5 sells, it should cancel the parent.
|
||||
|
||||
9) Repeat 3-8, but this time set Enable Scratch on Overfill = false, Enable Stay In = true
|
||||
- You should see the same results in 7, except the 1 lot scratch won't happen so you'll still have 6 working hedges
|
||||
|
||||
9) Repeat 3-6, but this time set Enable Scratch on Overfill = false, Enable Stay In = false
|
||||
- After filling your last lot in 1 you should see your working order cancel, with 6 hedges working
|
||||
- The ladder may deceive you here, check the OB
|
||||
- Cancel your hedges, this should cancel the whole chain
|
||||
|
||||
9) Repeat 3-6, but this time set Enable Scratch on Overfill = true, Enable Stay In = false
|
||||
- After filling your last lot in 1 you should see your working order cancel, one hedge scratch (at 2831.50), and 5 hedges working
|
||||
- The ladder may deceive you here, check the OB
|
||||
- Cancel your hedges, this should cancel the whole chain
|
||||
|
||||
10) Repeat all of this on the sell side
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
Test Author: Kevin
|
||||
If it breaks: Kevin
|
||||
|
||||
When the scratch order is placed, it takes a snapshot of the opposite inside market; if that level gets
|
||||
worse, it will cross the market chase_ticks through.
|
||||
|
||||
It also continually monitors the size on the same side of the market if the quantity at that (same side) level falls below the "Scratch Threshold" AND the order's price is equal to the best bid or offer. It will cross by chase_ticks.
|
||||
|
||||
0. This needs sim market data **not** to be merged with replay (or
|
||||
cert), so we can create our own markets. Use the following key to set
|
||||
market data up:
|
||||
|
||||
ExchangeSim {
|
||||
value {
|
||||
merge_with_md: false
|
||||
}
|
||||
}
|
||||
|
||||
1. Bring up a ladder, lets say in SIM:ESU9 (does not matter which security)
|
||||
|
||||
2. Create the ask side of the market by sending 50 lot sell limit orders at 2833.25 through 2832.25
|
||||
(if there are no markets use the M View and the ticket to enter, if you already had left over
|
||||
orders cancel them)
|
||||
|
||||
2. Create the bid side of the market by sending 50 lot buy limit orders at 2830.50 through 2831.50.
|
||||
You should have no orders at 2831.75 and 2832.
|
||||
|
||||
Basics:
|
||||
3. Enter a 20 lot buy scratch order at 2831.50 with the following parameters
|
||||
Scratch Threshold = Absolute:21
|
||||
Max Chase Ticks = 2
|
||||
Child = Limit
|
||||
|
||||
Verify that the Scratch order along with the Child order shows up
|
||||
|
||||
4) Now cancel the 50 lot sell at 2832.25, you should see the 20 lot scratch pay 2832.50 on 20
|
||||
|
||||
5) Repeat 3, now cancel the 50 lot buy at 2831.50, you should again see scratch pay 2832.50 on 20.
|
||||
Put the 50 lot buy back in.
|
||||
|
||||
6) Repeat 3, put an offer in at 2832.25, cancel it; nothing should happen. Cancel the Scratch Algo
|
||||
|
||||
7) This time enter the algo with Max Chase = 0, cancel the 50 lot offer at 2832.75 and 2833. Nothing should happen. Now cancel the 2832.5 offer, you should see the algo pay up to 2832.5, but not fill.
|
||||
|
||||
8) Cancel the last offer at 2833.25. Nothing should happen.
|
||||
|
||||
9) Repeat all of this on the sell side
|
||||
|
||||
|
||||
Reference in new issue
Block a user