SPARK-2234 / SPARK-2332 ladder - toggle conf to display algo params in a grid (like orderbook)
This commit is contained in:
1 parent
e5bffc3e89
commit
3d96bc98e2
6 files changed
+100
-13
No files matched your search
@@ -63,6 +63,7 @@ namespace bts.shell {
|
||||
init.use_defaults |= state_settings == null;
|
||||
var vm = LadderVM.create(_bus, model, settings_manager, init);
|
||||
vm.order_properties_vm.open_algo_popup_on_select = _ladder_conf.open_algo_popup_on_select;
|
||||
vm.order_properties_vm.use_algo_param_grid = _ladder_conf.use_algo_param_grid;
|
||||
var lv = new LadderView(vm);
|
||||
foreach (var kv in AlgoStudioModelUtils.get_dynamic_resources(vm.model.order_gateway.algo_model.ui_configuration))
|
||||
lv.Resources[kv.Key] = kv.Value;
|
||||
@@ -137,12 +138,13 @@ namespace bts.shell {
|
||||
|
||||
readonly struct LadderConfig {
|
||||
public readonly uint max_open_ladders;
|
||||
public readonly bool ladders_on_threads, open_algo_popup_on_select;
|
||||
public readonly bool ladders_on_threads, open_algo_popup_on_select, use_algo_param_grid;
|
||||
public readonly TimeSpan security_timeout;
|
||||
|
||||
public LadderConfig(bts.config.LadderKnobs knobs, bool ladders_on_threads) {
|
||||
max_open_ladders = knobs.max_open_ladders;
|
||||
open_algo_popup_on_select = knobs.open_algo_popup_on_select;
|
||||
use_algo_param_grid = knobs.use_algo_param_grid;
|
||||
security_timeout = TimeSpan.FromSeconds(Math.Max(15, knobs.security_timeout_secs));
|
||||
this.ladders_on_threads = ladders_on_threads;
|
||||
}
|
||||
|
||||
@@ -63,10 +63,12 @@ namespace mbts.spark {
|
||||
readonly TableUpdateBuffer<AlgoData, AlgoKey> _definitions_buffer = new TableUpdateBuffer<AlgoData, AlgoKey>(d => d.key);
|
||||
readonly EditableCollectionModel<AlgoDefinitionTemplateVM, AlgoDefinitionVM> _algo_template_collection_model;
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoKey> _favorite_templates = new ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoKey>(tvm => tvm.key);
|
||||
readonly ObservableAggregateCollection<AlgoParamRowVM> _algo_param_rows = new ObservableAggregateCollection<AlgoParamRowVM>();
|
||||
IReadOnlyDictionary<AlgoKey, AlgoDefinitionMetadata> _algo_metadata = DictionaryHelper.empty<AlgoKey, AlgoDefinitionMetadata>();
|
||||
IReadOnlyDictionary<AlgoKey, int> _favorite_algos_index = DictionaryHelper.empty<AlgoKey, int>();
|
||||
IReadOnlyDictionary<AlgoKey, int> _favorite_algos_index = DictionaryHelper.empty<AlgoKey, int>();
|
||||
IDisposable _algo_param_rows_hook;
|
||||
int _favorite_algos_column_count;
|
||||
bool _open_algo_popup_on_select;
|
||||
bool _open_algo_popup_on_select, _use_algo_param_grid;
|
||||
|
||||
public OrderPropertiesEditorVM(OrdersModel model, IObservable<SecurityMD> security_md_source, IObservable<InlineOrderProperties> order_properties) {
|
||||
_model = model;
|
||||
@@ -207,7 +209,10 @@ namespace mbts.spark {
|
||||
d.selected_format = fmt;
|
||||
}),
|
||||
vm), true)) {
|
||||
() => Disposable.dispose(ref _template_collection_sync)
|
||||
() => {
|
||||
Disposable.dispose(ref _template_collection_sync);
|
||||
Disposable.dispose(ref _algo_param_rows_hook);
|
||||
}
|
||||
};
|
||||
async Task save_template_async(AlgoDefinitionTemplateVM template) {
|
||||
using (_preserve_selection_by_index())
|
||||
@@ -238,8 +243,11 @@ namespace mbts.spark {
|
||||
IDisposable _template_collection_sync;
|
||||
void _selected_algo_definition_Changed(AlgoDefinitionVM old_value, AlgoDefinitionVM new_value, SelectionReason reason) {
|
||||
Disposable.dispose(ref _template_collection_sync);
|
||||
Disposable.dispose(ref _algo_param_rows_hook);
|
||||
if (new_value != null) {
|
||||
_template_collection_sync = ObservableAutoWrapper.connect_two_way(new_value.templates_with_custom, algo_templates);
|
||||
if (use_algo_param_grid)
|
||||
_algo_param_rows_hook = _connect_algo_param_rows(new_value, _algo_param_rows);
|
||||
if (reason != SelectionReason.Explicit)
|
||||
_selected_algo_stack.Push(new_value.key);
|
||||
} else {
|
||||
@@ -267,9 +275,21 @@ namespace mbts.spark {
|
||||
public TimeInForce selected_time_in_force { get => _time_in_force.selected_item; set => _time_in_force.selected_item = value; }
|
||||
public CustomOrderDefinitionImmutable? definition => selected_algo_template?.algo_root?.definition;
|
||||
public int favorite_algos_column_count { get => _favorite_algos_column_count; private set => Set(ref _favorite_algos_column_count, value); }
|
||||
public bool use_algo_param_grid {
|
||||
get => _use_algo_param_grid;
|
||||
set {
|
||||
if (_use_algo_param_grid != value) {
|
||||
_use_algo_param_grid = value;
|
||||
if (value) {
|
||||
Disposable.replace(ref _algo_param_rows_hook, _connect_algo_param_rows(selected_algo_definition, _algo_param_rows));
|
||||
} else Disposable.dispose(ref _algo_param_rows_hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
// items sources
|
||||
public ObservableCollection<AlgoDefinitionVM> algo_definitions => _algo_definitions;
|
||||
public ObservableCollection<AlgoDefinitionTemplateVM> algo_templates { get; } = new ObservableCollection<AlgoDefinitionTemplateVM>();
|
||||
public IReadOnlyObservableCollection<AlgoParamRowVM> algo_param_rows => _algo_param_rows;
|
||||
public ICollectionView<AlgoDefinitionVM> algo_definitions_view => _algo_definitions_view;
|
||||
public ICollectionView<AlgoDefinitionVM> favorite_algo_definitions_view => _favorite_algo_definitions_view;
|
||||
public ICollectionView algo_templates_view { get; }
|
||||
@@ -388,6 +408,9 @@ namespace mbts.spark {
|
||||
favorite_algos_column_count = value.column_count;
|
||||
}
|
||||
|
||||
static IDisposable _connect_algo_param_rows(AlgoDefinitionVM def, ObservableAggregateCollection<AlgoParamRowVM> rows) =>
|
||||
AlgoParamRowsHelper.connect(def, rows, false);
|
||||
|
||||
int? _get_favorite_algo_index(AlgoKey key) =>
|
||||
key.mode == AlgoKey.Mode.Persisted && _favorite_algos_index.TryGetValue(key, out int i) ? i : (int?)null;
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
Margin="4,0,0,0"
|
||||
MinWidth="100"
|
||||
Text="{Binding Definition.name, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Visibility="Collapsed"
|
||||
>
|
||||
<c:EditableTextBlock.CommandBindings>
|
||||
<CommandBinding Command="{x:Static c:EditableTextBlock.EndEditCommand}" Executed="{x:Static c:EditableTextBlock.EndEditExecuted}"/>
|
||||
@@ -352,4 +353,4 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
@@ -31,8 +32,27 @@
|
||||
<Style x:Key="AlgoTemplateItemContainerStyle" TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
</Style>
|
||||
<DataTemplate x:Key="AlgoTemplateHeaderContentTemplate">
|
||||
<TextBlock Text="{Binding StringFormat='{}{0}:'}" FontWeight="Bold" VerticalAlignment="Center"/>
|
||||
<DataTemplate x:Key="AlgoTemplateHeaderContentTemplate" DataType="sp:AlgoDefinitionVM">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
x:Name="order_type"
|
||||
Text="{Binding algo_root.order_type, Converter={StaticResource OrderTypeDisplayTextConverter}, StringFormat='{}{0}: ', Mode=OneWay}"
|
||||
FontWeight="Bold"
|
||||
/>
|
||||
<TextBlock x:Name="display_name" Text="{Binding name, Mode=OneWay}" FontWeight="Normal"/>
|
||||
</StackPanel>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Value="{u:True}">
|
||||
<DataTrigger.Binding>
|
||||
<MultiBinding Converter="{x:Static cv:ValueConverters.AreEqualConverter}">
|
||||
<Binding Path="(sp:AlgoDefinitionVM.algo_root).(sp:IAlgoVM.order_type)" Converter="{StaticResource OrderTypeDisplayTextConverter}"/>
|
||||
<Binding Path="(sp:AlgoDefinitionVM.name)"/>
|
||||
</MultiBinding>
|
||||
</DataTrigger.Binding>
|
||||
<Setter TargetName="order_type" Property="Visibility" Value="{x:Static Visibility.Collapsed}"/>
|
||||
<Setter TargetName="display_name" Property="FontWeight" Value="{x:Static FontWeights.Bold}"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
<Style TargetType="uag:OrderDetailsPopupControl">
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
@@ -43,7 +63,27 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="uag:OrderDetailsPopupControl">
|
||||
<Grid x:Name="Root" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<Grid
|
||||
x:Name="Root"
|
||||
u:StateManager.VisualState="{Binding use_algo_param_grid, Converter={x:Static uag:OrderDetailsPopupControl.AlgoParamsVisualStateConverter}}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:OrderDetailsPopupControl.VisualStateNames.AlgoParams}}">
|
||||
<VisualState Name="{x:Static Grid, MemberType={u:Nested uag:OrderDetailsPopupControl.VisualStateNames.AlgoParams}}"/>
|
||||
<VisualState Name="{x:Static Studio, MemberType={u:Nested uag:OrderDetailsPopupControl.VisualStateNames.AlgoParams}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ParamGridView" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StudioView" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="0"/>
|
||||
@@ -102,7 +142,7 @@
|
||||
Definition="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=uag:OrderDetailsPopupControl}}"
|
||||
EditableCollectionModel="{Binding algo_template_collection_model}"
|
||||
Padding="0,1,0,3"
|
||||
Header="{Binding SelectedItem.algo_root.order_type, RelativeSource={RelativeSource AncestorType=uag:OrderDetailsPopupControl}, Converter={StaticResource OrderTypeDisplayTextConverter}}"
|
||||
Header="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=uag:OrderDetailsPopupControl}}"
|
||||
HeaderTemplate="{StaticResource AlgoTemplateHeaderContentTemplate}"
|
||||
RemoveCommand="{Binding remove_template_cmd}"
|
||||
UndoCommand="{Binding undo_cmd}"
|
||||
@@ -151,10 +191,20 @@
|
||||
</uag:AlgoTemplateToolBar.CommandBindings>
|
||||
</uag:AlgoTemplateToolBar>
|
||||
<ContentControl
|
||||
x:Name="StudioView"
|
||||
Grid.Row="1"
|
||||
Margin="12,8,12,12"
|
||||
Content="{Binding SelectedItem.visible_algo_root, RelativeSource={RelativeSource AncestorType=uag:OrderDetailsPopupControl}}"
|
||||
ContentTemplateSelector="{StaticResource AlgoTemplateSelector}"
|
||||
Visibility="Collapsed"
|
||||
/>
|
||||
<usp:AlgoEditorGridView
|
||||
x:Name="ParamGridView"
|
||||
Grid.Row="1"
|
||||
Margin="12,8,12,12"
|
||||
CanUserChangeAlgoRoot="False"
|
||||
AlgoParamRows="{Binding algo_param_rows}"
|
||||
Visibility="Visible"
|
||||
/>
|
||||
</Grid>
|
||||
</c:PopupControl>
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
@@ -17,14 +16,15 @@ namespace mbts.ui.spark.algo {
|
||||
static OrderDetailsPopupControl() =>
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderDetailsPopupControl), new FrameworkPropertyMetadata(typeof(OrderDetailsPopupControl)));
|
||||
|
||||
public static IValueConverter TriggerPayupTypeDescriptionConverter =
|
||||
ValueConverter.create<TriggerPayupPrice.Types.TriggerPayupPriceType, string>(
|
||||
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());
|
||||
}
|
||||
});
|
||||
}),
|
||||
AlgoParamsVisualStateConverter = ValueConverter.create<bool, string>(use_param_grid => use_param_grid ? VisualStateNames.AlgoParams.Grid : VisualStateNames.AlgoParams.Studio);
|
||||
|
||||
#region ExpandDirection
|
||||
public static readonly DependencyProperty ExpandDirectionProperty = DependencyProperty.Register(nameof(ExpandDirection), typeof(ExpandDirection), typeof(OrderDetailsPopupControl),
|
||||
@@ -98,5 +98,15 @@ namespace mbts.ui.spark.algo {
|
||||
|
||||
public override void OnApplyTemplate() =>
|
||||
TrySetGridColumnWidths();
|
||||
|
||||
public static class VisualStateNames {
|
||||
public static class AlgoParams {
|
||||
public const string GroupName = nameof(AlgoParams);
|
||||
|
||||
public static readonly string
|
||||
Studio = $"{GroupName}{nameof(Studio)}",
|
||||
Grid = $"{GroupName}{nameof(Grid)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,7 @@ message LadderKnobs {
|
||||
optional uint32 max_open_ladders = 4 [default = 75];
|
||||
optional uint32 security_timeout_secs = 5 [default = 60];
|
||||
optional bool open_algo_popup_on_select = 6 [default = false];
|
||||
optional bool use_algo_param_grid = 7 [default = false];
|
||||
}
|
||||
|
||||
message ShellPingOptions {
|
||||
|
||||
Reference in new issue
Block a user