Manual merge of last 2 weeks
This commit is contained in:
1 parent
27bbb305fc
commit
d632dbd937
159 files changed
+8108
-4464
No files matched your search
@@ -1,492 +1,492 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mbts="clr-namespace:mbts.ui"
|
||||
xmlns:control="clr-namespace:mbts.ui.controls"
|
||||
xmlns:shell="clr-namespace:mbts.ui.shell">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/uicore/images/vector/icons.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DefinedColors.xaml"/>
|
||||
<ResourceDictionary Source="/view/Colors.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/Buttons.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/ComboBoxes.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/MenuItems.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ObservableItemsControl/ObservableComboBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DragDropItemsControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableContentControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DragDropListBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableListBoxItem.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKCancel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKApplyCancel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ComboCheckBox/ComboCheckBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/MultiSelectDropDown.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/PriceEntryControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/BusySpinner.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/RangeFilter.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/Time/DateTimePicker.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/Time/TimeFilterControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/WindowStyle.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/LogViewer.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DataGrid.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/TickUpDown/TickUpDown.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/TextBoxEx.xaml" />
|
||||
<!--<ResourceDictionary Source="/view/Controls/TickEntryControl/TickEntryControl.xaml" />-->
|
||||
<!--<ResourceDictionary Source="/view/Controls/ExpirationLabel/ExpirationLabel.xaml" />-->
|
||||
<!--<ResourceDictionary Source="/view/Controls/SecurityLabel/SecurityLabel.xaml" />-->
|
||||
<ResourceDictionary Source="/view/Controls/SecurityLabel/SecurityTupleLabel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/RadioButtonsControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DIYGrid/DIYGridresources.xaml" />
|
||||
|
||||
<ResourceDictionary Source="/view/Shell/Report/CommonControls/VolShiftControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Shell/Report/CommonControls/DriverShiftControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ObjectEditor/ObjectEditor.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<!-- Override xp/win7 style themes with Win8 style flat for certain controls -->
|
||||
|
||||
<Style x:Key="FocusVisual">
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFF0F0F0" Offset="0.0"/>
|
||||
<GradientStop Color="#FFE5E5E5" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Border" Color="#FFACACAC"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FFABADB3"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFECF4FC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFEBF4FC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#FF000000"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFDAECFC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFC4E0FC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#FF569DE5"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#FF569DE5"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFDAEBFC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFC4E0FC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF606060"/>
|
||||
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
<Setter Property="IsTabStop" Value="false"/>
|
||||
<Setter Property="Focusable" Value="false"/>
|
||||
<Setter Property="ClickMode" Value="Press"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource ComboBox.Static.Background}" SnapsToDevicePixels="true">
|
||||
<Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
|
||||
<Path x:Name="arrow" 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="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsPressed" Value="true">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1"
|
||||
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
|
||||
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
|
||||
<ScrollViewer x:Name="DropDownScrollViewer">
|
||||
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
|
||||
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasItems" Value="false">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
|
||||
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF"/>
|
||||
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
<Setter Property="AllowDrop" Value="true"/>
|
||||
<Setter Property="MinWidth" Value="0"/>
|
||||
<Setter Property="MinHeight" Value="0"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TextBox}">
|
||||
<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
|
||||
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
|
||||
<ScrollViewer x:Name="DropDownScrollViewer">
|
||||
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
|
||||
<Border x:Name="border" Background="{StaticResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}">
|
||||
<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocusWithin" Value="true">
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="false">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
|
||||
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="{x:Type ComboBox}">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
|
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
|
||||
<Setter Property="Padding" Value="6,3,5,3"/>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEditable" Value="true">
|
||||
<Setter Property="IsTabStop" Value="false"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type CheckBox}">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
|
||||
<Setter Property="Background" Value="#FFFFFFFF"/>
|
||||
<Setter Property="BorderBrush" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type CheckBox}">
|
||||
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="checkBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
|
||||
<Grid x:Name="markGrid">
|
||||
<Path x:Name="optionMark" Data="F1 M 9.97498,1.22334L 4.6983,9.09834L 4.52164,9.09834L 0,5.19331L 1.27664,3.52165L 4.255,6.08833L 8.33331,1.52588e-005L 9.97498,1.22334 Z " Fill="#FF212121" Margin="1" Opacity="0" Stretch="None"/>
|
||||
<Rectangle x:Name="indeterminateMark" Fill="#FF212121" Margin="2" Opacity="0"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasContent" Value="true">
|
||||
<Setter Property="FocusVisualStyle">
|
||||
<Setter.Value>
|
||||
<Style>
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Padding" Value="4,-1,0,0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFF3F9FF"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFE6E6E6"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF707070"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF707070"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="true">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFD9ECFF"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FF3C77DD"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="true">
|
||||
<Setter Property="Opacity" TargetName="optionMark" Value="1"/>
|
||||
<Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="{x:Null}">
|
||||
<Setter Property="Opacity" TargetName="optionMark" Value="0"/>
|
||||
<Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="SelectableTabsTemplate" TargetType="TabItem">
|
||||
<Border>
|
||||
<Grid>
|
||||
<Border x:Name="border" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock x:Name="label" Text="{TemplateBinding Header}"/>
|
||||
<TextBlock x:Name="check" Text="✓" Foreground="{mbts:BTSColor Name=header_text}" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="label" Property="Foreground" Value="Black"/>
|
||||
<Setter TargetName="check" Property="Visibility" Value="Visible"/>
|
||||
<Setter TargetName="label" Property="FontWeight" Value="Bold"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="False">
|
||||
<Setter TargetName="label" Property="Foreground" Value="Gray"/>
|
||||
<Setter TargetName="check" Property="Visibility" Value="Hidden"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<DataTemplate x:Key="checkbox_template">
|
||||
<CheckBox Content="{Binding name}" IsChecked="{Binding is_selected}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<Style TargetType="{x:Type control:TextBoxListDoubles}" BasedOn="{StaticResource {x:Type TextBox}}" />
|
||||
|
||||
<ItemsPanelTemplate x:Key="TopBottomLeftRightFlow">
|
||||
<WrapPanel IsItemsHost="True" Orientation="Vertical" FlowDirection="LeftToRight"/>
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
<HierarchicalDataTemplate x:Key="ShellLaunchWithDeleteItemTemplate" DataType="control:LaunchItemWithDelete">
|
||||
<Button Height="32" Command="{Binding launch}" Style="{DynamicResource StartMenuButton}" Foreground="{DynamicResource StartMenuForeground}" HorizontalAlignment="Stretch" MinWidth="190" Padding="4">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding name}" VerticalAlignment="Center" Margin="4,0,7,0" />
|
||||
<Button Grid.Column="1" Style="{StaticResource RoundCloseButton}" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding delete}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
<HierarchicalDataTemplate x:Key="ShellHierarchicalGroupItemTemplate" DataType="control:GroupItem" ItemsSource="{Binding Value}" >
|
||||
<TextBlock Text="{Binding Key}" Margin="4,6,4,4" />
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
<Style TargetType="{x:Type control:BTSListBoxItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type control:BTSListBoxItem}">
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="LightBlue"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="LightBlue" Opacity="0.5"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
<!--<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsSelected" Value="true" />
|
||||
<Condition Property="IsSelectionActive" Value="false" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter TargetName="Bd" Value="{DynamicResource {x:Static ControlBrush}}" Property="Background" />
|
||||
<Setter Value="{DynamicResource {x:Static ControlTextBrush}}" Property="Foreground" />
|
||||
</MultiTrigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Value="{DynamicResource {x:Static GrayTextBrush}}" Property="Foreground" />
|
||||
</Trigger>-->
|
||||
</ControlTemplate.Triggers>
|
||||
<Border Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="BoldHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="Bold"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SemiBoldHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="SemiBold"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SemiBoldItalicHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="SemiBold" FontStyle="Italic"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="ItalicHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontStyle="Italic"/>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mbts="clr-namespace:mbts.ui"
|
||||
xmlns:control="clr-namespace:mbts.ui.controls">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/uicore/Images/Vector/Icons.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DefinedColors.xaml"/>
|
||||
<ResourceDictionary Source="/view/Colors.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/Buttons.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/ComboBoxes.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/MenuItems.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ObservableItemsControl/ObservableComboBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DragDropItemsControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableContentControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DragDropListBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableListBoxItem.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKCancel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKApplyCancel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ComboCheckBox/ComboCheckBox.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/MultiSelectDropDown.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/BusySpinner.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/RangeFilter.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/Time/DateTimePicker.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/Time/TimeFilterControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/WindowStyle.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/LogViewer.xaml" />
|
||||
<ResourceDictionary Source="/view/Resources/DataGrid.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/TickUpDown/TickUpDown.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/TextBoxEx.xaml" />
|
||||
<!--<ResourceDictionary Source="/view/Controls/TickEntryControl/TickEntryControl.xaml" />-->
|
||||
<!--<ResourceDictionary Source="/view/Controls/ExpirationLabel/ExpirationLabel.xaml" />-->
|
||||
<!--<ResourceDictionary Source="/view/Controls/SecurityLabel/SecurityLabel.xaml" />-->
|
||||
<ResourceDictionary Source="/view/Controls/SecurityLabel/SecurityTupleLabel.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/RadioButtonsControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/DIYGrid/DIYGridresources.xaml" />
|
||||
|
||||
<ResourceDictionary Source="/view/Shell/Report/CommonControls/VolShiftControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Shell/Report/CommonControls/DriverShiftControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/ObjectEditor/ObjectEditor.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/NumberPad.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/PriceEntryControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AlgoTypeItem.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<!-- Override xp/win7 style themes with Win8 style flat for certain controls -->
|
||||
|
||||
<Style x:Key="FocusVisual">
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFF0F0F0" Offset="0.0"/>
|
||||
<GradientStop Color="#FFE5E5E5" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Border" Color="#FFACACAC"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FFABADB3"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFECF4FC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFEBF4FC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#FF000000"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFDAECFC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFC4E0FC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#FF569DE5"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#FF569DE5"/>
|
||||
<LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFDAEBFC" Offset="0.0"/>
|
||||
<GradientStop Color="#FFC4E0FC" Offset="1.0"/>
|
||||
</LinearGradientBrush>
|
||||
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/>
|
||||
<SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF606060"/>
|
||||
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
<Setter Property="IsTabStop" Value="false"/>
|
||||
<Setter Property="Focusable" Value="false"/>
|
||||
<Setter Property="ClickMode" Value="Press"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource ComboBox.Static.Background}" SnapsToDevicePixels="true">
|
||||
<Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
|
||||
<Path x:Name="arrow" 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="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsPressed" Value="true">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
|
||||
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/>
|
||||
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
|
||||
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/>
|
||||
</MultiDataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1"
|
||||
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
|
||||
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
|
||||
<ScrollViewer x:Name="DropDownScrollViewer">
|
||||
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
|
||||
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasItems" Value="false">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
|
||||
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF"/>
|
||||
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="true"/>
|
||||
<Setter Property="AllowDrop" Value="true"/>
|
||||
<Setter Property="MinWidth" Value="0"/>
|
||||
<Setter Property="MinHeight" Value="0"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TextBox}">
|
||||
<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
|
||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
|
||||
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
|
||||
<ScrollViewer x:Name="DropDownScrollViewer">
|
||||
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
<ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
|
||||
<Border x:Name="border" Background="{StaticResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}">
|
||||
<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocusWithin" Value="true">
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="false">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="true"/>
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
|
||||
</MultiTrigger>
|
||||
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
|
||||
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="{x:Type ComboBox}">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
|
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
|
||||
<Setter Property="Padding" Value="6,3,5,3"/>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEditable" Value="true">
|
||||
<Setter Property="IsTabStop" Value="false"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type CheckBox}">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
|
||||
<Setter Property="Background" Value="#FFFFFFFF"/>
|
||||
<Setter Property="BorderBrush" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type CheckBox}">
|
||||
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="checkBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
|
||||
<Grid x:Name="markGrid">
|
||||
<Path x:Name="optionMark" Data="F1 M 9.97498,1.22334L 4.6983,9.09834L 4.52164,9.09834L 0,5.19331L 1.27664,3.52165L 4.255,6.08833L 8.33331,1.52588e-005L 9.97498,1.22334 Z " Fill="#FF212121" Margin="1" Opacity="0" Stretch="None"/>
|
||||
<Rectangle x:Name="indeterminateMark" Fill="#FF212121" Margin="2" Opacity="0"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasContent" Value="true">
|
||||
<Setter Property="FocusVisualStyle">
|
||||
<Setter.Value>
|
||||
<Style>
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Padding" Value="4,-1,0,0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFF3F9FF"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFE6E6E6"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF707070"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF707070"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="true">
|
||||
<Setter Property="Background" TargetName="checkBoxBorder" Value="#FFD9ECFF"/>
|
||||
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FF3C77DD"/>
|
||||
<Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/>
|
||||
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="true">
|
||||
<Setter Property="Opacity" TargetName="optionMark" Value="1"/>
|
||||
<Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="{x:Null}">
|
||||
<Setter Property="Opacity" TargetName="optionMark" Value="0"/>
|
||||
<Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="SelectableTabsTemplate" TargetType="TabItem">
|
||||
<Border>
|
||||
<Grid>
|
||||
<Border x:Name="border" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock x:Name="label" Text="{TemplateBinding Header}"/>
|
||||
<TextBlock x:Name="check" Text="✓" Foreground="{mbts:BTSColor Name=header_text}" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="label" Property="Foreground" Value="Black"/>
|
||||
<Setter TargetName="check" Property="Visibility" Value="Visible"/>
|
||||
<Setter TargetName="label" Property="FontWeight" Value="Bold"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="False">
|
||||
<Setter TargetName="label" Property="Foreground" Value="Gray"/>
|
||||
<Setter TargetName="check" Property="Visibility" Value="Hidden"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<DataTemplate x:Key="checkbox_template">
|
||||
<CheckBox Content="{Binding name}" IsChecked="{Binding is_selected}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<Style TargetType="{x:Type control:TextBoxListDoubles}" BasedOn="{StaticResource {x:Type TextBox}}" />
|
||||
|
||||
<ItemsPanelTemplate x:Key="TopBottomLeftRightFlow">
|
||||
<WrapPanel IsItemsHost="True" Orientation="Vertical" FlowDirection="LeftToRight"/>
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
<HierarchicalDataTemplate x:Key="ShellLaunchWithDeleteItemTemplate" DataType="control:LaunchItemWithDelete">
|
||||
<Button Height="32" Command="{Binding launch}" Style="{DynamicResource StartMenuButton}" Foreground="{DynamicResource StartMenuForeground}" HorizontalAlignment="Stretch" MinWidth="190" Padding="4">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding name}" VerticalAlignment="Center" Margin="4,0,7,0" />
|
||||
<Button Grid.Column="1" Style="{StaticResource RoundCloseButton}" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding delete}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
<HierarchicalDataTemplate x:Key="ShellHierarchicalGroupItemTemplate" DataType="control:GroupItem" ItemsSource="{Binding Value}" >
|
||||
<TextBlock Text="{Binding Key}" Margin="4,6,4,4" />
|
||||
</HierarchicalDataTemplate>
|
||||
|
||||
<Style TargetType="{x:Type control:BTSListBoxItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type control:BTSListBoxItem}">
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="LightBlue"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="LightBlue" Opacity="0.5"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
<!--<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsSelected" Value="true" />
|
||||
<Condition Property="IsSelectionActive" Value="false" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter TargetName="Bd" Value="{DynamicResource {x:Static ControlBrush}}" Property="Background" />
|
||||
<Setter Value="{DynamicResource {x:Static ControlTextBrush}}" Property="Foreground" />
|
||||
</MultiTrigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Value="{DynamicResource {x:Static GrayTextBrush}}" Property="Foreground" />
|
||||
</Trigger>-->
|
||||
</ControlTemplate.Triggers>
|
||||
<Border Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
|
||||
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="BoldHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="Bold"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SemiBoldHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="SemiBold"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SemiBoldItalicHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontWeight="SemiBold" FontStyle="Italic"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="ItalicHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" FontStyle="Italic"/>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -16,6 +16,10 @@ namespace System.Collections.Generic
|
||||
public static IEnumerable<T> DistinctOn<T, TKey>(this IEnumerable<T> enumerable, Func<T, TKey> key_selector) {
|
||||
return enumerable.Distinct(new AnonymousEqualityComparer<T>((x, y) => key_selector(x).Equals(key_selector(y)), x => key_selector(x).GetHashCode()));
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Intersect<T, TKey>(this IEnumerable<T> enumerable, IEnumerable<TKey> intersection, Func<T, TKey> key_selector) {
|
||||
return enumerable.Where(t => intersection.Contains(key_selector(t)));
|
||||
}
|
||||
}
|
||||
|
||||
public static class DictionaryExtensions
|
||||
@@ -49,6 +53,25 @@ namespace System.Collections.Generic
|
||||
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static bool Pop<T, TKey>(this IList<T> list, TKey key, Func<T, TKey> key_selector, out T result) {
|
||||
for(int i = 0; i < list.Count; i++) {
|
||||
if (key_selector(list[i]).Equals(key)) {
|
||||
result = list[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = default(T);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool PopDispose<T, TKey>(this IList<T> list, TKey key, Func<T, TKey> key_selector) where T : IDisposable {
|
||||
if (list.Pop(key, key_selector, out T result)) {
|
||||
result.Dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static T Pop<T>(this IList<T> list, int index) {
|
||||
T rv = list.ElementAt(index);
|
||||
list.RemoveAt(index);
|
||||
@@ -149,9 +172,13 @@ namespace mbts.collections.extensions
|
||||
|
||||
public static class DictionaryExtensions
|
||||
{
|
||||
//public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) {
|
||||
// return dictionary.TryGetValue(key, out TValue result) ? result : default(TValue);
|
||||
//}
|
||||
public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) {
|
||||
return dictionary.TryGetValue(key, out TValue result) ? result : default(TValue);
|
||||
}
|
||||
|
||||
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) {
|
||||
return dictionary.TryGetValue(key, out TValue result) ? result : default(TValue);
|
||||
}
|
||||
|
||||
public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue error_val) {
|
||||
return dictionary.TryGetValue(key, out TValue result) ? result : error_val;
|
||||
@@ -162,11 +189,4 @@ namespace mbts.collections.extensions
|
||||
else dictionary.Add(key, create_new());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReadOnlyDictionaryExtensions
|
||||
{
|
||||
public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) {
|
||||
return dictionary.TryGetValue(key, out TValue result) ? result : default(TValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -426,6 +426,10 @@ namespace System.Reactive.Linq
|
||||
IObservable<bool> alive = source.Select(_ => true);
|
||||
return dead.Merge(alive).DistinctUntilChanged();
|
||||
}
|
||||
|
||||
public static IObservable<(TSource prev, TSource curr)> PairWithPrevious<TSource>(this IObservable<TSource> source) {
|
||||
return source.Scan<TSource, (TSource prev, TSource curr)>((default(TSource), default(TSource)), (last, next) => (last.curr, next));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using bts.api;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.core
|
||||
{
|
||||
@@ -22,7 +20,7 @@ namespace bts.core
|
||||
if (inst.TryGetValue(tag, out ISubject<T> result)) {
|
||||
return result;
|
||||
}
|
||||
result = new Subject<T>();
|
||||
result = new StateSubject<T>();
|
||||
inst[tag] = result;
|
||||
return result;
|
||||
}
|
||||
@@ -36,4 +34,4 @@ namespace bts.core
|
||||
return subject<T>(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,22 @@ namespace mbts.utils
|
||||
{
|
||||
public static class CompareUtils
|
||||
{
|
||||
#region Equality
|
||||
public static IEqualityComparer<T> NullCheckEqualityComparer<T>(Func<T, T, bool> never_null_equals, Func<T, int> get_hash_code) {
|
||||
return EqualityComparer.Create(NullCheckEquality(never_null_equals), get_hash_code);
|
||||
}
|
||||
public static Func<T, T, bool> NullCheckEquality<T>(Func<T, T, bool> never_null_equals) {
|
||||
return (x, y) => NullCheckEquals(x, y, never_null_equals);
|
||||
}
|
||||
public static bool NullCheckEquals<T>(T x, T y) {
|
||||
return NullCheckEquals(x, y, (_x, _y) => _x.Equals(_y));
|
||||
}
|
||||
public static bool NullCheckEquals<T>(T x, T y, Func<T, T, bool> never_null_equals) {
|
||||
return x == null ? y == null : y == null ? false : never_null_equals(x, y);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Comparison
|
||||
public static Comparison<T> NullCheckComparison<T>(Comparison<T> never_null_comparison) where T : class {
|
||||
return new Comparison<T>((x, y) => NullCheckCompare(x, y, never_null_comparison));
|
||||
}
|
||||
@@ -14,5 +30,6 @@ namespace mbts.utils
|
||||
public static int NullCheckCompare<T>(T x, T y, Comparison<T> never_null_comparison) where T : class {
|
||||
return x == null ? y == null ? 0 : -1 : y == null ? 1 : never_null_comparison(x, y);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Subscribes to the source and stores the latest valule internally. All subscription sequences begin with the latest value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class StatePublisher<T> : IObservable<T>, IDisposable
|
||||
{
|
||||
public StatePublisher(IObservable<T> source) {
|
||||
_publisher = source.Select(val => {
|
||||
lock (_lock) {
|
||||
_value_initialized = true;
|
||||
return _last_value = val;
|
||||
}
|
||||
}).Publish();
|
||||
_connection = _publisher.Connect();
|
||||
}
|
||||
|
||||
private readonly IConnectableObservable<T> _publisher;
|
||||
private readonly IDisposable _connection;
|
||||
private readonly object _lock = new object();
|
||||
private bool _value_initialized;
|
||||
private T _last_value;
|
||||
|
||||
public IDisposable Subscribe(IObserver<T> observer) {
|
||||
lock(_lock) return (_value_initialized ? _publisher.StartWith(_last_value) : _publisher).Subscribe(observer);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.utils
|
||||
{
|
||||
public class StateSubject<T> : ISubject<T>, IDisposable
|
||||
{
|
||||
public StateSubject() {
|
||||
_publisher = new StatePublisher<T>(_subject);
|
||||
}
|
||||
|
||||
private readonly Subject<T> _subject = new Subject<T>();
|
||||
private readonly StatePublisher<T> _publisher;
|
||||
|
||||
#region ISubject
|
||||
public void OnNext(T value) { _subject.OnNext(value); }
|
||||
public void OnError(Exception error) { _subject.OnError(error); }
|
||||
public void OnCompleted() { _subject.OnCompleted(); }
|
||||
public IDisposable Subscribe(IObserver<T> observer) { return _publisher.Subscribe(observer); }
|
||||
#endregion
|
||||
|
||||
public void Dispose() {
|
||||
_subject.OnCompleted();
|
||||
_publisher.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ namespace mbts.spark
|
||||
{ Order.AlgoOrderTypeOneofCase.StopLimitOrder, typeof(orders.StopLimitOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.StopMarketOrder, typeof(orders.StopMarketOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder, typeof(orders.CrossingHedgeOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder, typeof(orders.SimpleHedgeOrderActor) },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -53,9 +53,9 @@ namespace mbts.spark.orders
|
||||
{
|
||||
if(_status != null)
|
||||
{
|
||||
PriceSize bid_or_ask;
|
||||
PriceSize bid_or_ask;
|
||||
if(_status.Order.Side == BuySell.Buy)
|
||||
bid_or_ask = bbo.Item2;
|
||||
bid_or_ask = bbo.Item2;
|
||||
else
|
||||
bid_or_ask = bbo.Item1;
|
||||
|
||||
@@ -64,6 +64,10 @@ namespace mbts.spark.orders
|
||||
{
|
||||
_exchange.modify_price(_order.Id, bid_or_ask.price);
|
||||
}
|
||||
|
||||
uint distance = Convert.ToUInt32(Math.Abs(bid_or_ask.price - _status.Order.Price) / compute_tick(_order.Security));
|
||||
if(distance > _order.CrossingHedgeOrder.TicksBetterThreshold)
|
||||
_exchange.modify_price(_order.Id, bid_or_ask.price);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-13
@@ -13,9 +13,13 @@ namespace mbts.spark.orders
|
||||
{
|
||||
class SyntheticLimitOrder : SyntheticOrderBase, ICancelable, IModifiable, IPausable, ICrackable, IPollable
|
||||
{
|
||||
bool _paused;
|
||||
bool _paused;
|
||||
double _order_price;
|
||||
uint _order_size;
|
||||
public SyntheticLimitOrder(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
{
|
||||
_order_price = order.Price;
|
||||
_order_size = order.Size;
|
||||
}
|
||||
|
||||
protected override void on_book_change(BookType book)
|
||||
@@ -28,7 +32,7 @@ namespace mbts.spark.orders
|
||||
{
|
||||
if(!_books.Values.Any(x => x == null))
|
||||
{
|
||||
foreach(Security sec in _leg_sizes.Keys)
|
||||
foreach(Security sec in _leg_ratios.Keys)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
_execution_strategy.TryGetValue(sec.Id, out param);
|
||||
@@ -41,12 +45,15 @@ namespace mbts.spark.orders
|
||||
{
|
||||
if(size == 0)
|
||||
{
|
||||
reduce_working(sec, 0, side, null, true);
|
||||
clear_working(sec, side);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(current_order == null) //no current order, send one
|
||||
spawn_limit_order(sec, size, price, side, _order.TimeInForce);
|
||||
{
|
||||
var ord = spawn_limit_order(sec, size, price, side, _order.TimeInForce);
|
||||
track_child(ord);
|
||||
}
|
||||
else
|
||||
update_existing_order(current_order, price, size, side, this_leg_book, param, bypass_quote_rules);
|
||||
}
|
||||
@@ -67,7 +74,7 @@ namespace mbts.spark.orders
|
||||
if(is_done_state(status.Status) || is_problem_state(status.Status))
|
||||
return;
|
||||
|
||||
if(new_size > status.Order.Size || bypass_quote_rules)
|
||||
if(new_size != status.Order.Size && bypass_quote_rules)
|
||||
current_order.modify_size(new_size);
|
||||
|
||||
double tick = compute_tick(current_order.security);
|
||||
@@ -100,17 +107,17 @@ namespace mbts.spark.orders
|
||||
out BuySell final_side, out IReadOnlyList<PriceSize> this_leg_book)
|
||||
{
|
||||
//this is the price we want the spread, this algorithm works backwards from this price to get the price of the quote leg
|
||||
final_price = _order.Price * -1.0; //-4 means a credit
|
||||
final_price = _order_price * -1.0; //-X means credit
|
||||
final_size = 0;
|
||||
final_side = BuySell.Buy;
|
||||
this_leg_book = null;
|
||||
bool hit_myself = false;
|
||||
foreach(Security sec in _leg_sizes.Keys)
|
||||
foreach(Security sec in _leg_ratios.Keys)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
if(!_execution_strategy.TryGetValue(sec.Id, out param))
|
||||
return false;
|
||||
double quote_size = _leg_sizes[sec];
|
||||
double quote_size = _leg_ratios[sec] * _order_size;
|
||||
|
||||
if(leg.Equals(sec)) //this leg -- do sizing
|
||||
{
|
||||
@@ -141,7 +148,7 @@ namespace mbts.spark.orders
|
||||
else
|
||||
bid_or_ask_book = _books[sec].Item1;
|
||||
double leg_price = 0.0; bool ok = false;
|
||||
uint looking_for_size = Convert.ToUInt32(Math.Abs(quote_size) * param.QuoteParams.HedgeRatio);
|
||||
uint looking_for_size = Convert.ToUInt32(Math.Abs(quote_size) * param.QuoteParams.LeanQuantityRatio);
|
||||
uint size_counter = looking_for_size;
|
||||
foreach(var level in bid_or_ask_book)
|
||||
{
|
||||
@@ -192,15 +199,14 @@ namespace mbts.spark.orders
|
||||
|
||||
bool IModifiable.on_modify_price(double new_price)
|
||||
{
|
||||
_order.Price = new_price;
|
||||
_order_price = new_price;
|
||||
requote(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_size(uint new_size)
|
||||
{
|
||||
_order.Size = new_size;
|
||||
flatten_synthetic(_order, out _leg_sizes, out _price_mults);
|
||||
_order_size = new_size;
|
||||
requote(true);
|
||||
return true;
|
||||
}
|
||||
+2
-2
@@ -20,7 +20,7 @@ namespace mbts.spark.orders
|
||||
override public void on_spawn()
|
||||
{
|
||||
base.on_spawn();
|
||||
foreach(var kv in _leg_sizes)
|
||||
foreach(var kv in _leg_ratios)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
if(_execution_strategy.TryGetValue(kv.Key.Id, out param))
|
||||
@@ -28,7 +28,7 @@ namespace mbts.spark.orders
|
||||
if(param.QuoteParams.IsWorking)
|
||||
{
|
||||
BuySell side = kv.Value > 0.0 ? BuySell.Buy : BuySell.Sell;
|
||||
uint size = Convert.ToUInt32(Math.Abs(kv.Value));
|
||||
uint size = Convert.ToUInt32(Math.Abs(kv.Value * _order.Size));
|
||||
spawn_market_order(kv.Key, size, side, _order.TimeInForce);
|
||||
//break; //only send market for one working leg, the rest should come out in the hedge
|
||||
}
|
||||
+67
-49
@@ -16,15 +16,15 @@ namespace mbts.spark.orders
|
||||
{
|
||||
readonly protected object _destroy_lock = new object();
|
||||
readonly protected IMarketDataSource _md;
|
||||
protected IDictionary<Security, double> _leg_sizes;
|
||||
protected IDictionary<Security, double> _leg_ratios;
|
||||
protected IDictionary<Security, double> _price_mults;
|
||||
readonly protected IDictionary<Security, BookType> _books = new ConcurrentDictionary<Security, BookType>();
|
||||
readonly protected IDictionary<Security, HedgeInfo> _hedge_info = new ConcurrentDictionary<Security, HedgeInfo>();
|
||||
readonly protected ConcurrentBag<OrderID> _hedges = new ConcurrentBag<OrderID>();
|
||||
public SyntheticOrderBase(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
flatten_synthetic(order, out _leg_sizes, out _price_mults);
|
||||
foreach(var ven in _leg_sizes.Keys) //TODO: Multi exchange
|
||||
flatten_synthetic(order, out _leg_ratios, out _price_mults);
|
||||
foreach(var ven in _leg_ratios.Keys) //TODO: Multi exchange
|
||||
fabric.find_wellknown_service<IMarketDataSource>(ven.Exchange, out _md);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mbts.spark.orders
|
||||
|
||||
override public void on_spawn()
|
||||
{
|
||||
foreach(var sec in _leg_sizes.Keys)
|
||||
foreach(var sec in _leg_ratios.Keys)
|
||||
{
|
||||
_books[sec] = null;
|
||||
_disposables.Add(_md.subscribe_depth(sec).Subscribe(x =>
|
||||
@@ -69,43 +69,54 @@ namespace mbts.spark.orders
|
||||
|
||||
protected override void on_child_fill(Fill fill, ref Fill merged_fill)
|
||||
{
|
||||
lock(_destroy_lock)
|
||||
{
|
||||
if(!reduce_working(fill.Order.Security, fill.Size, fill.Side, fill.Order.Id) &&
|
||||
!_hedges.Contains(fill.Order.Id))
|
||||
{
|
||||
hedge_working_order(fill);
|
||||
}
|
||||
reduce_and_hedge(fill).ContinueWith( _ => { });
|
||||
}
|
||||
|
||||
protected void clear_working(Security sec, BuySell side)
|
||||
{
|
||||
reduce_working(sec, 0, side, null, true).ContinueWith(_ => { });
|
||||
}
|
||||
|
||||
async Task reduce_and_hedge(Fill fill)
|
||||
{
|
||||
//if this fill was not because of a hedge, fire a hedge
|
||||
if(!_hedges.Contains(fill.Order.Id))
|
||||
{
|
||||
//send a hedge
|
||||
await hedge_working_order(fill);
|
||||
//await reduce_working(fill.Order.Security, fill.Size, fill.Side, fill.Order.Id);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool reduce_working(Security sec, uint size, BuySell side, OrderID oid = null, bool all = false)
|
||||
|
||||
protected async Task<bool> reduce_working(Security sec, uint size, BuySell side, OrderID oid = null, bool all = false)
|
||||
{
|
||||
bool gotone = false;
|
||||
var existing = _child_status.Where(x => x.Value.Order.Security.Equals(sec) && x.Value.Order.Side == side);
|
||||
existing.ForEach(x =>
|
||||
{
|
||||
if(!x.Key.Equals(oid ?? new OrderID()))
|
||||
{
|
||||
IOrderHandle existing_working;
|
||||
if(_children.TryGetValue(x.Key, out existing_working))
|
||||
{
|
||||
gotone = true;
|
||||
if(all || size >= x.Value.Order.Size)
|
||||
existing_working.cancel();
|
||||
else
|
||||
{
|
||||
UInt32 new_size = x.Value.Order.Size - size;
|
||||
existing_working.modify_size(new_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var existing = _child_status.Where(x => x.Value.Order.Security.Equals(sec) &&
|
||||
x.Value.Order.Side == side &&
|
||||
!_hedges.Contains(x.Key) );
|
||||
foreach(var x in existing)
|
||||
{
|
||||
if(!x.Key.Equals(oid ?? new OrderID()))
|
||||
{
|
||||
IOrderHandle existing_working;
|
||||
if(_children.TryGetValue(x.Key, out existing_working))
|
||||
{
|
||||
gotone = true;
|
||||
if(all || size >= x.Value.Order.Size)
|
||||
await existing_working.cancel();
|
||||
else
|
||||
{
|
||||
UInt32 new_size = x.Value.Order.Size - size;
|
||||
await existing_working.modify_size(new_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return gotone;
|
||||
}
|
||||
|
||||
|
||||
async void hedge_working_order(Fill fill)
|
||||
async Task hedge_working_order(Fill fill)
|
||||
{
|
||||
if(_order.Security.Equals(fill.Order.Security))
|
||||
return; //don't hedge yourself if you are a synthetic
|
||||
@@ -115,38 +126,45 @@ namespace mbts.spark.orders
|
||||
continue; //don't hedge yourself
|
||||
|
||||
var hedge_side = (kv.Value.size > 0.0) ? BuySell.Buy : BuySell.Sell;
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(kv.Value.size) * fill.Size / fill.Order.Size);
|
||||
double ratio = _leg_ratios[kv.Key];
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(ratio) * fill.Size);
|
||||
double hedge_price = kv.Value.price;
|
||||
hedge_price = compute_hedge_price(kv.Value.leg, hedge_side, hedge_size, kv.Value.leg_params, hedge_price);
|
||||
|
||||
//look for existing
|
||||
var existing = _child_status.Where(x => x.Value.Order.Security.Equals(kv.Key) &&
|
||||
x.Value.Order.Side == hedge_side &&
|
||||
x.Value.Order.Price == hedge_price);
|
||||
if(existing.Any())
|
||||
{
|
||||
var existing_status = existing.First();
|
||||
IOrderHandle existing_order;
|
||||
if(_children.TryGetValue(existing_status.Key, out existing_order))
|
||||
{
|
||||
var res = await existing_order.modify_size(existing_status.Value.Order.Size + hedge_size);
|
||||
if(res.result)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//var existing = _child_status.Where(x => x.Value.Order.Security.Equals(kv.Key) &&
|
||||
// x.Value.Order.Side == hedge_side &&
|
||||
// x.Value.Order.Price == hedge_price);
|
||||
|
||||
//if(existing.Any())
|
||||
//{
|
||||
// var existing_status = existing.First();
|
||||
// IOrderHandle existing_order;
|
||||
// if(_children.TryGetValue(existing_status.Key, out existing_order))
|
||||
// {
|
||||
// var res = await existing_order.modify_size(existing_status.Value.Order.Size + hedge_size);
|
||||
// if(res.result)
|
||||
// continue;
|
||||
// }
|
||||
//}
|
||||
|
||||
double tick = compute_tick(kv.Key);
|
||||
var post = kv.Value.leg_params.HedgeParams.PostHedgeRules;
|
||||
var cross = new CrossingHedgeOrder
|
||||
{
|
||||
CrossSizeThreshold = post == null ? 0 : post.CrossSizeThreshold,
|
||||
CrossRatioThreshold = post == null ? 1.0 : post.CrossRatioThreshold,
|
||||
TicksBetterThreshold = Convert.ToUInt32(Math.Abs(hedge_price - kv.Value.price) / tick),
|
||||
};
|
||||
|
||||
var hedge = create_order<CrossingHedgeOrder>(kv.Value.leg, hedge_size, hedge_price,
|
||||
hedge_side, Order.Types.TimeInForce.Day, cross);
|
||||
_hedges.Add(hedge.order_id);
|
||||
track_child(hedge.order_id, hedge);
|
||||
track_child(hedge);
|
||||
await hedge.spawn();
|
||||
//reduce any working quantity by the amount of the hedge
|
||||
//initially I meant to reduce working on hedge fills, but now that I see it in action, there's too many orders out if we do it that way
|
||||
await reduce_working(kv.Value.leg, hedge_size, hedge_side);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace mbts.spark.orders
|
||||
class LimitOrderActor : IActor, ICancelable, IModifiable, IPausable, ICrackable, IPollable,
|
||||
IOrderStatusProducer, IFillProducer
|
||||
{
|
||||
readonly OrderActorBase _impl;
|
||||
readonly SimpleOrderBase _impl;
|
||||
readonly ICancelable _cancel;
|
||||
readonly IModifiable _modify;
|
||||
readonly IPausable _pause;
|
||||
@@ -22,8 +22,9 @@ namespace mbts.spark.orders
|
||||
throw new NotSupportedException("Limit order doesn't support SecurityType == None");
|
||||
else if(order.Security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
{
|
||||
var algo = new SyntheticLimitOrder(fabric, order);
|
||||
_impl = algo; _cancel = algo; _modify = algo; _pause = algo; _crack = algo; _poll = algo;
|
||||
var algo = new SimpleSyntheticLimitOrder(fabric, order);
|
||||
//var algo = new SyntheticLimitOrder(fabric, order);
|
||||
_impl = algo; _cancel = algo; _modify = algo; _pause = null; _crack = null; _poll = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -11,13 +11,8 @@ using bts.spark;
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
abstract class OrderActorBase : IActor, IOrderStatusProducer, IFillProducer
|
||||
{
|
||||
readonly IOrderIDGenerator _generator;
|
||||
protected readonly IActorFabric _fabric;
|
||||
protected readonly Order _order;
|
||||
|
||||
readonly protected List<IDisposable> _disposables = new List<IDisposable>();
|
||||
abstract class OrderActorBase : SimpleOrderBase
|
||||
{
|
||||
readonly protected ConcurrentDictionary<OrderID, IOrderHandle> _children = new ConcurrentDictionary<OrderID, IOrderHandle>();
|
||||
readonly protected ConcurrentDictionary<OrderID, IOrderHandle> _ex_children = new ConcurrentDictionary<OrderID, IOrderHandle>();
|
||||
readonly protected ConcurrentDictionary<OrderID, OrderStatus> _child_status = new ConcurrentDictionary<OrderID, OrderStatus>();
|
||||
@@ -25,54 +20,12 @@ namespace mbts.spark.orders
|
||||
readonly protected ConcurrentBag<Fill> _child_fills = new ConcurrentBag<Fill>();
|
||||
readonly protected ConcurrentDictionary<uint, SyntheticLegExecutionParams> _execution_strategy = new ConcurrentDictionary<uint, SyntheticLegExecutionParams>();
|
||||
|
||||
protected OrderActorBase(IActorFabric fabric, Order order)
|
||||
protected OrderActorBase(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
_order = order.Clone();
|
||||
_fabric = fabric;
|
||||
_fabric.find_wellknown_service<IOrderIDGenerator>(out _generator);
|
||||
guid = Guid.NewGuid();
|
||||
if(order.ExecutionStrategy != null && order.ExecutionStrategy.SecurityIdToParams != null)
|
||||
order.ExecutionStrategy.SecurityIdToParams.ForEach(x => _execution_strategy.TryAdd(x.Key, x.Value));
|
||||
}
|
||||
|
||||
public Guid guid { get; private set; }
|
||||
readonly ConcurrentQueue<OrderID> _orderids = new ConcurrentQueue<OrderID>();
|
||||
protected OrderID generate_order_id()
|
||||
{
|
||||
//TODO we need to rework this when things have to go fast....
|
||||
if(_orderids.Count == 0)
|
||||
{
|
||||
const int nids = 100;
|
||||
OrderID[] oids;
|
||||
_generator.generate_order_ids(nids, out oids);
|
||||
oids.ForEach(x => _orderids.Enqueue(x));
|
||||
}
|
||||
OrderID id;
|
||||
var succ = _orderids.TryDequeue(out id);
|
||||
if(!succ)
|
||||
throw new NotSupportedException();
|
||||
//id.Id = this.GetType().Name + " " + id.Id;
|
||||
return id;
|
||||
}
|
||||
|
||||
protected IOrderHandle create_order<T>(Security sec, uint size, double price, BuySell side,
|
||||
Order.Types.TimeInForce tif = Order.Types.TimeInForce.Day,
|
||||
T algo_order_params = default(T)) where T : new()
|
||||
{
|
||||
Order ord = ActorMapping.create_order_of_type<T>(algo_order_params);
|
||||
ord.Id = generate_order_id();
|
||||
ord.Security = sec;
|
||||
ord.Price = price;
|
||||
ord.Size = size;
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
|
||||
Type actor_type;
|
||||
ActorMapping.order_actor_mapping.TryGetValue(ord.AlgoOrderTypeCase, out actor_type);
|
||||
IOrderHandle algoorder = _fabric.create(actor_type, ord);
|
||||
return algoorder;
|
||||
}
|
||||
|
||||
|
||||
protected IOrderHandle spawn_limit_order(Security sec, uint size, double price, BuySell side,
|
||||
Order.Types.TimeInForce tif = Order.Types.TimeInForce.Day)
|
||||
{
|
||||
@@ -85,7 +38,7 @@ namespace mbts.spark.orders
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
IOrderHandle algoorder = _fabric.create<LimitOrderActor, Order>(ord);
|
||||
track_child(ord.Id, algoorder);
|
||||
track_child(algoorder);
|
||||
algoorder.spawn();
|
||||
return algoorder;
|
||||
}
|
||||
@@ -101,7 +54,7 @@ namespace mbts.spark.orders
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
IOrderHandle algoorder = _fabric.create<MarketOrderActor, Order>(ord);
|
||||
track_child(ord.Id, algoorder);
|
||||
track_child(algoorder);
|
||||
algoorder.spawn();
|
||||
return algoorder;
|
||||
}
|
||||
@@ -118,7 +71,7 @@ namespace mbts.spark.orders
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
IOrderHandle algoorder = _fabric.create<StopLimitOrderActor, Order>(ord);
|
||||
track_child(ord.Id, algoorder);
|
||||
track_child(algoorder);
|
||||
algoorder.spawn();
|
||||
return algoorder;
|
||||
}
|
||||
@@ -135,7 +88,7 @@ namespace mbts.spark.orders
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
IOrderHandle algoorder = _fabric.create<StopMarketOrderActor, Order>(ord);
|
||||
track_child(ord.Id, algoorder);
|
||||
track_child(algoorder);
|
||||
algoorder.spawn();
|
||||
return algoorder;
|
||||
}
|
||||
@@ -154,42 +107,29 @@ namespace mbts.spark.orders
|
||||
do_to_children(async x => await x.cancel() );
|
||||
}
|
||||
|
||||
protected void flatten_synthetic(Order order, out IDictionary<Security, double> ratios, out IDictionary<Security, double> price_mults)
|
||||
override protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
ratios = new Dictionary<Security, double>();
|
||||
price_mults = new Dictionary<Security, double>();
|
||||
crack_synthetic(order.Security, ratios, price_mults, order.Side, order.Size);
|
||||
var statlist = new List<OrderStatus.Types.Status>();
|
||||
foreach(var stat in _child_status.Values)
|
||||
statlist.Add(stat.Status);
|
||||
return statlist;
|
||||
}
|
||||
|
||||
//break the synthetic into a dictionary of listed sub-securities and the proper signed quantity per leg
|
||||
void crack_synthetic(Security security, IDictionary<Security, double> listed_vs_signed_size,
|
||||
IDictionary<Security, double> listed_vs_price_mult,
|
||||
BuySell side = BuySell.Buy, uint quantity = 1)
|
||||
override protected void on_child_status(OrderStatus child_status, ref OrderStatus merged_status)
|
||||
{
|
||||
if(security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
if(is_done_state(child_status.Status))
|
||||
{
|
||||
foreach(var leg in security.Synthetic.Legs)
|
||||
{
|
||||
if(leg.Security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
crack_synthetic(leg.Security, listed_vs_signed_size, listed_vs_price_mult, side, quantity);
|
||||
else
|
||||
{
|
||||
listed_vs_signed_size.Add(leg.Security, leg.Quantity * (leg.Side == BuySell.Sell ? -1 : 1) *
|
||||
quantity * (side == BuySell.Sell ? -1 : 1));
|
||||
listed_vs_price_mult.Add(leg.Security, leg.PriceMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listed_vs_signed_size.Add(security, quantity * (side == BuySell.Sell ? -1 : 1));
|
||||
listed_vs_price_mult.Add(security, 1.0);
|
||||
IOrderHandle handle;
|
||||
if(_children.TryRemove(child_status.Order.Id, out handle))
|
||||
_ex_children.TryAdd(child_status.Order.Id, handle);
|
||||
}
|
||||
merged_status.Children.AddRange(_children.Select(x => x.Key));
|
||||
merged_status.Children.AddRange(_ex_children.Select(x => x.Key));
|
||||
}
|
||||
|
||||
protected void track_child(OrderID order_id, IOrderHandle algo)
|
||||
override protected void track_child(IOrderHandle algo)
|
||||
{
|
||||
_children[order_id] = algo;
|
||||
_children[algo.order_id] = algo;
|
||||
_disposables.Add(algo.order_status.Subscribe(x =>
|
||||
{
|
||||
_child_status[x.Order.Id] = x;
|
||||
@@ -201,163 +141,5 @@ namespace mbts.spark.orders
|
||||
compute_fill_internal(x);
|
||||
}));
|
||||
}
|
||||
|
||||
protected OrderStatus.Types.Status merge_status(List<OrderStatus.Types.Status> statlist)
|
||||
{
|
||||
OrderStatus.Types.Status newstatus = OrderStatus.Types.Status.Undefined;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.PendingNew || x == OrderStatus.Types.Status.New))
|
||||
newstatus = OrderStatus.Types.Status.PendingNew;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.New))
|
||||
newstatus = OrderStatus.Types.Status.New;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PartiallyFilled || x == OrderStatus.Types.Status.Filled))
|
||||
newstatus = OrderStatus.Types.Status.PartiallyFilled;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Filled))
|
||||
newstatus = OrderStatus.Types.Status.Filled;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingCancel || x == OrderStatus.Types.Status.Canceled))
|
||||
newstatus = OrderStatus.Types.Status.PendingCancel;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Canceled))
|
||||
newstatus = OrderStatus.Types.Status.Canceled;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingReplace|| x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.PendingReplace;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.Replaced;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingReplace || x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.PendingReplace;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.Replaced;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Stopped))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Stopped;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Rejected))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Rejected;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Suspended))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Suspended;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Calculated))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Calculated;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.AcceptedForBidding))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.AcceptedForBidding;
|
||||
return newstatus;
|
||||
}
|
||||
var dist = statlist.Distinct();
|
||||
if(dist.Count() == 1)
|
||||
newstatus = dist.First();
|
||||
else if(statlist.All(x => is_done_state(x)))
|
||||
newstatus = OrderStatus.Types.Status.Done;
|
||||
|
||||
return newstatus;
|
||||
}
|
||||
virtual protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
var statlist = new List<OrderStatus.Types.Status>();
|
||||
foreach(var stat in _child_status.Values)
|
||||
statlist.Add(stat.Status);
|
||||
return statlist;
|
||||
}
|
||||
|
||||
protected void compute_status_internal(OrderStatus child_status)
|
||||
{
|
||||
OrderStatus merged = new OrderStatus();
|
||||
merged.Order = _order == null ? new Order() : _order.Clone();
|
||||
|
||||
List<OrderStatus.Types.Status> statlist = child_status_list();
|
||||
merged.Status = merge_status(statlist);
|
||||
|
||||
if(is_done_state(child_status.Status))
|
||||
{
|
||||
IOrderHandle handle;
|
||||
if(_children.TryRemove(child_status.Order.Id, out handle))
|
||||
_ex_children.TryAdd(child_status.Order.Id, handle);
|
||||
}
|
||||
merged.Children.AddRange(_children.Select(x => x.Key));
|
||||
merged.Children.AddRange(_ex_children.Select(x => x.Key));
|
||||
on_child_status(child_status, ref merged);
|
||||
|
||||
_status_sink.OnNext(child_status);
|
||||
if(merged != null)
|
||||
{
|
||||
_status_sink.OnNext(merged);
|
||||
if(is_done_state(merged.Status))
|
||||
exit();
|
||||
if(is_problem_state(merged.Status))
|
||||
exit("parent order problem state");
|
||||
}
|
||||
if(is_problem_state(child_status.Status))
|
||||
exit("child order problem state");
|
||||
}
|
||||
protected virtual void on_child_status(OrderStatus child_status, ref OrderStatus merged_status) { }
|
||||
|
||||
void compute_fill_internal(Fill child_fill)
|
||||
{
|
||||
Fill merged = null;
|
||||
on_child_fill(child_fill, ref merged);
|
||||
_fills_sink.OnNext(child_fill);
|
||||
if(merged != null)
|
||||
_fills_sink.OnNext(merged);
|
||||
}
|
||||
protected virtual void on_child_fill(Fill child_fill, ref Fill merged_fill) { }
|
||||
|
||||
protected bool is_done_state(OrderStatus.Types.Status stat)
|
||||
{
|
||||
return stat == OrderStatus.Types.Status.Canceled ||
|
||||
stat == OrderStatus.Types.Status.Done ||
|
||||
stat == OrderStatus.Types.Status.Expired ||
|
||||
stat == OrderStatus.Types.Status.Filled;
|
||||
}
|
||||
|
||||
protected bool is_problem_state(OrderStatus.Types.Status stat)
|
||||
{
|
||||
return stat == OrderStatus.Types.Status.Undefined ||
|
||||
stat == OrderStatus.Types.Status.Stopped ||
|
||||
stat == OrderStatus.Types.Status.Rejected ||
|
||||
stat == OrderStatus.Types.Status.Suspended ||
|
||||
stat == OrderStatus.Types.Status.Calculated ||
|
||||
stat == OrderStatus.Types.Status.AcceptedForBidding
|
||||
;
|
||||
}
|
||||
|
||||
protected double compute_tick(Security sec)
|
||||
{
|
||||
return sec.ContractSpec.LowTick;
|
||||
}
|
||||
|
||||
readonly protected Subject<OrderStatus> _status_sink = new Subject<OrderStatus>();
|
||||
public IObservable<OrderStatus> order_status
|
||||
{
|
||||
get { return _status_sink; }
|
||||
}
|
||||
|
||||
readonly protected Subject<Fill> _fills_sink = new Subject<Fill>();
|
||||
public IObservable<Fill> fills
|
||||
{
|
||||
get { return _fills_sink; }
|
||||
}
|
||||
|
||||
protected void exit(string error = null)
|
||||
{
|
||||
_fabric.destroy(this, error);
|
||||
}
|
||||
|
||||
public abstract void on_spawn();
|
||||
public virtual void on_destroy()
|
||||
{
|
||||
_disposables.ForEach(x => x.Dispose());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
|
||||
using BBOType = System.Tuple<mbts.co2.PriceSize, mbts.co2.PriceSize>;
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
class SimpleHedgeOrderActor : SimpleOrderBase, ICancelable, IModifiable
|
||||
{
|
||||
readonly IMarketDataSource _md;
|
||||
readonly IExchangeGateway _exchange;
|
||||
readonly IDropCopy _dc;
|
||||
OrderStatus _status;
|
||||
readonly double _tick;
|
||||
public SimpleHedgeOrderActor(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
//TODO Multi exchange
|
||||
fabric.find_wellknown_service<IMarketDataSource>(order.Security.Exchange, out _md);
|
||||
fabric.find_wellknown_service<IExchangeGateway>(order.Security.Exchange, out _exchange);
|
||||
fabric.find_wellknown_service<IDropCopy>(order.Security.Exchange, out _dc);
|
||||
_tick = compute_tick(order.Security);
|
||||
}
|
||||
|
||||
override protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
var stat = new List<OrderStatus.Types.Status>();
|
||||
if(_status != null)
|
||||
stat.Add(_status.Status);
|
||||
return stat;
|
||||
}
|
||||
|
||||
override protected void on_child_status(OrderStatus child_status, ref OrderStatus merged_status)
|
||||
{
|
||||
_status = child_status;
|
||||
if(_status.Order?.Id != null)
|
||||
merged_status.Children.Add(_status.Order.Id);
|
||||
}
|
||||
|
||||
public override void on_spawn()
|
||||
{
|
||||
_disposables.Add(_md.subscribe_bbo(_order.Security).Subscribe(x =>
|
||||
{
|
||||
if(x != null)
|
||||
watch_hedges(x);
|
||||
}));
|
||||
_disposables.Add(_dc.subscribe_fills(new Predicate<Fill>(x => _order.Id.Equals(x.Order.Id))).Subscribe(x =>
|
||||
{
|
||||
compute_fill_internal(x);
|
||||
}));
|
||||
_disposables.Add(_dc.subscribe_status(new Predicate<OrderStatus>(x => _order.Id.Equals(x.Order.Id))).Subscribe(x =>
|
||||
{
|
||||
compute_status_internal(x);
|
||||
}));
|
||||
|
||||
var clone = _order.Clone();
|
||||
clone.LimitOrder = new LimitOrder();
|
||||
_exchange.send_order(clone);
|
||||
}
|
||||
|
||||
void watch_hedges(BBOType bbo)
|
||||
{
|
||||
if(_status != null)
|
||||
{
|
||||
PriceSize inside_market;
|
||||
if(_status.Order.Side == BuySell.Buy)
|
||||
inside_market = bbo.Item2;
|
||||
else
|
||||
inside_market = bbo.Item1;
|
||||
|
||||
evaluate_post_hedge_rules(inside_market);
|
||||
}
|
||||
}
|
||||
|
||||
void evaluate_post_hedge_rules(PriceSize inside_market)
|
||||
{
|
||||
PostHedgePriceBasedForcedCross post = _order.SimpleHedgeOrder.Post;
|
||||
if(post == null || _status == null || post.TicksThreshold == 0 || post.MarketCrossTicks == 0)
|
||||
return;
|
||||
|
||||
if(_status.Order.Side == BuySell.Buy)
|
||||
{
|
||||
uint diff = Convert.ToUInt32((inside_market.price - _status.Order.Price) / _tick);
|
||||
if(diff >= post.TicksThreshold)
|
||||
_exchange.modify_price(_order.Id, _status.Order.Price + _tick * post.MarketCrossTicks);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint diff = Convert.ToUInt32((_status.Order.Price - inside_market.price) / _tick);
|
||||
if(diff >= post.TicksThreshold)
|
||||
_exchange.modify_price(_order.Id, _status.Order.Price - _tick * post.MarketCrossTicks);
|
||||
}
|
||||
}
|
||||
|
||||
bool ICancelable.on_cancel()
|
||||
{
|
||||
_exchange.cancel_order(_order.Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_price(double new_price)
|
||||
{
|
||||
_exchange.modify_price(_order.Id, new_price);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_size(uint new_size)
|
||||
{
|
||||
_exchange.modify_size(_order.Id, new_size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
abstract class SimpleOrderBase : IActor, IOrderStatusProducer, IFillProducer
|
||||
{
|
||||
readonly protected List<IDisposable> _disposables = new List<IDisposable>();
|
||||
readonly IOrderIDGenerator _generator;
|
||||
protected readonly IActorFabric _fabric;
|
||||
protected readonly Order _order;
|
||||
|
||||
public SimpleOrderBase(IActorFabric fabric, Order order)
|
||||
{
|
||||
_order = order.Clone();
|
||||
_fabric = fabric;
|
||||
_fabric.find_wellknown_service<IOrderIDGenerator>(out _generator);
|
||||
guid = Guid.NewGuid();
|
||||
}
|
||||
public Guid guid { get; private set; }
|
||||
|
||||
static protected void flatten_synthetic(Order order, out IDictionary<Security, double> ratios, out IDictionary<Security, double> price_mults)
|
||||
{
|
||||
ratios = new Dictionary<Security, double>();
|
||||
price_mults = new Dictionary<Security, double>();
|
||||
crack_synthetic(order.Security, ratios, price_mults, order.Side);
|
||||
}
|
||||
|
||||
//break the synthetic into a dictionary of listed sub-securities and the proper signed quantity per leg
|
||||
static void crack_synthetic(Security security, IDictionary<Security, double> listed_vs_signed_ratio,
|
||||
IDictionary<Security, double> listed_vs_price_mult,
|
||||
BuySell side = BuySell.Buy, uint quantity = 1)
|
||||
{
|
||||
if(security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
{
|
||||
foreach(var leg in security.Synthetic.Legs)
|
||||
{
|
||||
if(leg.Security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
crack_synthetic(leg.Security, listed_vs_signed_ratio, listed_vs_price_mult, side, quantity);
|
||||
else
|
||||
{
|
||||
listed_vs_signed_ratio.Add(leg.Security, leg.Quantity * (leg.Side == BuySell.Sell ? -1 : 1) *
|
||||
quantity * (side == BuySell.Sell ? -1 : 1));
|
||||
listed_vs_price_mult.Add(leg.Security, leg.PriceMultiplier == 0.0 ? 1.0 : leg.PriceMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listed_vs_signed_ratio.Add(security, quantity * (side == BuySell.Sell ? -1 : 1));
|
||||
listed_vs_price_mult.Add(security, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
static readonly ConcurrentQueue<OrderID> _orderids = new ConcurrentQueue<OrderID>();
|
||||
protected OrderID generate_order_id()
|
||||
{
|
||||
//TODO we need to rework this when things have to go fast....
|
||||
if(_orderids.Count == 0)
|
||||
{
|
||||
const int nids = 100;
|
||||
OrderID[] oids;
|
||||
_generator.generate_order_ids(nids, out oids);
|
||||
oids.ForEach(x => _orderids.Enqueue(x));
|
||||
}
|
||||
OrderID id;
|
||||
var succ = _orderids.TryDequeue(out id);
|
||||
if(!succ)
|
||||
throw new NotSupportedException();
|
||||
//id.Id = this.GetType().Name + " " + id.Id;
|
||||
return id;
|
||||
}
|
||||
|
||||
protected IOrderHandle create_order<T>(Security sec, uint size, double price, BuySell side,
|
||||
Order.Types.TimeInForce tif = Order.Types.TimeInForce.Day,
|
||||
T algo_order_params = default(T)) where T : new()
|
||||
{
|
||||
Order ord = ActorMapping.create_order_of_type<T>(algo_order_params);
|
||||
ord.Id = generate_order_id();
|
||||
ord.Security = sec;
|
||||
ord.Price = price;
|
||||
ord.Size = size;
|
||||
ord.Side = side;
|
||||
ord.TimeInForce = tif;
|
||||
|
||||
Type actor_type;
|
||||
ActorMapping.order_actor_mapping.TryGetValue(ord.AlgoOrderTypeCase, out actor_type);
|
||||
IOrderHandle algoorder = _fabric.create(actor_type, ord);
|
||||
return algoorder;
|
||||
}
|
||||
|
||||
virtual protected void track_child(IOrderHandle algo)
|
||||
{
|
||||
_disposables.Add(algo.order_status.Subscribe(x =>
|
||||
{
|
||||
compute_status_internal(x);
|
||||
}));
|
||||
_disposables.Add(algo.fills.Subscribe(x =>
|
||||
{
|
||||
compute_fill_internal(x);
|
||||
}));
|
||||
}
|
||||
|
||||
static protected OrderStatus.Types.Status merge_status(List<OrderStatus.Types.Status> statlist)
|
||||
{
|
||||
if(!statlist.Any())
|
||||
return OrderStatus.Types.Status.New;
|
||||
OrderStatus.Types.Status newstatus = OrderStatus.Types.Status.Undefined;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.PendingNew || x == OrderStatus.Types.Status.New))
|
||||
newstatus = OrderStatus.Types.Status.PendingNew;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.New))
|
||||
newstatus = OrderStatus.Types.Status.New;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PartiallyFilled || x == OrderStatus.Types.Status.Filled))
|
||||
newstatus = OrderStatus.Types.Status.PartiallyFilled;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Filled))
|
||||
newstatus = OrderStatus.Types.Status.Filled;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingCancel || x == OrderStatus.Types.Status.Canceled))
|
||||
newstatus = OrderStatus.Types.Status.PendingCancel;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Canceled))
|
||||
newstatus = OrderStatus.Types.Status.Canceled;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingReplace || x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.PendingReplace;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.Replaced;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.PendingReplace || x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.PendingReplace;
|
||||
if(statlist.All(x => x == OrderStatus.Types.Status.Replaced))
|
||||
newstatus = OrderStatus.Types.Status.Replaced;
|
||||
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Stopped))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Stopped;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Rejected))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Rejected;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Suspended))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Suspended;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.Calculated))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.Calculated;
|
||||
return newstatus;
|
||||
}
|
||||
if(statlist.Any(x => x == OrderStatus.Types.Status.AcceptedForBidding))
|
||||
{
|
||||
newstatus = OrderStatus.Types.Status.AcceptedForBidding;
|
||||
return newstatus;
|
||||
}
|
||||
var dist = statlist.Distinct();
|
||||
if(dist.Count() == 1)
|
||||
newstatus = dist.First();
|
||||
else if(statlist.All(x => is_done_state(x)))
|
||||
newstatus = OrderStatus.Types.Status.Done;
|
||||
|
||||
return newstatus;
|
||||
}
|
||||
|
||||
protected void compute_status_internal(OrderStatus child_status)
|
||||
{
|
||||
OrderStatus merged = new OrderStatus();
|
||||
merged.Order = _order == null ? new Order() : _order.Clone();
|
||||
|
||||
on_child_status(child_status, ref merged);
|
||||
List<OrderStatus.Types.Status> statlist = child_status_list();
|
||||
merged.Status = merge_status(statlist);
|
||||
|
||||
_status_sink.OnNext(child_status);
|
||||
if(merged != null)
|
||||
{
|
||||
_status_sink.OnNext(merged);
|
||||
if(is_done_state(merged.Status))
|
||||
exit();
|
||||
if(is_problem_state(merged.Status))
|
||||
exit("parent order problem state");
|
||||
}
|
||||
if(is_problem_state(child_status.Status))
|
||||
exit("child order problem state");
|
||||
}
|
||||
|
||||
abstract protected List<OrderStatus.Types.Status> child_status_list();
|
||||
protected virtual void on_child_status(OrderStatus child_status, ref OrderStatus merged_status) { }
|
||||
|
||||
protected void compute_fill_internal(Fill child_fill)
|
||||
{
|
||||
Fill merged = null;
|
||||
on_child_fill(child_fill, ref merged);
|
||||
_fills_sink.OnNext(child_fill);
|
||||
if(merged != null)
|
||||
_fills_sink.OnNext(merged);
|
||||
}
|
||||
protected virtual void on_child_fill(Fill child_fill, ref Fill merged_fill) { }
|
||||
|
||||
static protected bool is_done_state(OrderStatus.Types.Status stat)
|
||||
{
|
||||
return stat == OrderStatus.Types.Status.Canceled ||
|
||||
stat == OrderStatus.Types.Status.Done ||
|
||||
stat == OrderStatus.Types.Status.Expired ||
|
||||
stat == OrderStatus.Types.Status.Filled;
|
||||
}
|
||||
|
||||
static protected bool is_problem_state(OrderStatus.Types.Status stat)
|
||||
{
|
||||
return stat == OrderStatus.Types.Status.Undefined ||
|
||||
stat == OrderStatus.Types.Status.Stopped ||
|
||||
stat == OrderStatus.Types.Status.Rejected ||
|
||||
stat == OrderStatus.Types.Status.Suspended ||
|
||||
stat == OrderStatus.Types.Status.Calculated ||
|
||||
stat == OrderStatus.Types.Status.AcceptedForBidding
|
||||
;
|
||||
}
|
||||
static protected bool is_final_state(OrderStatus.Types.Status status)
|
||||
{
|
||||
return is_done_state(status) || is_problem_state(status);
|
||||
}
|
||||
|
||||
protected double compute_tick(Security sec)
|
||||
{
|
||||
return sec.ContractSpec.LowTick;
|
||||
}
|
||||
|
||||
readonly protected Subject<OrderStatus> _status_sink = new Subject<OrderStatus>();
|
||||
public IObservable<OrderStatus> order_status
|
||||
{
|
||||
get { return _status_sink; }
|
||||
}
|
||||
|
||||
readonly protected Subject<Fill> _fills_sink = new Subject<Fill>();
|
||||
public IObservable<Fill> fills
|
||||
{
|
||||
get { return _fills_sink; }
|
||||
}
|
||||
|
||||
|
||||
protected virtual void exit(string error = null)
|
||||
{
|
||||
_fabric.destroy(this, error);
|
||||
}
|
||||
|
||||
public abstract void on_spawn();
|
||||
public virtual void on_destroy()
|
||||
{
|
||||
_disposables.ForEach(x => x.Dispose());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
|
||||
using BookType = System.Tuple<mbts.co2.PriceSize[], mbts.co2.PriceSize[]>;
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
|
||||
class SpreaderLegOrderInfo
|
||||
{
|
||||
public IOrderHandle handle;
|
||||
public double last_hedge_price;
|
||||
}
|
||||
|
||||
struct SpreaderLeg
|
||||
{
|
||||
public readonly Security security;
|
||||
public readonly SimpleExecutionParams param;
|
||||
public readonly double ratio;
|
||||
public readonly double mult;
|
||||
public readonly double tick;
|
||||
|
||||
public BookType book;
|
||||
public OrderStatus status;
|
||||
public SpreaderLegOrderInfo order_info;
|
||||
public SpreaderLeg(Security sec, SimpleExecutionParams para, double ratio, double mult, double tick)
|
||||
{
|
||||
this.security = sec;
|
||||
this.param = para;
|
||||
this.ratio = ratio;
|
||||
this.mult = mult;
|
||||
this.tick = tick;
|
||||
|
||||
this.book = null;
|
||||
this.status = null;
|
||||
this.order_info = new SpreaderLegOrderInfo();
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleSyntheticLimitOrder : SimpleOrderBase, IActor, ICancelable, IModifiable
|
||||
{
|
||||
readonly IMarketDataSource _md;
|
||||
|
||||
SpreaderLeg _leg1, _leg2;
|
||||
readonly ConcurrentDictionary<OrderID, object> _hedges = new ConcurrentDictionary<OrderID, object>();
|
||||
readonly ConcurrentDictionary<OrderID, OrderStatus> _status = new ConcurrentDictionary<OrderID, OrderStatus>();
|
||||
public SimpleSyntheticLimitOrder(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
IDictionary<Security, double> leg_ratios;
|
||||
IDictionary<Security, double> price_mults;
|
||||
flatten_synthetic(order, out leg_ratios, out price_mults);
|
||||
foreach(var sec in leg_ratios.Keys)
|
||||
{
|
||||
if(sec.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
throw new NotSupportedException("Nested Synthetics not supported");
|
||||
fabric.find_wellknown_service<IMarketDataSource>(sec.Exchange, out _md);
|
||||
}
|
||||
if(leg_ratios.Keys.Count != 2)
|
||||
throw new NotSupportedException("Simple Synthetic Only Supports 2 Legs");
|
||||
|
||||
SimpleExecutionStrategy simple = order.SimpleExecutionStrategy;
|
||||
//map the current UI to this new simple mode
|
||||
if(simple == null && order.ExecutionStrategy != null)
|
||||
{
|
||||
var map = order.ExecutionStrategy.SecurityIdToParams;
|
||||
Security sec1 = leg_ratios.Keys.First();
|
||||
Security sec2 = leg_ratios.Keys.Last();
|
||||
|
||||
SyntheticLegExecutionParams old1 = map[sec1.Id], old2 = map[sec2.Id];
|
||||
SimpleExecutionParams s1 = convert_exec_params(sec1, old1), s2 = convert_exec_params(sec2, old2);
|
||||
_leg1 = new SpreaderLeg(sec1, s1, leg_ratios[sec1], price_mults[sec1], compute_tick(sec1));
|
||||
_leg2 = new SpreaderLeg(sec2, s2, leg_ratios[sec2], price_mults[sec2], compute_tick(sec2));
|
||||
}
|
||||
else
|
||||
{
|
||||
Security sec1 = order.SimpleExecutionStrategy.Leg1.Security;
|
||||
Security sec2 = order.SimpleExecutionStrategy.Leg2.Security;
|
||||
_leg1 = new SpreaderLeg(sec1, order.SimpleExecutionStrategy.Leg1, leg_ratios[sec1], price_mults[sec1], compute_tick(sec1));
|
||||
_leg2 = new SpreaderLeg(sec2, order.SimpleExecutionStrategy.Leg2, leg_ratios[sec2], price_mults[sec2], compute_tick(sec2));
|
||||
}
|
||||
}
|
||||
|
||||
SimpleExecutionParams convert_exec_params(Security sec, SyntheticLegExecutionParams old)
|
||||
{
|
||||
uint slop = 0;
|
||||
var ss = old.QuoteParams?.TickRangeRequoteRules?.TicksAwayToSensitivity?.FirstOrDefault();
|
||||
if(ss.HasValue)
|
||||
slop = ss.Value.Value;
|
||||
int payup = 0;
|
||||
var pu = old.HedgeParams?.PayupHedgeRules;
|
||||
if(pu != null && pu.EnablePayup)
|
||||
payup = Convert.ToInt32(pu.PayupTicks);
|
||||
var pl = old.HedgeParams?.PaylessHedgeRules;
|
||||
if(pl != null && pl.EnablePayless)
|
||||
payup = -Convert.ToInt32(pu.PayupTicks);
|
||||
var post = old.HedgeParams?.PostHedgeRules;
|
||||
|
||||
var s = new SimpleExecutionParams()
|
||||
{
|
||||
IsHedging = true,
|
||||
IsWorking = old.QuoteParams.IsWorking,
|
||||
Security = sec,
|
||||
Slop = new QuoteMuteZone { InsideTicks = slop, OutsideTicks = slop },
|
||||
PreHedgePayupTicks = payup,
|
||||
Post = new PostHedgePriceBasedForcedCross
|
||||
{
|
||||
MarketCrossTicks = post == null ? 0 : post.CrossSizeThreshold,
|
||||
TicksThreshold = post == null ? 0 : Convert.ToUInt32(post.CrossRatioThreshold),
|
||||
},
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
override protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
return _status.Values.Select(x => x.Status).ToList();
|
||||
}
|
||||
override protected void on_child_status(OrderStatus child_status, ref OrderStatus merged_status)
|
||||
{
|
||||
if(child_status.Order.Security.Equals(_leg1.security))
|
||||
_leg1.status = child_status;
|
||||
if(child_status.Order.Security.Equals(_leg2.security))
|
||||
_leg2.status = child_status;
|
||||
|
||||
if(_leg1.order_info.handle != null)
|
||||
merged_status.Children.Add(_leg1.order_info.handle.order_id);
|
||||
if(_leg2.order_info.handle != null)
|
||||
merged_status.Children.Add(_leg2.order_info.handle.order_id);
|
||||
_status[child_status.Order.Id] = child_status;
|
||||
}
|
||||
|
||||
|
||||
override public void on_spawn()
|
||||
{
|
||||
_disposables.Add(_md.subscribe_depth(_leg1.security).Subscribe(x =>
|
||||
{
|
||||
BookType transformed = Tuple.Create(x.Item1.Select(xx => new PriceSize(xx.price * _leg1.mult, xx.size)).ToArray(),
|
||||
x.Item2.Select(xx => new PriceSize(xx.price * _leg1.mult, xx.size)).ToArray());
|
||||
_leg1.book = transformed;
|
||||
requote(_leg2, _leg1);
|
||||
}));
|
||||
|
||||
_disposables.Add(_md.subscribe_depth(_leg2.security).Subscribe(x =>
|
||||
{
|
||||
BookType transformed = Tuple.Create(x.Item1.Select(xx => new PriceSize(xx.price * _leg2.mult, xx.size)).ToArray(),
|
||||
x.Item2.Select(xx => new PriceSize(xx.price * _leg2.mult, xx.size)).ToArray());
|
||||
_leg2.book = transformed;
|
||||
requote(_leg1, _leg2);
|
||||
}));
|
||||
}
|
||||
|
||||
public override void on_destroy()
|
||||
{
|
||||
base.on_destroy();
|
||||
}
|
||||
|
||||
#region Quoting
|
||||
|
||||
//always pessimistic
|
||||
bool walk_book(PriceSize[] book, uint size, out double leg_price)
|
||||
{
|
||||
bool ok = false; leg_price = double.NaN;
|
||||
uint agg = 0;
|
||||
foreach(var level in book)
|
||||
{
|
||||
agg += level.size;
|
||||
if(agg >= size)
|
||||
{
|
||||
leg_price = level.price;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(leg_price == 0.0)
|
||||
leg_price = double.NaN;
|
||||
return ok;
|
||||
}
|
||||
|
||||
void new_quote_order(Security security, uint quote_size, double quote_price, BuySell quote_side, double hedge_price,
|
||||
SpreaderLegOrderInfo order_info)
|
||||
{
|
||||
order_info.handle = create_order<LimitOrder>(security, quote_size, quote_price, quote_side, _order.TimeInForce, new LimitOrder());
|
||||
order_info.last_hedge_price = hedge_price; //cache this for later
|
||||
track_child(order_info.handle);
|
||||
order_info.handle.spawn();
|
||||
}
|
||||
|
||||
void replace_quote_order(SpreaderLeg quote_leg, double hedge_price, ref double quote_price)
|
||||
{
|
||||
if(evaluate_prequote_rules(quote_leg, ref quote_price))
|
||||
{
|
||||
if(double.IsNaN(quote_price))
|
||||
quote_leg.order_info.handle.cancel();
|
||||
else
|
||||
{
|
||||
quote_leg.order_info.handle.modify_price(quote_price);
|
||||
quote_leg.order_info.last_hedge_price = hedge_price; //cache this for later
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void requote_all()
|
||||
{
|
||||
requote(_leg1, _leg2);
|
||||
requote(_leg2, _leg1);
|
||||
}
|
||||
|
||||
//reprice the quote leg in terms of the hedge leg
|
||||
void requote(SpreaderLeg quote_leg, SpreaderLeg hedge_leg)
|
||||
{
|
||||
if(quote_leg.status != null && is_final_state(quote_leg.status.Status))
|
||||
return;
|
||||
if(!quote_leg.param.IsWorking)
|
||||
return;
|
||||
|
||||
double quote_price = _order.Price * -1.0;
|
||||
|
||||
int hedge_size_signed = Convert.ToInt32(_order.Size * hedge_leg.ratio);
|
||||
int hedge_side = (hedge_size_signed < 0 ? -1 : 1);
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(hedge_size_signed));
|
||||
|
||||
double hedge_price_at_size = double.NaN;
|
||||
if(hedge_side < 0)
|
||||
walk_book(hedge_leg.book.Item1, hedge_size, out hedge_price_at_size);
|
||||
else
|
||||
walk_book(hedge_leg.book.Item2, hedge_size, out hedge_price_at_size);
|
||||
|
||||
quote_price += hedge_side * hedge_price_at_size * (_order.Side == BuySell.Sell ? -1 : 1);
|
||||
quote_price = Math.Round(Math.Abs(quote_price) / quote_leg.tick, MidpointRounding.AwayFromZero) * quote_leg.tick;
|
||||
|
||||
if(quote_leg.order_info.handle == null && !double.IsNaN(quote_price)) //new order
|
||||
{
|
||||
int quote_size_signed = Convert.ToInt32(_order.Size * quote_leg.ratio);
|
||||
BuySell quote_side = (quote_size_signed < 0 ? BuySell.Sell : BuySell.Buy);
|
||||
uint quote_size = Convert.ToUInt32(Math.Abs(quote_size_signed));
|
||||
new_quote_order(quote_leg.security, quote_size, quote_price, quote_side, hedge_price_at_size, quote_leg.order_info);
|
||||
}
|
||||
else
|
||||
replace_quote_order(quote_leg, hedge_price_at_size, ref quote_price);
|
||||
}
|
||||
|
||||
//one day this could modify size, do a fancy rule chain, etc
|
||||
bool evaluate_prequote_rules(SpreaderLeg quote_leg, ref double quote_price)
|
||||
{
|
||||
SimpleExecutionParams param = quote_leg.param;
|
||||
if(param.Slop != null)
|
||||
{
|
||||
double? orig_price = quote_leg.status?.Order.Price;
|
||||
if(orig_price.HasValue)
|
||||
{
|
||||
int diff = Convert.ToInt32((quote_price - orig_price) / quote_leg.tick);
|
||||
if(diff != 0)
|
||||
{
|
||||
if(quote_leg.status.Order.Side == BuySell.Buy)
|
||||
{
|
||||
if(diff >= param.Slop.InsideTicks || diff <= -param.Slop.OutsideTicks)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(diff <= -param.Slop.InsideTicks || diff >= param.Slop.OutsideTicks)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hedging
|
||||
|
||||
protected override void on_child_fill(Fill child_fill, ref Fill merged_fill)
|
||||
{
|
||||
if(!_hedges.ContainsKey(child_fill.Order.Id))
|
||||
hedge_fill(child_fill);
|
||||
}
|
||||
|
||||
void reduce_working_order(OrderStatus quote_leg_status, SpreaderLegOrderInfo order_info, uint hedge_size)
|
||||
{
|
||||
if(order_info.handle != null && quote_leg_status != null && !is_final_state(quote_leg_status.Status))
|
||||
{
|
||||
if(hedge_size < quote_leg_status.Order.Size)
|
||||
order_info.handle.modify_size(quote_leg_status.Order.Size - hedge_size);
|
||||
else
|
||||
order_info.handle.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void hedge_fill(Fill fill)
|
||||
{
|
||||
SpreaderLeg quote_leg, hedge_leg;
|
||||
if(fill.Order.Security.Equals(_leg1.security))
|
||||
{
|
||||
quote_leg = _leg1;
|
||||
hedge_leg = _leg2;
|
||||
}
|
||||
else
|
||||
{
|
||||
quote_leg = _leg2;
|
||||
hedge_leg = _leg1;
|
||||
}
|
||||
if(!hedge_leg.param.IsHedging)
|
||||
return;
|
||||
|
||||
double hedge_size_signed = hedge_leg.ratio * fill.Size * (fill.Side == BuySell.Buy ? 1.0 : -1.0);
|
||||
var hedge_side = (hedge_size_signed > 0.0) ? BuySell.Buy : BuySell.Sell;
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(hedge_size_signed));
|
||||
reduce_working_order(hedge_leg.status, hedge_leg.order_info, hedge_size);
|
||||
double hedge_price = quote_leg.order_info.last_hedge_price + hedge_leg.param.PreHedgePayupTicks * hedge_leg.tick;
|
||||
|
||||
var rules = new SimpleHedgeOrder { Post = hedge_leg.param.Post };
|
||||
var hedge = create_order<SimpleHedgeOrder>(hedge_leg.security, hedge_size, hedge_price,
|
||||
hedge_side, Order.Types.TimeInForce.Day, rules);
|
||||
_hedges[hedge.order_id] = null;
|
||||
track_child(hedge);
|
||||
hedge.spawn();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
bool ICancelable.on_cancel()
|
||||
{
|
||||
if(_leg1.order_info.handle != null)
|
||||
_leg1.order_info.handle.cancel();
|
||||
if(_leg2.order_info.handle != null)
|
||||
_leg2.order_info.handle.cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_price(double new_price)
|
||||
{
|
||||
_order.Price = new_price;
|
||||
requote_all();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_size(uint new_size)
|
||||
{
|
||||
_order.Size = new_size;
|
||||
_leg1.order_info.handle?.cancel();
|
||||
_leg1.order_info = null;
|
||||
_leg2.order_info.handle?.cancel();
|
||||
_leg2.order_info = null;
|
||||
requote_all();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
public class QuoteLegPriceQuantityState
|
||||
{
|
||||
/// These are set by the users
|
||||
private double _target_spread_price;
|
||||
private Nullable<double> _leg_price_override;
|
||||
private uint _target_leg_qty;
|
||||
|
||||
/// As fills come in _aggregated_filled_qty is updated.
|
||||
private uint _aggregated_hedged_qty,
|
||||
/// As other legs are filled, this is updated
|
||||
_aggregated_filled_qty;
|
||||
|
||||
private double _computed_price;
|
||||
private uint _computed_qty;
|
||||
|
||||
public double out_price = Double.NaN;
|
||||
public uint out_qty = 0;
|
||||
|
||||
private readonly Func<uint, Tuple<double, uint>> _price_qty_evaluator;
|
||||
|
||||
public QuoteLegPriceQuantityState(double target_spread_price,
|
||||
uint target_leg_qty,
|
||||
uint aggregated_hedged_qty,
|
||||
uint aggregated_filled_qty,
|
||||
Func<uint, Tuple<double, uint>> price_qty_evaluator)
|
||||
{
|
||||
_target_spread_price = target_spread_price;
|
||||
_target_leg_qty = target_leg_qty;
|
||||
_aggregated_hedged_qty = aggregated_hedged_qty;
|
||||
_aggregated_filled_qty = aggregated_filled_qty;
|
||||
_price_qty_evaluator = price_qty_evaluator;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
private void _update_output()
|
||||
{
|
||||
/// ignore leg price override for now
|
||||
if (_aggregated_filled_qty >= _target_leg_qty)
|
||||
{
|
||||
_computed_qty = 0;
|
||||
_computed_price = Double.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint hedge_adjusted_qty = _target_leg_qty - _aggregated_filled_qty;
|
||||
if (_aggregated_filled_qty >= hedge_adjusted_qty)
|
||||
{
|
||||
_computed_qty = 0;
|
||||
_computed_price = Double.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint remainder_to_get_qty = hedge_adjusted_qty - _aggregated_filled_qty;
|
||||
Tuple<double, uint> price_qty = _price_qty_evaluator(remainder_to_get_qty);
|
||||
if (price_qty.Item2 == 0)
|
||||
{
|
||||
_computed_qty = 0;
|
||||
_computed_price = Double.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
_computed_qty = price_qty.Item2 + _aggregated_filled_qty;
|
||||
_computed_price = price_qty.Item1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update_hedges(uint normalized_qty)
|
||||
{
|
||||
_aggregated_hedged_qty += normalized_qty;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public void update_fills(uint filled_qty)
|
||||
{
|
||||
_aggregated_filled_qty += filled_qty;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public void update_target_leg_qty(uint target_leg_qty)
|
||||
{
|
||||
_target_leg_qty = target_leg_qty;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public void update_target_spread_price(double target_spread_price)
|
||||
{
|
||||
_target_spread_price = target_spread_price;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public void update_target_leg_price(double target_leg_price)
|
||||
{
|
||||
_leg_price_override = target_leg_price;
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public void update_md()
|
||||
{
|
||||
_update_output();
|
||||
}
|
||||
|
||||
public uint target_leg_qty { get { return _target_leg_qty; } }
|
||||
|
||||
public uint aggregated_filled_qty { get { return _aggregated_filled_qty; } }
|
||||
|
||||
public uint aggegated_hedged_qty { get { return _aggregated_hedged_qty; } }
|
||||
|
||||
public uint computed_qty { get { return _computed_qty; } }
|
||||
|
||||
public double computed_price { get { return _computed_price; } }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
public class OrderOperationResult
|
||||
internal class OrderOperationResult
|
||||
{
|
||||
public readonly bool success;
|
||||
public readonly string details;
|
||||
@@ -18,13 +18,13 @@ namespace mbts.spark
|
||||
}
|
||||
}
|
||||
|
||||
public interface IOrderStateWatcher
|
||||
internal interface IOrderStateWatcher
|
||||
{
|
||||
void on_order_status(bts.spark.OrderID order_id, bts.spark.OrderStatus.Types.Status status);
|
||||
void on_fills(bts.spark.OrderID order_id, bts.api.BuySell side, uint qty, double price);
|
||||
}
|
||||
|
||||
interface IOrderManager : IOrderStateWatcher
|
||||
internal interface IOrderManager : IOrderStateWatcher
|
||||
{
|
||||
OrderOperationResult initialize(IAlgoHyperLoop algo_hyper_loop, bts.spark.Order order);
|
||||
OrderOperationResult modify_order(bts.spark.Order order);
|
||||
@@ -36,7 +36,7 @@ namespace mbts.spark
|
||||
void time_quantam();
|
||||
}
|
||||
|
||||
interface IAlgoHyperLoop
|
||||
internal interface IAlgoHyperLoop
|
||||
{
|
||||
/// Internal calls from within the application
|
||||
OrderOperationResult send_order(IOrderManager order_manager, bts.spark.Order order);
|
||||
@@ -51,4 +51,53 @@ namespace mbts.spark
|
||||
void send_fill_status(bts.spark.OrderID order_id, bts.api.BuySell side, uint qty, double price);
|
||||
mbts.co2.IMDHandle get_md_handle();
|
||||
}
|
||||
|
||||
internal class BTSOrders
|
||||
{
|
||||
/// Price can be enterred in an offset from
|
||||
/// Bid, Ask or LTP
|
||||
public class PriceOffset
|
||||
{
|
||||
public enum PriceType { Bid, Ask, LastTradePrice };
|
||||
public int offset_ticks;
|
||||
}
|
||||
|
||||
public class QuantityThreshold
|
||||
{
|
||||
public enum QuantityType { Absolute, Ratio };
|
||||
public uint absolute_qty;
|
||||
public double ratio;
|
||||
}
|
||||
|
||||
public class BTSRetryParamaters
|
||||
{
|
||||
/// <summary>
|
||||
/// 1. Can this be fundamental data associated
|
||||
/// with any order ?
|
||||
/// 2. How is the parent child relation mantained
|
||||
/// a. There will be multiple orders, only one
|
||||
/// active though associated with the synthetic parent
|
||||
/// b. After the child is accepted, TT makes the synthetic go away
|
||||
/// </summary>
|
||||
public uint max_number_of_retries;
|
||||
public TimeSpan time_between_retries;
|
||||
/// Only of these will be true
|
||||
public TimeSpan offset_from_now;
|
||||
public DateTime start_time;
|
||||
}
|
||||
|
||||
public class BTSRetryOrder
|
||||
{
|
||||
/// only market and limit order types are supported
|
||||
}
|
||||
|
||||
/// This is fundamental data associated with an order.
|
||||
/// Any order can have a WithATick parameters associated
|
||||
/// with it
|
||||
/// There will be a BTSWithATickOrder too
|
||||
public class BTSWithATickParameters
|
||||
{
|
||||
public QuantityThreshold threshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
/// This class is reponsible for mantaining the hedge for quoting fill
|
||||
internal class SingleFillHedger
|
||||
{
|
||||
private readonly ISingleSecurityExchangeGateway _order_gateway;
|
||||
public Action<bts.spark.Fill> on_fill = f => { };
|
||||
|
||||
public SingleFillHedger(Order hedge_order,
|
||||
ContractLeg leg,
|
||||
LegSpreaderParams leg_spreader_param,
|
||||
mbts.co2.IMDHandle md_handle,
|
||||
ISingleSecurityExchangeGateway order_gateway)
|
||||
{
|
||||
_order_gateway = order_gateway;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal enum QuoterState
|
||||
{
|
||||
START = 0,
|
||||
WAITING_FOR_MARKET,
|
||||
WAITING_FOR_FIRST_ACK,
|
||||
WORKING,
|
||||
WAITING_FOR_CANCEL_ACK,
|
||||
END
|
||||
}
|
||||
|
||||
internal enum ExternalEvents
|
||||
{
|
||||
/// Normal status event from the exchange
|
||||
OrderStatusNormal = 0,
|
||||
/// Error status event from the exchage (this could be a temporary error, however the state machine will cxl the order)
|
||||
OrderStatusError,
|
||||
/// When the order is completely filled (end event, should not expect anything else after that)
|
||||
OrderStatusFilled,
|
||||
/// When the order is cancelled (end event, should not expect anything else after that)
|
||||
OrderStatusCancelled,
|
||||
/// Fills reported by the exchange
|
||||
OrderFills,
|
||||
/// Market data update from the exchange
|
||||
MDUpdate,
|
||||
/// One of the other quoting legs in the spread got filled (not a hedge fill)
|
||||
OtherLegQuotingFill,
|
||||
/// User changes the price of the spread order
|
||||
UserSpreadPriceChange,
|
||||
/// User changes the quantity of the spread order
|
||||
UserSpreadQuantityChange,
|
||||
/// User changes the price of this leg
|
||||
UserLegPriceChange,
|
||||
/// User cancels this leg
|
||||
UserLegCancel,
|
||||
/// Either the user or the spreader cancels the order
|
||||
CancelOrder
|
||||
}
|
||||
|
||||
internal class SingleLegQuoter
|
||||
{
|
||||
private readonly double _tick_size;
|
||||
private readonly Order _order;
|
||||
private readonly ContractLeg _leg;
|
||||
private readonly bts.spark.LegSpreaderParams _leg_params;
|
||||
private readonly double _leg_price_ratio, _leg_qty_ratio;
|
||||
private readonly mbts.co2.IMDHandle _md_handle;
|
||||
private readonly ISingleSecurityExchangeGateway _order_gateway;
|
||||
private readonly IDictionary<QuoterState, Action<ExternalEvents>> _handler_map;
|
||||
private readonly IDictionary<uint, ContractLeg> _leg_map;
|
||||
public Action<bts.spark.Fill> on_fill = f => { };
|
||||
public Action<Order> on_send_hedge_order = o => { };
|
||||
public Action<uint, bool> on_end = (f, b) => { };
|
||||
|
||||
/// This is the actual state
|
||||
private QuoteLegPriceQuantityState _price_qty_state;
|
||||
private QuoterState _state = QuoterState.START;
|
||||
private TempFlatOrderState _order_state;
|
||||
|
||||
public SingleLegQuoter(Order order,
|
||||
ContractLeg leg,
|
||||
LegSpreaderParams leg_spreader_param,
|
||||
mbts.co2.IMDHandle md_handle,
|
||||
ISingleSecurityExchangeGateway order_gateway)
|
||||
{
|
||||
mbts.Logger.assert(leg.Security.ContractSpec.LowTick == leg.Security.ContractSpec.HighTick);
|
||||
_tick_size = leg.Security.ContractSpec.LowTick;
|
||||
_order = order;
|
||||
_leg = leg;
|
||||
_leg_params = leg_spreader_param;
|
||||
_leg_qty_ratio = leg.Quantity; /// TODO, can be a double
|
||||
_leg_price_ratio = leg_spreader_param.PriceMultiplier;
|
||||
_md_handle = md_handle;
|
||||
_order_gateway = order_gateway;
|
||||
_handler_map = new Dictionary<QuoterState, Action<ExternalEvents>>()
|
||||
{
|
||||
{QuoterState.WAITING_FOR_MARKET, _handle_events_in_WAITING_FOR_MARKET},
|
||||
{QuoterState.WAITING_FOR_FIRST_ACK, _handle_events_in_WAITING_FOR_FIRST_ACK},
|
||||
{QuoterState.WORKING, _handle_events_in_WORKING},
|
||||
{QuoterState.WAITING_FOR_CANCEL_ACK, _handle_events_in_WAITING_FOR_CANCEL_ACK}
|
||||
};
|
||||
_leg_map = order.Security.Synthetic.Legs.ToDictionary(l => l.Security.Id, l => l);
|
||||
_price_qty_state = new QuoteLegPriceQuantityState(_order.Price, Convert.ToUInt32(order.Size * _leg_qty_ratio), 0, 0, _compute_market_adjusted_price_qty);
|
||||
_change_state(QuoterState.START);
|
||||
}
|
||||
|
||||
private uint _get_target_leg_qty() { return Convert.ToUInt32(_order.Size * _leg_qty_ratio); }
|
||||
|
||||
/// Based on the desired leg qty it looks at all the other legs
|
||||
/// and see how much it can get and at what price
|
||||
private Tuple<double, uint> _compute_market_adjusted_price_qty(uint desired_leg_qty)
|
||||
{
|
||||
/// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
private Order _get_new_order()
|
||||
{
|
||||
/// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
private uint _get_equivelant_qty(uint other_leg_key, uint other_leg_fill_qty)
|
||||
{
|
||||
/// TODO
|
||||
mbts.Logger.assert (_leg_map.ContainsKey (other_leg_key));
|
||||
return Convert.ToUInt32(other_leg_fill_qty * _leg_qty_ratio / _leg_map[other_leg_key].Quantity);
|
||||
}
|
||||
|
||||
private void _change_state(QuoterState new_state)
|
||||
{
|
||||
QuoterState current_state = _state;
|
||||
_state = new_state;
|
||||
if (new_state == QuoterState.WAITING_FOR_MARKET)
|
||||
{
|
||||
mbts.Logger.assert(current_state == QuoterState.START, String.Format("Only {0}->{1} possible", QuoterState.START.ToString(), new_state.ToString()));
|
||||
/// TODO: sub to the market here
|
||||
_handle_events_in_WAITING_FOR_MARKET(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (new_state == QuoterState.WAITING_FOR_FIRST_ACK)
|
||||
{
|
||||
/// change to this state means send the order
|
||||
mbts.Logger.assert(current_state == QuoterState.WAITING_FOR_MARKET, String.Format("Only {0}->{1} possible", QuoterState.WAITING_FOR_MARKET.ToString(), new_state.ToString()));
|
||||
mbts.Logger.assert(_price_qty_state.aggregated_filled_qty == 0);
|
||||
mbts.Logger.assert(_price_qty_state.out_qty == 0);
|
||||
/// All changes to price (for spread, there is no active leg order till now) and qty
|
||||
/// have been subsumed into the price_qty_state
|
||||
/// Also anything that would have ended the order (mainly other leg fills
|
||||
/// and subsequent hedges) would have been checked in waiting_for_md
|
||||
_price_qty_state.out_price = _price_qty_state.computed_price;
|
||||
_price_qty_state.out_qty = _price_qty_state.computed_qty;
|
||||
/// This is the first and only time an order is sent from SingleLegQuoter
|
||||
/// TODO send order
|
||||
}
|
||||
else if (new_state == QuoterState.WORKING)
|
||||
{
|
||||
mbts.Logger.assert(current_state == QuoterState.WAITING_FOR_FIRST_ACK, String.Format("Only {0}->{1} possible", QuoterState.WAITING_FOR_FIRST_ACK.ToString(), new_state.ToString()));
|
||||
/// check for pending changes immediatly
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
#region MD/Order Callback
|
||||
|
||||
private void _on_md()
|
||||
{
|
||||
mbts.Logger.log(bts.log.Level.Info, bts.log.Subsystem.Engine, String.Format("Received MD for contract", _leg.ToString()));
|
||||
_handler_map[_state](ExternalEvents.MDUpdate);
|
||||
}
|
||||
|
||||
private void _on_order_callback(TempFlatOrderState order_state)
|
||||
{
|
||||
_order_state = order_state;
|
||||
ExternalEvents e = ExternalEvents.OrderStatusNormal;
|
||||
if (order_state.current_state == TempFlatOrderState.State.Cancelled)
|
||||
e = ExternalEvents.OrderStatusCancelled;
|
||||
else if (order_state.current_state == TempFlatOrderState.State.Filled)
|
||||
e = ExternalEvents.OrderStatusFilled;
|
||||
/// So if an order is still Open but somehow there was an error (caused
|
||||
/// by one of the last actions maybe), it is converted into an error state
|
||||
/// for the order
|
||||
else
|
||||
{
|
||||
if (order_state.last_error_state == TempFlatOrderState.ErrorState.Something)
|
||||
e = ExternalEvents.OrderStatusError;
|
||||
}
|
||||
_handler_map[_state](e);
|
||||
}
|
||||
|
||||
private void _on_fill(double price, BuySell side, uint qty)
|
||||
{
|
||||
_price_qty_state.update_fills(qty);
|
||||
_handler_map[_state](ExternalEvents.OrderFills);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void _handle_events_in_WAITING_FOR_MARKET(ExternalEvents e)
|
||||
{
|
||||
if (e == ExternalEvents.OrderStatusNormal || e == ExternalEvents.OrderStatusError || e == ExternalEvents.OrderStatusFilled ||
|
||||
e == ExternalEvents.OrderStatusCancelled || e == ExternalEvents.OrderFills)
|
||||
{
|
||||
mbts.Logger.assert(false, "Order should have already reached terminal state, in this state");
|
||||
}
|
||||
else if (e == ExternalEvents.UserLegPriceChange || e == ExternalEvents.UserLegCancel)
|
||||
{
|
||||
mbts.Logger.assert (false, "No active working order for this leg");
|
||||
}
|
||||
else if (e == ExternalEvents.MDUpdate)
|
||||
{
|
||||
_price_qty_state.update_md();
|
||||
if (_price_qty_state.computed_qty > 0)
|
||||
_change_state(QuoterState.WAITING_FOR_FIRST_ACK);
|
||||
else
|
||||
{
|
||||
if (_price_qty_state.aggegated_hedged_qty >= _price_qty_state.target_leg_qty)
|
||||
{
|
||||
/// Other fills could keep coming , reducing this leg's quoting qty.
|
||||
/// If the other sides have been fully filled, this means this side
|
||||
/// will be all hedges, and no need to quote
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e == ExternalEvents.OtherLegQuotingFill)
|
||||
{
|
||||
/// Since this will result in a reduced quoting
|
||||
/// quantity, the above can apply
|
||||
_handle_events_in_WAITING_FOR_MARKET(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserSpreadPriceChange)
|
||||
{
|
||||
_handle_events_in_WAITING_FOR_MARKET(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserSpreadQuantityChange)
|
||||
{
|
||||
/// if the quantity is reduced, then the md might be
|
||||
/// sufficient which can make this state-machine change states
|
||||
_handle_events_in_WAITING_FOR_MARKET(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.CancelOrder)
|
||||
{
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
}
|
||||
|
||||
private void _handle_events_in_WAITING_FOR_FIRST_ACK(ExternalEvents e)
|
||||
{
|
||||
if (e == ExternalEvents.OrderStatusNormal)
|
||||
{
|
||||
_change_state(QuoterState.WORKING);
|
||||
}
|
||||
else if (e == ExternalEvents.OrderStatusError || e == ExternalEvents.CancelOrder || e == ExternalEvents.UserLegCancel)
|
||||
{
|
||||
_change_state(QuoterState.WAITING_FOR_CANCEL_ACK);
|
||||
}
|
||||
else if (e == ExternalEvents.OrderStatusFilled || e == ExternalEvents.OrderStatusCancelled)
|
||||
{
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
}
|
||||
|
||||
private void _handle_events_in_WAITING_FOR_CANCEL_ACK(ExternalEvents e)
|
||||
{
|
||||
if (e == ExternalEvents.OrderStatusCancelled || e == ExternalEvents.OrderStatusFilled)
|
||||
{
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
}
|
||||
|
||||
private void _handle_events_in_WORKING(ExternalEvents e)
|
||||
{
|
||||
if (e == ExternalEvents.OrderStatusNormal)
|
||||
{
|
||||
}
|
||||
else if (e == ExternalEvents.OrderStatusError)
|
||||
{
|
||||
_change_state(QuoterState.WAITING_FOR_CANCEL_ACK);
|
||||
}
|
||||
else if (e == ExternalEvents.OrderStatusFilled)
|
||||
{
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
else if (e == ExternalEvents.OrderStatusCancelled)
|
||||
{
|
||||
_change_state(QuoterState.END);
|
||||
}
|
||||
else if (e == ExternalEvents.OrderFills)
|
||||
{
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.MDUpdate)
|
||||
{
|
||||
_price_qty_state.update_md();
|
||||
if (_price_qty_state.computed_qty == 0)
|
||||
{
|
||||
_change_state(QuoterState.WAITING_FOR_CANCEL_ACK);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_price_qty_state.out_qty != _price_qty_state.computed_qty)
|
||||
{
|
||||
_price_qty_state.out_price = _price_qty_state.computed_price;
|
||||
/// TODO : modify order
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_price_qty_state.computed_price != _price_qty_state.out_price)
|
||||
{
|
||||
/// TODO: check slop and modify order
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e == ExternalEvents.OtherLegQuotingFill)
|
||||
{
|
||||
/// Since this shoots off a hedge, the
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserSpreadPriceChange)
|
||||
{
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserSpreadQuantityChange)
|
||||
{
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserLegPriceChange)
|
||||
{
|
||||
_handle_events_in_WORKING(ExternalEvents.MDUpdate);
|
||||
}
|
||||
else if (e == ExternalEvents.UserLegCancel)
|
||||
{
|
||||
_change_state(QuoterState.WAITING_FOR_CANCEL_ACK);
|
||||
}
|
||||
else if (e == ExternalEvents.CancelOrder)
|
||||
{
|
||||
_change_state(QuoterState.WAITING_FOR_CANCEL_ACK);
|
||||
}
|
||||
}
|
||||
|
||||
#region External Calls
|
||||
|
||||
public void set_other_leg_fill(uint sec_key, bts.api.BuySell side, uint fill_qty)
|
||||
{
|
||||
/// reduce the leg qty and send out a hedge request
|
||||
uint equivelant_qty = _get_equivelant_qty(sec_key, fill_qty);
|
||||
_price_qty_state.update_hedges(equivelant_qty);
|
||||
_handler_map[_state](ExternalEvents.OtherLegQuotingFill);
|
||||
}
|
||||
|
||||
public void change_main_order_price(double new_price)
|
||||
{
|
||||
_order.Price = new_price;
|
||||
_price_qty_state.update_target_spread_price(new_price);
|
||||
_handler_map[_state](ExternalEvents.UserSpreadPriceChange);
|
||||
}
|
||||
|
||||
/// This is a user changing the qty of the order
|
||||
public void change_main_order_qty(uint new_qty)
|
||||
{
|
||||
_order.Size = new_qty;
|
||||
_price_qty_state.update_target_leg_qty(_get_target_leg_qty());
|
||||
_handler_map[_state](ExternalEvents.UserSpreadQuantityChange);
|
||||
}
|
||||
|
||||
public void cancel_order()
|
||||
{
|
||||
_handler_map[_state](ExternalEvents.CancelOrder);
|
||||
}
|
||||
|
||||
public void change_leg_price(double new_price)
|
||||
{
|
||||
_price_qty_state.update_target_leg_price(new_price);
|
||||
_handler_map[_state](ExternalEvents.UserLegPriceChange);
|
||||
}
|
||||
|
||||
public void cancel_leg_order()
|
||||
{
|
||||
_handler_map[_state](ExternalEvents.UserLegCancel);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
public class TempFlatOrderState
|
||||
{
|
||||
public enum ErrorState
|
||||
{
|
||||
None = 0,
|
||||
Something
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
Open,
|
||||
Cancelled,
|
||||
Filled
|
||||
}
|
||||
|
||||
public readonly string id;
|
||||
public readonly double price;
|
||||
public readonly uint qty;
|
||||
public readonly uint filled;
|
||||
public ErrorState last_error_state;
|
||||
public State current_state;
|
||||
}
|
||||
|
||||
public class Spreader
|
||||
{
|
||||
private readonly IDictionary<ContractLeg, SingleLegQuoter> _quoter_map = new Dictionary<ContractLeg, SingleLegQuoter>();
|
||||
private readonly List<SingleFillHedger> _hedgers = new List<SingleFillHedger>();
|
||||
private readonly IDictionary<ContractLeg, uint> _fill_map = new Dictionary<ContractLeg, uint>();
|
||||
|
||||
public Spreader(Order synthetic_spread_order)
|
||||
{
|
||||
ExecutionStrategy exec_strategy = synthetic_spread_order.ExecutionStrategy;
|
||||
foreach (ContractLeg l in synthetic_spread_order.Security.Synthetic.Legs)
|
||||
{
|
||||
var leg_spreader_params = exec_strategy.LegParamsMap[l.Security.Id];
|
||||
SingleLegQuoter quoter = new SingleLegQuoter(synthetic_spread_order, l, leg_spreader_params, null, null);
|
||||
_quoter_map[l] = quoter;
|
||||
quoter.on_fill += f => _on_quote_fill (l, f);
|
||||
quoter.on_send_hedge_order += o => _on_send_hedge_order(l, o);
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_quote_fill(ContractLeg leg, Fill fill)
|
||||
{
|
||||
_update_fill(leg, fill);
|
||||
/// tell all the quoters about this fill)
|
||||
foreach (SingleLegQuoter q in _quoter_map.Values)
|
||||
q.set_other_leg_fill(leg.Security.Id, fill.Side, fill.Size);
|
||||
}
|
||||
|
||||
private void _on_send_hedge_order(ContractLeg leg, Order hedge_order)
|
||||
{
|
||||
SingleFillHedger hedger = new SingleFillHedger(hedge_order, leg, null, null, null);
|
||||
_hedgers.Add(hedger);
|
||||
}
|
||||
|
||||
private void _on_hedge_fill(ContractLeg leg, Fill fill)
|
||||
{
|
||||
_update_fill(leg, fill);
|
||||
}
|
||||
|
||||
private void _update_fill(ContractLeg leg, Fill fill)
|
||||
{
|
||||
if (!_fill_map.ContainsKey(leg))
|
||||
_fill_map.Add(leg, 0);
|
||||
_fill_map[leg] = _fill_map[leg] + fill.Size;
|
||||
}
|
||||
|
||||
#region User Action
|
||||
/// Changes qty of the spreader order
|
||||
public void change_qty(uint new_qty)
|
||||
{
|
||||
}
|
||||
|
||||
/// Changes price of the spreader order
|
||||
public void change_price(double new_price)
|
||||
{
|
||||
}
|
||||
|
||||
/// Changes price of one leg
|
||||
public void change_leg_price(Security security, double new_leg_price)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters">
|
||||
<uspcv:TickDisplayTwoWayConverter x:Key="TickDisplayTwoWayConverter" x:Shared="False"/>
|
||||
<ControlTemplate x:Key="PriceEntryTemplate" TargetType="usp:PriceEntryControl">
|
||||
<c:TickUpDown BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
TickUpCommand="{TemplateBinding TickUpCommand}"
|
||||
TickDownCommand="{TemplateBinding TickDownCommand}">
|
||||
<TextBox x:Name="_text" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TickDisplayTwoWayConverter}, Mode=TwoWay}"/>
|
||||
</c:TickUpDown>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="usp:PriceEntryControl">
|
||||
<Setter Property="Template" Value="{StaticResource PriceEntryTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -1,73 +0,0 @@
|
||||
using bts.api;
|
||||
using mbts.spark;
|
||||
using mbts.ui.spark.converters;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PriceEntryControl.xaml
|
||||
/// </summary>
|
||||
internal class PriceEntryControl : Control
|
||||
{
|
||||
static PriceEntryControl() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(PriceEntryControl), new FrameworkPropertyMetadata(typeof(PriceEntryControl)));
|
||||
}
|
||||
|
||||
#region Value
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(PriceEntryControl), new FrameworkPropertyMetadata(double.NaN, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region TickUp
|
||||
private static readonly DependencyPropertyKey TickUpCommandPropertyKey = DependencyProperty.RegisterReadOnly("TickUpCommand", typeof(ICommand), typeof(PriceEntryControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty TickUpCommandProperty = TickUpCommandPropertyKey.DependencyProperty;
|
||||
public ICommand TickUpCommand { get => GetValue(TickUpCommandProperty) as ICommand; private set => SetValue(TickUpCommandPropertyKey, value); }
|
||||
#endregion
|
||||
|
||||
#region TickDown
|
||||
private static readonly DependencyPropertyKey TickDownCommandPropertyKey = DependencyProperty.RegisterReadOnly("TickDownCommand", typeof(ICommand), typeof(PriceEntryControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty TickDownCommandProperty = TickDownCommandPropertyKey.DependencyProperty;
|
||||
public ICommand TickDownCommand { get => GetValue(TickDownCommandProperty) as ICommand; private set => SetValue(TickDownCommandPropertyKey, value); }
|
||||
#endregion
|
||||
|
||||
#region ContractSpec
|
||||
public static readonly DependencyProperty ContractSpecProperty = DependencyProperty.Register("ContractSpec", typeof(ContractSpecification), typeof(PriceEntryControl), new PropertyMetadata(TickUtils.DefaultSpec, OnContractSpecChanged));
|
||||
private static void OnContractSpecChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((PriceEntryControl)d)._update_text_binding(); }
|
||||
public ContractSpecification ContractSpec { get => GetValue(ContractSpecProperty) as ContractSpecification; set => SetValue(ContractSpecProperty, value); }
|
||||
#endregion
|
||||
|
||||
public PriceEntryControl() {
|
||||
TickUpCommand = new DelegateCommand(_tick_up);
|
||||
TickDownCommand = new DelegateCommand(_tick_down);
|
||||
}
|
||||
|
||||
private TextBox _text;
|
||||
|
||||
private void _tick_up() { SetCurrentValue(ValueProperty, ContractSpec.tickup(Value)); }
|
||||
private void _tick_down() { SetCurrentValue(ValueProperty, ContractSpec.tickdown(Value)); }
|
||||
|
||||
private void _update_text_binding() {
|
||||
if (_text != null) {
|
||||
var spec = ContractSpec;
|
||||
if (spec != null) {
|
||||
var be = _text.GetBindingExpression(TextBox.TextProperty);
|
||||
if (be != null) {
|
||||
var converter = be.ParentBinding.Converter as TickDisplayTwoWayConverter;
|
||||
if (converter != null) {
|
||||
converter.ContractSpec = spec;
|
||||
be.UpdateTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
_text = GetTemplateChild("_text") as TextBox;
|
||||
_update_text_binding();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
using static mbts.ui.utilities.DisplayNameHelper;
|
||||
|
||||
namespace mbts.spark {
|
||||
public static class OrderUtils {
|
||||
@@ -16,24 +15,12 @@ namespace mbts.spark {
|
||||
return camel_to_title_case(order.Descriptor.Name);
|
||||
}
|
||||
|
||||
// Adds spaces to CamelCase => "Camel Case"
|
||||
public static string camel_to_title_case(string name) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var ch in name) {
|
||||
if (sb.Length == 0) { sb.Append(Char.ToUpper(ch)); }
|
||||
else {
|
||||
if (Char.IsUpper(ch)) {
|
||||
sb.Append(" ");
|
||||
}
|
||||
sb.Append(ch);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
public static string algo_display_name(Order.AlgoOrderTypeOneofCase algo) {
|
||||
return algo_display_name(algo.ToString());
|
||||
}
|
||||
|
||||
|
||||
public static string algo_display_name(Order.AlgoOrderTypeOneofCase algo) {
|
||||
return camel_to_title_case(algo.ToString()).Replace(" Order", "");
|
||||
public static string algo_display_name(string algo_name) {
|
||||
return camel_to_title_case(Regex.Replace(algo_name, "Order", string.Empty, RegexOptions.IgnoreCase));
|
||||
}
|
||||
|
||||
public static long filled(OrderBookEntry order) {
|
||||
@@ -54,6 +41,7 @@ namespace mbts.spark {
|
||||
case Order.AlgoOrderTypeOneofCase.StopLimitOrder: return order.StopLimitOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.IcebergOrder: return order.IcebergOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder: return order.CrossingHedgeOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder: return order.SimpleHedgeOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.CustomOrder: return order.CustomOrder;
|
||||
default:
|
||||
throw new MissingFieldException($"No field for: {order.AlgoOrderTypeCase}");
|
||||
@@ -71,10 +59,6 @@ namespace mbts.spark {
|
||||
|
||||
}
|
||||
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook book, uint security) {
|
||||
return book.get_all_orders_for_security(security).Where(order => is_active(order.OrderStatus)).ToList();
|
||||
}
|
||||
|
||||
public static string order_summary(OrderBookEntry order) {
|
||||
return $"{camel_to_title_case(order.order().AlgoOrderTypeCase.ToString())}: {order.order().Side} {order.order().Size} at {order.order().Price}";
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using bts.api;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
static class SparkBusData
|
||||
internal static class SparkBusData
|
||||
{
|
||||
public class BusMessageWrapper<T>
|
||||
{
|
||||
@@ -50,19 +50,27 @@ namespace mbts.spark
|
||||
}
|
||||
public class ShowAuditLogsMessage { }
|
||||
public class ShowFillsMessage { }
|
||||
public class ShowLadderMessage : BusMessageWrapper<IReadOnlyCollection<SecurityMD>> {
|
||||
public ShowLadderMessage(SecurityMD smd) : this(new[] { smd }) { }
|
||||
public ShowLadderMessage(IReadOnlyCollection<SecurityMD> smd) : base(smd) { }
|
||||
public class ShowLadderMessage : BusMessageWrapper<IReadOnlyCollection<Security>> {
|
||||
public ShowLadderMessage(Security security) : this(new[] { security }) { }
|
||||
public ShowLadderMessage(IReadOnlyCollection<Security> security) : base(security) { }
|
||||
}
|
||||
public class ShowLinkedLadderMessage : BusMessageWrapper<IObservable<SecurityMD>> {
|
||||
public ShowLinkedLadderMessage(IObservable<SecurityMD> security_md) : base(security_md) { }
|
||||
}
|
||||
public class ShowMarketViewMessage : BusMessageWrapper<IReadOnlyCollection<Security>> {
|
||||
public ShowMarketViewMessage(IReadOnlyCollection<Security> securities) : base(securities) { }
|
||||
}
|
||||
public class ShowOrderBookMessage { }
|
||||
public class ShowOrderModifyMessage : BusMessageWrapper<Order> {
|
||||
public ShowOrderModifyMessage(Order order) : base(order) { }
|
||||
public class ShowOrderModifyMessage : BusMessageWrapper<IReadOnlyCollection<Order>> {
|
||||
public ShowOrderModifyMessage(Order order) : base(new[] { order }) { }
|
||||
public ShowOrderModifyMessage(IReadOnlyCollection<Order> orders) : base(orders) { }
|
||||
}
|
||||
public class ShowOrderTicketMessage : BusMessageWrapper<Order> {
|
||||
public ShowOrderTicketMessage(Order order) : base(order) { }
|
||||
public class ShowOrderTicketMessage : BusMessageWrapper<IReadOnlyCollection<Order>> {
|
||||
public ShowOrderTicketMessage(Order order) : base(new[] { order }) { }
|
||||
public ShowOrderTicketMessage(IReadOnlyCollection<Order> orders) : base(orders) { }
|
||||
}
|
||||
public class ShowLinkedOrderTicketMessage : BusMessageWrapper<IObservable<Order>> {
|
||||
public ShowLinkedOrderTicketMessage(IObservable<Order> order) : base(order) { }
|
||||
}
|
||||
public class ShowPositionsMessage { }
|
||||
public class ShowSpreadMatrixMessage : BusMessageWrapper<IReadOnlyCollection<Security>> {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using mbts.ui;
|
||||
using System.Windows.Markup;
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using mbts.ui;
|
||||
using System.Windows.Markup;
|
||||
using mbts.co2;
|
||||
using bts.api;
|
||||
using System.Windows.Input;
|
||||
@@ -16,45 +16,47 @@ using System.Windows.Media.Animation;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderGridHost : Control {
|
||||
const int _rowcount = 1001;
|
||||
|
||||
LadderSettings _settings;
|
||||
LadderVM _vm;
|
||||
ContractSpecification _spec;
|
||||
|
||||
VisualHost _visualHost = new VisualHost() {};
|
||||
LadderOrdersHost _ordershost;
|
||||
ScrollViewer _scrollViewer;
|
||||
ulong _prices_updated;
|
||||
NativePriceSize[] _bids, _asks;
|
||||
bool _price_dirty = false;
|
||||
double[] _price_list = null;
|
||||
double _last_mid;
|
||||
NativePriceSize _last_trade;
|
||||
DrawingVisual _bidvis = new DrawingVisual(),
|
||||
_askvis = new DrawingVisual(),
|
||||
_pricevis = new DrawingVisual(),
|
||||
_lastvis = new DrawingVisual(),
|
||||
_midvis = new DrawingVisual(),
|
||||
_gridvis = new DrawingVisual();
|
||||
|
||||
public LadderGridHost() {
|
||||
_ordershost = new LadderOrdersHost(this) { HorizontalAlignment = HorizontalAlignment.Left };
|
||||
var scrollViewerFactory = new FrameworkElementFactory(typeof(ScrollViewer));
|
||||
scrollViewerFactory.SetValue(FocusableProperty, false);
|
||||
Template = new ControlTemplate() {
|
||||
VisualTree = scrollViewerFactory
|
||||
};
|
||||
Loaded += (_, __) => scroll_to_center();
|
||||
RecenterCommand = new DelegateCommand(o => scroll_to_center());
|
||||
}
|
||||
|
||||
public event Action<double,BuySell?> click;
|
||||
|
||||
public Security security => _vm.security;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderGridHost : Control {
|
||||
const int _rowcount = 1001;
|
||||
|
||||
IDisposable _settings_sub, _tick_sub;
|
||||
LadderSettings _settings;
|
||||
LadderVM _vm;
|
||||
ContractSpecification _spec;
|
||||
|
||||
VisualHost _visualHost = new VisualHost() {};
|
||||
LadderOrdersHost _ordershost;
|
||||
ScrollViewer _scrollViewer;
|
||||
ulong _prices_updated;
|
||||
NativePriceSize[] _bids, _asks;
|
||||
bool _price_dirty = false;
|
||||
double[] _price_list = null;
|
||||
double _last_mid;
|
||||
NativePriceSize _last_trade;
|
||||
DrawingVisual _bidvis = new DrawingVisual(),
|
||||
_askvis = new DrawingVisual(),
|
||||
_pricevis = new DrawingVisual(),
|
||||
_lastvis = new DrawingVisual(),
|
||||
_midvis = new DrawingVisual(),
|
||||
_gridvis = new DrawingVisual();
|
||||
|
||||
public LadderGridHost() {
|
||||
_ordershost = new LadderOrdersHost(this) { HorizontalAlignment = HorizontalAlignment.Left };
|
||||
var scrollViewerFactory = new FrameworkElementFactory(typeof(ScrollViewer));
|
||||
scrollViewerFactory.SetValue(FocusableProperty, false);
|
||||
Template = new ControlTemplate() {
|
||||
VisualTree = scrollViewerFactory
|
||||
};
|
||||
Loaded += (_, __) => scroll_to_center();
|
||||
RecenterCommand = new DelegateCommand(o => scroll_to_center());
|
||||
DataContextChanged += (s, e) => _connect_vm();
|
||||
}
|
||||
|
||||
public event Action<double,BuySell?> click;
|
||||
|
||||
public Security security => _vm.security;
|
||||
|
||||
public ICommand RecenterCommand { get; }
|
||||
public ICommand Command {
|
||||
get { return (ICommand)GetValue(CommandProperty); }
|
||||
@@ -96,22 +98,30 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
base.OnApplyTemplate();
|
||||
_scrollViewer = this.descendants_of_type<ScrollViewer>().First();
|
||||
// _visualHost draws grid lines on top of _ordershost
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate() {
|
||||
base.OnApplyTemplate();
|
||||
_scrollViewer = this.descendants_of_type<ScrollViewer>().First();
|
||||
// _visualHost draws grid lines on top of _ordershost
|
||||
var grid = new Grid() { Children = { _ordershost, _visualHost, } };
|
||||
_scrollViewer.Content = grid;
|
||||
_vm = DataContext as LadderVM;
|
||||
_spec = _vm.security.ContractSpec;
|
||||
if (_vm != null) {
|
||||
_vm.on_tick += tick;
|
||||
_vm.settings.Subscribe(settings_updated);
|
||||
}
|
||||
}
|
||||
|
||||
_scrollViewer.Content = grid;
|
||||
_connect_vm();
|
||||
}
|
||||
|
||||
private void _connect_vm() {
|
||||
Disposable.dispose(ref _settings_sub);
|
||||
Disposable.dispose(ref _tick_sub);
|
||||
_vm = DataContext as LadderVM;
|
||||
if (_vm != null) {
|
||||
_spec = _vm.security.ContractSpec;
|
||||
_prices_updated = 0;
|
||||
_vm.on_tick += tick;
|
||||
_settings_sub = _vm.settings.Subscribe(settings_updated);
|
||||
_tick_sub = Disposable.Create(() => _vm.on_tick -= tick);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<(LadderColumnSettings, DrawingVisual)> columns {
|
||||
get {
|
||||
if (_settings != null) {
|
||||
@@ -122,32 +132,32 @@ namespace mbts.spark {
|
||||
yield return (_settings.last_column, _lastvis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void settings_updated(LadderSettings s) {
|
||||
_settings = s;
|
||||
}
|
||||
|
||||
private void settings_updated(LadderSettings s) {
|
||||
_settings = s;
|
||||
_visualHost.Height = _rowcount * s.row_height;
|
||||
_price_dirty = _settings.price_column.show;
|
||||
|
||||
// Clear and re-add the columns to the viewer to ensure offset/visibility is correct
|
||||
_visualHost.Clear();
|
||||
double offset = 0.0;
|
||||
|
||||
// Orders column
|
||||
_ordershost.Visibility = s.orders_column.show ? Visibility.Visible : Visibility.Collapsed;
|
||||
_price_dirty = _settings.price_column.show;
|
||||
|
||||
// Clear and re-add the columns to the viewer to ensure offset/visibility is correct
|
||||
_visualHost.Clear();
|
||||
double offset = 0.0;
|
||||
|
||||
// Orders column
|
||||
_ordershost.Visibility = s.orders_column.show ? Visibility.Visible : Visibility.Collapsed;
|
||||
if (s.orders_column.show) {
|
||||
_ordershost.Width = s.orders_column.width;
|
||||
_ordershost.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
offset += s.orders_column.width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ((var col, var visual) in columns) {
|
||||
if (col.show && visual != null) {
|
||||
visual.Offset = new Vector(offset, 0);
|
||||
offset += col.width;
|
||||
_visualHost.AddVisualChild(visual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renders the grid lines
|
||||
_visualHost.AddVisualChild(_gridvis);
|
||||
@@ -181,8 +191,8 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
if (_settings != null) {
|
||||
private void tick() {
|
||||
if (_settings != null) {
|
||||
if (_vm.md.get_depth(ref _prices_updated, ref _bids, ref _asks)) {
|
||||
var mid = TickUtils.mid_tick(_spec, _bids[0].price, _asks[0].price);
|
||||
if (_price_dirty) {
|
||||
@@ -210,9 +220,9 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
_price_dirty = false;
|
||||
}
|
||||
}
|
||||
_price_dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -265,5 +275,5 @@ namespace mbts.spark {
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,9 @@ namespace mbts.spark {
|
||||
new LimitOrder (),
|
||||
new StopMarketOrder (),
|
||||
new StopLimitOrder (),
|
||||
new IcebergOrder (),
|
||||
new IcebergOrder(),
|
||||
new BTSStopOrder (),
|
||||
new BTSIcebergOrder ()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,6 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
base.Dispose(disposing);
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,8 @@ using System.Windows.Shapes;
|
||||
|
||||
namespace mbts.spark {
|
||||
public partial class LadderView : UserControl {
|
||||
readonly LadderVM _vm;
|
||||
internal LadderView(LadderVM vm) {
|
||||
internal LadderView() {
|
||||
InitializeComponent();
|
||||
DataContext = _vm = vm;
|
||||
//KeyDown += key_down;
|
||||
}
|
||||
|
||||
//private void key_down(object sender, KeyEventArgs e) {
|
||||
// _vm.key_pressed(e);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace mbts.spark {
|
||||
_order_template = order_template;
|
||||
_meta = meta;
|
||||
|
||||
name = OrderUtils.camel_to_title_case(order.Descriptor.Name);
|
||||
name = OrderUtils.algo_display_name(order.Descriptor.Name);
|
||||
type_name = order.Descriptor.Name;
|
||||
_accessor = Order.Descriptor.Oneofs
|
||||
.First(ood => ood.Name == "algo_order_type")
|
||||
@@ -62,6 +62,8 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public bool is_bts_type => name.Contains("BTS");
|
||||
|
||||
public bool key_match(KeyEventArgs key) {
|
||||
return key.Key == (Key.A + name[0] - 'A');
|
||||
}
|
||||
|
||||
@@ -8,19 +8,15 @@ using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using static mbts.spark.SparkBusData;
|
||||
using static mbts.spark.SparkTags;
|
||||
using static mbts.spark.utilities.UserConfigurationHelper;
|
||||
using MDMap = System.Collections.Generic.Dictionary<System.UInt32, mbts.spark.SecurityMD>;
|
||||
using SecurityKey = System.UInt32;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class MarketViewModel : IDisposable
|
||||
internal class MarketViewModel : IDisposable
|
||||
{
|
||||
public MarketViewModel(IBus bus) {
|
||||
_bus = bus;
|
||||
_subs.Add(_bus.subscribe<Dictionary<SecurityKey, SecurityMD>>(SecuritiesTag).ObserveOnDispatcher().Subscribe(m => {
|
||||
_data = m;
|
||||
_fire();
|
||||
}));
|
||||
_subs.Add(_bus.subscribe<PositionsMessage>(PositionsTag).Subscribe(m => {
|
||||
foreach (var kv in m.data) _positions_demuxer.push_data(kv.Key, kv.Value);
|
||||
}));
|
||||
@@ -29,33 +25,24 @@ namespace mbts.spark
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly OrdersModel _orders_model;
|
||||
private readonly Subject<IEnumerable<SecurityMD>> _rows_subject = new Subject<IEnumerable<SecurityMD>>();
|
||||
private readonly Subject<HashSet<SecurityKey>> _securities_subject = new Subject<HashSet<SecurityKey>>();
|
||||
private readonly ObservableDemuxer<SecurityKey, int> _positions_demuxer = new ObservableDemuxer<SecurityKey, int>(k => 0);
|
||||
private IList<IDisposable> _subs = new List<IDisposable>();
|
||||
private HashSet<SecurityKey> _active_securities = new HashSet<SecurityKey>();
|
||||
private IDictionary<SecurityKey, SecurityMD> _data = new Dictionary<SecurityKey, SecurityMD>();
|
||||
|
||||
private void _fire() { _rows_subject.OnNext(_data.Where(kv => _active_securities.Contains(kv.Key)).Select(kv => kv.Value)); }
|
||||
|
||||
public IObservable<IEnumerable<SecurityMD>> rows => _rows_subject.AsObservable();
|
||||
public IObservable<IEnumerable<SecurityMD>> rows => _bus.subscribe<MDMap>(SecuritiesTag).StartWith(new MDMap()).CombineLatest(_securities_subject, (md, secs) => md.Intersect(secs, kv => kv.Key).Select(kv => kv.Value));
|
||||
public IReadOnlyCollection<Security> all_securities => _data.Values.Select(s => s.security).ToList();
|
||||
public OrdersModel orders_model => _orders_model;
|
||||
|
||||
public IObservable<int> security_position(SecurityKey key) { return _positions_demuxer.subscribe(key); }
|
||||
public void show_ladder(Security security) { if (_data.TryGetValue(security.Id, out SecurityMD smd)) _bus.post(ShowLadderTag, new ShowLadderMessage(smd)); }
|
||||
public IObservable<int> security_position(SecurityKey key) { return _positions_demuxer.subscribe(key).DistinctUntilChanged(); }
|
||||
public void show_ladder(Security security) { _bus.post(ShowLadderTag, new ShowLadderMessage(security)); }
|
||||
public void show_order_modify(Order order) { _bus.post(ShowOrderModifyTag, new ShowOrderModifyMessage(order)); }
|
||||
public void show_order_ticket(Security sec, BuySell side, double price, uint size = 1) {
|
||||
_bus.post(ShowOrderTicketTag, new ShowOrderTicketMessage(new Order { User = UserName, Security = sec, Side = side, Price = price, Size = size, LimitOrder = new LimitOrder() }));
|
||||
}
|
||||
public void set_securities(IEnumerable<Security> securities) {
|
||||
_active_securities = new HashSet<SecurityKey>(securities.Select(s => s.Id));
|
||||
_fire();
|
||||
}
|
||||
public void show_order_ticket(Order order) { _bus.post(ShowOrderTicketTag, new ShowOrderTicketMessage(order)); }
|
||||
public void set_securities(IEnumerable<Security> securities) { _securities_subject.OnNext(new HashSet<SecurityKey>(securities.Select(s => s.Id))); }
|
||||
public void Dispose() {
|
||||
Disposable.dispose(_subs);
|
||||
_rows_subject.Dispose();
|
||||
_securities_subject.Dispose();
|
||||
_positions_demuxer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using static mbts.ui.spark.MarketViewView;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal partial class MarketViewVM
|
||||
{
|
||||
public class Row : GridRowViewModelBase<Columns>
|
||||
{
|
||||
public Row(MarketViewVM owner, MarketViewModel model, SecurityMD smd, IObservable<int> position) {
|
||||
_owner = owner;
|
||||
_model = model;
|
||||
security = AddCell(Columns.Security, smd.security);
|
||||
this.position = AddCell(Columns.Position, position, 0);
|
||||
var md_pump = new SecurityMDPump(smd.md);
|
||||
bid_price = AddCell(Columns.Bid, md_pump.bid_price, double.NaN);
|
||||
bid_size = AddCell(Columns.BidSize, md_pump.bid_size, (ushort)0);
|
||||
ask_price = AddCell(Columns.Ask, md_pump.ask_price, double.NaN);
|
||||
ask_size = AddCell(Columns.AskSize, md_pump.ask_size, (ushort)0);
|
||||
last_price = AddCell(Columns.Last, md_pump.last_price, double.NaN);
|
||||
last_size = AddCell(Columns.LastSize, md_pump.last_size, (ushort)0);
|
||||
settlement = AddCell(Columns.Settlement, md_pump.settlement_price, double.NaN);
|
||||
volume = AddCell(Columns.Volume, md_pump.volume, (ulong)0);
|
||||
//
|
||||
_working_orders = new ObservableFilterCollection<OrderBookEntry>(_orders, o => o.is_active());
|
||||
_working_bids = new ObservableFilterCollection<OrderBookEntry>(_working_orders, o => o.order().Side == BuySell.Buy);
|
||||
_working_asks = new ObservableFilterCollection<OrderBookEntry>(_working_orders, o => o.order().Side == BuySell.Sell);
|
||||
_working_bids_sorted = new ObservableSortedCollection<OrderBookEntry>(_working_bids, CompareUtils.NullCheckComparer<OrderBookEntry>((x, y) => y.order().Price.CompareTo(x.order().Price)));
|
||||
_working_asks_sorted = new ObservableSortedCollection<OrderBookEntry>(_working_asks, CompareUtils.NullCheckComparer<OrderBookEntry>((x, y) => x.order().Price.CompareTo(y.order().Price)));
|
||||
_inside_bids = new ObservableFilterCollection<OrderBookEntry>(_working_bids_sorted, o => o.order().Price >= bid_price.output);
|
||||
_inside_asks = new ObservableFilterCollection<OrderBookEntry>(_working_asks_sorted, o => o.order().Price <= ask_price.output);
|
||||
var day_change_src = md_pump.settlement_price.CombineLatest(md_pump.last_price, (s, l) => l - s);
|
||||
var working_best_bid_src = _working_bids_sorted.Observe().Select(_ => _working_bids_sorted.Count == 0 ? double.NaN : _working_bids_sorted.First().order().Price).DistinctUntilChanged();
|
||||
var working_best_ask_src = _working_asks_sorted.Observe().Select(_ => _working_asks_sorted.Count == 0 ? double.NaN : _working_asks_sorted.First().order().Price).DistinctUntilChanged();
|
||||
var working_bids_volume_src = _working_bids.Observe().Select(_ => _working_bids.Aggregate(0u, (v, o) => v + o.order().Size - o.Fills.Aggregate(0u, (fv, f) => fv + f.Size))).DistinctUntilChanged();
|
||||
var working_asks_volume_src = _working_asks.Observe().Select(_ => _working_asks.Aggregate(0u, (v, o) => v + o.order().Size - o.Fills.Aggregate(0u, (fv, f) => fv + f.Size))).DistinctUntilChanged();
|
||||
//
|
||||
day_change = AddCell(Columns.DayChange, day_change_src, double.NaN);
|
||||
session_low = AddCell(Columns.SessionLow, md_pump.session_low, double.NaN);
|
||||
session_high = AddCell(Columns.SessionHigh, md_pump.session_high, double.NaN);
|
||||
working_bids_text = AddCell(Columns.WorkingBids, working_bids_volume_src.CombineLatest(working_best_bid_src, (size, price) => size == 0u ? string.Empty : "{0} @ {1}".fmt(smd.security.ContractSpec.format(price), size)), string.Empty);
|
||||
working_asks_text = AddCell(Columns.WorkingAsks, working_asks_volume_src.CombineLatest(working_best_ask_src, (size, price) => size == 0u ? string.Empty : "{0} @ {1}".fmt(smd.security.ContractSpec.format(price), size)), string.Empty);
|
||||
_working_best_bid = backing(nameof(working_best_bid), working_best_bid_src);
|
||||
_working_best_ask = backing(nameof(working_best_ask), working_best_ask_src);
|
||||
_animation.AnimationsChanged += _animation_AnimationsChanged;
|
||||
_dispose = Disposable.Create(md_pump,
|
||||
position.PairWithPrevious().Select(vals => vals.curr > vals.prev).ObserveOnDispatcher().Subscribe(_animation.animate_position),
|
||||
_working_bids.Observe().Select(_ => _working_bids.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_bids_active),
|
||||
_working_asks.Observe().Select(_ => _working_asks.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_asks_active),
|
||||
_inside_bids.Observe().Select(_ => _inside_bids.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_bids_inside),
|
||||
_inside_asks.Observe().Select(_ => _inside_asks.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_asks_inside),
|
||||
day_change_src.PairWithPrevious().Select(vals => vals.curr > vals.prev).ObserveOnDispatcher().Subscribe(_animation.animate_day_change),
|
||||
Disposable.Create(() => _animation.AnimationsChanged -= _animation_AnimationsChanged)
|
||||
);
|
||||
}
|
||||
private readonly MarketViewVM _owner;
|
||||
private readonly MarketViewModel _model;
|
||||
private readonly AnimationManager _animation = new AnimationManager();
|
||||
private readonly ObservableSortedCollection<OrderBookEntry> _working_bids_sorted, _working_asks_sorted;
|
||||
private readonly ObservableCollection<OrderBookEntry> _orders = new ObservableCollection<OrderBookEntry>();
|
||||
private readonly ObservableFilterCollection<OrderBookEntry> _working_orders, _working_bids, _working_asks, _inside_bids, _inside_asks;
|
||||
private readonly Property<double> _working_best_bid, _working_best_ask;
|
||||
|
||||
private void _animation_AnimationsChanged() { RaisePropertyChanged(nameof(animations)); }
|
||||
|
||||
#region Bound Properties
|
||||
public SelectableViewModelBase<Security> security { get; }
|
||||
public RXReadOnlyDataGridCell<int> position { get; }
|
||||
public RXReadOnlyDataGridCell<double> last_price { get; }
|
||||
public RXReadOnlyDataGridCell<ushort> last_size { get; }
|
||||
public RXReadOnlyDataGridCell<double> bid_price { get; }
|
||||
public RXReadOnlyDataGridCell<ushort> bid_size { get; }
|
||||
public RXReadOnlyDataGridCell<double> ask_price { get; }
|
||||
public RXReadOnlyDataGridCell<ushort> ask_size { get; }
|
||||
public RXReadOnlyDataGridCell<ulong> volume { get; }
|
||||
public RXReadOnlyDataGridCell<double> settlement { get; }
|
||||
public RXReadOnlyDataGridCell<double> day_change { get; }
|
||||
public RXReadOnlyDataGridCell<double> session_low { get; }
|
||||
public RXReadOnlyDataGridCell<double> session_high { get; }
|
||||
public RXReadOnlyDataGridCell<uint> working_bid_volume { get; }
|
||||
public RXReadOnlyDataGridCell<uint> working_ask_volume { get; }
|
||||
public RXReadOnlyDataGridCell<string> working_bids_text { get; }
|
||||
public RXReadOnlyDataGridCell<string> working_asks_text { get; }
|
||||
public double working_best_bid => _working_best_ask.Value;
|
||||
public double working_best_ask => _working_best_ask.Value;
|
||||
public IEnumerable<CellAnimation> animations => _animation.get_animations();
|
||||
public ICommand show_ladder => new DelegateCommand(() => _model.show_ladder(security.value));
|
||||
public ICommand show_order_ticket => new DelegateCommand<Columns>(col => _model.show_order_ticket(_create_order(this, col)));
|
||||
#endregion
|
||||
|
||||
public void refresh(IEnumerable<OrderBookEntry> orders) {
|
||||
_orders.sync_with(orders);
|
||||
_working_orders.trigger_filter();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,232 +1,113 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.co2;
|
||||
using mbts.collections;
|
||||
using mbts.spark.menu_items;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using static mbts.ui.spark.MarketViewView;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal partial class MarketViewVM : ViewModelBase, IDisposable
|
||||
internal partial class MarketViewVM : DisposableViewModelBase, IDisposable
|
||||
{
|
||||
public const int VERSION = 1;
|
||||
public const string SAVE_NAME = "MarketView";
|
||||
|
||||
public MarketViewVM(IBus bus, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
|
||||
_bus = bus;
|
||||
_model = new MarketViewModel(bus);
|
||||
_rows = new RXObservableCollection<SecurityMD>(_model.rows);
|
||||
_row_vms = new ObservableAutoWrapper<RowVM, SecurityMD>(_rows, r => new RowVM(this, _model, ref r, _model.security_position(r.security.Id)));
|
||||
_row_vms.ViewDestroyed += r => r.Dispose();
|
||||
row_views = CollectionViewSource.GetDefaultView(_row_vms);
|
||||
if (sorting_criteria == null || sorting_criteria.Count == 0) row_views.SortDescriptions.Add(new SortDescription(nameof(RowVM.security), ListSortDirection.Ascending));
|
||||
else row_views.SortDescriptions.AddRange(sorting_criteria.Select(sc => new SortDescription(sc.col_name, sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending)));
|
||||
_model.set_securities(securities);
|
||||
_model.orders_model.on_orderbook().ObserveOnDispatcher().Subscribe(ob => {
|
||||
_resources.Add(_model = new MarketViewModel(bus));
|
||||
_resources.Add(_rows = new RXObservableCollection<SecurityMD>(_model.rows));
|
||||
_rows_vm = new ObservableAutoWrapper<Row, SecurityMD>(_rows, smd => new Row(this, _model, smd, _model.security_position(smd.security.Id)));
|
||||
_rows_vm.ViewDestroyed += r => r.Dispose();
|
||||
_resources.Add(Disposable.Create(() => _rows_vm.Clear()));
|
||||
rows_view = CollectionViewSource.GetDefaultView(_rows_vm);
|
||||
if (sorting_criteria == null || sorting_criteria.Count == 0) rows_view.SortDescriptions.Add(new SortDescription(nameof(Row.security), ListSortDirection.Ascending));
|
||||
else rows_view.SortDescriptions.AddRange(sorting_criteria.Select(sc => new SortDescription(sc.col_name, sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending)));
|
||||
_resources.Add(_context_menu = new ContextMenuVM(_context_menu_item_factory));
|
||||
_resources.Add(_model.orders_model.on_orderbook().ObserveOnDispatcher().Subscribe(ob => {
|
||||
_order_book = ob;
|
||||
_refresh();
|
||||
});
|
||||
context_menu = CollectionViewSource.GetDefaultView(_context_menu);
|
||||
context_menu.GroupDescriptions.Add(new PropertyGroupDescription(nameof(MenuItemVM.sectional_id)));
|
||||
_work_loop = WorkLoop.Start(_refresh);
|
||||
}));
|
||||
_model.set_securities(securities);
|
||||
_resources.Add(WorkLoop.Start(_refresh));
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly IDisposable _work_loop;
|
||||
private readonly MarketViewModel _model;
|
||||
private readonly ObservableAutoWrapper<RowVM, SecurityMD> _row_vms;
|
||||
private readonly ContextMenuVM _context_menu;
|
||||
private readonly ObservableAutoWrapper<Row, SecurityMD> _rows_vm;
|
||||
private readonly RXObservableCollection<SecurityMD> _rows;
|
||||
private readonly ColdObseravbleProperty<DataGridCellInfo> _current_cell = new ColdObseravbleProperty<DataGridCellInfo>();
|
||||
private IList<IDisposable> _resources = new List<IDisposable>();
|
||||
private IOrderBook _order_book = new OrderBook();
|
||||
private ObservableCollection<MenuItemVM> _context_menu = new ObservableCollection<MenuItemVM>();
|
||||
private bool _is_context_menu_open;
|
||||
|
||||
private void _refresh() {
|
||||
var orders_map = _order_book.get_order_sec_map();
|
||||
foreach(var rvm in _row_vms) rvm.refresh(orders_map.TryGetValue(rvm.security.Id, out IEnumerable<OrderBookEntry> orders) ? orders : Enumerable.Empty<OrderBookEntry>());
|
||||
foreach(var rvm in _rows_vm) rvm.refresh(orders_map.TryGetValue(rvm.security.value.Id, out IEnumerable<OrderBookEntry> orders) ? orders : Enumerable.Empty<OrderBookEntry>());
|
||||
}
|
||||
|
||||
private void _refresh_context_menu() {
|
||||
Disposable.dispose(_context_menu);
|
||||
_context_menu.Clear();
|
||||
_context_menu.Add(MenuItemVM.Create("Add/Remove Securities...", "misc", Icons.Coins, new DialogCommand(() => new SecuritySelectorDialog {
|
||||
DataContext = new SecuritySelectorDialogVM("Market View", _rows.Select(r => r.security).ToArray(), _model.set_securities)
|
||||
}, () => true, true, -12, -30)));
|
||||
var selected_securities = new ObservableCollection<Security>(_row_vms.Where(r => r.is_selected).Select(r => r.security));
|
||||
_context_menu.AddRange(new IMenuItem[] {
|
||||
new LadderMenuItem(_bus), new SpreadMatrixMenuItem(_bus), new TimeAndSalesMenuItem(_bus)
|
||||
}.Select(m => MenuItemVM.Create(m, selected_securities)));
|
||||
const string order_actions = "order_actions";
|
||||
_context_menu.Add(MenuItemVM.Create(new OrderTicketMenuItem(_bus), selected_securities));
|
||||
var securities = _row_vms.Where(r => r.is_selected).Select(r => r.security).Ordered().ToList();
|
||||
var orders = securities.SelectMany(s => _order_book.get_active_orders_for_security(s.Id)).Select(obe => obe.order()).Ordered(OrderUtils.Compare.depth_compare).ToList();
|
||||
_context_menu.Add(MenuItemVM.Create("Modify Order", order_actions, Icons.Import, items:orders.Select(o => _create_order_item(o, _model.orders_model.get_metadata(o), () => _model.show_order_modify(o))).ToList()));
|
||||
_context_menu.Add(MenuItemVM.Create("Cancel Order", order_actions, Icons.CancelOrders, items:orders.Select(o => _create_order_item(o, _model.orders_model.get_metadata(o), () => _model.orders_model.cancel_order(o.Id))).ToList()));
|
||||
var sec_keys = securities.Select(s => s.Id);
|
||||
_context_menu.Add(MenuItemVM.Create("Cancel Buy Orders", order_actions, Icons.CancelOrders, new DelegateCommand(() => _model.orders_model.cancel_security_orders(sec_keys, true, false))));
|
||||
_context_menu.Add(MenuItemVM.Create("Cancel Sell Orders", order_actions, Icons.CancelOrders, new DelegateCommand(() => _model.orders_model.cancel_security_orders(sec_keys, false, true))));
|
||||
_context_menu.Add(MenuItemVM.Create("Cancel All Orders", order_actions, Icons.CancelOrders, new DelegateCommand(() => _model.orders_model.cancel_security_orders(sec_keys, true, true))));
|
||||
}
|
||||
|
||||
private static MenuItemVM _create_order_item(Order o, OrderMetadata omd, Action a) { return MenuItemVM.Create(_format_order(o), o.Side.ToString(), OrderIconFactory.Create(omd, o.Side), command:new DelegateCommand(a)); }
|
||||
private static string _format_order(Order order) { return "{0} {1} {2} / {3}".fmt(order.Side, order.Security, order.Security.ContractSpec.format(order.Price), order.Size); }
|
||||
private RowVM _get_active_row() { return selected_row ?? _row_vms.FirstOrDefault(r => r.is_selected); }
|
||||
|
||||
public ICollectionView row_views { get; }
|
||||
public RowVM selected_row { get; set; }
|
||||
public ICollectionView context_menu { get; }
|
||||
public bool is_context_menu_open { get => _is_context_menu_open; set { _is_context_menu_open = value; _refresh_context_menu(); } }
|
||||
|
||||
public StartupData get_startup_data() { return new StartupData(_rows.Select(r => r.security).ToArray(), row_views.SortDescriptions.Select(sd => new SortingCriteria { col_name = sd.PropertyName, is_ascending = sd.Direction == ListSortDirection.Ascending }).ToArray()); }
|
||||
|
||||
public void Dispose() {
|
||||
_work_loop.Dispose();
|
||||
_rows.Dispose();
|
||||
Disposable.dispose(_row_vms);
|
||||
_model.Dispose();
|
||||
Disposable.dispose(_context_menu);
|
||||
}
|
||||
|
||||
public class RowVM : DisposableViewModelBase {
|
||||
public RowVM(MarketViewVM owner, MarketViewModel model, ref SecurityMD security_md, IObservable<int> position) {
|
||||
_owner = owner;
|
||||
_model = model;
|
||||
_security_md = security_md;
|
||||
_position = backing(nameof(position), position);
|
||||
_bid_price = backing(nameof(bid_price), double.NaN);
|
||||
_bid_size = backing(nameof(bid_size), (ushort)0);
|
||||
_ask_price = backing(nameof(ask_price), double.NaN);
|
||||
_ask_size = backing(nameof(ask_size), (ushort)0);
|
||||
_last_price = backing(nameof(last_price), double.NaN);
|
||||
_last_size = backing(nameof(last_size), (ushort)0);
|
||||
_settlement = backing(nameof(settlement), double.NaN);
|
||||
_volume = backing(nameof(volume), (ulong)0);
|
||||
_day_change = backing(nameof(day_change), _last_price.Select(v => v.newval).CombineLatest(_settlement.Select(v => v.newval), (l, s) => l - s), double.NaN);
|
||||
_session_low = backing(nameof(session_low), double.NaN);
|
||||
_session_high = backing(nameof(session_high), double.NaN);
|
||||
_working_best_bid = backing(nameof(working_best_bid), double.NaN);
|
||||
_working_best_ask = backing(nameof(working_best_ask), double.NaN);
|
||||
_working_orders = new ObservableFilterCollection<OrderBookEntry>(_orders, o => o.is_active());
|
||||
_working_bids = new ObservableFilterCollection<OrderBookEntry>(_working_orders, o => o.order().Side == BuySell.Buy);
|
||||
_working_asks = new ObservableFilterCollection<OrderBookEntry>(_working_orders, o => o.order().Side == BuySell.Sell);
|
||||
_working_bids_sorted = new ObservableSortedCollection<OrderBookEntry>(_working_bids, CompareUtils.NullCheckComparer<OrderBookEntry>((x, y) => y.order().Price.CompareTo(x.order().Price)));
|
||||
_working_asks_sorted = new ObservableSortedCollection<OrderBookEntry>(_working_asks, CompareUtils.NullCheckComparer<OrderBookEntry>((x, y) => x.order().Price.CompareTo(y.order().Price)));
|
||||
_inside_bids = new ObservableFilterCollection<OrderBookEntry>(_working_bids_sorted, o => o.order().Price >= bid_price);
|
||||
_inside_asks = new ObservableFilterCollection<OrderBookEntry>(_working_asks_sorted, o => o.order().Price <= ask_price);
|
||||
_working_best_bid = backing(nameof(working_best_bid), _working_bids_sorted.Observe().Select(_ => _working_bids_sorted.Count == 0 ? double.NaN : _working_bids_sorted.First().order().Price).ObserveOnDispatcher());
|
||||
_working_best_ask = backing(nameof(working_best_ask), _working_asks_sorted.Observe().Select(_ => _working_asks_sorted.Count == 0 ? double.NaN : _working_asks_sorted.First().order().Price).ObserveOnDispatcher());
|
||||
_working_bid_volume = backing(nameof(working_bid_volume), _working_bids.Observe().Select(_ => _working_bids.Aggregate(0u, (v, o) => v + o.order().Size - o.Fills.Aggregate(0u, (fv, f) => fv + f.Size))).ObserveOnDispatcher());
|
||||
_working_ask_volume = backing(nameof(working_ask_volume), _working_asks.Observe().Select(_ => _working_asks.Aggregate(0u, (v, o) => v + o.order().Size - o.Fills.Aggregate(0u, (fv, f) => fv + f.Size))).ObserveOnDispatcher());
|
||||
_working_bids_text = backing(nameof(working_bids_text), _working_bid_volume.Select(vals => vals.newval).CombineLatest(
|
||||
_working_best_bid.Select(vals => vals.newval), (size, price) => size == 0u ? string.Empty : "{0} / {1}".fmt(size, security.ContractSpec.format(price))).ObserveOnDispatcher());
|
||||
_working_asks_text = backing(nameof(working_asks_text), _working_ask_volume.Select(vals => vals.newval).CombineLatest(
|
||||
_working_best_ask.Select(vals => vals.newval), (size, price) => size == 0u ? string.Empty : "{0} / {1}".fmt(size, security.ContractSpec.format(price))).ObserveOnDispatcher());
|
||||
_animation.AnimationsChanged += _animation_AnimationsChanged;
|
||||
_dispose = Disposable.Create(
|
||||
_position.Select(p => p.newval > p.oldval).ObserveOnDispatcher().Subscribe(_animation.animate_position),
|
||||
_working_bids.Observe().Select(_ => _working_bids.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_bids_active),
|
||||
_working_asks.Observe().Select(_ => _working_asks.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_asks_active),
|
||||
_inside_bids.Observe().Select(_ => _inside_bids.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_bids_inside),
|
||||
_inside_asks.Observe().Select(_ => _inside_asks.Count > 0).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(_animation.animate_working_asks_inside),
|
||||
_day_change.Select(vals => vals.newval > vals.oldval).ObserveOnDispatcher().Subscribe(_animation.animate_day_change),
|
||||
Disposable.Create(() => _animation.AnimationsChanged -= _animation_AnimationsChanged)
|
||||
);
|
||||
private IEnumerable<MenuItemVM> _context_menu_item_factory() {
|
||||
yield return MenuItemVM.Create(new ModifySecuritySelectionMenuItem(_rows.Select(r => r.security).ToList(), _model.set_securities));
|
||||
if (current_cell != null && current_cell.Column != null && current_cell.Item != null && !current_cell.Item.Equals(System.Windows.DependencyProperty.UnsetValue)) {
|
||||
var curr_col = (Columns)DataGridEx.GetArgument(current_cell.Column);
|
||||
var securities = _rows_vm.Where(r => r.is_selected).Select(r => r.security.value).ToList();
|
||||
yield return MenuItemVM.Create(new LadderMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new LinkedLadderMenuItem(_bus, _get_current_security_observable().ToSecurityMD()));
|
||||
yield return MenuItemVM.Create(new OrderTicketMenuItem(_model.orders_model, s => _create_order(_rows_vm.First(r => r.security.value.Equals(s)), curr_col)), securities);
|
||||
yield return MenuItemVM.Create(new LinkedOrderTicketMenuItem(_bus, _current_cell.Select(_create_order)));
|
||||
yield return MenuItemVM.Create(new SpreadMatrixMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new TimeAndSalesMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticCreateMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticStrategyMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new ModifyOrderRootMenuItem(_model.orders_model, _order_book.get_active_orders_for_security(securities).Select(e => e.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrderRootMenuItem(_model.orders_model, _order_book.get_active_orders_for_security(securities).Select(e => e.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelBuyOrdersMenuItem(_model.orders_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelSellOrdersMenuItem(_model.orders_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrdersMenuItem(_model.orders_model), securities);
|
||||
}
|
||||
}
|
||||
|
||||
private void _animation_AnimationsChanged() { RaisePropertyChanged(nameof(animations)); }
|
||||
|
||||
private readonly MarketViewVM _owner;
|
||||
private readonly MarketViewModel _model;
|
||||
private readonly AnimationManager _animation = new AnimationManager();
|
||||
private readonly SecurityMD _security_md;
|
||||
private readonly ObservableCollection<OrderBookEntry> _orders = new ObservableCollection<OrderBookEntry>();
|
||||
private readonly ObservableFilterCollection<OrderBookEntry> _working_orders, _working_bids, _working_asks, _inside_bids, _inside_asks;
|
||||
private readonly ObservableSortedCollection<OrderBookEntry> _working_bids_sorted, _working_asks_sorted;
|
||||
private ulong _bbo_time = 0, _last_time = 0;
|
||||
private Property<int> _position;
|
||||
private Property<ushort> _bid_size, _ask_size, _last_size;
|
||||
private Property<double> _bid_price, _ask_price, _last_price, _settlement, _day_change, _session_low, _session_high, _working_best_bid, _working_best_ask;
|
||||
private Property<uint> _working_bid_volume, _working_ask_volume;
|
||||
private Property<string> _working_bids_text, _working_asks_text;
|
||||
private Property<ulong> _volume;
|
||||
|
||||
#region Bound Properties
|
||||
public Security security => _security_md.security;
|
||||
public bool is_selected { get; set; }
|
||||
public int position => _position.Value;
|
||||
public double last_price => _last_price.Value;
|
||||
public ushort last_size => _last_size.Value;
|
||||
public double bid_price => _bid_price.Value;
|
||||
public ushort bid_size => _bid_size.Value;
|
||||
public double ask_price => _ask_price.Value;
|
||||
public ushort ask_size => _ask_size.Value;
|
||||
public ulong volume => _volume.Value;
|
||||
public double settlement => _settlement.Value;
|
||||
public double day_change => _day_change.Value;
|
||||
public double session_low => _session_low.Value;
|
||||
public double session_high => _session_high.Value;
|
||||
public double working_best_bid => _working_best_bid.Value;
|
||||
public double working_best_ask => _working_best_ask.Value;
|
||||
public uint working_bid_volume => _working_bid_volume.Value;
|
||||
public uint working_ask_volume => _working_ask_volume.Value;
|
||||
public string working_bids_text => _working_bids_text.Value;
|
||||
public string working_asks_text => _working_asks_text.Value;
|
||||
public IEnumerable<CellAnimation> animations => _animation.get_animations();
|
||||
public ICommand show_ladder => new DelegateCommand(() => _model.show_ladder(_security_md.security));
|
||||
public ICommand show_order_ticket => new DelegateCommand<Columns>(col => {
|
||||
switch(col) {
|
||||
case Columns.Bid: _model.show_order_ticket(security, BuySell.Sell, bid_price); break;
|
||||
case Columns.BidSize: _model.show_order_ticket(security, BuySell.Sell, bid_price, bid_size); break;
|
||||
case Columns.Ask: _model.show_order_ticket(security, BuySell.Buy, ask_price); break;
|
||||
case Columns.AskSize: _model.show_order_ticket(security, BuySell.Buy, ask_price, ask_size); break;
|
||||
case Columns.WorkingBids:
|
||||
if (_working_bids_sorted.Count > 0) _model.show_order_modify(_working_bids_sorted.First().order());
|
||||
else _model.show_order_ticket(security, BuySell.Buy, bid_price);
|
||||
break;
|
||||
case Columns.WorkingAsks:
|
||||
if (_working_asks_sorted.Count > 0) _model.show_order_modify(_working_asks_sorted.First().order());
|
||||
else _model.show_order_ticket(security, BuySell.Sell, ask_price);
|
||||
break;
|
||||
}
|
||||
});
|
||||
#endregion
|
||||
|
||||
public void refresh(IEnumerable<OrderBookEntry> orders) {
|
||||
if (_security_md.md.get_bbo(ref _bbo_time, out NativePriceSize b, out NativePriceSize a)) {
|
||||
_bid_price.set(b.price);
|
||||
_bid_size.set(b.size);
|
||||
_ask_price.set(a.price);
|
||||
_ask_size.set(a.size);
|
||||
}
|
||||
if (_security_md.md.get_last_trade(ref _last_time, out NativePriceSize l, out DateTime ts, out ulong v)) {
|
||||
_last_price.set(l.price);
|
||||
_last_size.set(l.size);
|
||||
_volume.set(v);
|
||||
}
|
||||
_settlement.set(_security_md.md.settlement_price);
|
||||
_session_low.set(_security_md.md.session_low);
|
||||
_session_high.set(_security_md.md.session_high);
|
||||
_orders.sync_with(orders);
|
||||
private IObservable<Security> _get_current_security_observable() { return _current_cell.Select(_get_security).DistinctUntilChanged(); }
|
||||
private static Security _get_security(DataGridCellInfo cell) { return ((Row)cell.Item).security.value; }
|
||||
private static Order _create_order(DataGridCellInfo cell) { return _create_order((Row)cell.Item, (Columns)DataGridEx.GetArgument(cell.Column)); }
|
||||
private static Order _create_order(Row row, Columns col) {
|
||||
var order = new Order { Security = row.security.value, MarketOrder = new MarketOrder(), Price = 0, Size = 1 };
|
||||
switch(col) {
|
||||
case Columns.Bid: order.Price = row.bid_price.output; break;
|
||||
case Columns.BidSize: order.Price = row.bid_price.output; order.Size = row.bid_size.output; break;
|
||||
case Columns.Ask: order.Price = row.ask_price.output; break;
|
||||
case Columns.AskSize: order.Price = row.ask_price.output; order.Size = row.ask_size.output; break;
|
||||
case Columns.Last: order.Price = row.last_price.output; break;
|
||||
case Columns.LastSize: order.Price = row.last_price.output; order.Size = row.last_size.output; break;
|
||||
case Columns.WorkingBids: order.Price = row.working_best_bid; break;
|
||||
case Columns.WorkingAsks: order.Price = row.working_best_ask; break;
|
||||
case Columns.SessionLow: order.Price = row.session_low.output; break;
|
||||
case Columns.SessionHigh: order.Price = row.session_high.output; break;
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Order> get_bids_sorted() { return _working_bids_sorted.Select(o => o.order()).ToList(); }
|
||||
public IReadOnlyList<Order> get_asks_sorted() { return _working_asks_sorted.Select(o => o.order()).ToList(); }
|
||||
}
|
||||
public double row_height { get; set; } = 18;
|
||||
public ICollectionView rows_view { get; }
|
||||
public DataGridCellInfo current_cell { get => _current_cell.Value; set => _current_cell.set(value); }
|
||||
public ContextMenuVM context_menu => _context_menu;
|
||||
|
||||
public StartupData get_startup_data() { return new StartupData(_rows.Select(r => r.security).ToArray(), rows_view.SortDescriptions.Select(sd => new SortingCriteria { col_name = sd.PropertyName, is_ascending = sd.Direction == ListSortDirection.Ascending }).ToArray()); }
|
||||
protected override void Dispose(bool disposing) { Disposable.dispose(_resources); }
|
||||
|
||||
[ProtoContract]
|
||||
public class StartupData {
|
||||
|
||||
@@ -1,158 +1,175 @@
|
||||
<UserControl x:Class="mbts.ui.spark.MarketViewView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Utilities/Converters/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Themes/generic.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style x:Key="LastPriceElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.last}"/>
|
||||
</Style>
|
||||
<Style x:Key="LastSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.last}"/>
|
||||
</Style>
|
||||
<Style x:Key="BidSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
</Style>
|
||||
<Style x:Key="AskSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</Style>
|
||||
<Style x:Key="SecurityCell" TargetType="DataGridCell" BasedOn="{StaticResource RowHeaderCell}">
|
||||
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_ladder}"/>
|
||||
</Style>
|
||||
<Style x:Key="OrderTicketCell" TargetType="DataGridCell" BasedOn="{StaticResource DataGridCellStaticBackgroundStyle}">
|
||||
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_order_ticket}"/>
|
||||
<Setter Property="u:AttachedCommands.DoubleClickParameter" Value="{Binding Path='Column.(c:DataGridEx.Argument)', RelativeSource={RelativeSource Self}}"/>
|
||||
</Style>
|
||||
<Style x:Key="BidPriceCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="c:DataGridEx.CellStaticBackground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Setter Property="Background" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</Style>
|
||||
<Style x:Key="AskPriceCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="c:DataGridEx.CellStaticBackground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
<Setter Property="Background" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</Style>
|
||||
<Style x:Key="PositionCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="Foreground" Value="{Binding position, Converter={StaticResource PositionSignBrushConverter}}"/>
|
||||
<Setter Property="Padding" Value="8,0,4,0"/>
|
||||
</Style>
|
||||
<Style x:Key="DayChangeCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="Foreground" Value="{Binding day_change, Converter={StaticResource DayChangeSignBrushConverter}}"/>
|
||||
<Setter Property="Padding" Value="8,0,4,0"/>
|
||||
</Style>
|
||||
<Style x:Key="Mine" TargetType="ContextMenu" BasedOn="{StaticResource Coodies}"/>
|
||||
<!--<ControlTemplate x:Key="ContextMenuGroupItemTemplate" TargetType="GroupItem">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<ItemsPresenter x:Name="ItemsHost" SnapsToDevicePixels="True"/>
|
||||
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Fill="DarkGray" RadiusX="1" Margin="27,0,0,0" />
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="ContextMenuGroupItemStyle" TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource ContextMenuGroupItemTemplate}"/>
|
||||
</Style>
|
||||
<GroupStyle x:Key="ContextMenuGroupStyle" ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
<Style x:Key="MenuItemBase" TargetType="MenuItem">
|
||||
<Setter Property="Header" Value="{Binding display_name}"/>
|
||||
<Setter Property="Command" Value="{Binding command}"/>
|
||||
<Setter Property="Icon" Value="{Binding icon, Converter={StaticResource IconConverter}}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>-->
|
||||
<!--<Style TargetType="ContextMenu">
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource MenuItemBase}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>-->
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<c:DataGridEx ItemsSource="{Binding row_views}" SelectedRow="{Binding selected_row, Mode=TwoWay}" CanUserSortColumns="True" GridLinesVisibility="None" u:DataGridBehavior.NotifyColumnsOfSorting="True" usp:GridAnimation.Enableanimation="True">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding context_menu}" IsOpen="{Binding is_context_menu_open, Mode=OneWayToSource}" ItemContainerStyle="{StaticResource ContextMenuItemStyle}">
|
||||
<ContextMenu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
</ContextMenu.GroupStyle>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="IsSelected" Value="{Binding is_selected, Mode=OneWayToSource}"/>
|
||||
<Setter Property="usp:GridAnimation.RowAnimation" Value="{Binding animations}"/>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Name" IsReadOnly="True" CellStyle="{StaticResource SecurityCell}" Binding="{Binding security, StringFormat='q/n:./m:c'}"/>
|
||||
<DataGridTextColumn Header="Volume" IsReadOnly="True" Binding="{Binding volume}"/>
|
||||
<DataGridTextColumn Header="Last" IsReadOnly="True" ElementStyle="{StaticResource LastPriceElement}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="last_price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" IsReadOnly="True" ElementStyle="{StaticResource LastSizeElement}" Binding="{Binding last_size}"/>
|
||||
<DataGridTextColumn Header="Pos" IsReadOnly="True" CellStyle="{StaticResource PositionCell}" Binding="{Binding position}" c:DataGridEx.Argument="{u:Enum Position, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Wrkg" IsReadOnly="True" CellStyle="{StaticResource OrderTicketCell}" ElementStyle="{StaticResource BidSizeElement}" Binding="{Binding working_bids_text}" SortMemberPath="working_bids.Count" c:DataGridEx.Argument="{u:Enum WorkingBids, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Qty" IsReadOnly="True" CellStyle="{StaticResource OrderTicketCell}" ElementStyle="{StaticResource BidSizeElement}" Binding="{Binding bid_size}" c:DataGridEx.Argument="{u:Enum BidSize, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Bid" IsReadOnly="True" CellStyle="{StaticResource BidPriceCell}" c:DataGridEx.Argument="{u:Enum Bid, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="bid_price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Ask" IsReadOnly="True" CellStyle="{StaticResource AskPriceCell}" c:DataGridEx.Argument="{u:Enum Ask, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="ask_price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" IsReadOnly="True" CellStyle="{StaticResource OrderTicketCell}" ElementStyle="{StaticResource AskSizeElement}" Binding="{Binding ask_size}" c:DataGridEx.Argument="{u:Enum AskSize, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Wrkg" IsReadOnly="True" CellStyle="{StaticResource OrderTicketCell}" ElementStyle="{StaticResource AskSizeElement}" Binding="{Binding working_asks_text}" SortMemberPath="working_asks.Count" c:DataGridEx.Argument="{u:Enum WorkingAsks, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Settlement" IsReadOnly="True">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="settlement"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Change" IsReadOnly="True" CellStyle="{StaticResource DayChangeCell}" c:DataGridEx.Argument="{u:Enum DayChange, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="day_change"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Low" IsReadOnly="True">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="session_low"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="High" IsReadOnly="True" Width="*">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="session_high"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</c:DataGridEx>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.ui.spark.MarketViewView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Resources/MenuResources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style x:Key="OrderTicketCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_order_ticket}"/>
|
||||
<Setter Property="u:AttachedCommands.DoubleClickParameter" Value="{Binding Path='Column.(c:DataGridEx.Argument)', RelativeSource={RelativeSource Self}}"/>
|
||||
</Style>
|
||||
<Style x:Key="OrderTicketStaticBackgroundCell" TargetType="DataGridCell" BasedOn="{StaticResource DataGridCellStaticBackgroundStyle}">
|
||||
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_order_ticket}"/>
|
||||
<Setter Property="u:AttachedCommands.DoubleClickParameter" Value="{Binding Path='Column.(c:DataGridEx.Argument)', RelativeSource={RelativeSource Self}}"/>
|
||||
</Style>
|
||||
<Style x:Key="SecurityCell" TargetType="DataGridCell" BasedOn="{StaticResource RowHeaderCell}">
|
||||
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_ladder}"/>
|
||||
<Setter Property="IsSelected" Value="{Binding security.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="VolumeCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding volume.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="LastPriceCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding last_price.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="LastSizeCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding last_size.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="PositionCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="Foreground" Value="{Binding position.output, Converter={StaticResource PositionSignBrushConverter}}"/>
|
||||
<Setter Property="Padding" Value="8,0,4,0"/>
|
||||
<Setter Property="IsSelected" Value="{Binding position.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="WorkingBidsCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding working_bids_text.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="BidSizeCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding bid_size.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="BidPriceCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketStaticBackgroundCell}">
|
||||
<Setter Property="c:DataGridEx.CellStaticBackground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Setter Property="Background" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="IsSelected" Value="{Binding bid_price.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="AskPriceCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketStaticBackgroundCell}">
|
||||
<Setter Property="c:DataGridEx.CellStaticBackground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
<Setter Property="Background" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="IsSelected" Value="{Binding ask_price.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="AskSizeCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding ask_size.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="WorkingAsksCell" TargetType="DataGridCell" BasedOn="{StaticResource OrderTicketCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding working_asks_text.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="SettlementCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding settlement.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="DayChangeCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="Foreground" Value="{Binding day_change.output, Converter={StaticResource DayChangeSignBrushConverter}}"/>
|
||||
<Setter Property="Padding" Value="8,0,4,0"/>
|
||||
<Setter Property="IsSelected" Value="{Binding day_change.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="SessionLowCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding session_low.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="SessionHighCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding session_high.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="LastPriceElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.last}"/>
|
||||
</Style>
|
||||
<Style x:Key="LastSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.last}"/>
|
||||
</Style>
|
||||
<Style x:Key="BidSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
</Style>
|
||||
<Style x:Key="AskSizeElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<c:DataGridEx ItemsSource="{Binding rows_view}" IsReadOnly="True" SelectionUnit="Cell" CanUserSortColumns="True" GridLinesVisibility="None" RowHeight="{Binding row_height, Mode=OneWay}"
|
||||
CurrentCell="{Binding current_cell, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" u:DataGridBehavior.NotifyColumnsOfSorting="True" usp:GridAnimation.Enableanimation="True">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding context_menu.items_view}" IsOpen="{Binding context_menu.is_open, Mode=OneWayToSource}" ItemContainerStyle="{StaticResource ContextMenuItemStyle}">
|
||||
<ContextMenu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
</ContextMenu.GroupStyle>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="usp:GridAnimation.RowAnimation" Value="{Binding animations}"/>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Name" CellStyle="{StaticResource SecurityCell}" Binding="{Binding security.value}" c:DataGridEx.Argument="{u:Enum Security, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Volume" CellStyle="{StaticResource VolumeCell}" Binding="{Binding volume.output}" c:DataGridEx.Argument="{u:Enum Volume, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Last" CellStyle="{StaticResource LastPriceCell}" ElementStyle="{StaticResource LastPriceElement}" c:DataGridEx.Argument="{u:Enum Last, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="last_price.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" CellStyle="{StaticResource LastSizeCell}" ElementStyle="{StaticResource LastSizeElement}" Binding="{Binding last_size.output}" c:DataGridEx.Argument="{u:Enum LastSize, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Pos" CellStyle="{StaticResource PositionCell}" Binding="{Binding position.output}" c:DataGridEx.Argument="{u:Enum Position, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Wrkg" CellStyle="{StaticResource WorkingBidsCell}" ElementStyle="{StaticResource BidSizeElement}" Binding="{Binding working_bids_text.output}" SortMemberPath="working_best_bid" c:DataGridEx.Argument="{u:Enum WorkingBids, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Qty" CellStyle="{StaticResource BidSizeCell}" ElementStyle="{StaticResource BidSizeElement}" Binding="{Binding bid_size.output}" c:DataGridEx.Argument="{u:Enum BidSize, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Bid" CellStyle="{StaticResource BidPriceCell}" c:DataGridEx.Argument="{u:Enum Bid, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="bid_price.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Ask" CellStyle="{StaticResource AskPriceCell}" c:DataGridEx.Argument="{u:Enum Ask, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="ask_price.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" CellStyle="{StaticResource AskSizeCell}" ElementStyle="{StaticResource AskSizeElement}" Binding="{Binding ask_size.output}" c:DataGridEx.Argument="{u:Enum AskSize, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Wrkg" CellStyle="{StaticResource WorkingAsksCell}" ElementStyle="{StaticResource AskSizeElement}" Binding="{Binding working_asks_text.output}" SortMemberPath="working_best_ask" c:DataGridEx.Argument="{u:Enum WorkingAsks, Type={u:Nested usp:MarketViewView.Columns}}"/>
|
||||
<DataGridTextColumn Header="Settlement" CellStyle="{StaticResource SettlementCell}" c:DataGridEx.Argument="{u:Enum Settlement, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="settlement.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Change" CellStyle="{StaticResource DayChangeCell}" c:DataGridEx.Argument="{u:Enum DayChange, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="day_change.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Low" CellStyle="{StaticResource SessionLowCell}" c:DataGridEx.Argument="{u:Enum SessionLow, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="session_low.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="High" Width="*" CellStyle="{StaticResource SessionHighCell}" c:DataGridEx.Argument="{u:Enum SessionHigh, Type={u:Nested usp:MarketViewView.Columns}}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="session_high.output"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</c:DataGridEx>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -12,7 +12,7 @@ namespace mbts.ui.spark
|
||||
/// </summary>
|
||||
public partial class MarketViewView : UserControl
|
||||
{
|
||||
public enum Columns { Position, Bid, BidSize, WorkingBids, Ask, AskSize, WorkingAsks, Last, LastSize, DayChange }
|
||||
public enum Columns { Security, Volume, Last, LastSize, Position, WorkingBids, Bid, BidSize, Ask, AskSize, WorkingAsks, Settlement, DayChange, SessionLow, SessionHigh }
|
||||
|
||||
public MarketViewView() {
|
||||
InitializeComponent();
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using bts.api;
|
||||
using System.Collections.Generic;
|
||||
using static mbts.ui.shell.ProtoBufSerializationHelper;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class MarketViewWindow : IShellWindow
|
||||
{
|
||||
public MarketViewWindow(IShellModule owner, IBus bus, IReadOnlyCollection<Security> securities) : this(owner, bus, securities, new SortingCriteria[0]) { }
|
||||
public MarketViewWindow(IShellModule owner, IBus bus, MarketViewVM.StartupData startup_data) : this(owner, bus, startup_data.securities.Select(deserialize<Security>).ToList(), startup_data.sorting_criteria) { }
|
||||
|
||||
private MarketViewWindow(IShellModule owner, IBus bus, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
|
||||
_bus = bus;
|
||||
_securities = securities;
|
||||
_sorting_criteria = sorting_criteria;
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly IReadOnlyCollection<Security> _securities;
|
||||
private readonly IReadOnlyCollection<SortingCriteria> _sorting_criteria;
|
||||
private MarketViewVM _vm;
|
||||
private IShellModule _owner;
|
||||
private string _title = "Market Sheets";
|
||||
private ImageSource _icon = Icons.Sheets;
|
||||
|
||||
public string Title { get => _title; set { _title = value; TitleChanged(); } }
|
||||
public ImageSource Icon { get => _icon; set { _icon = value; IconChanged(); } }
|
||||
public IShellModule Owner { get => _owner; set => _owner = value; }
|
||||
|
||||
public event Action TitleChanged;
|
||||
public event Action IconChanged;
|
||||
public void Dispose() { Disposable.dispose(ref _vm); }
|
||||
public ShellWindowUI GetContent() {
|
||||
var mvv = new MarketViewView { DataContext = _vm = new MarketViewVM(_bus, _securities, _sorting_criteria) };
|
||||
const double two_thirds = 2.0 / 3.0;
|
||||
const double title_panel_height = 32.0, col_header_height = 26 + two_thirds + 10.0, row_height = 15 + two_thirds;
|
||||
mvv.Height = Math.Min(title_panel_height + col_header_height + _securities.Count * row_height, System.Windows.SystemParameters.WorkArea.Height);
|
||||
mvv.Width = 705;
|
||||
return new ShellWindowUI(mvv);
|
||||
}
|
||||
public void GetState(Stream save_here) {
|
||||
if (_vm != null) {
|
||||
serialize(save_here, new ShellSerializationHeader { name = MarketViewVM.SAVE_NAME, version = MarketViewVM.VERSION });
|
||||
serialize(save_here, _vm.get_startup_data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using bts.spark;
|
||||
using bts.api;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -7,11 +9,40 @@ namespace mbts.spark
|
||||
{
|
||||
OrderBookEntry get_order(OrderID order_id);
|
||||
IEnumerable<OrderBookEntry> get_all_orders();
|
||||
IEnumerable<OrderBookEntry> get_all_orders_for_security(uint security);
|
||||
IEnumerable<Fill> get_all_fills();
|
||||
IEnumerable<FillTuple> get_all_fill_tuples();
|
||||
IDictionary<uint, IEnumerable<OrderBookEntry>> get_order_sec_map();
|
||||
IDictionary<uint, IEnumerable<Fill>> get_fill_sec_map();
|
||||
IDictionary<uint, IEnumerable<FillTuple>> get_fill_tuple_sec_map();
|
||||
}
|
||||
|
||||
public static class OrderBookExtensions
|
||||
{
|
||||
public static IEnumerable<OrderBookEntry> get_all_orders_for_security(this IOrderBook ob, Security security) { return ob.get_all_orders_for_security(security.Id); }
|
||||
public static IEnumerable<OrderBookEntry> get_all_orders_for_security(this IOrderBook ob, IEnumerable<Security> security) { return ob.get_all_orders_for_security(new HashSet<uint>(security.Select(s => s.Id))); }
|
||||
public static IEnumerable<OrderBookEntry> get_all_orders_for_security(this IOrderBook ob, uint security) { return ob.get_all_orders().Where(e => e.sec_key() == security); }
|
||||
public static IEnumerable<OrderBookEntry> get_all_orders_for_security(this IOrderBook ob, IEnumerable<uint> securities) { return ob.get_all_orders_for_security(new HashSet<uint>(securities)); }
|
||||
public static IEnumerable<OrderBookEntry> get_all_orders_for_security(this IOrderBook ob, HashSet<uint> securities) { return ob.get_all_orders().Where(e => securities.Contains(e.sec_key())); }
|
||||
public static IDictionary<uint, IEnumerable<OrderBookEntry>> get_order_sec_map(this IOrderBook ob) { return ob.get_all_orders().Map(e => e.sec_key()); }
|
||||
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders(this IOrderBook ob) { return ob.get_all_orders().Where(e => e.is_active()); }
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, Security security) { return ob.get_active_orders_for_security(security.Id); }
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, IEnumerable<Security> security) { return ob.get_active_orders_for_security(new HashSet<uint>(security.Select(s => s.Id))); }
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, uint security) { return ob.get_all_orders().Where(e => e.sec_key() == security && e.is_active()); }
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, IEnumerable<uint> securities) { return ob.get_active_orders_for_security(new HashSet<uint>(securities)); }
|
||||
public static IEnumerable<OrderBookEntry> get_active_orders_for_security(this IOrderBook ob, HashSet<uint> securities) { return ob.get_all_orders().Where(e => securities.Contains(e.sec_key()) && e.is_active()); }
|
||||
public static IDictionary<uint, IEnumerable<OrderBookEntry>> get_active_order_sec_map(this IOrderBook ob) { return ob.get_active_orders().Map(e => e.sec_key()); }
|
||||
|
||||
public static IEnumerable<Fill> get_all_fills(this IOrderBook ob) { return ob.get_all_orders().SelectMany(e => e.Fills); }
|
||||
public static IEnumerable<Fill> get_all_fills_for_security(this IOrderBook ob, Security security) { return ob.get_all_fills_for_security(security.Id); }
|
||||
public static IEnumerable<Fill> get_all_fills_for_security(this IOrderBook ob, IEnumerable<Security> security) { return ob.get_all_fills_for_security(new HashSet<uint>(security.Select(s => s.Id))); }
|
||||
public static IEnumerable<Fill> get_all_fills_for_security(this IOrderBook ob, uint security) { return ob.get_all_orders_for_security(security).SelectMany(e => e.Fills); }
|
||||
public static IEnumerable<Fill> get_all_fills_for_security(this IOrderBook ob, IEnumerable<uint> securities) { return ob.get_all_fills_for_security(new HashSet<uint>(securities)); }
|
||||
public static IEnumerable<Fill> get_all_fills_for_security(this IOrderBook ob, HashSet<uint> securities) { return ob.get_all_orders_for_security(securities).SelectMany(e => e.Fills); }
|
||||
public static IDictionary<uint, IEnumerable<Fill>> get_fill_sec_map(this IOrderBook ob) { return ob.get_all_fills().Map(f => f.Order.Security.Id); }
|
||||
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples(this IOrderBook ob) { return ob.get_all_orders().SelectMany(e => e.Fills.Select(f => new FillTuple(f, e))); }
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples_for_security(this IOrderBook ob, Security security) { return ob.get_all_fill_tuples_for_security(security.Id); }
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples_for_security(this IOrderBook ob, IEnumerable<Security> security) { return ob.get_all_fill_tuples_for_security(new HashSet<uint>(security.Select(s => s.Id))); }
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples_for_security(this IOrderBook ob, uint security) { return ob.get_all_orders_for_security(security).SelectMany(e => e.Fills.Select(f => new FillTuple(f, e))); }
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples_for_security(this IOrderBook ob, IEnumerable<uint> securities) { return ob.get_all_fill_tuples_for_security(new HashSet<uint>(securities)); }
|
||||
public static IEnumerable<FillTuple> get_all_fill_tuples_for_security(this IOrderBook ob, HashSet<uint> securities) { return ob.get_all_orders_for_security(securities).SelectMany(e => e.Fills.Select(f => new FillTuple(f, e))); }
|
||||
public static IDictionary<uint, IEnumerable<FillTuple>> get_fill_tuple_sec_map(this IOrderBook ob) { return ob.get_all_orders().Map(o => o.sec_key(), o => o.Fills.Select(f => new FillTuple(f, o))); }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace mbts.spark
|
||||
OrderBookEntry curr = get_order(order_status.Order.Id);
|
||||
if (curr == null) {
|
||||
/// new order
|
||||
curr = new OrderBookEntry () { OrderStatus = order_status, };
|
||||
curr = new OrderBookEntry() { OrderStatus = order_status };
|
||||
if (curr.parent_id() == null) {
|
||||
/// Does not have a parent => its a "Root" order
|
||||
_orderbook.Add(curr);
|
||||
@@ -74,30 +74,6 @@ namespace mbts.spark
|
||||
return _get_all_orders(_orderbook);
|
||||
}
|
||||
|
||||
public IEnumerable<OrderBookEntry> get_all_orders_for_security(uint security) {
|
||||
return get_all_orders().Where(o => o.OrderStatus.Order.Security.Id == security);
|
||||
}
|
||||
|
||||
public IDictionary<uint, IEnumerable<OrderBookEntry>> get_order_sec_map() {
|
||||
return get_all_orders().Map(o => o.sec_key(), o => o);
|
||||
}
|
||||
|
||||
public IEnumerable<Fill> get_all_fills() {
|
||||
return get_all_orders().SelectMany(o => o.Fills);
|
||||
}
|
||||
|
||||
public IDictionary<uint, IEnumerable<Fill>> get_fill_sec_map() {
|
||||
return get_all_fills().Map(f => f.Order.Security.Id);
|
||||
}
|
||||
|
||||
public IEnumerable<FillTuple> get_all_fill_tuples() {
|
||||
return get_all_orders().SelectMany(o => o.Fills.Select(f => new FillTuple(f, o)));
|
||||
}
|
||||
|
||||
public IDictionary<uint, IEnumerable<FillTuple>> get_fill_tuple_sec_map() {
|
||||
return get_all_orders().Map(o => o.sec_key(), o => o.Fills.Select(f => new FillTuple(f, o)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void _remove_child_entry(OrderID parent_order_id, OrderID child_order_id) {
|
||||
|
||||
@@ -48,5 +48,14 @@ namespace mbts.spark
|
||||
public static bool is_child(this OrderBookEntry me) {
|
||||
return me.parent_id() != null;
|
||||
}
|
||||
|
||||
public static string summary(this Order order, bool show_side=true, bool show_security=true, bool show_price=true, bool show_qty=true) {
|
||||
var parts = new List<object>();
|
||||
if (show_side) parts.Add(order.Side);
|
||||
if (show_security) parts.Add(order.Security.ToString(null));
|
||||
if (show_price) parts.Add(order.Security.ContractSpec.format(order.Price));
|
||||
if (show_qty) parts.Add("@ {0}".fmt(order.Size));
|
||||
return string.Join(" ", parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,36 @@
|
||||
<UserControl x:Class="mbts.ui.spark.OrderModificationControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:sp="clr-namespace:bts.spark;assembly=spark_core"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark">
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Utilities/Converters/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/PriceEntryControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/PriceOffsetControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/TimeWindowControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/BTSIcebergOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Popup/PopupControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">8.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">4.0</sys:Double>
|
||||
<sys:Double x:Key="ButtonHeight">22.0</sys:Double>
|
||||
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
|
||||
<Setter Property="Height" Value="{StaticResource ButtonHeight}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
</Style>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="Height" Value="{StaticResource ButtonHeight}"/>
|
||||
</Style>
|
||||
<Style x:Key="AlgoDetailsToggleButton" TargetType="ToggleButton">
|
||||
<Setter Property="FontStyle" Value="Italic"/>
|
||||
<Setter Property="Content" Value="Show Details"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="19" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Ellipse x:Name="circle" Fill="White" HorizontalAlignment="Center" Height="19" Stroke="#FF333333" VerticalAlignment="Center" Width="19"/>
|
||||
<Path x:Name="arrow" Data="M1,1.5L4.5,5 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#FF333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<ContentPresenter Grid.Column="1" Margin="4,0,0,0" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M1,4.5L4.5,1 8,4.5"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFF3F9FF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF3C77DD"/>
|
||||
<Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFD9ECFF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFE6E6E6"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Content" Value="Hide Details"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
@@ -78,9 +44,9 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
<ColumnDefinition Width="140"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalSpacing}}"/>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
<ColumnDefinition Width="140"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<usp:PriceEntryControl Value="{Binding price}" ContractSpec="{Binding security.ContractSpec}"/>
|
||||
<c:TickUpDown Grid.Row="2" DataContext="{Binding size_calculator}" TickUpCommand="{Binding click}" TickDownCommand="{Binding click}" TickUpParameter="1" TickDownParameter="-1">
|
||||
@@ -117,26 +83,86 @@
|
||||
<ItemsControl Grid.Row="4" Margin="-2,0" DataContext="{Binding size_calculator}" ItemsSource="{Binding buttons}" Focusable="False">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Focusable="False" />
|
||||
<UniformGrid Columns="3" Focusable="False" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button Margin="2" Command="{Binding Path=DataContext.click, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" Content="{Binding}" />
|
||||
<Button Margin="2" Command="{Binding Path=DataContext.click, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" Content="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="6" Margin="2" VerticalAlignment="Top" Command="{Binding size_calculator.click}" CommandParameter="0">Clear</Button>
|
||||
<Grid Grid.Row="4" Grid.Column="2" DataContext="{Binding order_params}">
|
||||
<Grid Grid.Row="4" Grid.Column="2" Grid.RowSpan="3" DataContext="{Binding order_params}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ComboBox Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
|
||||
<ComboBox Grid.Row="1" Margin="2" ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding time_in_force}"/>
|
||||
<ComboBox Grid.Row="2" Margin="2" ItemsSource="{Binding algo_types}" SelectedItem="{Binding algo_type}" DisplayMemberPath="name"/>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
|
||||
<ComboBox Grid.Row="1" Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding time_in_force}"/>
|
||||
<ComboBox Grid.Row="2" Margin="2" ItemsSource="{Binding algo_types_view}" SelectedItem="{Binding algo_type}" DisplayMemberPath="name">
|
||||
<ComboBox.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.ContainerStyle>
|
||||
<Style TargetType="GroupItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GroupItem">
|
||||
<StackPanel>
|
||||
<ItemsPresenter/>
|
||||
<Rectangle Height="1" Fill="{x:Static uc:BTSColors.logo_brush}" HorizontalAlignment="Stretch"/>
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</GroupStyle.ContainerStyle>
|
||||
</GroupStyle>
|
||||
</ComboBox.GroupStyle>
|
||||
</ComboBox>
|
||||
<c:PopupControl Grid.Row="2" Grid.Column="1" Margin="2" Content="{Binding algo_type.order_details}" PopupPlacement="Right">
|
||||
<c:PopupControl.ContentTemplateSelector>
|
||||
<usp:OrderModificationTemplateSelector>
|
||||
<usp:OrderModificationTemplateSelector.BTSIcebergOrderTemplate>
|
||||
<DataTemplate>
|
||||
<uag:BTSIcebergOrderControl Order="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.BTSIcebergOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.ReflectionTemplate>
|
||||
<DataTemplate>
|
||||
<c:ObjectEditor EditableObject="{Binding}">
|
||||
<c:ObjectEditor.CustomDataTemplates>
|
||||
<DataTemplate DataType="{x:Type sp:PriceTrigger}">
|
||||
<GroupBox Header="{Binding Name}">
|
||||
<uag:PriceTriggerControl PriceTrigger="{Binding Value}"/>
|
||||
</GroupBox>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type sp:QuantityMeasure}">
|
||||
<GroupBox Header="{Binding Name}">
|
||||
<uag:QuantityMeasureControl QuantityMeasure="{Binding Value}"/>
|
||||
</GroupBox>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type sp:PriceOffset}">
|
||||
<GroupBox Header="{Binding Name}">
|
||||
<uag:PriceOffsetControl PriceOffset="{Binding Value}"/>
|
||||
</GroupBox>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type sp:BTSIcebergOrder}">
|
||||
<uag:BTSIcebergOrderControl Order="{Binding Value}"/>
|
||||
</DataTemplate>
|
||||
</c:ObjectEditor.CustomDataTemplates>
|
||||
</c:ObjectEditor>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.ReflectionTemplate>
|
||||
</usp:OrderModificationTemplateSelector>
|
||||
</c:PopupControl.ContentTemplateSelector>
|
||||
</c:PopupControl>
|
||||
</Grid>
|
||||
<c:ObjectEditor Grid.Row="6" Grid.Column="2" DataContext="{Binding order_params}" Visibility="{Binding IsChecked, ElementName=details_toggle, Converter={StaticResource BooleanToVisibilityConverter}}" EditableObject="{Binding algo_type.order_details}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -1,17 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.spark;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
@@ -24,4 +13,14 @@ namespace mbts.ui.spark
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
internal class OrderModificationTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public DataTemplate BTSIcebergOrderTemplate { get; set; }
|
||||
public DataTemplate ReflectionTemplate { get; set; }
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
||||
if (item is BTSIcebergOrder) return BTSIcebergOrderTemplate;
|
||||
else return ReflectionTemplate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.TitleContent="{Binding bbo, Mode=OneWay}"
|
||||
u:WindowStyle.CloseOnEscape="True"
|
||||
@@ -13,40 +11,13 @@
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Utilities/Converters/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">8.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">4.0</sys:Double>
|
||||
<sys:Double x:Key="ButtonHeight">22.0</sys:Double>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<!--<u:WindowStyle.TitleContentTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="{Binding security, Mode=OneWay}" FontWeight="Bold"/>
|
||||
<Run Foreground="{uc:BTSColor MarketData.bid}" FontSize="10" Text="{Binding bid_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
<Run Foreground="{uc:BTSColor MarketData.bid}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="bid"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{uc:BTSColor MarketData.ask}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="ask"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{uc:BTSColor MarketData.ask}" FontSize="10" Text="{Binding ask_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</u:WindowStyle.TitleContentTemplate>-->
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -64,4 +35,31 @@
|
||||
</Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40" FontWeight="Bold" u:Behavior.CloseWindow="True" Command="{Binding modify_order}">Modify</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
<u:WindowStyle.TitleContentTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="{Binding security, Mode=OneWay}" FontWeight="Bold"/>
|
||||
<Run Foreground="{u:BTSColor MarketData.bid}" FontSize="10" Text="{Binding bid_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
<Run Foreground="{u:BTSColor MarketData.bid}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="bid"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{u:BTSColor MarketData.ask}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="ask"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{u:BTSColor MarketData.ask}" FontSize="10" Text="{Binding ask_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</u:WindowStyle.TitleContentTemplate>
|
||||
</Window>
|
||||
@@ -1,39 +1,100 @@
|
||||
using bts.spark;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class OrderHelper
|
||||
{
|
||||
public static IMessage[] get_default_algos() { return new IMessage[] { new MarketOrder(), new LimitOrder(), new StopMarketOrder(), new StopLimitOrder(), new IcebergOrder(), }; }
|
||||
public static IMessage[] get_default_algos() {
|
||||
return new IMessage[] {
|
||||
new MarketOrder(),
|
||||
new LimitOrder(),
|
||||
new StopMarketOrder(),
|
||||
new StopLimitOrder(),
|
||||
new IcebergOrder(),
|
||||
new BTSStopOrder(),
|
||||
new BTSIcebergOrder {
|
||||
DisplayQuantity = Defaults.QuantityMeasure,
|
||||
MarketOffset = Defaults.PriceOffset,
|
||||
PriceTrigger = Defaults.PriceTrigger,
|
||||
TimedWindowParameters = Defaults.TimeWindow,
|
||||
WithatickParameters = Defaults.WithATick
|
||||
}
|
||||
};
|
||||
}
|
||||
public static Order get_default_order(Security security) {
|
||||
return new Order {
|
||||
User = ImportedResources.UserName,
|
||||
Security = security,
|
||||
LimitOrder = new LimitOrder()
|
||||
};
|
||||
}
|
||||
|
||||
public static class Defaults
|
||||
{
|
||||
public static QuantityMeasure QuantityMeasure => new QuantityMeasure { Absolute = 1 };
|
||||
public static PriceType PriceType => new PriceType { Status = PriceType.Types.Status.Bid };
|
||||
public static PriceOffset PriceOffset => new PriceOffset { PriceType = PriceType };
|
||||
public static QuantityTrigger QuantityTrigger => new QuantityTrigger { QuantityMeasure = QuantityMeasure, LessThanEqualto = true };
|
||||
public static AbsolutePriceTrigger AbsolutePriceTrigger => new AbsolutePriceTrigger { PriceType = PriceType, QuantityTrigger = QuantityTrigger };
|
||||
public static TrailingTrigger TrailingTrigger => new TrailingTrigger { PriceType = PriceType, Stop = true };
|
||||
public static PriceTrigger PriceTrigger => new PriceTrigger { AbsolutePriceTrigger = AbsolutePriceTrigger, TrailingTrigger = TrailingTrigger };
|
||||
public static OrderTime OrderTime => new OrderTime { Now = true };
|
||||
public static BTSTimedWindowParameters TimeWindow => new BTSTimedWindowParameters { Cancel = true, StartTime = OrderTime, StopTime = new OrderTime() };
|
||||
public static BTSWithATickParameters WithATick => new BTSWithATickParameters { QuantityThreshold = QuantityMeasure };
|
||||
public static BTSIcebergOrder BTSIcebergOrder => new BTSIcebergOrder { DisplayQuantity = QuantityMeasure, MarketOffset = PriceOffset, PriceTrigger = PriceTrigger, TimedWindowParameters = TimeWindow, WithatickParameters = WithATick };
|
||||
}
|
||||
}
|
||||
|
||||
internal class OrderParamsVM : ViewModelBase
|
||||
internal class OrderParamsVM : DisposableViewModelBase
|
||||
{
|
||||
public OrderParamsVM(Order order, OrdersModel model) {
|
||||
_order = order;
|
||||
public OrderParamsVM(Order order, OrdersModel model) : this(Observable.Return(order), model) { }
|
||||
public OrderParamsVM(IObservable<Order> order, OrdersModel model) {
|
||||
_model = model;
|
||||
algo_types = OrderHelper.get_default_algos().Select(algo => {
|
||||
var meta = _model.get_metadata(algo);
|
||||
return meta != null ? new OrderTypeVM(_order, algo, meta) : null;
|
||||
}).ToArray();
|
||||
if (string.IsNullOrEmpty(account)) account = accounts[0];
|
||||
_dispose = order.Subscribe(o => {
|
||||
_order = o;
|
||||
_algo_types.Clear();
|
||||
foreach (var a in _get_algo_types()) _algo_types.Add(a);
|
||||
RaisePropertyChanged(nameof(account), nameof(algo_type), nameof(time_in_force));
|
||||
});
|
||||
_algo_types = new ObservableCollection<OrderTypeVM>(_get_algo_types());
|
||||
algo_types_view = CollectionViewSource.GetDefaultView(_algo_types);
|
||||
algo_types_view.GroupDescriptions.Add(new PropertyGroupDescription(nameof(OrderTypeVM.is_bts_type)));
|
||||
algo_types_view.SortDescriptions.Add(new SortDescription(nameof(OrderTypeVM.is_bts_type), ListSortDirection.Ascending));
|
||||
}
|
||||
|
||||
private readonly OrdersModel _model;
|
||||
private readonly Order _order;
|
||||
private readonly ObservableCollection<OrderTypeVM> _algo_types;
|
||||
private Order _order = new Order { LimitOrder = new LimitOrder() };
|
||||
|
||||
public string[] accounts => new[] { "Account1", "Account2", "Account3", "Account4" };
|
||||
private IEnumerable<OrderTypeVM> _get_algo_types() {
|
||||
return OrderHelper.get_default_algos().Select(algo => {
|
||||
var meta = _model.get_metadata(algo);
|
||||
return meta != null ? new OrderTypeVM(_order, algo, meta) : null;
|
||||
});
|
||||
}
|
||||
|
||||
public string[] accounts { get; } = new[] { "Account1", "Account2", "Account3", "Account4" };
|
||||
public string account { get => _order.Account; set => _order.Account = value; }
|
||||
public OrderTypeVM[] algo_types { get; }
|
||||
public OrderTypeVM algo_type { get => algo_types.FirstOrDefault(o => o.is_selected); set { value.is_selected = true; RaisePropertyChanged(); } }
|
||||
public ICollectionView algo_types_view { get; private set; }
|
||||
public OrderTypeVM algo_type {
|
||||
get => _algo_types.FirstOrDefault(o => o.is_selected);
|
||||
set {
|
||||
if (value != null) value.is_selected = true;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
public IEnumerable<Order.Types.TimeInForce> time_in_forces => EnumHelper.get_values<Order.Types.TimeInForce>();
|
||||
public Order.Types.TimeInForce time_in_force { get => _order.TimeInForce; set => _order.TimeInForce = value; }
|
||||
}
|
||||
|
||||
@@ -1,65 +1,64 @@
|
||||
<Window x:Class="mbts.ui.spark.OrderTicket"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:msys="clr-namespace:bts.api;assembly=bts_msys"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.TitleContent="{Binding bbo, Mode=OneWay}"
|
||||
u:WindowStyle.CloseOnEscape="True"
|
||||
Style="{StaticResource BTSWindowTitleTemplate}">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Utilities/Converters/Converters.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">8.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">4.0</sys:Double>
|
||||
<sys:Double x:Key="ButtonHeight">22.0</sys:Double>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<!--<u:WindowStyle.TitleContentTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="{Binding security, Mode=OneWay}" FontWeight="Bold"/>
|
||||
<Run Foreground="{uc:BTSColor MarketData.bid}" FontSize="10" Text="{Binding bid_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
<Run Foreground="{uc:BTSColor MarketData.bid}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="bid"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{uc:BTSColor MarketData.ask}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="ask"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{uc:BTSColor MarketData.ask}" FontSize="10" Text="{Binding ask_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</u:WindowStyle.TitleContentTemplate>-->
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalSpacing}}"/>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<usp:OrderModificationControl Grid.ColumnSpan="3" />
|
||||
<Button Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40" Background="{uc:BTSColor MarketData.bid}" Foreground="White" FontWeight="Bold" u:Behavior.CloseWindow="True" Command="{Binding send_order}" CommandParameter="{u:Enum Buy, Type=msys:BuySell}">Buy</Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40" Background="{uc:BTSColor MarketData.ask}" Foreground="White" FontWeight="Bold" u:Behavior.CloseWindow="True" Command="{Binding send_order}" CommandParameter="{u:Enum Sell, Type=msys:BuySell}">Sell</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
<Window x:Class="mbts.ui.spark.OrderTicket"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:msys="clr-namespace:bts.api;assembly=spark_api"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.TitleContent="{Binding bbo, Mode=OneWay}"
|
||||
u:WindowStyle.CloseOnEscape="True"
|
||||
Style="{StaticResource BTSWindowTitleTemplate}">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">8.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">4.0</sys:Double>
|
||||
<sys:Double x:Key="ButtonHeight">22.0</sys:Double>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalSpacing}}"/>
|
||||
<ColumnDefinition MinWidth="120"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<usp:OrderModificationControl Grid.ColumnSpan="3" />
|
||||
<Button Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40" Background="{u:BTSColor MarketData.bid}" Foreground="White" FontWeight="Bold" u:Behavior.CloseWindow="True" Command="{Binding send_order}" CommandParameter="{u:Enum Buy, Type=msys:BuySell}">Buy</Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="40" Background="{u:BTSColor MarketData.ask}" Foreground="White" FontWeight="Bold" u:Behavior.CloseWindow="True" Command="{Binding send_order}" CommandParameter="{u:Enum Sell, Type=msys:BuySell}">Sell</Button>
|
||||
</Grid>
|
||||
<u:WindowStyle.TitleContentTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="{Binding security, Mode=OneWay}" FontWeight="Bold"/>
|
||||
<Run Foreground="{u:BTSColor MarketData.bid}" FontSize="10" Text="{Binding bid_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
<Run Foreground="{u:BTSColor MarketData.bid}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="bid"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{u:BTSColor MarketData.ask}" FontWeight="Bold">
|
||||
<Run.Text>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
|
||||
<Binding Path="ask"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</Run.Text>
|
||||
</Run>
|
||||
<Run Foreground="{u:BTSColor MarketData.ask}" FontSize="10" Text="{Binding ask_size, Mode=OneWay, StringFormat='{}({0})'}"/>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</u:WindowStyle.TitleContentTemplate>
|
||||
</Window>
|
||||
@@ -10,24 +10,31 @@ namespace mbts.spark
|
||||
{
|
||||
internal class OrderTicketVM : DisposableViewModelBase
|
||||
{
|
||||
public OrderTicketVM(Order order, OrdersModel model, SecurityMD smd, IObservable<LadderSettings> settings) {
|
||||
_order = order;
|
||||
order_params = new OrderParamsVM(_order, model);
|
||||
bbo = new BBOVM(smd);
|
||||
size_calculator = new CalculatorLogic(order.Size, settings.Select(s => s.calculator_buttons));
|
||||
public OrderTicketVM(OrdersModel model, Order order, IObservable<LadderSettings> settings) : this(model, Observable.Return(order), settings) { }
|
||||
public OrderTicketVM(OrdersModel model, IObservable<Order> order, IObservable<LadderSettings> settings) {
|
||||
var order_pub = order.Select(o => {
|
||||
_order = o;
|
||||
size_calculator.value = _order.Size;
|
||||
RaisePropertyChanged(nameof(price), nameof(security));
|
||||
return _order;
|
||||
}).Publish();
|
||||
order_params = new OrderParamsVM(order_pub, model);
|
||||
bbo = new BBOVM(order.Select(o => o.Security));
|
||||
size_calculator = new CalculatorLogic(0, settings.Select(s => s.calculator_buttons));
|
||||
set_price_command = new DelegateCommand<double>(p => { price = p; RaisePropertyChanged(nameof(price)); });
|
||||
send_order = new DelegateCommand<BuySell>(side => { _prepare_order(side); model.send_order(_order); });
|
||||
modify_order = new DelegateCommand(() => { _prepare_order(); model.modify_order(_order); });
|
||||
cancel_order = new DelegateCommand(() => model.cancel_order(new[] { _order.Id }));
|
||||
_dispose = WorkLoop.Start(bbo.refresh);
|
||||
_dispose = Disposable.Create(order_pub.Connect(), order_params, bbo);
|
||||
}
|
||||
|
||||
private readonly Order _order;
|
||||
private Order _order = new Order { Security = Security.Empty, LimitOrder = new LimitOrder() };
|
||||
|
||||
private void _prepare_order(BuySell? side = null) {
|
||||
_order.Size = size_calculator.value;
|
||||
if (side != null) _order.Side = side.Value;
|
||||
}
|
||||
|
||||
public Security security => _order.Security;
|
||||
public CalculatorLogic size_calculator { get; }
|
||||
public double price { get => _order.Price; set => _order.Price = value; }
|
||||
@@ -37,5 +44,5 @@ namespace mbts.spark
|
||||
public ICommand send_order { get; }
|
||||
public ICommand modify_order { get; }
|
||||
public ICommand cancel_order { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,12 @@ namespace mbts.spark
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void show_order_ticket(Order order) { _bus.post(SparkTags.ShowOrderTicketTag, new SparkBusData.ShowOrderTicketMessage(order)); }
|
||||
public void show_order_ticket(IReadOnlyCollection<Order> orders) { _bus.post(SparkTags.ShowOrderTicketTag, new SparkBusData.ShowOrderTicketMessage(orders)); }
|
||||
public void show_order_modify(Order order) { _bus.post(SparkTags.ShowOrderModifyTag, new SparkBusData.ShowOrderModifyMessage(order)); }
|
||||
public void show_order_modify(IReadOnlyCollection<Order> orders) { _bus.post(SparkTags.ShowOrderModifyTag, new SparkBusData.ShowOrderModifyMessage(orders)); }
|
||||
|
||||
internal void show_order_details(OrderID order_id) {
|
||||
_bus.post(SparkTags.ShowOrderDetailsTag, order_id);
|
||||
}
|
||||
@@ -119,6 +125,7 @@ namespace mbts.spark
|
||||
case Order.AlgoOrderTypeOneofCase.IcebergOrder:
|
||||
return new OrderMetadata() { KeyBinding = "I", Color = BTSColors.module_colors[4].rgb_color() };
|
||||
case Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder:
|
||||
case Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder:
|
||||
case Order.AlgoOrderTypeOneofCase.CustomOrder:
|
||||
default:
|
||||
case Order.AlgoOrderTypeOneofCase.None:
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace mbts.spark
|
||||
if (DateTime.Now - _last_fill_activity > _fill_activity_period)
|
||||
{
|
||||
_last_fill_activity = DateTime.Now;
|
||||
IEnumerable<OrderBookEntry> exch_orders = _orderbook.get_all_orders().Where(o => OrderUtils.is_active (o.OrderStatus) && o.order().Security.Exchange != Venue.Bts);
|
||||
IEnumerable<OrderBookEntry> exch_orders = _orderbook.get_all_orders().Where(o => o.is_active() && o.order().Security.Exchange != Venue.Bts);
|
||||
foreach (var o in exch_orders)
|
||||
{
|
||||
double qty = o.order().Size, filled = OrderUtils.filled(o);
|
||||
@@ -46,7 +46,7 @@ namespace mbts.spark
|
||||
new_fill_size = filled + new_fill_size <= qty ? new_fill_size : qty - filled;
|
||||
if (new_fill_size + filled >= qty)
|
||||
o.OrderStatus.Status = OrderStatus.Types.Status.Filled;
|
||||
o.Fills.Add(new Fill() { Order = o.order(), Side = o.order().Side, Size = (uint)new_fill_size, Price = o.order().Price });
|
||||
o.Fills.Add(new Fill() { Id = new FillID { Id = Guid.NewGuid().ToString() }, Order = o.order(), Side = o.order().Side, Size = (uint)new_fill_size, Price = o.order().Price });
|
||||
}
|
||||
}
|
||||
_hub.update_orderbook(_orderbook);
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Reactive.Linq;
|
||||
using bts.api;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
|
||||
@@ -1,155 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.spark;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Reactive.Linq;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
|
||||
public interface ISingleSecurityExchangeGateway
|
||||
{
|
||||
void init (Order order);
|
||||
void modify_price (double new_price);
|
||||
void modify_size (uint size);
|
||||
void cancel_order ();
|
||||
void poll ();
|
||||
IObservable<OrderStatus> on_order_status{get;}
|
||||
IObservable<Fill> on_fills { get; }
|
||||
}
|
||||
|
||||
internal class SimSingleSecurityLimitOrderExchangeGateway : ISingleSecurityExchangeGateway
|
||||
{
|
||||
internal class SimSingleSecurityLimitOrderExchangeGateway : SimSingleSecurityOrderExchangeGateway
|
||||
{
|
||||
private readonly ISubject<OrderStatus> _status_sub = new Subject<OrderStatus>();
|
||||
private readonly ISubject<Fill> _fill_sub = new Subject<Fill>();
|
||||
private readonly IList<Fill> _fills = new List<Fill>();
|
||||
public SimSingleSecurityLimitOrderExchangeGateway(OrderID parent_order_id, SecurityMD md) : base(parent_order_id, md) { }
|
||||
|
||||
private readonly SecurityMD _md;
|
||||
private OrderStatus _order;
|
||||
private OrderID _parent_order_id;
|
||||
private bool _stop;
|
||||
private ulong _depth_ref;
|
||||
public SimSingleSecurityLimitOrderExchangeGateway(OrderID parent_order_id, SecurityMD md)
|
||||
{
|
||||
_md = md;
|
||||
_parent_order_id = parent_order_id;
|
||||
}
|
||||
|
||||
#region ISingleSecurityExchangeGateway
|
||||
public void init(bts.spark.Order order)
|
||||
{
|
||||
|
||||
_order = new OrderStatus()
|
||||
{
|
||||
Order = order,
|
||||
Status = OrderStatus.Types.Status.PendingNew,
|
||||
ParentId = _parent_order_id,
|
||||
};
|
||||
_fire_status();
|
||||
}
|
||||
|
||||
public void modify_price(double new_price)
|
||||
{
|
||||
if(OrderUtils.is_active(_order))
|
||||
{
|
||||
_order.Status = OrderStatus.Types.Status.PendingReplace;
|
||||
_order.Order.Price = new_price;
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
|
||||
public void modify_size(uint new_size)
|
||||
{
|
||||
if(OrderUtils.is_active(_order))
|
||||
{
|
||||
_order.Status = OrderStatus.Types.Status.PendingReplace;
|
||||
_order.Order.Size = new_size;
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel_order()
|
||||
{
|
||||
lock(this)
|
||||
_stop = true;
|
||||
_order.Status = OrderStatus.Types.Status.Canceled;
|
||||
_fire_status();
|
||||
}
|
||||
|
||||
public void poll()
|
||||
{
|
||||
/// poll md mainly
|
||||
if(!_stop)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
if(!_stop)
|
||||
_analyze();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<OrderStatus> on_order_status => _status_sub.AsObservable();
|
||||
|
||||
public IObservable<Fill> on_fills => _fill_sub.AsObservable();
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void _analyze()
|
||||
{
|
||||
if (OrderUtils.is_active(_order)) {
|
||||
if (_order.Status == OrderStatus.Types.Status.PendingReplace) {
|
||||
_order.Status = OrderStatus.Types.Status.Replaced;
|
||||
_fire_status();
|
||||
return;
|
||||
} else {
|
||||
co2.NativePriceSize[] bids = null, asks = null;
|
||||
if (_md.md.get_depth(ref _depth_ref, ref bids, ref asks)) {
|
||||
if (_order.Order.Side == bts.api.BuySell.Buy) {
|
||||
if (_order.Order.Price >= asks[0].price) _fire_fill(asks[0].price, Math.Min(_order.Order.Size - _aggregate_fill_size(), asks[0].size));
|
||||
} else if (_order.Order.Price <= bids[0].price) {
|
||||
_fire_fill(bids[0].price, Math.Min(_order.Order.Size - _aggregate_fill_size(), bids[0].size));
|
||||
} else {
|
||||
/// cross hasnt happened
|
||||
_order.Status = _order.Order.TimeInForce == Order.Types.TimeInForce.Fok || _order.Order.TimeInForce == Order.Types.TimeInForce.Ioc ? OrderStatus.Types.Status.Canceled : OrderStatus.Types.Status.New;
|
||||
}
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _fire_fill(double price, uint size) {
|
||||
var fill = new Fill {
|
||||
Id = new FillID { Id = Guid.NewGuid().ToString() },
|
||||
Order = _order.Order,
|
||||
Side = _order.Order.Side,
|
||||
Price = price,
|
||||
Size = size,
|
||||
Timestamp = (ulong)DateTime.Now.Ticks
|
||||
};
|
||||
_fills.Add(fill);
|
||||
if (_aggregate_fill_size() == _order.Order.Size) {
|
||||
_stop = true;
|
||||
_order.Status = OrderStatus.Types.Status.Filled;
|
||||
} else _order.Status = OrderStatus.Types.Status.PartiallyFilled;
|
||||
_fill_sub.OnNext(fill);
|
||||
}
|
||||
|
||||
private uint _aggregate_fill_size() {
|
||||
uint agg_size = 0;
|
||||
foreach (var f in _fills) agg_size += f.Size;
|
||||
return agg_size;
|
||||
}
|
||||
|
||||
|
||||
private void _fire_status() { _status_sub.OnNext(_order); }
|
||||
|
||||
private void _fire_fill(Fill fill) { _fill_sub.OnNext(fill); }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
protected override bool acceptable_buy_price(double price) { return price <= _order.Order.Price; }
|
||||
protected override bool acceptable_sell_price(double price) { return price >= _order.Order.Price; }
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.spark;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Reactive.Linq;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class SimSingleSecurityMarketOrderExchangeGateway : ISingleSecurityExchangeGateway
|
||||
internal class SimSingleSecurityMarketOrderExchangeGateway : SimSingleSecurityOrderExchangeGateway
|
||||
{
|
||||
private readonly ISubject<OrderStatus> _status_sub = new Subject<OrderStatus>();
|
||||
private readonly ISubject<Fill> _fill_sub = new Subject<Fill>();
|
||||
private readonly SecurityMD _md;
|
||||
private OrderID _parent_order_id;
|
||||
public SimSingleSecurityMarketOrderExchangeGateway(OrderID parent_order_id, SecurityMD md) : base(parent_order_id, md) { }
|
||||
|
||||
public SimSingleSecurityMarketOrderExchangeGateway(OrderID parent_order_id, SecurityMD md)
|
||||
{
|
||||
_md = md;
|
||||
_parent_order_id = parent_order_id;
|
||||
}
|
||||
|
||||
public void init(bts.spark.Order order)
|
||||
{
|
||||
OrderStatus order_status = new OrderStatus()
|
||||
{
|
||||
Order = order,
|
||||
Status = OrderStatus.Types.Status.PendingNew,
|
||||
ParentId = _parent_order_id,
|
||||
};
|
||||
co2.NativePriceSize[] bids = null, asks = null;
|
||||
_md.md.get_depth(ref bids, ref asks);
|
||||
if (order_status.Order.Side == bts.api.BuySell.Buy)
|
||||
{
|
||||
if (asks != null && asks.Length > 0)
|
||||
{
|
||||
order_status.Status = OrderStatus.Types.Status.Filled;
|
||||
Fill fill = new Fill()
|
||||
{
|
||||
Order = order_status.Order,
|
||||
Price = asks[0].price,
|
||||
Side = order_status.Order.Side,
|
||||
Size = order_status.Order.Size
|
||||
};
|
||||
_status_sub.OnNext(order_status);
|
||||
_fill_sub.OnNext(fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
order_status.Status = OrderStatus.Types.Status.Rejected;
|
||||
_status_sub.OnNext(order_status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bids != null && bids.Length > 0)
|
||||
{
|
||||
order_status.Status = OrderStatus.Types.Status.Filled;
|
||||
Fill fill = new Fill()
|
||||
{
|
||||
Order = order_status.Order,
|
||||
Price = bids[0].price,
|
||||
Side = order_status.Order.Side,
|
||||
Size = order_status.Order.Size
|
||||
};
|
||||
_status_sub.OnNext(order_status);
|
||||
_fill_sub.OnNext(fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
order_status.Status = OrderStatus.Types.Status.Rejected;
|
||||
_status_sub.OnNext(order_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void modify_price(double new_price) { }
|
||||
|
||||
public void modify_size(uint new_size) { }
|
||||
|
||||
public void cancel_order() { }
|
||||
|
||||
public void poll() { }
|
||||
|
||||
public IObservable<OrderStatus> on_order_status { get { return _status_sub; } }
|
||||
|
||||
public IObservable<Fill> on_fills { get { return _fill_sub; } }
|
||||
|
||||
|
||||
protected override bool acceptable_buy_price(double price) { return true; }
|
||||
protected override bool acceptable_sell_price(double price) { return true; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
public interface ISingleSecurityExchangeGateway
|
||||
{
|
||||
void init(Order order);
|
||||
void modify_price(double new_price);
|
||||
void modify_size(uint size);
|
||||
void cancel_order();
|
||||
void poll();
|
||||
IObservable<OrderStatus> on_order_status { get; }
|
||||
IObservable<Fill> on_fills { get; }
|
||||
}
|
||||
|
||||
internal abstract class SimSingleSecurityOrderExchangeGateway : ISingleSecurityExchangeGateway
|
||||
{
|
||||
private readonly ISubject<OrderStatus> _status_sub = new Subject<OrderStatus>();
|
||||
private readonly ISubject<Fill> _fill_sub = new Subject<Fill>();
|
||||
private readonly IList<Fill> _fills = new List<Fill>();
|
||||
private readonly SecurityMD _md;
|
||||
|
||||
protected OrderStatus _order;
|
||||
|
||||
private OrderID _parent_order_id;
|
||||
private bool _stop;
|
||||
private ulong _depth_ref;
|
||||
protected SimSingleSecurityOrderExchangeGateway(OrderID parent_order_id, SecurityMD md) {
|
||||
_md = md;
|
||||
_parent_order_id = parent_order_id;
|
||||
}
|
||||
|
||||
#region ISingleSecurityExchangeGateway
|
||||
public void init(Order order) {
|
||||
_order = new OrderStatus() { Order = order, Status = OrderStatus.Types.Status.PendingNew, ParentId = _parent_order_id, };
|
||||
_fire_status();
|
||||
}
|
||||
|
||||
public void modify_price(double new_price) {
|
||||
if (OrderUtils.is_active(_order)) {
|
||||
_order.Status = OrderStatus.Types.Status.PendingReplace;
|
||||
_order.Order.Price = new_price;
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
|
||||
public void modify_size(uint new_size) {
|
||||
if (OrderUtils.is_active(_order)) {
|
||||
_order.Status = OrderStatus.Types.Status.PendingReplace;
|
||||
_order.Order.Size = new_size;
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel_order() {
|
||||
lock (this) _stop = true;
|
||||
_order.Status = OrderStatus.Types.Status.Canceled;
|
||||
_fire_status();
|
||||
}
|
||||
|
||||
public void poll() {
|
||||
/// poll md mainly
|
||||
if (!_stop) {
|
||||
lock (this) {
|
||||
if (!_stop) _analyze();
|
||||
_stop = !OrderUtils.is_active(_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<OrderStatus> on_order_status => _status_sub.AsObservable();
|
||||
|
||||
public IObservable<Fill> on_fills => _fill_sub.AsObservable();
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void _analyze() {
|
||||
if (OrderUtils.is_active(_order)) {
|
||||
if (_order.Status == OrderStatus.Types.Status.PendingReplace) {
|
||||
_order.Status = OrderStatus.Types.Status.Replaced;
|
||||
} else {
|
||||
co2.NativePriceSize[] bids = null, asks = null;
|
||||
if (_md.md.get_depth(ref _depth_ref, ref bids, ref asks)) {
|
||||
if (_order.Order.Side == bts.api.BuySell.Buy) _process_fills(asks, acceptable_buy_price);
|
||||
else _process_fills(bids, acceptable_sell_price);
|
||||
if (_fills.Count == 0) {
|
||||
/// cross hasnt happened
|
||||
_order.Status = _order.Order.TimeInForce == Order.Types.TimeInForce.Fok || _order.Order.TimeInForce == Order.Types.TimeInForce.Ioc ? OrderStatus.Types.Status.Canceled : OrderStatus.Types.Status.New;
|
||||
}
|
||||
}
|
||||
}
|
||||
_fire_status();
|
||||
}
|
||||
}
|
||||
|
||||
private void _process_fills(co2.NativePriceSize[] depth, Func<double, bool> accept_price) {
|
||||
int target = _get_fill_target();
|
||||
foreach (var d in depth.Where(d => d.size > 0)) {
|
||||
if (target <= 0 || !accept_price(d.price)) break;
|
||||
_fire_fill(_get_fill(d.price, target > d.size ? (uint)d.size : (uint)target));
|
||||
target = _get_fill_target();
|
||||
}
|
||||
_order.Status = target <= 0 ? OrderStatus.Types.Status.Filled : OrderStatus.Types.Status.PartiallyFilled;
|
||||
}
|
||||
|
||||
private int _get_fill_target() { return (int)_order.Order.Size - _fills.Sum(f => (int)f.Size); }
|
||||
|
||||
private Fill _get_fill(double price, uint size) {
|
||||
return new Fill {
|
||||
Id = new FillID { Id = Guid.NewGuid().ToString() },
|
||||
Order = _order.Order,
|
||||
Side = _order.Order.Side,
|
||||
Price = price,
|
||||
Size = size,
|
||||
Timestamp = (ulong)DateTime.Now.Ticks
|
||||
};
|
||||
}
|
||||
|
||||
private void _fire_status() { _status_sub.OnNext(_order); }
|
||||
|
||||
private void _fire_fill(Fill fill) {
|
||||
_fills.Add(fill);
|
||||
_fill_sub.OnNext(fill);
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected abstract bool acceptable_buy_price(double price);
|
||||
protected abstract bool acceptable_sell_price(double price);
|
||||
}
|
||||
}
|
||||
+27
-32
@@ -1,33 +1,28 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Themes/generic.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Utilities/Converters/Converters.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Controls/NumberPad.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Controls/PriceEntryControl.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Controls/AlgoTypeItem.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<ControlTemplate x:Key="ContextMenuGroupItemTemplate" TargetType="GroupItem">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<ItemsPresenter x:Name="ItemsHost" SnapsToDevicePixels="True"/>
|
||||
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Fill="DarkGray" RadiusX="1" Margin="27,0,0,0" />
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="ContextMenuGroupItemStyle" TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource ContextMenuGroupItemTemplate}"/>
|
||||
</Style>
|
||||
<GroupStyle x:Key="ContextMenuGroupStyle" ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
<Style x:Key="ContextMenuItemStyle" TargetType="MenuItem">
|
||||
<Setter Property="Header" Value="{Binding display_name}"/>
|
||||
<Setter Property="Command" Value="{Binding command}"/>
|
||||
<Setter Property="Icon" Value="{Binding icon, Converter={StaticResource IconConverter}}"/>
|
||||
<Setter Property="ItemsSource" Value="{Binding items_view}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>
|
||||
<Style x:Key="ContextMenuStyle" TargetType="ContextMenu">
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource ContextMenuItemStyle}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/Converters.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<ControlTemplate x:Key="ContextMenuGroupItemTemplate" TargetType="GroupItem">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<ItemsPresenter x:Name="ItemsHost" SnapsToDevicePixels="True"/>
|
||||
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Fill="DarkGray" RadiusX="1" Margin="27,0,0,0" />
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="ContextMenuGroupItemStyle" TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource ContextMenuGroupItemTemplate}"/>
|
||||
</Style>
|
||||
<GroupStyle x:Key="ContextMenuGroupStyle" ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
<Style x:Key="ContextMenuItemStyle" TargetType="MenuItem">
|
||||
<Setter Property="Header" Value="{Binding display_name}"/>
|
||||
<Setter Property="Command" Value="{Binding command}"/>
|
||||
<Setter Property="Icon" Value="{Binding icon, Converter={StaticResource IconConverter}}"/>
|
||||
<Setter Property="ItemsSource" Value="{Binding items_view}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>
|
||||
<Style x:Key="ContextMenuStyle" TargetType="ContextMenu">
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource ContextMenuItemStyle}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource ContextMenuGroupStyle}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -1,224 +1,224 @@
|
||||
<Window x:Class="mbts.ui.spark.SecurityBrowser"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:sp="clr-namespace:mbts.ui.spark"
|
||||
Title="Security Browser"
|
||||
MinHeight="300"
|
||||
Padding="16,12"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:WindowStyle.DisposeVMOnClose="True"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.CommandBindings>
|
||||
<CommandBinding Command="Close" Executed="CloseCommandHandler" />
|
||||
</Window.CommandBindings>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="Esc" Command="Close" />
|
||||
</Window.InputBindings>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
<SolidColorBrush x:Key="LightBlueGray" Color="{Binding Source={x:Static uc:BTSCoreColors.blue_grey_lightest}, Converter={StaticResource BTSColorConverter}, Mode=OneTime}"/>
|
||||
<SolidColorBrush x:Key="Menu.Disabled.Foreground" Color="Gray" />
|
||||
<SolidColorBrush x:Key="MenuItem.MouseOver.Border" Color="#A826A0DA" />
|
||||
<Style x:Key="MenuButtonStyle" TargetType="Button">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left" />
|
||||
<Setter Property="MinWidth" Value="140" />
|
||||
<Setter Property="Padding" Value="6,2" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{Binding icon}" Width="19" Height="19" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<ContentPresenter x:Name="contentPresenter" Grid.Column="1"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentStringFormat="{TemplateBinding ContentStringFormat}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
RecognizesAccessKey="True"
|
||||
Focusable="False"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource MenuItem.MouseOver.Border}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" TargetName="border" Value="#FFA4B5D6"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ToggleButton.IsChecked" Value="True">
|
||||
<Setter Property="Background" TargetName="border" Value="#FFBCDDEE"/>
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="#FF245A83"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Menu.Disabled.Foreground}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#3D26A0DA"/>
|
||||
<Setter Property="BorderBrush" Value="#FF26A0DA"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="MenuTreeViewItemStyle" TargetType="TreeViewItem">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="IsExpanded" Value="{Binding is_expanded, Mode=TwoWay}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TreeViewItem}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="19" Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="M0,0 L0,6 L6,0 z" Fill="White" Stroke="#FF818181">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF27C7F7"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FFCCEEFB"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1CC4F7"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FF82DFFB"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
</ToggleButton>
|
||||
<Border x:Name="Bd" Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
|
||||
Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" SnapsToDevicePixels="True">
|
||||
<ContentPresenter x:Name="PART_Header" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderStringFormat}"
|
||||
ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Border>
|
||||
<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.Row="1"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsExpanded" Value="False">
|
||||
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{StaticResource Menu.Disabled.Foreground}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<HierarchicalDataTemplate x:Key="MenuTreeViewItemDataTemplate" ItemsSource="{Binding menu_items}">
|
||||
<Button Command="{Binding command}" Content="{Binding display_name}" Style="{StaticResource MenuButtonStyle}" />
|
||||
</HierarchicalDataTemplate>
|
||||
<Style x:Key="MenuTreeViewStyle" TargetType="TreeView">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left"/>
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource MenuTreeViewItemStyle}"/>
|
||||
<Setter Property="ItemTemplate" Value="{StaticResource MenuTreeViewItemDataTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="20" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<sp:SecuritySelectorControl Grid.RowSpan="3" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" Template="{StaticResource SecuritySelectorCheckBoxTemplate}"/>
|
||||
<Border Grid.Column="2" BorderBrush="DimGray" BorderThickness="1" Background="{StaticResource LightBlueGray}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Background="{uc:BTSColor header}" Padding="8">
|
||||
<Border.Resources>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
</Border.Resources>
|
||||
<TextBlock HorizontalAlignment="Center" Foreground="{StaticResource LightBlueGray}" FontWeight="Bold">Actions</TextBlock>
|
||||
</Border>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding action_menu_items}" Style="{StaticResource MenuTreeViewStyle}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="2" BorderBrush="DimGray" BorderThickness="1" Background="{StaticResource LightBlueGray}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Background="{uc:BTSColor header}" Padding="8">
|
||||
<Border.Resources>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
</Border.Resources>
|
||||
<TextBlock HorizontalAlignment="Center" Foreground="{StaticResource LightBlueGray}" FontWeight="Bold">Windows</TextBlock>
|
||||
</Border>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding window_menu_items}" Style="{StaticResource MenuTreeViewStyle}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
<Window x:Class="mbts.ui.spark.SecurityBrowser"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:sp="clr-namespace:mbts.ui.spark"
|
||||
Title="Security Browser"
|
||||
MinHeight="300"
|
||||
Padding="16,12"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:WindowStyle.DisposeVMOnClose="True"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.CommandBindings>
|
||||
<CommandBinding Command="Close" Executed="CloseCommandHandler" />
|
||||
</Window.CommandBindings>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="Esc" Command="Close" />
|
||||
</Window.InputBindings>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
<SolidColorBrush x:Key="LightBlueGray" Color="{Binding Source={x:Static uc:BTSCoreColors.blue_grey_lightest}, Converter={StaticResource BTSColorConverter}, Mode=OneTime}"/>
|
||||
<SolidColorBrush x:Key="Menu.Disabled.Foreground" Color="Gray" />
|
||||
<SolidColorBrush x:Key="MenuItem.MouseOver.Border" Color="#A826A0DA" />
|
||||
<Style x:Key="MenuButtonStyle" TargetType="Button">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left" />
|
||||
<Setter Property="MinWidth" Value="140" />
|
||||
<Setter Property="Padding" Value="6,2" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{Binding icon}" Width="19" Height="19" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<ContentPresenter x:Name="contentPresenter" Grid.Column="1"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentStringFormat="{TemplateBinding ContentStringFormat}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
RecognizesAccessKey="True"
|
||||
Focusable="False"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource MenuItem.MouseOver.Border}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" TargetName="border" Value="#FFA4B5D6"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ToggleButton.IsChecked" Value="True">
|
||||
<Setter Property="Background" TargetName="border" Value="#FFBCDDEE"/>
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="#FF245A83"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Menu.Disabled.Foreground}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#3D26A0DA"/>
|
||||
<Setter Property="BorderBrush" Value="#FF26A0DA"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="MenuTreeViewItemStyle" TargetType="TreeViewItem">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="IsExpanded" Value="{Binding is_expanded, Mode=TwoWay}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TreeViewItem}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="19" Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="M0,0 L0,6 L6,0 z" Fill="White" Stroke="#FF818181">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF27C7F7"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FFCCEEFB"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1CC4F7"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="#FF82DFFB"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
</ToggleButton>
|
||||
<Border x:Name="Bd" Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
|
||||
Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" SnapsToDevicePixels="True">
|
||||
<ContentPresenter x:Name="PART_Header" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderStringFormat}"
|
||||
ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</Border>
|
||||
<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.Row="1"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsExpanded" Value="False">
|
||||
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{StaticResource Menu.Disabled.Foreground}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<HierarchicalDataTemplate x:Key="MenuTreeViewItemDataTemplate" ItemsSource="{Binding menu_items}">
|
||||
<Button Command="{Binding command}" Content="{Binding display_name}" Style="{StaticResource MenuButtonStyle}" />
|
||||
</HierarchicalDataTemplate>
|
||||
<Style x:Key="MenuTreeViewStyle" TargetType="TreeView">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left"/>
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource MenuTreeViewItemStyle}"/>
|
||||
<Setter Property="ItemTemplate" Value="{StaticResource MenuTreeViewItemDataTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="20" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<sp:SecuritySelectorControl Grid.RowSpan="3" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" Template="{StaticResource SecuritySelectorCheckBoxTemplate}"/>
|
||||
<Border Grid.Column="2" BorderBrush="DimGray" BorderThickness="1" Background="{StaticResource LightBlueGray}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Background="{uc:BTSColor header}" Padding="8">
|
||||
<Border.Resources>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
</Border.Resources>
|
||||
<TextBlock HorizontalAlignment="Center" Foreground="{StaticResource LightBlueGray}" FontWeight="Bold">Actions</TextBlock>
|
||||
</Border>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding action_menu_items}" Style="{StaticResource MenuTreeViewStyle}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="2" BorderBrush="DimGray" BorderThickness="1" Background="{StaticResource LightBlueGray}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Background="{uc:BTSColor header}" Padding="8">
|
||||
<Border.Resources>
|
||||
<cv:BTSColorConverter x:Key="BTSColorConverter"/>
|
||||
</Border.Resources>
|
||||
<TextBlock HorizontalAlignment="Center" Foreground="{StaticResource LightBlueGray}" FontWeight="Bold">Windows</TextBlock>
|
||||
</Border>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding window_menu_items}" Style="{StaticResource MenuTreeViewStyle}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -7,7 +7,8 @@ namespace mbts.spark
|
||||
internal class SecurityBrowserVM : SecuritySelectorVM
|
||||
{
|
||||
public SecurityBrowserVM(IBus bus) {
|
||||
_actions = MenuItemVM.CreateMenu(selected_securities, new CancelOrdersMenuItem(bus), new SyntheticCreateMenuItem(bus), new SyntheticStrategyMenuItem(bus), new OrderTicketMenuItem(bus));
|
||||
var orders_model = new OrdersModel(bus);
|
||||
_actions = MenuItemVM.CreateMenu(selected_securities, new CancelOrdersMenuItem(orders_model), new SyntheticCreateMenuItem(bus), new SyntheticStrategyMenuItem(bus), new OrderTicketMenuItem(orders_model));
|
||||
_windows = MenuItemVM.CreateMenu(selected_securities, new LadderMenuItem(bus), new MarketViewMenuItem(bus), new SpreadMatrixMenuItem(bus), new TimeAndSalesMenuItem(bus));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<Window x:Class="mbts.ui.spark.SecuritySelectorDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:sp="clr-namespace:mbts.ui.spark"
|
||||
Title="{Binding title, FallbackValue='Security Browser'}"
|
||||
MinHeight="300"
|
||||
MinWidth="250"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<sp:SecuritySelectorControl Margin="8" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" Template="{StaticResource SecuritySelectorCheckBoxTemplate}" />
|
||||
<c:DialogSkirtOKCancel Grid.Row="1" OKCommand="{Binding commit}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
<Window x:Class="mbts.ui.spark.SecuritySelectorDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:sp="clr-namespace:mbts.ui.spark"
|
||||
Title="{Binding title, FallbackValue='Security Browser'}"
|
||||
MinHeight="300"
|
||||
MinWidth="250"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<sp:SecuritySelectorControl Margin="8" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" Template="{StaticResource SecuritySelectorCheckBoxTemplate}" />
|
||||
<c:DialogSkirtOKCancel Grid.Row="1" OKCommand="{Binding commit}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -8,8 +8,8 @@ namespace mbts.spark
|
||||
{
|
||||
internal class SecuritySelectorDialogVM : SecuritySelectorVM
|
||||
{
|
||||
public SecuritySelectorDialogVM(string title, Security[] preselected_securities, Action<IEnumerable<Security>> commit) : this (title, preselected_securities, commit, SecuritySource.GetObservable()) { }
|
||||
public SecuritySelectorDialogVM(string title, Security[] preselected_securities, Action<IEnumerable<Security>> commit, IObservable<Security[]> securities_stream) : base(preselected_securities, securities_stream) {
|
||||
public SecuritySelectorDialogVM(string title, IReadOnlyCollection<Security> preselected_securities, Action<IEnumerable<Security>> commit) : this (title, preselected_securities, commit, SecuritySource.GetObservable()) { }
|
||||
public SecuritySelectorDialogVM(string title, IReadOnlyCollection<Security> preselected_securities, Action<IEnumerable<Security>> commit, IObservable<Security[]> securities_stream) : base(preselected_securities, securities_stream) {
|
||||
this.title = title;
|
||||
this.commit = new DelegateCommand(() => commit(selected_securities));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts.api;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace mbts.spark
|
||||
@@ -8,8 +9,8 @@ namespace mbts.spark
|
||||
public class SecuritySelectorVM : IDisposable
|
||||
{
|
||||
public SecuritySelectorVM() : this(new Security[0]) { }
|
||||
public SecuritySelectorVM(Security[] preselected_securities) : this(preselected_securities, SecuritySource.GetObservable()) { }
|
||||
public SecuritySelectorVM(Security[] preselected_securities, IObservable<Security[]> securities_stream) {
|
||||
public SecuritySelectorVM(IReadOnlyCollection<Security> preselected_securities) : this(preselected_securities, SecuritySource.GetObservable()) { }
|
||||
public SecuritySelectorVM(IReadOnlyCollection<Security> preselected_securities, IObservable<Security[]> securities_stream) {
|
||||
selected_securities = new ObservableCollection<Security>(preselected_securities);
|
||||
securities = new RXObservableCollection<Security>(securities_stream);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using bts.api;
|
||||
using mbts.ui;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal static class SecuritySource
|
||||
{
|
||||
public static IObservable<Security[]> GetObservable() { return _instance.source.AsObservable(); }
|
||||
public static IObservable<Security[]> GetObservable() {
|
||||
return _instance.publisher.AsObservable();
|
||||
}
|
||||
|
||||
private static InternalSource _instance;
|
||||
|
||||
@@ -20,15 +22,15 @@ namespace mbts.spark
|
||||
{
|
||||
[ImportingConstructor]
|
||||
public InternalSource(IBus bus) {
|
||||
source = bus.subscribe<Dictionary<uint, SecurityMD>>(SparkTags.SecuritiesTag)
|
||||
.Select(m => m.Values.Select(s => s.security).Ordered().ToArray())
|
||||
.Publish(new Security[0]);
|
||||
publisher = new StatePublisher<Security[]>(bus.subscribe<Dictionary<uint, SecurityMD>>(SparkTags.SecuritiesTag)
|
||||
.Select(m => m.Values.Select(s => s.security).Ordered().ToArray()));
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
public readonly IConnectableObservable<Security[]> source;
|
||||
internal readonly StatePublisher<Security[]> publisher;
|
||||
|
||||
public int priority => int.MaxValue;
|
||||
public void initialize() { source.Connect(); }
|
||||
public void initialize() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
public class CalculatorLogic : DisposableViewModelBase {
|
||||
public CalculatorLogic(uint initial_size, IObservable<int[]> buttons_source) {
|
||||
_size = backing(nameof(value), initial_size);
|
||||
_buttons = backing(nameof(buttons), buttons_source);
|
||||
}
|
||||
|
||||
Property<uint> _size;
|
||||
public uint value { get => _size.Value; set => _size.set(value); }
|
||||
Property<int[]> _buttons;
|
||||
public int[] buttons { get => _buttons.Value; set => _buttons.set(value); }
|
||||
public ICommand click => new DelegateCommand<uint>(handle_calculator_click);
|
||||
public ICommand set_value_command => new DelegateCommand<uint>(_size.set);
|
||||
|
||||
private void handle_calculator_click(uint value) {
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || value == 0) {
|
||||
_size.Value = value;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
public class CalculatorLogic : DisposableViewModelBase {
|
||||
public CalculatorLogic(uint initial_size, IObservable<int[]> buttons_source) {
|
||||
_size = backing(nameof(value), initial_size);
|
||||
_buttons = backing(nameof(buttons), buttons_source);
|
||||
}
|
||||
|
||||
Property<uint> _size;
|
||||
public uint value { get => _size.Value; set => _size.set(value); }
|
||||
Property<int[]> _buttons;
|
||||
public int[] buttons { get => _buttons.Value; set => _buttons.set(value); }
|
||||
public ICommand click => new DelegateCommand<uint>(handle_calculator_click);
|
||||
public ICommand set_value_command => new DelegateCommand<uint>(_size.set);
|
||||
|
||||
private void handle_calculator_click(uint value) {
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || value == 0) {
|
||||
_size.Value = value;
|
||||
} else if (KeyboardExtensions.IsCtrlDown()) {
|
||||
_size.Value -= value;
|
||||
}
|
||||
else {
|
||||
_size.Value += value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
_size.Value += value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.spark.menu_items;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
@@ -10,7 +12,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
@@ -23,15 +24,18 @@ namespace mbts.spark
|
||||
public const int VERSION = 1;
|
||||
public const string SAVE_NAME = "Fills";
|
||||
|
||||
public FillsVM(OrdersModel model, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria = null) {
|
||||
public FillsVM(IBus bus, OrdersModel model, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria = null) {
|
||||
_bus = bus;
|
||||
_model = model;
|
||||
_securities = new HashSet<Security>(securities);
|
||||
var rows = new ObservableAutoWrapper<Row, FillTuple>(_fills, f => new Row(f, _model));
|
||||
row_views = CollectionViewSource.GetDefaultView(rows);
|
||||
if (sorting_criteria != null) row_views.SortDescriptions.AddRange(sorting_criteria.Select(sc => sc.to_sort_description()));
|
||||
else row_views.SortDescriptions.Add(new SortDescription(nameof(Row.fill_time), ListSortDirection.Descending));
|
||||
//_dispose = _model.on_orderbook().Buffer(TimeSpan.FromSeconds(1)).Where(obs => obs.Count > 0).Select(obs => obs[obs.Count -1]).ObserveOnDispatcher().Subscribe(ob => { _order_book = ob; _update(); });
|
||||
_dispose = _model.on_orderbook().Buffer(TimeSpan.FromSeconds(1)).Where(obs => obs.Count > 0).Select(obs => obs[obs.Count - 1]).ObserveOnDispatcher().Subscribe(ob => { _order_book = ob; _update(); });
|
||||
_rows = new ObservableAutoWrapper<Row, FillTuple>(_fills, f => new Row(f, _model));
|
||||
rows_view = CollectionViewSource.GetDefaultView(_rows);
|
||||
if (sorting_criteria != null) rows_view.SortDescriptions.AddRange(sorting_criteria.Select(sc => sc.to_sort_description()));
|
||||
else rows_view.SortDescriptions.Add(new SortDescription(nameof(Row.fill_time), ListSortDirection.Descending));
|
||||
_dispose = Disposable.Create(
|
||||
_context_menu = new ContextMenuVM(_context_menu_item_factory),
|
||||
_model.on_orderbook().Buffer(TimeSpan.FromSeconds(1)).Where(obs => obs.Count > 0).Select(obs => obs[obs.Count - 1]).ObserveOnDispatcher().Subscribe(ob => { _order_book = ob; _update(); })
|
||||
);
|
||||
modify_security_selection = new DialogCommand(() => new SecuritySelectorDialog {
|
||||
DataContext = new SecuritySelectorDialogVM("Fills", _securities.ToArray(),
|
||||
secs => {
|
||||
@@ -41,11 +45,14 @@ namespace mbts.spark
|
||||
}, () => true, true, -12, -30);
|
||||
}
|
||||
|
||||
private OrdersModel _model;
|
||||
private HashSet<Security> _securities;
|
||||
private readonly IBus _bus;
|
||||
private readonly OrdersModel _model;
|
||||
private readonly ObservableCollection<FillTuple> _fills = new ObservableCollection<FillTuple>();
|
||||
private readonly ObservableAutoWrapper<Row, FillTuple> _rows;
|
||||
private HashSet<Security> _securities;
|
||||
private IOrderBook _order_book = new OrderBook();
|
||||
private List<TimeSpan> _update_log = new List<TimeSpan>();
|
||||
private ContextMenuVM _context_menu;
|
||||
|
||||
private void _update() {
|
||||
var map = _order_book.get_fill_tuple_sec_map();
|
||||
@@ -55,17 +62,37 @@ namespace mbts.spark
|
||||
_fills.sync_with(map.Where(kv => sec_keys.Contains(kv.Key)).SelectMany(kv => kv.Value));
|
||||
}
|
||||
}
|
||||
private IEnumerable<MenuItemVM> _context_menu_item_factory() {
|
||||
var selected_rows = _rows.Where(r => r.is_selected);
|
||||
var securities = new HashSet<Security>(selected_rows.Select(r => r.security));
|
||||
yield return MenuItemVM.Create(new LadderMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new OrderTicketMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new MarketViewMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SpreadMatrixMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticCreateMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticStrategyMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new ModifyOrderRootMenuItem(_model, new HashSet<Order>(selected_rows.Select(r => r.entry.order()))), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrderRootMenuItem(_model, new HashSet<Order>(selected_rows.Where(r => r.entry.status() != OrderStatus.Types.Status.Canceled).Select(r => r.entry.order()))), securities);
|
||||
yield return MenuItemVM.Create(new CancelBuyOrdersMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelSellOrdersMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrdersMenuItem(_model), securities);
|
||||
}
|
||||
|
||||
public IDialogCommand modify_security_selection { get; }
|
||||
public ICollectionView row_views { get; private set; }
|
||||
public ICollectionView rows_view { get; private set; }
|
||||
public ContextMenuVM context_menu => _context_menu;
|
||||
|
||||
public void get_state(Stream save_here) {
|
||||
ProtoBufSerializationHelper.serialize(save_here, new ShellSerializationHeader { name = SAVE_NAME, version = VERSION });
|
||||
ProtoBufSerializationHelper.serialize(save_here, new StartupData(_securities, row_views.SortDescriptions.Select(sd => new SortingCriteria(sd)).ToArray()));
|
||||
ProtoBufSerializationHelper.serialize(save_here, new StartupData(_securities, rows_view.SortDescriptions.Select(sd => new SortingCriteria(sd)).ToArray()));
|
||||
}
|
||||
|
||||
private class Row {
|
||||
public Row(FillTuple fill, OrdersModel model) {
|
||||
_fill = fill.Fill;
|
||||
if (_fill.Id == null) {
|
||||
|
||||
}
|
||||
_entry = fill.OrderBookEntry;
|
||||
_model = model;
|
||||
uint aggr_fills = 0;
|
||||
@@ -77,6 +104,7 @@ namespace mbts.spark
|
||||
private readonly OrdersModel _model;
|
||||
private readonly Fill _fill;
|
||||
private readonly OrderBookEntry _entry;
|
||||
public OrderBookEntry entry => _entry;
|
||||
public DateTime order_time => _entry.order().Timestamp.lldatetime();
|
||||
public DateTime fill_time => _fill.Timestamp.lldatetime();
|
||||
public Order.Types.TimeInForce time_in_force => _fill.Order.TimeInForce;
|
||||
@@ -96,6 +124,7 @@ namespace mbts.spark
|
||||
public string bts_fill_id => _fill.Id.Id;
|
||||
public string bts_order_id => _fill.Order.Id.Id;
|
||||
public string exch_order_id => "None because this is a simulation.";
|
||||
public bool is_selected { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
|
||||
@@ -1,56 +1,73 @@
|
||||
<UserControl x:Class="mbts.ui.spark.FillsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<uspcv:TickDisplayConverter x:Key="TickDisplayConverter"/>
|
||||
<uspcv:AlgoTypeDisplayBrushConverter x:Key="AlgoTypeDisplayBrushConverter"/>
|
||||
<uspcv:AlgoTypeDisplayTextConverter x:Key="AlgoTypeDisplayTextConverter"/>
|
||||
<Style x:Key="SideColorCodedTextElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding side}" Value="Sell">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AlgoTypeElement" TargetType="usp:AlgoTypeItem">
|
||||
<Setter Property="AlgoType" Value="{Binding algo_type}"/>
|
||||
<Setter Property="Metadata" Value="{Binding order_metadata}"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<DataGrid IsReadOnly="True" CanUserSortColumns="True" GridLinesVisibility="None" ItemsSource="{Binding row_views}" u:DataGridBehavior.NotifyColumnsOfSorting="True">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Order Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding order_time, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="Fill Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding fill_time, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="User" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding user}"/>
|
||||
<DataGridTextColumn Header="Account" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding account}"/>
|
||||
<DataGridTextColumn Header="Exchange" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding exchange}"/>
|
||||
<DataGridTextColumn Header="Security" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding security, StringFormat='q/n:./m:c'}"/>
|
||||
<DataGridTextColumn Header="TIF" Binding="{Binding time_in_force}"/>
|
||||
<usp:DataGridAlgoTypeColumn Header="Algo" ElementStyle="{StaticResource AlgoTypeElement}" SortMemberPath="algo_type"/>
|
||||
<DataGridTextColumn Header="B/S" ElementStyle="{StaticResource SideColorCodedTextElement}" Binding="{Binding side}" />
|
||||
<DataGridTextColumn Header="Price" SortMemberPath="price">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" Binding="{Binding size_text}" SortMemberPath="size"/>
|
||||
<DataGridTextColumn Header="Filled%" Binding="{Binding fill_percentage, StringFormat=P1}"/>
|
||||
<DataGridTextColumn Header="Order%" Binding="{Binding order_percentage, StringFormat=P1}"/>
|
||||
<DataGridTextColumn Header="Status" Binding="{Binding order_status}"/>
|
||||
<DataGridTextColumn Header="BTS Fill" Binding="{Binding bts_fill_id}"/>
|
||||
<DataGridTextColumn Header="BTS Order" Binding="{Binding bts_order_id}"/>
|
||||
<DataGridTextColumn Header="Exchange Order" Binding="{Binding exch_order_id}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.ui.spark.FillsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Resources/MenuResources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<uspcv:TickDisplayConverter x:Key="TickDisplayConverter"/>
|
||||
<uspcv:AlgoTypeDisplayBrushConverter x:Key="AlgoTypeDisplayBrushConverter"/>
|
||||
<uspcv:AlgoTypeDisplayTextConverter x:Key="AlgoTypeDisplayTextConverter"/>
|
||||
<Style x:Key="SideColorCodedTextElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding side}" Value="Sell">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AlgoTypeElement" TargetType="usp:AlgoTypeItem">
|
||||
<Setter Property="AlgoType" Value="{Binding algo_type}"/>
|
||||
<Setter Property="Metadata" Value="{Binding order_metadata}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<DataGrid IsReadOnly="True" CanUserSortColumns="True" GridLinesVisibility="None" ItemsSource="{Binding rows_view}" u:DataGridBehavior.NotifyColumnsOfSorting="True">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding context_menu.items_view}" IsOpen="{Binding context_menu.is_open, Mode=OneWayToSource}" ItemContainerStyle="{StaticResource ContextMenuItemStyle}">
|
||||
<ContextMenu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
</ContextMenu.GroupStyle>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="IsSelected" Value="{Binding is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Order Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding order_time, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="Fill Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding fill_time, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="User" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding user}"/>
|
||||
<DataGridTextColumn Header="Account" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding account}"/>
|
||||
<DataGridTextColumn Header="Exchange" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding exchange}"/>
|
||||
<DataGridTextColumn Header="Security" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding security, StringFormat='q/n:./m:c'}"/>
|
||||
<DataGridTextColumn Header="TIF" Binding="{Binding time_in_force}"/>
|
||||
<usp:DataGridAlgoTypeColumn Header="Algo" ElementStyle="{StaticResource AlgoTypeElement}" SortMemberPath="algo_type"/>
|
||||
<DataGridTextColumn Header="B/S" ElementStyle="{StaticResource SideColorCodedTextElement}" Binding="{Binding side}" />
|
||||
<DataGridTextColumn Header="Price" SortMemberPath="price">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" Binding="{Binding size_text}" SortMemberPath="size"/>
|
||||
<DataGridTextColumn Header="Filled%" Binding="{Binding fill_percentage, StringFormat=P1}"/>
|
||||
<DataGridTextColumn Header="Order%" Binding="{Binding order_percentage, StringFormat=P1}"/>
|
||||
<DataGridTextColumn Header="Status" Binding="{Binding order_status}"/>
|
||||
<DataGridTextColumn Header="BTS Fill" Binding="{Binding bts_fill_id}"/>
|
||||
<DataGridTextColumn Header="BTS Order" Binding="{Binding bts_order_id}"/>
|
||||
<DataGridTextColumn Header="Exchange Order" Binding="{Binding exch_order_id}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,146 +1,146 @@
|
||||
<UserControl x:Class="mbts.ui.spark.LaunchMenu"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
MinHeight="10"
|
||||
MinWidth="200"
|
||||
MaxHeight="{StaticResource MaxMenuHeight}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<ControlTemplate x:Key="GroupItemTemplate" TargetType="GroupItem">
|
||||
<Border x:Name="bd" BorderBrush="Black" BorderThickness="0,0,0,1">
|
||||
<ItemsPresenter x:Name="ItemsHost"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource GroupItemTemplate}"/>
|
||||
</Style>
|
||||
<GroupStyle x:Key="MenuItemGroupStyle" ContainerStyle="{StaticResource {x:Type GroupItem}}"/>
|
||||
<ControlTemplate x:Key="MenuItemTemplate" TargetType="{x:Type MenuItem}">
|
||||
<Border x:Name="templateRoot" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{Binding icon}" Width="19" Height="19" Margin="6,0"/>
|
||||
<ContentPresenter Grid.Column="1" ContentSource="Header" Margin="4" MinWidth="150" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
<Path x:Name="Arrow" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" Fill="Black" Margin="0,0,3,0" Data="M 0,0 L 4,3.5 L 0,7 Z"/>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right">
|
||||
<Border x:Name="SubMenuBorder" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="3" Background="#FFF6F6F6" Padding="2">
|
||||
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
|
||||
<Grid RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
|
||||
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsHighlighted" Value="True">
|
||||
<Setter TargetName="templateRoot" Property="Background" Value="{DynamicResource StartMenuMouseOverBackground}" />
|
||||
<Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource StartMenuPressedBorderBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
|
||||
</Trigger>
|
||||
<Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
|
||||
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True" >
|
||||
<Setter Property="IsOpen" TargetName="PART_Popup" Value="True"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Visibility" TargetName="SubMenuBorder" Value="Collapsed" />
|
||||
<Setter Property="Visibility" TargetName="Arrow" Value="Collapsed" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="MenuItem">
|
||||
<Setter Property="Command" Value="{Binding command}"/>
|
||||
<Setter Property="Template" Value="{StaticResource MenuItemTemplate}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource MenuItemGroupStyle}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Menu HorizontalAlignment="Stretch" ItemsSource="{Binding items_view}">
|
||||
<Menu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource {x:Type GroupItem}}"/>
|
||||
</Menu.GroupStyle>
|
||||
<Menu.ItemTemplateSelector>
|
||||
<usp:LaunchMenuItemTemplateSelector>
|
||||
<usp:LaunchMenuItemTemplateSelector.ActionTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.ActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.SecurityActionTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
<Popup IsOpen="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource AncestorType=MenuItem}}" StaysOpen="True" MaxHeight="500" Focusable="False" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}}">
|
||||
<Border Background="{StaticResource CommonBackground}" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:SecuritySelectorControl Margin="6" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" SelectionMode="Single"/>
|
||||
<Border Grid.Row="1" Padding="6,4" Background="{DynamicResource StartMenuMouseOverBackground}">
|
||||
<Button HorizontalAlignment="Right" IsDefault="True" Command="{Binding launch_command}" Style="{StaticResource CommonButton}">Launch</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.SecurityActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.SecuritiesActionTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
<Popup IsOpen="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource AncestorType=MenuItem}}" StaysOpen="True" MaxHeight="500" Focusable="False" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}}">
|
||||
<Border Background="{StaticResource CommonBackground}" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:SecuritySelectorControl Margin="6" Focusable="False" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" SelectionMode="Multiple"/>
|
||||
<Border Grid.Row="1" Padding="6,4" Background="{DynamicResource StartMenuMouseOverBackground}">
|
||||
<Button HorizontalAlignment="Right" Focusable="False" IsDefault="True" Command="{Binding launch_command}" Style="{StaticResource CommonButton}">Launch</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.SecuritiesActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.GroupTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding items_view}">
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
</HierarchicalDataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.GroupTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector>
|
||||
</Menu.ItemTemplateSelector>
|
||||
<Menu.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</Menu.ItemsPanel>
|
||||
</Menu>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.ui.spark.LaunchMenu"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
MinHeight="10"
|
||||
MinWidth="200"
|
||||
MaxHeight="{StaticResource MaxMenuHeight}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<ControlTemplate x:Key="GroupItemTemplate" TargetType="GroupItem">
|
||||
<Border x:Name="bd" BorderBrush="Black" BorderThickness="0,0,0,1">
|
||||
<ItemsPresenter x:Name="ItemsHost"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource GroupItemTemplate}"/>
|
||||
</Style>
|
||||
<GroupStyle x:Key="MenuItemGroupStyle" ContainerStyle="{StaticResource {x:Type GroupItem}}"/>
|
||||
<ControlTemplate x:Key="MenuItemTemplate" TargetType="{x:Type MenuItem}">
|
||||
<Border x:Name="templateRoot" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{Binding icon}" Width="19" Height="19" Margin="6,0"/>
|
||||
<ContentPresenter Grid.Column="1" ContentSource="Header" Margin="4" MinWidth="150" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
<Path x:Name="Arrow" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" Fill="Black" Margin="0,0,3,0" Data="M 0,0 L 4,3.5 L 0,7 Z"/>
|
||||
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right">
|
||||
<Border x:Name="SubMenuBorder" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="3" Background="#FFF6F6F6" Padding="2">
|
||||
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
|
||||
<Grid RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
|
||||
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=SubMenuBorder}" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
|
||||
</Canvas>
|
||||
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSuspendingPopupAnimation" Value="True">
|
||||
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsHighlighted" Value="True">
|
||||
<Setter TargetName="templateRoot" Property="Background" Value="{DynamicResource StartMenuMouseOverBackground}" />
|
||||
<Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource StartMenuPressedBorderBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
|
||||
</Trigger>
|
||||
<Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
|
||||
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
|
||||
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True" >
|
||||
<Setter Property="IsOpen" TargetName="PART_Popup" Value="True"/>
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Visibility" TargetName="SubMenuBorder" Value="Collapsed" />
|
||||
<Setter Property="Visibility" TargetName="Arrow" Value="Collapsed" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="MenuItem">
|
||||
<Setter Property="Command" Value="{Binding command}"/>
|
||||
<Setter Property="Template" Value="{StaticResource MenuItemTemplate}"/>
|
||||
<Setter Property="usp:LaunchMenu.GroupStyle" Value="{StaticResource MenuItemGroupStyle}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Menu HorizontalAlignment="Stretch" ItemsSource="{Binding items_view}">
|
||||
<Menu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource {x:Type GroupItem}}"/>
|
||||
</Menu.GroupStyle>
|
||||
<Menu.ItemTemplateSelector>
|
||||
<usp:LaunchMenuItemTemplateSelector>
|
||||
<usp:LaunchMenuItemTemplateSelector.ActionTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.ActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.SecurityActionTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
<Popup IsOpen="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource AncestorType=MenuItem}}" StaysOpen="True" MaxHeight="500" Focusable="False" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}}">
|
||||
<Border Background="{StaticResource CommonBackground}" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:SecuritySelectorControl Margin="6" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" SelectionMode="Single"/>
|
||||
<Border Grid.Row="1" Padding="6,4" Background="{DynamicResource StartMenuMouseOverBackground}">
|
||||
<Button HorizontalAlignment="Right" IsDefault="True" Command="{Binding launch_command}" Style="{StaticResource CommonButton}">Launch</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.SecurityActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.SecuritiesActionTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
<Popup IsOpen="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource AncestorType=MenuItem}}" StaysOpen="True" MaxHeight="500" Focusable="False" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=MenuItem}}">
|
||||
<Border Background="{StaticResource CommonBackground}" BorderBrush="{DynamicResource StartMenuMouseOverBackground}" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:SecuritySelectorControl Margin="6" Focusable="False" Securities="{Binding securities}" SelectedSecurities="{Binding selected_securities}" SelectionMode="Multiple"/>
|
||||
<Border Grid.Row="1" Padding="6,4" Background="{DynamicResource StartMenuMouseOverBackground}">
|
||||
<Button HorizontalAlignment="Right" Focusable="False" IsDefault="True" Command="{Binding launch_command}" Style="{StaticResource CommonButton}">Launch</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Popup>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.SecuritiesActionTemplate>
|
||||
<usp:LaunchMenuItemTemplateSelector.GroupTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding items_view}">
|
||||
<TextBlock Text="{Binding display_name}"/>
|
||||
</HierarchicalDataTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector.GroupTemplate>
|
||||
</usp:LaunchMenuItemTemplateSelector>
|
||||
</Menu.ItemTemplateSelector>
|
||||
<Menu.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</Menu.ItemsPanel>
|
||||
</Menu>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using static mbts.ui.spark.LaunchMenuItemTemplateSelector;
|
||||
@@ -22,8 +23,6 @@ namespace mbts.spark.menu_items
|
||||
public static LaunchMenuItemVM Create(IMenuItem model) {
|
||||
var act_mi = model as IMenuActionItem;
|
||||
if (act_mi != null) return Create(act_mi);
|
||||
var sec_mi = model as IMenuSecurityActionItem;
|
||||
if (sec_mi != null) return Create(sec_mi);
|
||||
var secs_mi = model as IMenuSecuritiesActionItem;
|
||||
if (secs_mi != null) return Create(secs_mi);
|
||||
var grp_mi = model as IMenuGroupItem;
|
||||
@@ -37,21 +36,13 @@ namespace mbts.spark.menu_items
|
||||
return new LaunchMenuItemVM(model.display_name, model.sectional_id, model.icon, command, Template.Action, dispose:model as IDisposable);
|
||||
}
|
||||
|
||||
public static LaunchMenuItemVM Create(IMenuSecurityActionItem model) {
|
||||
SecurityLaunchMenuItem rv = null; IDisposable sub = null;
|
||||
var command = new DelegateCommand(() => model.execute(rv.selected_securities.SingleOrDefault()), () => rv.selected_securities.Count == 1 && model.can_execute(rv.selected_securities[0]));
|
||||
rv = new SecurityLaunchMenuItem(model.display_name, model.sectional_id, model.icon, command, Template.Security, Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }));
|
||||
sub = rv.selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged());
|
||||
model.can_execute_changed += () => command.RaiseCanExecuteChanged();
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static LaunchMenuItemVM Create(IMenuSecuritiesActionItem model) {
|
||||
SecurityLaunchMenuItem rv = null;
|
||||
IDisposable sub = null;
|
||||
IRaiseCanExecuteChangedCommand command = null;
|
||||
command = new DelegateCommand(() => {
|
||||
using (sub) model.execute(rv.selected_securities);
|
||||
using (sub) model.execute(rv.selected_securities.ToList());
|
||||
rv.selected_securities.Clear();
|
||||
sub = rv.selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged());
|
||||
}, () => model.can_execute(rv.selected_securities));
|
||||
rv = new SecurityLaunchMenuItem(model.display_name, model.sectional_id, model.icon, command, Template.Securities, Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }));
|
||||
@@ -66,7 +57,7 @@ namespace mbts.spark.menu_items
|
||||
#endregion
|
||||
|
||||
protected LaunchMenuItemVM(string display_name, string sectional_id, ImageSource icon, ICommand command=null, Template template_key=Template.Action, IEnumerable<LaunchMenuItemVM> items=null, IDisposable dispose=null)
|
||||
: base(display_name, sectional_id, icon, command, items, dispose) {
|
||||
: base(Observable.Return(display_name), sectional_id, icon, command, items, dispose) {
|
||||
this.template_key = template_key;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,20 +21,21 @@ using SecurityKey = System.UInt32;
|
||||
namespace mbts.spark
|
||||
{
|
||||
[Export(typeof(IShellModule))]
|
||||
internal class MarketModule : IShellModule
|
||||
{
|
||||
internal class MarketModule : IShellModule {
|
||||
[ImportingConstructor]
|
||||
public MarketModule(IBus bus, IWindowManager wm) {
|
||||
_bus = bus;
|
||||
_wm = wm;
|
||||
_dispose = Disposable.Create(
|
||||
_bus.subscribe<Dictionary<SecurityKey,SecurityMD>>(SecuritiesTag).ObserveOnDispatcher().Subscribe(s => _securities = s),
|
||||
_bus.subscribe<Dictionary<SecurityKey, SecurityMD>>(SecuritiesTag).ObserveOnDispatcher().Subscribe(s => _securities = s),
|
||||
_bus.subscribe<SyntheticSecuritiesMessage>(SyntheticSecuritiesTag).ObserveOnDispatcher().Subscribe(ssm => _synthetic_strategy_map = ssm.data),
|
||||
_bus.subscribe<ShowMarketViewMessage>(ShowMarketViewTag).ObserveOnDispatcher().Subscribe(show_market_view),
|
||||
_bus.subscribe<ShowSpreadMatrixMessage>(ShowSpreadMatrixTag).ObserveOnDispatcher().Subscribe(show_spread_matrix),
|
||||
_bus.subscribe<ShowLadderMessage>(ShowLadderTag).ObserveOnDispatcher().Subscribe(show_ladder),
|
||||
_bus.subscribe<ShowOrderTicketMessage>(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(msg => show_order_ticket(msg.data, false)),
|
||||
_bus.subscribe<ShowOrderModifyMessage>(ShowOrderModifyTag).ObserveOnDispatcher().Subscribe(msg => show_order_ticket(msg.data, true)),
|
||||
_bus.subscribe<ShowLinkedLadderMessage>(ShowLadderTag).ObserveOnDispatcher().Subscribe(show_linked_ladder),
|
||||
_bus.subscribe<ShowOrderModifyMessage>(ShowOrderModifyTag).ObserveOnDispatcher().Subscribe(show_order_modify),
|
||||
_bus.subscribe<ShowOrderTicketMessage>(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_order_ticket),
|
||||
_bus.subscribe<ShowLinkedOrderTicketMessage>(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_linked_order_ticket),
|
||||
_bus.subscribe<ShowSyntheticCreateMessage>(ShowSyntheticCreateTag).ObserveOnDispatcher().Subscribe(show_synthetic_create_editor),
|
||||
_bus.subscribe<ShowSyntheticStrategyMessage>(ShowSyntheticStrategyTag).ObserveOnDispatcher().Subscribe(show_synthetic_strategy_editor)
|
||||
);
|
||||
@@ -43,12 +44,19 @@ namespace mbts.spark
|
||||
private readonly IWindowManager _wm;
|
||||
private readonly IDisposable _dispose;
|
||||
private IDictionary<SecurityKey, SecurityMD> _securities = new Dictionary<SecurityKey, SecurityMD>();
|
||||
private IDictionary<SecurityKey, SyntheticExecutionStrategy> _synthetic_strategy_map = new Dictionary<SecurityKey, SyntheticExecutionStrategy>();
|
||||
private IDictionary<SecurityKey, SyntheticExecutionStrategy> _synthetic_strategy_map = new Dictionary<SecurityKey, SyntheticExecutionStrategy>();
|
||||
|
||||
public int priority => 2;
|
||||
public string name => "Market";
|
||||
public ImageSource icon => Icons.Date;
|
||||
public IShellWindow launch_ui => new LaunchMenu { DataContext = new LaunchMenuVM(new MarketViewMenuItem(_bus), new SpreadMatrixMenuItem(_bus), new LadderMenuItem(_bus), new OrderTicketMenuItem(_bus), MenuItemFactory.Create("Security Browser...", "sb", Icons.Coins, execute:show_security_browser)) };
|
||||
public IShellWindow launch_ui => new LaunchMenu {
|
||||
DataContext = new LaunchMenuVM(
|
||||
new MarketViewMenuItem(_bus),
|
||||
new SpreadMatrixMenuItem(_bus),
|
||||
new LadderMenuItem(_bus),
|
||||
new OrderTicketMenuItem(new OrdersModel(_bus)),
|
||||
MenuItemFactory.Create("Security Browser...", "sb", Icons.Coins, execute: show_security_browser))
|
||||
};
|
||||
public void load_state(Stream state = null) { }
|
||||
public void get_state(Stream save_here) { }
|
||||
public async Task<IShellWindow> create(Stream load_stream) {
|
||||
@@ -59,7 +67,9 @@ namespace mbts.spark
|
||||
await Wait.until_true(() => _securities != null && _securities.ContainsKey(key), TimeSpan.FromSeconds(15));
|
||||
if (_securities != null && _securities.TryGetValue((uint)header.version, out SecurityMD md)) return create_ladder_window(md);
|
||||
else break;
|
||||
case MarketViewVM.SAVE_NAME: if (try_deserialize(load_stream, out MarketViewVM.StartupData data)) return new MarketViewWindow(this, _bus, data); break;
|
||||
case MarketViewVM.SAVE_NAME:
|
||||
if (try_deserialize(load_stream, out MarketViewVM.StartupData data)) return create_market_view(data.securities.Select(deserialize<Security>).ToList(), data.sorting_criteria);
|
||||
else break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -67,28 +77,75 @@ namespace mbts.spark
|
||||
public void start() { }
|
||||
public void Dispose() { _dispose.Dispose(); }
|
||||
|
||||
#region SecurityBrowser
|
||||
private void show_security_browser() { new SecurityBrowser { DataContext = new SecurityBrowserVM(_bus) }.Show(-200, -300, true); }
|
||||
private void show_market_view(ShowMarketViewMessage msg) { _wm.Windows.Add(new MarketViewWindow(this, _bus, msg.data)); }
|
||||
#endregion
|
||||
|
||||
#region MarketView
|
||||
private void show_market_view(ShowMarketViewMessage msg) { _wm.Windows.Add(create_market_view(msg.data, null)); }
|
||||
private IShellWindow create_market_view(IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting) {
|
||||
var vm = new MarketViewVM(_bus, securities, sorting);
|
||||
var view = new MarketViewView { DataContext = vm };
|
||||
const double two_thirds = 2.0 / 3.0;
|
||||
const double title_panel_height = 32.0, col_header_height = 26 + two_thirds + 10.0;
|
||||
double row_height = vm.row_height + two_thirds;
|
||||
view.Height = Math.Min(title_panel_height + col_header_height + securities.Count * row_height, System.Windows.SystemParameters.WorkArea.Height);
|
||||
view.Width = 720;
|
||||
return ShellWindow.create(this, "Market View", view, stream => {
|
||||
serialize(stream, new ShellSerializationHeader { name = MarketViewVM.SAVE_NAME, version = MarketViewVM.VERSION });
|
||||
serialize(stream, vm.get_startup_data());
|
||||
}, Icons.Sheets);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SpreadMatrix
|
||||
private void show_spread_matrix(ShowSpreadMatrixMessage msg) { }
|
||||
private void show_order_ticket(Order order, bool is_modify) {
|
||||
if (_securities.TryGetValue(order.Security.Id, out SecurityMD smd)) {
|
||||
if (string.IsNullOrEmpty(order.User)) order.User = UserConfigurationHelper.UserName;
|
||||
var vm = new OrderTicketVM(order, new OrdersModel(_bus), smd, _get_ladder_settings());
|
||||
(is_modify ? (Window)new OrderModificationDialog { DataContext = vm } : new OrderTicket { DataContext = vm }).Show(-200, -160, true);
|
||||
#endregion
|
||||
|
||||
#region OrderTicket
|
||||
private void show_order_modify(ShowOrderModifyMessage msg) { show_order_ticket(msg.data, true); }
|
||||
private void show_order_ticket(ShowOrderTicketMessage msg) { show_order_ticket(msg.data, false); }
|
||||
private void show_order_ticket(IReadOnlyCollection<Order> orders, bool is_modify) {
|
||||
foreach (var o in orders) {
|
||||
if (_securities.TryGetValue(o.Security.Id, out SecurityMD smd)) {
|
||||
if (string.IsNullOrEmpty(o.User)) o.User = ImportedResources.UserName;
|
||||
var vm = new OrderTicketVM(new OrdersModel(_bus), o, _get_ladder_settings());
|
||||
(is_modify ? (Window)new OrderModificationDialog { DataContext = vm } : new OrderTicket { DataContext = vm }).Show(-200, -160, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void show_linked_order_ticket(ShowLinkedOrderTicketMessage msg) {
|
||||
new OrderTicket {
|
||||
DataContext = new OrderTicketVM(new OrdersModel(_bus), msg.data, _get_ladder_settings())
|
||||
}.Show(-200, -160, true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Ladder
|
||||
private void show_ladder(ShowLadderMessage msg) { foreach (var s in msg.data) show_ladder(s); }
|
||||
private void show_ladder(ShowLadderMessage msg) { foreach (var s in msg.data) if (_securities.TryGetValue(s.Id, out SecurityMD smd)) show_ladder(smd); }
|
||||
private void show_ladder(SecurityMD sec) { _wm.Windows.Add(create_ladder_window(sec)); }
|
||||
private async void show_linked_ladder(ShowLinkedLadderMessage msg) { _wm.Windows.Add(await create_ladder_window(msg.data)); }
|
||||
private IShellWindow create_ladder_window(SecurityMD md) {
|
||||
var model = new LadderModel(md, new OrdersModel(_bus));
|
||||
var vm = new LadderVM(model, _get_ladder_settings());
|
||||
var view = new LadderView(vm);
|
||||
var window = ShellWindow.create(this, md.security.ToString(), view, vm.save_state, icon: Icons.Logo);
|
||||
return window;
|
||||
var view = new LadderView { DataContext = vm };
|
||||
return ShellWindow.create(this, md.security.ToString(null), view, vm, vm.save_state, Icons.Depth);
|
||||
}
|
||||
private IObservable<LadderSettings> _get_ladder_settings() { return Observable.Return(new LadderSettings()); }
|
||||
private async Task<IShellWindow> create_ladder_window(IObservable<SecurityMD> security_md) {
|
||||
var first_smd = await security_md.FirstAsync();
|
||||
OrdersModel om = new OrdersModel(_bus);
|
||||
LadderVM vm = new LadderVM(new LadderModel(first_smd, om), _get_ladder_settings());
|
||||
LadderView view = new LadderView { DataContext = vm };
|
||||
IDisposable sub = null;
|
||||
var sw = ShellWindow.create(this, first_smd.security.ToString(null), view, Disposable.Create(() => { sub?.Dispose(); vm.Dispose(); }), state => vm.save_state(state), Icons.Depth);
|
||||
sub = security_md.ObserveOnDispatcher().Subscribe(smd => {
|
||||
vm.Dispose();
|
||||
view.DataContext = vm = new LadderVM(new LadderModel(smd, om), _get_ladder_settings());
|
||||
sw.Title = smd.security.ToString(null);
|
||||
});
|
||||
return sw;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Synthentic
|
||||
|
||||
@@ -13,13 +13,15 @@ namespace mbts.spark.menu_items
|
||||
|
||||
private readonly IBus _bus;
|
||||
|
||||
public string display_name => "Audit Logs";
|
||||
public string display_name => "Audit Logs...";
|
||||
public int priority => 3;
|
||||
public ImageSource icon => Icons.DataCopy;
|
||||
public string sectional_id => null;
|
||||
public string sectional_id => MenuItemSections.OrderPassiveWindow;
|
||||
public void execute() { _bus.post(SparkTags.ShowAuditLogsTag, new SparkBusData.ShowAuditLogsMessage()); }
|
||||
public bool can_execute() { return true; }
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class CancelOrderRootMenuItem : OrderActionMenuItemRoot
|
||||
{
|
||||
public CancelOrderRootMenuItem(OrdersModel model, IReadOnlyCollection<Order> orders) : base(orders) {
|
||||
_model = model;
|
||||
}
|
||||
private OrdersModel _model;
|
||||
public override string display_name => "Cancel Order";
|
||||
public override ImageSource icon => Icons.CancelOrders;
|
||||
protected override OrderMenuActionItem create_item(Order order) { return new CancelOrderMenuItem(_model, order); }
|
||||
|
||||
internal class CancelOrderMenuItem : OrderMenuActionItem {
|
||||
public CancelOrderMenuItem(OrdersModel model, Order order) : base(order, model.get_metadata(order)) {
|
||||
_model = model;
|
||||
_order = order;
|
||||
}
|
||||
|
||||
private readonly OrdersModel _model;
|
||||
private readonly Order _order;
|
||||
public override void execute() { _model.cancel_order(_order.Id); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,46 @@ using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using bts.spark;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class CancelOrdersMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
public CancelOrdersMenuItem(IBus bus) {
|
||||
_model = new OrdersModel(bus);
|
||||
public CancelOrdersMenuItem(OrdersModel model) {
|
||||
_model = model;
|
||||
_sub = _model.on_orderbook().ObserveOnDispatcher().Subscribe(ob => _orderbook = ob);
|
||||
}
|
||||
|
||||
private readonly IDisposable _sub;
|
||||
private readonly OrdersModel _model;
|
||||
private IOrderBook _orderbook = new OrderBook();
|
||||
|
||||
public string display_name => "Cancel Orders";
|
||||
public virtual string display_name => "Cancel All Orders";
|
||||
public int priority => 0;
|
||||
public ImageSource icon => Icons.CancelOrders;
|
||||
public string sectional_id => null;
|
||||
public void execute(IReadOnlyList<Security> securities) { _model.cancel_security_orders(securities.Select(s => s.Id), true, true); }
|
||||
public bool can_execute(IReadOnlyList<Security> securities) { return securities.Any(); }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.OrderOp;
|
||||
public void execute(IReadOnlyCollection<Security> securities) {
|
||||
var orders = _orderbook.get_all_orders().Select(e => e.order()).Where(o => securities.Contains(o.Security) && filter(o)).Select(o => o.Id).ToList();
|
||||
_model.cancel_order(orders);
|
||||
}
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Any(); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
protected virtual bool filter(Order order) { return true; }
|
||||
public void Dispose() { _sub.Dispose(); }
|
||||
}
|
||||
|
||||
internal class CancelBuyOrdersMenuItem : CancelOrdersMenuItem {
|
||||
public CancelBuyOrdersMenuItem(OrdersModel model) : base(model) { }
|
||||
public override string display_name => "Cancel Buy Orders";
|
||||
protected override bool filter(Order order) { return order.Side == BuySell.Buy; }
|
||||
}
|
||||
|
||||
internal class CancelSellOrdersMenuItem : CancelOrdersMenuItem {
|
||||
public CancelSellOrdersMenuItem(OrdersModel model) : base(model) { }
|
||||
protected override bool filter(Order order) { return order.Side == BuySell.Sell; }
|
||||
public override string display_name => "Cancel Sell Orders";
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,15 @@ namespace mbts.spark.menu_items
|
||||
|
||||
private readonly IBus _bus;
|
||||
|
||||
public string display_name => "Fills";
|
||||
public string display_name => "Fills...";
|
||||
public int priority => 1;
|
||||
public ImageSource icon => Icons.Payment;
|
||||
public string sectional_id => null;
|
||||
public string sectional_id => MenuItemSections.OrderPassiveWindow;
|
||||
public void execute() { _bus.post(SparkTags.ShowFillsTag, new SparkBusData.ShowFillsMessage()); }
|
||||
public bool can_execute() { return true; }
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -11,31 +11,40 @@ namespace mbts.spark.menu_items
|
||||
int priority { get; }
|
||||
ImageSource icon { get; }
|
||||
string sectional_id { get; }
|
||||
event Action display_name_changed;
|
||||
}
|
||||
|
||||
public interface IMenuActionItem : IMenuItem
|
||||
public interface ICanExecuteChanged
|
||||
{
|
||||
event Action can_execute_changed;
|
||||
}
|
||||
|
||||
public interface IMenuActionItem : IMenuItem, ICanExecuteChanged
|
||||
{
|
||||
void execute();
|
||||
bool can_execute();
|
||||
event Action can_execute_changed;
|
||||
}
|
||||
|
||||
public interface IMenuSecuritiesActionItem : IMenuItem
|
||||
public interface IMenuSecuritiesActionItem : IMenuItem, ICanExecuteChanged
|
||||
{
|
||||
void execute(IReadOnlyList<Security> securities);
|
||||
bool can_execute(IReadOnlyList<Security> securities);
|
||||
event Action can_execute_changed;
|
||||
}
|
||||
|
||||
public interface IMenuSecurityActionItem : IMenuItem
|
||||
{
|
||||
bool can_execute(Security security);
|
||||
void execute(Security security);
|
||||
event Action can_execute_changed;
|
||||
void execute(IReadOnlyCollection<Security> securities);
|
||||
bool can_execute(IReadOnlyCollection<Security> securities);
|
||||
}
|
||||
|
||||
public interface IMenuGroupItem : IMenuItem
|
||||
{
|
||||
IEnumerable<IMenuItem> items { get; }
|
||||
}
|
||||
}
|
||||
|
||||
internal class MenuItemSections
|
||||
{
|
||||
public const string Window = nameof(Window),
|
||||
SecurityWindow = nameof(SecurityWindow),
|
||||
OrderActiveWindow = nameof(OrderActiveWindow),
|
||||
OrderPassiveWindow = nameof(OrderPassiveWindow),
|
||||
OrderOp = nameof(OrderOp),
|
||||
Action = nameof(Action),
|
||||
ModifySecuritySelection = nameof(ModifySecuritySelection),
|
||||
Misc = nameof(Misc);
|
||||
}
|
||||
}
|
||||
@@ -5,28 +5,46 @@ using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
using static mbts.spark.SparkBusData;
|
||||
using static mbts.spark.SparkTags;
|
||||
using SecurityKey = System.UInt32;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class LadderMenuItem : IMenuSecurityActionItem
|
||||
internal class LadderMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
public LadderMenuItem(IBus bus, string sectional_id = "rw") {
|
||||
this.sectional_id = sectional_id;
|
||||
public LadderMenuItem(IBus bus) {
|
||||
_bus = bus;
|
||||
_bus.subscribe<Dictionary<SecurityKey, SecurityMD>>(SecuritiesTag).ObserveOnDispatcher().Subscribe(s => { _securities = s; raise_can_execute_changed(); });
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private Dictionary<uint, SecurityMD> _securities = new Dictionary<SecurityKey, SecurityMD>();
|
||||
|
||||
public string display_name => "Ladder";
|
||||
public int priority => 2;
|
||||
public ImageSource icon => Icons.Depth;
|
||||
public string sectional_id { get; }
|
||||
public void execute(Security security) { if (_securities.TryGetValue(security.Id, out SecurityMD md)) _bus.post(ShowLadderTag, new ShowLadderMessage(md)); }
|
||||
public bool can_execute(Security security) { return security != null && _securities.ContainsKey(security.Id); }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.OrderActiveWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _bus.post(ShowLadderTag, new ShowLadderMessage(securities)); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Count > 0; }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
|
||||
internal class LinkedLadderMenuItem : IMenuActionItem
|
||||
{
|
||||
public LinkedLadderMenuItem(IBus bus, IObservable<SecurityMD> security_md) {
|
||||
_bus = bus;
|
||||
_security_md = security_md;
|
||||
}
|
||||
private readonly IBus _bus;
|
||||
private readonly IObservable<SecurityMD> _security_md;
|
||||
public string display_name => "Linked Ladder";
|
||||
public int priority => int.MaxValue;
|
||||
public ImageSource icon => Icons.Depth;
|
||||
public string sectional_id => MenuItemSections.OrderActiveWindow;
|
||||
public bool can_execute() { return true; }
|
||||
public void execute() { _bus.post(ShowLadderTag, new ShowLinkedLadderMessage(_security_md)); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,12 @@ namespace mbts.spark.menu_items
|
||||
public string display_name => "Market View";
|
||||
public int priority => 0;
|
||||
public ImageSource icon => Icons.Sheets;
|
||||
public string sectional_id => "ro";
|
||||
public void execute(IReadOnlyList<Security> securities) { _bus.post(SparkTags.ShowMarketViewTag, new SparkBusData.ShowMarketViewMessage(securities.ToList())); }
|
||||
public bool can_execute(IReadOnlyList<Security> securities) { return securities.Any(); }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.SecurityWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _bus.post(SparkTags.ShowMarketViewTag, new SparkBusData.ShowMarketViewMessage(securities.ToList())); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Any(); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace mbts.spark.menu_items
|
||||
return new AnonymousMenuActionItem(display_name, sectional_id, icon, priority, execute, can_execute);
|
||||
}
|
||||
|
||||
private class AnonymousMenuActionItem : IMenuActionItem, IDisposable {
|
||||
private class AnonymousMenuActionItem : IMenuActionItem, IDisposable
|
||||
{
|
||||
public AnonymousMenuActionItem(string display_name, string sectional_id, ImageSource icon, int priority, Action execute, Func<bool> can_execute, IDisposable dispose = null) {
|
||||
this.display_name = display_name;
|
||||
this.sectional_id = sectional_id;
|
||||
@@ -30,9 +31,10 @@ namespace mbts.spark.menu_items
|
||||
public int priority { get; }
|
||||
public void execute() { _execute(); }
|
||||
public bool can_execute() { return _can_execute(); }
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
|
||||
public event Action can_execute_changed;
|
||||
public event Action display_name_changed;
|
||||
public void Dispose() { _dispose?.Dispose(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using bts.api;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -7,25 +8,37 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
public class MenuItemVM : IDisposable
|
||||
public class MenuItemVM : DisposableViewModelBase
|
||||
{
|
||||
#region Static Factory
|
||||
public static IList<MenuItemVM> CreateMenu(ObservableCollection<Security> selected_securities, params IMenuItem[] menu_items) {
|
||||
return menu_items.Select(m => Create(m, selected_securities)).ToList();
|
||||
}
|
||||
|
||||
public static IList<MenuItemVM> CreateMenu(IReadOnlyCollection<Security> selected_securities, params IMenuItem[] menu_items) {
|
||||
return menu_items.Select(m => Create(m, selected_securities)).ToList();
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuItem model, ObservableCollection<Security> selected_securities) {
|
||||
var act_mi = model as IMenuActionItem;
|
||||
if (act_mi != null) return Create(act_mi);
|
||||
var sec_mi = model as IMenuSecurityActionItem;
|
||||
if (sec_mi != null) return Create(sec_mi, selected_securities);
|
||||
var secs_mi = model as IMenuSecuritiesActionItem;
|
||||
if (secs_mi != null) return Create(secs_mi, selected_securities);
|
||||
var grp_mi = model as IMenuGroupItem;
|
||||
if (grp_mi != null) return Create(grp_mi, selected_securities);
|
||||
throw new NotImplementedException("LaunchMenuVM cannot create vm for {0} ({1}).".fmt(model?.display_name ?? "unnamed", model?.GetType().ToString() ?? "null"));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuItem model, IReadOnlyCollection<Security> selected_securities) {
|
||||
var act_mi = model as IMenuActionItem;
|
||||
if (act_mi != null) return Create(act_mi);
|
||||
var secs_mi = model as IMenuSecuritiesActionItem;
|
||||
if (secs_mi != null) return Create(secs_mi, selected_securities);
|
||||
var grp_mi = model as IMenuGroupItem;
|
||||
@@ -34,44 +47,48 @@ namespace mbts.spark.menu_items
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuActionItem model) {
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, new DelegateCommand(model.execute, model.can_execute), dispose: model as IDisposable);
|
||||
return new MenuItemVM(_observe_display_name(model), model.sectional_id, model.icon, _hook_command(model, model.execute, model.can_execute), dispose: model as IDisposable);
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuSecurityActionItem model, Security selected_security) {
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, new DelegateCommand(() => model.execute(selected_security), () => model.can_execute(selected_security)), dispose: model as IDisposable);
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuSecurityActionItem model, IReadOnlyList<Security> selected_securities) {
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, new DelegateCommand(() => model.execute(selected_securities.SingleOrDefault()), () => selected_securities.Count == 1 && model.can_execute(selected_securities[0])), dispose: model as IDisposable);
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuSecurityActionItem model, ObservableCollection<Security> selected_securities) {
|
||||
var command = new DelegateCommand(() => model.execute(selected_securities.SingleOrDefault()), () => selected_securities.Count == 1 && model.can_execute(selected_securities[0]));
|
||||
IDisposable sub = selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged());
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, command, dispose: Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuSecuritiesActionItem model, IReadOnlyList<Security> selected_securities) {
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, new DelegateCommand(() => model.execute(selected_securities), () => model.can_execute(selected_securities)));
|
||||
public static MenuItemVM Create(IMenuSecuritiesActionItem model, IReadOnlyCollection<Security> selected_securities) {
|
||||
return new MenuItemVM(_observe_display_name(model), model.sectional_id, model.icon, _hook_command(model, () => model.execute(selected_securities), () => model.can_execute(selected_securities)));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuSecuritiesActionItem model, ObservableCollection<Security> selected_securities) {
|
||||
var command = new DelegateCommand(() => model.execute(selected_securities), () => model.can_execute(selected_securities));
|
||||
var command = _hook_command(model, () => model.execute(selected_securities), () => model.can_execute(selected_securities));
|
||||
IDisposable sub = selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged());
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, command, dispose: Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }));
|
||||
return new MenuItemVM(_observe_display_name(model), model.sectional_id, model.icon, command, dispose: Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuGroupItem model, ObservableCollection<Security> selected_securities) {
|
||||
return new MenuItemVM(model.display_name, model.sectional_id, model.icon, new DelegateCommand(() => { }, () => model.items.Any()), CreateMenu(selected_securities, model.items.ToArray()));
|
||||
return new MenuItemVM(_observe_display_name(model), model.sectional_id, model.icon, new DelegateCommand(() => { }, () => model.items.Any()), CreateMenu(selected_securities, model.items.ToArray()));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IMenuGroupItem model, IReadOnlyCollection<Security> selected_securities) {
|
||||
return new MenuItemVM(_observe_display_name(model), model.sectional_id, model.icon, new DelegateCommand(() => { }, () => model.items.Any()), CreateMenu(selected_securities, model.items.ToArray()));
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(IObservable<string> display_name, string sectional_id = null, ImageSource icon = null, ICommand command = null, IEnumerable<MenuItemVM> items = null) {
|
||||
return new MenuItemVM(display_name, sectional_id, icon, command, items);
|
||||
}
|
||||
|
||||
public static MenuItemVM Create(string display_name, string sectional_id=null, ImageSource icon=null, ICommand command=null, IEnumerable<MenuItemVM> items = null) {
|
||||
return new MenuItemVM(display_name, sectional_id, icon, command, items);
|
||||
return new MenuItemVM(Observable.Return(display_name), sectional_id, icon, command, items);
|
||||
}
|
||||
|
||||
private static IRaiseCanExecuteChangedCommand _hook_command(ICanExecuteChanged model, Action execute, Func<bool> can_execute=null) {
|
||||
var command = new DelegateCommand(execute, can_execute);
|
||||
model.can_execute_changed += command.RaiseCanExecuteChanged;
|
||||
return command;
|
||||
}
|
||||
|
||||
private static IObservable<string> _observe_display_name(IMenuItem model) {
|
||||
return Observable.FromEvent(cb => model.display_name_changed += cb, cb => model.display_name_changed -= cb).Select(_ => model.display_name).StartWith(model.display_name);
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected MenuItemVM(string display_name, string sectional_id=null, ImageSource icon=null, ICommand command=null, IEnumerable<MenuItemVM> items=null, IDisposable dispose=null) {
|
||||
this.display_name = display_name;
|
||||
|
||||
protected MenuItemVM(IObservable<string> display_name, string sectional_id=null, ImageSource icon=null, ICommand command=null, IEnumerable<MenuItemVM> items=null, IDisposable dispose=null) {
|
||||
_display_name = backing(nameof(display_name), display_name, null);
|
||||
this.sectional_id = sectional_id;
|
||||
this.icon = icon;
|
||||
this.command = command ?? Commands.Empty;
|
||||
@@ -81,20 +98,15 @@ namespace mbts.spark.menu_items
|
||||
_dispose = dispose;
|
||||
}
|
||||
|
||||
private IDisposable _dispose;
|
||||
private IList<MenuItemVM> _items;
|
||||
private readonly Property<string> _display_name;
|
||||
|
||||
public string display_name { get; }
|
||||
public string display_name { get => _display_name.Value; set => _display_name.set(value); }
|
||||
public string sectional_id { get; }
|
||||
public ImageSource icon { get; }
|
||||
public ICommand command { get; }
|
||||
public ICollectionView items_view { get; }
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
Disposable.dispose(ref _dispose);
|
||||
Disposable.dispose(_items);
|
||||
}
|
||||
protected override void Dispose(bool disposing) { Disposable.dispose(_items); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class ModifyOrderRootMenuItem : OrderActionMenuItemRoot
|
||||
{
|
||||
public ModifyOrderRootMenuItem(OrdersModel model, IReadOnlyCollection<Order> orders) : base(orders) {
|
||||
_model = model;
|
||||
}
|
||||
private OrdersModel _model;
|
||||
public override string display_name => "Modify Order";
|
||||
public override ImageSource icon => Icons.Import;
|
||||
protected override OrderMenuActionItem create_item(Order order) { return new ModifyOrderMenuItem(_model, order); }
|
||||
|
||||
internal class ModifyOrderMenuItem : OrderMenuActionItem {
|
||||
public ModifyOrderMenuItem(OrdersModel model, Order order) : base(order, model.get_metadata(order)) {
|
||||
_model = model;
|
||||
_order = order;
|
||||
}
|
||||
|
||||
private readonly OrdersModel _model;
|
||||
private readonly Order _order;
|
||||
public override void execute() { _model.show_order_modify(_order); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using bts.api;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class ModifySecuritySelectionMenuItem : IMenuActionItem
|
||||
{
|
||||
public ModifySecuritySelectionMenuItem(IReadOnlyCollection<Security> securities, Action<IEnumerable<Security>> commit, string dialog_title="Select Securities") {
|
||||
_securities = securities;
|
||||
_commit = commit;
|
||||
_dialog_title = dialog_title;
|
||||
}
|
||||
private readonly string _dialog_title;
|
||||
private readonly IReadOnlyCollection<Security> _securities;
|
||||
private readonly Action<IEnumerable<Security>> _commit;
|
||||
public string display_name => "Add/Remove Securities";
|
||||
public int priority => int.MinValue;
|
||||
public ImageSource icon => Icons.Coins;
|
||||
public string sectional_id => MenuItemSections.ModifySecuritySelection;
|
||||
public bool can_execute() { return true; }
|
||||
private IDisposable _dialog;
|
||||
public void execute() {
|
||||
Disposable.dispose(ref _dialog);
|
||||
_dialog = new SecuritySelectorDialog { DataContext = new SecuritySelectorDialogVM(_dialog_title, _securities, _commit) }.Show(-12, -30, true);
|
||||
}
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Windows.Media;
|
||||
using static mbts.spark.SparkBusData;
|
||||
using static mbts.spark.SparkTags;
|
||||
using static mbts.spark.menu_items.MenuItemFactory;
|
||||
using System;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
@@ -12,16 +13,18 @@ namespace mbts.spark.menu_items
|
||||
{
|
||||
public OrderBookMenuItem(IBus bus) {
|
||||
items = new [] {
|
||||
Create("All Orders...", execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage())),
|
||||
Create("Active Orders...", execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage())),
|
||||
Create("Spreader Orders...", execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage()))
|
||||
Create("All Orders...", "a", Icons.Book, execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage())),
|
||||
Create("Active Orders...", "b", Icons.Book, execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage())),
|
||||
Create("Spreader Orders...", "b", Icons.Book, execute:() => bus.post(ShowOrderBookTag, new ShowOrderBookMessage()))
|
||||
};
|
||||
}
|
||||
|
||||
public string display_name => "Order Book";
|
||||
public int priority => 0;
|
||||
public ImageSource icon => Icons.Orders;
|
||||
public string sectional_id => null;
|
||||
public ImageSource icon => Icons.Book;
|
||||
public string sectional_id => MenuItemSections.OrderPassiveWindow;
|
||||
public IEnumerable<IMenuItem> items { get; }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal abstract class OrderActionMenuItemRoot : IMenuGroupItem
|
||||
{
|
||||
public OrderActionMenuItemRoot(IReadOnlyCollection<Order> orders) {
|
||||
_orders = orders;
|
||||
_items = new Lazy<IReadOnlyCollection<OrderMenuActionItem>>(() => _orders.Select(create_item).ToList());
|
||||
}
|
||||
private readonly IReadOnlyCollection<Order> _orders;
|
||||
private readonly Lazy<IReadOnlyCollection<OrderMenuActionItem>> _items;
|
||||
public abstract string display_name { get; }
|
||||
public abstract ImageSource icon { get; }
|
||||
public int priority => int.MaxValue;
|
||||
public string sectional_id => MenuItemSections.OrderOp;
|
||||
public IEnumerable<IMenuItem> items => _items.Value;
|
||||
public event Action display_name_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
protected abstract OrderMenuActionItem create_item(Order order);
|
||||
}
|
||||
|
||||
internal abstract class OrderMenuActionItem : IMenuActionItem
|
||||
{
|
||||
public OrderMenuActionItem(Order order, OrderMetadata metadata) {
|
||||
_order = order;
|
||||
_metadata = metadata;
|
||||
}
|
||||
private readonly Order _order;
|
||||
private readonly OrderMetadata _metadata;
|
||||
public string display_name => _order.summary();
|
||||
public int priority => int.MaxValue;
|
||||
public ImageSource icon => OrderIconFactory.Create(_metadata, _order.Side);
|
||||
public string sectional_id => MenuItemSections.OrderOp;
|
||||
public abstract void execute();
|
||||
public bool can_execute() { return true; }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
}
|
||||
}
|
||||
@@ -3,31 +3,56 @@ using bts.spark;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Media;
|
||||
using static mbts.spark.SparkBusData;
|
||||
using static mbts.spark.SparkTags;
|
||||
using SecurityKey = System.UInt32;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class OrderTicketMenuItem : IMenuSecurityActionItem
|
||||
internal class OrderTicketMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
public OrderTicketMenuItem(IBus bus, string sectional_id = "rw") {
|
||||
this.sectional_id = sectional_id;
|
||||
_bus = bus;
|
||||
_bus.subscribe<Dictionary<SecurityKey, SecurityMD>>(SecuritiesTag).ObserveOnDispatcher().Subscribe(s => _securities = s);
|
||||
public OrderTicketMenuItem(OrdersModel model, Func<Security, Order> order_factory=null) {
|
||||
_model = model;
|
||||
_order_factory = order_factory ?? new Func<Security, Order>(s => new Order { Security = s, LimitOrder = new LimitOrder(), Size = 1 });
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private Dictionary<uint, SecurityMD> _securities = new Dictionary<SecurityKey, SecurityMD>();
|
||||
|
||||
private readonly OrdersModel _model;
|
||||
private readonly Func<Security, Order> _order_factory;
|
||||
|
||||
public string display_name => "Order Ticket";
|
||||
public int priority => 3;
|
||||
public ImageSource icon => Icons.Ticket;
|
||||
public string sectional_id { get; }
|
||||
public void execute(Security security) { _bus.post(ShowOrderTicketTag, new ShowOrderTicketMessage(new Order { Security = security, LimitOrder = new LimitOrder() })); }
|
||||
public bool can_execute(Security security) { return security != null; }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.OrderActiveWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _model.show_order_ticket(securities.Select(_order_factory).ToList()); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Count > 0; }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
|
||||
internal class LinkedOrderTicketMenuItem : IMenuActionItem
|
||||
{
|
||||
public LinkedOrderTicketMenuItem(IBus bus, IObservable<Security> security, Func<Security, Order> order_factory) : this(bus, security.Select(order_factory).Where(o => o != null)) { }
|
||||
public LinkedOrderTicketMenuItem(IBus bus, IObservable<Order> order) {
|
||||
_bus = bus;
|
||||
_order = order;
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly IObservable<Order> _order;
|
||||
|
||||
public string display_name => "Linked Order Ticket";
|
||||
public int priority => int.MaxValue;
|
||||
public ImageSource icon => Icons.Ticket;
|
||||
public string sectional_id => MenuItemSections.OrderActiveWindow;
|
||||
public bool can_execute() { return true; }
|
||||
public void execute() { _bus.post(ShowOrderTicketTag, new ShowLinkedOrderTicketMessage(_order)); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,8 @@ using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
[Export(nameof(TradesModule), typeof(IMenuItem))]
|
||||
internal class PositionsMenuItem : IMenuActionItem
|
||||
{
|
||||
[ImportingConstructor]
|
||||
public PositionsMenuItem(IBus bus) {
|
||||
_bus = bus;
|
||||
}
|
||||
@@ -19,10 +17,12 @@ namespace mbts.spark.menu_items
|
||||
public string display_name => "Positions/PnL...";
|
||||
public int priority => 3;
|
||||
public ImageSource icon => Icons.Accounting;
|
||||
public string sectional_id => nameof(PositionsMenuItem);
|
||||
public string sectional_id => MenuItemSections.Window;
|
||||
public void execute() { _bus.post(SparkTags.ShowPositionsTag, new SparkBusData.ShowPositionsMessage()); }
|
||||
public bool can_execute() { return true; }
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class SpreadMatrixMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
public SpreadMatrixMenuItem(IBus bus, string sectional_id = "rw") {
|
||||
this.sectional_id = sectional_id;
|
||||
public SpreadMatrixMenuItem(IBus bus) {
|
||||
_bus = bus;
|
||||
}
|
||||
|
||||
@@ -19,10 +18,12 @@ namespace mbts.spark.menu_items
|
||||
public string display_name => "Spread Matrix";
|
||||
public int priority => 1;
|
||||
public ImageSource icon => Icons.Cube3d;
|
||||
public string sectional_id { get; }
|
||||
public void execute(IReadOnlyList<Security> securities) { _bus.post(SparkTags.ShowSpreadMatrixTag, new SparkBusData.ShowSpreadMatrixMessage(securities.ToList())); }
|
||||
public bool can_execute(IReadOnlyList<Security> securities) { return securities.Any(); }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.SecurityWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _bus.post(SparkTags.ShowSpreadMatrixTag, new SparkBusData.ShowSpreadMatrixMessage(securities.ToList())); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Any(); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using static bts.api.Security;
|
||||
@@ -13,22 +12,23 @@ namespace mbts.spark.menu_items
|
||||
{
|
||||
internal class SyntheticCreateMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
[ImportingConstructor]
|
||||
public SyntheticCreateMenuItem(IBus bus) {
|
||||
_bus = bus;
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
|
||||
public string display_name => "Create Synthetic";
|
||||
public string display_name => "Create Synthetic...";
|
||||
public int priority => 2;
|
||||
public ImageSource icon => Icons.Cube3d;
|
||||
public string sectional_id => null;
|
||||
public void execute(IReadOnlyList<Security> securities) { _bus.post(ShowSyntheticCreateTag, new ShowSyntheticCreateMessage(securities)); }
|
||||
public bool can_execute(IReadOnlyList<Security> securities) {
|
||||
public ImageSource icon => Icons.Tetris;
|
||||
public string sectional_id => MenuItemSections.SecurityWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _bus.post(ShowSyntheticCreateTag, new ShowSyntheticCreateMessage(securities)); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) {
|
||||
return securities.Count > 1 || (securities.Count == 1 && (securities.First().ContractCase == ContractOneofCase.Synthetic || securities.First().ContractCase == ContractOneofCase.Spread));
|
||||
}
|
||||
public event Action can_execute_changed;
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,13 @@ namespace mbts.spark.menu_items
|
||||
|
||||
public string display_name => "Execution Strategy...";
|
||||
public int priority => 1;
|
||||
public ImageSource icon => Icons.Target;
|
||||
public string sectional_id => null;
|
||||
public void execute(IReadOnlyList<Security> securities) { _bus.post(ShowSyntheticStrategyTag, new ShowSyntheticStrategyMessage(securities.First())); }
|
||||
public bool can_execute(IReadOnlyList<Security> securities) { return securities.Count == 1 && securities.First().ContractCase == Security.ContractOneofCase.Synthetic; }
|
||||
public event Action can_execute_changed;
|
||||
public ImageSource icon => Icons.Knight;
|
||||
public string sectional_id => MenuItemSections.SecurityWindow;
|
||||
public void execute(IReadOnlyCollection<Security> securities) { _bus.post(ShowSyntheticStrategyTag, new ShowSyntheticStrategyMessage(securities.First())); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> securities) { return securities.Count == 1 && securities.First().ContractCase == Security.ContractOneofCase.Synthetic; }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,13 @@
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark.menu_items
|
||||
{
|
||||
[Export(nameof(TradesModule), typeof(IMenuItem))]
|
||||
public class TimeAndSalesMenuItem : IMenuSecuritiesActionItem
|
||||
{
|
||||
[ImportingConstructor]
|
||||
public TimeAndSalesMenuItem(IBus bus) {
|
||||
_bus = bus;
|
||||
}
|
||||
@@ -21,10 +18,12 @@ namespace mbts.spark.menu_items
|
||||
public string display_name => "Time And Sales";
|
||||
public int priority => 4;
|
||||
public ImageSource icon => Icons.Clock;
|
||||
public string sectional_id => nameof(TimeAndSalesMenuItem);
|
||||
public void execute(IReadOnlyList<Security> ordered_selection) { _bus.post(SparkTags.ShowTimeAndSalesTag, new SparkBusData.ShowTimeAndSalesMessage(ordered_selection.ToList())); }
|
||||
public bool can_execute(IReadOnlyList<Security> ordered_selection) { return ordered_selection.Any(); }
|
||||
public event Action can_execute_changed;
|
||||
public string sectional_id => MenuItemSections.SecurityWindow;
|
||||
public void execute(IReadOnlyCollection<Security> ordered_selection) { _bus.post(SparkTags.ShowTimeAndSalesTag, new SparkBusData.ShowTimeAndSalesMessage(ordered_selection.ToList())); }
|
||||
public bool can_execute(IReadOnlyCollection<Security> ordered_selection) { return ordered_selection.Any(); }
|
||||
public void raise_display_name_changed() { display_name_changed?.Invoke(); }
|
||||
public void raise_can_execute_changed() { can_execute_changed?.Invoke(); }
|
||||
public event Action display_name_changed;
|
||||
public event Action can_execute_changed;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using bts.spark;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Linq;
|
||||
using bts.api;
|
||||
using mbts.ui;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
namespace mbts.spark
|
||||
{
|
||||
class OrderBookRowVM : ViewModelBase {
|
||||
readonly OrderBookVM _parent;
|
||||
readonly OrdersModel _model;
|
||||
@@ -35,6 +36,7 @@ namespace mbts.spark {
|
||||
|
||||
// need actual security prop for sorting
|
||||
public Security security => _order.order().Security;
|
||||
public OrderBookEntry order => _order;
|
||||
public string security_text {
|
||||
// indent child 3 spaces
|
||||
get => (is_child ? " " : "") + _order.order().Security.ToString("");
|
||||
@@ -68,7 +70,7 @@ namespace mbts.spark {
|
||||
set => ignore();
|
||||
}
|
||||
public string exchange {
|
||||
get => bts.security_model.Exchange.type.GLBX.ToString();
|
||||
get => string.Empty;
|
||||
set => ignore();
|
||||
}
|
||||
public Order.AlgoOrderTypeOneofCase algo_type {
|
||||
@@ -135,6 +137,7 @@ namespace mbts.spark {
|
||||
get => _order.ChildOrders.Count;
|
||||
set => ignore();
|
||||
}
|
||||
public bool is_selected { get; set; }
|
||||
|
||||
|
||||
public ContractSpecification contract_spec => _order.order().Security.ContractSpec;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using bts.spark;
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.spark.menu_items;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
@@ -16,7 +19,8 @@ namespace mbts.spark {
|
||||
public const string SAVE_NAME = "SparkOrderBookWindow";
|
||||
readonly OrdersModel _model;
|
||||
|
||||
public OrderBookVM(OrdersModel model, OrderBookState state, IObservable<OrderBookSettings> settings) {
|
||||
public OrderBookVM(IBus bus, OrdersModel model, OrderBookState state, IObservable<OrderBookSettings> settings) {
|
||||
_bus = bus;
|
||||
_model = model;
|
||||
|
||||
_order_books = new ObservableCollection<OrderBookEntry>();
|
||||
@@ -39,6 +43,7 @@ namespace mbts.spark {
|
||||
|
||||
_enable_calculator = backing(nameof(enable_calculator), false);
|
||||
_calculator_price = backing(nameof(calculator_price), double.NaN);
|
||||
_dispose = _context_menu = new ContextMenuVM(_context_menu_item_factory);
|
||||
}
|
||||
|
||||
public void get_state(System.IO.Stream output) {
|
||||
@@ -50,6 +55,7 @@ namespace mbts.spark {
|
||||
ProtoBuf.Serializer.SerializeWithLengthPrefix(output, new OrderBookState(), ProtoBuf.PrefixStyle.Fixed32);
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
ObservableCollection<OrderBookEntry> _order_books;
|
||||
OrderIDComparer _order_cmp = new OrderIDComparer();
|
||||
void orders_updated(IOrderBook order_book) {
|
||||
@@ -71,6 +77,23 @@ namespace mbts.spark {
|
||||
|
||||
OrderBookRowVM wrap(OrderBookEntry entry) => new OrderBookRowVM(this, _model, entry);
|
||||
|
||||
private IEnumerable<MenuItemVM> _context_menu_item_factory() {
|
||||
var selected_rows = this.orders.Where(vm => vm.is_selected && vm.is_visible).ToList();
|
||||
var orders = selected_rows.Select(vm => vm.order).ToList();
|
||||
var securities = new HashSet<Security>(selected_rows.Select(vm => vm.security));
|
||||
yield return MenuItemVM.Create(new LadderMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new OrderTicketMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new MarketViewMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SpreadMatrixMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticCreateMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticStrategyMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new ModifyOrderRootMenuItem(_model, selected_rows.Select(vm => vm.order.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrderRootMenuItem(_model, selected_rows.Where(vm => vm.order.status() != OrderStatus.Types.Status.Canceled).Select(vm => vm.order.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelBuyOrdersMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelSellOrdersMenuItem(_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrdersMenuItem(_model), securities);
|
||||
}
|
||||
|
||||
private ICommand top_bar_command(Action<IEnumerable<OrderID>> call) {
|
||||
return new DelegateCommand<IEnumerable<object>>(items => {
|
||||
call(items.Select(i => ((OrderBookRowVM)i).order_id).ToList());
|
||||
@@ -130,10 +153,13 @@ namespace mbts.spark {
|
||||
|
||||
#endregion
|
||||
|
||||
private ContextMenuVM _context_menu;
|
||||
public ContextMenuVM context_menu => _context_menu;
|
||||
public ObservableCollection<OrderBookRowVM> orders { get; }
|
||||
// Bind column visibility
|
||||
Property<OrderBookSettings> _settings;
|
||||
public OrderBookSettings settings => _settings.Value;
|
||||
public double row_height { get; set; } = 18;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,261 +1,275 @@
|
||||
<UserControl x:Class="mbts.spark.OrderBookView" x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:convert="clr-namespace:mbts.ui.converters"
|
||||
xmlns:controls="clr-namespace:mbts.ui.controls"
|
||||
xmlns:spark="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
TextElement.FontSize="11"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="1080">
|
||||
<UserControl.Resources>
|
||||
<convert:BooleanToVisibilityConverter x:Key="bool_to_vis" VisibilityForFalse="Visible" VisibilityForTrue="Hidden" />
|
||||
<convert:BooleanToObjectConverter x:Key="bool_to_play_pause" ValueForTrue="Play" ValueForFalse="Pause" />
|
||||
<uspcv:TickDisplayConverter x:Key="TickDisplayConverter"/>
|
||||
<uspcv:AlgoTypeDisplayBrushConverter x:Key="AlgoTypeDisplayBrushConverter"/>
|
||||
<uspcv:AlgoTypeDisplayTextConverter x:Key="AlgoTypeDisplayTextConverter"/>
|
||||
<Style x:Key="SideColorCodedTextElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding side}" Value="Sell">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AlgoTypeElement" TargetType="spark:AlgoTypeItem">
|
||||
<Setter Property="AlgoType" Value="{Binding algo_type}"/>
|
||||
<Setter Property="Metadata" Value="{Binding order_metadata}"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<!-- filters-->
|
||||
<RowDefinition Height="Auto" />
|
||||
<!-- row Immidiate Action bar -->
|
||||
<RowDefinition Height="Auto" />
|
||||
<!-- Table -->
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Immidiate change controls -->
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="Image" x:Key="disabled_image_style">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value="0.5" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style TargetType="Path" x:Key="disabled_path_style">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value="0.5" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Button Background="Red" Foreground="White" Padding="5,2" Margin="5" Command="{Binding cancel_command}" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">Cancel</Button>
|
||||
<Button Command="{Binding tick_up_command}" Focusable="False" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="Tick" Margin="5,0,5,0" />
|
||||
<Path Height="12" Width="12" Data="M6,2 L12,10 L0,10 z" Fill="Black" Margin="2" Style="{StaticResource disabled_path_style}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding tick_down_command}" Focusable="False" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="Tick" Margin="5,0,5,0" />
|
||||
<Path Height="12" Width="12" Data="M6,10 L12,2 L0,2 z" Fill="Black" Margin="2" Style="{StaticResource disabled_path_style}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding unpause_command}" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<Image Source="{StaticResource PlayIcon}" Width="12" Height="12" Margin="2" Style="{StaticResource disabled_image_style}" />
|
||||
</Button>
|
||||
<Button Command="{Binding pause_command}" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<Image Source="{StaticResource PauseIcon}" Width="12" Height="12" Margin="2" Style="{StaticResource disabled_image_style}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Commit button changes -->
|
||||
<GroupBox Header="Modify Order" Grid.Row="2" IsEnabled="{Binding enable_calculator}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Price" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<spark:PriceEntryControl
|
||||
Grid.Row="0" Grid.Column="1" Margin="2"
|
||||
ContractSpec="{Binding ElementName=_grid,Path=SelectedItem.contract_spec}" Value="{Binding calculator_price}" />
|
||||
<TextBlock Text="Size" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<controls:TickUpDownUInt
|
||||
Grid.Row="1" Grid.Column="1" Margin="2"
|
||||
Increment="1" Value="{Binding calculator.value}" />
|
||||
<ItemsControl ItemsSource="{Binding calculator.buttons}" Focusable="False" Grid.Row="2" Grid.ColumnSpan="2">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Focusable="False" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button Margin="2" Command="{Binding Path=DataContext.calculator.click, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding }" Content="{Binding }" HorizontalAlignment="Stretch" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="3" Grid.ColumnSpan="2" Height="40" Margin="2" HorizontalAlignment="Stretch" Command="{Binding commit_change_command}" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">Change</Button>
|
||||
<Button Grid.Row="4" Grid.ColumnSpan="2" Margin="2" HorizontalAlignment="Stretch" Command="{Binding calculator.click}" CommandParameter="0">Clear</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GridSplitter Width="2" Grid.Row="2" Grid.Column="0" />
|
||||
|
||||
<DataGrid Grid.Row="2" Grid.Column="1" x:Name="_grid" BorderThickness="0" GridLinesVisibility="None" CanUserSortColumns="True" ItemsSource="{Binding orders}" SelectionMode="Extended" SelectionUnit="FullRow" SelectionChanged="_grid_SelectionChanged">
|
||||
<DataGrid.Resources>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Fill" Color="#FF595959"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Stroke" Color="#FF262626"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Stroke" Color="#FF27C7F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Fill" Color="#FFCCEEFB"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Stroke" Color="#FF1CC4F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Fill" Color="#FF82DFFB"/>
|
||||
<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Fill" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Stroke" Color="#FF818181"/>
|
||||
<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="Visibility" Value="{Binding is_visible, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding is_child}" Value="true">
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ToggleButton x:Name="toggle_button" Command="{Binding toggle_command}" IsChecked="{Binding is_expanded}" ClickMode="Press" Style="{StaticResource ExpandCollapseToggleStyle}" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding is_parent}" Value="False">
|
||||
<Setter TargetName="toggle_button" Property="Visibility" Value="Hidden" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding time, StringFormat='M/d H:mm:ss'}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="User" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding user}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Account" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding account}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Exchange" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding exchange}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Security" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding security_text}" SortMemberPath="security" IsReadOnly="true" />
|
||||
<DataGridTemplateColumn IsReadOnly="True">
|
||||
<DataGridTemplateColumn.Header>
|
||||
<Image Source="{StaticResource PlayIcon}" Width="10" Height="10" Margin="3" />
|
||||
</DataGridTemplateColumn.Header>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Image Source="{StaticResource PauseIcon}" x:Name="img" Width="10" Height="10" Margin="3" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding is_paused}" Value="true">
|
||||
<Setter TargetName="img" Property="Source" Value="{StaticResource PlayIcon}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="TIF" Binding="{Binding tif}" IsReadOnly="True" />
|
||||
<spark:DataGridAlgoTypeColumn Header="Algo" ElementStyle="{StaticResource AlgoTypeElement}" SortMemberPath="algo_type" />
|
||||
<DataGridTextColumn Header="B/S" ElementStyle="{StaticResource SideColorCodedTextElement}" Binding="{Binding side}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Price" SortMemberPath="price">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" Binding="{Binding size}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Filled" Binding="{Binding filled}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Filled%" Binding="{Binding percent_filled, StringFormat=P1}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Avg Filled" Binding="{Binding average_price}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="O/C" Binding="{Binding oc}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Modifier" Binding="{Binding modifier}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Status" Binding="{Binding status}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Algo Params" Binding="{Binding algo_params}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="BTS Order" Binding="{Binding order_id.Id}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Exchange Order" Binding="{Binding exchange_id}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Broker" Binding="{Binding broker}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="# Children" Binding="{Binding num_children}" IsReadOnly="true" />
|
||||
<DataGridTemplateColumn Header="Fill Details" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<Hyperlink Command="{Binding details_command}">fills</Hyperlink>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
|
||||
</DataGrid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.spark.OrderBookView" x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:uc="clr-namespace:mbts.ui"
|
||||
xmlns:convert="clr-namespace:mbts.ui.converters"
|
||||
xmlns:controls="clr-namespace:mbts.ui.controls"
|
||||
xmlns:spark="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters"
|
||||
TextElement.FontSize="11"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="1080">
|
||||
<UserControl.Resources>
|
||||
<convert:BooleanToVisibilityConverter x:Key="bool_to_vis" VisibilityForFalse="Visible" VisibilityForTrue="Hidden" />
|
||||
<convert:BooleanToObjectConverter x:Key="bool_to_play_pause" ValueForTrue="Play" ValueForFalse="Pause" />
|
||||
<uspcv:TickDisplayConverter x:Key="TickDisplayConverter"/>
|
||||
<uspcv:AlgoTypeDisplayBrushConverter x:Key="AlgoTypeDisplayBrushConverter"/>
|
||||
<uspcv:AlgoTypeDisplayTextConverter x:Key="AlgoTypeDisplayTextConverter"/>
|
||||
<Style x:Key="SideColorCodedTextElement" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.bid}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding side}" Value="Sell">
|
||||
<Setter Property="Foreground" Value="{uc:BTSColor MarketData.ask}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AlgoTypeElement" TargetType="spark:AlgoTypeItem">
|
||||
<Setter Property="AlgoType" Value="{Binding algo_type}"/>
|
||||
<Setter Property="Metadata" Value="{Binding order_metadata}"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<!-- filters-->
|
||||
<RowDefinition Height="Auto" />
|
||||
<!-- row Immidiate Action bar -->
|
||||
<RowDefinition Height="Auto" />
|
||||
<!-- Table -->
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Immidiate change controls -->
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="Image" x:Key="disabled_image_style">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value="0.5" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style TargetType="Path" x:Key="disabled_path_style">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value="0.5" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Button Background="Red" Foreground="White" Padding="5,2" Margin="5" Command="{Binding cancel_command}" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">Cancel</Button>
|
||||
<Button Command="{Binding tick_up_command}" Focusable="False" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="Tick" Margin="5,0,5,0" />
|
||||
<Path Height="12" Width="12" Data="M6,2 L12,10 L0,10 z" Fill="Black" Margin="2" Style="{StaticResource disabled_path_style}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding tick_down_command}" Focusable="False" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="Tick" Margin="5,0,5,0" />
|
||||
<Path Height="12" Width="12" Data="M6,10 L12,2 L0,2 z" Fill="Black" Margin="2" Style="{StaticResource disabled_path_style}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding unpause_command}" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<Image Source="{StaticResource PlayIcon}" Width="12" Height="12" Margin="2" Style="{StaticResource disabled_image_style}" />
|
||||
</Button>
|
||||
<Button Command="{Binding pause_command}" Margin="5,2" VerticalAlignment="Center" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">
|
||||
<Image Source="{StaticResource PauseIcon}" Width="12" Height="12" Margin="2" Style="{StaticResource disabled_image_style}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Commit button changes -->
|
||||
<GroupBox Header="Modify Order" Grid.Row="2" IsEnabled="{Binding enable_calculator}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Price" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<spark:PriceEntryControl
|
||||
Grid.Row="0" Grid.Column="1" Margin="2"
|
||||
ContractSpec="{Binding ElementName=_grid,Path=SelectedItem.contract_spec}" Value="{Binding calculator_price}" />
|
||||
<TextBlock Text="Size" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" />
|
||||
<controls:TickUpDownUInt
|
||||
Grid.Row="1" Grid.Column="1" Margin="2"
|
||||
Increment="1" Value="{Binding calculator.value}" />
|
||||
<ItemsControl ItemsSource="{Binding calculator.buttons}" Focusable="False" Grid.Row="2" Grid.ColumnSpan="2">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Focusable="False" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Button Margin="2" Command="{Binding Path=DataContext.calculator.click, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding }" Content="{Binding }" HorizontalAlignment="Stretch" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="3" Grid.ColumnSpan="2" Height="40" Margin="2" HorizontalAlignment="Stretch" Command="{Binding commit_change_command}" CommandParameter="{Binding ElementName=_grid, Path=SelectedItems}">Change</Button>
|
||||
<Button Grid.Row="4" Grid.ColumnSpan="2" Margin="2" HorizontalAlignment="Stretch" Command="{Binding calculator.click}" CommandParameter="0">Clear</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<GridSplitter Width="2" Grid.Row="2" Grid.Column="0" />
|
||||
|
||||
<DataGrid Grid.Row="2" Grid.Column="1" x:Name="_grid" IsReadOnly="True" BorderThickness="0" GridLinesVisibility="None" CanUserSortColumns="True"
|
||||
ItemsSource="{Binding orders}" RowHeight="{Binding row_height}" SelectionMode="Extended" SelectionUnit="FullRow" SelectionChanged="_grid_SelectionChanged">
|
||||
<DataGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Resources/MenuResources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Fill" Color="#FF595959"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Stroke" Color="#FF262626"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Stroke" Color="#FF27C7F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Fill" Color="#FFCCEEFB"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Stroke" Color="#FF1CC4F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Fill" Color="#FF82DFFB"/>
|
||||
<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Fill" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Stroke" Color="#FF818181"/>
|
||||
<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding context_menu.items_view}" IsOpen="{Binding context_menu.is_open, Mode=OneWayToSource}" ItemContainerStyle="{StaticResource ContextMenuItemStyle}">
|
||||
<ContextMenu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
</ContextMenu.GroupStyle>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="IsSelected" Value="{Binding is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Setter Property="Visibility" Value="{Binding is_visible, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding is_child}" Value="true">
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ToggleButton x:Name="toggle_button" Command="{Binding toggle_command}" IsChecked="{Binding is_expanded}" ClickMode="Press" Style="{StaticResource ExpandCollapseToggleStyle}" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding is_parent}" Value="False">
|
||||
<Setter TargetName="toggle_button" Property="Visibility" Value="Hidden" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="Time" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding time, StringFormat='M/d H:mm:ss'}" />
|
||||
<DataGridTextColumn Header="User" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding user}" />
|
||||
<DataGridTextColumn Header="Account" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding account}" />
|
||||
<DataGridTextColumn Header="Exchange" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding exchange}" />
|
||||
<DataGridTextColumn Header="Security" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding security_text}" SortMemberPath="security" IsReadOnly="true" />
|
||||
<DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.Header>
|
||||
<Image Source="{StaticResource PlayIcon}" Width="10" Height="10" Margin="3" />
|
||||
</DataGridTemplateColumn.Header>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Image Source="{StaticResource PauseIcon}" x:Name="img" Width="10" Height="10" Margin="3" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding is_paused}" Value="true">
|
||||
<Setter TargetName="img" Property="Source" Value="{StaticResource PlayIcon}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="TIF" Binding="{Binding tif}" />
|
||||
<spark:DataGridAlgoTypeColumn Header="Algo" ElementStyle="{StaticResource AlgoTypeElement}" SortMemberPath="algo_type" />
|
||||
<DataGridTextColumn Header="B/S" ElementStyle="{StaticResource SideColorCodedTextElement}" Binding="{Binding side}" />
|
||||
<DataGridTextColumn Header="Price" SortMemberPath="price">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" Binding="{Binding size}" />
|
||||
<DataGridTextColumn Header="Filled" Binding="{Binding filled}" />
|
||||
<DataGridTextColumn Header="Filled%" Binding="{Binding percent_filled, StringFormat=P1}" />
|
||||
<DataGridTextColumn Header="Avg Filled" Binding="{Binding average_price}" />
|
||||
<DataGridTextColumn Header="O/C" Binding="{Binding oc}" />
|
||||
<DataGridTextColumn Header="Modifier" Binding="{Binding modifier}" />
|
||||
<DataGridTextColumn Header="Status" Binding="{Binding status}" />
|
||||
<DataGridTextColumn Header="Algo Params" Binding="{Binding algo_params}" />
|
||||
<DataGridTextColumn Header="BTS Order" Binding="{Binding order_id.Id}" />
|
||||
<DataGridTextColumn Header="Exchange Order" Binding="{Binding exchange_id}" />
|
||||
<DataGridTextColumn Header="Broker" Binding="{Binding broker}" />
|
||||
<DataGridTextColumn Header="# Children" Binding="{Binding num_children}" IsReadOnly="true" />
|
||||
<DataGridTemplateColumn Header="Fill Details">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<Hyperlink Command="{Binding details_command}">fills</Hyperlink>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
|
||||
</DataGrid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,156 +1,156 @@
|
||||
<UserControl x:Class="mbts.ui.spark.ExecutionStrategyEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls">
|
||||
<UserControl.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="2*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Working" IsEnabled="{Binding is_working}" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="8">
|
||||
<Grid DataContext="{Binding quote_params}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Hedge Ratio</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="2" Value="{Binding hedge_ratio}" HorizontalAlignment="Stretch" Increment="0.05" />
|
||||
</Grid>
|
||||
<CheckBox Grid.Row="2" Grid.ColumnSpan="3" IsChecked="{Binding pessimistic_hedge_pricing}" Content="Pessimistic Hedge Pricing" />
|
||||
<GroupBox Grid.Row="4" Grid.ColumnSpan="3" Header="Tick Range Requote" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="4" MinWidth="200">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ItemsControl ItemsSource="{Binding tick_range_requote_items}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Margin="0,3,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Style="{StaticResource RoundCloseButton}" Command="{Binding DataContext.remove_tick_range_requote_item, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
<TextBlock Grid.Column="1">within</TextBlock>
|
||||
<TextBox Grid.Column="2" Margin="2,0" MinWidth="20" Text="{Binding range, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="3">ticks, requote every</TextBlock>
|
||||
<TextBox Grid.Column="4" Margin="2,0" MinWidth="20" Text="{Binding sensitivity, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="5">ticks</TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="1" HorizontalAlignment="Left" Margin="14,6,0,0" Width="60" Command="{Binding add_tick_range_requote_item}">+</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Hedge" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding hedge_params}" Padding="8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Payup" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payup_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payup}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payup_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Payless" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payless_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payless}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payless_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="4" Header="Post" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding post_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_post_hedge}" />
|
||||
<TextBlock Grid.Row="2">Size</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding cross_size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding cross_ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.ui.spark.ExecutionStrategyEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls">
|
||||
<UserControl.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="2*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Working" IsEnabled="{Binding is_working}" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="8">
|
||||
<Grid DataContext="{Binding quote_params}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Hedge Ratio</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="2" Value="{Binding lean_quantity_ratio}" HorizontalAlignment="Stretch" Increment="0.05" />
|
||||
</Grid>
|
||||
<CheckBox Grid.Row="2" Grid.ColumnSpan="3" IsChecked="{Binding pessimistic_hedge_pricing}" Content="Pessimistic Hedge Pricing" />
|
||||
<GroupBox Grid.Row="4" Grid.ColumnSpan="3" Header="Tick Range Requote" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="4" MinWidth="200">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ItemsControl ItemsSource="{Binding tick_range_requote_items}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Margin="0,3,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Style="{StaticResource RoundCloseButton}" Command="{Binding DataContext.remove_tick_range_requote_item, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
<TextBlock Grid.Column="1">within</TextBlock>
|
||||
<TextBox Grid.Column="2" Margin="2,0" MinWidth="20" Text="{Binding range, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="3">ticks, requote every</TextBlock>
|
||||
<TextBox Grid.Column="4" Margin="2,0" MinWidth="20" Text="{Binding sensitivity, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="5">ticks</TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="1" HorizontalAlignment="Left" Margin="14,6,0,0" Width="60" Command="{Binding add_tick_range_requote_item}">+</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Hedge" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding hedge_params}" Padding="8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Payup" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payup_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payup}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payup_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Payless" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payless_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payless}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payless_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="4" Header="Post" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding post_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_post_hedge}" />
|
||||
<TextBlock Grid.Row="2">Size</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding cross_size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding cross_ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,212 +1,212 @@
|
||||
<Window x:Class="mbts.ui.spark.SyntheticEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:msys="clr-namespace:bts.api;assembly=bts_msys"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
Title="{Binding title}"
|
||||
Width="648"
|
||||
Height="617"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:BoundCommands.New="{Binding legs.AddItemCommand}"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
<SolidColorBrush x:Key="GridBorderBrush" Color="#688CAF" />
|
||||
<ControlTemplate x:Key="ChooseSecurityPromptTemplate" TargetType="ComboBox">
|
||||
<TextBlock FontStyle="Italic">None</TextBlock>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="SideComboBox" TargetType="ComboBox">
|
||||
<Setter Property="ItemsSource" Value="{u:EnumBindingSource msys:BuySell}" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
<Style x:Key="StrategyToggleSwitch" TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="19" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Ellipse x:Name="circle" Fill="White" HorizontalAlignment="Center" Height="19" Stroke="#FF333333" VerticalAlignment="Center" Width="19"/>
|
||||
<Path x:Name="arrow" Data="M1,1.5L4.5,5 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#FF333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="text" Grid.Column="1" Margin="4,0,0,0" Text="Execution Strategy" FontStyle="Italic" FontWeight="SemiBold" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M1,4.5L4.5,1 8,4.5"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFF3F9FF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF3C77DD"/>
|
||||
<Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFD9ECFF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFE6E6E6"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" TargetName="text" Value="Gray"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding security}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="n" Modifiers="Ctrl" Command="New" />
|
||||
</Window.InputBindings>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Name</TextBlock>
|
||||
<TextBox Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Text="{Binding name}" />
|
||||
<TextBlock Grid.Row="2">Tick</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Value="{Binding tick_size}" Increment="0.05" />
|
||||
</Grid>
|
||||
<Border Grid.Row="1" BorderBrush="{StaticResource GridBorderBrush}" Padding="10">
|
||||
<ScrollViewer VerticalAlignment="Stretch">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DataGrid Grid.ColumnSpan="2" IsReadOnly="{Binding is_new, Converter={StaticResource NotConverter}, Mode=OneTime}" u:DataGridBehavior.SingleClickEdit="{Binding is_new, Mode=OneTime}"
|
||||
HeadersVisibility="All" CanUserDeleteRows="{Binding is_new, Mode=OneTime}" SelectionUnit="FullRow" ItemsSource="{Binding legs}">
|
||||
<DataGrid.RowHeaderStyle>
|
||||
<Style TargetType="DataGridRowHeader">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRowHeader">
|
||||
<Button Command="{Binding DataContext.legs.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource RoundCloseButton}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowHeaderStyle>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="DetailsVisibility" Value="Visible"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRow">
|
||||
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid>
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<SelectiveScrollingGrid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</SelectiveScrollingGrid.RowDefinitions>
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Visibility="{Binding show_strategy, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
<DataGridDetailsPresenter Grid.Row="1" Margin="0,3">
|
||||
<SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
<Binding Path="AreRowDetailsFrozen" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<SelectiveScrollingOrientation>Vertical</SelectiveScrollingOrientation>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
</DataGridDetailsPresenter>
|
||||
<Rectangle Visibility="Collapsed" Grid.Row="2" Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect Direction="-315" />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
<DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
|
||||
<DataGridRowHeader.Visibility>
|
||||
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<DataGridHeadersVisibility>Row</DataGridHeadersVisibility>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</DataGridRowHeader.Visibility>
|
||||
</DataGridRowHeader>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.RowDetailsTemplate>
|
||||
<DataTemplate>
|
||||
<usp:ExecutionStrategyEditor />
|
||||
</DataTemplate>
|
||||
</DataGrid.RowDetailsTemplate>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Security" Width="120" IsReadOnly="True" Binding="{Binding security}"/>
|
||||
<DataGridComboBoxColumn Header="Side" Width="60" ElementStyle="{StaticResource SideComboBox}" EditingElementStyle="{StaticResource SideComboBox}" SelectedItemBinding="{Binding side}" />
|
||||
<c:DataGridEditableUIntColumn Header="Qty" Width="60" ValueBinding="{Binding quantity}" />
|
||||
<c:DataGridEditableDoubleColumn Header="Multiplier" Width="60" ValueBinding="{Binding multiplier}"/>
|
||||
<DataGridTemplateColumn Header="Working" Width="60" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox IsChecked="{Binding is_working, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ToggleButton IsChecked="{Binding show_strategy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource StrategyToggleSwitch}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Button Grid.Row="1" VerticalAlignment="Top" Width="60" Command="{Binding legs.AddItemCommand}" ToolTip="Add Leg (Ctrl+n)">+</Button>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<c:DialogSkirtOKCancel Grid.Row="2" IsOkDefault="False" OKCommand="{Binding commit}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
<Window x:Class="mbts.ui.spark.SyntheticEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:api="clr-namespace:bts.api"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
Title="{Binding title}"
|
||||
Width="648"
|
||||
Height="617"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:BoundCommands.New="{Binding legs.AddItemCommand}"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
<SolidColorBrush x:Key="GridBorderBrush" Color="#688CAF" />
|
||||
<ControlTemplate x:Key="ChooseSecurityPromptTemplate" TargetType="ComboBox">
|
||||
<TextBlock FontStyle="Italic">None</TextBlock>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="SideComboBox" TargetType="ComboBox">
|
||||
<Setter Property="ItemsSource" Value="{u:EnumBindingSource api:BuySell}" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
<Style x:Key="StrategyToggleSwitch" TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="19" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Ellipse x:Name="circle" Fill="White" HorizontalAlignment="Center" Height="19" Stroke="#FF333333" VerticalAlignment="Center" Width="19"/>
|
||||
<Path x:Name="arrow" Data="M1,1.5L4.5,5 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#FF333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="text" Grid.Column="1" Margin="4,0,0,0" Text="Execution Strategy" FontStyle="Italic" FontWeight="SemiBold" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M1,4.5L4.5,1 8,4.5"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFF3F9FF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF3C77DD"/>
|
||||
<Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFD9ECFF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFE6E6E6"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" TargetName="text" Value="Gray"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding security}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="n" Modifiers="Ctrl" Command="New" />
|
||||
</Window.InputBindings>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Name</TextBlock>
|
||||
<TextBox Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Text="{Binding name}" />
|
||||
<TextBlock Grid.Row="2">Tick</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Value="{Binding tick_size}" Increment="0.05" />
|
||||
</Grid>
|
||||
<Border Grid.Row="1" BorderBrush="{StaticResource GridBorderBrush}" Padding="10">
|
||||
<ScrollViewer VerticalAlignment="Stretch">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DataGrid Grid.ColumnSpan="2" IsReadOnly="{Binding is_new, Converter={StaticResource NotConverter}, Mode=OneTime}" u:DataGridBehavior.SingleClickEdit="{Binding is_new, Mode=OneTime}"
|
||||
HeadersVisibility="All" CanUserDeleteRows="{Binding is_new, Mode=OneTime}" SelectionUnit="FullRow" ItemsSource="{Binding legs}">
|
||||
<DataGrid.RowHeaderStyle>
|
||||
<Style TargetType="DataGridRowHeader">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRowHeader">
|
||||
<Button Command="{Binding DataContext.legs.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource RoundCloseButton}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowHeaderStyle>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="DetailsVisibility" Value="Visible"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRow">
|
||||
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid>
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<SelectiveScrollingGrid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</SelectiveScrollingGrid.RowDefinitions>
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Visibility="{Binding show_strategy, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
<DataGridDetailsPresenter Grid.Row="1" Margin="0,3">
|
||||
<SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
<Binding Path="AreRowDetailsFrozen" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<SelectiveScrollingOrientation>Vertical</SelectiveScrollingOrientation>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
</DataGridDetailsPresenter>
|
||||
<Rectangle Visibility="Collapsed" Grid.Row="2" Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect Direction="-315" />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
<DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
|
||||
<DataGridRowHeader.Visibility>
|
||||
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<DataGridHeadersVisibility>Row</DataGridHeadersVisibility>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</DataGridRowHeader.Visibility>
|
||||
</DataGridRowHeader>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.RowDetailsTemplate>
|
||||
<DataTemplate>
|
||||
<usp:ExecutionStrategyEditor />
|
||||
</DataTemplate>
|
||||
</DataGrid.RowDetailsTemplate>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Security" Width="120" IsReadOnly="True" Binding="{Binding security}"/>
|
||||
<DataGridComboBoxColumn Header="Side" Width="60" ElementStyle="{StaticResource SideComboBox}" EditingElementStyle="{StaticResource SideComboBox}" SelectedItemBinding="{Binding side}" />
|
||||
<c:DataGridEditableUIntColumn Header="Qty" Width="60" ValueBinding="{Binding quantity}" />
|
||||
<c:DataGridEditableDoubleColumn Header="Multiplier" Width="60" ValueBinding="{Binding multiplier}"/>
|
||||
<DataGridTemplateColumn Header="Working" Width="60" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox IsChecked="{Binding is_working, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ToggleButton IsChecked="{Binding show_strategy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource StrategyToggleSwitch}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Button Grid.Row="1" VerticalAlignment="Top" Width="60" Command="{Binding legs.AddItemCommand}" ToolTip="Add Leg (Ctrl+n)">+</Button>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<c:DialogSkirtOKCancel Grid.Row="2" IsOkDefault="False" OKCommand="{Binding commit}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -63,7 +63,7 @@ namespace mbts.spark
|
||||
|
||||
#region Defaults/Sanitization
|
||||
private static QuoteParams _default_quote_params() {
|
||||
var rv = new QuoteParams { HedgeRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
var rv = new QuoteParams { LeanQuantityRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
_sanitize_quote_params(rv);
|
||||
return rv;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace mbts.spark
|
||||
_sanitize_hedge_params(selp.HedgeParams);
|
||||
}
|
||||
private static void _sanitize_quote_params(QuoteParams quote_parms) {
|
||||
if (quote_parms == null) quote_parms = new QuoteParams { HedgeRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
if (quote_parms == null) quote_parms = new QuoteParams { LeanQuantityRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
if (quote_parms.TickRangeRequoteRules == null) quote_parms.TickRangeRequoteRules = new TickRangeRequoteRules();
|
||||
}
|
||||
private static void _sanitize_hedge_params(HedgeParams hedge_params) {
|
||||
@@ -102,20 +102,20 @@ namespace mbts.spark
|
||||
|
||||
public class QuoteParamsVM {
|
||||
public QuoteParamsVM(QuoteParams from) {
|
||||
hedge_ratio = from.HedgeRatio;
|
||||
lean_quantity_ratio = from.LeanQuantityRatio;
|
||||
pessimistic_hedge_pricing = from.PessimisticHedgePricing;
|
||||
foreach (var rr in from.TickRangeRequoteRules.TicksAwayToSensitivity) tick_range_requote_items.Add(new TickRangeRequoteVM(rr.Key, rr.Value));
|
||||
remove_tick_range_requote_item = new DelegateCommand<TickRangeRequoteVM>(item => tick_range_requote_items.Remove(item));
|
||||
add_tick_range_requote_item = new DelegateCommand(() => tick_range_requote_items.Add(new TickRangeRequoteVM(tick_range_requote_items.Count == 0 ? 0 : tick_range_requote_items.Select(trr => trr.range).Max(), 1)));
|
||||
}
|
||||
public double hedge_ratio { get; set; }
|
||||
public double lean_quantity_ratio { get; set; }
|
||||
public bool pessimistic_hedge_pricing { get; set; }
|
||||
public ObservableCollection<TickRangeRequoteVM> tick_range_requote_items { get; } = new ObservableCollection<TickRangeRequoteVM>();
|
||||
public ICommand remove_tick_range_requote_item { get; private set; }
|
||||
public ICommand add_tick_range_requote_item { get; private set; }
|
||||
|
||||
public QuoteParams get_params_obj(bool is_working) {
|
||||
var rv = new QuoteParams { PessimisticHedgePricing = pessimistic_hedge_pricing, HedgeRatio = hedge_ratio, IsWorking = is_working, TickRangeRequoteRules = new TickRangeRequoteRules() };
|
||||
var rv = new QuoteParams { PessimisticHedgePricing = pessimistic_hedge_pricing, LeanQuantityRatio = lean_quantity_ratio, IsWorking = is_working, TickRangeRequoteRules = new TickRangeRequoteRules() };
|
||||
foreach (var rr in tick_range_requote_items) rv.TickRangeRequoteRules.TicksAwayToSensitivity[rr.range] = rr.sensitivity;
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -6,37 +6,38 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Windows.Threading;
|
||||
using static bts.api.SecurityConverter;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class TimeAndSalesModel : IDisposable
|
||||
{
|
||||
public TimeAndSalesModel(IReadOnlyCollection<Security> securities) {
|
||||
this.securities = securities;
|
||||
_timer = new DispatcherTimer(TimeSpan.FromSeconds(0.1), DispatcherPriority.Normal, _tick, Dispatcher.CurrentDispatcher);
|
||||
public TimeAndSalesModel(IBus bus, IReadOnlyCollection<Security> securities) {
|
||||
set_securities(securities);
|
||||
_orders_model = new OrdersModel(bus);
|
||||
_work_loop = WorkLoop.Start(_refresh);
|
||||
}
|
||||
|
||||
private readonly DispatcherTimer _timer;
|
||||
private readonly IDisposable _work_loop;
|
||||
private readonly OrdersModel _orders_model;
|
||||
|
||||
private readonly Subject<IReadOnlyList<Tuple<Security, TradeMessage>>> _trades = new Subject<IReadOnlyList<Tuple<Security, TradeMessage>>>();
|
||||
private readonly Dictionary<Security, MDConsumerChannel> _channels = new Dictionary<Security, MDConsumerChannel>();
|
||||
|
||||
private void _tick(object sender, EventArgs e) {
|
||||
private void _refresh() {
|
||||
var ts = _channels.SelectMany(kv => kv.Value.read_trades().Select(t => Tuple.Create(kv.Key, t))).ToList();
|
||||
if (ts.Count > 0) _trades.OnNext(ts);
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<Tuple<Security, TradeMessage>>> trades => _trades.AsObservable();
|
||||
public IReadOnlyCollection<Security> securities {
|
||||
get => _channels.Keys;
|
||||
set {
|
||||
foreach (var r in _channels.Keys.Except(value).ToList()) _channels.Remove(r);
|
||||
foreach (var a in value.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
}
|
||||
public IReadOnlyCollection<Security> securities => _channels.Keys;
|
||||
public OrdersModel orders_model => _orders_model;
|
||||
|
||||
public void set_securities(IEnumerable<Security> securities) {
|
||||
foreach (var r in _channels.Keys.Except(securities).ToList()) _channels.Remove(r);
|
||||
foreach (var a in securities.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
}
|
||||
|
||||
public void start() { _timer.Start(); }
|
||||
public void Dispose() { _timer.Stop(); }
|
||||
public void Dispose() { _work_loop.Dispose(); }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
using bts.api;
|
||||
using bts.co2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.spark.menu_items;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utilities;
|
||||
using mbts.ui.utility;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
@@ -10,7 +14,10 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using static mbts.ui.spark.TimeAndSalesView;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -19,13 +26,18 @@ namespace mbts.spark
|
||||
public const int VERSION = 1;
|
||||
public const string SAVE_NAME = "TimeAndSales";
|
||||
|
||||
public TimeAndSalesVM(IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria = null) {
|
||||
_model = new TimeAndSalesModel(securities);
|
||||
var rows = new ObservableAutoWrapper<Row, Tuple<Security, TradeMessage>>(_trades, tup => new Row(tup.Item1, tup.Item2));
|
||||
row_views = CollectionViewSource.GetDefaultView(rows);
|
||||
if (sorting_criteria != null) row_views.SortDescriptions.AddRange(sorting_criteria.Select(sc => sc.to_sort_description()));
|
||||
else row_views.SortDescriptions.Add(new SortDescription(nameof(Row.trade_time), ListSortDirection.Descending));
|
||||
_sub = _model.trades.ObserveOnDispatcher().Subscribe(ts => {
|
||||
public TimeAndSalesVM(IBus bus, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria = null) {
|
||||
_bus = bus;
|
||||
_resources.Add(_model = new TimeAndSalesModel(bus, securities));
|
||||
_rows = new ObservableAutoWrapper<Row, Tuple<Security, TradeMessage>>(_trades, tup => new Row(tup.Item1, tup.Item2));
|
||||
_rows.ViewDestroyed += r => r.Dispose();
|
||||
_resources.Add(Disposable.Create(() => _rows.Clear()));
|
||||
rows_view = CollectionViewSource.GetDefaultView(_rows);
|
||||
if (sorting_criteria != null) rows_view.SortDescriptions.AddRange(sorting_criteria.Select(sc => sc.to_sort_description()));
|
||||
else rows_view.SortDescriptions.Add(new SortDescription(nameof(Row.trade_time), ListSortDirection.Descending));
|
||||
_resources.Add(_context_menu = new ContextMenuVM(_context_menu_item_factory));
|
||||
_resources.Add(_model.orders_model.on_orderbook().ObserveOnDispatcher().Subscribe(ob => _order_book = ob));
|
||||
_resources.Add(_model.trades.ObserveOnDispatcher().Subscribe(ts => {
|
||||
if (ts.Count >= 1000) {
|
||||
_trades.Clear();
|
||||
for (int i = ts.Count - 1000; i < ts.Count; i++) _trades.Add(ts[i]);
|
||||
@@ -35,38 +47,63 @@ namespace mbts.spark
|
||||
while (remove-- > 0) _trades.RemoveAt(0);
|
||||
_trades.AddRange(ts);
|
||||
}
|
||||
});
|
||||
modify_security_selection = new DialogCommand(() => new SecuritySelectorDialog {
|
||||
DataContext = new SecuritySelectorDialogVM("Time And Sales", _model.securities.ToArray(),
|
||||
s => {
|
||||
var new_secs = s.ToList();
|
||||
foreach (var r in _trades.Where(tup => !new_secs.Contains(tup.Item1)).ToList()) _trades.Remove(r);
|
||||
_model.securities = new_secs;
|
||||
}) }, () => true, true, -12, -30);
|
||||
}));
|
||||
_resources.Add(_current_cell);
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly TimeAndSalesModel _model;
|
||||
private readonly ObservableCollection<Tuple<Security, TradeMessage>> _trades = new ObservableCollection<Tuple<Security, TradeMessage>>();
|
||||
private TimeAndSalesModel _model;
|
||||
private IDisposable _sub;
|
||||
private readonly ObservableAutoWrapper<Row, Tuple<Security, TradeMessage>> _rows;
|
||||
private readonly ContextMenuVM _context_menu;
|
||||
private readonly ColdObseravbleProperty<DataGridCellInfo> _current_cell = new ColdObseravbleProperty<DataGridCellInfo>();
|
||||
private IList<IDisposable> _resources = new List<IDisposable>();
|
||||
private IOrderBook _order_book = new OrderBook();
|
||||
|
||||
public ICollectionView row_views { get; private set; }
|
||||
public IDialogCommand modify_security_selection { get; private set; }
|
||||
|
||||
public StartupData get_startup_data() { return new StartupData(_model.securities, row_views.SortDescriptions.Select(sd => new SortingCriteria(sd)).ToArray()); }
|
||||
public void Dispose() { Disposable.dispose(ref _sub); Disposable.dispose(ref _model); }
|
||||
|
||||
private class Row {
|
||||
public Row(Security security, TradeMessage trade) {
|
||||
_security = security;
|
||||
_trade = trade;
|
||||
private IEnumerable<MenuItemVM> _context_menu_item_factory() {
|
||||
yield return MenuItemVM.Create(new ModifySecuritySelectionMenuItem(new HashSet<Security>(_rows.Select(r => r.security.value)), _model.set_securities));
|
||||
if (current_cell != null && current_cell.Column != null && current_cell.Item != null && !current_cell.Item.Equals(System.Windows.DependencyProperty.UnsetValue)) {
|
||||
var securities = _rows.Where(r => r.is_selected).Select(r => r.security.value).ToList();
|
||||
yield return MenuItemVM.Create(new LadderMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new LinkedLadderMenuItem(_bus, _get_current_security_observable().ToSecurityMD()));
|
||||
yield return MenuItemVM.Create(new OrderTicketMenuItem(_model.orders_model), securities);
|
||||
yield return MenuItemVM.Create(new LinkedOrderTicketMenuItem(_bus, _get_current_security_observable().Select(OrderHelper.get_default_order)));
|
||||
yield return MenuItemVM.Create(new MarketViewMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SpreadMatrixMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticCreateMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new SyntheticStrategyMenuItem(_bus), securities);
|
||||
yield return MenuItemVM.Create(new ModifyOrderRootMenuItem(_model.orders_model, _order_book.get_active_orders_for_security(securities).Select(e => e.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrderRootMenuItem(_model.orders_model, _order_book.get_active_orders_for_security(securities).Select(e => e.order()).ToList()), securities);
|
||||
yield return MenuItemVM.Create(new CancelBuyOrdersMenuItem(_model.orders_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelSellOrdersMenuItem(_model.orders_model), securities);
|
||||
yield return MenuItemVM.Create(new CancelOrdersMenuItem(_model.orders_model), securities);
|
||||
}
|
||||
private readonly Security _security;
|
||||
private readonly TradeMessage _trade;
|
||||
}
|
||||
|
||||
public Security security => _security;
|
||||
public uint quantity => _trade.size;
|
||||
public double price => _trade.mantissa * Math.Pow(10, _trade.exponent);
|
||||
public DateTime trade_time => _trade.time.lldatetime();
|
||||
private IObservable<Security> _get_current_security_observable() { return _current_cell.Select(_get_security).DistinctUntilChanged(); }
|
||||
private static Security _get_security(DataGridCellInfo cell) { return ((Row)cell.Item).security.value; }
|
||||
|
||||
public ICollectionView rows_view { get; private set; }
|
||||
public DataGridCellInfo current_cell { get => _current_cell.Value; set => _current_cell.set(value); }
|
||||
public ContextMenuVM context_menu => _context_menu;
|
||||
|
||||
public StartupData get_startup_data() { return new StartupData(_model.securities, rows_view.SortDescriptions.Select(sd => new SortingCriteria(sd)).ToArray()); }
|
||||
public void Dispose() { Disposable.dispose(_resources); }
|
||||
|
||||
private class Row : GridRowViewModelBase<Columns> {
|
||||
public Row(Security security, TradeMessage trade) {
|
||||
this.security = AddCell(Columns.Security, security);
|
||||
quantity = AddCell(Columns.Size, trade.size);
|
||||
price = AddCell(Columns.Price, trade.mantissa * Math.Pow(10, trade.exponent));
|
||||
trade_time = AddCell(Columns.TradeTime, trade.time.lldatetime());
|
||||
order_type = AddCell(Columns.OrderType, Order.AlgoOrderTypeOneofCase.None);
|
||||
}
|
||||
|
||||
public SelectableViewModelBase<Security> security { get; }
|
||||
public SelectableViewModelBase<uint> quantity { get; }
|
||||
public SelectableViewModelBase<double> price { get; }
|
||||
public SelectableViewModelBase<DateTime> trade_time { get; }
|
||||
public SelectableViewModelBase<Order.AlgoOrderTypeOneofCase> order_type { get; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
|
||||
@@ -1,34 +1,57 @@
|
||||
<UserControl x:Class="mbts.ui.spark.TimeAndSalesView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:scv="clr-namespace:mbts.ui.spark.converters"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<scv:TickDisplayConverter x:Key="TickDisplayConverter" HideNaN="True"/>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<c:DataGridEx ItemsSource="{Binding row_views}" IsReadOnly="True" GridLinesVisibility="None" CanUserSortColumns="True" u:DataGridBehavior.NotifyColumnsOfSorting="True">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Add/Remove Securities..." Command="{Binding modify_security_selection}"/>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Time" IsReadOnly="True" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding trade_time, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="Security" IsReadOnly="True" CellStyle="{StaticResource RowHeaderCell}" Binding="{Binding security, StringFormat='q/n:./m:c'}"/>
|
||||
<DataGridTextColumn Header="Price" IsReadOnly="True">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price"/>
|
||||
<Binding Path="security.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" IsReadOnly="True" Binding="{Binding quantity}"/>
|
||||
<DataGridTextColumn Header="Type" IsReadOnly="True" Binding="{Binding order_type, Converter={StaticResource EnumDescriptionConverter}}"/>
|
||||
</DataGrid.Columns>
|
||||
</c:DataGridEx>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="mbts.ui.spark.TimeAndSalesView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:scv="clr-namespace:mbts.ui.spark.converters"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
TextElement.FontSize="11">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Resources/MenuResources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<scv:TickDisplayConverter x:Key="TickDisplayConverter" HideNaN="True"/>
|
||||
<Style x:Key="TradeTimeCell" TargetType="DataGridCell" BasedOn="{StaticResource RowHeaderCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding trade_time.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="SecurityCell" TargetType="DataGridCell" BasedOn="{StaticResource RowHeaderCell}">
|
||||
<Setter Property="IsSelected" Value="{Binding security.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="PriceCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding price.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="SizeCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding size.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
<Style x:Key="OrderTypeCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
|
||||
<Setter Property="IsSelected" Value="{Binding order_type.is_selected, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<c:DataGridEx ItemsSource="{Binding rows_view}" IsReadOnly="True" SelectionUnit="Cell" CanUserSortColumns="True" GridLinesVisibility="None"
|
||||
CurrentCell="{Binding current_cell, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" u:DataGridBehavior.NotifyColumnsOfSorting="True">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding context_menu.items_view}" IsOpen="{Binding context_menu.is_open, Mode=OneWayToSource}" ItemContainerStyle="{StaticResource ContextMenuItemStyle}">
|
||||
<ContextMenu.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource ContextMenuGroupItemStyle}"/>
|
||||
</ContextMenu.GroupStyle>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Time" CellStyle="{StaticResource TradeTimeCell}" Binding="{Binding trade_time.value, StringFormat='M/d H:mm:ss'}"/>
|
||||
<DataGridTextColumn Header="Security" CellStyle="{StaticResource SecurityCell}" Binding="{Binding security.value, StringFormat='q/n:./m:c'}"/>
|
||||
<DataGridTextColumn Header="Price" CellStyle="{StaticResource PriceCell}">
|
||||
<DataGridTextColumn.Binding>
|
||||
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
|
||||
<Binding Path="price.value"/>
|
||||
<Binding Path="security.value.ContractSpec"/>
|
||||
</MultiBinding>
|
||||
</DataGridTextColumn.Binding>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Qty" CellStyle="{StaticResource SizeCell}" Binding="{Binding quantity.value}"/>
|
||||
<DataGridTextColumn Header="Type" CellStyle="{StaticResource OrderTypeCell}" Binding="{Binding order_type.value, Converter={StaticResource EnumDescriptionConverter}}"/>
|
||||
</DataGrid.Columns>
|
||||
</c:DataGridEx>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -7,6 +7,8 @@ namespace mbts.ui.spark
|
||||
/// </summary>
|
||||
public partial class TimeAndSalesView : UserControl
|
||||
{
|
||||
public enum Columns { TradeTime, Security, Price, Size, OrderType }
|
||||
|
||||
public TimeAndSalesView() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ namespace mbts.spark
|
||||
{
|
||||
internal class TimeAndSalesWindow : IShellWindow
|
||||
{
|
||||
public TimeAndSalesWindow(IShellModule owner, IReadOnlyCollection<Security> securities) : this (owner, securities, null) { }
|
||||
public TimeAndSalesWindow(IShellModule owner, TimeAndSalesVM.StartupData startup_data) : this(owner, startup_data.securities.Select(deserialize<Security>).ToList(), startup_data.sorting_criteria) { }
|
||||
public TimeAndSalesWindow(IShellModule owner, IBus bus, IReadOnlyCollection<Security> securities) : this (owner, bus, securities, null) { }
|
||||
public TimeAndSalesWindow(IShellModule owner, IBus bus, TimeAndSalesVM.StartupData startup_data) : this(owner, bus, startup_data.securities.Select(deserialize<Security>).ToList(), startup_data.sorting_criteria) { }
|
||||
|
||||
private TimeAndSalesWindow(IShellModule owner, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
|
||||
private TimeAndSalesWindow(IShellModule owner, IBus bus, IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
|
||||
_bus = bus;
|
||||
_securities = securities;
|
||||
_sorting_criteria = sorting_criteria;
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
private readonly IBus _bus;
|
||||
private readonly IReadOnlyCollection<Security> _securities;
|
||||
private readonly IReadOnlyCollection<SortingCriteria> _sorting_criteria;
|
||||
private TimeAndSalesVM _vm;
|
||||
@@ -35,7 +37,7 @@ namespace mbts.spark
|
||||
public event Action TitleChanged;
|
||||
public event Action IconChanged;
|
||||
public void Dispose() { Disposable.dispose(ref _vm); }
|
||||
public ShellWindowUI GetContent() { return new ShellWindowUI(new TimeAndSalesView { DataContext = _vm = new TimeAndSalesVM(_securities, _sorting_criteria), Width = 400, Height = 500 }); }
|
||||
public ShellWindowUI GetContent() { return new ShellWindowUI(new TimeAndSalesView { DataContext = _vm = new TimeAndSalesVM(_bus, _securities, _sorting_criteria), Width = 400, Height = 500 }); }
|
||||
public void GetState(Stream save_here) {
|
||||
if (_vm != null) {
|
||||
serialize(save_here, new ShellSerializationHeader { name = TimeAndSalesVM.SAVE_NAME, version = TimeAndSalesVM.VERSION });
|
||||
|
||||
@@ -40,7 +40,14 @@ namespace mbts.spark
|
||||
public int priority => 1;
|
||||
public string name => "Trades";
|
||||
public ImageSource icon => Icons.Trades;
|
||||
public IShellWindow launch_ui => new LaunchMenu { DataContext = new LaunchMenuVM(new OrderBookMenuItem(_bus), new FillsMenuItem(_bus), new AuditLogsMenuItem(_bus), new PositionsMenuItem(_bus), new TimeAndSalesMenuItem(_bus)) };
|
||||
public IShellWindow launch_ui => new LaunchMenu {
|
||||
DataContext = new LaunchMenuVM(
|
||||
new OrderBookMenuItem(_bus),
|
||||
new FillsMenuItem(_bus),
|
||||
new AuditLogsMenuItem(_bus),
|
||||
new PositionsMenuItem(_bus),
|
||||
new TimeAndSalesMenuItem(_bus))
|
||||
};
|
||||
public void load_state(Stream state = null) { }
|
||||
public void get_state(Stream save_here) { }
|
||||
public Task<IShellWindow> create(Stream load_stream) {
|
||||
@@ -48,7 +55,7 @@ namespace mbts.spark
|
||||
switch(header?.name) {
|
||||
case OrderBookVM.SAVE_NAME: if (try_deserialize(load_stream, out OrderBookState orders_state)) return Task.FromResult(create_order_book_window(orders_state)); break;
|
||||
case FillsVM.SAVE_NAME: { if (try_deserialize(load_stream, out FillsVM.StartupData state)) return Task.FromResult(create_fills_window(state)); break; }
|
||||
case TimeAndSalesVM.SAVE_NAME: { if (try_deserialize(load_stream, out TimeAndSalesVM.StartupData state)) return Task.FromResult<IShellWindow>(new TimeAndSalesWindow(this, state)); break; }
|
||||
case TimeAndSalesVM.SAVE_NAME: { if (try_deserialize(load_stream, out TimeAndSalesVM.StartupData state)) return Task.FromResult<IShellWindow>(new TimeAndSalesWindow(this, _bus, state)); break; }
|
||||
}
|
||||
return Task.FromResult<IShellWindow>(null);
|
||||
}
|
||||
@@ -56,7 +63,7 @@ namespace mbts.spark
|
||||
public void Dispose() { _dispose.Dispose(); }
|
||||
|
||||
private IShellWindow create_order_book_window(OrderBookState state) {
|
||||
var vm = new OrderBookVM(new OrdersModel(_bus), state, Observable.Return(new OrderBookSettings()));
|
||||
var vm = new OrderBookVM(_bus, new OrdersModel(_bus), state, Observable.Return(new OrderBookSettings()));
|
||||
var view = new OrderBookView(vm) { Width = 1526, Height = 800 };
|
||||
return ShellWindow.create(this, "Order Book", view, vm.get_state);
|
||||
}
|
||||
@@ -64,7 +71,7 @@ namespace mbts.spark
|
||||
private IShellWindow create_fills_window(FillsVM.StartupData startup_data) { return create_fills_window(startup_data.securities.Select(deserialize<Security>).ToList(), startup_data.sorting_criteria); }
|
||||
private IShellWindow create_fills_window(IReadOnlyCollection<Security> securities) { return create_fills_window(securities, null); }
|
||||
private IShellWindow create_fills_window(IReadOnlyCollection<Security> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
|
||||
var vm = new FillsVM(new OrdersModel(_bus), securities, sorting_criteria);
|
||||
var vm = new FillsVM(_bus, new OrdersModel(_bus), securities, sorting_criteria);
|
||||
var view = new FillsView { DataContext = vm, Width = 1024, Height = 800 };
|
||||
return ShellWindow.create(this, "Fills", view, vm.get_state, Icons.Ticket);
|
||||
}
|
||||
@@ -73,6 +80,6 @@ namespace mbts.spark
|
||||
private void show_fills(ShowFillsMessage msg) { _wm.Windows.Add(create_fills_window(new List<Security>())); }
|
||||
private void show_audit_log(ShowAuditLogsMessage msg) { }
|
||||
private void show_positions(ShowPositionsMessage msg) { }
|
||||
private void show_time_and_sales(ShowTimeAndSalesMessage msg) { _wm.Windows.Add(new TimeAndSalesWindow(this, msg.data)); }
|
||||
private void show_time_and_sales(ShowTimeAndSalesMessage msg) { _wm.Windows.Add(new TimeAndSalesWindow(this, _bus, msg.data)); }
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,32 @@
|
||||
using bts.api;
|
||||
using mbts.co2;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class BBOVM : ViewModelBase
|
||||
internal class BBOVM : DisposableViewModelBase
|
||||
{
|
||||
public BBOVM(SecurityMD smd) {
|
||||
_smd = smd;
|
||||
_bid = backing(nameof(bid), double.NaN);
|
||||
_ask = backing(nameof(ask), double.NaN);
|
||||
_bid_size = backing(nameof(bid_size), (ushort)0);
|
||||
_ask_size = backing(nameof(ask_size), (ushort)0);
|
||||
refresh();
|
||||
public BBOVM(uint security) : this(Observable.Return(security)) { }
|
||||
public BBOVM(IObservable<uint> security) : this(security.ToSecurity()) { }
|
||||
public BBOVM(IObservable<Security> security) : this(security, new SecurityMDPump(security)) { }
|
||||
public BBOVM(IObservable<Security> security, ISecurityMDPump md_pump) {
|
||||
_security = backing(nameof(security), security, Security.Empty);
|
||||
_bid = backing(nameof(bid), md_pump.bid_price, double.NaN);
|
||||
_ask = backing(nameof(ask), md_pump.ask_price, double.NaN);
|
||||
_bid_size = backing(nameof(bid_size), md_pump.bid_size, (ushort)0);
|
||||
_ask_size = backing(nameof(ask_size), md_pump.ask_size, (ushort)0);
|
||||
}
|
||||
|
||||
private readonly SecurityMD _smd;
|
||||
private readonly Property<Security> _security;
|
||||
private readonly Property<double> _bid, _ask;
|
||||
private readonly Property<ushort> _bid_size, _ask_size;
|
||||
private ulong _time = 0;
|
||||
|
||||
public Security security => _smd.security;
|
||||
public Security security => _security.Value;
|
||||
public double bid => _bid.Value;
|
||||
public double ask => _ask.Value;
|
||||
public ushort bid_size => _bid_size.Value;
|
||||
public ushort ask_size => _ask_size.Value;
|
||||
|
||||
public void refresh() {
|
||||
if (_smd.md.get_bbo(ref _time, out NativePriceSize b, out NativePriceSize a)) {
|
||||
_bid.set(b.price);
|
||||
_bid_size.set(b.size);
|
||||
_ask.set(a.price);
|
||||
_ask_size.set(a.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using mbts.spark.menu_items;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.spark.utilities
|
||||
{
|
||||
internal class ContextMenuVM : IDisposable
|
||||
{
|
||||
public ContextMenuVM(Func<IEnumerable<MenuItemVM>> menu_factory) {
|
||||
_menu_factory = menu_factory;
|
||||
_items = new ObservableCollection<MenuItemVM>(_menu_factory());
|
||||
items_view = CollectionViewSource.GetDefaultView(_items);
|
||||
items_view.GroupDescriptions.Add(new PropertyGroupDescription(nameof(MenuItemVM.sectional_id)));
|
||||
}
|
||||
|
||||
private readonly Func<IEnumerable<MenuItemVM>> _menu_factory;
|
||||
private readonly ObservableCollection<MenuItemVM> _items;
|
||||
private bool _is_open;
|
||||
public bool is_open {
|
||||
get => _is_open;
|
||||
set {
|
||||
_is_open = value;
|
||||
Disposable.dispose(_items);
|
||||
foreach (var item in _menu_factory()) _items.Add(item);
|
||||
}
|
||||
}
|
||||
public ICollectionView items_view { get; }
|
||||
|
||||
public void Dispose() { Disposable.dispose(_items); }
|
||||
}
|
||||
}
|
||||
Loaded 100 of 159 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user