SPARK-487, SPARK-488 - sprucing up ladder

This commit is contained in:
John Colvin committed 2018-02-17 21:42:09 -05:00
1 parent 2acec803c5
commit cd050b5a00
4 files changed
+188 -177

No files matched your search

@@ -1,24 +1,20 @@
using bts.api;
using bts.spark;
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;
namespace mbts.ui.controls {
public class SparkMenu : ItemsControl {
static SparkMenu() {
static SparkMenu() =>
DefaultStyleKeyProperty.OverrideMetadata(typeof(SparkMenu), new FrameworkPropertyMetadata(typeof(SparkMenu)));
}
public SparkMenu(IEnumerable<SparkCommand> commands, IBus bus) {
ItemsSource = commands.Select(c => new SparkCommandVM(c, bus)).ToList();
public SparkMenu() =>
SetCurrentValue(FocusableProperty, false);
}
public SparkMenu(IEnumerable<SparkCommand> commands, IBus bus) : this() =>
ItemsSource = commands.Select(c => new SparkCommandVM(c, bus)).ToList();
public bool ShowText {
get { return (bool)GetValue(ShowTextProperty); }
@@ -26,7 +22,5 @@ namespace mbts.ui.controls {
}
public static readonly DependencyProperty ShowTextProperty =
DependencyProperty.Register("ShowText", typeof(bool), typeof(SparkMenu), new PropertyMetadata(true));
}
}
}
+20 -4
View File
@@ -1,5 +1,6 @@
using bts.api;
using bts.api.orderman;
using bts.spark;
using mbts.co2;
using mbts.ui;
using mbts.ui.shell;
@@ -40,15 +41,29 @@ namespace mbts.spark {
// calculator
calculator = new CalculatorLogic(0, settings.Select(s => s.calculator_buttons));
// cancel
cancel_command = new AsyncCommand<LadderModel.CancelType>(_model.cancel_orders);
send_order_command = new AsyncCommand<(double, Side?)>(send_order);
// Order
_selected_time_in_force = backing(nameof(selected_order_type), TimeInForce.Day);
selected_order_type = _limit;
_revert = backing(nameof(revert), false);
show_ticket_command = new DelegateCommand(show_ticket);
send_order_command = new AsyncCommand<(double, Side?)>(send_order);
cancel_command = new AsyncCommand<LadderModel.CancelType>(_model.cancel_orders);
menu_items = new[] {
new SparkCommandVM(SparkCommand.create("Cxl Buys", Icons.CancelBuys, SparkTags.CancelOrders).complete(() => orders.Where(ovm => ovm.side == Side.Buy).Select(ovm => ovm.id)), _bus),
new SparkCommandVM(SparkCommand.create("Cxl Sells", Icons.CancelSells, SparkTags.CancelOrders).complete(() => orders.Where(ovm => ovm.side == Side.Sell).Select(ovm => ovm.id)), _bus),
new SparkCommandVM(SparkCommand.create("Cxl All", Icons.CancelOrders, SparkTags.CancelOrders).complete(() => orders.Select(ovm => ovm.id)), _bus),
new SparkCommandVM(SparkCommand.create("Details", Icons.Book, SparkTags.ShowOrderBookTag).complete(() => new bts.shell.OrderBookWindowFactory.OrderBookStartupData {
filters = new bts.shell.OrderBookWindowFactory.FilterStates {
security_criteria = new SecurityCriteria(security)
}
}), _bus),
//new SparkCommandVM(SparkCommands.ShowFills.complete(() => new bts.shell.FillsWindowFactory.StartupData(
// new bts.shell.FillsWindowFactory.FilterStates {
// security = new SecurityCriteria(security)
// }
//)), _bus),
new SparkCommandVM(SparkCommand.create("Ticket", Icons.Ticket, SparkTags.ShowOrderTicketTag).complete(() => (new OrderDefinitionImmutable(create_order()), 0d, 0u)), _bus)
};
// Settings
this.settings = settings;
@@ -77,6 +92,7 @@ namespace mbts.spark {
public IMDHandle md => _model.md;
public bool is_synthetic => _model.security.ContractCase == Security.ContractOneofCase.Synthetic;
public CalculatorLogic calculator { get; }
public SparkCommandVM[] menu_items { get; }
internal LadderModel model => _model;
internal IReadOnlyDictionary<uint, OrderRecordImmutable> orders_cache { get; private set; } = new Dictionary<uint, OrderRecordImmutable>();
+161 -161
View File
@@ -4,9 +4,7 @@
xmlns:mbts="clr-namespace:mbts.ui"
xmlns:controls="clr-namespace:mbts.ui.controls"
xmlns:spark="clr-namespace:mbts.spark"
xmlns:usp="clr-namespace:mbts.ui.spark"
xmlns:uag="clr-namespace:mbts.ui.spark.algo"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:converters="clr-namespace:mbts.ui.converters"
Height="600"
Width="400"
@@ -18,169 +16,171 @@
</ResourceDictionary.MergedDictionaries>
<converters:BooleanToVisibilityConverter x:Key="BoolToInVisibility" VisibilityForTrue="Collapsed" VisibilityForFalse="Visible" />
<converters:BooleanToObjectConverter x:Key="bool_to_margin">
<converters:BooleanToObjectConverter.ValueForTrue>
<Thickness />
</converters:BooleanToObjectConverter.ValueForTrue>
<converters:BooleanToObjectConverter.ValueForFalse>
<Thickness Top="32" />
</converters:BooleanToObjectConverter.ValueForFalse>
<converters:BooleanToObjectConverter.ValueForTrue>
<Thickness />
</converters:BooleanToObjectConverter.ValueForTrue>
<converters:BooleanToObjectConverter.ValueForFalse>
<Thickness Top="32" />
</converters:BooleanToObjectConverter.ValueForFalse>
</converters:BooleanToObjectConverter>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="112"/>
<ColumnDefinition Width="1"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Background="{mbts:BTSColor UI.spark_menu_background}">
<StackPanel Margin="5,0">
<StackPanel.Resources>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</StackPanel.Resources>
<ComboBox Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
<ComboBox ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding selected_time_in_force}" Margin="2" />
<uag:OrderDetailsPopupControl ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}" Margin="2" ExpandDirection="Left"/>
<!-- reset to defaults after order -->
<CheckBox IsChecked="{Binding revert}">Revert</CheckBox>
<StackPanel.Resources>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</StackPanel.Resources>
<ComboBox Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
<ComboBox ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding selected_time_in_force}" Margin="2" />
<uag:OrderDetailsPopupControl ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}" Margin="2" ExpandDirection="Left"/>
<!-- reset to defaults after order -->
<CheckBox IsChecked="{Binding revert}">Revert</CheckBox>
<TextBox HorizontalContentAlignment="Right" Text="{Binding calculator.value}" Margin="2,15,2,0" />
<ItemsControl ItemsSource="{Binding calculator.buttons}" Focusable="False">
<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 }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Margin="2" HorizontalAlignment="Stretch" Command="{Binding calculator.clear}">Clear</Button>
<StackPanel Margin="0,15,0,5">
<Button Height="30" Margin="2" Command="{Binding cancel_command}" CommandParameter="All">Cxl All</Button>
<Button Margin="2" Command="{Binding cancel_command}" CommandParameter="Bids" Background="{mbts:BTSColor MarketData.bid}" Foreground="White">Cxl Bids</Button>
<Button Margin="2" Command="{Binding cancel_command}" CommandParameter="Asks" Background="{mbts:BTSColor MarketData.ask}" Foreground="White">Cxl Asks</Button>
</StackPanel>
<TextBox HorizontalContentAlignment="Right" Text="{Binding calculator.value}" Margin="2,15,2,0" />
<ItemsControl ItemsSource="{Binding calculator.buttons}" Focusable="False">
<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 }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Margin="2" HorizontalAlignment="Stretch" Command="{Binding calculator.clear}">Clear</Button>
<controls:SparkMenu ItemsSource="{Binding menu_items}" ShowText="True"/>
<Grid Margin="8,4,0,0" Visibility="{Binding is_synthetic,Converter={StaticResource BoolToInVisibility}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Day"/>
<TextBlock Grid.Column="0" Grid.Row="2" Text="High"/>
<TextBlock Grid.Column="0" Grid.Row="4" Text="Low"/>
<TextBlock Grid.Column="0" Grid.Row="6" Text="Open"/>
<TextBlock Grid.Column="0" Grid.Row="8" Text="Volume"/>
<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding change}" Foreground="{Binding change_double, Converter={StaticResource NumericSignBrushConverter}}" FontWeight="Bold"/>
<TextBlock Grid.Column="2" Grid.Row="2" Text="{Binding high, Mode=OneWay}" Foreground="{mbts:BTSColor success}" FontWeight="Bold" />
<TextBlock Grid.Column="2" Grid.Row="4" Text="{Binding low, Mode=OneWay}" Foreground="{mbts:BTSColor danger}" FontWeight="Bold" />
<TextBlock Grid.Column="2" Grid.Row="6" Text="{Binding open, Mode=OneWay}" FontWeight="Bold" />
<TextBlock Grid.Column="2" Grid.Row="8" Text="{Binding volume, Mode=OneWay}" FontWeight="Bold" />
<spark:RecenterCountdown Grid.ColumnSpan="3" Grid.Row="9"
Width="16" Height="16" Margin="6"
HorizontalAlignment="Center"
Command="{Binding RecenterCommand, ElementName=_ladder}"
Foreground="Black" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"
PieBackground="Black" SliceBackground="White" />
</Grid>
</StackPanel>
<Button Margin="5,0,5,15" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Command="{Binding show_ticket_command}">Ticket</Button>
<Grid Grid.Column="1" Margin="4" Height="24" VerticalAlignment="Top" TextBlock.FontSize="9"
Visibility="{Binding is_synthetic,Converter={StaticResource BoolToInVisibility}}">
<Grid.Resources>
<Thickness x:Key="text_margin" Right="2" />
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" /> <ColumnDefinition />
<ColumnDefinition Width="Auto" /> <ColumnDefinition />
<ColumnDefinition Width="Auto" /> <!-- padding -->
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.RowSpan="2" Text="{Binding change}" FontSize="14" Foreground="{Binding change_double, Converter={StaticResource NumericSignBrushConverter}}" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="H:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="L:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding high, Mode=OneWay}" Foreground="{mbts:BTSColor success}" FontWeight="Bold" />
<TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding low, Mode=OneWay}" Foreground="{mbts:BTSColor danger}" FontWeight="Bold" />
<TextBlock Grid.Column="3" Grid.Row="0" Text="O:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="3" Grid.Row="1" Text="V:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="4" Grid.Row="0" Text="{Binding open, Mode=OneWay}" FontWeight="Bold" />
<TextBlock Grid.Column="4" Grid.Row="1" Text="{Binding volume, Mode=OneWay}" FontWeight="Bold" />
<spark:RecenterCountdown Grid.Column="5" Grid.RowSpan="2"
Width="16" Height="16" Margin="2"
Command="{Binding RecenterCommand, ElementName=_ladder}"
Foreground="Black" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"
PieBackground="Black" SliceBackground="White" />
</Grid>
<spark:LadderGridHost x:Name="_ladder" Grid.Column="1" Margin="{Binding Path=is_synthetic, Converter={StaticResource bool_to_margin}}" Command="{Binding send_order_command}" Orders="{Binding orders}">
<spark:LadderGridHost.Resources>
<Style TargetType="controls:Badge">
<Setter Property="Background" Value="{Binding background}" />
<Setter Property="BorderBrush" Value="{Binding border}" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="TopText" Value="{Binding line1}" />
<Setter Property="BottomText" Value="{Binding line2}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Width" Value="14" />
<Setter Property="Height" Value="8" />
<Setter Property="Margin" Value="0" />
<Setter Property="ToolTip" Value="{Binding summary}" />
<Setter Property="CornerRadius" Value="1" />
<Setter Property="Opacity" Value="{Binding opacity}" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<ContextMenu.Template>
<ControlTemplate>
<Border Width="200" Background="{mbts:BTSColor UI.default_background}" BorderBrush="{mbts:BTSColor UI.form_border}" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Background="{Binding header_brush}" Height="32">
<TextBlock Foreground="White" Text="{Binding summary}" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<TextBlock Text="{Binding description}" Margin="5,5,0,5" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" />
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
<Setter Property="Margin" Value="5,2" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Button Command="{Binding shatter_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource BombIcon}" />
<TextBlock Text="Shatter" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Button Command="{Binding cancel_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource CancelIcon}" />
<TextBlock Text="Cancel" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Button Command="{Binding modify_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ModifyIcon}" />
<TextBlock Text="Modify" VerticalAlignment="Center" />
</StackPanel>
</Button>
</StackPanel>
<Rectangle Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Height="4"
</Grid>
<Rectangle Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="{mbts:BTSColor UI.form_content_border}"/>
<spark:LadderGridHost x:Name="_ladder" Grid.Column="2" Command="{Binding send_order_command}" Orders="{Binding orders}">
<spark:LadderGridHost.Resources>
<Style TargetType="controls:Badge">
<Setter Property="Background" Value="{Binding background}" />
<Setter Property="BorderBrush" Value="{Binding border}" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="TopText" Value="{Binding line1}" />
<Setter Property="BottomText" Value="{Binding line2}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Width" Value="14" />
<Setter Property="Height" Value="8" />
<Setter Property="Margin" Value="0" />
<Setter Property="ToolTip" Value="{Binding summary}" />
<Setter Property="CornerRadius" Value="1" />
<Setter Property="Opacity" Value="{Binding opacity}" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<ContextMenu.Template>
<ControlTemplate>
<Border Width="200" Background="{mbts:BTSColor UI.default_background}" BorderBrush="{mbts:BTSColor UI.form_border}" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Background="{Binding header_brush}" Height="32">
<TextBlock Foreground="White" Text="{Binding summary}" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<TextBlock Text="{Binding description}" Margin="5,5,0,5" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" />
<StackPanel Grid.Column="1" Grid.Row="1">
<StackPanel.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
<Setter Property="Margin" Value="5,2" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Button Command="{Binding shatter_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource BombIcon}" />
<TextBlock Text="Shatter" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Button Command="{Binding cancel_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource CancelIcon}" />
<TextBlock Text="Cancel" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Button Command="{Binding modify_command}" Margin="5" Padding="5">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ModifyIcon}" />
<TextBlock Text="Modify" VerticalAlignment="Center" />
</StackPanel>
</Button>
</StackPanel>
<Rectangle Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Height="4"
Fill="{Binding background}" />
</Grid>
</Border>
</ControlTemplate>
</ContextMenu.Template>
</ContextMenu>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{Binding hoverbackground}" />
</Trigger>
</Style.Triggers>
</Style>
</spark:LadderGridHost.Resources>
</spark:LadderGridHost>
</Grid>
</UserControl>
</Grid>
</Border>
</ControlTemplate>
</ContextMenu.Template>
</ContextMenu>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{Binding hoverbackground}" />
</Trigger>
</Style.Triggers>
</Style>
</spark:LadderGridHost.Resources>
</spark:LadderGridHost>
</Grid>
</UserControl>
@@ -62,6 +62,7 @@ namespace mbts.spark {
public uint id => _order.Key;
public uint security_key => _parent.security.Id;
public double price { get => double.IsNaN(_phantom_price) ? _real_price : _phantom_price; }
public Side side => _order.Def.Side;
public string text => "";
string _buy_sell_indicator => _order.Def.Side == Side.Buy ? "B" : "S";