103 lines
4.3 KiB
C#
103 lines
4.3 KiB
C#
using bts.api.orderman;
|
|
using mbts.ui;
|
|
using mbts.ui.controls;
|
|
using mbts.ui.converters;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
|
|
namespace mbts.spark {
|
|
internal partial class OrderBookGridView : DIYGrid {
|
|
public const string
|
|
SubTypeFilterTemplateKey = "SubTypeFilterTemplate",
|
|
ExpandCollapseToggleStyleKey = "ExpandCollapseToggleStyle",
|
|
RowStyleKey = "RowStyle",
|
|
RowTemplateKey = "RowTemplateKey",
|
|
CVRowStyleKey = "CVRowStyle",
|
|
CVRowTemplateKey = "CVRowTemplateKey";
|
|
|
|
// IMPORTANT: these enums are stored as strings in the general-purpose GridColumnSettings proto, and are used to ID THE COLUMNS!
|
|
// Do NOT RENAME them! However, if you must, be sure to write an IShellWindowMigrationRule or something to account for backwards compatability.
|
|
public enum ColumnKeys {
|
|
Security = 1,
|
|
Symbol = 1 << 1,
|
|
Time = 1 << 2,
|
|
LastChange = 1 << 3,
|
|
User = 1 << 4,
|
|
Account = 1 << 5,
|
|
Exchange = 1 << 6,
|
|
TimeInForce = 1 << 7,
|
|
OrderType = 1 << 8,
|
|
SubType = 1 << 9,
|
|
Side = 1 << 10,
|
|
Size = 1 << 11,
|
|
Price = 1 << 12,
|
|
Filled = 1 << 13,
|
|
AvgFilled = 1 << 14,
|
|
LastPrice = 1 << 15,
|
|
Status = 1 << 16,
|
|
LastMessage = 1 << 17,
|
|
SecurityKey = 1 << 18,
|
|
OrderKey = 1 << 19,
|
|
ParentKey = 1 << 20,
|
|
AttachedTargetOrderKey = 1 << 21,
|
|
Cancel = 1 << 22,
|
|
EditableQty = 1 << 23,
|
|
EditablePrice = 1 << 24,
|
|
Attach = 1 << 25,
|
|
Detach = 1 << 26,
|
|
Update = 1 << 27,
|
|
Commit = 1 << 28,
|
|
RootAlgoType = 1 << 29
|
|
}
|
|
|
|
public OrderBookGridView() {
|
|
InitializeComponent();
|
|
var row_template_factory = new FrameworkElementFactory(typeof(OrderBookRowView));
|
|
row_template_factory.SetValue(OrderBookRowView.BackgroundProperty, RowBackgroundHelper.row_background_binding);
|
|
RowTemplate = new DataTemplate { VisualTree = row_template_factory };
|
|
}
|
|
|
|
static class RowBackgroundHelper {
|
|
public static readonly BindingBase row_background_binding;
|
|
|
|
static RowBackgroundHelper() {
|
|
var bg_binding = new MultiBinding();
|
|
bg_binding.Bindings.Add(new Binding(nameof(OrderBookRowVM.status)));
|
|
bg_binding.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) });
|
|
double overlay_opacity = config.Configuration.get<bts.config.OrderBookOptions>().status_color_opacity_when_selected;
|
|
if (overlay_opacity > 0.1 && overlay_opacity < 0.9) {
|
|
bg_binding.Converter = ValueConverter.create<OrderStatus, bool, Brush>((status, is_selected) => {
|
|
var color = _status_color(status);
|
|
return color.HasValue ? new SolidColorBrush(color.Value) { Opacity = is_selected ? overlay_opacity : 1.0 } : null;
|
|
});
|
|
} else {
|
|
bg_binding.Converter = ValueConverter.create<OrderStatus, bool, Brush>((status, is_selected) => {
|
|
if (is_selected)
|
|
return null;
|
|
var color = _status_color(status);
|
|
return color.HasValue ? new SolidColorBrush(color.Value) : null;
|
|
});
|
|
}
|
|
row_background_binding = bg_binding;
|
|
}
|
|
|
|
static Color? _status_color(OrderStatus status) {
|
|
switch (status) {
|
|
case OrderStatus.Canceled: return BTSColors.Orders.canceled_order_background;
|
|
case OrderStatus.Completed: return BTSColors.Orders.completed_order_background;
|
|
case OrderStatus.Disconnected:
|
|
case OrderStatus.RejectedBySpark:
|
|
case OrderStatus.Error:
|
|
return BTSColors.Orders.error_order_background;
|
|
default: return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class OrderBookRowView : DIYGrid.HighPerformanceRow<OrderBookRowVM, OrderBookGridView.ColumnKeys> {
|
|
public OrderBookRowView() : base() { }
|
|
}
|
|
} |