ladder/ticket spreader template
This commit is contained in:
1 parent
d7c92855e9
commit
e0a8dc62c4
10 files changed
+102
-49
No files matched your search
@@ -70,14 +70,19 @@ namespace mbts.ui.spark
|
||||
public static readonly DependencyProperty ParameterRowsProperty = DependencyProperty.Register("ParameterRows", typeof(IEnumerable<IParameterViewMetadata>), typeof(ExecutionStrategyEditor),
|
||||
new PropertyMetadata(Enumerable.Empty<IParameterViewMetadata>(), OnParameterRowsChanged));
|
||||
static void OnParameterRowsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var rows = e.NewValue as IEnumerable<IParameterViewMetadata>;
|
||||
if (rows != null) {
|
||||
var prv = CollectionViewSource.GetDefaultView(rows);
|
||||
int n_groups = rows.Max(r => r.section_path.Length);
|
||||
for (int i = 0; i < n_groups; i++) prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]"));
|
||||
var new_rows = e.NewValue as IEnumerable<IParameterViewMetadata> ?? Enumerable.Empty<IParameterViewMetadata>();
|
||||
var target = (ExecutionStrategyEditor)d;
|
||||
if (target._rows == null) {
|
||||
target._rows = new ObservableCollection<IParameterViewMetadata>(new_rows);
|
||||
var prv = CollectionViewSource.GetDefaultView(target._rows);
|
||||
int n_groups = target._rows.Max(r => r.section_path.Length);
|
||||
for (int i = 0; i < n_groups; i++)
|
||||
prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]"));
|
||||
d.SetValue(ParameterRowsViewPropertyKey, prv);
|
||||
} else d.SetValue(ParameterRowsViewPropertyKey, null);
|
||||
} else
|
||||
target._rows.SetItems(new_rows);
|
||||
}
|
||||
ObservableCollection<IParameterViewMetadata> _rows;
|
||||
public IEnumerable<IParameterViewMetadata> ParameterRows { get => GetValue(ParameterRowsProperty) as IEnumerable<IParameterViewMetadata>; set => SetValue(ParameterRowsProperty, value); }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -17,6 +18,16 @@ namespace mbts.spark {
|
||||
/// </summary>
|
||||
partial class SyntheticEditorVM : ViewModelBase, IDisposable {
|
||||
readonly Security _synthetic;
|
||||
readonly ExecutionStrategyImmutable _strategy;
|
||||
/// <summary>
|
||||
/// Inititalizes a new instance of SyntheticEditorVM class. This constructor may only be used for already-existing synthetic securities.
|
||||
/// </summary>
|
||||
/// <param name="synthetic">The already-existing synthetic security who's strategy may be modified</param>
|
||||
/// <param name="strategy">The already-existing strategy that may be modified</param>
|
||||
public SyntheticEditorVM(SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy)
|
||||
: this(null, model, synthetic, strategy) {
|
||||
ExceptionAssert.InvalidOperation.That(synthetic.Id != 0, "This constructor may only be used for already-existing synthetic securities.");
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of SyntheticEditorVM class. The commit command will create a new Synthetic if synthetic's Id is 0, otherwise it will modify the existing synthetic's strategy.
|
||||
/// </summary>
|
||||
@@ -26,11 +37,11 @@ namespace mbts.spark {
|
||||
public SyntheticEditorVM(IBus bus, SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy) {
|
||||
_synthetic = synthetic.CloneToMutable();
|
||||
_synthetic.Exchange = Venue.Bts;
|
||||
var mutable_strategy = strategy.CloneToMutable();
|
||||
_strategy = strategy;
|
||||
leg_tuples = new ObservableCollection<LegSpreaderParamsTuple>(
|
||||
_synthetic.Synthetic.Legs
|
||||
.OrderBy(l => l.Security, SecurityHelper.Comparer.Instance)
|
||||
.Select(l => new LegSpreaderParamsTuple(l, mutable_strategy.LegParamsMap[l.Security.Id]))
|
||||
.Select(l => new LegSpreaderParamsTuple(l, _strategy.LegParamsMap[l.Security.Id].Clone()))
|
||||
);
|
||||
is_new = synthetic.Id == 0;
|
||||
if (is_new) {
|
||||
@@ -49,15 +60,13 @@ namespace mbts.spark {
|
||||
_synthetic.Synthetic.Legs.Clear();
|
||||
_synthetic.Synthetic.Legs.AddRange(leg_tuples.Select(l => l.leg).OrderBy(l => l.Security, SecurityHelper.Comparer.Instance));
|
||||
_synthetic.Symbol = _deduce_symbol(_synthetic);
|
||||
mutable_strategy.LegParamsMap.Clear();
|
||||
foreach (var lt in leg_tuples) mutable_strategy.LegParamsMap.Add(lt.leg.Security.Id, lt.leg_params);
|
||||
uint? id = await model.create_synthetic(_synthetic);
|
||||
if (id.HasValue && id != 0) await model.save_strategy(id.Value, new ExecutionStrategyImmutable(mutable_strategy));
|
||||
if (id.HasValue && id != 0) await model.save_strategy(id.Value, create_strategy());
|
||||
});
|
||||
} else {
|
||||
title = $"Edit '{synthetic.Synthetic.Name}'";
|
||||
icon = Icons.Knight;
|
||||
commit = new DelegateCommand(async () => await model.save_strategy(_synthetic.Id, new ExecutionStrategyImmutable(mutable_strategy)));
|
||||
commit = new DelegateCommand(async () => await model.save_strategy(_synthetic.Id, create_strategy()));
|
||||
}
|
||||
rows = new IRowModel [] {
|
||||
new SizeModel(!is_new),
|
||||
@@ -96,6 +105,13 @@ namespace mbts.spark {
|
||||
public ICommand remove_leg { get; }
|
||||
public ContractPickerModel contract_picker_model { get; }
|
||||
|
||||
public ExecutionStrategyImmutable create_strategy() {
|
||||
var mutable_strategy = _strategy.CloneToMutable();
|
||||
mutable_strategy.LegParamsMap.Clear();
|
||||
foreach (var lt in leg_tuples) mutable_strategy.LegParamsMap.Add(lt.leg.Security.Id, lt.leg_params);
|
||||
return new ExecutionStrategyImmutable(mutable_strategy);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
foreach (var r in rows) r.Dispose();
|
||||
contract_picker_model?.Dispose();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sp="clr-namespace:bts.spark;assembly=spark_api"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
@@ -17,6 +16,7 @@
|
||||
<ResourceDictionary Source="/view/Controls/Order/BTSStopOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/BTSIcebergOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Popup/PopupControl.xaml"/>
|
||||
<ResourceDictionary Source="/Modules/Spreader/ExecutionStrategyEditor.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style TargetType="uag:OrderDetailsPopupControl">
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
@@ -72,7 +72,7 @@
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Content="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Visibility="{TemplateBinding HasEditableProperties, Converter={StaticResource BoolToVisibility}}"
|
||||
Visibility="{Binding HasEditableProperties, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibility}}"
|
||||
>
|
||||
<c:PopupControl.PopupContainerStyle>
|
||||
<Style TargetType="Border" BasedOn="{StaticResource PopupContainerStyleBase}">
|
||||
@@ -141,10 +141,31 @@
|
||||
<TextBlock VerticalAlignment="Center">Show Quantity</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="2" Value="{Binding show_quantity}"/>
|
||||
<TextBlock Grid.Row="2">Child</TextBlock>
|
||||
<uag:OrderDetailsPopupControl Grid.Row="2" Grid.Column="2" ItemsSource="{Binding child_order_types}" SelectedItem="{Binding child_order}"/>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="2" Grid.Column="2"
|
||||
ItemsSource="{Binding child_order_types}"
|
||||
SelectedItem="{Binding child_order}"
|
||||
HasEditableProperties="{Binding child_order.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.IcebergOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.SpreaderTemplate>
|
||||
<DataTemplate>
|
||||
<usp:ExecutionStrategyEditor
|
||||
HorizontalAlignment="Stretch" Margin="6"
|
||||
DataContext="{Binding strategy_editor}"
|
||||
SyntheticName="{Binding name}"
|
||||
IsNew="{Binding is_new}"
|
||||
IsNewLegPopupOpen="{Binding is_new_leg_popup_open}"
|
||||
PriceCalc="{Binding price_calc}"
|
||||
ParameterRows="{Binding rows}"
|
||||
LegTuples="{Binding leg_tuples}"
|
||||
RemoveLegCommand="{Binding remove_leg}"
|
||||
ContractPickerModel="{Binding contract_picker_model}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.SpreaderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.BTSStopOrderTemplate>
|
||||
<DataTemplate>
|
||||
<uag:BTSStopOrderControl Order="{Binding}"/>
|
||||
|
||||
@@ -13,9 +13,8 @@ namespace mbts.ui.spark.algo
|
||||
/// </summary>
|
||||
class OrderDetailsPopupControl : Control
|
||||
{
|
||||
static OrderDetailsPopupControl() {
|
||||
static OrderDetailsPopupControl() =>
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderDetailsPopupControl), new FrameworkPropertyMetadata(typeof(OrderDetailsPopupControl)));
|
||||
}
|
||||
|
||||
#region ExpandDirection
|
||||
public static readonly DependencyProperty ExpandDirectionProperty = DependencyProperty.Register(nameof(ExpandDirection), typeof(ExpandDirection), typeof(OrderDetailsPopupControl),
|
||||
@@ -56,28 +55,20 @@ namespace mbts.ui.spark.algo
|
||||
#endregion
|
||||
|
||||
#region HasEditableProperties
|
||||
public static readonly DependencyProperty HasEditablePropertiesProperty =
|
||||
DependencyProperty.Register("HasEditableProperties", typeof(bool), typeof(OrderDetailsPopupControl), new PropertyMetadata(false));
|
||||
|
||||
public bool HasEditableProperties {
|
||||
get { return (bool)GetValue(HasEditablePropertiesProperty.DependencyProperty); }
|
||||
set { SetValue(HasEditablePropertiesProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyPropertyKey HasEditablePropertiesProperty =
|
||||
DependencyProperty.RegisterReadOnly("HasEditableProperties", typeof(bool), typeof(OrderDetailsPopupControl), new PropertyMetadata(true));
|
||||
|
||||
public bool HasEditableProperties { get => (bool)GetValue(HasEditablePropertiesProperty); set => SetValue(HasEditablePropertiesProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region SelectedItem
|
||||
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(IOrderTypeDefVM), typeof(OrderDetailsPopupControl),
|
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedItemChanged));
|
||||
|
||||
private static void SelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs baseValue) {
|
||||
var item = ((OrderDetailsPopupControl)d).SelectedItem;
|
||||
d.SetValue(HasEditablePropertiesProperty, item != null && !item.meta.NoProps);
|
||||
}
|
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
|
||||
public IOrderTypeDefVM SelectedItem { get => GetValue(SelectedItemProperty) as IOrderTypeDefVM; set => SetValue(SelectedItemProperty, value); }
|
||||
#endregion
|
||||
|
||||
private void TrySetGridColumnWidths() {
|
||||
void TrySetGridColumnWidths() {
|
||||
var grid = GetTemplateChild("Root") as Grid;
|
||||
if (grid != null && grid.ColumnDefinitions.Count > 2) {
|
||||
switch (ExpandDirection) {
|
||||
@@ -93,8 +84,7 @@ namespace mbts.ui.spark.algo
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
public override void OnApplyTemplate() =>
|
||||
TrySetGridColumnWidths();
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-10
@@ -4,20 +4,19 @@ using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
using mbts.ui.utilities;
|
||||
|
||||
namespace mbts.ui.converters
|
||||
{
|
||||
namespace mbts.ui.converters {
|
||||
[ValueConversion(typeof(SyntheticContract.Types.PriceCalc), typeof(string))]
|
||||
internal class SyntheticPriceCalcDisplayTextConverter : IValueConverter
|
||||
{
|
||||
class SyntheticPriceCalcDisplayTextConverter : IValueConverter {
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
switch ((SyntheticContract.Types.PriceCalc)value) {
|
||||
case SyntheticContract.Types.PriceCalc.Diff: return "Standard";
|
||||
default: return DisplayNameHelper.camel_to_title_case(value.ToString());
|
||||
}
|
||||
if (value is SyntheticContract.Types.PriceCalc price_calc) {
|
||||
switch (price_calc) {
|
||||
case SyntheticContract.Types.PriceCalc.Diff: return "Standard";
|
||||
default: return DisplayNameHelper.camel_to_title_case(value.ToString());
|
||||
}
|
||||
} else return value != null ? value.ToString() : string.Empty;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,11 @@
|
||||
</Grid>
|
||||
<ComboBox Margin="2,10,2,2" ItemsSource="{Binding accounts}" SelectedItem="{Binding selected_account}"/>
|
||||
<ComboBox ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding selected_time_in_force}" Margin="2"/>
|
||||
<uag:OrderDetailsPopupControl ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}" Margin="2" ExpandDirection="Left"/>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Margin="2" ExpandDirection="Left"
|
||||
ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}"
|
||||
HasEditableProperties="{Binding selected_order_type.has_editable_properties, FallbackValue=False}"
|
||||
/>
|
||||
|
||||
<TextBox HorizontalContentAlignment="Right" Text="{Binding size_calculator.value}" Margin="2,17,2,2"/>
|
||||
<ItemsControl ItemsSource="{Binding size_calculator.buttons}" Focusable="False">
|
||||
|
||||
@@ -104,6 +104,7 @@ namespace mbts.spark {
|
||||
public bool is_bts_type => display_name.StartsWith("BTS");
|
||||
public string display_name => OrderUtils.order_type_display_name(order_type);
|
||||
public OrderMetadata meta => factory.get_metadata(order_type);
|
||||
public virtual bool has_editable_properties => !meta.NoProps;
|
||||
|
||||
public abstract void assign_to(CustomOrderDefinition value);
|
||||
|
||||
@@ -294,6 +295,7 @@ namespace mbts.spark {
|
||||
if (!is_initialized) initialize();
|
||||
if ((value is ILazyOrderTypeDefVM lvm) && !lvm.is_initialized) lvm.initialize();
|
||||
_child_order = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,10 +456,22 @@ namespace mbts.spark {
|
||||
SecurityImmutable? _security;
|
||||
OrdersModel _orders_model;
|
||||
ExecutionStrategyImmutable? _strategy;
|
||||
SyntheticEditorVM _strategy_editor;
|
||||
|
||||
internal SpreaderOrderVM(OrdersModel orders_model) : base(orders_model.factory) =>
|
||||
_orders_model = orders_model;
|
||||
|
||||
public SyntheticEditorVM strategy_editor {
|
||||
get {
|
||||
if (_strategy_editor == null && _security.HasValue && _strategy.HasValue)
|
||||
_strategy_editor = new SyntheticEditorVM(_orders_model.spreader, _security.Value, _strategy.Value);
|
||||
return _strategy_editor;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool has_editable_properties =>
|
||||
base.has_editable_properties && _security.HasValue && _strategy.HasValue;
|
||||
|
||||
public override string error_message =>
|
||||
_security.HasValue && _strategy.HasValue ? string.Empty : "waiting for strategy";
|
||||
|
||||
@@ -465,15 +479,15 @@ namespace mbts.spark {
|
||||
using (_defer_invoke_is_ready_changed()) {
|
||||
_security = security;
|
||||
var lookup = await _orders_model.spreader.lookup_strategy_async(security);
|
||||
if (lookup.success)
|
||||
_strategy = lookup.result;
|
||||
if (lookup.success) _strategy = lookup.result;
|
||||
RaisePropertyChanged(nameof(has_editable_properties));
|
||||
}
|
||||
}
|
||||
|
||||
public override void assign_to(CustomOrderDefinition value) {
|
||||
if (is_ready) {
|
||||
var s = factory.spreader_order();
|
||||
s.ExecutionStrategy = _strategy.Value.CloneToMutable();
|
||||
s.ExecutionStrategy = (_strategy_editor != null ? _strategy_editor.create_strategy() : _strategy.Value).CloneToMutable();
|
||||
s.Security = _security.Value.CloneToMutable();
|
||||
value.Spreader = s;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,9 @@
|
||||
/>
|
||||
<uag:OrderDetailsPopupControl
|
||||
Grid.Row="2" Margin="0,2" ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}"
|
||||
usp:OrderModificationControl.IsDirty="{Binding order_type_dirty, FallbackValue={x:Null}}">
|
||||
usp:OrderModificationControl.IsDirty="{Binding order_type_dirty, FallbackValue={x:Null}}"
|
||||
HasEditableProperties="{Binding selected_order_type.has_editable_properties, FallbackValue=False}"
|
||||
>
|
||||
<uag:OrderDetailsPopupControl.Style>
|
||||
<Style TargetType="uag:OrderDetailsPopupControl" BasedOn="{StaticResource {x:Type uag:OrderDetailsPopupControl}}">
|
||||
<Style.Triggers>
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace mbts.ui.spark {
|
||||
case CustomOrderDefinition.CustomOneofCase.StopLimit: return StopLimitOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.TimeBox: return TimeBoxOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Iceberg: return IcebergOrderTemplate;
|
||||
case CustomOrderDefinition.CustomOneofCase.Spreader: return SpreaderTemplate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -133,6 +133,7 @@ namespace mbts.spark {
|
||||
lvm.initialize();
|
||||
_on_selected_order_type_changed(_selected_order_type = value);
|
||||
_validate_selected_order_type();
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
public ICommand set_price_command { get; }
|
||||
|
||||
Reference in new issue
Block a user