QuantityMeasureControl - change QuantityMeasure prop to nullable QuantityMeasureImmutable
This commit is contained in:
1 parent
3492bcdbd5
commit
4e3bdad812
8 files changed
+46
-39
No files matched your search
+1
-1
@@ -35,7 +35,7 @@ namespace mbts.ui.spark {
|
||||
return StringTemplate;
|
||||
if (pvm is IAlgoParamVM<IAlgoVM>)
|
||||
return OrderDefTemplate;
|
||||
if (pvm is IAlgoParamVM<QuantityMeasureImmutable>)
|
||||
if (pvm is IAlgoParamVM<QuantityMeasureImmutable?>)
|
||||
return QuantityMeasureTemplate;
|
||||
if (pvm is IAlgoParamVM<ExecutionStrategy>)
|
||||
return ExecutionStrategyTemplate;
|
||||
|
||||
@@ -5,13 +5,13 @@ using JoinDefi = bts.api.orderman.JoinOrderDefinitionImmutable;
|
||||
namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class JoinOrderVM : OrderTypeVMBase<JoinDef, JoinDefi> {
|
||||
readonly Property<QuantityMeasureImmutable> _join_threshold;
|
||||
readonly Property<QuantityMeasureImmutable?> _join_threshold;
|
||||
|
||||
public JoinOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
: base(key, display_name, editing_permissions) =>
|
||||
_join_threshold = add_property<QuantityMeasure, QuantityMeasureImmutable>(nameof(join_threshold), JoinDef.JoinThresholdFieldNumber, new QuantityMeasureImmutable(new QuantityMeasure { Ratio = 1.0, Absolute = 1 }));
|
||||
|
||||
public QuantityMeasureImmutable join_threshold { get => _join_threshold.Value; set => _join_threshold.set(value); }
|
||||
public QuantityMeasureImmutable? join_threshold { get => _join_threshold.Value; set => _join_threshold.set(value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using LeanDefi = bts.api.orderman.LeanOrderDefinitionImmutable;
|
||||
namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class LeanOrderVM : OrderTypeVMBase<LeanDef, LeanDefi> {
|
||||
readonly Property<QuantityMeasureImmutable> _cross_threshold;
|
||||
readonly Property<QuantityMeasureImmutable?> _cross_threshold;
|
||||
readonly Property<uint> _max_chase_ticks;
|
||||
readonly Property<LeanDef.Types.OnToward> _trade_toward_behavior;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mbts.spark {
|
||||
public LeanDef.Types.OnToward trade_toward_behavior { get => _trade_toward_behavior.Value; set => _trade_toward_behavior.set(value); }
|
||||
public IEnumerable<LeanDef.Types.OnToward> trade_toward_types => EnumHelper.get_values_except<LeanDef.Types.OnToward>();
|
||||
// auxiliary
|
||||
public QuantityMeasureImmutable cross_threshold { get => _cross_threshold.Value; set => _cross_threshold.set(value); }
|
||||
public QuantityMeasureImmutable? cross_threshold { get => _cross_threshold.Value; set => _cross_threshold.set(value); }
|
||||
public uint max_chase_ticks { get => _max_chase_ticks.Value; set => _max_chase_ticks.set(value); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,22 +368,18 @@ namespace mbts.spark {
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected Property<TImmutableValue> add_property<TMutableValue, TImmutableValue>(string prop_name, int target_field_number, TImmutableValue init_value = default, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) where TMutableValue : class, IMessage, new() where TImmutableValue : IImmutableMessage {
|
||||
protected Property<TImmutableValue?> add_property<TMutableValue, TImmutableValue>(string prop_name, int target_field_number, TImmutableValue? init_value = null, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite)
|
||||
where TMutableValue : class, IMessage, new()
|
||||
where TImmutableValue : struct, IImmutableMessage {
|
||||
var prop = backing(prop_name, init_value);
|
||||
var field_desc = new TMutable().Descriptor.FindFieldByNumber(target_field_number);
|
||||
var param = new AlgoParamVM<TImmutableValue>(prop_name, DisplayNameHelper.snake_to_title_case(prop_name), init_value) { permissions = permissions };
|
||||
_link_props(param, prop);
|
||||
var param = new AlgoParamVM<TImmutableValue?>(prop_name, DisplayNameHelper.snake_to_title_case(prop_name), init_value) { permissions = permissions };
|
||||
_algo_params.Add(param);
|
||||
add_property<TMutableValue>(
|
||||
_auto_props.Add(new AutoProp(
|
||||
prop_name,
|
||||
mdef => field_desc.Accessor.GetValue(mdef) as TMutableValue,
|
||||
(mdef, mval) => field_desc.Accessor.SetValue(mdef, mval),
|
||||
mval => prop.set(ProtoHelper.immutable_factory<TMutableValue, TImmutableValue>(mval ?? new TMutableValue())),
|
||||
() => {
|
||||
// TODO: perhaps CloneToMutable() should be a member of IImmutableMessage.
|
||||
// this method makes things so simple for the caller...but this dynamic cast is a little sketch.
|
||||
return ((dynamic)prop.Value).CloneToMutable();
|
||||
});
|
||||
algo => field_desc.Accessor.SetValue(algo, prop.Value.HasValue ? ((dynamic)prop.Value.Value).CloneToMutable() : null),
|
||||
algo => prop.set(field_desc.Accessor.GetValue(algo) is TMutableValue mval ? ProtoHelper.immutable_factory<TMutableValue, TImmutableValue>(mval) : (TImmutableValue?)null),
|
||||
_link_props(param, prop)));
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class TickOrderVM : OrderTypeVMBase<TickDef, TickDefi> {
|
||||
readonly Property<uint> _tick_offset_on_deploy, _cross_ticks, _max_chase_ticks;
|
||||
readonly Property<QuantityMeasureImmutable> _cross_threshold;
|
||||
readonly Property<QuantityMeasureImmutable?> _cross_threshold;
|
||||
readonly Property<bool> _detach_on_toward;
|
||||
|
||||
public TickOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
@@ -18,7 +18,7 @@ namespace mbts.spark {
|
||||
_detach_on_toward = add_property(nameof(detach_on_toward), TickDef.DetachOnTowardFieldNumber, true);
|
||||
}
|
||||
|
||||
public QuantityMeasureImmutable cross_threshold { get => _cross_threshold.Value; set => _cross_threshold.set(value); }
|
||||
public QuantityMeasureImmutable? cross_threshold { get => _cross_threshold.Value; set => _cross_threshold.set(value); }
|
||||
public uint cross_ticks { get => _cross_ticks.Value; set => _cross_ticks.set(value); }
|
||||
public uint tick_offset_on_deploy { get => _tick_offset_on_deploy.Value; set => _tick_offset_on_deploy.set(value); }
|
||||
public uint max_chase_ticks { get => _max_chase_ticks.Value; set => _max_chase_ticks.set(value); }
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class TopOrderVM : OrderTypeVMBase<TopDef, TopDefi> {
|
||||
readonly Property<uint> _watch_level_tick_offset;
|
||||
readonly Property<QuantityMeasureImmutable> _top_threshold;
|
||||
readonly Property<QuantityMeasureImmutable?> _top_threshold;
|
||||
|
||||
public TopOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
: base(key, display_name, editing_permissions) {
|
||||
@@ -15,7 +15,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public uint watch_level_tick_offset { get => _watch_level_tick_offset.Value; set => _watch_level_tick_offset.set(value); }
|
||||
public QuantityMeasureImmutable top_threshold { get => _top_threshold.Value; set => _top_threshold.set(value); }
|
||||
public QuantityMeasureImmutable? top_threshold { get => _top_threshold.Value; set => _top_threshold.set(value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace mbts.ui.spark.algo {
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, oldval, newval) => {
|
||||
o._update_gate.try_update(() => {
|
||||
var mutable = o.QuantityMeasure.CloneToMutable();
|
||||
var mutable = o.QuantityMeasure?.CloneToMutable() ?? new bts.spark.QuantityMeasure();
|
||||
switch (oldval) {
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Absolute: o._cached_absolute = mutable.Absolute; break;
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Ratio: o._cached_ratio = mutable.Ratio; break;
|
||||
@@ -70,7 +70,7 @@ namespace mbts.ui.spark.algo {
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, v) => {
|
||||
o._update_gate.try_update(() => {
|
||||
var mutable = o.QuantityMeasure.CloneToMutable();
|
||||
var mutable = o.QuantityMeasure?.CloneToMutable() ?? new QuantityMeasure();
|
||||
mutable.Absolute = v;
|
||||
o.SetCurrentValue(QuantityMeasureProperty, new QuantityMeasureImmutable(mutable));
|
||||
o.SetCurrentValue(QuantityCaseProperty, bts.spark.QuantityMeasure.QuantityOneofCase.Absolute);
|
||||
@@ -90,7 +90,7 @@ namespace mbts.ui.spark.algo {
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, v) => {
|
||||
o._update_gate.try_update(() => {
|
||||
var mutable = o.QuantityMeasure.CloneToMutable();
|
||||
var mutable = o.QuantityMeasure?.CloneToMutable() ?? new QuantityMeasure();
|
||||
mutable.Ratio = v;
|
||||
o.SetCurrentValue(QuantityMeasureProperty, new QuantityMeasureImmutable(mutable));
|
||||
o.SetCurrentValue(QuantityCaseProperty, bts.spark.QuantityMeasure.QuantityOneofCase.Ratio);
|
||||
@@ -103,23 +103,32 @@ namespace mbts.ui.spark.algo {
|
||||
#endregion
|
||||
|
||||
#region QuantityMeasure
|
||||
public static readonly DependencyProperty QuantityMeasureProperty = WPFHelper.create_dp<QuantityMeasureImmutable, QuantityMeasureControl>(
|
||||
public static readonly DependencyProperty QuantityMeasureProperty = WPFHelper.create_dp<QuantityMeasureImmutable?, QuantityMeasureControl>(
|
||||
nameof(QuantityMeasure),
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, oldval, newval) => o._update_gate.try_update(() => {
|
||||
switch (oldval.QuantityCase) {
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Absolute: o._cached_absolute = oldval.Absolute; break;
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Ratio: o._cached_ratio = oldval.Ratio; break;
|
||||
if (oldval.HasValue) {
|
||||
switch (oldval.Value.QuantityCase) {
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Absolute: o._cached_absolute = oldval.Value.Absolute; break;
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Ratio: o._cached_ratio = oldval.Value.Ratio; break;
|
||||
}
|
||||
}
|
||||
switch (newval.QuantityCase) {
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Absolute: o.SetCurrentValue(AbsoluteProperty, newval.Absolute); break;
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Ratio: o.SetCurrentValue(RatioProperty, newval.Ratio); break;
|
||||
if (newval.HasValue) {
|
||||
switch (newval.Value.QuantityCase) {
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Absolute: o.SetCurrentValue(AbsoluteProperty, newval.Value.Absolute); break;
|
||||
case bts.spark.QuantityMeasure.QuantityOneofCase.Ratio: o.SetCurrentValue(RatioProperty, newval.Value.Ratio); break;
|
||||
}
|
||||
o.SetCurrentValue(QuantityCaseProperty, newval.Value.QuantityCase);
|
||||
} else {
|
||||
o.SetCurrentValue(QuantityCaseProperty, bts.spark.QuantityMeasure.QuantityOneofCase.None);
|
||||
}
|
||||
o.SetCurrentValue(QuantityCaseProperty, newval.QuantityCase);
|
||||
}),
|
||||
_default_quantity_measure);
|
||||
|
||||
public QuantityMeasureImmutable QuantityMeasure { get => (QuantityMeasureImmutable)GetValue(QuantityMeasureProperty); set => SetValue(QuantityMeasureProperty, value); }
|
||||
public QuantityMeasureImmutable? QuantityMeasure {
|
||||
get => GetValue(QuantityMeasureProperty) as QuantityMeasureImmutable?;
|
||||
set => SetValue(QuantityMeasureProperty, value);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -23,15 +23,17 @@ namespace mbts.ui.converters {
|
||||
DoubleTextConverter = new DoubleTextConverter(),
|
||||
IntTextConverter = new IntTextConverter(),
|
||||
UIntTextConverter = new UIntTextConverter(),
|
||||
QuantityMeasureTextConverter = ValueConverter.create<QuantityMeasureImmutable, string>(fmt),
|
||||
QuantityMeasureTextConverter = ValueConverter.create<QuantityMeasureImmutable?, string>(fmt),
|
||||
SimpleString = new AnonymousValueConverter(obj => obj?.ToString());
|
||||
|
||||
public static string fmt(QuantityMeasureImmutable qm) {
|
||||
switch (qm.QuantityCase) {
|
||||
case QuantityMeasure.QuantityOneofCase.Absolute: return qm.Absolute.ToString();
|
||||
case QuantityMeasure.QuantityOneofCase.Ratio: return qm.Ratio.ToString("#0.00#");
|
||||
default: return "N/A";
|
||||
public static string fmt(QuantityMeasureImmutable? qm) {
|
||||
if (qm.HasValue) {
|
||||
switch (qm.Value.QuantityCase) {
|
||||
case QuantityMeasure.QuantityOneofCase.Absolute: return qm.Value.Absolute.ToString();
|
||||
case QuantityMeasure.QuantityOneofCase.Ratio: return qm.Value.Ratio.ToString("#0.00#");
|
||||
}
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user