Merge branch 'SPARK-1944-attach/detach/update' of bitbucket.org:bluetradesys/spark into ice_exec3
This commit is contained in:
commit
bdbdda947f
59 files changed
+2361
-513
No files matched your search
@@ -374,6 +374,29 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public void load_many(IEnumerable<CustomOrderDefinitionImmutable> defs) {
|
||||
var def_list = defs as IList<CustomOrderDefinitionImmutable> ?? defs.ToList();
|
||||
switch (def_list.Count) {
|
||||
case 0: algo_root = null; break;
|
||||
case 1: load_def(def_list[0]); break;
|
||||
default:
|
||||
var def = def_list[0];
|
||||
var key = OrderDataHelper.get_shallow_factory_key(def);
|
||||
if (algo_root?.id == key) {
|
||||
algo_root.load_many(def_list);
|
||||
} else if (_algo_roots.TryGetValue(key, out IAlgoVM vm)) {
|
||||
vm.load_many(def_list);
|
||||
algo_root = vm;
|
||||
} else {
|
||||
OrderTypeVMFactory.create(key, def.display_name(), def.CustomCase, is_expanded: true);
|
||||
algo_roots.Add(vm = _mk_algo_root(def));
|
||||
vm.load_many(def_list);
|
||||
algo_root = vm;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void load(AlgoData data) {
|
||||
_assert_can_load(data.key);
|
||||
if (algo_root != null)
|
||||
|
||||
@@ -18,8 +18,21 @@ namespace mbts.spark {
|
||||
|
||||
public IAlgoVM algo { get; set; }
|
||||
public IAlgoParamVM param { get; }
|
||||
public int level => parent == null ? 0 : parent.level + 1;
|
||||
public AlgoParamRowVM parent { get; }
|
||||
public int level => parent == null ? 0 : parent.level + 1;
|
||||
public string path_disambiguation {
|
||||
get {
|
||||
if (parent == null)
|
||||
return string.Empty;
|
||||
string pd = parent.path_disambiguation;
|
||||
if (parent.algo.order_type == bts.api.orderman.CustomOrderDefinition.CustomOneofCase.Cover) {
|
||||
if (pd.Length > 0)
|
||||
pd += ".";
|
||||
pd += parent.param.display_name;
|
||||
}
|
||||
return pd;
|
||||
}
|
||||
}
|
||||
public bool is_enabled { get => _is_enabled; set => Set(ref _is_enabled, value); }
|
||||
|
||||
public void raise_invalidated() => invalidated?.Invoke();
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace mbts.spark {
|
||||
public void assign_to(CustomOrderDefinition value) => _algo_root?.assign_to(value);
|
||||
public bool key_match(KeyEventArgs e) => _algo_root?.key_match(e) ?? false;
|
||||
public void load_from(CustomOrderDefinitionImmutable value) => _algo_root?.load_from(value);
|
||||
public void load_many(IEnumerable<CustomOrderDefinitionImmutable> values) => _algo_root?.load_many(values);
|
||||
public Task<CustomOrderDefinitionImmutable?> load_from_async(CustomOrderDefinitionImmutable definition) => _algo_root is IAlgoVM vm ? vm.load_from_async(definition) : Task.FromResult<CustomOrderDefinitionImmutable?>(null);
|
||||
|
||||
IDisposable _set_hooks(AlgoDefinitionVM vm) {
|
||||
|
||||
+106
-15
@@ -4,12 +4,14 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
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:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
u:StateManager.VisualState="{Binding CanUserChangeAlgoRoot, RelativeSource={RelativeSource Self}, Converter={x:Static usp:AlgoEditorGridView.AlgoRootVisualStateConverter}}"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
@@ -35,6 +37,7 @@
|
||||
<cv:TimeConverter x:Key="TimeConverter"/>
|
||||
<cv:GridLengthConverter x:Key="GridLengthPixelConverter" Multiplier="18" UnitType="Pixel"/>
|
||||
<cv:EnumItemsSourceConverter x:Key="EnumItemsSourceConverter"/>
|
||||
<cv:NullableEnumDescriptionConverter x:Key="NullableEnumDescriptionConverter" TextForNull="*"/>
|
||||
<!--Default Styles-->
|
||||
<Style TargetType="uag:AlgoPickerNodeView" BasedOn="{StaticResource {x:Type uag:AlgoPickerNodeView}}">
|
||||
<Setter Property="DropDownStyleKey" Value="{Binding DataContext, RelativeSource={RelativeSource AncestorType=usp:AlgoEditorView}, Converter={x:Static usp:AlgoContentTemplateSelector.AlgoDropDownStyleKeyConverter}}"/>
|
||||
@@ -44,7 +47,23 @@
|
||||
<usp:OrderTypeItem DisplayName="{Binding display_name}" BadgeFill="{Binding meta.Color, Converter={StaticResource ColorToBrushConverter}}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="ParamNameCellTemplate">
|
||||
<DataTemplate x:Key="NullableEnumDescriptionTemplate">
|
||||
<TextBlock Text="{Binding Converter={StaticResource NullableEnumDescriptionConverter}}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="ParamNameAndDisambiguationCellTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock x:Name="disambig_text" Margin="0,0,2,0" FontWeight="Light" Text="{Binding path_disambiguation, StringFormat='[{0}]', Mode=OneWay}"/>
|
||||
<TextBlock Text="{Binding Path='param.(sp:IAlgoParamVM.display_name)', Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding path_disambiguation}" Value="{x:Static sys:String.Empty}">
|
||||
<Setter TargetName="disambig_text" Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="IndentedParamNameAndBadgeCellTemplate">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding level, Converter={StaticResource GridLengthPixelConverter}}"/>
|
||||
@@ -71,6 +90,7 @@
|
||||
DoubleTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
IntTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
UIntTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
NullableUIntTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
ExecutionStrategyTemplate="{StaticResource ExecutionStrategyTemplate}"
|
||||
>
|
||||
<usp:AlgoParamTemplateSelector.EnumTemplate>
|
||||
@@ -78,6 +98,11 @@
|
||||
<TextBlock Text="{Binding param.value, Converter={StaticResource EnumDescriptionConverter}}"/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.EnumTemplate>
|
||||
<usp:AlgoParamTemplateSelector.NullableEnumTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding param.value, Converter={StaticResource NullableEnumDescriptionConverter}}"/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.NullableEnumTemplate>
|
||||
<usp:AlgoParamTemplateSelector.BoolTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Focusable="False" VerticalAlignment="Center" IsChecked="{Binding param.value, Mode=TwoWay}"/>
|
||||
@@ -116,6 +141,11 @@
|
||||
<c:TickUpDownUInt Focusable="False" HorizontalAlignment="Stretch" Value="{Binding param.value}"/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.UIntTemplate>
|
||||
<usp:AlgoParamTemplateSelector.NullableUIntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownNullableUInt Focusable="False" HorizontalAlignment="Stretch" Value="{Binding param.value}"/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.NullableUIntTemplate>
|
||||
<usp:AlgoParamTemplateSelector.BoolTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Focusable="False" VerticalAlignment="Center" IsChecked="{Binding param.value, Mode=TwoWay}"/>
|
||||
@@ -123,9 +153,24 @@
|
||||
</usp:AlgoParamTemplateSelector.BoolTemplate>
|
||||
<usp:AlgoParamTemplateSelector.EnumTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox HorizontalAlignment="Stretch" ItemsSource="{Binding param.value, Converter={StaticResource EnumItemsSourceConverter}, Mode=OneTime}" SelectedItem="{Binding param.value}"/>
|
||||
<ComboBox
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding param.value, Converter={StaticResource EnumItemsSourceConverter}, Mode=OneTime}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding param.value}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.EnumTemplate>
|
||||
<usp:AlgoParamTemplateSelector.NullableEnumTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding param.value, Converter={StaticResource EnumItemsSourceConverter}, Mode=OneTime}"
|
||||
ItemTemplate="{StaticResource NullableEnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding param.value}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</usp:AlgoParamTemplateSelector.NullableEnumTemplate>
|
||||
<usp:AlgoParamTemplateSelector.TimestampTemplate>
|
||||
<DataTemplate>
|
||||
<Grid DataContext="{Binding algo}">
|
||||
@@ -199,16 +244,62 @@
|
||||
</usp:AlgoEditorGridRowStyleSelector>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<DataGrid x:Name="_param_grid" VirtualizingPanel.ScrollUnit="Pixel" MinRowHeight="18" ItemsSource="{Binding ParamRowsViewSource.View, RelativeSource={RelativeSource AncestorType=usp:AlgoEditorGridView}}" SelectionMode="Single" RowStyleSelector="{StaticResource RowStyleSelector}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Header="Param" CellTemplate="{StaticResource ParamNameCellTemplate}" MinWidth="140" Width="Auto">
|
||||
<DataGridTemplateColumn.CellStyle>
|
||||
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
</Style>
|
||||
</DataGridTemplateColumn.CellStyle>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="Value" CellTemplateSelector="{StaticResource ParamTemplateSelector}" CellEditingTemplateSelector="{StaticResource ParamEditingTemplateSelector}" MinWidth="160" Width="Auto"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</UserControl>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested usp:AlgoEditorGridView.VisualStateNames.AlgoRoot}}">
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested usp:AlgoEditorGridView.VisualStateNames.AlgoRoot}}"/>
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested usp:AlgoEditorGridView.VisualStateNames.AlgoRoot}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="root_algo_label" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="root_algo_combo_box" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ThicknessAnimation Storyboard.TargetName="_param_grid" Storyboard.TargetProperty="(Control.Margin)" BeginTime="0" Duration="0" To="0,4,0,0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="root_algo_label" VerticalAlignment="Center" Margin="{StaticResource Margin.LP2}" Visibility="Collapsed">Algo</TextBlock>
|
||||
<ComboBox
|
||||
x:Name="root_algo_combo_box"
|
||||
Margin="40,0,0,0"
|
||||
ItemsSource="{Binding AlgoVM.algo_roots, RelativeSource={RelativeSource AncestorType=usp:AlgoEditorGridView}}"
|
||||
SelectedItem="{Binding AlgoVM.algo_root, RelativeSource={RelativeSource AncestorType=usp:AlgoEditorGridView}}"
|
||||
Visibility="Collapsed"
|
||||
>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<usp:OrderTypeItem BadgeFill="{Binding meta.Color, Converter={StaticResource ColorToBrushConverter}}" DisplayName="{Binding display_name}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<DataGrid
|
||||
x:Name="_param_grid"
|
||||
Grid.Row="1"
|
||||
VirtualizingPanel.ScrollUnit="Pixel"
|
||||
Margin="0,2,0,0"
|
||||
MinRowHeight="18"
|
||||
ColumnHeaderHeight="0"
|
||||
ItemsSource="{Binding ParamRowsViewSource.View, RelativeSource={RelativeSource AncestorType=usp:AlgoEditorGridView}}"
|
||||
SelectionMode="Single"
|
||||
RowStyleSelector="{StaticResource RowStyleSelector}"
|
||||
>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Header="Param" CellTemplate="{StaticResource ParamNameAndDisambiguationCellTemplate}" MinWidth="140" Width="Auto">
|
||||
<DataGridTemplateColumn.CellStyle>
|
||||
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
</Style>
|
||||
</DataGridTemplateColumn.CellStyle>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="Value" CellTemplateSelector="{StaticResource ParamTemplateSelector}" CellEditingTemplateSelector="{StaticResource ParamEditingTemplateSelector}" MinWidth="160" Width="Auto"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+26
-13
@@ -1,13 +1,19 @@
|
||||
using mbts.spark;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
partial class AlgoEditorGridView : UserControl {
|
||||
public static readonly IValueConverter
|
||||
AlgoRootVisualStateConverter = ValueConverter.create<bool, string>(show_bbo => show_bbo ? VisualStateNames.AlgoRoot.Active : VisualStateNames.AlgoRoot.Inactive),
|
||||
AlgoRootComboBoxMarginConverter = ValueConverter.create<double, Thickness>(name_col_width => new Thickness(name_col_width + 8, 0, 0, 0));
|
||||
|
||||
readonly ObservableAggregateCollection<AlgoParamRowVM> _param_rows = new ObservableAggregateCollection<AlgoParamRowVM>();
|
||||
IDisposable _rows_hook;
|
||||
|
||||
@@ -22,6 +28,16 @@ namespace mbts.ui.spark {
|
||||
|
||||
public CollectionViewSource<ListCollectionView<AlgoParamRowVM>> ParamRowsViewSource { get; }
|
||||
|
||||
#region CanUserChangeAlgoRoot
|
||||
public static readonly DependencyProperty CanUserChangeAlgoRootProperty =
|
||||
WPFHelper.create_dp<bool, AlgoEditorGridView>(nameof(CanUserChangeAlgoRoot));
|
||||
|
||||
public bool CanUserChangeAlgoRoot {
|
||||
get => (bool)GetValue(CanUserChangeAlgoRootProperty);
|
||||
set => SetValue(CanUserChangeAlgoRootProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowAlgoTypeNodes
|
||||
public static readonly DependencyProperty ShowAlgoTypeNodesProperty =
|
||||
WPFHelper.create_dp<bool, AlgoEditorGridView>(
|
||||
@@ -46,19 +62,6 @@ namespace mbts.ui.spark {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowAlgoTypeNodes
|
||||
public static readonly DependencyProperty ShowExecutionStrategyProperty =
|
||||
DependencyProperty.RegisterAttached("ShowExecutionStrategy", typeof(bool), typeof(AlgoEditorGridView),
|
||||
new PropertyMetadata(false, (d, e) => {
|
||||
var el = (FrameworkElement)d;
|
||||
if (el.try_find_ancestor_of_type(out DataGridRow row_view))
|
||||
row_view.SetCurrentValue(DataGridRow.DetailsVisibilityProperty, (bool)e.NewValue ? Visibility.Visible : Visibility.Collapsed);
|
||||
}));
|
||||
|
||||
public static bool GetShowExecutionStrategy(DependencyObject d) => (bool)d.GetValue(ShowExecutionStrategyProperty);
|
||||
public static void SetShowExecutionStrategy(DependencyObject d, bool value) => d.SetValue(ShowExecutionStrategyProperty, value);
|
||||
#endregion
|
||||
|
||||
void _on_execution_strategy_toggle_click(object sender, RoutedEventArgs e) {
|
||||
if (sender is Hyperlink hl && hl.try_find_ancestor_of_type(out DataGridRow row_view)) {
|
||||
Visibility vis; string text;
|
||||
@@ -74,6 +77,16 @@ namespace mbts.ui.spark {
|
||||
row_view.SetCurrentValue(DataGridRow.DetailsVisibilityProperty, vis);
|
||||
}
|
||||
}
|
||||
|
||||
public static class VisualStateNames {
|
||||
public static class AlgoRoot {
|
||||
public const string GroupName = nameof(AlgoRoot);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlgoEditorGridRowStyleSelector : StyleSelector {
|
||||
|
||||
+14
-1
@@ -12,7 +12,20 @@ namespace mbts.ui.spark {
|
||||
partial class AlgoEditorGridView : UserControl {
|
||||
static class AlgoParamRowsHelper {
|
||||
public static IDisposable reset(AlgoDefinitionVM algo, ObservableAggregateCollection<AlgoParamRowVM> rows, bool include_algo_type_rows) =>
|
||||
algo == null ? null : new CompositeDisposable(_wrap_rows(algo, rows, include_algo_type_rows)) { rows.clear_collections };
|
||||
algo == null ? null : new CompositeDisposable(algo.observe_algo_root().SubscribeHookLatest(a => {
|
||||
rows.clear_collections();
|
||||
if (a == null)
|
||||
return Disposable.empty;
|
||||
var child_rows = new ObservableAggregateCollection<AlgoParamRowVM>();
|
||||
/// Note: the order of operations here matters
|
||||
/// <see cref="_wrap_rows(IAlgoVM, AlgoParamRowVM, ObservableAggregateCollection{AlgoParamRowVM}, bool)" /> has the potential to trigger a lot of CollectionChanged events (depending on how deep the algo-tree is).
|
||||
/// There is no need to burden the aggregate 'rows' with echoing all of these events, if the child-row collection is finished changing when it is added to the aggregate.
|
||||
var hook = _wrap_rows(a, null, child_rows, include_algo_type_rows);
|
||||
rows.add_collection(child_rows.AsReadOnly());
|
||||
return hook;
|
||||
})) {
|
||||
rows.clear_collections
|
||||
};
|
||||
|
||||
static IDisposable _wrap_rows(AlgoDefinitionVM algo_def, ObservableAggregateCollection<AlgoParamRowVM> rows, bool include_algo_type_rows) {
|
||||
AlgoParamRowVM root = null;
|
||||
|
||||
+19
-18
@@ -1,5 +1,6 @@
|
||||
using bts.spark;
|
||||
using mbts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
@@ -12,8 +13,10 @@ namespace mbts.ui.spark {
|
||||
public DataTemplate BoolTemplate { get; set; }
|
||||
public DataTemplate IntTemplate { get; set; }
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
public DataTemplate NullableUIntTemplate { get; set; }
|
||||
public DataTemplate DoubleTemplate { get; set; }
|
||||
public DataTemplate EnumTemplate { get; set; }
|
||||
public DataTemplate NullableEnumTemplate { get; set; }
|
||||
public DataTemplate StringTemplate { get; set; }
|
||||
public DataTemplate QuantityMeasureTemplate { get; set; }
|
||||
public DataTemplate OrderDefTemplate { get; set; }
|
||||
@@ -23,28 +26,26 @@ namespace mbts.ui.spark {
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
||||
IAlgoParamVM pvm = item as IAlgoParamVM ?? (item as AlgoParamRowVM)?.param;
|
||||
if (pvm != null) {
|
||||
if (pvm is IAlgoParamVM<double>)
|
||||
return DoubleTemplate;
|
||||
if (pvm is IAlgoParamVM<int>)
|
||||
return IntTemplate;
|
||||
if (pvm is IAlgoParamVM<uint>)
|
||||
return UIntTemplate;
|
||||
if (pvm is IAlgoParamVM<bool>)
|
||||
return BoolTemplate;
|
||||
if (pvm is IAlgoParamVM<string>)
|
||||
return StringTemplate;
|
||||
if (pvm is IAlgoParamVM<IAlgoVM>)
|
||||
return OrderDefTemplate;
|
||||
if (pvm is IAlgoParamVM<QuantityMeasureImmutable>)
|
||||
return QuantityMeasureTemplate;
|
||||
if (pvm is IAlgoParamVM<ExecutionStrategy>)
|
||||
return ExecutionStrategyTemplate;
|
||||
if (pvm is IAlgoParamVM<Google.Protobuf.WellKnownTypes.Timestamp>)
|
||||
return TimestampTemplate;
|
||||
if (pvm is IAlgoParamVM<double>) return DoubleTemplate;
|
||||
if (pvm is IAlgoParamVM<int>) return IntTemplate;
|
||||
if (pvm is IAlgoParamVM<uint>) return UIntTemplate;
|
||||
if (pvm is IAlgoParamVM<uint?>) return NullableUIntTemplate;
|
||||
if (pvm is IAlgoParamVM<bool>) return BoolTemplate;
|
||||
if (pvm is IAlgoParamVM<string>) return StringTemplate;
|
||||
if (pvm is IAlgoParamVM<IAlgoVM>) return OrderDefTemplate;
|
||||
if (pvm is IAlgoParamVM<QuantityMeasureImmutable?>) return QuantityMeasureTemplate;
|
||||
if (pvm is IAlgoParamVM<ExecutionStrategy>) return ExecutionStrategyTemplate;
|
||||
if (pvm is IAlgoParamVM<Google.Protobuf.WellKnownTypes.Timestamp>) return TimestampTemplate;
|
||||
var targ = ReflectionHelper.GetGenericTypeArgs(pvm.GetType(), typeof(IAlgoParamVM<>)).FirstOrDefault();
|
||||
if (targ != null) {
|
||||
if (targ.IsEnum)
|
||||
return EnumTemplate;
|
||||
else if (targ.IsNullable()) {
|
||||
targ = targ.GetGenericArguments()[0];
|
||||
if (targ.IsEnum)
|
||||
return NullableEnumTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using mbts.co2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderModel {
|
||||
readonly OrdersModel _order_gateway;
|
||||
readonly MarketDataAuxiliaryModel _md_auxiliary_model;
|
||||
|
||||
public LadderModel(SecurityMD source, OrdersModel ordergw, MarketDataAuxiliaryModel md_auxiliary_model) {
|
||||
public LadderModel(SecurityMD source, OrdersModel ordergw, Func<OrderSecurity, bool> order_filter = null) {
|
||||
security_md = source;
|
||||
_order_gateway = ordergw;
|
||||
_md_auxiliary_model = md_auxiliary_model;
|
||||
orders = ordergw.working_orders;
|
||||
if (order_filter != null)
|
||||
orders = orders.Select(order_map => new FilteredDictionary<uint, OrderSecurity>(order_map, order_filter));
|
||||
}
|
||||
|
||||
public enum CancelType { All, Bids, Asks }
|
||||
@@ -20,7 +26,7 @@ namespace mbts.spark {
|
||||
public SecurityImmutable security => security_md.security;
|
||||
public MDConsumerHandle md => security_md.md;
|
||||
public OrdersModel order_gateway => _order_gateway;
|
||||
public MarketDataAuxiliaryModel md_auxiliary_model => _md_auxiliary_model;
|
||||
public IObservable<IReadOnlyDictionary<uint, OrderSecurity>> orders { get; }
|
||||
|
||||
public Task cancel_orders(CancelType ct) {
|
||||
switch (ct) {
|
||||
|
||||
@@ -257,8 +257,8 @@ namespace mbts.spark {
|
||||
ask_column.background = BTSColors.MarketData.ask;
|
||||
price_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
last_column.background = 0xFFFFFF;
|
||||
return new LadderSettings {
|
||||
row_height = 20,
|
||||
var rv = new LadderSettings {
|
||||
row_height = 22,
|
||||
grid_line_color = 0x535353,
|
||||
orders_column = orders_column,
|
||||
bid_column = bid_column,
|
||||
@@ -301,6 +301,8 @@ namespace mbts.spark {
|
||||
zoom_factor = _default_zoom_factor,
|
||||
net_change = NetChangeTerms.None,
|
||||
};
|
||||
rv.row_height = LadderRender.measure_row_height(rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,16 +23,14 @@ namespace bts.shell {
|
||||
readonly IWindowManager _wm;
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly MarketDataAuxiliaryModel _md_auxiliary_model;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _securities = new Dictionary<uint, SecurityMD>();
|
||||
|
||||
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model, MarketDataAuxiliaryModel md_auxiliary_model)
|
||||
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model)
|
||||
: base(owner, "SparkLadder") {
|
||||
_bus = bus;
|
||||
_wm = wm;
|
||||
_settings_hub = settings_hub;
|
||||
_orders_model = orders_model;
|
||||
_md_auxiliary_model = md_auxiliary_model;
|
||||
_ladder_conf = new LadderConfig(Configuration.get<bts.config.LadderKnobs>(), Configuration.get<bts.config.MultiThreadedWindows>().ladder);
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s),
|
||||
@@ -56,14 +54,14 @@ namespace bts.shell {
|
||||
IShellWindow create_ladder_window(SecurityMD md, LadderSettings state_settings) {
|
||||
var id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount;
|
||||
var view = new Lazy<UIElement>(() => {
|
||||
var model = new LadderModel(md, _orders_model, _md_auxiliary_model);
|
||||
var model = new LadderModel(md, _orders_model);
|
||||
var settings_manager = new WindowSettingsManager<LadderSettings>(
|
||||
_settings_hub, state_settings == null || state_settings.use_defaults ? null : state_settings,
|
||||
us => sanitize_ladder_settings(us.ladder),
|
||||
(us, v) => us.with(sanitize_ladder_settings(v)));
|
||||
var init = state_settings ?? settings_manager.default_settings;
|
||||
init.use_defaults |= state_settings == null;
|
||||
var vm = new LadderVM(_bus, model, settings_manager, init);
|
||||
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;
|
||||
var lv = new LadderView(vm);
|
||||
foreach (var kv in AlgoStudioModelUtils.get_dynamic_resources(vm.model.order_gateway.algo_model.ui_configuration))
|
||||
|
||||
@@ -38,14 +38,26 @@ namespace mbts.spark {
|
||||
IEqualityComparer<double> _equality;
|
||||
Dictionary<double, LadderOrderVM> _slot_price_vs_orders;
|
||||
|
||||
public LadderVM(IBus bus, LadderModel model, IWindowSettingsManager<LadderSettings> settings_manager, LadderSettings init) {
|
||||
public static LadderVM create(IBus bus, LadderModel model, IWindowSettingsManager<LadderSettings> settings_manager, LadderSettings init) {
|
||||
var non_shared_wsm = settings_manager.as_non_shared();
|
||||
return new LadderVM(bus, model, settings_manager, non_shared_wsm, init, new OrderPropertiesEditorVM(model.order_gateway, Observable.Return(model.security_md), settings_manager.subscribe_current().Select(s => new InlineOrderProperties(model.order_gateway, s))));
|
||||
}
|
||||
|
||||
public static LadderVM create_readonly(IBus bus, LadderModel model) {
|
||||
var default_settings = LadderSettings.Default;
|
||||
return create_readonly(bus, model, new WindowSettingsManager<LadderSettings>.DisconnectedImpl(default_settings), default_settings);
|
||||
}
|
||||
|
||||
public static LadderVM create_readonly(IBus bus, LadderModel model, IWindowSettingsManager<LadderSettings> settings_manager, LadderSettings init) =>
|
||||
new LadderVM(bus, model, settings_manager, settings_manager.as_non_shared(), init);
|
||||
|
||||
LadderVM(IBus bus, LadderModel model, IWindowSettingsManager<LadderSettings> settings_manager, IWindowSettingsManagerNonShared<LadderSettings> non_shared_wsm, LadderSettings init, OrderPropertiesEditorVM order_properties_vm = null) {
|
||||
_bus = bus;
|
||||
_model = model;
|
||||
_equality = TickUtils.tick_equality_comparer(_model.security.ContractSpec);
|
||||
_slot_price_vs_orders = new Dictionary<double, LadderOrderVM>(_equality);
|
||||
var non_shared_wsm = settings_manager.as_non_shared();
|
||||
_settings_manager = non_shared_wsm;
|
||||
order_properties_vm = new OrderPropertiesEditorVM(_model.order_gateway, Observable.Return(_model.security_md), _settings_manager.subscribe_current().Select(s => new InlineOrderProperties(_model.order_gateway, s)));
|
||||
this.order_properties_vm = order_properties_vm;
|
||||
_high = backing(nameof(high), double.NaN);
|
||||
_low = backing(nameof(low), double.NaN);
|
||||
_change = backing(nameof(change), double.NaN);
|
||||
@@ -126,13 +138,11 @@ namespace mbts.spark {
|
||||
_dispose = Disposable.Create(
|
||||
settings_command,
|
||||
non_shared_wsm,
|
||||
settings.OnDispatcher().Subscribe(s => order_properties_vm.on_favorite_algos(s.favorite_algos)),
|
||||
order_properties_vm,
|
||||
order_properties_vm.observe_account(true).Select(a => a?.name ?? string.Empty).Subscribe(account_positions),
|
||||
get_order_properties_editor_hooks(),
|
||||
account_positions,
|
||||
size_calculator = new CalculatorLogic(0, _settings_manager.subscribe_current().Select(s => s.calculator_buttons)),
|
||||
bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update),
|
||||
model.order_gateway.working_orders.OnDispatcher().Subscribe(working => {
|
||||
model.orders.OnDispatcher().Subscribe(working => {
|
||||
// Here we manage N orders to 1 price slot in the ladder
|
||||
|
||||
Dictionary<double, HashSet<uint>> orders_used_in_this_update = new Dictionary<double, HashSet<uint>>(_equality);
|
||||
@@ -225,6 +235,13 @@ namespace mbts.spark {
|
||||
WorkLoop.Start($"Ladder '{security}'", _tick),
|
||||
Disposable.Create(() => _on_disposed_impl?.Invoke(true))
|
||||
);
|
||||
IDisposable get_order_properties_editor_hooks() =>
|
||||
order_properties_vm == null ?
|
||||
Disposable.empty :
|
||||
Disposable.Create(
|
||||
settings.OnDispatcher().Subscribe(s => order_properties_vm.on_favorite_algos(s.favorite_algos)),
|
||||
order_properties_vm,
|
||||
order_properties_vm.observe_account(true).Select(a => a?.name ?? string.Empty).Subscribe(account_positions));
|
||||
}
|
||||
|
||||
public IBus bus => _bus;
|
||||
@@ -269,6 +286,7 @@ namespace mbts.spark {
|
||||
public ulong volume => _volume.Value;
|
||||
public bool auto_clear { get => _auto_clear.Value; set => _auto_clear.set(value); }
|
||||
public CalculatorLogic size_calculator { get; }
|
||||
/// Important: <see cref="order_properties_vm"/> can be null.
|
||||
public OrderPropertiesEditorVM order_properties_vm { get; }
|
||||
public ObservableCollection<LadderOrderVM> orders { get; }
|
||||
public IAsyncCommand cancel_command { get; }
|
||||
@@ -318,6 +336,8 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public void key_down(KeyEventArgs e) {
|
||||
if (order_properties_vm == null)
|
||||
return;
|
||||
// the ctrl modifier requirement helps avoid keyboard-input collisions w/ algo-templates popup
|
||||
if (!KeyboardExtensions.IsCtrlDown()) return;
|
||||
var new_algo = order_properties_vm.algo_definitions.FirstOrDefault(o => o.algo_root.key_match(e));
|
||||
@@ -328,6 +348,8 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public async void send_order((double price, Side? side, bool size_from_alternate) args) {
|
||||
if (order_properties_vm == null)
|
||||
return;
|
||||
var s = _settings_manager.current_settings();
|
||||
if (DoubleHelper.IsNaNOrInfinity(args.price) || !args.side.HasValue || HasErrors || order_properties_vm.HasErrors || (args.size_from_alternate && s.alternate_order_size == 0))
|
||||
return;
|
||||
@@ -383,8 +405,10 @@ namespace mbts.spark {
|
||||
}
|
||||
});
|
||||
|
||||
void _show_ticket() =>
|
||||
_bus.post(SparkTags.ShowOrderTicketTag, (new OrderDefinitionImmutable(order_properties_vm.create(Side.Buy)), 0d, 0u));
|
||||
void _show_ticket() {
|
||||
if (order_properties_vm != null)
|
||||
_bus.post(SparkTags.ShowOrderTicketTag, (new OrderDefinitionImmutable(order_properties_vm.create(Side.Buy)), 0d, 0u));
|
||||
}
|
||||
|
||||
void _tick() {
|
||||
_update_header();
|
||||
|
||||
@@ -5,8 +5,8 @@ using bts.utils;
|
||||
using mbts.co2;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.ui.utility.text;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
@@ -53,7 +53,7 @@ namespace mbts.spark {
|
||||
LadderVM _vm;
|
||||
LadderTactileAdorner _tactile_adorner;
|
||||
ulong _prices_updated;
|
||||
NativePriceSize[] _bids, _asks;
|
||||
NativePriceSize[] _bids = new NativePriceSize[NativePriceHelpers.COCONUT_MAX_DEPTH], _asks = new NativePriceSize[NativePriceHelpers.COCONUT_MAX_DEPTH];
|
||||
bool _price_dirty = false;
|
||||
double[] _price_list = null;
|
||||
IComparer<double> _price_comparer;
|
||||
@@ -81,6 +81,7 @@ namespace mbts.spark {
|
||||
};
|
||||
RecenterCommand = new DelegateCommand(_scroll_to_center);
|
||||
DataContextChanged += (s, e) => _connect_vm();
|
||||
IsVisibleChanged += (s, e) => _connect_vm();
|
||||
Unloaded += (s, e) => {
|
||||
Disposable.dispose(ref _settings_sub);
|
||||
Disposable.dispose(ref _tick_sub);
|
||||
@@ -192,6 +193,25 @@ namespace mbts.spark {
|
||||
set => SetValue(LastColumnWidthProperty, value);
|
||||
}
|
||||
|
||||
#region CanUserSendOrders
|
||||
public static readonly DependencyProperty CanUserSendOrdersProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(CanUserSendOrders),
|
||||
typeof(bool),
|
||||
typeof(LadderGridHost),
|
||||
new PropertyMetadata(true, (d, e) => ((LadderGridHost)d).OnCanUserSendOrdersChanged(e)));
|
||||
|
||||
public bool CanUserSendOrders {
|
||||
get => (bool)GetValue(CanUserSendOrdersProperty);
|
||||
set => SetValue(CanUserSendOrdersProperty, value);
|
||||
}
|
||||
|
||||
event Action<bool> CanUserSendOrdersChanged;
|
||||
|
||||
void OnCanUserSendOrdersChanged(DependencyPropertyChangedEventArgs e) =>
|
||||
CanUserSendOrdersChanged?.Invoke((bool)e.NewValue);
|
||||
#endregion
|
||||
|
||||
#region Command
|
||||
public ICommand Command {
|
||||
get => (ICommand)GetValue(CommandProperty);
|
||||
@@ -244,6 +264,26 @@ namespace mbts.spark {
|
||||
public void drag_out_of_bounds() =>
|
||||
_tactile_adorner?.drag_out_of_bounds();
|
||||
|
||||
public void scroll_to_price(double price) {
|
||||
if (_scrollViewer == null || _price_list.is_null_or_empty())
|
||||
return;
|
||||
if (security.ContractSpec.tickdiff(_price_list[0], price) is int target_row) {
|
||||
int visible_row_count = (int)(_scrollViewer.ActualHeight / _settings.row_height);
|
||||
int curr_row = visible_row_count + (int)(_scrollViewer.VerticalOffset / _settings.row_height);
|
||||
if ((target_row > curr_row && target_row < _row_count) || (target_row < (curr_row - visible_row_count) && target_row >= 0))
|
||||
_scroll_to_row(target_row);
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<ColumnType> subscribe_hover_column() =>
|
||||
Observable.Create<ColumnType>(o => {
|
||||
notify(Mouse.GetPosition(this));
|
||||
return this.SubscribePreviewMouseMove((s, e) => notify(e.GetPosition(this)));
|
||||
void notify(Point pt) =>
|
||||
o.OnNext(_column_for_point(pt)?.column_type ?? ColumnType.None);
|
||||
});
|
||||
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
base.OnApplyTemplate();
|
||||
_scrollViewer = this.descendants_of_type<ScrollViewer>().First();
|
||||
@@ -419,14 +459,18 @@ namespace mbts.spark {
|
||||
void _connect_vm() {
|
||||
_dispose_resources();
|
||||
_vm = DataContext as LadderVM;
|
||||
if (_vm != null) {
|
||||
if (!IsVisible)
|
||||
return;
|
||||
else if (_vm == null) {
|
||||
_clear_visuals();
|
||||
} else {
|
||||
_vm.OnDisposed += _on_vm_disposed;
|
||||
_prices_updated = 0;
|
||||
_price_comparer = Comparer<double>.Create((x, y) => security.ContractSpec.tick_equals(x, y) ? 0 : y.CompareTo(x));
|
||||
_price_dirty = true;
|
||||
_vm.on_tick += _tick;
|
||||
_settings_sub = _vm.settings.OnDispatcher().Subscribe(_settings_updated);
|
||||
_volume_sub = _vm.model.md_auxiliary_model.security_volume_at_price(security.Id).Subscribe(t => _volume_container.write_value(t.state.Values));
|
||||
_volume_sub = _vm.model.order_gateway.md_auxiliary_model.security_volume_at_price(security.Id).Subscribe(t => _volume_container.write_value(t.state.Values));
|
||||
_tick_sub = Disposable.Create(() => _vm.on_tick -= _tick);
|
||||
}
|
||||
}
|
||||
@@ -459,11 +503,21 @@ namespace mbts.spark {
|
||||
Storyboard.SetTargetProperty(anim, new PropertyPath(Behavior.AnimatedScrollViewerVerticalOffsetProperty));
|
||||
sb.Begin();
|
||||
} else {
|
||||
_scrollViewer.ScrollToVerticalOffset(_row_count * (_settings.row_height / 2) - (ActualHeight / 2));
|
||||
_scroll_to_row(_row_count / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _scroll_to_row(int row) =>
|
||||
_scrollViewer.ScrollToVerticalOffset((row * _settings.row_height) - (ActualHeight / 2));
|
||||
|
||||
IObservable<bool> _subscribe_can_send_orders() =>
|
||||
Observable.Create<bool>(o => {
|
||||
o.OnNext(CanUserSendOrders);
|
||||
CanUserSendOrdersChanged += o.OnNext;
|
||||
return Disposable.Create(() => CanUserSendOrdersChanged -= o.OnNext);
|
||||
});
|
||||
|
||||
#region Timer.Tick, Refresh Methods
|
||||
void _tick() {
|
||||
if (_settings != null) {
|
||||
@@ -636,6 +690,26 @@ namespace mbts.spark {
|
||||
_ordershost.Height = height;
|
||||
_render_grid_background();
|
||||
}
|
||||
|
||||
void _clear_visuals() {
|
||||
if (_settings == null)
|
||||
return;
|
||||
_price_list = new double[_row_count];
|
||||
for (int i = 0; i < _price_list.Length; i++)
|
||||
_price_list[i] = double.NaN;
|
||||
Array.Clear(_bids, 0, _bids.Length);
|
||||
Array.Clear(_asks, 0, _asks.Length);
|
||||
_price_dirty = true;
|
||||
LadderRender.clear_prices(_price_vis_tup.visual, _row_count, _settings.row_height, _settings.price_column, _price_vis_tup.glyph_context);
|
||||
_refresh_bid_mkt_break();
|
||||
_refresh_ask_mkt_break();
|
||||
_refresh_mid_mkt_break();
|
||||
_refresh_session_low_line();
|
||||
_refresh_session_high_line();
|
||||
_refresh_session_range();
|
||||
_refresh_last_trade();
|
||||
_refresh_sizes();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Market Break, Session Low/High Utils
|
||||
@@ -887,4 +961,4 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using bts.api.md.auxiliary;
|
||||
using mbts.co2;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -86,6 +85,16 @@ namespace mbts.spark {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void clear_prices(DrawingVisual price, int row_count, double row_height, LadderColumnSettings settings, GlyphContext glyph_context) {
|
||||
var foreground = settings.foreground.rgb_brush();
|
||||
var fprices = _format_empty_prices(row_count, row_height, settings, glyph_context);
|
||||
using (var dc = price.RenderOpen())
|
||||
using (_draw_with_clip(dc, settings, row_height, row_count)) {
|
||||
for (int x = 0; x < row_count; ++x)
|
||||
dc.DrawGlyphRun(foreground, fprices[x]);
|
||||
}
|
||||
}
|
||||
|
||||
public static double[] render_prices(DrawingVisual price, GlyphContext glyph_context, double mid, double wrt_price, bool format_in_tick_terms, int row_count, double row_height,
|
||||
LadderColumnSettings settings, ContractSpecificationImmutable spec) {
|
||||
var dprices = gen_prices(mid, row_count, spec);
|
||||
@@ -293,6 +302,12 @@ namespace mbts.spark {
|
||||
dc.DrawRectangle(new SolidColorBrush(color.rgb_color()) { Opacity = 0.2 }, null, new Rect(0, high_index * row_height, settings.width, (low_index - high_index) * row_height));
|
||||
}
|
||||
|
||||
static GlyphRun[] _format_empty_prices(int row_count, double row_height, LadderColumnSettings settings, GlyphContext glyph_context) {
|
||||
var result = new GlyphRun[row_count];
|
||||
Parallel.For(0, row_count, i => result[i] = format_text("-", i, row_height, settings, glyph_context));
|
||||
return result;
|
||||
}
|
||||
|
||||
static IDisposable _draw_with_clip(DrawingContext dc, LadderColumnSettings settings, double row_height, int row_count) {
|
||||
dc.PushClip(new RectangleGeometry(new Rect(0, 0, settings.width, row_height * row_count)));
|
||||
return Disposable.Create(dc.Pop);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
@@ -30,7 +30,7 @@ namespace mbts.spark {
|
||||
readonly LadderGridHost _host;
|
||||
readonly IList<IDisposable> _hooks;
|
||||
|
||||
bool _is_mouse_over, _is_mouse_down, _is_mouse_dragging;
|
||||
bool _is_mouse_over, _is_mouse_down, _is_mouse_dragging, _can_send_orders;
|
||||
int _curr_row;
|
||||
Column _curr_column = Column.Empty;
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace mbts.spark {
|
||||
_bid_mouse_down_pen = new Pen(new SolidColorBrush(Color.FromRgb(102, 178, 255)), 1).frozen();
|
||||
_ask_mouse_down_pen = new Pen(new SolidColorBrush(Color.FromRgb(255, 178, 102)), 1).frozen();
|
||||
_hooks = new List<IDisposable> {
|
||||
_host._subscribe_can_send_orders().Subscribe(v => {
|
||||
_can_send_orders = v;
|
||||
_host.Cursor = _evaluate_position();
|
||||
}),
|
||||
_host.SubscribeMouseEnter(_host_MouseEnter),
|
||||
_host.SubscribeMouseMove(_host_MouseMove),
|
||||
_host.SubscribeMouseLeave(_host_MouseLeave),
|
||||
@@ -88,7 +92,7 @@ namespace mbts.spark {
|
||||
_draw_cell(drawingContext, _navy_pen, x, y, _curr_column.settings.width);
|
||||
}
|
||||
}
|
||||
else if (_is_mouse_over && (_curr_column.column_type == ColumnType.Bid || _curr_column.column_type == ColumnType.Ask)) {
|
||||
else if (_is_mouse_over && _can_send_orders && (_curr_column.column_type == ColumnType.Bid || _curr_column.column_type == ColumnType.Ask)) {
|
||||
double y = _curr_row * _host._settings.row_height;
|
||||
double x = _curr_column.x_left;
|
||||
Pen style = default;
|
||||
@@ -112,12 +116,17 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
Cursor _evaluate_position() {
|
||||
var pos = Mouse.GetPosition(_host);
|
||||
return _evaluate_position(_host._column_for_point(pos), pos, _host.columns);
|
||||
}
|
||||
|
||||
Cursor _evaluate_position(Column column, Point point, Column[] columns) {
|
||||
if (columns.Length == 0)
|
||||
return Cursors.Arrow;
|
||||
switch (column.column_type) {
|
||||
case ColumnType.Bid:
|
||||
case ColumnType.Ask: return Cursors.Hand;
|
||||
case ColumnType.Ask: return _can_send_orders ? Cursors.Hand : Cursors.No;
|
||||
default: return Cursors.Arrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using mbts.ui;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
static class LadderViewHelper {
|
||||
public static readonly DragDeltaEventHandler ColumnHeaderThumb_DragDeltaHandler =
|
||||
(s, e) =>
|
||||
e.Handled =
|
||||
s is Thumb thumb &&
|
||||
thumb.try_find_ancestor_of_type(out Canvas canvas) &&
|
||||
canvas.ActualWidth + e.HorizontalChange < canvas.MinWidth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<UserControl
|
||||
x:Class="mbts.ui.spark.MiniLadderView"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
Background="{x:Static u:BTSColors.common_background_brush}"
|
||||
TextElement.FontSize="{x:Static u:FontSizes.Small}"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style TargetType="GridViewColumnHeader">
|
||||
<Setter Property="Background" Value="{u:BTSColor header}"/>
|
||||
<Setter Property="Foreground" Value="{u:BTSColor header_text}"/>
|
||||
<Setter Property="BorderBrush" Value="{u:BTSColor header_border}"/>
|
||||
<Setter Property="BorderThickness" Value="0,0,1,0"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="Height" Value="23" />
|
||||
<Setter Property="MinWidth" Value="30" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
|
||||
<Grid SnapsToDevicePixels="True">
|
||||
<Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition MaxHeight="7"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Padding="{TemplateBinding Padding}" Grid.RowSpan="2">
|
||||
<ContentPresenter x:Name="HeaderContent"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentStringFormat="{TemplateBinding ContentStringFormat}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Margin="0,0,0,1"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Canvas MinWidth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MinWidth, Mode=OneTime}">
|
||||
<Thumb x:Name="PART_HeaderGripper" DragDelta="{x:Static usp:LadderViewHelper.ColumnHeaderThumb_DragDeltaHandler}">
|
||||
<Thumb.Style>
|
||||
<Style TargetType="{x:Type Thumb}">
|
||||
<Setter Property="Canvas.Right" Value="-9"/>
|
||||
<Setter Property="Width" Value="18"/>
|
||||
<Setter Property="Height" Value="{Binding ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Thumb}">
|
||||
<Border Background="Transparent" Padding="{TemplateBinding Padding}">
|
||||
<Rectangle Fill="{TemplateBinding Background}" HorizontalAlignment="Center" Width="2"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{u:BTSColor header_text}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Thumb.Style>
|
||||
</Thumb>
|
||||
</Canvas>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
<sp:LadderGridHost
|
||||
x:Name="ladder_grid_host"
|
||||
Command="{Binding send_order_command}"
|
||||
Orders="{Binding orders}"
|
||||
orders_column_width="{Binding Settings.orders_column.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
bid_column_width="{Binding Settings.orders_column.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
price_column_width="{Binding Settings.price_column.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
ask_column_width="{Binding Settings.ask_column.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
LastColumnWidth="{Binding Settings.last_column.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
VolumeColumnWidth="{Binding Settings.volume_column.general.width, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
CanUserSendOrders="{Binding CanUserSendOrders, RelativeSource={RelativeSource AncestorType=usp:MiniLadderView}}"
|
||||
>
|
||||
<sp:LadderGridHost.Resources>
|
||||
<Style TargetType="c:Badge">
|
||||
<Setter Property="Background" Value="{Binding background}"/>
|
||||
<Setter Property="BorderBrush" Value="{Binding border}"/>
|
||||
<Setter Property="FontFamily" Value="{Binding font_family}"/>
|
||||
<Setter Property="FontSize" Value="{Binding font_size}"/>
|
||||
<Setter Property="Foreground" Value="{Binding foreground}"/>
|
||||
<Setter Property="TextLines" Value="{Binding text_lines}"/>
|
||||
<Setter Property="Width" Value="{x:Static c:Badge.DefaultWidth}"/>
|
||||
<Setter Property="IsExchangeOrder" Value="{Binding is_exchange_order}"/>
|
||||
<Setter Property="HasMultipleOrdersAtLevel" Value="{Binding has_multiple_orders_at_same_level}"/>
|
||||
<Setter Property="IsHedgeOrder" Value="{Binding is_hedge_order}"/>
|
||||
<Setter Property="ParentAlgoType" Value="{Binding parent_algo_type}"/>
|
||||
<Setter Property="ParentAlgoTypeBrush" Value="{Binding parent_algo_type_brush}"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{Binding hoverbackground}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</sp:LadderGridHost.Resources>
|
||||
</sp:LadderGridHost>
|
||||
</AdornerDecorator>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
partial class MiniLadderView : UserControl {
|
||||
public MiniLadderView() =>
|
||||
InitializeComponent();
|
||||
|
||||
#region Settings
|
||||
public static readonly DependencyProperty SettingsProperty =
|
||||
WPFHelper.create_dp<mbts.spark.LadderSettings, MiniLadderView>(nameof(Settings));
|
||||
|
||||
public mbts.spark.LadderSettings Settings {
|
||||
get => GetValue(SettingsProperty) as mbts.spark.LadderSettings;
|
||||
set => SetValue(SettingsProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CanUserSendOrders
|
||||
public static readonly DependencyProperty CanUserSendOrdersProperty =
|
||||
WPFHelper.create_dp<bool, MiniLadderView>(nameof(CanUserSendOrders));
|
||||
|
||||
public bool CanUserSendOrders {
|
||||
get => (bool)GetValue(CanUserSendOrdersProperty);
|
||||
set => SetValue(CanUserSendOrdersProperty, value);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,10 @@ using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Reactive.Linq;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class OrderBookRowVM : DisposableViewModelBase, IEquatable<OrderBookRowVM>, DIYGrid.IRowVM {
|
||||
@@ -104,6 +101,7 @@ namespace mbts.spark {
|
||||
public uint quantity => order.quantity();
|
||||
public uint filled_quantity => order.filled();
|
||||
public string last_msg => order.last_msg();
|
||||
public string filled_status_desc => order.filled_status_description(security.spec_or_default());
|
||||
// Tree
|
||||
public bool is_parent { get => _is_parent; set => Set(ref _is_parent, value); }
|
||||
public bool is_child => order.has_parent();
|
||||
@@ -185,54 +183,50 @@ namespace mbts.spark {
|
||||
|
||||
public void update(OrderSecurityAlgoMeta order_tuple) {
|
||||
Log.assert(order_tuple.order.Key == this.order.Key, "OrderBookRowVM: update_order was called with an order with the wrong key.");
|
||||
bool had_security = _security.HasValue;
|
||||
var old_order_tuple = this.order_tuple;
|
||||
// _show_order_modify_cmd is lazy (instantiated in the default_command getter); it might be null, don't not force instantiation
|
||||
bool? could_modify_execute = _show_order_modify_cmd?.CanExecute(null);
|
||||
OrderRecordImmutable old_order = old_order_tuple.order;
|
||||
var old_order_tuple = this.order_tuple;
|
||||
var dirty = ViewRefresh.get_dirty_cells(old_order_tuple, order_tuple);
|
||||
this.order_tuple = order_tuple;
|
||||
// most cells are "render-cells," which don't use databindings - the only way to update such cells is to raise the invalidated event
|
||||
bool invalidate = !(
|
||||
old_order.last_change() == order.last_change() &&
|
||||
old_order.filled() == order.filled() &&
|
||||
old_order.last_price() == order.last_price() &&
|
||||
old_order.avg_price().Equals(order.avg_price()) &&
|
||||
old_order.price().Equals(order.price()) &&
|
||||
old_order.quantity() == order.quantity() &&
|
||||
old_order.last_msg() == order.last_msg());
|
||||
// however, the order-type and security cells DO use databindings - if these cells have changed, the PropertyChanged event must be raised regardless of whether or not invalidated is raised
|
||||
if (old_order.order_type() != order.order_type())
|
||||
// order type
|
||||
if ((Columns.OrderType & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(order_type), nameof(order_metadata));
|
||||
if (old_order.quantity() != order.quantity()) {
|
||||
RaisePropertyChanged(nameof(quantity));
|
||||
RaisePropertyChanged(nameof(is_qty_dirty));
|
||||
}
|
||||
if (old_order.price() != order.price()) {
|
||||
// quantity
|
||||
if ((Columns.Size & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(quantity), nameof(is_qty_dirty));
|
||||
// price
|
||||
if ((Columns.Price & dirty) != 0) {
|
||||
RaisePropertyChanged(nameof(price));
|
||||
RaisePropertyChanged(nameof(is_price_dirty));
|
||||
}
|
||||
if (!had_security && _security.HasValue) {
|
||||
// security
|
||||
if ((Columns.Security & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(security), nameof(security_text));
|
||||
// need to raise invalidated to refresh the price cells (the security.ContractSpec determines how they are formatted - Ticks!)
|
||||
invalidate = true;
|
||||
}
|
||||
// badge fill
|
||||
if (old_order_tuple.meta?.badge_color != order_tuple.meta?.badge_color) {
|
||||
// invalidate by setting to null (will be re-instantiated in the public getter)
|
||||
_badge_fill = null;
|
||||
RaisePropertyChanged(nameof(badge_fill));
|
||||
}
|
||||
// display name
|
||||
if (old_order_tuple.display_name() != order_tuple.display_name())
|
||||
RaisePropertyChanged(nameof(display_name));
|
||||
if (old_order.status() != order.status()) {
|
||||
invalidate = true;
|
||||
// status
|
||||
if ((Columns.Status & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(status));
|
||||
}
|
||||
if (old_order.last_msg() != order.last_msg()) {
|
||||
// last message
|
||||
if ((Columns.LastMessage & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(last_msg));
|
||||
}
|
||||
// filled status desc
|
||||
if ((ViewRefresh.filled_status_desc_mask & dirty) != 0)
|
||||
RaisePropertyChanged(nameof(filled_status_desc));
|
||||
// show order modify cmd
|
||||
if (could_modify_execute.HasValue && could_modify_execute.Value != _show_order_modify_cmd.CanExecute(null))
|
||||
_show_order_modify_cmd.RaiseCanExecuteChanged();
|
||||
// always raise updated
|
||||
updated?.Invoke((old_order_tuple, order_tuple));
|
||||
if (invalidate)
|
||||
// conditionally raise invalidated
|
||||
if ((dirty & ViewRefresh.invalidate_mask) != 0)
|
||||
raise_invalidated();
|
||||
}
|
||||
|
||||
@@ -254,5 +248,52 @@ namespace mbts.spark {
|
||||
string _fmt_price(double v) => security.HasValue ?
|
||||
security.Value.ContractSpec.format(v) :
|
||||
Math.Round(v, _unknown_security_price_num_fractional_digits, MidpointRounding.AwayFromZero).ToString(_unknown_security_price_format_string);
|
||||
|
||||
static class ViewRefresh {
|
||||
public const Columns
|
||||
invalidate_mask =
|
||||
Columns.Security |
|
||||
Columns.LastChange |
|
||||
Columns.Filled |
|
||||
Columns.LastPrice |
|
||||
Columns.AvgFilled |
|
||||
Columns.Price |
|
||||
Columns.Size |
|
||||
Columns.Status |
|
||||
Columns.ParentKey |
|
||||
Columns.AttachedTargetOrderKey |
|
||||
Columns.LastMessage,
|
||||
filled_status_desc_mask =
|
||||
Columns.Filled |
|
||||
Columns.AvgFilled |
|
||||
Columns.Status;
|
||||
|
||||
public static Columns get_dirty_cells(OrderSecurityAlgoMeta oldval, OrderSecurityAlgoMeta newval) {
|
||||
var dirty = (Columns)0;
|
||||
if (oldval.security != newval.security)
|
||||
dirty |= Columns.Security;
|
||||
if (oldval.order.last_change() != newval.order.last_change())
|
||||
dirty |= Columns.LastChange;
|
||||
if (oldval.order.filled() != newval.order.filled())
|
||||
dirty |= Columns.Filled;
|
||||
if (oldval.order.last_price() != newval.order.last_price())
|
||||
dirty |= Columns.LastPrice;
|
||||
if (oldval.order.avg_price() != newval.order.avg_price())
|
||||
dirty |= Columns.AvgFilled;
|
||||
if (oldval.order.price() != newval.order.price())
|
||||
dirty |= Columns.Price;
|
||||
if (oldval.order.quantity() != newval.order.quantity())
|
||||
dirty |= Columns.Size;
|
||||
if (oldval.order.ParentKey != newval.order.ParentKey)
|
||||
dirty |= Columns.ParentKey;
|
||||
if (oldval.order.attached_target_order_key() != newval.order.attached_target_order_key())
|
||||
dirty |= Columns.AttachedTargetOrderKey;
|
||||
if (oldval.order.status() != newval.order.status())
|
||||
dirty |= Columns.Status;
|
||||
if (oldval.order.last_msg() != newval.order.last_msg())
|
||||
dirty |= Columns.LastMessage;
|
||||
return dirty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,14 @@ using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
@@ -35,23 +37,27 @@ using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
namespace mbts.spark {
|
||||
partial class OrderBookVM : DisposableViewModelBase, IHandleRowSelection, IHandleGridSorting {
|
||||
const double
|
||||
_min_visible_right_panel_width = 200,
|
||||
_min_visible_fills_slave_grid_height = 100;
|
||||
_min_right_panel_width = 200,
|
||||
_min_order_params_height = 300,
|
||||
_min_ladder_height = 100,
|
||||
_min_fills_height = 100;
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _model;
|
||||
readonly Property<OrderBookRowVM> _current_row;
|
||||
readonly Property<bool> _fills_slave_grid_is_visible;
|
||||
readonly Property<bool> _fills_slave_grid_is_visible, _show_ladder, _show_fills, _show_order_params;
|
||||
readonly OrderBookRowCollection _row_collection;
|
||||
readonly OrderBookColumnCollection _columns;
|
||||
readonly IWindowSettingsManager<OrderBookGridSettings> _settings_manager;
|
||||
readonly SelectedOrderParamsMon _selected_params_mon;
|
||||
double
|
||||
_raw_right_panel_width = OrderBookStartupData.Default.right_panel_width,
|
||||
_order_params_height = OrderBookStartupData.Default.order_params_height,
|
||||
_ladder_height = OrderBookStartupData.Default.ladder_height,
|
||||
_raw_fills_slave_grid_height = OrderBookStartupData.Default.fills_slave_grid_height;
|
||||
OrderBookStartupData _state;
|
||||
bool
|
||||
_show_right_panel = OrderBookStartupData.Default.show_right_panel,
|
||||
_is_attaching_algos,
|
||||
_is_attaching_orders,
|
||||
_is_row_collection_populated;
|
||||
|
||||
public OrderBookVM(IObservable<string> owner_title, IBus bus, INotificationService notification_service, OrdersModel model, IWindowSettingsManager<OrderBookGridSettings> settings_manager, bool rows_are_initially_expanded = false) {
|
||||
@@ -61,6 +67,9 @@ namespace mbts.spark {
|
||||
order_mod_vm = new OrderParamsVM(this, AlgoDefinitionVM.create(model, OrderDataHelper.Defaults.AlgoData(), editing_permissions: AlgoEditingPermissions.AllowEditValues));
|
||||
order_mod_vm.algo_vm.editing_permissions_mask = AlgoEditingPermissions.None;
|
||||
order_mod_vm.algo_vm.algo_root = null;
|
||||
_show_ladder = backing(nameof(show_ladder), false);
|
||||
_show_fills = backing(nameof(show_fills), false);
|
||||
_show_order_params = backing(nameof(show_order_params), false);
|
||||
attach_vm = new OrderParamsVM(this, AlgoDefinitionVM.create(_model, OrderDataHelper.Defaults.AlgoData(CustomOrderDefinition.CustomOneofCase.Iceberg), editing_permissions: AlgoEditingPermissions.AllowEditStructure | AlgoEditingPermissions.AllowEditValues));
|
||||
_fills_slave_grid_is_visible = backing(nameof(fills_slave_grid_is_visible), false);
|
||||
_settings_manager = settings_manager;
|
||||
@@ -73,13 +82,13 @@ namespace mbts.spark {
|
||||
_columns.filter_changed += on_filter_changed;
|
||||
collapse_all_rows_command = new DelegateCommand(_row_collection.collapse_all);
|
||||
expand_all_rows_command = new DelegateCommand(_row_collection.expand_all);
|
||||
var modify_selected_algos_async_cmd = new AsyncCommand(_modify_selected_algos_async, () => _selected_params_mon.all_active);
|
||||
modify_selected_algos_command = modify_selected_algos_async_cmd;
|
||||
var modify_selected_orders_async_cmd = new AsyncCommand(_modify_selected_orders_async, () => _selected_params_mon.all_active);
|
||||
modify_selected_orders_cmd = modify_selected_orders_async_cmd;
|
||||
var send_attached_orders_async_cmd = new AsyncCommand(send_attached_orders_async, () => _selected_params_mon.all_active);
|
||||
send_attached_orders_cmd = send_attached_orders_async_cmd;
|
||||
cancel_attach_orders_cmd = new DelegateCommand(() => is_attaching_algos = false);
|
||||
cancel_attach_orders_cmd = new DelegateCommand(() => is_attaching_orders = false);
|
||||
begin_attach_command = new DelegateCommand(() => begin_attach_algos(), () => selected_rows.Count > 0);
|
||||
detach_command = new DelegateCommand(() => detach_selected_algos(), () => selected_rows.Count > 0);
|
||||
detach_command = new DelegateCommand(() => detach_selected_orders(), () => selected_rows.Count > 0);
|
||||
toggle_show_right_panel_cmd = new DelegateCommand(() => show_right_panel = !show_right_panel);
|
||||
toggle_fills_slave_grid_is_visible_cmd = new DelegateCommand(() => fills_slave_grid_is_visible = !fills_slave_grid_is_visible);
|
||||
grid_settings_manager = _create_grid_settings_manager(owner_title, bus, notification_service, model, rows, core_columns);
|
||||
@@ -87,8 +96,24 @@ namespace mbts.spark {
|
||||
begin_attaching += on_begin_attaching;
|
||||
end_attaching += on_end_attaching;
|
||||
concat_disposable(
|
||||
connect_common_selected_params(order_mod_vm),
|
||||
connect_order_mod_vm(),
|
||||
_show_ladder.Subscribe(ch => {
|
||||
if (ch.newval && ladder_height < _min_ladder_height)
|
||||
ladder_height = _min_ladder_height;
|
||||
}),
|
||||
_show_order_params.Subscribe(ch => {
|
||||
if (ch.newval && order_params_height < _min_order_params_height)
|
||||
order_params_height = _min_order_params_height;
|
||||
}),
|
||||
_show_fills.Subscribe(ch => {
|
||||
if (ch.newval && fills_slave_grid_height < _min_fills_height)
|
||||
fills_slave_grid_height = _min_fills_height;
|
||||
}),
|
||||
_selected_params_mon.subscribe_all_active().Subscribe(on_all_selected_orders_active_changed),
|
||||
_selected_params_mon.subscribe_security_plurality().Subscribe(p => {
|
||||
security_plurality = p;
|
||||
RaisePropertyChanged(nameof(security_plurality));
|
||||
}),
|
||||
model.on_order_tuples.OnDispatcher().Subscribe(_row_collection.update),
|
||||
grid_settings_manager,
|
||||
order_mod_vm.algo_vm.connect_data(Observable.Return(model)),
|
||||
@@ -96,7 +121,7 @@ namespace mbts.spark {
|
||||
order_mod_vm.algo_vm,
|
||||
bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(_selected_params_mon.on_security_md_map),
|
||||
attach_vm,
|
||||
_fills_slave_grid_is_visible.observe_current(true)
|
||||
_show_fills.observe_current(true)
|
||||
.Subscribe(is_visible => fills_vm.value = is_visible ?
|
||||
new FillsVM(
|
||||
bus, model, Observable.Return(FillsWindowFactory.StartupData.Default()),
|
||||
@@ -117,22 +142,24 @@ namespace mbts.spark {
|
||||
}
|
||||
IObservable<Func<FillTuple, bool>> mk_fills_slave_predicate_src() =>
|
||||
Observable.Create<Func<FillTuple, bool>>(o => {
|
||||
return selected_rows.Observe().BufferLatest(TimeSpan.FromSeconds(0.2)).OnDispatcher().Subscribe(_ => {
|
||||
var keys = new HashSet<uint>(selected_rows.SelectMany(r => new[] { r }.Concat(_row_collection.get_descendent_rows(r))).Select(r => r.order_key));
|
||||
o.OnNext(ft => keys.Contains(ft.fill.OrderKey));
|
||||
});
|
||||
notify();
|
||||
return _subscribe_throttled_selected_rows().OnDispatcher().Subscribe(_ => notify());
|
||||
void notify() {
|
||||
var keys = new HashSet<uint>(selected_hierarchical_rows.Select(r => r.order_key));
|
||||
o.OnNext(new Func<FillTuple, bool>(ft => keys.Contains(ft.fill.OrderKey)));
|
||||
}
|
||||
});
|
||||
|
||||
void on_filter_changed() => _row_collection.filter = _columns.get_filter();
|
||||
|
||||
void on_all_selected_orders_active_changed(bool newval) {
|
||||
order_mod_vm.algo_vm.editing_permissions_mask = newval ? AlgoEditingPermissions.AllowEditValues : AlgoEditingPermissions.None;
|
||||
modify_selected_algos_async_cmd.RaiseCanExecuteChanged();
|
||||
modify_selected_orders_async_cmd.RaiseCanExecuteChanged();
|
||||
send_attached_orders_async_cmd.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
async Task send_attached_orders_async() {
|
||||
is_attaching_algos = false;
|
||||
is_attaching_orders = false;
|
||||
try {
|
||||
double price = attach_vm.price;
|
||||
uint size = attach_vm.size_calculator.value ?? 0;
|
||||
@@ -165,15 +192,13 @@ namespace mbts.spark {
|
||||
}
|
||||
void on_end_attaching() => Disposable.dispose(ref attach_vm_hooks);
|
||||
|
||||
IDisposable connect_order_mod_vm() =>
|
||||
Disposable.Create(
|
||||
_selected_params_mon.subscribe_algos().Subscribe(order_mod_vm.algo_vm.load_many),
|
||||
connect_common_selected_params(order_mod_vm));
|
||||
|
||||
IDisposable connect_common_selected_params(OrderParamsVM vm) =>
|
||||
Disposable.Create(
|
||||
_selected_params_mon.subscribe_algo().Subscribe(newval => {
|
||||
if (newval.HasValue) {
|
||||
order_mod_vm.algo_vm.load_def(newval.Value);
|
||||
} else {
|
||||
order_mod_vm.algo_vm.algo_root = null;
|
||||
}
|
||||
}),
|
||||
_selected_params_mon.subscribe_security_md().Subscribe(newval => vm.security_md = newval),
|
||||
_selected_params_mon.subscribe_price().Subscribe(newval => vm.price = newval),
|
||||
_selected_params_mon.subscribe_size().Subscribe(newval => vm.size_calculator.value = newval),
|
||||
@@ -211,17 +236,18 @@ namespace mbts.spark {
|
||||
public OrderParamsVM attach_vm { get; }
|
||||
public ObservableCollection<OrderBookRowVM> selected_rows { get; } = new ObservableCollection<OrderBookRowVM>();
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => selected_rows.Select(r => r.order);
|
||||
public IEnumerable<OrderBookRowVM> selected_hierarchical_rows => selected_rows.SelectMany(r => new[] { r }.Concat(_row_collection.get_descendent_rows(r)));
|
||||
public _GridSettingsManager grid_settings_manager { get; }
|
||||
public bool is_attaching_algos {
|
||||
get => _is_attaching_algos;
|
||||
public bool is_attaching_orders {
|
||||
get => _is_attaching_orders;
|
||||
set {
|
||||
if (Set(ref _is_attaching_algos, value))
|
||||
if (Set(ref _is_attaching_orders, value))
|
||||
(value ? begin_attaching : end_attaching)?.Invoke();
|
||||
}
|
||||
}
|
||||
public ICommand collapse_all_rows_command { get; }
|
||||
public ICommand expand_all_rows_command { get; }
|
||||
public ICommand modify_selected_algos_command { get; }
|
||||
public ICommand modify_selected_orders_cmd { get; }
|
||||
public ICommand send_attached_orders_cmd { get; }
|
||||
public ICommand cancel_attach_orders_cmd { get; }
|
||||
public ICommand begin_attach_command { get; }
|
||||
@@ -230,20 +256,38 @@ namespace mbts.spark {
|
||||
public ICommand toggle_fills_slave_grid_is_visible_cmd { get; }
|
||||
public bool show_right_panel {
|
||||
get => _show_right_panel;
|
||||
set => Set(ref _show_right_panel, value);
|
||||
set {
|
||||
if (Set(ref _show_right_panel, value) && value && !(show_order_params || show_ladder || show_fills))
|
||||
show_order_params = true;
|
||||
}
|
||||
}
|
||||
public double right_panel_width {
|
||||
get => Math.Max(_raw_right_panel_width, _min_visible_right_panel_width);
|
||||
get => Math.Max(_raw_right_panel_width, _min_right_panel_width);
|
||||
set => Set(ref _raw_right_panel_width, value);
|
||||
}
|
||||
public double order_params_height {
|
||||
get => _order_params_height;
|
||||
set => Set(ref _order_params_height, value);
|
||||
}
|
||||
public double fills_slave_grid_height {
|
||||
get => Math.Max(_raw_fills_slave_grid_height, _min_visible_fills_slave_grid_height);
|
||||
get => _raw_fills_slave_grid_height;
|
||||
set => Set(ref _raw_fills_slave_grid_height, value);
|
||||
}
|
||||
public double ladder_height {
|
||||
get => _ladder_height;
|
||||
set => Set(ref _ladder_height, value);
|
||||
}
|
||||
public bool is_row_collection_populated {
|
||||
get => _is_row_collection_populated;
|
||||
set => Set(ref _is_row_collection_populated, value);
|
||||
}
|
||||
public bool show_ladder { get => _show_ladder.Value; set => _show_ladder.set(value); }
|
||||
public bool show_fills { get => _show_fills.Value; set => _show_fills.set(value); }
|
||||
public bool show_order_params { get => _show_order_params.Value; set => _show_order_params.set(value); }
|
||||
public Plurality security_plurality { get; private set; }
|
||||
|
||||
public IObservable<bool> subscribe_show_ladder() =>
|
||||
_show_ladder.observe_current(true);
|
||||
|
||||
public void row_selection_changed(SelectionChangedEventArgs e) {
|
||||
try {
|
||||
@@ -274,16 +318,34 @@ namespace mbts.spark {
|
||||
public OrderBookStartupData create() {
|
||||
var (filters, sorting) = _columns.create();
|
||||
var gs = grid_settings_manager.create();
|
||||
return new OrderBookStartupData(filters, gs.general.with(sorting_criterion: sorting), _show_right_panel, _raw_right_panel_width, _raw_fills_slave_grid_height, fills_slave_grid_is_visible, gs.predicate_animations, use_defaults: _settings_manager.instance_settings == null);
|
||||
return new OrderBookStartupData(
|
||||
filters,
|
||||
gs.general.with(sorting_criterion: sorting),
|
||||
_show_right_panel,
|
||||
_raw_right_panel_width,
|
||||
_raw_fills_slave_grid_height,
|
||||
show_fills,
|
||||
gs.predicate_animations,
|
||||
use_defaults: _settings_manager.instance_settings == null) {
|
||||
order_params_height = order_params_height,
|
||||
show_ladder = show_ladder,
|
||||
show_order_params = show_order_params,
|
||||
ladder_height = ladder_height
|
||||
};
|
||||
}
|
||||
|
||||
public void load_from(OrderBookStartupData state) {
|
||||
if (state == null) return;
|
||||
_state = state;
|
||||
show_right_panel = state.show_right_panel;
|
||||
show_order_params = state.show_order_params;
|
||||
right_panel_width = state.right_panel_width;
|
||||
order_params_height = state.order_params_height;
|
||||
fills_slave_grid_height = state.fills_slave_grid_height;
|
||||
fills_slave_grid_is_visible = state.fills_slave_grid_is_visible;
|
||||
show_fills = state.fills_slave_grid_is_visible;
|
||||
show_ladder = state.show_ladder;
|
||||
ladder_height = state.ladder_height;
|
||||
var gs = state.grid_settings_wrapper();
|
||||
if (gs != null) {
|
||||
grid_settings_manager.load_from(gs);
|
||||
@@ -328,9 +390,9 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public void begin_attach_algos() => is_attaching_algos = true;
|
||||
public void begin_attach_algos() => is_attaching_orders = true;
|
||||
|
||||
public void detach_selected_algos() =>
|
||||
public void detach_selected_orders() =>
|
||||
_detach_orders(selected_rows
|
||||
.Where(r => r.order.can_detach())
|
||||
.Select(r => this._get_branch_root(r))
|
||||
@@ -404,7 +466,7 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
async Task _modify_selected_algos_async() {
|
||||
async Task _modify_selected_orders_async() {
|
||||
var malgo = order_mod_vm.algo_vm.algo_root?.created_assigned();
|
||||
var algo = malgo == null ? (CustomOrderDefinitionImmutable?)null : new CustomOrderDefinitionImmutable(malgo);
|
||||
double? price = DoubleHelper.nan_nullable(order_mod_vm.price);
|
||||
@@ -415,6 +477,9 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
IObservable<ObservableCollection<OrderBookRowVM>> _subscribe_throttled_selected_rows() =>
|
||||
selected_rows.Observe().BufferLatest(TimeSpan.FromSeconds(0.2)).Select(_ => selected_rows);
|
||||
|
||||
static _GridSettingsManager _create_grid_settings_manager(
|
||||
IObservable<string> owner_title, IBus bus, INotificationService notification_service, OrdersModel model, ObservableCollection<OrderBookRowVM> rows, ObservableCollection<DIYGrid.ColumnBase> columns) {
|
||||
// make font-weight immutable for all columns (the font-weight rule is hard-coded: Regular for root-orders, Light for all others)
|
||||
@@ -525,6 +590,8 @@ namespace mbts.spark {
|
||||
public class OrderParamsVM : DisposableViewModelBase {
|
||||
readonly SelectorProperty<AccountTuple, AccountTuple?> _accounts;
|
||||
readonly OrderBookVM _owner;
|
||||
HashSet<uint> _selected_order_tree = new HashSet<uint>();
|
||||
LadderVM _ladder_vm;
|
||||
SecurityMD? _security_md;
|
||||
double _price = 0;
|
||||
|
||||
@@ -549,7 +616,13 @@ namespace mbts.spark {
|
||||
Array.Empty<PropertyValidation<AccountTuple?>>());
|
||||
set_price_command = new DelegateCommand<double>(p => price = p);
|
||||
bbo = new BBOVM { security_md = security_md };
|
||||
_dispose = Disposable.Create( bbo, algo_vm);
|
||||
_dispose = new CompositeDisposable(bbo, algo_vm,
|
||||
owner._subscribe_throttled_selected_rows().OnDispatcher().Subscribe(_ => {
|
||||
_selected_order_tree = new HashSet<uint>(_owner.selected_hierarchical_rows.Select(r => r.order_key));
|
||||
_reset_ladder_vm();
|
||||
})) {
|
||||
() => Disposable.dispose(ref _ladder_vm)
|
||||
};
|
||||
}
|
||||
|
||||
public ReadOnlyObservableCollection<AccountTuple> accounts => _accounts.items;
|
||||
@@ -559,7 +632,8 @@ namespace mbts.spark {
|
||||
get => _security_md;
|
||||
set {
|
||||
if (Set(ref _security_md, value)) {
|
||||
RaisePropertyChanged(nameof(security), nameof(spec));
|
||||
_reset_ladder_vm();
|
||||
RaisePropertyChanged(nameof(security), nameof(spec), nameof(ladder_vm));
|
||||
bbo.security_md = value;
|
||||
}
|
||||
}
|
||||
@@ -568,11 +642,22 @@ namespace mbts.spark {
|
||||
public double price { get => _price; set => Set(ref _price, value); }
|
||||
public CalculatorLogic size_calculator { get; }
|
||||
public AlgoDefinitionVM algo_vm { get; }
|
||||
public LadderVM ladder_vm => _ladder_vm;
|
||||
public BBOVM bbo { get; }
|
||||
public ICommand send_order { get; }
|
||||
public ICommand set_price_command { get; }
|
||||
|
||||
OrdersModel _model => _owner._model;
|
||||
|
||||
void _reset_ladder_vm() {
|
||||
if (_ladder_vm == null && !_security_md.HasValue)
|
||||
return;
|
||||
Disposable.replace(ref _ladder_vm,
|
||||
_security_md.HasValue ?
|
||||
LadderVM.create_readonly(_owner._bus, new LadderModel(security_md.Value, _owner._model, new Func<OrderSecurity, bool>(osec => _selected_order_tree.Contains(osec.order.Key)))) :
|
||||
null);
|
||||
RaisePropertyChanged(nameof(ladder_vm));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -580,7 +665,11 @@ namespace mbts.spark {
|
||||
/// </summary>
|
||||
class SelectedOrderParamsMon {
|
||||
static readonly TimeSpan _throttle = TimeSpan.FromSeconds(0.1);
|
||||
readonly CommonValueMonitor<AlgoSecurityKey> _algo_mon = new CommonValueMonitor<AlgoSecurityKey>();
|
||||
readonly CommonValueGroupMonitor<AlgoSecurityKey, AlgoSecurityKey> _algo_def_mon =
|
||||
new CommonValueGroupMonitor<AlgoSecurityKey, AlgoSecurityKey>(
|
||||
ask => ask,
|
||||
EqualityComparer<AlgoSecurityKey>.Default,
|
||||
EqualityComparer.Create<AlgoSecurityKey, CustomOrderDefinitionImmutable>(ask => ask.algo, OrderDataHelper.EqualsHelpers.custom_order_def_compareri));
|
||||
readonly CommonValueMonitor<SecurityImmutable?> _spreader_security_mon = new CommonValueMonitor<SecurityImmutable?>();
|
||||
readonly CommonValueMonitor<SecurityImmutable?> _security_mon = new CommonValueMonitor<SecurityImmutable?>();
|
||||
readonly CommonValueMonitor<double> _price_mon = new CommonValueMonitor<double>(double.NaN);
|
||||
@@ -593,7 +682,7 @@ namespace mbts.spark {
|
||||
|
||||
public SelectedOrderParamsMon(DynamicOrderHelper dyn_helper) {
|
||||
_dyn_helper = dyn_helper;
|
||||
_group_mon.add_member_mon(_algo_mon, _algo_key);
|
||||
_group_mon.add_member_mon(_algo_def_mon, _algo_key);
|
||||
_group_mon.add_member_mon(_spreader_security_mon, _get_spreader_sec, s => s.HasValue);
|
||||
_group_mon.add_member_mon(_security_mon, osam => osam.security, s => s.HasValue);
|
||||
_group_mon.add_member_mon(_price_mon, osam => osam.order.price());
|
||||
@@ -604,7 +693,6 @@ namespace mbts.spark {
|
||||
|
||||
event Action _security_md_map_changed;
|
||||
|
||||
public CustomOrderDefinitionImmutable? algo => _algo_mon.common_value_nullable()?.algo;
|
||||
public SecurityImmutable? security => _security_mon.common_value;
|
||||
public SecurityMD? security_md => security is SecurityImmutable sec && _security_md_map.TryGetValue(sec.Id, out SecurityMD smd) ? smd : (SecurityMD?)null;
|
||||
public SecurityImmutable? spreader_security => _spreader_security_mon.common_value;
|
||||
@@ -613,7 +701,7 @@ namespace mbts.spark {
|
||||
public AccountTuple? account => _account_mon.common_value_nullable();
|
||||
public bool all_active => _all_active_mon.common_value;
|
||||
|
||||
public IObservable<CustomOrderDefinitionImmutable?> subscribe_algo() => _algo_mon.SubscribeThrottledNullable(_throttle).Select(ask => ask.HasValue ? ask.Value.algo: (CustomOrderDefinitionImmutable?)null);
|
||||
public IObservable<IEnumerable<CustomOrderDefinitionImmutable>> subscribe_algos() => _algo_def_mon.SubscribeThrottled(_throttle, (ask, vals) => vals.Select(v => v.algo), Enumerable.Empty<CustomOrderDefinitionImmutable>());
|
||||
public IObservable<SecurityImmutable?> subscribe_spreader_security() => _spreader_security_mon.SubscribeThrottled(_throttle);
|
||||
public IObservable<SecurityImmutable?> subscribe_security() => _security_mon.SubscribeThrottled(_throttle);
|
||||
public IObservable<SecurityMD?> subscribe_security_md() =>
|
||||
@@ -637,6 +725,7 @@ namespace mbts.spark {
|
||||
public IObservable<uint?> subscribe_size() => _size_mon.SubscribeThrottledNullable(_throttle);
|
||||
public IObservable<AccountTuple?> subscribe_account() => _account_mon.SubscribeThrottledNullable(_throttle);
|
||||
public IObservable<bool> subscribe_all_active() => _all_active_mon.SubscribeThrottled(_throttle);
|
||||
public IObservable<Plurality> subscribe_security_plurality() => _security_mon.SubscribePluralityThrottled(_throttle);
|
||||
|
||||
public IDisposable begin_udpate() =>
|
||||
_group_mon.defer_updates();
|
||||
@@ -657,8 +746,10 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
void _on_row_updated((OrderSecurityAlgoMeta oldval, OrderSecurityAlgoMeta newval) ch) {
|
||||
_group_mon.remove(ch.oldval);
|
||||
_group_mon.add(ch.newval);
|
||||
using (begin_udpate()) {
|
||||
_group_mon.remove(ch.oldval);
|
||||
_group_mon.add(ch.newval);
|
||||
}
|
||||
}
|
||||
|
||||
static SecurityImmutable? _get_spreader_sec(OrderSecurityAlgoMeta osam) =>
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace mbts.spark {
|
||||
var detach_selected_orders_command = new SparkCommandCommand(
|
||||
"Detach And Cancel Selected Orders",
|
||||
Icons.DetachAlgos,
|
||||
new DelegateCommand(_vm.detach_selected_algos, () => _vm.selected_rows.Count > 0),
|
||||
new DelegateCommand(_vm.detach_selected_orders, () => _vm.selected_rows.Count > 0),
|
||||
new KeyGesture(Key.D, ModifierKeys.Control | ModifierKeys.Shift));
|
||||
|
||||
var toggle_collapse_all_command = new SparkCommandCommand("Collapse All",
|
||||
@@ -209,7 +209,7 @@ namespace mbts.spark {
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
Disposable.replace(ref _attachment_exit_sub, parent_view.SubscribePreviewKeyDown((s, e) => {
|
||||
if (e.Key == Key.Escape || (e.Key == Key.Z && KeyboardExtensions.IsCtrlDown()))
|
||||
_vm.is_attaching_algos = false;
|
||||
_vm.is_attaching_orders = false;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -50,10 +50,14 @@ namespace bts.shell {
|
||||
|
||||
[ProtoContract]
|
||||
public class OrderBookStartupData {
|
||||
const bool _default_show_right_panel = true;
|
||||
const bool
|
||||
_default_show_right_panel = true,
|
||||
_default_show_order_params = true;
|
||||
const double
|
||||
_default_right_panel_width = 400,
|
||||
_default_fills_slave_grid_height = 138;
|
||||
_default_order_params_height = 250,
|
||||
_default_fills_slave_grid_height = 300,
|
||||
_default_ladder_height = 350;
|
||||
// ALREADY USED TAGS
|
||||
// [ProtoMember(5)]
|
||||
// public readonly List<SortingCriteria> sort_criteria;
|
||||
@@ -73,6 +77,14 @@ namespace bts.shell {
|
||||
[ProtoMember(17)]
|
||||
[DefaultValue(_default_right_panel_width)]
|
||||
public double right_panel_width { get; set; }
|
||||
// show order params
|
||||
[ProtoMember(23)]
|
||||
[DefaultValue(_default_show_order_params)]
|
||||
public bool show_order_params { get; set; }
|
||||
// order params height
|
||||
[ProtoMember(24)]
|
||||
[DefaultValue(_default_order_params_height)]
|
||||
public double order_params_height { get; set; }
|
||||
// fills slave grid height
|
||||
[ProtoMember(18)]
|
||||
[DefaultValue(_default_fills_slave_grid_height)]
|
||||
@@ -80,6 +92,13 @@ namespace bts.shell {
|
||||
// fills slave grid is visible
|
||||
[ProtoMember(19)]
|
||||
public bool fills_slave_grid_is_visible { get; set; }
|
||||
// ladder height
|
||||
[ProtoMember(21)]
|
||||
[DefaultValue(_default_ladder_height)]
|
||||
public double ladder_height { get; set; }
|
||||
// show ladder
|
||||
[ProtoMember(22)]
|
||||
public bool show_ladder { get; set; }
|
||||
// predicate animations
|
||||
[ProtoMember(20)]
|
||||
[Obsolete]
|
||||
@@ -90,8 +109,11 @@ namespace bts.shell {
|
||||
|
||||
public OrderBookStartupData() {
|
||||
show_right_panel = _default_show_right_panel;
|
||||
show_order_params = _default_show_order_params;
|
||||
right_panel_width = _default_right_panel_width;
|
||||
order_params_height = _default_order_params_height;
|
||||
fills_slave_grid_height = _default_fills_slave_grid_height;
|
||||
ladder_height = _default_ladder_height;
|
||||
}
|
||||
|
||||
public OrderBookStartupData(FilterStates filters, GridSettings grid = default, bool show_right_panel = false, double right_panel_width = 0, double fills_slave_grid_height = 0, bool fills_slave_grid_is_visible = false, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null, bool use_defaults = false) {
|
||||
@@ -122,7 +144,10 @@ namespace bts.shell {
|
||||
_default_show_right_panel,
|
||||
_default_right_panel_width,
|
||||
_default_fills_slave_grid_height,
|
||||
use_defaults: true);
|
||||
use_defaults: true) {
|
||||
show_order_params = _default_show_order_params,
|
||||
order_params_height = _default_order_params_height
|
||||
};
|
||||
|
||||
public static OrderBookGridSettings DefaultGrid => new OrderBookGridSettings(_default_general_grid);
|
||||
|
||||
|
||||
@@ -13,33 +13,33 @@ namespace mbts.spark {
|
||||
// IMPORTANT: these enums are stored as strings in the general-purpose GridColumnSettings proto, and are used to ID THE COLUMNS!
|
||||
// Do NOT RENAME them! However, if you must, be sure to write an IShellWindowMigrationRule or something to account for backwards compatability.
|
||||
public enum ColumnKeys {
|
||||
Security,
|
||||
Symbol,
|
||||
Time,
|
||||
LastChange,
|
||||
User,
|
||||
Account,
|
||||
Exchange,
|
||||
TimeInForce,
|
||||
OrderType,
|
||||
SubType,
|
||||
Side,
|
||||
Size,
|
||||
Price,
|
||||
Filled,
|
||||
AvgFilled,
|
||||
LastPrice,
|
||||
Status,
|
||||
LastMessage,
|
||||
SecurityKey,
|
||||
OrderKey,
|
||||
ParentKey,
|
||||
AttachedTargetOrderKey,
|
||||
Cancel,
|
||||
EditableQty,
|
||||
EditablePrice,
|
||||
Attach,
|
||||
Detach
|
||||
Security = 1,
|
||||
Symbol = 1 << 1,
|
||||
Time = 1 << 2,
|
||||
LastChange = 1 << 3,
|
||||
User = 1 << 4,
|
||||
Account = 1 << 5,
|
||||
Exchange = 1 << 6,
|
||||
TimeInForce = 1 << 7,
|
||||
OrderType = 1 << 8,
|
||||
SubType = 1 << 9,
|
||||
Side = 1 << 10,
|
||||
Size = 1 << 11,
|
||||
Price = 1 << 12,
|
||||
Filled = 1 << 13,
|
||||
AvgFilled = 1 << 14,
|
||||
LastPrice = 1 << 15,
|
||||
Status = 1 << 16,
|
||||
LastMessage = 1 << 17,
|
||||
SecurityKey = 1 << 18,
|
||||
OrderKey = 1 << 19,
|
||||
ParentKey = 1 << 20,
|
||||
AttachedTargetOrderKey = 1 << 21,
|
||||
Cancel = 1 << 22,
|
||||
EditableQty = 1 << 23,
|
||||
EditablePrice = 1 << 24,
|
||||
Attach = 1 << 25,
|
||||
Detach = 1 << 26
|
||||
}
|
||||
|
||||
public OrderBookGridView() =>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
x:Name="Root"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:api="clr-namespace:bts.api;assembly=spark_api"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
@@ -21,9 +22,18 @@
|
||||
<ResourceDictionary Source="/Modules/Trading/OrderBook/View/OrderParamsPanel.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="GridSplitterWidth">5</sys:Double>
|
||||
<sys:Double x:Key="FillsSlaveGridMinHeight">64</sys:Double>
|
||||
<SolidColorBrush x:Key="AlgoAttachmentBackground" Color="#55009500"/>
|
||||
<cv:GridLengthConverter x:Key="GridLengthPixelConverter" UnitType="Pixel"/>
|
||||
<cv:GridLengthConverter x:Key="GridLengthStarConverter" UnitType="Star"/>
|
||||
<cv:IntSubtractionConverter x:Key="MinusOneConverter" Value="1"/>
|
||||
<cv:ValueConverterPipe x:Key="SelectedOrdersAndOthersSuffixVisibilityConverter">
|
||||
<cv:IntGreaterThanConverter Value="1"/>
|
||||
<BooleanToVisibilityConverter/>
|
||||
</cv:ValueConverterPipe>
|
||||
<cv:ValueMap x:Key="SideToBrushConverter" Default="{u:Brush Black}">
|
||||
<cv:KeyValue Key="{u:Enum Buy, Type=api:Side}" Value="{x:Static bid_brush, MemberType={u:Nested u:BTSColors.MarketData}}"/>
|
||||
<cv:KeyValue Key="{u:Enum Sell, Type=api:Side}" Value="{x:Static ask_brush, MemberType={u:Nested u:BTSColors.MarketData}}"/>
|
||||
</cv:ValueMap>
|
||||
<Style TargetType="GridSplitter">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
@@ -32,6 +42,83 @@
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="RightPanel.MenuItem" TargetType="MenuItem">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="BorderThickness" Value="1,0"/>
|
||||
<Setter Property="Padding" Value="4,1,5,1"/>
|
||||
<Setter Property="IsCheckable" Value="True"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="MenuItem">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="CheckMark" VerticalAlignment="Bottom" Height="9.5" Margin="0,0,0,3" Visibility="Hidden">
|
||||
<Image.Source>
|
||||
<DrawingImage>
|
||||
<DrawingImage.Drawing>
|
||||
<GeometryDrawing Brush="Black" Geometry="{Binding Source={StaticResource {x:Static u:Icons.CheckMarkGeometryKey}}}"/>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<Image Grid.Column="1" Margin="{DynamicResource IconPadding}" Source="{TemplateBinding Icon}"/>
|
||||
<ContentPresenter
|
||||
Grid.Column="2"
|
||||
TextElement.FontWeight="SemiBold"
|
||||
Margin="4,0,0,0"
|
||||
ContentSource="Header"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
<Condition Property="IsMouseOver" Value="False"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Visibility" Value="Visible" TargetName="CheckMark"/>
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsChecked" Value="False"/>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" Value="#200080FF"/>
|
||||
<Setter Property="BorderBrush" Value="#90006CD9"/>
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Visibility" Value="Visible" TargetName="CheckMark"/>
|
||||
<Setter Property="Background" Value="#400080FF"/>
|
||||
<Setter Property="BorderBrush" Value="#90006CD9"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="BorderBrush" Value="#FF006CD9"/>
|
||||
<Setter Property="Background" Value="#800080FF"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="{x:Static usp:OrderParamsPanel.BestBidPriceButtonStyleKey}" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
|
||||
<Setter Property="ToolTip">
|
||||
<Setter.Value>
|
||||
@@ -76,6 +163,25 @@
|
||||
<Setter Property="Command" Value="{Binding DataContext.size_calculator.click, RelativeSource={RelativeSource AncestorType=usp:OrderParamsPanel}}"/>
|
||||
<Setter Property="CommandParameter" Value="{Binding}"/>
|
||||
</Style>
|
||||
<DataTemplate x:Key="OrderDescriptionTemplate">
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="{Binding security, Mode=OneWay}" FontWeight="Bold"/>
|
||||
<Run Text="{Binding side, Mode=OneWay}" Foreground="{Binding side, Converter={StaticResource SideToBrushConverter}}"/>
|
||||
<Run Text="{Binding quantity, Mode=OneWay}"/>
|
||||
<Run>@</Run>
|
||||
<Run>
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price" Mode="OneWay"/>
|
||||
<Binding Path="security.ContractSpec" Mode="OneWay"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Text="{Binding filled_status_desc, Mode=OneWay, StringFormat='({0})'}"/>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
@@ -89,15 +195,15 @@
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.RightPanel}}">
|
||||
<!--Normal State-->
|
||||
<VisualState Name="{x:Static Normal, MemberType={u:Nested sp:OrderBookView.VisualStateNames.RightPanel}}"/>
|
||||
<!--Modify Orders State-->
|
||||
<VisualState Name="{x:Static ModifyOrders, MemberType={u:Nested sp:OrderBookView.VisualStateNames.RightPanel}}">
|
||||
<!--Right Panel Closed-->
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested sp:OrderBookView.VisualStateNames.RightPanel}}"/>
|
||||
<!--Right Panel Open-->
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested sp:OrderBookView.VisualStateNames.RightPanel}}">
|
||||
<Storyboard>
|
||||
<!--Orders Grid-->
|
||||
<Int32Animation Storyboard.TargetName="orders_grid" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<!--Right Panel-->
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="right_panel_host" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="right_panel_content_root" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="right_panel_width_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
@@ -135,99 +241,239 @@
|
||||
BorderThickness="1,0,0,0"
|
||||
Visibility="Collapsed"
|
||||
/>
|
||||
<Grid x:Name="right_panel_host" Grid.Column="1" Visibility="Collapsed">
|
||||
<Grid x:Name="right_panel_content_root" Grid.Column="1" Visibility="Collapsed">
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager Target="{Binding Source={u:DirectReference right_panel_content_root}}">
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition>
|
||||
<MultiBinding Converter="{x:Static sp:OrderBookView.SlaveDataVisualStateConverter}">
|
||||
<Binding Path="DataContext.show_order_params" Source="{u:DirectReference right_panel_content_root}"/>
|
||||
<Binding Path="DataContext.show_fills" Source="{u:DirectReference right_panel_content_root}"/>
|
||||
<Binding Path="DataContext.show_ladder" Source="{u:DirectReference right_panel_content_root}"/>
|
||||
</MultiBinding>
|
||||
</u:StateDefinition>
|
||||
<u:StateDefinition State="{Binding DataContext.security_plurality, Source={u:DirectReference right_panel_content_root}, Converter={x:Static sp:OrderBookView.LadderVisualStateConverter}}"/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<VisualState Name="{x:Static None, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static OrderParams, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(Grid.RowSpan)" To="5" Duration="0" BeginTime="0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static OrderParamsLadder, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="ladder" Storyboard.TargetProperty="(Grid.RowSpan)" To="4" Duration="0" BeginTime="0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static OrderParamsFills, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<Int32Animation Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(Grid.Row)" To="4" Duration="0" BeginTime="0"/>
|
||||
<Int32Animation Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(Grid.RowSpan)" To="3" Duration="0" BeginTime="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static OrderParamsLadderFills, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}"/>
|
||||
<VisualState Name="{x:Static Ladder, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="ladder" Storyboard.TargetProperty="(Grid.Row)" To="2" Duration="0" BeginTime="0"/>
|
||||
<Int32Animation Storyboard.TargetName="ladder" Storyboard.TargetProperty="(Grid.RowSpan)" To="5" Duration="0" BeginTime="0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static LadderFills, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="ladder" Storyboard.TargetProperty="(Grid.Row)" To="2" Duration="0" BeginTime="0"/>
|
||||
<Int32Animation Storyboard.TargetName="ladder" Storyboard.TargetProperty="(Grid.RowSpan)" To="3" Duration="0" BeginTime="0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static Fills, MemberType={u:Nested sp:OrderBookView.VisualStateNames.SlaveData}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(Grid.Row)" To="2" Duration="0" BeginTime="0"/>
|
||||
<Int32Animation Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(Grid.RowSpan)" To="5" Duration="0" BeginTime="0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.Ladder}}">
|
||||
<VisualState Name="{x:Static OneSecuritySelected, MemberType={u:Nested sp:OrderBookView.VisualStateNames.Ladder}}"/>
|
||||
<VisualState Name="{x:Static NoSecuritySelected, MemberType={u:Nested sp:OrderBookView.VisualStateNames.Ladder}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(FrameworkElement.ToolTip)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="No Orders Selected (select orders in the grid)"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static ManySecuritiesSelected, MemberType={u:Nested sp:OrderBookView.VisualStateNames.Ladder}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ladder" Storyboard.TargetProperty="(FrameworkElement.ToolTip)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="Multiple Securities Selected (select orders with a common security)"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource GridSplitterWidth}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding order_params_height, Converter={StaticResource GridLengthStarConverter}, Mode=TwoWay}"/>
|
||||
<RowDefinition Height="5" MaxHeight="5"/>
|
||||
<RowDefinition Height="{Binding ladder_height, Converter={StaticResource GridLengthStarConverter}, Mode=TwoWay}"/>
|
||||
<RowDefinition Height="5" MaxHeight="5"/>
|
||||
<RowDefinition Height="{Binding fills_slave_grid_height, Converter={StaticResource GridLengthStarConverter}, Mode=TwoWay}"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid x:Name="right_panel_content_root">
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager Target="{Binding Source={u:DirectReference right_panel_content_root}}">
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition State="{Binding DataContext.fills_slave_grid_is_visible, Source={u:DirectReference right_panel_content_root}, Converter={x:Static sp:OrderBookView.FillsSlaveGridStateConverter}}"/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<Menu Grid.Column="1" HorizontalAlignment="Stretch" Height="26" Background="LightGray" BorderBrush="DarkGray" BorderThickness="1" ItemContainerStyle="{StaticResource RightPanel.MenuItem}">
|
||||
<MenuItem Header="Params" IsChecked="{Binding show_order_params}" Icon="{x:Static u:Icons.ModifyOrder}" ToolTip="Show Order/Algo Parameters for Selected Orders">
|
||||
<MenuItem.Resources>
|
||||
<Thickness x:Key="IconPadding" Left="2" Top="3" Bottom="2"/>
|
||||
</MenuItem.Resources>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Ladder" IsChecked="{Binding show_ladder}" Icon="{x:Static u:Icons.Ladder}" ToolTip="Show Selected Orders in Ladder">
|
||||
<MenuItem.Resources>
|
||||
<Thickness x:Key="IconPadding" Left="2" Top="3" Bottom="2"/>
|
||||
</MenuItem.Resources>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Fills" IsChecked="{Binding show_fills}" Icon="{x:Static u:Icons.Payment}" ToolTip="Show Fills for Selected Orders">
|
||||
<MenuItem.Resources>
|
||||
<Thickness x:Key="IconPadding" Left="2" Top="4.5" Bottom="4.5"/>
|
||||
</MenuItem.Resources>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" u:StateManager.VisualState="{Binding current_row, Converter={x:Static sp:OrderBookView.OrderDescriptionVisualStateConverter}}" Orientation="Vertical">
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.FillsPanel}}">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested sp:OrderBookView.VisualStateNames.FillsPanel}}">
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested sp:OrderBookView.VisualStateNames.OrderDescription}}">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested sp:OrderBookView.VisualStateNames.OrderDescription}}"/>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested sp:OrderBookView.VisualStateNames.OrderDescription}}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_grid" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="no_rows_selected_text_block" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="fills_order_params_splitter" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="current_row_description_content_control" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="order_description_root" Storyboard.TargetProperty="(FrameworkElement.ToolTip)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="Select orders in the grid to view corresponding details/parameters below."/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<Int32AnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(Grid.Row)">
|
||||
<DiscreteInt32KeyFrame KeyTime="0" Value="2"/>
|
||||
</Int32AnimationUsingKeyFrames>
|
||||
<Int32AnimationUsingKeyFrames Storyboard.TargetName="order_params_group_box" Storyboard.TargetProperty="(Grid.RowSpan)">
|
||||
<DiscreteInt32KeyFrame KeyTime="0" Value="1"/>
|
||||
</Int32AnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested sp:OrderBookView.VisualStateNames.FillsPanel}}"/>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource GridSplitterWidth}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition MinHeight="{StaticResource FillsSlaveGridMinHeight}" Height="{Binding fills_slave_grid_height, Converter={StaticResource GridLengthPixelConverter}, Mode=TwoWay}" MaxHeight="{Binding ActualHeight, ElementName=right_panel_content_root, Converter={x:Static sp:OrderBookView.FillsSlaveGridMaxHeightConverter}}"/>
|
||||
<RowDefinition MinHeight="{x:Static sp:OrderBookView.GridSplitterHeight}" Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="fills_toggle_hyperlink" Grid.Column="1">
|
||||
<TextBlock.Margin>
|
||||
<Thickness Left="{StaticResource DialogSkirtPadding.Left}" Top="4"/>
|
||||
</TextBlock.Margin>
|
||||
<Hyperlink KeyboardNavigation.IsTabStop="False" Command="{Binding toggle_fills_slave_grid_is_visible_cmd}">
|
||||
<Hyperlink.Inlines>
|
||||
<Run Text="{Binding current_row, Converter={x:Static sp:OrderBookView.OrderDescriptionConverter}, Mode=OneWay}"/>
|
||||
</Hyperlink.Inlines>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<c:DIYGrid x:Name="fills_grid" Grid.Column="1" Grid.Row="1" Columns="{Binding fills_vm.columns}" Rows="{Binding fills_vm.rows}" Visibility="Collapsed">
|
||||
<c:DIYGrid.Margin>
|
||||
<Thickness Bottom="{x:Static sp:OrderBookView.GridSplitterHeight}"/>
|
||||
</c:DIYGrid.Margin>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<usp:FillsRowView/>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
<GridSplitter
|
||||
x:Name="fills_order_params_splitter"
|
||||
Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Panel.ZIndex="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="{x:Static sp:OrderBookView.GridSplitterHeight}"
|
||||
BorderThickness="0,1,0,0"
|
||||
Visibility="Collapsed"
|
||||
/>
|
||||
<GroupBox
|
||||
x:Name="order_params_group_box"
|
||||
Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Padding="12"
|
||||
BorderThickness="1"
|
||||
HorizontalAlignment="Left"
|
||||
Header="Order Parameters"
|
||||
HeaderTemplate="{StaticResource BoldHeaderTemplate}"
|
||||
>
|
||||
<StackPanel.Margin>
|
||||
<Thickness Left="{StaticResource DialogSkirtPadding.Left}" Top="4"/>
|
||||
</StackPanel.Margin>
|
||||
<StackPanel x:Name="order_description_root" Margin="0,5,0,1" Orientation="Horizontal">
|
||||
<StackPanel.ToolTip>
|
||||
<ItemsControl ItemsSource="{Binding DataContext.selected_rows, Source={u:DirectReference right_panel_content_root}}" ItemTemplate="{StaticResource OrderDescriptionTemplate}"/>
|
||||
</StackPanel.ToolTip>
|
||||
<ContentControl x:Name="current_row_description_content_control" Content="{Binding current_row}" ContentTemplate="{StaticResource OrderDescriptionTemplate}" Visibility="Visible"/>
|
||||
<TextBlock x:Name="no_rows_selected_text_block" Visibility="Collapsed">
|
||||
(No orders are selected)
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
Margin="3,0,0,0"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding selected_rows.Count, Converter={StaticResource SelectedOrdersAndOthersSuffixVisibilityConverter}}"
|
||||
VerticalAlignment="Top"
|
||||
Text="{Binding selected_rows.Count, Converter={StaticResource MinusOneConverter}, Mode=OneWay, StringFormat='and {0} others...'}"
|
||||
/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Border
|
||||
x:Name="order_params_group_box"
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Grid.RowSpan="2"
|
||||
Padding="12,12,12,6"
|
||||
HorizontalAlignment="Left"
|
||||
>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:OrderParamsPanel
|
||||
x:Name="order_params_panel"
|
||||
DataContext="{Binding order_mod_vm}"
|
||||
Price="{Binding price}"
|
||||
Size="{Binding size_calculator.value}"
|
||||
Accounts="{Binding accounts}"
|
||||
SelectedAccount="{Binding selected_account}"
|
||||
ShowAccount="False"
|
||||
ShowTimeInForce="False"
|
||||
BestBidPrice="{Binding bbo.bid}"
|
||||
BestBidSize="{Binding bbo.bid_size}"
|
||||
BestAskPrice="{Binding bbo.ask}"
|
||||
@@ -241,34 +487,55 @@
|
||||
<CommandBinding Command="{x:Static usp:OrderParamsPanel.SetPriceCommand}" Executed="{x:Static usp:OrderParamsPanel.SetPriceExecuted}"/>
|
||||
</usp:OrderParamsPanel.CommandBindings>
|
||||
</usp:OrderParamsPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
<Canvas Grid.Row="1" HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=order_params_group_box}" Height="30">
|
||||
<Button
|
||||
x:Name="modify_orders_button"
|
||||
Canvas.Top="{StaticResource DialogSkirtPadding.Top}"
|
||||
Command="{Binding modify_selected_algos_command}"
|
||||
>
|
||||
<Canvas.Left>
|
||||
<MultiBinding Converter="{x:Static sp:OrderBookView.RightPanelDialogSkirtLeftAnchorConverter}">
|
||||
<Binding Path="Width" RelativeSource="{RelativeSource AncestorType=Canvas}"/>
|
||||
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
|
||||
</MultiBinding>
|
||||
</Canvas.Left>
|
||||
<TextBlock>
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="{Binding selected_rows.Count, StringFormat='Modify Orders ({0})'}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsEnabled, RelativeSource={RelativeSource AncestorType=Button}}" Value="False">
|
||||
<Setter Property="Text" Value="Modify Orders"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
</Canvas>
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Margin="0,8,0,0">
|
||||
<Button x:Name="modify_orders_button" Command="{Binding modify_selected_orders_cmd}" ToolTip="Modify selected orders with the parameters above.">
|
||||
<TextBlock>
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="{Binding selected_rows.Count, StringFormat='Modify Orders ({0})'}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsEnabled, RelativeSource={RelativeSource AncestorType=Button}}" Value="False">
|
||||
<Setter Property="Text" Value="Modify Orders"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<!--TODO: Add Revert Button-->
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
<GridSplitter
|
||||
x:Name="order_params_splitter"
|
||||
Grid.Column="1"
|
||||
Grid.Row="3"
|
||||
Panel.ZIndex="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Height="{x:Static sp:OrderBookView.GridSplitterHeight}"
|
||||
BorderThickness="0,1,0,0"
|
||||
ResizeBehavior="PreviousAndNext"
|
||||
/>
|
||||
<usp:MiniLadderView x:Name="ladder" Grid.Column="1" Grid.Row="4" DataContext="{Binding order_mod_vm.ladder_vm}" CanUserSendOrders="False" Settings="{x:Static sp:LadderSettings.Default}"/>
|
||||
<GridSplitter
|
||||
x:Name="ladder_splitter"
|
||||
Grid.Column="1"
|
||||
Grid.Row="5"
|
||||
Panel.ZIndex="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Height="{x:Static sp:OrderBookView.GridSplitterHeight}"
|
||||
BorderThickness="0,1,0,0"
|
||||
ResizeBehavior="PreviousAndNext"
|
||||
/>
|
||||
<c:DIYGrid x:Name="fills_grid" Grid.Column="1" Grid.Row="6" Columns="{Binding fills_vm.columns}" Rows="{Binding fills_vm.rows}">
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<usp:FillsRowView/>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</Grid>
|
||||
<StatusBar Grid.Row="1" DockPanel.Dock="Bottom">
|
||||
<StatusBarItem HorizontalAlignment="Right">
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.controls.adorners;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using OrderParamsVM = mbts.spark.OrderBookVM.OrderParamsVM;
|
||||
|
||||
@@ -18,29 +22,58 @@ namespace mbts.spark {
|
||||
internal partial class OrderBookView : UserControl {
|
||||
public const double
|
||||
GridSplitterWidth = 5,
|
||||
GridSplitterHeight = 5,
|
||||
MinAlgoEditorHeight = 64,
|
||||
MinAttachOrderParamsPanelWidth = 340,
|
||||
AttachOrderParamsPanelWidthRatio = 0.33;
|
||||
GridSplitterHeight = 5;
|
||||
|
||||
public static readonly IValueConverter
|
||||
OrderDescriptionConverter = ValueConverter.create<OrderBookRowVM, string>(row => row == null ? string.Empty : row.order.short_description(row.security)),
|
||||
RightPanelVisualStateConverter = ValueConverter.create<bool, string>(is_modifying => is_modifying ? VisualStateNames.RightPanel.ModifyOrders : VisualStateNames.RightPanel.Normal),
|
||||
FillsSlaveGridMaxHeightConverter = ValueConverter.create<double, double>(right_panel_height => right_panel_height - (GridSplitterHeight + MinAlgoEditorHeight)),
|
||||
FillsPanelVisualStateConverter = ValueConverter.create<bool, string>(show => show ? VisualStateNames.FillsPanel.Active : VisualStateNames.FillsPanel.Inactive),
|
||||
FillsSlaveGridStateConverter = ValueConverter.create<bool, string>(is_fills_grid_visible => is_fills_grid_visible ? VisualStateNames.FillsPanel.Active : VisualStateNames.FillsPanel.Inactive),
|
||||
AttachmentTargetCursorConverter = ValueConverter.create<bool, Cursor>(is_active => is_active ? Cursors.Pen : Cursors.Arrow);
|
||||
RightPanelVisualStateConverter = ValueConverter.create<bool, string>(show_panel => show_panel ? VisualStateNames.RightPanel.Active : VisualStateNames.RightPanel.Inactive),
|
||||
OrderDescriptionVisualStateConverter = ValueConverter.create<OrderBookRowVM, string>(row => row != null ? VisualStateNames.OrderDescription.Active : VisualStateNames.OrderDescription.Inactive),
|
||||
LadderVisualStateConverter = ValueConverter.create<Plurality, string>(security_plurality => {
|
||||
switch (security_plurality) {
|
||||
case Plurality.None: return VisualStateNames.Ladder.NoSecuritySelected;
|
||||
case Plurality.One: return VisualStateNames.Ladder.OneSecuritySelected;
|
||||
case Plurality.Many: return VisualStateNames.Ladder.ManySecuritiesSelected;
|
||||
default: return null;
|
||||
}
|
||||
});
|
||||
|
||||
public static readonly IMultiValueConverter
|
||||
RightPanelDialogSkirtLeftAnchorConverter = ValueConverter.create<double, double, double>((canvas_width, skirt_width) => canvas_width - skirt_width + GridSplitterWidth);
|
||||
RightPanelDialogSkirtLeftAnchorConverter = ValueConverter.create<double, double, double>((canvas_width, skirt_width) => canvas_width - skirt_width + GridSplitterWidth),
|
||||
SlaveDataVisualStateConverter = ValueConverter.create<bool, bool, bool, string>(
|
||||
(show_order_params, show_fills, show_ladder) => {
|
||||
VisualStateNames.SlaveData.Data d = (VisualStateNames.SlaveData.Data)0;
|
||||
if (show_order_params)
|
||||
d |= VisualStateNames.SlaveData.Data.OrderParams;
|
||||
if (show_fills)
|
||||
d |= VisualStateNames.SlaveData.Data.Fills;
|
||||
if (show_ladder)
|
||||
d |= VisualStateNames.SlaveData.Data.Ladder;
|
||||
return VisualStateNames.SlaveData.fmt_name(d);
|
||||
});
|
||||
|
||||
IDisposable _attach_op;
|
||||
|
||||
public OrderBookView(OrderBookVM vm) {
|
||||
InitializeComponent();
|
||||
DataContext = vm;
|
||||
// 'send attach orders' behavior
|
||||
vm.begin_attaching += begin_attach_orders;
|
||||
vm.end_attaching += () => Disposable.dispose(ref _attach_op);
|
||||
// 'scroll to current order' behavior (mini ladder)
|
||||
vm.SubscribeDisposed(vm.subscribe_show_ladder().SubscribeHookLatest(show => show ? connect_mini_ladder_auto_scroll() : null));
|
||||
IDisposable connect_mini_ladder_auto_scroll() {
|
||||
bool is_busy = false;
|
||||
vm.selected_order_changed += on_selected_order_changed;
|
||||
return Disposable.Create(() => vm.selected_order_changed -= on_selected_order_changed);
|
||||
async void on_selected_order_changed(OrderRecordImmutable? order) {
|
||||
if (order.HasValue && !is_busy) {
|
||||
is_busy = true;
|
||||
await Task.Delay(200);
|
||||
if (vm.current_order.HasValue && vm.current_order.Value.security_key() == ladder.ladder_grid_host.security.Id && vm.current_order.Value.is_active())
|
||||
ladder.ladder_grid_host.scroll_to_price(vm.current_order.Value.price());
|
||||
is_busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new OrderBookVM DataContext {
|
||||
@@ -55,7 +88,11 @@ namespace mbts.spark {
|
||||
var attach_orders_view = new OrderParamsPanel {
|
||||
DataContext = vm,
|
||||
Margin = new Thickness(6),
|
||||
ShowAlgoTypeNodes = true
|
||||
CanUserChangeAlgoRoot = true,
|
||||
ShowAccount = false,
|
||||
ShowTimeInForce = false,
|
||||
ShowCalculatorButtons = false,
|
||||
ShowBBO = false
|
||||
};
|
||||
attach_orders_view.SetBinding(OrderParamsPanel.PriceProperty, new Binding(nameof(OrderParamsVM.price)) { Source = vm });
|
||||
attach_orders_view.SetBinding(OrderParamsPanel.SizeProperty, new Binding($"{nameof(CalculatorLogic.value)}") { Source = vm.size_calculator });
|
||||
@@ -95,7 +132,8 @@ namespace mbts.spark {
|
||||
VerticalPosition.Middle,
|
||||
0,
|
||||
orders_grid.RowHeight) {
|
||||
OpenRelativeToMouse = true
|
||||
OpenRelativeToMouse = true,
|
||||
ClipToBounds = true
|
||||
};
|
||||
popup_adorner.attach();
|
||||
popup_adorner.IsOpen = true;
|
||||
@@ -107,7 +145,7 @@ namespace mbts.spark {
|
||||
() => {
|
||||
popup_adorner.IsOpen = false;
|
||||
popup_adorner.detach();
|
||||
DataContext.is_attaching_algos = false;
|
||||
DataContext.is_attaching_orders = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -117,17 +155,51 @@ namespace mbts.spark {
|
||||
public const string GroupName = nameof(RightPanel);
|
||||
|
||||
public static readonly string
|
||||
Normal = $"{GroupName}{nameof(Normal)}",
|
||||
ModifyOrders = $"{GroupName}{nameof(ModifyOrders)}";
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
|
||||
public static class FillsPanel {
|
||||
public const string GroupName = nameof(FillsPanel);
|
||||
public static class OrderDescription {
|
||||
public const string GroupName = nameof(OrderDescription);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
|
||||
public static class Ladder {
|
||||
public const string GroupName = nameof(Ladder);
|
||||
|
||||
public static readonly string
|
||||
NoSecuritySelected = $"{GroupName}{nameof(NoSecuritySelected)}",
|
||||
OneSecuritySelected = $"{GroupName}{nameof(OneSecuritySelected)}",
|
||||
ManySecuritiesSelected = $"{GroupName}{nameof(ManySecuritiesSelected)}";
|
||||
}
|
||||
|
||||
public static class SlaveData {
|
||||
public const string GroupName = nameof(SlaveData);
|
||||
|
||||
public static readonly string
|
||||
None = $"{GroupName}{nameof(None)}",
|
||||
OrderParams = $"{GroupName}{nameof(OrderParams)}",
|
||||
OrderParamsLadder = $"{GroupName}{nameof(OrderParamsLadder)}",
|
||||
OrderParamsFills = $"{GroupName}{nameof(OrderParamsFills)}",
|
||||
OrderParamsLadderFills = $"{GroupName}{nameof(OrderParamsLadderFills)}",
|
||||
LadderFills = $"{GroupName}{nameof(LadderFills)}",
|
||||
Ladder = $"{GroupName}{nameof(Ladder)}",
|
||||
Fills = $"{GroupName}{nameof(Fills)}";
|
||||
|
||||
public enum Data {
|
||||
OrderParams = 1,
|
||||
Ladder = 1 << 1,
|
||||
Fills = 1 << 2
|
||||
}
|
||||
|
||||
public static string fmt_name(Data d) {
|
||||
var vis_data = string.Join("", EnumHelper.split_flags(d));
|
||||
return vis_data == string.Empty ? None : GroupName + vis_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:order="clr-namespace:bts.api.orderman;assembly=spark_api"
|
||||
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:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
>
|
||||
<cv:MultiValueConverterPipe x:Key="CalculatorButtonsVisualStateConverter">
|
||||
<cv:BooleanNoneConverter/>
|
||||
<cv:ValueMap Default="{x:Static Normal, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.CalculatorButtons}}">
|
||||
<cv:KeyValue Key="{u:True}" Value="{x:Static Stretched, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.CalculatorButtons}}"/>
|
||||
</cv:ValueMap>
|
||||
</cv:MultiValueConverterPipe>
|
||||
|
||||
<cv:MultiValueConverterPipe x:Key="CalculatorButtonsColumnsConverter">
|
||||
<cv:BooleanNoneConverter/>
|
||||
<cv:ValueMap Default="{u:Int 3}">
|
||||
<cv:KeyValue Key="{u:True}" Value="{u:Int 6}"/>
|
||||
</cv:ValueMap>
|
||||
</cv:MultiValueConverterPipe>
|
||||
|
||||
<ControlTemplate x:Key="OrderParamsPanelTemplate" TargetType="usp:OrderParamsPanel">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
@@ -17,6 +29,64 @@
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
>
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager AttachToMembers="True">
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition State="{Binding Path='(u:StateDefinition.Group).(u:StateGroupsManager.Target).(Border.TemplatedParent).(usp:OrderParamsPanel.ShowBBO)', RelativeSource={RelativeSource Self}, Converter={x:Static usp:OrderParamsPanel.BBOVisualStateConverter}}"/>
|
||||
<u:StateDefinition>
|
||||
<MultiBinding Converter="{StaticResource CalculatorButtonsVisualStateConverter}">
|
||||
<Binding Path="(u:StateDefinition.Group).(u:StateGroupsManager.Target).(Border.TemplatedParent).(usp:OrderParamsPanel.ShowAccount)" RelativeSource="{RelativeSource Self}"/>
|
||||
<Binding Path="(u:StateDefinition.Group).(u:StateGroupsManager.Target).(Border.TemplatedParent).(usp:OrderParamsPanel.ShowTimeInForce)" RelativeSource="{RelativeSource Self}"/>
|
||||
</MultiBinding>
|
||||
</u:StateDefinition>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.BBO}}">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.BBO}}"/>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.BBO}}">
|
||||
<Storyboard>
|
||||
<!--Price-->
|
||||
<Int32Animation Storyboard.TargetName="price_entry_control" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="price_entry_control" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="5"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="price_entry_control" Storyboard.TargetProperty="(Control.Margin)" BeginTime="0" Duration="0" To="40,0,0,0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="price_label" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--Size-->
|
||||
<Int32Animation Storyboard.TargetName="size_tick_up_down" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="size_tick_up_down" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="5"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="size_tick_up_down" Storyboard.TargetProperty="(Control.Margin)" BeginTime="0" Duration="0" To="40,0,0,0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="size_label" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--BBO Buttons-->
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="best_bid_button" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="best_bid_size_button" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="best_ask_button" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="best_ask_size_button" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.CalculatorButtons}}">
|
||||
<VisualState Name="{x:Static Normal, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.CalculatorButtons}}"/>
|
||||
<VisualState Name="{x:Static Stretched, MemberType={u:Nested usp:OrderParamsPanel.VisualStateNames.CalculatorButtons}}">
|
||||
<Storyboard>
|
||||
<Int32Animation Storyboard.TargetName="calculator_buttons_items_control" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="calculator_buttons_items_control" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="5"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -30,10 +100,16 @@
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush1}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush2}}"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush1}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock x:Name="price_label" Margin="8,0,0,0" Text="Price" Visibility="Collapsed"/>
|
||||
<usp:PriceEntryControl
|
||||
x:Name="price_entry_control"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ContractSpec="{Binding ContractSpec, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Value="{Binding Price, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
|
||||
ToolTip="Price"
|
||||
@@ -75,7 +151,7 @@
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush1}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush2}}"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush1}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -84,7 +160,8 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:TickUpDownNullableUInt Value="{Binding Size, RelativeSource={RelativeSource TemplatedParent}}" ToolTip="Size"/>
|
||||
<TextBlock x:Name="size_label" Margin="8,0,0,0" Text="Size" Visibility="Collapsed"/>
|
||||
<c:TickUpDownNullableUInt x:Name="size_tick_up_down" Value="{Binding Size, RelativeSource={RelativeSource TemplatedParent}}" ToolTip="Size"/>
|
||||
<Button
|
||||
x:Name="best_bid_size_button"
|
||||
Grid.Column="2"
|
||||
@@ -102,22 +179,30 @@
|
||||
Style="{DynamicResource {x:Static usp:OrderParamsPanel.BestAskSizeButtonStyleKey}}"
|
||||
/>
|
||||
<ItemsControl
|
||||
x:Name="calculator_buttons_items_control"
|
||||
Grid.Row="2"
|
||||
Grid.RowSpan="2"
|
||||
Margin="-2,-2,-2,0"
|
||||
Margin="-4,-4,0,0"
|
||||
ItemsSource="{Binding SizePresets, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
IsTabStop="False"
|
||||
>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="3" Focusable="False"/>
|
||||
<UniformGrid Focusable="False">
|
||||
<UniformGrid.Columns>
|
||||
<MultiBinding Converter="{StaticResource CalculatorButtonsColumnsConverter}">
|
||||
<Binding Path="ShowAccount" RelativeSource="{RelativeSource AncestorType=usp:OrderParamsPanel}"/>
|
||||
<Binding Path="ShowTimeInForce" RelativeSource="{RelativeSource AncestorType=usp:OrderParamsPanel}"/>
|
||||
</MultiBinding>
|
||||
</UniformGrid.Columns>
|
||||
</UniformGrid>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="2,4,2,0"
|
||||
Margin="4,4,0,0"
|
||||
Content="{Binding}"
|
||||
Style="{DynamicResource {x:Static usp:OrderParamsPanel.SizeCalculatorButtonStyleKey}}"
|
||||
/>
|
||||
@@ -129,8 +214,14 @@
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ComboBox Margin="0,2,0,4" ItemsSource="{Binding Accounts, RelativeSource={RelativeSource TemplatedParent}}" SelectedItem="{Binding SelectedAccount, RelativeSource={RelativeSource TemplatedParent}}" ToolTip="Choose Account"/>
|
||||
<ComboBox Grid.Row="1">
|
||||
<ComboBox
|
||||
x:Name="account_combo_box"
|
||||
Margin="0,2,0,4"
|
||||
ItemsSource="{Binding Accounts, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding SelectedAccount, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ToolTip="Choose Account"
|
||||
/>
|
||||
<ComboBox x:Name="time_in_force_combo_box" Grid.Row="1">
|
||||
<ComboBox.Style>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource DisabledPlaceholderComboBox}">
|
||||
<Setter Property="ItemsSource">
|
||||
@@ -145,9 +236,26 @@
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<usp:AlgoEditorGridView x:Name="algo_editor" Grid.Row="4" AlgoVM="{Binding AlgoVM, RelativeSource={RelativeSource TemplatedParent}}" ShowAlgoTypeNodes="{TemplateBinding ShowAlgoTypeNodes}"/>
|
||||
<usp:AlgoEditorGridView
|
||||
x:Name="algo_editor"
|
||||
Grid.Row="4"
|
||||
AlgoVM="{Binding AlgoVM, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
CanUserChangeAlgoRoot="{TemplateBinding CanUserChangeAlgoRoot}"
|
||||
ShowAlgoTypeNodes="{TemplateBinding ShowAlgoTypeNodes}"
|
||||
/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="ShowAccount" Value="False">
|
||||
<Setter TargetName="account_combo_box" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ShowTimeInForce" Value="False">
|
||||
<Setter TargetName="time_in_force_combo_box" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ShowCalculatorButtons" Value="False">
|
||||
<Setter TargetName="calculator_buttons_items_control" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="usp:OrderParamsPanel">
|
||||
@@ -156,4 +264,4 @@
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Template" Value="{StaticResource OrderParamsPanelTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -1,10 +1,12 @@
|
||||
using bts.api;
|
||||
using mbts.spark;
|
||||
using mbts.ui.converters;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
@@ -28,6 +30,9 @@ namespace mbts.ui.spark {
|
||||
SetPriceCanExecute = (s, e) => e.CanExecute = e.Parameter is double,
|
||||
SetSizeCanExecute = (s, e) => e.CanExecute = e.Parameter is uint;
|
||||
|
||||
public static readonly IValueConverter BBOVisualStateConverter =
|
||||
ValueConverter.create<bool, string>(show_bbo => show_bbo ? VisualStateNames.BBO.Active : VisualStateNames.BBO.Inactive);
|
||||
|
||||
static OrderParamsPanel() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderParamsPanel), new FrameworkPropertyMetadata(typeof(OrderParamsPanel)));
|
||||
}
|
||||
@@ -102,6 +107,46 @@ namespace mbts.ui.spark {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowBBO
|
||||
public static readonly DependencyProperty ShowBBOProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(ShowBBO), true);
|
||||
|
||||
public bool ShowBBO {
|
||||
get => (bool)GetValue(ShowBBOProperty);
|
||||
set => SetValue(ShowBBOProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowCalculatorButtons
|
||||
public static readonly DependencyProperty ShowCalculatorButtonsProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(ShowCalculatorButtons), true);
|
||||
|
||||
public bool ShowCalculatorButtons {
|
||||
get => (bool)GetValue(ShowCalculatorButtonsProperty);
|
||||
set => SetValue(ShowCalculatorButtonsProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowTimeInForce
|
||||
public static readonly DependencyProperty ShowTimeInForceProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(ShowTimeInForce), true);
|
||||
|
||||
public bool ShowTimeInForce {
|
||||
get => (bool)GetValue(ShowTimeInForceProperty);
|
||||
set => SetValue(ShowTimeInForceProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowAccount
|
||||
public static readonly DependencyProperty ShowAccountProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(ShowAccount), true);
|
||||
|
||||
public bool ShowAccount {
|
||||
get => (bool)GetValue(ShowAccountProperty);
|
||||
set => SetValue(ShowAccountProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Accounts
|
||||
public static readonly DependencyProperty AccountsProperty =
|
||||
WPFHelper.create_dp<IEnumerable, OrderParamsPanel>(nameof(Accounts), Enumerable.Empty<string>());
|
||||
@@ -179,6 +224,16 @@ namespace mbts.ui.spark {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CanUserChangeAlgoRoot
|
||||
public static readonly DependencyProperty CanUserChangeAlgoRootProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(CanUserChangeAlgoRoot));
|
||||
|
||||
public bool CanUserChangeAlgoRoot {
|
||||
get => (bool)GetValue(CanUserChangeAlgoRootProperty);
|
||||
set => SetValue(CanUserChangeAlgoRootProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ShowAlgoTypeNodes
|
||||
public static readonly DependencyProperty ShowAlgoTypeNodesProperty =
|
||||
WPFHelper.create_dp<bool, OrderParamsPanel>(nameof(ShowAlgoTypeNodes));
|
||||
@@ -194,5 +249,23 @@ namespace mbts.ui.spark {
|
||||
_algo_editor = GetTemplateChild("algo_editor") as AlgoEditorView;
|
||||
_algo_editor?.SetCurrentValue(VisibilityProperty, AlgoVM != null ? Visibility.Visible : Visibility.Collapsed);
|
||||
}
|
||||
|
||||
public static class VisualStateNames {
|
||||
public static class BBO {
|
||||
public const string GroupName = nameof(BBO);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
|
||||
public static class CalculatorButtons {
|
||||
public const string GroupName = nameof(CalculatorButtons);
|
||||
|
||||
public static readonly string
|
||||
Normal = $"{GroupName}{nameof(Normal)}",
|
||||
Stretched = $"{GroupName}{nameof(Stretched)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using bts.api;
|
||||
using bts.api.md.auxiliary;
|
||||
using bts.spark;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
@@ -22,8 +21,8 @@ namespace bts.shell {
|
||||
|
||||
[ImportingConstructor]
|
||||
public TradingShellModule(IBus bus, IWindowManager wm, INotificationService notification_service, INotificationServiceDataCache notification_service_data_cache,
|
||||
UserSettingsHub settings_hub, OrdersModel orders_model, PAndLModel pandl_model, MarketDataAuxiliaryModel md_auxiliary_model, ErrorReporter error_reporter) {
|
||||
_lwf = new LadderWindowFactory(this, bus, wm, settings_hub, orders_model, md_auxiliary_model);
|
||||
UserSettingsHub settings_hub, OrdersModel orders_model, PAndLModel pandl_model, ErrorReporter error_reporter) {
|
||||
_lwf = new LadderWindowFactory(this, bus, wm, settings_hub, orders_model);
|
||||
_obwf = new OrderBookWindowFactory(this, bus, notification_service, notification_service_data_cache, orders_model, settings_hub);
|
||||
_fwf = new FillsWindowFactory(this, bus, settings_hub, orders_model);
|
||||
_plwf = new PAndLWindowFactory(this, bus, settings_hub, pandl_model);
|
||||
|
||||
@@ -5,6 +5,7 @@ using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
@@ -52,6 +53,7 @@ namespace mbts.spark {
|
||||
public void assign_to(AlgoDef value) => value.MergeFrom(definition.CloneToMutable());
|
||||
public bool key_match(KeyEventArgs e) => false;
|
||||
public void load_from(AlgoDefi value) => impl?.load_from(value);
|
||||
public void load_many(IEnumerable<AlgoDefi> values) => impl?.load_many(values);
|
||||
public Task<AlgoDefi?> load_from_async(AlgoDefi definition) =>
|
||||
impl?.load_from_async(definition) ?? Task.FromResult<AlgoDefi?>(definition);
|
||||
|
||||
|
||||
@@ -77,5 +77,15 @@ namespace mbts.spark {
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
internal static string get_enumerated_value(DynamicOrderParam param) => param?.AsEnumerated?.EnumValue;
|
||||
internal static void set_enumerated_value(DynamicOrderParam param, string value) {
|
||||
if (param == null) {
|
||||
return;
|
||||
} else if (param.ValueCase != DynamicOrderParam.ValueOneofCase.AsEnumerated) {
|
||||
param.AsEnumerated = new DynamicOrderEnumerated();
|
||||
}
|
||||
param.AsEnumerated.EnumValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,30 +41,13 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
protected abstract void on_param_changed();
|
||||
|
||||
public static DynamicOrderParamVM create(DynamicOrderParamDescriptor descriptor) {
|
||||
ExceptionAssert.Argument.NotNull(descriptor, nameof(descriptor));
|
||||
switch (descriptor.ParamType.DescriptorCase) {
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Primitive:
|
||||
switch (descriptor.ParamType.Primitive) {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveBool: return new DynamicOrderParamVM<bool>(descriptor, DynamicOrderParam.AsBoolFieldNumber);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveDouble: return new DynamicOrderParamVM<double>(descriptor, DynamicOrderParam.AsDoubleFieldNumber);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveInt: return new DynamicOrderParamVM<uint>(descriptor, DynamicOrderParam.AsInt32FieldNumber);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveUint: return new DynamicOrderParamVM<uint>(descriptor, DynamicOrderParam.AsUint32FieldNumber);
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: return new DynamicOrderParamVM<string>(descriptor, DynamicOrderParam.AsStringFieldNumber);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.Primitive, nameof(descriptor));
|
||||
}
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Enumerated: return new DynamicOrderEnumeratedVM(descriptor);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.DescriptorCase, nameof(descriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DynamicOrderParamVM<T> : DynamicOrderParamVM, IDynamicOrderParamVM<T> {
|
||||
readonly FieldDescriptor _field_desc;
|
||||
|
||||
public DynamicOrderParamVM(DynamicOrderParamDescriptor descriptor, int field_number) : base(descriptor) =>
|
||||
_field_desc = DynamicOrderParam.Descriptor.FindFieldByNumber(field_number);
|
||||
public DynamicOrderParamVM(DynamicOrderParamDescriptor descriptor, FieldDescriptor field_descriptor) : base(descriptor) =>
|
||||
_field_desc = field_descriptor;
|
||||
|
||||
public T value {
|
||||
get => ConvertUtils.try_convert<T>(_field_desc.Accessor.GetValue(param));
|
||||
@@ -95,17 +78,12 @@ namespace mbts.spark {
|
||||
public ObservableCollection<string> elements { get; }
|
||||
|
||||
public string selected_element {
|
||||
get => param?.ValueCase == DynamicOrderParam.ValueOneofCase.AsEnumerated ? param.AsEnumerated.EnumValue : null;
|
||||
get => DynamicOrderHelper.get_enumerated_value(param);
|
||||
set {
|
||||
if (param == null) {
|
||||
param = new DynamicOrderParam { AsEnumerated = new DynamicOrderEnumerated() };
|
||||
} else if (param.ValueCase != DynamicOrderParam.ValueOneofCase.AsEnumerated) {
|
||||
param.AsEnumerated = new DynamicOrderEnumerated();
|
||||
}
|
||||
if (param.AsEnumerated.EnumValue != value) {
|
||||
param.AsEnumerated.EnumValue = value;
|
||||
var orig = selected_element;
|
||||
DynamicOrderHelper.set_enumerated_value(param, value);
|
||||
if (selected_element != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
string IDynamicOrderParamVM<string>.value { get => selected_element; set => selected_element = value; }
|
||||
|
||||
@@ -73,21 +73,27 @@ namespace mbts.spark {
|
||||
case DynamicOrderPrimitiveDescriptor.DynamicOrderPrimitiveString: return mk<string>(DynamicOrderParam.AsStringFieldNumber);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.Primitive, nameof(descriptor));
|
||||
}
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Enumerated: return attached<string, DynamicOrderEnumeratedVM>(new DynamicOrderEnumeratedVM(descriptor));
|
||||
case DynamicOrderTypeDescriptor.DescriptorOneofCase.Enumerated:
|
||||
var pvm = new DynamicOrderEnumeratedVM(descriptor);
|
||||
attached(pvm, DynamicOrderHelper.get_enumerated_value, DynamicOrderHelper.set_enumerated_value);
|
||||
return pvm;
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(descriptor.ParamType.DescriptorCase, nameof(descriptor));
|
||||
}
|
||||
|
||||
DynamicOrderParamVM<T> mk<T>(int field_number) =>
|
||||
attached<T, DynamicOrderParamVM<T>>(new DynamicOrderParamVM<T>(descriptor, field_number));
|
||||
DynamicOrderParamVM<T> mk<T>(int field_number) {
|
||||
var fdesc = DynamicOrderParam.Descriptor.FindFieldByNumber(field_number);
|
||||
var pvm = new DynamicOrderParamVM<T>(descriptor, fdesc);
|
||||
return attached<T, DynamicOrderParamVM<T>>(pvm, get_from_param, assign_to_param);
|
||||
|
||||
TParam attached<T, TParam>(TParam pvm) where TParam : DynamicOrderParamVM, IDynamicOrderParamVM<T> {
|
||||
add_property(
|
||||
T get_from_param(DynamicOrderParam param) => ConvertUtils.try_convert<T>(fdesc.Accessor.GetValue(param));
|
||||
void assign_to_param(DynamicOrderParam param, T value) => fdesc.Accessor.SetValue(param, value);
|
||||
}
|
||||
|
||||
TParam attached<T, TParam>(TParam pvm, Func<DynamicOrderParam, T> selector, Action<DynamicOrderParam, T> assign_to_param) where TParam : DynamicOrderParamVM, IDynamicOrderParamVM<T> {
|
||||
add_property<T>(
|
||||
pvm.descriptor.ParamName,
|
||||
mdef => mdef.OrderParams[pvm.descriptor.ParamName] = pvm.param,
|
||||
mdef => {
|
||||
if (mdef.OrderParams.TryGetValue(pvm.descriptor.ParamName, out DynamicOrderParam p))
|
||||
pvm.param = p;
|
||||
},
|
||||
mdef => mdef.OrderParams.TryGetValue(pvm.descriptor.ParamName, out DynamicOrderParam p) ? selector(p) : default,
|
||||
(mdef, v) => assign_to_param(mdef.OrderParams.GetOrAdd(pvm.descriptor.ParamName, pn => new DynamicOrderParam()), v),
|
||||
() => pvm.value,
|
||||
v => pvm.value = v,
|
||||
pvm.subscribe_value());
|
||||
@@ -96,4 +102,4 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace mbts.spark {
|
||||
dynamic children_vm { get; }
|
||||
bool key_match(KeyEventArgs e);
|
||||
Task<CustomOrderDefinitionImmutable?> load_from_async(CustomOrderDefinitionImmutable definition);
|
||||
void load_many(IEnumerable<CustomOrderDefinitionImmutable> definitions);
|
||||
}
|
||||
|
||||
interface IDynamicAlgoVMImpl {
|
||||
|
||||
@@ -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,23 +7,23 @@ 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<uint> _max_chase_ticks;
|
||||
readonly Property<LeanDef.Types.OnToward> _trade_toward_behavior;
|
||||
readonly Property<QuantityMeasureImmutable?> _cross_threshold;
|
||||
readonly Property<uint?> _max_chase_ticks;
|
||||
readonly Property<LeanDef.Types.OnToward?> _trade_toward_behavior;
|
||||
|
||||
public LeanOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
: base(key, display_name, editing_permissions) {
|
||||
_trade_toward_behavior = add_property(nameof(trade_toward_behavior), LeanDef.TradeTowardBehaviorFieldNumber, LeanDef.Types.OnToward.NoChange);
|
||||
_trade_toward_behavior = add_nullable_property(nameof(trade_toward_behavior), LeanDef.TradeTowardBehaviorFieldNumber, LeanDef.Types.OnToward.NoChange);
|
||||
_cross_threshold = add_property<QuantityMeasure, QuantityMeasureImmutable>(nameof(cross_threshold), LeanDef.CrossThresholdFieldNumber, new QuantityMeasureImmutable(new QuantityMeasure { Ratio = 1.0, Absolute = 1 }));
|
||||
_max_chase_ticks = add_property(nameof(max_chase_ticks), LeanDef.MaxChaseTicksFieldNumber, 2u);
|
||||
_max_chase_ticks = add_nullable_property(nameof(max_chase_ticks), LeanDef.MaxChaseTicksFieldNumber, 2u);
|
||||
}
|
||||
|
||||
// trade toward behavior
|
||||
public LeanDef.Types.OnToward trade_toward_behavior { get => _trade_toward_behavior.Value; set => _trade_toward_behavior.set(value); }
|
||||
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 uint max_chase_ticks { get => _max_chase_ticks.Value; set => _max_chase_ticks.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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,6 +259,68 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public void load_many(IEnumerable<AlgoDefi> values) {
|
||||
var value_list = values as IList<AlgoDefi> ?? values.ToList();
|
||||
switch (value_list.Count) {
|
||||
case 0: return;
|
||||
case 1:
|
||||
// **do not remove this case (as of 04/04/2019, some code below assumes that value_list has more than 1 element)
|
||||
load_from(value_list[0]);
|
||||
return;
|
||||
}
|
||||
var algos = value_list.Select(value => _descriptor.Accessor.GetValue(value.CloneToMutable()) as TMutable ?? new TMutable()).ToList();
|
||||
var security_src = Observable.Create<SecurityImmutable?>(o => {
|
||||
o.OnNext(security);
|
||||
_security_changed += o.OnNext;
|
||||
return Disposable.Create(() => _security_changed -= o.OnNext);
|
||||
});
|
||||
Disposable.replace(ref _pending_load,
|
||||
Disposable.Create(
|
||||
ObservableAutoWrapper.connect_item_hooks(
|
||||
_child_algo_selector_data.AsCollection(),
|
||||
sd => security_src.Subscribe(_ => ObservableAutoWrapper.connect_item_actions(_child_algo_selector_data.AsCollection(), selector_load_impl))),
|
||||
ObservableAutoWrapper.connect_item_actions(_auto_props.AsCollection(), p => p.load_many(algos))));
|
||||
|
||||
void selector_load_impl(AlgoSelectorData sd) {
|
||||
// **assume that algos has more than 1 element
|
||||
var child_list = new List<AlgoDefi>(2);
|
||||
var init = sd.get_from_impl(algos[0]);
|
||||
if (!init.HasValue) {
|
||||
// this method loads common values, if any child is null, there is no common value (i.e., the common value is null)
|
||||
return;
|
||||
}
|
||||
AlgoKey key;
|
||||
if (security.HasValue) {
|
||||
init = OrderDataHelper.fit_to_type(init.Value, security.Value.ContractCase);
|
||||
if (!init.HasValue)
|
||||
return;
|
||||
key = OrderDataHelper.get_shallow_factory_key(init.Value);
|
||||
child_list.Add(init.Value);
|
||||
for (int i = 1; i < algos.Count; i++) {
|
||||
var child = sd.get_from_impl(algos[i]);
|
||||
if (!child.HasValue || key != OrderDataHelper.get_shallow_factory_key(child.Value))
|
||||
return;
|
||||
child = OrderDataHelper.fit_to_type(child.Value, security.Value.ContractCase);
|
||||
if (!child.HasValue)
|
||||
return;
|
||||
child_list.Add(child.Value);
|
||||
}
|
||||
} else {
|
||||
key = OrderDataHelper.get_shallow_factory_key(init.Value);
|
||||
child_list.Add(init.Value);
|
||||
for (int i = 1; i < algos.Count; i++) {
|
||||
var child = sd.get_from_impl(algos[i]);
|
||||
if (!child.HasValue || key != OrderDataHelper.get_shallow_factory_key(child.Value))
|
||||
return;
|
||||
child_list.Add(child.Value);
|
||||
}
|
||||
}
|
||||
var vm = sd.selector.algos.GetOrAdd(key, k => create(k, init.Value.display_name(), init.Value.CustomCase, is_expanded: is_expanded));
|
||||
vm.load_many(child_list);
|
||||
sd.selector.selected_algo = vm;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Task on_load_from_async(AlgoDefi defi) => Task.CompletedTask;
|
||||
|
||||
protected void raise_definition_changed() =>
|
||||
@@ -276,7 +338,10 @@ namespace mbts.spark {
|
||||
protected void sync_selectors() {
|
||||
using (reset()) {
|
||||
foreach (var c in get_selector_datum()) {
|
||||
_children_vm[c.name] = mk_selector(c.name, new Func<AlgoDefi, AlgoDefi?>(defi => {
|
||||
_children_vm[c.name] = mk_selector(c.name, msg => {
|
||||
var mchild = c.get_child_from_impl(msg);
|
||||
return mchild != null ? new AlgoDefi(mchild) : (AlgoDefi?)null;
|
||||
}, new Func<AlgoDefi, AlgoDefi?>(defi => {
|
||||
var mchild = c.get_child(defi.CloneToMutable());
|
||||
if (mchild != null)
|
||||
return new AlgoDefi(mchild);
|
||||
@@ -309,7 +374,7 @@ namespace mbts.spark {
|
||||
_child_algo_selector_data.Remove(id);
|
||||
});
|
||||
}
|
||||
IAlgoSelector mk_selector(string prop_name, Func<AlgoDefi, AlgoDefi?> get_order, Action<AlgoDef, AlgoDef> set_order) {
|
||||
IAlgoSelector mk_selector(string prop_name, Func<IMessage, AlgoDefi?> get_from_impl, Func<AlgoDefi, AlgoDefi?> get_order, Action<AlgoDef, AlgoDef> set_order) {
|
||||
string prop_display_name = DisplayNameHelper.snake_to_title_case(prop_name);
|
||||
var rv = new AlgoSelector(prop_name, prop_display_name);
|
||||
var child_params = new ObservableAggregateCollection<IAlgoParamVM>();
|
||||
@@ -324,7 +389,7 @@ namespace mbts.spark {
|
||||
}
|
||||
}),
|
||||
param.as_demuxer().subscribe<IAlgoVM>(nameof(IAlgoParamVM.value)).Subscribe(child_vm => rv.selected_algo = child_vm));
|
||||
_child_algo_selector_data[prop_name] = new AlgoSelectorData(prop_name, rv, get_order, set_order, hook);
|
||||
_child_algo_selector_data[prop_name] = new AlgoSelectorData(prop_name, rv, get_from_impl, get_order, set_order, hook);
|
||||
_child_algo_params.Add(param);
|
||||
return rv;
|
||||
}
|
||||
@@ -338,6 +403,12 @@ namespace mbts.spark {
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected Property<T?> add_nullable_property<T>(string prop_name, int target_field_number, T init_value = default, bool validate_on_changed = false, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) where T : struct {
|
||||
var prop = backing<T?>(prop_name, init_value);
|
||||
_on_nullable_property_added(prop_name, target_field_number, prop, prop.set, validate_on_changed, permissions);
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected Property<T> add_property<T>(string prop_name, int[] target_field_number_path, T init_value = default, bool validate_on_changed = false, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) {
|
||||
var prop = backing(prop_name, init_value);
|
||||
_on_property_added(prop_name, prop_name, DisplayNameHelper.snake_to_title_case(prop_name), target_field_number_path, prop, prop.set, validate_on_changed, permissions);
|
||||
@@ -368,23 +439,23 @@ 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(get_from_algo(algo)),
|
||||
algos => {
|
||||
var distinct_val = algos.Select(get_from_algo).Distinct().SafeSingleOrDefault();
|
||||
prop.set(distinct_val);
|
||||
},
|
||||
_link_props(param, prop)));
|
||||
return prop;
|
||||
TImmutableValue? get_from_algo(TMutable algo) =>
|
||||
field_desc.Accessor.GetValue(algo) is TMutableValue mval ? ProtoHelper.immutable_factory<TMutableValue, TImmutableValue>(mval) : (TImmutableValue?)null;
|
||||
}
|
||||
|
||||
protected Property<TValue> add_property<TValue>(string prop_name, Func<TMutable, TValue> get_from_def, Action<TMutable, TValue> assign_to_def, TValue init_value = default, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) {
|
||||
@@ -396,6 +467,10 @@ namespace mbts.spark {
|
||||
prop_name,
|
||||
def => assign_to_def(def, prop.Value),
|
||||
def => prop.set(get_from_def(def)),
|
||||
algos => {
|
||||
var distinct_val = algos.Select(get_from_def).Distinct().SafeSingleOrDefault();
|
||||
prop.set(distinct_val);
|
||||
},
|
||||
_link_props(param, prop)));
|
||||
return prop;
|
||||
}
|
||||
@@ -410,15 +485,25 @@ namespace mbts.spark {
|
||||
prop_name,
|
||||
def => assign_to_def(def, get_local()),
|
||||
def => set_local(get_from_def(def)),
|
||||
algos => {
|
||||
var distinct_val = algos.Select(get_from_def).Distinct().SafeSingleOrDefault();
|
||||
prop.set(distinct_val);
|
||||
},
|
||||
_link_props(param, prop)));
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected void add_property<TValue>(string prop_name, Action<TMutable> assign, Action<TMutable> load, Func<TValue> get_local, Action<TValue> set_local, IObservable<TValue> subscribe_local, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) {
|
||||
protected void add_property<TValue>(string prop_name, Func<TMutable, TValue> get_from_def, Action<TMutable, TValue> assign_to_def, Func<TValue> get_local, Action<TValue> set_local, IObservable<TValue> subscribe_local, AlgoParamPermissions permissions = AlgoParamPermissions.ReadWrite) {
|
||||
var gate = new PropertyUpdateGate();
|
||||
var param = new AlgoParamVM<TValue>(prop_name, DisplayNameHelper.snake_to_title_case(prop_name), get_local()) { permissions = permissions };
|
||||
_algo_params.Add(param);
|
||||
_auto_props[prop_name] = new AutoProp(prop_name, assign, load,
|
||||
_auto_props[prop_name] = new AutoProp(prop_name,
|
||||
def => assign_to_def(def, get_local()),
|
||||
def => set_local(get_from_def(def)),
|
||||
defs => {
|
||||
var distinct_val = defs.Select(get_from_def).Distinct().SafeSingleOrDefault();
|
||||
set_local(distinct_val);
|
||||
},
|
||||
new CompositeDisposable(
|
||||
subscribe_local.Subscribe(v => gate.try_update(() => param.value = v)),
|
||||
param.subscribe_value().Subscribe(v => gate.try_update(() => set_local(v)))));
|
||||
@@ -452,6 +537,25 @@ namespace mbts.spark {
|
||||
field_desc.Accessor.SetValue(mval, prop.Value);
|
||||
},
|
||||
mval => assign_to_prop(mval == null ? default : ConvertUtils.try_convert<T>(field_desc.Accessor.GetValue(mval))),
|
||||
mvals => {
|
||||
var distinct_val = mvals.Select(v => ConvertUtils.try_convert<T>(field_desc.Accessor.GetValue(v))).Distinct().SafeSingleOrDefault();
|
||||
prop.Value = distinct_val;
|
||||
},
|
||||
_link_props(param, prop, assign_to_prop, validate_on_changed)));
|
||||
}
|
||||
|
||||
void _on_nullable_property_added<T>(string prop_name, int target_field_number, IProperty<T?> prop, Action<T?> assign_to_prop, bool validate_on_changed, AlgoParamPermissions permissions) where T : struct {
|
||||
var field_desc = new TMutable().Descriptor.FindFieldByNumber(target_field_number);
|
||||
var param = new AlgoParamVM<T?>(prop_name, DisplayNameHelper.snake_to_title_case(prop_name), prop.Value) { permissions = permissions };
|
||||
_algo_params.Add(param);
|
||||
_auto_props.Add(new AutoProp(prop_name, mval => {
|
||||
if (mval != null && prop.Value.HasValue)
|
||||
field_desc.Accessor.SetValue(mval, prop.Value.Value);
|
||||
},
|
||||
mval => assign_to_prop(mval == null ? default : ConvertUtils.try_convert<T>(field_desc.Accessor.GetValue(mval))),
|
||||
mvals => {
|
||||
prop.Value = mvals.Select(v => ConvertUtils.try_convert<T>(field_desc.Accessor.GetValue(v))).Distinct().TryGetSingle(out T dv) ? dv : (T?)null;
|
||||
},
|
||||
_link_props(param, prop, assign_to_prop, validate_on_changed)));
|
||||
}
|
||||
|
||||
@@ -482,6 +586,10 @@ namespace mbts.spark {
|
||||
if (mval != null && target_field_desc.Accessor.GetValue(mval) is IMessage msg)
|
||||
assign_to_prop(ProtoHelper.get_oneof_case<T>(oneof_descriptor, msg));
|
||||
},
|
||||
mvals => {
|
||||
var distinct_val = mvals.Select(v => ConvertUtils.try_convert<T>(target_field_desc.Accessor.GetValue(v))).Distinct().SafeSingleOrDefault();
|
||||
assign_to_prop(distinct_val);
|
||||
},
|
||||
_link_props(param, prop, assign_to_prop, validate_on_changed)));
|
||||
}
|
||||
|
||||
@@ -510,13 +618,19 @@ namespace mbts.spark {
|
||||
} while (++i < field_descs.Length - 1);
|
||||
field_descs[field_descs.Length - 1].Accessor.SetValue(src, prop.Value);
|
||||
}
|
||||
}, mval => {
|
||||
}, mval => assign_to_prop(get_from_def(mval)),
|
||||
mvals => {
|
||||
var distinct_val = mvals.Select(get_from_def).Distinct().SafeSingleOrDefault();
|
||||
assign_to_prop(distinct_val);
|
||||
},
|
||||
_link_props(param, prop, assign_to_prop, validate_on_changed)));
|
||||
|
||||
T get_from_def(TMutable mval) {
|
||||
var v = mval as IMessage;
|
||||
for (int i = 0; i < field_descs.Length - 1 && v != null; i++)
|
||||
v = field_descs[i].Accessor.GetValue(v) as IMessage;
|
||||
assign_to_prop(v == null ? default : ConvertUtils.try_convert<T>(field_descs[field_descs.Length - 1].Accessor.GetValue(v)));
|
||||
},
|
||||
_link_props(param, prop, assign_to_prop, validate_on_changed)));
|
||||
return v == null ? default : ConvertUtils.try_convert<T>(field_descs[field_descs.Length - 1].Accessor.GetValue(v));
|
||||
}
|
||||
}
|
||||
|
||||
IDisposable _link_props<T>(AlgoParamVM<T> param, Property<T> prop, bool validate_on_changed = false) =>
|
||||
@@ -610,12 +724,18 @@ namespace mbts.spark {
|
||||
class AutoProp : IDisposable {
|
||||
public readonly string name;
|
||||
public readonly Action<TMutable> assign, load;
|
||||
public readonly Action<IEnumerable<TMutable>> assign_many, load_many;
|
||||
IDisposable _dispose;
|
||||
|
||||
public AutoProp(string name, Action<TMutable> assign, Action<TMutable> load, IDisposable dispose) {
|
||||
public AutoProp(string name, Action<TMutable> assign, Action<TMutable> load, Action<IEnumerable<TMutable>> load_many, IDisposable dispose)
|
||||
: this(name, assign, load, algos => algos.ForEach(assign), load_many, dispose) { }
|
||||
|
||||
public AutoProp(string name, Action<TMutable> assign, Action<TMutable> load, Action<IEnumerable<TMutable>> assign_many, Action<IEnumerable<TMutable>> load_many, IDisposable dispose) {
|
||||
this.name = name;
|
||||
this.assign = assign;
|
||||
this.load = load;
|
||||
this.load_many = load_many;
|
||||
this.assign_many = assign_many;
|
||||
_dispose = dispose;
|
||||
}
|
||||
|
||||
@@ -662,12 +782,14 @@ namespace mbts.spark {
|
||||
public readonly string prop_name;
|
||||
public readonly AlgoSelector selector;
|
||||
public readonly Func<AlgoDefi, AlgoDefi?> get_order;
|
||||
public readonly Func<IMessage, AlgoDefi?> get_from_impl;
|
||||
public readonly Action<AlgoDef, AlgoDef> set_order;
|
||||
public readonly IDisposable hooks;
|
||||
|
||||
public AlgoSelectorData(string id, AlgoSelector selector, Func<AlgoDefi, AlgoDefi?> get_order, Action<AlgoDef, AlgoDef> set_order, IDisposable hooks = null) {
|
||||
public AlgoSelectorData(string id, AlgoSelector selector, Func<IMessage, AlgoDefi?> get_from_impl, Func<AlgoDefi, AlgoDefi?> get_order, Action<AlgoDef, AlgoDef> set_order, IDisposable hooks = null) {
|
||||
this.prop_name = id;
|
||||
this.selector = selector;
|
||||
this.get_from_impl = get_from_impl;
|
||||
this.get_order = get_order;
|
||||
this.set_order = set_order;
|
||||
this.hooks = hooks;
|
||||
@@ -842,4 +964,4 @@ namespace mbts.spark {
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.utils;
|
||||
@@ -22,6 +21,8 @@ using OrderUpdate = bts.api.core.TableUpdate<(bts.api.SecurityImmutable? sec, bt
|
||||
namespace mbts.spark {
|
||||
[Export]
|
||||
class OrdersModel : IDisposable {
|
||||
public readonly MarketDataAuxiliaryModel md_auxiliary_model;
|
||||
|
||||
readonly IBus _bus;
|
||||
readonly OrderFactory _factory;
|
||||
readonly OrderService _service;
|
||||
@@ -36,7 +37,7 @@ namespace mbts.spark {
|
||||
|
||||
[ImportingConstructor]
|
||||
OrdersModel(IBus bus, OrderFactory factory, OrderService service, PositionService position_service,
|
||||
SpreaderModel spreader, DynamicOrderHelper dynamic_helper, AdminModel admin_model, IAlgoStudioModel algo_model, SecurityStore sstore, ErrorReporter error) {
|
||||
SpreaderModel spreader, DynamicOrderHelper dynamic_helper, AdminModel admin_model, IAlgoStudioModel algo_model, MarketDataAuxiliaryModel md_auxiliary_model, SecurityStore sstore, ErrorReporter error) {
|
||||
_bus = bus;
|
||||
_factory = factory;
|
||||
_service = service;
|
||||
@@ -46,6 +47,7 @@ namespace mbts.spark {
|
||||
_dynamic_helper = dynamic_helper;
|
||||
this.admin_model = admin_model;
|
||||
this.algo_model = algo_model;
|
||||
this.md_auxiliary_model = md_auxiliary_model;
|
||||
var scheduler = ThreadPoolScheduler.Instance;
|
||||
var interval = TimeSpan.FromMilliseconds(100);
|
||||
on_orders =
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace mbts.collections {
|
||||
: this(EqualityComparer<TKey>.Default) { }
|
||||
|
||||
public RefCountMap(IEqualityComparer<TKey> key_comparer)
|
||||
: this(new Dictionary<TKey, KeyRefCount>(), key_comparer) { }
|
||||
: this(new Dictionary<TKey, KeyRefCount>(key_comparer), key_comparer) { }
|
||||
|
||||
RefCountMap(Dictionary<TKey, KeyRefCount> dictionary, IEqualityComparer<TKey> key_comparer) {
|
||||
_dictionary = dictionary;
|
||||
@@ -40,20 +40,30 @@ namespace mbts.collections {
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
GetEnumerator();
|
||||
|
||||
public void increment(TKey key) {
|
||||
public void increment(TKey key) =>
|
||||
increment(key, 1);
|
||||
|
||||
public void increment(TKey key, int count) {
|
||||
if (!_dictionary.TryGetValue(key, out KeyRefCount krc))
|
||||
_dictionary.Add(key, krc = new KeyRefCount(key));
|
||||
else krc.count++;
|
||||
_dictionary.Add(key, krc = new KeyRefCount(key) { count = count });
|
||||
else krc.count += count;
|
||||
}
|
||||
|
||||
public bool decrement(TKey key) {
|
||||
public bool decrement(TKey key) =>
|
||||
decrement(key, 1);
|
||||
|
||||
public bool decrement(TKey key, int count) {
|
||||
if (_dictionary.TryGetValue(key, out KeyRefCount krc)) {
|
||||
if ((--krc.count) == 0)
|
||||
if (krc.count > count) {
|
||||
krc.count -= count;
|
||||
} else {
|
||||
// count cannot be negative
|
||||
krc.count = 0;
|
||||
_dictionary.Remove(key);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool remove(TKey key) =>
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Linq;
|
||||
namespace mbts.collections {
|
||||
interface IGroupingSet<TKey, TElement> : IGrouping<TKey, TElement>, ISet<TElement> { }
|
||||
|
||||
class SetMap<TKey, TElement> : IEnumerable<IGroupingSet<TKey, TElement>>, ICollection {
|
||||
class SetMap<TKey, TElement> : IEnumerable<IGroupingSet<TKey, TElement>>, ICollection, IReadOnlyDictionary<TKey, IEnumerable<TElement>> {
|
||||
readonly IEqualityComparer<TKey> _key_comparer;
|
||||
readonly IEqualityComparer<TElement> _element_comparer;
|
||||
readonly Dictionary<TKey, InternalGroupSet> _dictionary;
|
||||
@@ -30,6 +30,10 @@ namespace mbts.collections {
|
||||
public object SyncRoot => null;
|
||||
public bool IsSynchronized => false;
|
||||
public IEnumerable<TKey> Keys => _dictionary.Keys;
|
||||
|
||||
public IEnumerable<IEnumerable<TElement>> Values => _dictionary.Values;
|
||||
IEnumerable<TElement> IReadOnlyDictionary<TKey, IEnumerable<TElement>>.this[TKey key] => _dictionary[key];
|
||||
|
||||
public ISet<TElement> this[TKey key] => _dictionary[key];
|
||||
|
||||
public void CopyTo(Array array, int index) =>
|
||||
@@ -103,6 +107,19 @@ namespace mbts.collections {
|
||||
kv => new InternalGroupSet(kv.Key, kv.Value, _element_comparer)
|
||||
), _key_comparer,
|
||||
_element_comparer);
|
||||
public bool ContainsKey(TKey key) => _dictionary.ContainsKey(key);
|
||||
public bool TryGetValue(TKey key, out IEnumerable<TElement> value) {
|
||||
if (_dictionary.TryGetValue(key, out InternalGroupSet igs)) {
|
||||
value = igs;
|
||||
return true;
|
||||
}
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
IEnumerator<KeyValuePair<TKey, IEnumerable<TElement>>> IEnumerable<KeyValuePair<TKey, IEnumerable<TElement>>>.GetEnumerator() {
|
||||
foreach (var kv in _dictionary)
|
||||
yield return new KeyValuePair<TKey, IEnumerable<TElement>>(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
class InternalGroupSet : HashSet<TElement>, IGroupingSet<TKey, TElement> {
|
||||
public InternalGroupSet(TKey key, IEqualityComparer<TElement> comparer)
|
||||
|
||||
+44
-3
@@ -57,13 +57,13 @@ namespace mbts.persist {
|
||||
new NonSharedWrapper(this);
|
||||
|
||||
class NonSharedWrapper : IWindowSettingsManagerNonShared<T> {
|
||||
readonly WindowSettingsManager<T> _wsm;
|
||||
readonly IWindowSettingsManager<T> _wsm;
|
||||
readonly BehaviorSubject<T> _default_subject;
|
||||
IDisposable _dispose;
|
||||
|
||||
public NonSharedWrapper(WindowSettingsManager<T> wsm) {
|
||||
public NonSharedWrapper(IWindowSettingsManager<T> wsm) {
|
||||
_wsm = wsm;
|
||||
_default_subject = new BehaviorSubject<T>(_wsm.default_settings ?? wsm._get(UserSettings.factory_defaults));
|
||||
_default_subject = new BehaviorSubject<T>(_wsm.default_settings);
|
||||
_dispose = wsm.subscribe_default().Subscribe(s =>
|
||||
_default_subject.OnNext(default_settings = MiscUtils.clone_proto(s)));
|
||||
}
|
||||
@@ -88,6 +88,47 @@ namespace mbts.persist {
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public class DisconnectedImpl : IWindowSettingsManager<T> {
|
||||
readonly BehaviorSubject<T> _default_settings_subject;
|
||||
T _instance_settings, _default_settings;
|
||||
|
||||
public DisconnectedImpl(T settings) : this(settings, settings) { }
|
||||
public DisconnectedImpl(T instance_settings, T default_settings) {
|
||||
_instance_settings = instance_settings;
|
||||
_default_settings = default_settings;
|
||||
_default_settings_subject = new BehaviorSubject<T>(default_settings);
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _instance_settings;
|
||||
set {
|
||||
if (!Equals(_instance_settings, value)) {
|
||||
_instance_settings = value;
|
||||
instance_settings_changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public T default_settings {
|
||||
get => _default_settings;
|
||||
set {
|
||||
if (!Equals(_default_settings, _default_settings)) {
|
||||
_default_settings = value;
|
||||
_default_settings_subject.OnNext(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<T> instance_settings_changed;
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() => new NonSharedWrapper(this);
|
||||
public Task save_default_settings(T value) {
|
||||
default_settings = value;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public IObservable<T> subscribe_default() => _default_settings_subject;
|
||||
}
|
||||
}
|
||||
|
||||
static class WindowSettingsManagerExtensions {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using mbts.collections;
|
||||
using bts.collections;
|
||||
using mbts.collections;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,6 +9,12 @@ using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.utils {
|
||||
enum Plurality {
|
||||
None,
|
||||
One,
|
||||
Many
|
||||
}
|
||||
|
||||
class CommonValueMonitor<T> {
|
||||
readonly RefCountMap<T> _values;
|
||||
readonly DeferrableActionWrapper _update;
|
||||
@@ -24,23 +31,49 @@ namespace bts.utils {
|
||||
_default_value = default_value;
|
||||
_values = new RefCountMap<T>(_comparer = comparer);
|
||||
_update = new DeferrableActionWrapper(on_update);
|
||||
void on_update() =>
|
||||
void on_update() {
|
||||
common_value_changed?.Invoke(common_value);
|
||||
plurality_changed?.Invoke(plurality);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<T> common_value_changed;
|
||||
public event Action<Plurality> plurality_changed;
|
||||
|
||||
public ICollection<T> distinct_values => _values.keys;
|
||||
public T common_value => _values.keys.SafeSingleOrDefault();
|
||||
public Plurality plurality {
|
||||
get {
|
||||
switch (_values.keys.Count) {
|
||||
case 0: return Plurality.None;
|
||||
case 1: return Plurality.One;
|
||||
default: return Plurality.Many;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IDisposable defer_updates() {
|
||||
var last_fired_qt = plurality;
|
||||
var last_fired = common_value;
|
||||
var d = _update.defer_execution();
|
||||
return Disposable.Create(() => {
|
||||
var v = common_value;
|
||||
if (_comparer.Equals(v, last_fired))
|
||||
if (_comparer.Equals(v, last_fired)) {
|
||||
_update.cancel_pending_execution();
|
||||
else d.Dispose();
|
||||
if (plurality_changed != null) {
|
||||
var qt = plurality;
|
||||
if (last_fired_qt != qt)
|
||||
plurality_changed(qt);
|
||||
}
|
||||
} else {
|
||||
var qt = plurality;
|
||||
if (last_fired_qt == qt) {
|
||||
_update.cancel_pending_execution();
|
||||
common_value_changed?.Invoke(v);
|
||||
} else {
|
||||
d.Dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,6 +96,116 @@ namespace bts.utils {
|
||||
}
|
||||
}
|
||||
|
||||
class CommonValueGroupMonitor<T, TKey> where TKey : struct {
|
||||
readonly IEqualityComparer<TKey> _key_comparer;
|
||||
readonly IEqualityComparer<T> _value_comparer;
|
||||
readonly Dictionary<TKey, RefCountMap<T>> _value_groups;
|
||||
readonly Func<T, TKey> _key;
|
||||
RefCountMap<T> _deferred_adds, _deferred_removes;
|
||||
int _deferral_count;
|
||||
bool _is_deferred => _deferral_count > 0;
|
||||
|
||||
public CommonValueGroupMonitor(Func<T, TKey> key)
|
||||
: this(key, EqualityComparer<TKey>.Default, EqualityComparer<T>.Default) { }
|
||||
|
||||
public CommonValueGroupMonitor(Func<T, TKey> key, IEqualityComparer<TKey> key_comparer, IEqualityComparer<T> value_comparer) {
|
||||
_key = key;
|
||||
_key_comparer = key_comparer;
|
||||
_value_comparer = value_comparer;
|
||||
_deferred_adds = new RefCountMap<T>(value_comparer);
|
||||
_deferred_removes = new RefCountMap<T>(value_comparer);
|
||||
_value_groups = new Dictionary<TKey, RefCountMap<T>>(key_comparer);
|
||||
distinct_value_groups = new MappedDictionary<TKey, RefCountMap<T>, IEnumerable<T>>(_value_groups, rcm => rcm.keys);
|
||||
}
|
||||
|
||||
public event Action<KeyValuePair<TKey, IEnumerable<T>>?> common_value_group_changed;
|
||||
public event Action<(IEnumerable<T> removed, IEnumerable<T> added)> common_values_changed;
|
||||
|
||||
public IReadOnlyDictionary<TKey, IEnumerable<T>> distinct_value_groups { get; }
|
||||
public KeyValuePair<TKey, IEnumerable<T>>? common_value_group =>
|
||||
distinct_value_groups.TryGetSingle(out KeyValuePair<TKey, IEnumerable<T>> kv) ? kv : (KeyValuePair<TKey, IEnumerable<T>>?)null;
|
||||
|
||||
public void add(T value) {
|
||||
if (_is_deferred) {
|
||||
if (!_deferred_removes.decrement(value))
|
||||
_deferred_adds.increment(value);
|
||||
} else {
|
||||
var k = _key(value);
|
||||
if (_value_groups.TryGetValue(k, out RefCountMap<T> rcm)) {
|
||||
if (rcm.increment_adds_key(value) && _value_groups.Count == 1) {
|
||||
common_values_changed?.Invoke((Enumerable.Empty<T>(), new[] { value }));
|
||||
}
|
||||
} else {
|
||||
_value_groups.Add(k, rcm = new RefCountMap<T>(_value_comparer));
|
||||
rcm.increment(value);
|
||||
switch (_value_groups.Count) {
|
||||
case 1: common_value_group_changed?.Invoke(distinct_value_groups.First()); break;
|
||||
case 2: common_value_group_changed?.Invoke(null); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(T value) {
|
||||
if (_is_deferred) {
|
||||
if (!_deferred_adds.decrement(value))
|
||||
_deferred_removes.increment(value);
|
||||
} else {
|
||||
var k = _key(value);
|
||||
if (_value_groups.TryGetValue(k, out RefCountMap<T> rcm)) {
|
||||
if (rcm.decrement_removes_key(value)) {
|
||||
switch (rcm.Count) {
|
||||
case 0:
|
||||
_value_groups.Remove(k);
|
||||
switch (_value_groups.Count) {
|
||||
case 0: common_value_group_changed?.Invoke(null); break;
|
||||
case 1: common_value_group_changed?.Invoke(distinct_value_groups.First()); break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (_value_groups.Count == 1)
|
||||
common_values_changed?.Invoke((new[] { value }, Enumerable.Empty<T>()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IDisposable deferr_updates() {
|
||||
var last_fired_common_key = common_value_group?.Key;
|
||||
++_deferral_count;
|
||||
return Disposable.Create(() => {
|
||||
if (--_deferral_count == 0 && (_deferred_adds.Count > 0 || _deferred_removes.Count > 0)) {
|
||||
foreach(var krc in _deferred_removes) {
|
||||
var k = _key(krc.key);
|
||||
if (_value_groups.TryGetValue(k, out RefCountMap<T> rcm)) {
|
||||
rcm.decrement(krc.key, krc.count);
|
||||
if (rcm.Count == 0)
|
||||
_value_groups.Remove(k);
|
||||
}
|
||||
}
|
||||
foreach (var krc in _deferred_adds) {
|
||||
var k = _key(krc.key);
|
||||
if (!_value_groups.TryGetValue(k, out RefCountMap<T> rcm)) {
|
||||
_value_groups.Add(k, rcm = new RefCountMap<T>(_value_comparer));
|
||||
}
|
||||
rcm.increment(krc.key, krc.count);
|
||||
}
|
||||
if (!EqualityComparer.nullable_equals(last_fired_common_key, common_value_group?.Key)) {
|
||||
common_value_group_changed?.Invoke(common_value_group);
|
||||
} else if (last_fired_common_key is TKey k) {
|
||||
common_values_changed?.Invoke((
|
||||
_deferred_removes.Select(krc => krc.key).Where(v => _key_comparer.Equals(_key(v), k)),
|
||||
_deferred_adds.Select(krc => krc.key).Where(v => _key_comparer.Equals(_key(v), k))));
|
||||
}
|
||||
_deferred_adds = new RefCountMap<T>(_value_comparer);
|
||||
_deferred_removes = new RefCountMap<T>(_value_comparer);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class CommonValueMonitorMultiplexor<TSource> {
|
||||
int _member_id_counter;
|
||||
readonly Dictionary<int, (Action<TSource> add, Action<TSource> remove, Func<IDisposable> defer)> _members = new Dictionary<int, (Action<TSource> add, Action<TSource> remove, Func<IDisposable> defer)>();
|
||||
@@ -105,6 +248,22 @@ namespace bts.utils {
|
||||
member_mon.defer_updates));
|
||||
return Disposable.Create(() => _members.Remove(id));
|
||||
}
|
||||
|
||||
public IDisposable add_member_mon<T, TKey>(CommonValueGroupMonitor<T, TKey> member_mon, Func<TSource, T> get_value) where TKey : struct {
|
||||
int id = _member_id_counter++;
|
||||
_members.Add(id, (
|
||||
v => {
|
||||
var res = get_value(v);
|
||||
member_mon.add(res);
|
||||
},
|
||||
v => {
|
||||
var res = get_value(v);
|
||||
member_mon.remove(res);
|
||||
},
|
||||
member_mon.deferr_updates
|
||||
));
|
||||
return Disposable.Create(() => _members.Remove(id));
|
||||
}
|
||||
}
|
||||
|
||||
static class CommonValueMonitorExtensions {
|
||||
@@ -176,9 +335,57 @@ namespace bts.utils {
|
||||
}
|
||||
void notify() =>
|
||||
o.OnNext(monitor.try_get_common_value(out T result) ? selector(result) : default_value);
|
||||
});
|
||||
});
|
||||
|
||||
public static IObservable<TResult> SubscribeThrottled<T, TKey, TResult>(this CommonValueGroupMonitor<T, TKey> monitor, TimeSpan throttle, Func<TKey, IEnumerable<T>, TResult> selector, TResult default_value) where TKey : struct =>
|
||||
Observable.Create<TResult>(o => {
|
||||
bool busy = false, dirty = false;
|
||||
notify();
|
||||
monitor.common_values_changed += on_values_changed;
|
||||
monitor.common_value_group_changed += on_value_group_changed;
|
||||
return Disposable.Create(() => {
|
||||
monitor.common_values_changed -= on_values_changed;
|
||||
monitor.common_value_group_changed -= on_value_group_changed;
|
||||
});
|
||||
void on_values_changed((IEnumerable<T>, IEnumerable<T>) _) => on_changed();
|
||||
void on_value_group_changed(KeyValuePair<TKey, IEnumerable<T>>? _) => on_changed();
|
||||
async void on_changed() {
|
||||
if (busy) {
|
||||
dirty = true;
|
||||
return;
|
||||
}
|
||||
dirty = false;
|
||||
do {
|
||||
notify();
|
||||
await Task.Delay(throttle);
|
||||
} while (dirty);
|
||||
busy = false;
|
||||
}
|
||||
void notify() =>
|
||||
o.OnNext(monitor.common_value_group is KeyValuePair<TKey, IEnumerable<T>> kv ? selector(kv.Key, kv.Value) : default_value);
|
||||
});
|
||||
|
||||
public static IObservable<T?> SubscribeThrottledNullable<T>(this CommonValueMonitor<T> monitor, TimeSpan throttle) where T : struct =>
|
||||
monitor.SubscribeThrottled<T, T?>(throttle, val => val, null);
|
||||
|
||||
public static IObservable<Plurality> SubscribePluralityThrottled<T>(this CommonValueMonitor<T> monitor, TimeSpan throttle) =>
|
||||
Observable.Create<Plurality>(o => {
|
||||
bool busy = false, dirty = false;
|
||||
o.OnNext(monitor.plurality);
|
||||
monitor.plurality_changed += on_changed;
|
||||
return Disposable.Create(() => monitor.plurality_changed -= on_changed);
|
||||
async void on_changed(Plurality _) {
|
||||
if (busy) {
|
||||
dirty = true;
|
||||
return;
|
||||
}
|
||||
dirty = false;
|
||||
do {
|
||||
o.OnNext(monitor.plurality);
|
||||
await Task.Delay(throttle);
|
||||
} while (dirty);
|
||||
busy = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,11 @@
|
||||
<!---TextBox-->
|
||||
<Color x:Key="TextBox.Static.Background.Color">#FFFFFFFF</Color>
|
||||
<Color x:Key="TextBox.Static.Border.Color">#FFABADB3</Color>
|
||||
<Color x:Key="TextBox.MouseOver.Border.Color">#FF7EB4EA</Color>
|
||||
|
||||
<SolidColorBrush x:Key="TextBox.Static.Border.Brush" Color="{StaticResource TextBox.Static.Border.Color}"/>
|
||||
<SolidColorBrush x:Key="TextBox.Static.Background.Brush" Color="{StaticResource TextBox.Static.Background.Color}"/>
|
||||
<SolidColorBrush x:Key="TextBox.MouseOver.Border.Brush" Color="{StaticResource TextBox.MouseOver.Border.Color}"/>
|
||||
|
||||
<!--CheckBox-->
|
||||
<Color x:Key="CheckBox.Static.ForegroundColor">#FF212121</Color>
|
||||
|
||||
@@ -103,8 +103,9 @@ namespace mbts.ui.controls.adorners {
|
||||
return _popupElement.TranslatePoint(new Point(0, 0), this);
|
||||
double el_width = _popupElement.DesiredSize.Width;
|
||||
double el_height = _popupElement.DesiredSize.Height;
|
||||
Point tl;
|
||||
if (OpenRelativeToMouse) {
|
||||
Point tl = Mouse.GetPosition(this);
|
||||
tl = Mouse.GetPosition(this);
|
||||
double rltv_x, rltv_y;
|
||||
switch (_horizontalPosition) {
|
||||
case HorizontalPosition.Left: rltv_x = -el_width; break;
|
||||
@@ -118,9 +119,9 @@ namespace mbts.ui.controls.adorners {
|
||||
case VerticalPosition.Botton: rltv_y = 0; break;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
return _popupTarget.TranslatePoint(new Point(tl.X + rltv_x + _horizontalOffset, tl.Y + rltv_y + _verticalOffset), _popupTarget);
|
||||
tl = new Point(tl.X + rltv_x + _horizontalOffset, tl.Y + rltv_y + _verticalOffset);
|
||||
} else {
|
||||
Point tl = _popupTarget.TranslatePoint(new Point(0, 0), AdornedElement);
|
||||
tl = _popupTarget.TranslatePoint(new Point(0, 0), AdornedElement);
|
||||
double rltv_x, rltv_y;
|
||||
switch (_horizontalPosition) {
|
||||
case HorizontalPosition.Left: rltv_x = -el_width; break;
|
||||
@@ -134,8 +135,14 @@ namespace mbts.ui.controls.adorners {
|
||||
case VerticalPosition.Botton: rltv_y = _popupTarget.ActualHeight + el_height; break;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
return _popupTarget.TranslatePoint(new Point(tl.X + rltv_x + _horizontalOffset, tl.Y + rltv_y + _verticalOffset), _popupTarget);
|
||||
tl = new Point(tl.X + rltv_x + _horizontalOffset, tl.Y + rltv_y + _verticalOffset);
|
||||
}
|
||||
if (ClipToBounds) {
|
||||
tl = tl.within_bounds(
|
||||
x_max: AdornedElement.RenderSize.Width - el_width,
|
||||
y_max: AdornedElement.RenderSize.Height - el_height);
|
||||
}
|
||||
return _popupTarget.TranslatePoint(tl, _popupTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@
|
||||
x:Name="PART_Absolute_TickUpDown"
|
||||
Grid.Column="2"
|
||||
Value="{Binding Absolute, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
VerticalAlignment="Center"
|
||||
MinWidth="40"
|
||||
Increment="1"
|
||||
Visibility="Collapsed"
|
||||
@@ -38,7 +37,6 @@
|
||||
x:Name="PART_Ratio_TickUpDown"
|
||||
Grid.Column="2"
|
||||
Value="{Binding Ratio, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
VerticalAlignment="Center"
|
||||
MinWidth="40"
|
||||
Increment="0.05"
|
||||
Visibility="Collapsed"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
TickUpCommand="{TemplateBinding TickUpCommand}"
|
||||
TickDownCommand="{TemplateBinding TickDownCommand}"
|
||||
>
|
||||
@@ -24,9 +28,7 @@
|
||||
u:Behavior.DisablePaste="True"
|
||||
u:TextBoxBehavior.InputFilter="{u:RegexInputFilter Regex={x:Static Member=PriceInput, MemberType={u:Nested txt:TextUtils.RegexFilters}}}"
|
||||
u:TextBoxBehavior.CommitOnEnter="True"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderThickness="0"
|
||||
>
|
||||
<TextBox.CommandBindings>
|
||||
<CommandBinding Command="{x:Static u:TextBoxBehavior.SelectAllCommand}" Executed="{x:Static u:TextBoxBehavior.SelectAllCommandExecutedHandler}"/>
|
||||
@@ -41,6 +43,7 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Template" Value="{StaticResource PriceEntryTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -13,36 +13,59 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Height" Value="20" />
|
||||
<Setter Property="MinWidth" Value="14" />
|
||||
<Setter Property="Focusable" Value="false" />
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="SnapsToDevicePixels" Value="True"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDown">
|
||||
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="14" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<ContentPresenter Grid.RowSpan="2" Grid.Column="0" VerticalAlignment="Center" Margin="{TemplateBinding Padding}" />
|
||||
<RepeatButton Command="{TemplateBinding TickUpCommand}" CommandParameter="{TemplateBinding TickUpParameter}" Grid.Row="0" Grid.Column="1" BorderThickness="0" Focusable="False">
|
||||
<Path Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z"
|
||||
<Border
|
||||
x:Name="Bd"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="14" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<ContentPresenter
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
/>
|
||||
<RepeatButton Command="{TemplateBinding TickUpCommand}" CommandParameter="{TemplateBinding TickUpParameter}" Grid.Row="0" Grid.Column="1" BorderThickness="0" Focusable="False">
|
||||
<Path Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z"
|
||||
Fill="#FF606060" HorizontalAlignment="Right" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="180" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</RepeatButton>
|
||||
<RepeatButton Command="{TemplateBinding TickDownCommand}" CommandParameter="{TemplateBinding TickDownParameter}" Grid.Row="1" Grid.Column="1" BorderThickness="0" Focusable="False">
|
||||
<Path Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z"
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="180" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</RepeatButton>
|
||||
<RepeatButton Command="{TemplateBinding TickDownCommand}" CommandParameter="{TemplateBinding TickDownParameter}" Grid.Row="1" Grid.Column="1" BorderThickness="0" Focusable="False">
|
||||
<Path Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z"
|
||||
Fill="#FF606060" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</RepeatButton>
|
||||
</Grid>
|
||||
</RepeatButton>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource TextBox.MouseOver.Border.Brush}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
@@ -51,13 +74,25 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownDouble">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
Name="PART_TextBox"
|
||||
BorderThickness="0"
|
||||
u:DoubleDisplay.Multiplier="{TemplateBinding Multiplier}"
|
||||
u:DoubleDisplay.Format="{TemplateBinding Format}"
|
||||
u:TextBoxBehavior.InputFilter="{u:RegexInputFilter Regex={x:Static Decimal, MemberType={u:Nested txt:TextUtils.RegexFilters}}}"
|
||||
@@ -74,12 +109,23 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownInt">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<TextBox Name="PART_TextBox"/>
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox Name="PART_TextBox" BorderThickness="0"/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -92,12 +138,23 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownUInt">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<TextBox Name="PART_TextBox"/>
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox Name="PART_TextBox" BorderThickness="0"/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -110,12 +167,26 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownUShort">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<TextBox Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource UShortTextConverter}}"/>
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource UShortTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -125,12 +196,26 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownULong">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<TextBox Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource ULongTextConverter}}"/>
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource ULongTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -140,12 +225,26 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownByte">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<TextBox Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource ByteTextConverter}}"/>
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource ByteTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -155,13 +254,25 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownNullableDouble">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableDoubleTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
@@ -173,14 +284,27 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownNullableInt">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableIntTextConverter}}"/>
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableIntTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -190,16 +314,26 @@
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.Static.Background.Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border.Brush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownNullableUInt">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
u:TextBoxBehavior.CommitOnEnter="{TemplateBinding CommitOnEnter}"
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableUIntTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
@@ -208,31 +342,57 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style TargetType="{x:Type c:TickUpDownNullableUShort}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownNullableUShort">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableUShortTextConverter}}"/>
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableUShortTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style TargetType="{x:Type c:TickUpDownNullableULong}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="c:TickUpDownNullableULong">
|
||||
<c:TickUpDown x:Name="PART_tick_up_down">
|
||||
<c:TickUpDown
|
||||
x:Name="PART_tick_up_down"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
>
|
||||
<TextBox
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableULongTextConverter}}"/>
|
||||
BorderThickness="0"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource NullableULongTextConverter}}"
|
||||
/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -87,7 +87,14 @@
|
||||
<ColumnDefinition Width="38"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:TickUpDown x:Name="PART_time_tick" HorizontalAlignment="Stretch" EnableArrowKeyTick="False" Template="{StaticResource HoverButtonOverlayTemplate}">
|
||||
<TextBox x:Name="PART_time_text" u:TextBoxBehavior.CommitOnEnter="True" Height="20" u:TextBoxBehavior.EnableArrowKeyTraverse="True" u:Behavior.DisablePaste="True">
|
||||
<TextBox
|
||||
x:Name="PART_time_text"
|
||||
u:TextBoxBehavior.CommitOnEnter="True"
|
||||
u:TextBoxBehavior.EnableArrowKeyTraverse="True"
|
||||
u:Behavior.DisablePaste="True"
|
||||
Height="20"
|
||||
BorderThickness="0"
|
||||
>
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Up" Command="{x:Static c:DateTimePicker.TickTimeComponentCommand}" CommandParameter="{u:Int 1}"/>
|
||||
<KeyBinding Key="Down" Command="{x:Static c:DateTimePicker.TickTimeComponentCommand}" CommandParameter="{u:Int -1}"/>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
u:TextBoxBehavior.InputFilter="{u:RegexInputFilter {x:Static Member=TimeSpan, MemberType={u:Nested txt:TextUtils.RegexFilters.Time}}}"
|
||||
u:Behavior.DisablePaste="True"
|
||||
Height="20"
|
||||
BorderThickness="0"
|
||||
/>
|
||||
<TextBlock
|
||||
Text="hh:mm:ss"
|
||||
|
||||
@@ -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 "*";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
class BooleanNoneConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
|
||||
values.All(v => v is bool b && !b);
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,15 @@ namespace mbts.ui.converters {
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
value;
|
||||
}
|
||||
|
||||
class NullableEnumDescriptionConverter : IValueConverter {
|
||||
public string TextForNull { get; set; }
|
||||
public TextCapitalizationFormat Capitalization { get; set; } = TextCapitalizationFormat.Default;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
value == null ? TextForNull : value is Enum ? EnumHelper.get_display_name((Enum)value, Capitalization) : value.ToString();
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
[ValueConversion(typeof(double), typeof(double))]
|
||||
class DoubleSubtractionConverter : IValueConverter {
|
||||
public double Value { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is double d)
|
||||
return d - Value;
|
||||
return new ValidationResult(false, "Not a double.");
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is double d)
|
||||
return d + Value;
|
||||
return new ValidationResult(false, "Not a double.");
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(double[]), typeof(double))]
|
||||
class DoubleDynamicSubtractionConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (values.Length > 0 && values[0] is double difference) {
|
||||
for (int i = 1; i < values.Length; i++) {
|
||||
if (values[i] is double v)
|
||||
difference -= v;
|
||||
}
|
||||
return difference;
|
||||
}
|
||||
return new ValidationResult(false, "No doubles.");
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
[ValueConversion(typeof(int), typeof(bool))]
|
||||
class IntGreaterThanConverter : IValueConverter {
|
||||
public int Value { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is int i)
|
||||
return i > Value;
|
||||
return new ValidationResult(false, "Not an integer.");
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
[ValueConversion(typeof(int), typeof(int))]
|
||||
class IntSubtractionConverter : IValueConverter {
|
||||
public int Value { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is int i)
|
||||
return i - Value;
|
||||
return new ValidationResult(false, "Not an integer.");
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is int i)
|
||||
return i + Value;
|
||||
return new ValidationResult(false, "Not an integer.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts;
|
||||
using bts.utils;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -116,6 +117,9 @@ namespace mbts.ui {
|
||||
return image_source;
|
||||
}
|
||||
|
||||
public static Point within_bounds(this Point point, double x_min = 0, double y_min = 0, double x_max = double.PositiveInfinity, double y_max = double.PositiveInfinity) =>
|
||||
new Point(MathUtils.within_range(x_min, x_max, point.X), MathUtils.within_range(y_min, y_max, point.Y));
|
||||
|
||||
// Perform a breadth first traversal of all children returning any that match the predicate.
|
||||
// Matching children are *not* further traversed
|
||||
public static IEnumerable<FrameworkElement> visual_children_where(this FrameworkElement v, Func<FrameworkElement, bool> match) {
|
||||
|
||||
@@ -165,16 +165,23 @@ namespace mbts.spark {
|
||||
$"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{spec.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}";
|
||||
|
||||
public static string short_description(this OrderRecordImmutable order, SecurityImmutable? security) {
|
||||
var sb = new StringBuilderEx("[", order.Key.ToString(), "] ", "[", camel_to_title_case(order.status().ToString()), "] ", security.display_name(), " ", order.side().ToString(), " ");
|
||||
if (order.HasState) {
|
||||
sb.Add(order.State.Quantity.ToString(), " @ ", security.spec_or_default().format(order.State.Price), " (filled ", order.State.FilledQuantity.ToString());
|
||||
if (order.State.FilledQuantity > 0) {
|
||||
sb.Add(" @ ", security.spec_or_default().format(order.State.AvgPrice));
|
||||
}
|
||||
sb.Add(")");
|
||||
} else {
|
||||
sb.Add("(unknown-quantity) @ (unknown-price)");
|
||||
}
|
||||
var spec = security.spec_or_default();
|
||||
return new StringBuilderEx(
|
||||
security.display_name(), " ",
|
||||
order.side().ToString(), " ",
|
||||
price_quantity_description(order.price(), order.quantity(), spec), " (",
|
||||
filled_status_description(order, spec), ")"
|
||||
).ToString();
|
||||
}
|
||||
|
||||
public static string price_quantity_description(double price, uint quantity, ContractSpecificationImmutable spec) =>
|
||||
new StringBuilderEx(quantity.ToString(), " @ ", spec.format(price) ?? price.ToString("#0.00##")).ToString();
|
||||
|
||||
public static string filled_status_description(this OrderRecordImmutable order, ContractSpecificationImmutable spec) {
|
||||
var sb = new StringBuilderEx("filled ", order.filled().ToString());
|
||||
if (order.filled() > 0)
|
||||
sb.Add(" @ ", spec.format(order.avg_price()));
|
||||
sb.Add(", ", camel_to_title_case(order.status().ToString(), TextCapitalizationFormat.NoCaps));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -16,6 +17,14 @@ namespace mbts.ui {
|
||||
|
||||
public string State { get => GetValue(StateProperty) as string; set => SetValue(StateProperty, value); }
|
||||
|
||||
public static readonly DependencyProperty GroupProperty =
|
||||
WPFHelper.create_dp<StateGroupsManager, StateDefinition>(nameof(Group));
|
||||
|
||||
public StateGroupsManager Group {
|
||||
get => GetValue(GroupProperty) as StateGroupsManager;
|
||||
set => SetValue(GroupProperty, value);
|
||||
}
|
||||
|
||||
public event PropertyChange<string> StateChanged;
|
||||
}
|
||||
|
||||
@@ -37,6 +46,8 @@ namespace mbts.ui {
|
||||
public StateDefinitionCollection StateDefinitions { get => GetValue(StateDefinitionsProperty) as StateDefinitionCollection; set => SetValue(StateDefinitionsProperty, value); }
|
||||
#endregion
|
||||
|
||||
public bool AttachToMembers { get; set; }
|
||||
|
||||
static void _reset(StateGroupsManager state_group, FrameworkElement target, StateDefinitionCollection state_defs) {
|
||||
if (state_group == null)
|
||||
return;
|
||||
@@ -47,6 +58,13 @@ namespace mbts.ui {
|
||||
sd.StateChanged += on_state_changed;
|
||||
return Disposable.Create(() => sd.StateChanged -= on_state_changed);
|
||||
});
|
||||
if (state_group.AttachToMembers) {
|
||||
state_group._state_definitions_hook = new CompositeDisposable(
|
||||
state_group._state_definitions_hook,
|
||||
ObservableAutoWrapper.connect_item_actions(
|
||||
state_defs,
|
||||
sd => sd.SetCurrentValue(StateDefinition.GroupProperty, state_group)));
|
||||
}
|
||||
void on_state_changed(string oldval, string newval) => StateManager.GoToState(target, newval);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +84,10 @@ namespace mbts.ui {
|
||||
class StateManager : DependencyObject {
|
||||
#region Groups
|
||||
public static readonly DependencyProperty GroupsProperty =
|
||||
DependencyProperty.RegisterAttached("Groups", typeof(StateGroupsManager), typeof(StateManager), new PropertyMetadata(null));
|
||||
DependencyProperty.RegisterAttached("Groups", typeof(StateGroupsManager), typeof(StateManager), new PropertyMetadata((d, e) => {
|
||||
if (d is FrameworkElement el && e.NewValue is StateGroupsManager m)
|
||||
m.SetCurrentValue(StateGroupsManager.TargetProperty, el);
|
||||
}));
|
||||
|
||||
public static StateGroupsManager GetGroups(DependencyObject d) => d.GetValue(GroupsProperty) as StateGroupsManager;
|
||||
public static void SetGroups(DependencyObject d, StateGroupsManager value) => d.SetValue(GroupsProperty, value);
|
||||
|
||||
Reference in new issue
Block a user