SPARK-1546 Trigger Order exit condition
This commit is contained in:
1 parent
13940c659b
commit
f42af15fe1
6 files changed
+355
-139
No files matched your search
@@ -11,72 +11,97 @@ using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using static bts.api.orderman.CustomOrderDefinition;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
static partial class OrderTypeVMFactory
|
||||
{
|
||||
class InlineTriggerOrderProperties
|
||||
{
|
||||
public InlineTriggerOrderProperties (CustomOneofCase selected_child_order_type, IReadOnlyCollection<CustomOneofCase> child_order_types)
|
||||
{
|
||||
namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class InlineTriggerOrderProperties {
|
||||
public readonly InlineUserProperty<CustomOneofCase> selected_child_order_type;
|
||||
public readonly InlineUserProperty<IReadOnlyCollection<CustomOneofCase>> child_order_types;
|
||||
public readonly InlineUserProperty<TriggerPriceType> trigger_price_type;
|
||||
public readonly InlineUserProperty<TriggerPayupPrice.Types.TriggerPayupPriceType> payup_price_type;
|
||||
public readonly InlineUserProperty<double> fixed_price;
|
||||
public readonly InlineUserProperty<int> payup_ticks;
|
||||
public readonly InlineUserProperty<bool> use_fixed_price, is_priceout_checked, is_timeout_checked;
|
||||
public readonly InlineUserProperty<int> timeout_secs;
|
||||
|
||||
public InlineTriggerOrderProperties(CustomOneofCase selected_child_order_type, IReadOnlyCollection<CustomOneofCase> child_order_types) {
|
||||
ExceptionAssert.InvalidOperation.That(child_order_types.Contains(selected_child_order_type), $"Child order type {selected_child_order_type} is not in child_order_types");
|
||||
this.selected_child_order_type = new InlineUserProperty<CustomOneofCase>(selected_child_order_type, true);
|
||||
this.child_order_types = new InlineUserProperty<IReadOnlyCollection<CustomOneofCase>>(child_order_types, true);
|
||||
|
||||
trigger_price_type = new InlineUserProperty<TriggerPriceType>(TriggerPriceType.Bid, false);
|
||||
order_price = new InlineUserProperty<double>(double.NaN, true);
|
||||
payup_price_type = new InlineUserProperty<TriggerPayupPrice.Types.TriggerPayupPriceType>();
|
||||
use_fixed_price = new InlineUserProperty<bool>(false);
|
||||
fixed_price = new InlineUserProperty<double>();
|
||||
payup_ticks = new InlineUserProperty<int>();
|
||||
is_priceout_checked = new InlineUserProperty<bool>();
|
||||
is_timeout_checked = new InlineUserProperty<bool>();
|
||||
timeout_secs = new InlineUserProperty<int>(10);
|
||||
}
|
||||
public readonly InlineUserProperty<CustomOneofCase> selected_child_order_type;
|
||||
public readonly InlineUserProperty<IReadOnlyCollection<CustomOneofCase>> child_order_types;
|
||||
|
||||
public readonly InlineUserProperty<TriggerPriceType> trigger_price_type;
|
||||
public readonly InlineUserProperty<double> order_price;
|
||||
}
|
||||
|
||||
class TriggerOrderVM : OrderTypeVMBase<TriggerOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable
|
||||
{
|
||||
class TriggerOrderVM : OrderTypeVMBase<TriggerOrderDefinition>, IHierarchicalOrderTypeVM, IDisposable {
|
||||
readonly IObservable<SecurityMD> _security_md_source;
|
||||
SecurityImmutable? _security;
|
||||
readonly UserProperty<TriggerPayupPrice.Types.TriggerPayupPriceType> _payup_price_type;
|
||||
readonly UserProperty<TriggerPriceType> _trigger_price_type;
|
||||
readonly UserProperty<double> _fixed_price;
|
||||
readonly UserProperty<int> _payup_ticks, _timeout_secs;
|
||||
readonly UserProperty<bool> _use_fixed_price, _is_timeout_checked, _is_priceout_checked;
|
||||
SecurityMD? _security_md;
|
||||
SecurityImmutable? _security => _security_md.HasValue ? _security_md.Value.security : null;
|
||||
ObservableCollection<CustomOneofCase> _order_types = new ObservableCollection<CustomOneofCase>();
|
||||
ObservableAutoWrapper<IOrderTypeVM, CustomOneofCase> _child_order_choices;
|
||||
InlineTriggerOrderProperties _inline_props;
|
||||
IOrderTypeVM _child_order;
|
||||
IDisposable _dispose, _child_order_errors_sub;
|
||||
|
||||
public TriggerPriceType trigger_price_type { get; set; } = TriggerPriceType.Bid;
|
||||
public double order_price { get; set; } = double.NaN;
|
||||
ulong _bbo_ref = 0, _last_trade_ref = 0;
|
||||
double _best_bid = double.NaN, _best_ask = double.NaN, _last_trade_price = double.NaN;
|
||||
|
||||
public TriggerOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source)
|
||||
: this(model, security_md_source, security_md_source.Select(smd =>
|
||||
new InlineTriggerOrderProperties(model.factory.default_order_type(smd.security), model.factory.default_order_types(smd.security).ToList()))) { }
|
||||
|
||||
public TriggerOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source,
|
||||
IObservable<InlineTriggerOrderProperties> inline_properties) : base(model)
|
||||
{
|
||||
public TriggerOrderVM(OrdersModel model, IObservable<SecurityMD> security_md_source, IObservable<InlineTriggerOrderProperties> inline_properties) : base(model) {
|
||||
_trigger_price_type = user_backing(nameof(trigger_price_type), TriggerPriceType.Bid);
|
||||
_use_fixed_price = user_backing(nameof(use_fixed_price), true);
|
||||
_fixed_price = user_backing(nameof(fixed_price), double.NaN);
|
||||
_payup_price_type = user_backing(nameof(payup_price_type), TriggerPayupPrice.Types.TriggerPayupPriceType.Trigger);
|
||||
_payup_ticks = user_backing(nameof(payup_ticks), 0);
|
||||
_is_priceout_checked = user_backing(nameof(is_priceout_checked), false);
|
||||
_is_timeout_checked = user_backing(nameof(is_timeout_checked), false);
|
||||
_timeout_secs = user_backing(nameof(timeout_secs), 0);
|
||||
_security_md_source = security_md_source;
|
||||
_dispose = Disposable.Create(
|
||||
security_md_source.OnDispatcher()
|
||||
.Subscribe(smd => _security = smd.security),
|
||||
.Subscribe(smd => {
|
||||
_security_md = smd;
|
||||
_refresh_md();
|
||||
if (double.IsNaN(fixed_price) || !_fixed_price.setter_called) {
|
||||
switch (trigger_price_type) {
|
||||
case TriggerPriceType.Bid: _fixed_price.bypass_setter(_best_bid); break;
|
||||
case TriggerPriceType.Ask: _fixed_price.bypass_setter(_best_ask); break;
|
||||
case TriggerPriceType.LastTradePrice: _fixed_price.bypass_setter(_last_trade_price); break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
inline_properties.OnDispatcher()
|
||||
.Subscribe(p => {
|
||||
if (_order_types.Count == 0 || p.child_order_types.force_override)
|
||||
{
|
||||
if (_order_types.Count == 0 || p.child_order_types.force_override) {
|
||||
_order_types.SetItems(p.child_order_types.value);
|
||||
}
|
||||
if (_child_order_choices != null && (_child_order == null || p.selected_child_order_type.force_override))
|
||||
{
|
||||
if (_child_order_choices != null && (_child_order == null || p.selected_child_order_type.force_override)) {
|
||||
_select_child_order(p.selected_child_order_type.value);
|
||||
}
|
||||
if (p.trigger_price_type.force_override)
|
||||
{
|
||||
trigger_price_type = p.trigger_price_type.value;
|
||||
RaisePropertyChanged(nameof(trigger_price_type));
|
||||
}
|
||||
if (p.order_price.force_override)
|
||||
{
|
||||
order_price = p.order_price.value;
|
||||
RaisePropertyChanged(nameof(order_price));
|
||||
}
|
||||
// trigger price
|
||||
_trigger_price_type.on_inline_prop(p.trigger_price_type);
|
||||
// fixed price
|
||||
_use_fixed_price.on_inline_prop(p.use_fixed_price);
|
||||
_fixed_price.on_inline_prop(p.fixed_price);
|
||||
// payup
|
||||
_payup_price_type.on_inline_prop(p.payup_price_type);
|
||||
_payup_ticks.on_inline_prop(p.payup_ticks);
|
||||
// exit
|
||||
_is_priceout_checked.on_inline_prop(p.is_priceout_checked);
|
||||
_is_timeout_checked.on_inline_prop(p.is_timeout_checked);
|
||||
_timeout_secs.on_inline_prop(p.timeout_secs);
|
||||
_inline_props = p;
|
||||
_validate();
|
||||
})
|
||||
@@ -84,65 +109,39 @@ namespace mbts.spark
|
||||
_validate();
|
||||
}
|
||||
|
||||
public IEnumerable<TriggerPriceType> trigger_price_types => EnumHelper.get_values_except<TriggerPriceType>(TriggerPriceType.LastTradePrice);
|
||||
|
||||
public override void assign_to(CustomOrderDefinition value)
|
||||
{
|
||||
if (_child_order == null)
|
||||
_select_child_order(model.factory.default_order_type(_security.Value, true));
|
||||
_validate();
|
||||
if (!HasErrors)
|
||||
{
|
||||
var i = factory.trigger_order();
|
||||
i.TriggerCondition = new TriggerCondition()
|
||||
{
|
||||
PriceType = trigger_price_type,
|
||||
AbsolutePriceTrigger = new AbsolutePriceTrigger() { TriggerQuantity = new TriggerQuantity() }
|
||||
};
|
||||
i.TriggerAction = new TriggerAction()
|
||||
{
|
||||
Price = order_price,
|
||||
SecurityId = _security.Value.Id
|
||||
};
|
||||
child_order.assign_to(i.Child);
|
||||
value.Trigger = i;
|
||||
}
|
||||
}
|
||||
|
||||
public double price_tick
|
||||
{
|
||||
get { return _security.Value.ContractSpec.LowTick; }
|
||||
}
|
||||
|
||||
public ContractSpecificationImmutable spec
|
||||
{
|
||||
get { return _security.Value.ContractSpec; }
|
||||
}
|
||||
|
||||
public ICollection<IOrderTypeVM> child_order_types
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_child_order_choices == null)
|
||||
// trigger price
|
||||
public IEnumerable<TriggerPriceType> trigger_price_types => EnumHelper.get_values_except(TriggerPriceType.LastTradePrice);
|
||||
public TriggerPriceType trigger_price_type { get => _trigger_price_type.Value; set => _trigger_price_type.Value = value; }
|
||||
// fixed price
|
||||
public bool use_fixed_price { get => _use_fixed_price.Value; set => _use_fixed_price.Value = value; }
|
||||
public double fixed_price { get => _fixed_price.Value; set => _fixed_price.Value = value; }
|
||||
// payup
|
||||
public IEnumerable<TriggerPayupPrice.Types.TriggerPayupPriceType> payup_price_types => EnumHelper.get_values<TriggerPayupPrice.Types.TriggerPayupPriceType>();
|
||||
public TriggerPayupPrice.Types.TriggerPayupPriceType payup_price_type { get => _payup_price_type.Value; set => _payup_price_type.Value = value; }
|
||||
public int payup_ticks { get => _payup_ticks.Value; set => _payup_ticks.Value = value; }
|
||||
// exit
|
||||
public bool is_priceout_checked { get => _is_priceout_checked.Value; set => _is_priceout_checked.Value = value; }
|
||||
public bool is_timeout_checked { get => _is_timeout_checked.Value; set => _is_timeout_checked.Value = value; }
|
||||
public int timeout_secs { get => _timeout_secs.Value; set => _timeout_secs.Value = value; }
|
||||
//
|
||||
public ContractSpecificationImmutable spec => _security.spec_or_default();
|
||||
public ICollection<IOrderTypeVM> child_order_types {
|
||||
get {
|
||||
if (_child_order_choices == null)
|
||||
_child_order_choices = new ObservableAutoWrapper<IOrderTypeVM, CustomOneofCase>(_order_types, ot => create(ot, model, _security_md_source));
|
||||
return _child_order_choices;
|
||||
}
|
||||
}
|
||||
|
||||
public IOrderTypeVM child_order
|
||||
{
|
||||
get
|
||||
{
|
||||
public IOrderTypeVM child_order {
|
||||
get {
|
||||
init();
|
||||
return _child_order;
|
||||
}
|
||||
set
|
||||
{
|
||||
set {
|
||||
Disposable.dispose(ref _child_order_errors_sub);
|
||||
_child_order = value;
|
||||
_child_order?.init();
|
||||
if (_child_order is INotifyDataErrorInfo ndei)
|
||||
{
|
||||
if (_child_order is INotifyDataErrorInfo ndei) {
|
||||
ndei.ErrorsChanged += on_errors_changed;
|
||||
void on_errors_changed(object s, DataErrorsChangedEventArgs e) =>
|
||||
_validate();
|
||||
@@ -151,40 +150,80 @@ namespace mbts.spark
|
||||
_validate();
|
||||
RaisePropertyChanged(nameof(child_order));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
public override void assign_to(CustomOrderDefinition value) {
|
||||
if (_child_order == null)
|
||||
_select_child_order(model.factory.default_order_type(_security.Value, true));
|
||||
_validate();
|
||||
if (!HasErrors) {
|
||||
var i = factory.trigger_order();
|
||||
i.TriggerAction = new TriggerAction {
|
||||
SecurityId = _security.Value.Id,
|
||||
};
|
||||
i.TriggerCondition = new TriggerCondition() {
|
||||
PriceType = trigger_price_type,
|
||||
AbsolutePriceTrigger = new AbsolutePriceTrigger() { TriggerQuantity = new TriggerQuantity() },
|
||||
};
|
||||
i.ExitCondition = new TriggerExitCondition {
|
||||
ConditionalCancel = is_priceout_checked,
|
||||
TimeoutEnabled = is_timeout_checked,
|
||||
TimeoutSeconds = (uint)(timeout_secs)
|
||||
};
|
||||
if (use_fixed_price) {
|
||||
// should already be null, setting it here for clarity
|
||||
i.TriggerAction.Payup = null;
|
||||
i.TriggerAction.Price = fixed_price;
|
||||
} else {
|
||||
i.TriggerAction.Price = double.NaN;
|
||||
i.TriggerAction.Payup = new TriggerPayupPrice {
|
||||
PayupTicks = payup_ticks,
|
||||
PayupPriceType = payup_price_type
|
||||
};
|
||||
}
|
||||
child_order.assign_to(i.Child);
|
||||
value.Trigger = i;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Disposable.dispose(ref _dispose);
|
||||
if (_child_order_choices != null)
|
||||
_child_order_choices.OfType<IDisposable>().DisposeAll();
|
||||
}
|
||||
|
||||
public override void init()
|
||||
{
|
||||
public override void init() {
|
||||
if (_child_order == null && _security.HasValue)
|
||||
_select_child_order();
|
||||
_validate();
|
||||
}
|
||||
|
||||
void _select_child_order()
|
||||
{
|
||||
void _refresh_md() {
|
||||
if (_security.HasValue) {
|
||||
_security_md.Value.md.get_bbo(ref _bbo_ref, out co2.NativePriceSize bid, out co2.NativePriceSize ask);
|
||||
_best_bid = bid.price;
|
||||
_best_ask = ask.price;
|
||||
_security_md.Value.md.get_last_trade(ref _last_trade_ref, out co2.NativePriceSize ps, out DateTime ts, out ulong v);
|
||||
}
|
||||
}
|
||||
|
||||
void _select_child_order() {
|
||||
CustomOneofCase ot = _inline_props != null && _inline_props.selected_child_order_type.has_value ?
|
||||
_inline_props.selected_child_order_type.value :
|
||||
model.factory.default_order_type(_security.Value, true);
|
||||
_select_child_order(ot);
|
||||
}
|
||||
|
||||
void _select_child_order(CustomOneofCase ot)
|
||||
{
|
||||
void _select_child_order(CustomOneofCase ot) {
|
||||
_child_order = child_order_types.FirstOrDefault(vm => vm.order_type == ot);
|
||||
if (_child_order == null)
|
||||
_child_order = child_order_types.FirstOrDefault();
|
||||
RaisePropertyChanged(nameof(child_order));
|
||||
}
|
||||
|
||||
void _validate()
|
||||
{
|
||||
void _validate() {
|
||||
assert(!use_fixed_price || !double.IsNaN(fixed_price), nameof(fixed_price));
|
||||
assert(!is_timeout_checked || timeout_secs > 0, nameof(timeout_secs));
|
||||
if (_child_order == null || (_child_order is INotifyDataErrorInfo ndei && ndei.HasErrors))
|
||||
set_error(nameof(child_order), string.Empty, true);
|
||||
else clear_error(nameof(child_order));
|
||||
|
||||
@@ -281,6 +281,16 @@ namespace mbts.ui.shell
|
||||
/// Sets 'setter_called' to false.
|
||||
/// </summary>
|
||||
public void reset() => setter_called = false;
|
||||
|
||||
public void on_inline_prop(InlineUserProperty<T> inline_prop) {
|
||||
if (inline_prop.force_override || (inline_prop.has_value && !setter_called))
|
||||
bypass_setter(inline_prop.value);
|
||||
}
|
||||
|
||||
public void on_inline_prop<TIn>(InlineUserProperty<TIn> inline_prop, Func<TIn, T> select) {
|
||||
if (inline_prop.force_override || (inline_prop.has_value && !setter_called))
|
||||
bypass_setter(select(inline_prop.value));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -440,6 +450,13 @@ namespace mbts.ui.shell
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected UserProperty<T> user_backing<T>(string name, T default_value = default) =>
|
||||
new UserProperty<T>(backing(name, default_value));
|
||||
|
||||
protected UserProperty<T> user_backing<T>(Property<T> property) =>
|
||||
new UserProperty<T>(property);
|
||||
|
||||
|
||||
// TODO: maybe include a revert_on_error flag?
|
||||
protected class PropertyValidation<T> {
|
||||
public readonly Func<T, (bool valid, string msg)> validate;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/ComboBoxes.xaml"/>
|
||||
@@ -13,6 +16,8 @@
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/Modules/Spreader/ExecutionStrategyEditor.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalPush">4</sys:Double>
|
||||
<sys:Double x:Key="VerticalPush">4</sys:Double>
|
||||
<Style TargetType="uag:OrderDetailsPopupControl">
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
|
||||
@@ -55,6 +60,11 @@
|
||||
IsOpen="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Visibility="{Binding HasEditableProperties, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibility}}"
|
||||
>
|
||||
<c:PopupControl.Resources>
|
||||
<Style TargetType="GroupBox">
|
||||
<Setter Property="Padding" Value="4"/>
|
||||
</Style>
|
||||
</c:PopupControl.Resources>
|
||||
<c:PopupControl.PopupContainerStyle>
|
||||
<Style TargetType="Border" BasedOn="{StaticResource PopupContainerStyleBase}">
|
||||
<Setter Property="Padding" Value="4"/>
|
||||
@@ -338,39 +348,140 @@
|
||||
</usp:OrderModificationTemplateSelector.TopOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.TriggerOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="12"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center">Trigger Price Type</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="1" Grid.Column="2"
|
||||
ItemsSource="{Binding trigger_price_types}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding trigger_price_type}"
|
||||
/>
|
||||
<TextBlock Grid.Row="3" VerticalAlignment="Center">Order Price</TextBlock>
|
||||
<usp:PriceEntryControl Grid.Row="3" Grid.Column="2" Value="{Binding order_price}" ContractSpec="{Binding spec}" />
|
||||
<TextBlock Grid.Row="5">Child</TextBlock>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="5" Grid.Column="2"
|
||||
IsOpen="{Binding child_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
HasEditableProperties="{Binding child_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
<GroupBox Header="Trigger Condition" HeaderTemplate="{StaticResource BoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center">Price Type</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
ItemsSource="{Binding trigger_price_types}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding trigger_price_type}"
|
||||
/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="2" Header="Trigger Action" HeaderTemplate="{StaticResource BoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition MaxWidth="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0">
|
||||
Child
|
||||
</TextBlock>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
IsOpen="{Binding child_order.editable_properties_open, FallbackValue=False}"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
HasEditableProperties="{Binding child_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
<GroupBox Grid.Row="2" Grid.ColumnSpan="3" Header="Price" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<RadioButton
|
||||
x:Name="fixed_price_rb"
|
||||
Grid.Row="0"
|
||||
GroupName="price-type"
|
||||
IsChecked="{Binding use_fixed_price, Mode=TwoWay}"
|
||||
VerticalContentAlignment="Center"
|
||||
>
|
||||
Fixed
|
||||
</RadioButton>
|
||||
<usp:PriceEntryControl
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
ContractSpec="{Binding spec}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=fixed_price_rb, Mode=OneWay}"
|
||||
Value="{Binding fixed_price}"
|
||||
/>
|
||||
<RadioButton
|
||||
x:Name="payup_price_rb"
|
||||
Grid.Row="2"
|
||||
GroupName="price-type"
|
||||
VerticalContentAlignment="Center"
|
||||
>
|
||||
Payup/less
|
||||
</RadioButton>
|
||||
<Grid Grid.Row="2" Grid.Column="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:TickUpDownInt
|
||||
IsEnabled="{Binding IsChecked, ElementName=payup_price_rb, Mode=OneWay}"
|
||||
Value="{Binding payup_ticks}"
|
||||
Width="34"
|
||||
/>
|
||||
<ComboBox
|
||||
Grid.Column="2"
|
||||
IsEnabled="{Binding use_fixed_price, Converter={StaticResource NotConverter}, Mode=OneWay}"
|
||||
ItemsSource="{Binding payup_price_types}"
|
||||
SelectedItem="{Binding payup_price_type}"
|
||||
>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static uag:OrderDetailsPopupControl.TriggerPayupTypeDescriptionConverter}}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="4" Header="Trigger Exit" HeaderTemplate="{StaticResource BoldHeaderTemplate}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox IsChecked="{Binding is_timeout_checked}" VerticalContentAlignment="Center">
|
||||
Timeout (secs)
|
||||
</CheckBox>
|
||||
<c:TickUpDownInt Grid.Column="2" IsEnabled="{Binding is_timeout_checked, Mode=OneWay}" Minimum="0" Value="{Binding timeout_secs}"/>
|
||||
<CheckBox Grid.Row="2" Grid.ColumnSpan="3" IsChecked="{Binding is_priceout_checked}" VerticalAlignment="Center">
|
||||
Price Conditional
|
||||
</CheckBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.TriggerOrderTemplate>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using mbts.spark;
|
||||
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;
|
||||
@@ -6,16 +9,23 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark.algo
|
||||
{
|
||||
namespace mbts.ui.spark.algo {
|
||||
/// <summary>
|
||||
/// Interaction logic for OrderDetailsPopupControl.xaml
|
||||
/// </summary>
|
||||
class OrderDetailsPopupControl : Control
|
||||
{
|
||||
class OrderDetailsPopupControl : Control {
|
||||
static OrderDetailsPopupControl() =>
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderDetailsPopupControl), new FrameworkPropertyMetadata(typeof(OrderDetailsPopupControl)));
|
||||
|
||||
public static IValueConverter TriggerPayupTypeDescriptionConverter =
|
||||
ValueConverter.create<TriggerPayupPrice.Types.TriggerPayupPriceType, string>(
|
||||
t => {
|
||||
switch (t) {
|
||||
case TriggerPayupPrice.Types.TriggerPayupPriceType.LastTradePrice: return "Last Trade";
|
||||
default: return DisplayNameHelper.camel_to_title_case(t.ToString());
|
||||
}
|
||||
});
|
||||
|
||||
#region ExpandDirection
|
||||
public static readonly DependencyProperty ExpandDirectionProperty = DependencyProperty.Register(nameof(ExpandDirection), typeof(ExpandDirection), typeof(OrderDetailsPopupControl),
|
||||
new PropertyMetadata(ExpandDirection.Right, OnExpandDirectionChanged, CoerceExpandDirection));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using mbts.spark.utilities;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -10,10 +11,42 @@ namespace mbts.ui.controls
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(TickUpDownInt), new FrameworkPropertyMetadata(typeof(TickUpDownInt)));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(TickUpDownInt), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public static readonly DependencyProperty MinimumProperty =
|
||||
WPFHelper.create_dp<int, TickUpDownInt>(
|
||||
nameof(Minimum),
|
||||
(o, v) => o.CoerceValue(ValueProperty),
|
||||
int.MinValue);
|
||||
|
||||
public int Minimum {
|
||||
get => (int)GetValue(MinimumProperty);
|
||||
set => SetValue(MinimumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaximumProperty =
|
||||
WPFHelper.create_dp<int, TickUpDownInt>(
|
||||
nameof(Maximum),
|
||||
(o, v) => o.CoerceValue(ValueProperty),
|
||||
int.MaxValue);
|
||||
|
||||
public int Maximum {
|
||||
get => (int)GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
WPFHelper.create_dp<int, TickUpDownInt>(
|
||||
nameof(Value),
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, v) => MathUtils.within_range(o.Minimum, o.Maximum, v),
|
||||
0);
|
||||
|
||||
public int Value {
|
||||
get => (int)GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(int), typeof(TickUpDownInt), new FrameworkPropertyMetadata(1));
|
||||
|
||||
public int Value { get { return (int)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } }
|
||||
public int Increment { get { return (int)GetValue(IncrementProperty); } set { SetValue(IncrementProperty, value); } }
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace mbts.ui {
|
||||
public static DependencyProperty create_dp<TValue, TOwner>(string name, FrameworkPropertyMetadataOptions options, Action<TOwner, TValue> callback, TValue default_value = default) =>
|
||||
DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(default_value, options, prop_changed_callback(callback)));
|
||||
|
||||
public static DependencyProperty create_dp<TValue, TOwner>(string name, FrameworkPropertyMetadataOptions options, Func<TOwner, TValue, TValue> coerce_value, TValue default_value = default) =>
|
||||
DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(default_value, options, null, coerce_value_callback(coerce_value)));
|
||||
|
||||
public static DependencyProperty create_dp<TValue, TOwner>(string name, PropertyChangedCallback<TValue, TOwner> callback, TValue default_value = default) =>
|
||||
DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(default_value, prop_changed_callback(callback)));
|
||||
|
||||
@@ -227,6 +230,9 @@ namespace mbts.ui {
|
||||
public static PropertyChangedCallback prop_changed_callback<TValue, TOwner>(Action<TOwner, TValue> callback) =>
|
||||
(d, e) => callback(ObjectHelper.try_convert<TOwner>(d), ObjectHelper.try_convert<TValue>(e.NewValue));
|
||||
|
||||
public static CoerceValueCallback coerce_value_callback<TValue, TOwner>(Func<TOwner, TValue, TValue> coerce_value) =>
|
||||
(d, obj) => coerce_value(ObjectHelper.try_convert<TOwner>(d), ObjectHelper.try_convert<TValue>(obj));
|
||||
|
||||
public static double control_base_width(Thickness border_thickness, Thickness padding) =>
|
||||
border_thickness.Left + padding.Left + padding.Right + border_thickness.Right;
|
||||
|
||||
|
||||
Reference in new issue
Block a user