SPARK-330 Ladder - hook up [new] OrdersModel
This commit is contained in:
1 parent
6e9857379c
commit
415dc4f580
53 files changed
+515
-478
No files matched your search
@@ -40,7 +40,7 @@ namespace mbts.spark
|
||||
SparkCommand.create("Update Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
|
||||
SparkCommands.ShowLadder.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedLadder
|
||||
SparkCommands.ShowOrderTicket.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedOrderTicket
|
||||
SparkCommands.ShowFills.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
SparkCommands.ShowTimeAndSales.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace mbts.spark
|
||||
SparkCommand.create("Update Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
|
||||
SparkCommands.ShowLadder.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedLadder
|
||||
SparkCommands.ShowOrderTicket.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedOrderTicket
|
||||
SparkCommands.ShowFills.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
SparkCommands.ShowMarketView.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/FilterTemplates.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="{u:BTSColor MarketData.bid}"/>
|
||||
<Style.Triggers>
|
||||
@@ -22,8 +20,8 @@
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="AlgoTypeElement" TargetType="usp:AlgoTypeItem">
|
||||
<Setter Property="AlgoType" Value="{Binding algo_type}"/>
|
||||
<Style x:Key="OrderTypeElement" TargetType="usp:OrderTypeItem">
|
||||
<Setter Property="OrderType" Value="{Binding order_type}"/>
|
||||
<Setter Property="Metadata" Value="{Binding order_metadata}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -66,7 +64,7 @@
|
||||
c:DataGridFilterProperties.Filter="{Binding time_in_force_filter, Source={u:DirectReference grid}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.time_in_force_filter.active, Source={u:DirectReference grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource DiscreteValuesTemplate}"/>
|
||||
<usp:DataGridAlgoTypeColumn Header="Algo" ElementStyle="{StaticResource AlgoTypeElement}" SortMemberPath="algo_type"
|
||||
<usp:DataGridOrderTypeColumn Header="Algo" ElementStyle="{StaticResource OrderTypeElement}" SortMemberPath="algo_type"
|
||||
c:DataGridEx.CellKey="{u:Enum AlgoType, Type={u:Nested usp:FillsView.Columns}}"
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.algo_type_filter, Source={u:DirectReference grid}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.algo_type_filter.active, Source={u:DirectReference grid}}"
|
||||
|
||||
@@ -13,31 +13,4 @@ namespace mbts.ui.spark
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
<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}"/>
|
||||
<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.value.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}"/>
|
||||
*/
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace mbts.spark
|
||||
SparkCommand.create("Update Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
|
||||
SparkCommands.ShowLadder.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedLadder
|
||||
SparkCommands.ShowOrderTicket.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(_md)), md => md.HasValue, md => md.Value),
|
||||
// TODO: ShowLinkedOrderTicket
|
||||
SparkCommands.ShowTimeAndSales.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
SparkCommands.ShowMarketView.complete(_vm.Observable.SelectMany(vm => vm.current_security_observable), s => s.HasValue, s => new SecurityCriteria(s.Value)),
|
||||
|
||||
@@ -14,12 +14,14 @@ namespace bts.shell {
|
||||
internal class LadderWindowFactory : ShellWindowFactory<LadderSaveState> {
|
||||
readonly IBus _bus;
|
||||
readonly IWindowManager _wm;
|
||||
readonly OrdersModel _orders_model;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _securities = new Dictionary<uint, SecurityMD>();
|
||||
|
||||
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm)
|
||||
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, OrdersModel orders_model)
|
||||
: base(owner, "SparkLadder") {
|
||||
_bus = bus;
|
||||
_wm = wm;
|
||||
_orders_model = orders_model;
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s),
|
||||
@@ -39,8 +41,8 @@ namespace bts.shell {
|
||||
IObservable<mbts.spark.LadderSettings> default_ladder_settings = Observable.Return(new mbts.spark.LadderSettings());
|
||||
|
||||
private IShellWindow create_ladder_window(SecurityMD md) {
|
||||
var model = new LadderModel(md, new DemoOrdersModel(_bus));
|
||||
var vm = new LadderVM(model, default_ladder_settings);
|
||||
var model = new LadderModel(md, _orders_model);
|
||||
var vm = new LadderVM(_bus, model, default_ladder_settings);
|
||||
var view = new LadderView() { DataContext = vm };
|
||||
var state = new LadderSaveState() { security_key = md.security.Id };
|
||||
return ShellWindow.create(module, md.security.ToString(), view, vm, s => save(state, s), Icons.Depth);
|
||||
@@ -64,7 +66,7 @@ namespace bts.shell {
|
||||
Icons.Depth);
|
||||
sub =
|
||||
keystream
|
||||
.Select(md => new LadderVM(new LadderModel(md, orders), default_ladder_settings))
|
||||
.Select(md => new LadderVM(_bus, new LadderModel(md, _orders_model), default_ladder_settings))
|
||||
.Aggregate((old, vm) => { old.Dispose(); return vm; })
|
||||
.Subscribe(vm => { view.DataContext = vm; window.Title = vm.security.ToString(); });
|
||||
}
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
using System;
|
||||
using bts.api;
|
||||
using bts.api;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using mbts;
|
||||
using System;
|
||||
|
||||
namespace bts.shell {
|
||||
internal class ShowOrderTicketHandler : IDisposable {
|
||||
class ShowOrderTicketHandler : IDisposable {
|
||||
readonly IBus _bus;
|
||||
IDisposable _dispose;
|
||||
|
||||
public ShowOrderTicketHandler(IBus bus) {
|
||||
_bus = bus;
|
||||
_dispose =
|
||||
bus.subscribe(SparkTags.ShowOrderTicketTag).Subscribe(show_order_ticket);
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.ShowOrderTicketFromSecurityTag).Subscribe(show_order_ticket),
|
||||
bus.subscribe(SparkTags.ShowOrderTicketTag).Subscribe(show_order_ticket)
|
||||
);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
private void show_order_ticket(SecurityMD md) {
|
||||
void show_order_ticket(SecurityMD md) =>
|
||||
show_order_ticket(new OrderDefinition { SecurityKey = md.security.Id });
|
||||
|
||||
void show_order_ticket(OrderDefinitionImmutable order) {
|
||||
// This is temporary until the new-new Order type comes in
|
||||
var vm =
|
||||
new OrderTicketVM(
|
||||
new DemoOrdersModel(_bus),
|
||||
new Order() { Security = md.security.CloneToMutable() },
|
||||
new Order { Security = new Security { ContractSpec = new ContractSpecification() } },
|
||||
null, _bus);
|
||||
|
||||
var ui = new OrderTicket() { DataContext = vm };
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace bts.shell {
|
||||
|
||||
[ImportingConstructor]
|
||||
public TradingShellModule(IBus bus, IWindowManager wm, SecuritySource ssrc, OrdersModel orders_model) {
|
||||
_lwf = new LadderWindowFactory(this, bus, wm);
|
||||
_lwf = new LadderWindowFactory(this, bus, wm, orders_model);
|
||||
_obwf = new OrderBookWindowFactory(this, bus, orders_model);
|
||||
_fwf = new FillsWindowFactory(this, bus, wm);
|
||||
_plwf = new PositionWindowFactory(this, bus);
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<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 Source="/view/Controls/Order/OrderTypeItem.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/DoubleMinMaxFilterControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/DiscreteValuesFilterControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/DataGridEx/Filters/Views/TimeFilterControl.xaml"/>
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using mbts.ui;
|
||||
using bts.api.orderman2;
|
||||
using mbts.spark;
|
||||
using static mbts.spark.SparkBusData;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
|
||||
namespace bts.spark
|
||||
{
|
||||
static class SparkCommands
|
||||
static class SparkCommands
|
||||
{
|
||||
|
||||
// Market
|
||||
@@ -42,10 +38,13 @@ namespace bts.spark
|
||||
public static SparkCommand PickLadder =>
|
||||
SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowPickOne, ShowLadder);
|
||||
|
||||
public static PartialCommand<SecurityMD> ShowOrderTicket =>
|
||||
// Order Ticket
|
||||
public static PartialCommand<OrderDefinitionImmutable> ShowOrderTicket =>
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowOrderTicketTag);
|
||||
public static PartialCommand<SecurityMD> ShowOrderTicketFromSecurity =>
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowOrderTicketFromSecurityTag);
|
||||
public static SparkCommand PickOrderTicket =>
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowPickOne, ShowOrderTicket);
|
||||
SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowPickOne, ShowOrderTicketFromSecurity);
|
||||
|
||||
// Spreader
|
||||
public static SparkCommand ShowSyntheticSpreads =>
|
||||
|
||||
@@ -9,26 +9,26 @@ using SecurityList = System.Collections.Generic.IEnumerable<bts.api.SecurityImmu
|
||||
using security_key = System.UInt32;
|
||||
using bts.api.orderman2;
|
||||
|
||||
namespace mbts.spark {
|
||||
namespace mbts.spark
|
||||
{
|
||||
|
||||
static class SparkTags {
|
||||
static class SparkTags
|
||||
{
|
||||
|
||||
public class Nothing { private Nothing() { } }
|
||||
|
||||
internal class SparkTag<T> : ITag<T> { private readonly string Name; public SparkTag(string name="") { Name = name; } public override string ToString() { return Name; } }
|
||||
internal class SparkTag<T> : ITag<T> { private readonly string Name; public SparkTag(string name = "") { Name = name; } public override string ToString() { return Name; } }
|
||||
|
||||
#region Core Data
|
||||
public static ITag<IReadOnlyDictionary<uint, SecurityMD>> SecuritiesTag { get; } = new SparkTag<IReadOnlyDictionary<uint, SecurityMD>>("Securities");
|
||||
public static ITag<SyntheticSecuritiesMessage> SyntheticSecuritiesTag { get; } = new SparkTag<SyntheticSecuritiesMessage>("SyntheticSecuritiesTag");
|
||||
public static ITag<PositionsMessage> PositionsTag { get; } = new SparkTag<PositionsMessage>(nameof(PositionsTag));
|
||||
|
||||
#region Orders
|
||||
|
||||
public static ITag<(OrderDefinitionImmutable definition, double price, uint size)> CreateOrder { get; } = new SparkTag<(OrderDefinitionImmutable, double, uint)>();
|
||||
public static ITag<IEnumerable<OrderKey>> CancelOrders { get; } = new SparkTag<IEnumerable<OrderKey>>();
|
||||
public static ITag<IEnumerable<OrderKey>> CrackOrders { get; } = new SparkTag<IEnumerable<OrderKey>>();
|
||||
public static ITag<(OrderKey key, double price, uint size)> UpdateOrder { get; } = new SparkTag<(OrderKey,double,uint)>();
|
||||
|
||||
public static ITag<IEnumerable<uint>> CancelOrders { get; } = new SparkTag<IEnumerable<uint>>();
|
||||
public static ITag<IEnumerable<uint>> CrackOrders { get; } = new SparkTag<IEnumerable<uint>>();
|
||||
public static ITag<(uint key, double price, uint size)> UpdateOrder { get; } = new SparkTag<(uint, double, uint)>();
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
@@ -43,7 +43,8 @@ namespace mbts.spark {
|
||||
public static ITag<OrderRecordImmutable> ShowModifyOrderTag { get; } = new SparkTag<OrderRecordImmutable>(nameof(ShowModifyOrderTag));
|
||||
public static ITag<OrderID> ShowOrderDetailsTag { get; } = new SparkTag<OrderID>(nameof(ShowOrderDetailsTag));
|
||||
public static ITag<ShowOrderModifyMessage> ShowOrderModifyTag { get; } = new SparkTag<ShowOrderModifyMessage>(nameof(ShowOrderModifyTag));
|
||||
public static ITag<SecurityMD> ShowOrderTicketTag = new SparkTag<SecurityMD>(nameof(ShowOrderTicketTag));
|
||||
public static ITag<SecurityMD> ShowOrderTicketFromSecurityTag = new SparkTag<SecurityMD>(nameof(ShowOrderTicketFromSecurityTag));
|
||||
public static ITag<OrderDefinitionImmutable> ShowOrderTicketTag = new SparkTag<OrderDefinitionImmutable>(nameof(ShowOrderTicketTag));
|
||||
public static ITag<Nothing> ShowPositionsTag { get; } = new SparkTag<Nothing>(nameof(ShowPositionsTag));
|
||||
public static ITag<ShowSpreadMatrixMessage> ShowSpreadMatrixTag { get; } = new SparkTag<ShowSpreadMatrixMessage>(nameof(ShowSpreadMatrixTag));
|
||||
public static ITag<ShowSyntheticCreateMessage> ShowSyntheticCreateTag { get; } = new SparkTag<ShowSyntheticCreateMessage>(nameof(ShowSyntheticCreateTag));
|
||||
@@ -70,8 +71,8 @@ namespace mbts.spark {
|
||||
#endregion
|
||||
|
||||
#region Persist
|
||||
public static ITag<PersistMessage> PersistCommandTag { get; }= new SparkTag<PersistMessage>("PersistCommandTag");
|
||||
public static ITag <PersistedItems>PersistedItemsTag { get; }= new SparkTag<PersistedItems>("PersistedItemsTag");
|
||||
public static ITag<PersistMessage> PersistCommandTag { get; } = new SparkTag<PersistMessage>("PersistCommandTag");
|
||||
public static ITag<PersistedItems> PersistedItemsTag { get; } = new SparkTag<PersistedItems>("PersistedItemsTag");
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using bts.spark;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using static bts.spark.Order;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AlgoTypeItem.xaml
|
||||
/// </summary>
|
||||
public partial class AlgoTypeItem : Control
|
||||
{
|
||||
static AlgoTypeItem() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(AlgoTypeItem), new FrameworkPropertyMetadata(typeof(AlgoTypeItem)));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AlgoTypeProperty = DependencyProperty.Register("AlgoType", typeof(AlgoOrderTypeOneofCase), typeof(AlgoTypeItem), new PropertyMetadata(AlgoOrderTypeOneofCase.None));
|
||||
public AlgoOrderTypeOneofCase AlgoType { get => (AlgoOrderTypeOneofCase)GetValue(AlgoTypeProperty); set => SetValue(AlgoTypeProperty, value); }
|
||||
|
||||
public static readonly DependencyProperty MetadataProperty = DependencyProperty.Register("Metadata", typeof(OrderMetadata), typeof(AlgoTypeItem), new PropertyMetadata(new OrderMetadata { Color = 0, KeyBinding = string.Empty }));
|
||||
public OrderMetadata Metadata { get => GetValue(MetadataProperty) as OrderMetadata; set => SetValue(MetadataProperty, value); }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityTriggerControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style TargetType="uag:AbsolutePriceTriggerControl">
|
||||
<Setter Property="Template">
|
||||
File renamed without changes.
+7
-7
@@ -7,13 +7,13 @@
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<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/TrailingPriceTriggerControl.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/Order/PriceOffsetControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TrailingPriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TimeWindowControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="VerticalSpacing">6.0</sys:Double>
|
||||
<sys:Double x:Key="HorizontalSpacing">6.0</sys:Double>
|
||||
File renamed without changes.
+7
-7
@@ -7,13 +7,13 @@
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<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/TrailingPriceTriggerControl.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/Order/PriceOffsetControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TrailingPriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TimeWindowControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="VerticalSpacing">6.0</sys:Double>
|
||||
<sys:Double x:Key="HorizontalSpacing">6.0</sys:Double>
|
||||
File renamed without changes.
+21
-21
@@ -8,27 +8,27 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<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/BTSStopOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/BTSIcebergOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/PriceOffsetControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TimeWindowControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/BTSStopOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/BTSIcebergOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Popup/PopupControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style TargetType="uag:AlgoDetailsPopupControl">
|
||||
<Style TargetType="uag:OrderDetailsPopupControl">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="uag:AlgoDetailsPopupControl">
|
||||
<ControlTemplate TargetType="uag:OrderDetailsPopupControl">
|
||||
<Grid x:Name="Root">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="0"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox x:Name="PART_AlgoTypeComboBox" ItemsSource="{TemplateBinding ItemsView}" SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch">
|
||||
<ComboBox x:Name="PART_OrderTypeComboBox" ItemsSource="{TemplateBinding ItemsView}" SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch">
|
||||
<ComboBox.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.ContainerStyle>
|
||||
@@ -49,11 +49,11 @@
|
||||
</ComboBox.GroupStyle>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<usp:AlgoTypeItem AlgoType="{Binding algo_type}" Metadata="{Binding meta}"/>
|
||||
<usp:OrderTypeItem OrderType="{Binding order_type}" Metadata="{Binding meta}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<c:PopupControl x:Name="PART_AlgoDetailsPopup" Grid.Column="2"
|
||||
<c:PopupControl x:Name="PART_OrderDetailsPopup" Grid.Column="2"
|
||||
Content="{Binding SelectedItem.order_details, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Visibility="{TemplateBinding HasEditableProperties, Converter={StaticResource BoolToVisibility}}">
|
||||
<c:PopupControl.ContentTemplateSelector>
|
||||
@@ -136,16 +136,16 @@
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="ExpandDirection" Value="Left">
|
||||
<Setter Property="PopupPlacement" TargetName="PART_AlgoDetailsPopup" Value="Left"/>
|
||||
<Setter Property="Margin" TargetName="PART_AlgoDetailsPopup" Value="0,0,2,0" />
|
||||
<Setter Property="Grid.Column" TargetName="PART_AlgoDetailsPopup" Value="0"/>
|
||||
<Setter Property="Grid.Column" TargetName="PART_AlgoTypeComboBox" Value="2"/>
|
||||
<Setter Property="PopupPlacement" TargetName="PART_OrderDetailsPopup" Value="Left"/>
|
||||
<Setter Property="Margin" TargetName="PART_OrderDetailsPopup" Value="0,0,2,0" />
|
||||
<Setter Property="Grid.Column" TargetName="PART_OrderDetailsPopup" Value="0"/>
|
||||
<Setter Property="Grid.Column" TargetName="PART_OrderTypeComboBox" Value="2"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ExpandDirection" Value="Right">
|
||||
<Setter Property="PopupPlacement" TargetName="PART_AlgoDetailsPopup" Value="Right"/>
|
||||
<Setter Property="Margin" TargetName="PART_AlgoDetailsPopup" Value="2,0,0,0" />
|
||||
<Setter Property="Grid.Column" TargetName="PART_AlgoDetailsPopup" Value="2"/>
|
||||
<Setter Property="Grid.Column" TargetName="PART_AlgoTypeComboBox" Value="0"/>
|
||||
<Setter Property="PopupPlacement" TargetName="PART_OrderDetailsPopup" Value="Right"/>
|
||||
<Setter Property="Margin" TargetName="PART_OrderDetailsPopup" Value="2,0,0,0" />
|
||||
<Setter Property="Grid.Column" TargetName="PART_OrderDetailsPopup" Value="2"/>
|
||||
<Setter Property="Grid.Column" TargetName="PART_OrderTypeComboBox" Value="0"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
+21
-30
@@ -1,41 +1,34 @@
|
||||
using bts.spark;
|
||||
using bts.api.orderman;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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.algo
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AlgoDetailsPopupControl.xaml
|
||||
/// Interaction logic for OrderDetailsPopupControl.xaml
|
||||
/// </summary>
|
||||
public class AlgoDetailsPopupControl : Control
|
||||
public class OrderDetailsPopupControl : Control
|
||||
{
|
||||
static AlgoDetailsPopupControl() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(AlgoDetailsPopupControl), new FrameworkPropertyMetadata(typeof(AlgoDetailsPopupControl)));
|
||||
static OrderDetailsPopupControl() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderDetailsPopupControl), new FrameworkPropertyMetadata(typeof(OrderDetailsPopupControl)));
|
||||
}
|
||||
|
||||
public interface IAlgoTypeVM {
|
||||
Order.AlgoOrderTypeOneofCase algo_type { get; }
|
||||
public interface IOrderTypeVM {
|
||||
CustomOrderDefinition.CustomOneofCase order_type { get; }
|
||||
bool is_bts_type { get; }
|
||||
OrderMetadata meta { get; }
|
||||
IMessage order_details { get; }
|
||||
}
|
||||
|
||||
#region ExpandDirection
|
||||
public static readonly DependencyProperty ExpandDirectionProperty = DependencyProperty.Register(nameof(ExpandDirection), typeof(ExpandDirection), typeof(AlgoDetailsPopupControl),
|
||||
public static readonly DependencyProperty ExpandDirectionProperty = DependencyProperty.Register(nameof(ExpandDirection), typeof(ExpandDirection), typeof(OrderDetailsPopupControl),
|
||||
new PropertyMetadata(ExpandDirection.Right, OnExpandDirectionChanged, CoerceExpandDirection));
|
||||
|
||||
private static object CoerceExpandDirection(DependencyObject d, object baseValue) {
|
||||
@@ -47,32 +40,31 @@ namespace mbts.ui.spark.algo
|
||||
}
|
||||
|
||||
private static void OnExpandDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
((AlgoDetailsPopupControl)d).TrySetGridColumnWidths();
|
||||
((OrderDetailsPopupControl)d).TrySetGridColumnWidths();
|
||||
}
|
||||
|
||||
public ExpandDirection ExpandDirection { get => (ExpandDirection)GetValue(ExpandDirectionProperty); set => SetValue(ExpandDirectionProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ItemsSource
|
||||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(IEnumerable<IAlgoTypeVM>), typeof(AlgoDetailsPopupControl),
|
||||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(IEnumerable<IOrderTypeVM>), typeof(OrderDetailsPopupControl),
|
||||
new PropertyMetadata(null, OnItemsSourceChanged, CoerceItemsSource));
|
||||
private static object CoerceItemsSource(DependencyObject d, object baseValue) { return baseValue as IEnumerable<IAlgoTypeVM> ?? Enumerable.Empty<IAlgoTypeVM>(); }
|
||||
private static object CoerceItemsSource(DependencyObject d, object baseValue) { return baseValue as IEnumerable<IOrderTypeVM> ?? Enumerable.Empty<IOrderTypeVM>(); }
|
||||
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var cvs = CollectionViewSource.GetDefaultView(e.NewValue);
|
||||
cvs.GroupDescriptions.Add(new PropertyGroupDescription(nameof(IAlgoTypeVM.is_bts_type)));
|
||||
cvs.SortDescriptions.Add(new SortDescription(nameof(IAlgoTypeVM.is_bts_type), ListSortDirection.Ascending));
|
||||
cvs.GroupDescriptions.Add(new PropertyGroupDescription(nameof(IOrderTypeVM.is_bts_type)));
|
||||
cvs.SortDescriptions.Add(new SortDescription(nameof(IOrderTypeVM.is_bts_type), ListSortDirection.Ascending));
|
||||
d.SetValue(ItemsViewPropertyKey, cvs);
|
||||
}
|
||||
public IEnumerable<IAlgoTypeVM> ItemsSource { get => GetValue(ItemsSourceProperty) as IEnumerable<IAlgoTypeVM>; set => SetValue(ItemsSourceProperty, value); }
|
||||
public IEnumerable<IOrderTypeVM> ItemsSource { get => GetValue(ItemsSourceProperty) as IEnumerable<IOrderTypeVM>; set => SetValue(ItemsSourceProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ItemsView (ReadOnly)
|
||||
private static readonly DependencyPropertyKey ItemsViewPropertyKey = DependencyProperty.RegisterReadOnly(nameof(ItemsView), typeof(ICollectionView), typeof(AlgoDetailsPopupControl), new PropertyMetadata(null));
|
||||
private static readonly DependencyPropertyKey ItemsViewPropertyKey = DependencyProperty.RegisterReadOnly(nameof(ItemsView), typeof(ICollectionView), typeof(OrderDetailsPopupControl), new PropertyMetadata(null));
|
||||
internal static readonly DependencyProperty ItemsViewProperty = ItemsViewPropertyKey.DependencyProperty;
|
||||
internal ICollectionView ItemsView { get => GetValue(ItemsViewProperty) as ICollectionView; private set => SetValue(ItemsViewPropertyKey, value); }
|
||||
#endregion
|
||||
|
||||
|
||||
#region HasEditableProperties
|
||||
|
||||
public bool HasEditableProperties {
|
||||
@@ -81,20 +73,19 @@ namespace mbts.ui.spark.algo
|
||||
}
|
||||
|
||||
public static readonly DependencyPropertyKey HasEditablePropertiesProperty =
|
||||
DependencyProperty.RegisterReadOnly("HasEditableProperties", typeof(bool), typeof(AlgoDetailsPopupControl), new PropertyMetadata(true));
|
||||
DependencyProperty.RegisterReadOnly("HasEditableProperties", typeof(bool), typeof(OrderDetailsPopupControl), new PropertyMetadata(true));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(IAlgoTypeVM), typeof(AlgoDetailsPopupControl),
|
||||
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(IOrderTypeVM), typeof(OrderDetailsPopupControl),
|
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedItemChanged));
|
||||
|
||||
private static void SelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs baseValue) {
|
||||
var item = ((AlgoDetailsPopupControl)d).SelectedItem;
|
||||
var item = ((OrderDetailsPopupControl)d).SelectedItem;
|
||||
d.SetValue(HasEditablePropertiesProperty, !item.meta.NoProps);
|
||||
}
|
||||
|
||||
public IAlgoTypeVM SelectedItem { get => GetValue(SelectedItemProperty) as IAlgoTypeVM; set => SetValue(SelectedItemProperty, value); }
|
||||
public IOrderTypeVM SelectedItem { get => GetValue(SelectedItemProperty) as IOrderTypeVM; set => SetValue(SelectedItemProperty, value); }
|
||||
|
||||
private void TrySetGridColumnWidths() {
|
||||
var grid = GetTemplateChild("Root") as Grid;
|
||||
File renamed without changes.
File renamed without changes.
+6
-6
@@ -3,20 +3,20 @@
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:uspcv="clr-namespace:mbts.ui.spark.converters">
|
||||
<uspcv:AlgoTypeDisplayBrushConverter x:Key="AlgoTypeDisplayBrushConverter"/>
|
||||
<uspcv:AlgoTypeDisplayTextConverter x:Key="AlgoTypeDisplayTextConverter"/>
|
||||
<Style TargetType="usp:AlgoTypeItem">
|
||||
<uspcv:OrderTypeBrushConverter x:Key="OrderTypeBrushConverter"/>
|
||||
<uspcv:OrderTypeDisplayTextConverter x:Key="OrderTypeDisplayTextConverter"/>
|
||||
<Style TargetType="usp:OrderTypeItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="usp:AlgoTypeItem">
|
||||
<ControlTemplate TargetType="usp:OrderTypeItem">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:Badge Background="{Binding Metadata, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource AlgoTypeDisplayBrushConverter}}" Width="15" Height="10" HorizontalAlignment="Left" />
|
||||
<TextBlock Text="{Binding AlgoType, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource AlgoTypeDisplayTextConverter}}" Margin="20,0,0,0" HorizontalAlignment="Left" />
|
||||
<c:Badge Background="{Binding Metadata, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource OrderTypeBrushConverter}}" Width="15" Height="10" HorizontalAlignment="Left" />
|
||||
<TextBlock Text="{Binding OrderType, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource OrderTypeDisplayTextConverter}}" Margin="20,0,0,0" HorizontalAlignment="Left" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
@@ -0,0 +1,25 @@
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for OrderTypeItem.xaml
|
||||
/// </summary>
|
||||
public partial class OrderTypeItem : Control
|
||||
{
|
||||
static OrderTypeItem() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(OrderTypeItem), new FrameworkPropertyMetadata(typeof(OrderTypeItem)));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OrderTypeProperty = DependencyProperty.Register(nameof(OrderType), typeof(CustomOrderDefinition.CustomOneofCase), typeof(OrderTypeItem),
|
||||
new PropertyMetadata(CustomOrderDefinition.CustomOneofCase.None));
|
||||
public CustomOrderDefinition.CustomOneofCase OrderType { get => (CustomOrderDefinition.CustomOneofCase)GetValue(OrderTypeProperty); set => SetValue(OrderTypeProperty, value); }
|
||||
|
||||
public static readonly DependencyProperty MetadataProperty = DependencyProperty.Register(nameof(Metadata), typeof(OrderMetadata), typeof(OrderTypeItem),
|
||||
new PropertyMetadata(new OrderMetadata { Color = 0, KeyBinding = string.Empty }));
|
||||
public OrderMetadata Metadata { get => GetValue(MetadataProperty) as OrderMetadata; set => SetValue(MetadataProperty, value); }
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+2
-2
@@ -5,8 +5,8 @@
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/TrailingPriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/TrailingPriceTriggerControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<cv:ValueConverterPipe x:Key="AbsoluteTriggerVisibilityConverter">
|
||||
<cv:StaticValueEqualsConverter Value="{u:Enum AbsolutePriceTrigger, Type={u:Nested sp:PriceTrigger.TriggerOneofCase}}"/>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -5,7 +5,7 @@
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/QuantityMeasureControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<uag:QuantityTriggerRelationDisplayTextConverter x:Key="QuantityTriggerRelationTextConverter"/>
|
||||
<Style TargetType="uag:QuantityTriggerControl">
|
||||
File renamed without changes.
+1
-1
@@ -3,7 +3,7 @@
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/OrderTimeControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/OrderTimeControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">6.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">6.0</sys:Double>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -6,7 +6,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.spark.converters
|
||||
{
|
||||
internal class AlgoTypeDisplayBrushConverter : IValueConverter
|
||||
internal class OrderTypeBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
var metadata = value as OrderMetadata;
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
using bts.spark;
|
||||
using bts.api.orderman2;
|
||||
using mbts.spark;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
@@ -6,10 +6,10 @@ using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark.converters
|
||||
{
|
||||
internal class AlgoTypeDisplayTextConverter : IValueConverter
|
||||
internal class OrderTypeDisplayTextConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return OrderUtils.algo_display_name((Order.AlgoOrderTypeOneofCase)value);
|
||||
return OrderUtils.order_type_display_name((CustomOrderDefinition.CustomOneofCase)value);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
@@ -1,32 +1,41 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using static mbts.ui.utilities.DisplayNameHelper;
|
||||
|
||||
namespace mbts.spark {
|
||||
public static class OrderUtils {
|
||||
|
||||
public static string display_name(this IMessage order) {
|
||||
return camel_to_title_case(order.Descriptor.Name);
|
||||
static class OrderUtils {
|
||||
#region OrderRecordImmutable methods
|
||||
public static uint filled(OrderRecordImmutable order) => order.State.FilledQuantity;
|
||||
public static double fill_ratio(OrderRecordImmutable order) {
|
||||
var size = order.State.Quantity;
|
||||
return filled(order) / (double)size;
|
||||
}
|
||||
|
||||
public static string algo_display_name(Order.AlgoOrderTypeOneofCase algo) {
|
||||
return algo_display_name(algo.ToString());
|
||||
}
|
||||
|
||||
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) {
|
||||
return order.Fills.Sum(fill => fill.Size);
|
||||
public static string full_description(this OrderRecordImmutable order, SecurityImmutable security) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Price: ");
|
||||
sb.AppendLine(TickUtils.format(security.ContractSpec, order.State.Price));
|
||||
sb.AppendLine($"Filled: {filled(order)} / {order.State.Quantity}");
|
||||
sb.AppendLine($"Time: {order.Def.TimeInForce}");
|
||||
return sb.ToString();
|
||||
}
|
||||
public static string short_description(this OrderRecordImmutable order) =>
|
||||
$"{order.Def.Side} {order.State.Quantity} at {order.State.Price}";
|
||||
public static bool has_parent(this OrderRecordImmutable order) => order.ParentKey != 0;
|
||||
#endregion
|
||||
|
||||
public static string display_name(this IMessage order) => camel_to_title_case(order.Descriptor.Name);
|
||||
public static string order_type_display_name(CustomOrderDefinition.CustomOneofCase order_type) => order_type_display_name(order_type.ToString());
|
||||
public static string order_type_display_name(string algo_name) => camel_to_title_case(Regex.Replace(algo_name, "Order", string.Empty, RegexOptions.IgnoreCase));
|
||||
public static long filled(OrderBookEntry order) => order.Fills.Sum(fill => fill.Size);
|
||||
public static double fill_ratio(OrderBookEntry order) {
|
||||
var size = order.order().Size;
|
||||
return filled(order) / (double)size;
|
||||
@@ -46,20 +55,17 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public static bool is_active(OrderStatus order) {
|
||||
return order != null && order.Status != OrderStatus.Types.Status.Canceled &&
|
||||
order.Status != OrderStatus.Types.Status.Done &&
|
||||
order.Status != OrderStatus.Types.Status.Expired &&
|
||||
order.Status != OrderStatus.Types.Status.Filled &&
|
||||
order.Status != OrderStatus.Types.Status.Rejected &&
|
||||
order.Status != OrderStatus.Types.Status.Stopped &&
|
||||
order.Status != OrderStatus.Types.Status.Suspended;
|
||||
public static bool is_active(bts.spark.OrderStatus order) =>
|
||||
order != null && order.Status != bts.spark.OrderStatus.Types.Status.Canceled &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Done &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Expired &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Filled &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Rejected &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Stopped &&
|
||||
order.Status != bts.spark.OrderStatus.Types.Status.Suspended;
|
||||
|
||||
}
|
||||
|
||||
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}";
|
||||
}
|
||||
public static string order_summary(OrderBookEntry order) =>
|
||||
$"{camel_to_title_case(order.order().AlgoOrderTypeCase.ToString())}: {order.order().Side} {order.order().Size} at {order.order().Price}";
|
||||
|
||||
public static IEnumerable<string> order_custom_props(OrderBookEntry order) {
|
||||
var o = algo_value(order.order());
|
||||
@@ -70,8 +76,8 @@ namespace mbts.spark {
|
||||
|
||||
public static class Compare {
|
||||
public static readonly IComparer<Order> DepthComparer = CompareUtils.NullCheckComparer<Order>(depth_compare_never_null);
|
||||
public static int depth_compare(Order x, Order y) { return CompareUtils.NullCheckCompare(x, y, depth_compare_never_null); }
|
||||
private static int depth_compare_never_null(Order x, Order y) { return x.Side == y.Side ? x.Side == Side.Buy ? y.Price.CompareTo(x.Price) : x.Price.CompareTo(y.Price) : x.Side == Side.Buy ? 1 : -1; }
|
||||
public static int depth_compare(Order x, Order y) => CompareUtils.NullCheckCompare(x, y, depth_compare_never_null);
|
||||
private static int depth_compare_never_null(Order x, Order y) => x.Side == y.Side ? x.Side == Side.Buy ? y.Price.CompareTo(x.Price) : x.Price.CompareTo(y.Price) : x.Side == Side.Buy ? 1 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using bts.api;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
public class SparkUtils
|
||||
static class SparkUtils
|
||||
{
|
||||
#region Serialization
|
||||
public static T deserialize_proto<T>(byte[] proto_bytes)
|
||||
@@ -44,5 +42,8 @@ namespace mbts.spark
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static async Task<SecurityImmutable> get_security_async(IBus bus, uint security_key) =>
|
||||
await bus.subscribe(SparkTags.SecuritiesTag).Where(map => map.ContainsKey(security_key)).Select(map => map[security_key].security).FirstAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using Google.Protobuf;
|
||||
using bts.api;
|
||||
using mbts.co2;
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace mbts.spark {
|
||||
namespace mbts.spark
|
||||
{
|
||||
class LadderModel
|
||||
{
|
||||
readonly OrdersModel _order_gateway;
|
||||
|
||||
class LadderModel {
|
||||
|
||||
private DemoOrdersModel _order_gateway;
|
||||
|
||||
public LadderModel(SecurityMD source, DemoOrdersModel ordergw) {
|
||||
public LadderModel(SecurityMD source, OrdersModel ordergw) {
|
||||
security = source.security;
|
||||
md = source.md;
|
||||
_order_gateway = ordergw;
|
||||
}
|
||||
|
||||
public SecurityImmutable security { get; }
|
||||
public IMDHandle md { get; }
|
||||
public IMDHandle md { get; }
|
||||
|
||||
public enum CancelType { All, Bids, Asks }
|
||||
|
||||
public void cancel_orders(CancelType ct) {
|
||||
order_gateway.cancel_security_orders (new uint[] {security.Id}, ct == CancelType.Bids || ct == CancelType.All, ct == CancelType.Asks || ct == CancelType.All);
|
||||
switch (ct) {
|
||||
case CancelType.All: _order_gateway.cancel_security_orders(security.Id).ignore(); break;
|
||||
case CancelType.Bids: _order_gateway.cancel_security_buy_orders(security.Id).ignore(); break;
|
||||
case CancelType.Asks: _order_gateway.cancel_security_sell_orders(security.Id).ignore(); break;
|
||||
default: Logger.warn(bts.log.Subsystem.Ui, $"Well, this is odd, {nameof(LadderModel)} has encountered an unexpected {nameof(CancelType)} request: {ct}"); return;
|
||||
}
|
||||
Logger.info(bts.log.Subsystem.Ui, $"Cancel {ct}");
|
||||
}
|
||||
|
||||
public DemoOrdersModel order_gateway => _order_gateway;
|
||||
public OrdersModel order_gateway => _order_gateway;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,33 @@
|
||||
using mbts.ui.shell;
|
||||
using bts.api;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.co2;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using System.Reactive.Linq;
|
||||
using mbts.co2;
|
||||
using System.Reactive.Subjects;
|
||||
using mbts.ui;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using bts.api;
|
||||
using mbts.ui.utility;
|
||||
using mbts.spark.utilities;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderVM : DisposableViewModelBase, IKeyListener {
|
||||
namespace mbts.spark
|
||||
{
|
||||
class LadderVM : DisposableViewModelBase, IKeyListener
|
||||
{
|
||||
readonly IBus _bus;
|
||||
readonly LadderModel _model;
|
||||
readonly DispatcherTimer _timer;
|
||||
Order _order_template;
|
||||
OrderDefinition _order_template;
|
||||
LadderSettings _settings;
|
||||
|
||||
public LadderVM(LadderModel model, IObservable<LadderSettings> settings) {
|
||||
public LadderVM(IBus bus, LadderModel model, IObservable<LadderSettings> settings) {
|
||||
_bus = bus;
|
||||
_model = model;
|
||||
_order_template = OrderDataHelper.Defaults.Order(_model.security);
|
||||
_timer = new DispatcherTimer() {
|
||||
Interval = TimeSpan.FromMilliseconds(100),
|
||||
IsEnabled = true
|
||||
};
|
||||
_timer.Tick += tick;
|
||||
_order_template = OrderDataHelper.Defaults.OrderDefinition(_model.security);
|
||||
|
||||
_high = backing(nameof(high), "");
|
||||
_low = backing(nameof(low), "");
|
||||
@@ -48,21 +43,23 @@ namespace mbts.spark {
|
||||
send_order_command = new DelegateCommand<(double, Side?)>(send_order);
|
||||
|
||||
// Order
|
||||
_selected_order_type = backing(nameof(selected_order_type), Order.Types.TimeInForce.Day);
|
||||
algo_types = OrderDataHelper.Defaults.Algos.SelectMany(wrap_order).ToArray();
|
||||
_selected_time_in_force = backing(nameof(selected_order_type), TimeInForce.Day);
|
||||
order_types = OrderDataHelper.Defaults.Algos.SelectMany(wrap_order).ToArray();
|
||||
_revert = backing(nameof(revert), false);
|
||||
show_ticket_command = new DelegateCommand(show_ticket);
|
||||
|
||||
// Orders
|
||||
_internal_orders = new ObservableCollection<OrderBookEntry>();
|
||||
orders = new ObservableAutoWrapper<OrderVM, OrderBookEntry>(_internal_orders, create_ordervm);
|
||||
_internal_orders = _model.order_gateway.get_security_orders_collection(security.Id);
|
||||
orders = new ObservableAutoWrapper<OrderVM, OrderRecordImmutable>(_internal_orders, create_ordervm);
|
||||
|
||||
// Settings
|
||||
this.settings = settings;
|
||||
_dispose = Disposable.Create(
|
||||
_internal_orders,
|
||||
calculator,
|
||||
settings.Subscribe(settings_updated),
|
||||
model.order_gateway.on_orderbook().ObserveOnDispatcher().Subscribe(orders_updated));
|
||||
WorkLoop.Start(tick)
|
||||
);
|
||||
}
|
||||
|
||||
internal LadderModel model => _model;
|
||||
@@ -71,17 +68,16 @@ namespace mbts.spark {
|
||||
|
||||
public bool is_synthetic => _model.security.ContractCase == Security.ContractOneofCase.Synthetic;
|
||||
|
||||
private void tick(object sender, EventArgs e) {
|
||||
void tick() {
|
||||
update_header();
|
||||
on_tick?.Invoke();
|
||||
}
|
||||
public event Action on_tick;
|
||||
// Use an ISubject to allow child elements to subscribe without leaking
|
||||
|
||||
void settings_updated(LadderSettings settings) {
|
||||
if (selected_algo_type == null) {
|
||||
selected_algo_type = algo_types.FirstOrDefault(o => o.type_name == settings.SelectedAlgo);
|
||||
_selected_order_type.Value = (Order.Types.TimeInForce)Enum.Parse(typeof(Order.Types.TimeInForce), settings.DefaultTimeInForce);
|
||||
if (selected_order_type == null) {
|
||||
selected_order_type = order_types.FirstOrDefault(o => o.type_name == settings.SelectedAlgo);
|
||||
_selected_time_in_force.Value = (TimeInForce)Enum.Parse(typeof(TimeInForce), settings.DefaultTimeInForce);
|
||||
}
|
||||
if (calculator.value == 0) calculator.value = (settings.size);
|
||||
_settings = settings;
|
||||
@@ -91,7 +87,7 @@ namespace mbts.spark {
|
||||
|
||||
#region Header properties
|
||||
ulong _misc_time = 0;
|
||||
private void update_header() {
|
||||
void update_header() {
|
||||
if (_misc_time != _model.md.misc_timestamp) {
|
||||
var spec = security.ContractSpec;
|
||||
_high.set(spec.format(md.session_high));
|
||||
@@ -101,8 +97,7 @@ namespace mbts.spark {
|
||||
md.get_last_trade(ref unused, out NativePriceSize last, out DateTime time, out ulong volume);
|
||||
if (!double.IsNaN(last.price)) {
|
||||
_change.set(spec.format(last.price - md.settlement_price));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
unused = 0;
|
||||
_model.md.get_bbo(ref unused, out NativePriceSize bid, out NativePriceSize ask);
|
||||
double mid = TickUtils.mid_tick(spec, bid.price, ask.price);
|
||||
@@ -140,24 +135,21 @@ namespace mbts.spark {
|
||||
public ICommand send_order_command { get; }
|
||||
public ICommand show_ticket_command { get; }
|
||||
|
||||
internal void show_ticket() {
|
||||
_model.order_gateway.show_order_ticket(_order_template.Clone());
|
||||
}
|
||||
internal void show_ticket() =>
|
||||
_bus.post(SparkTags.ShowOrderTicketTag, _order_template.Clone());
|
||||
|
||||
public void send_order((double price,Side? side) args) {
|
||||
public void send_order((double price, Side? side) args) {
|
||||
if (args.side.HasValue) {
|
||||
Order order = _order_template.Clone();
|
||||
order.Size = (uint)Math.Abs(calculator.value);
|
||||
order.Price = args.price;
|
||||
OrderDefinition order = _order_template.Clone();
|
||||
order.Side = args.side.Value;
|
||||
order.TimeInForce = selected_order_type;
|
||||
_model.order_gateway.send_order(order);
|
||||
order.TimeInForce = selected_time_in_force;
|
||||
_model.order_gateway.send_order(order, args.price, (uint)Math.Abs(calculator.value)).ignore();
|
||||
}
|
||||
if (revert) {
|
||||
foreach (var algo in algo_types) {
|
||||
foreach (var algo in order_types) {
|
||||
algo.reset();
|
||||
calculator.value = _settings.size;
|
||||
RaisePropertyChanged(nameof(selected_algo_type));
|
||||
RaisePropertyChanged(nameof(selected_order_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,76 +159,48 @@ namespace mbts.spark {
|
||||
|
||||
public string[] accounts { get; } = ImportedResources.Accounts;
|
||||
public string account { get => _order_template.Account; set => _order_template.Account = value; }
|
||||
public Order.Types.TimeInForce[] order_types => Enum.GetValues(typeof(Order.Types.TimeInForce)).Cast<Order.Types.TimeInForce>().ToArray();
|
||||
Property<Order.Types.TimeInForce> _selected_order_type;
|
||||
public Order.Types.TimeInForce selected_order_type { get => _selected_order_type.Value; set => _selected_order_type.Value = value; }
|
||||
public TimeInForce[] time_in_forces => Enum.GetValues(typeof(TimeInForce)).Cast<TimeInForce>().ToArray();
|
||||
Property<TimeInForce> _selected_time_in_force;
|
||||
public TimeInForce selected_time_in_force { get => _selected_time_in_force.Value; set => _selected_time_in_force.Value = value; }
|
||||
|
||||
IEnumerable<OrderTypeVM> wrap_order(IMessage order) {
|
||||
var meta = _model.order_gateway.get_metadata(order);
|
||||
var meta = OrderDataHelper.get_metadata(order);
|
||||
if (meta != null) {
|
||||
return new[] { new OrderTypeVM(_order_template, order, meta) };
|
||||
return new[] { new OrderTypeVM(_order_template.CustomDef, order, meta) };
|
||||
}
|
||||
return new OrderTypeVM[0];
|
||||
}
|
||||
public OrderTypeVM[] algo_types { get; }
|
||||
public OrderTypeVM selected_algo_type {
|
||||
get => algo_types.FirstOrDefault(o => o.is_selected);
|
||||
public OrderTypeVM[] order_types { get; }
|
||||
public OrderTypeVM selected_order_type {
|
||||
get => order_types.FirstOrDefault(o => o.is_selected);
|
||||
set {
|
||||
value.is_selected = true;
|
||||
RaisePropertyChanged("selected_algo_type");
|
||||
RaisePropertyChanged(nameof(selected_order_type));
|
||||
}
|
||||
}
|
||||
|
||||
readonly ObservableCollection<OrderBookEntry> _internal_orders;
|
||||
readonly ITableUpdateCollection<OrderRecordImmutable, uint> _internal_orders;
|
||||
public ObservableCollection<OrderVM> orders { get; }
|
||||
|
||||
IOrderBook _order_book;
|
||||
OrderVM create_ordervm(OrderBookEntry status) {
|
||||
var metadata = _model.order_gateway.get_metadata(status.order());
|
||||
OrderVM create_ordervm(OrderRecordImmutable order) {
|
||||
var metadata = OrderDataHelper.get_metadata(order.Def.CustomDef.CustomCase);
|
||||
// try to get the parent order. There might not be one.
|
||||
OrderMetadata parent_metadata = null;
|
||||
if (status.parent_id() != null) {
|
||||
OrderBookEntry parent = _order_book.get_order(status.parent_id());
|
||||
if (parent != null) {
|
||||
parent_metadata = _model.order_gateway.get_metadata(parent.order());
|
||||
}
|
||||
}
|
||||
return new OrderVM(status, metadata, parent_metadata, this);
|
||||
if (order.has_parent() && _internal_orders.TryGetValue(order.ParentKey, out OrderRecordImmutable parent))
|
||||
parent_metadata = OrderDataHelper.get_metadata(parent.Def.CustomDef.CustomCase);
|
||||
return new OrderVM(order, metadata, parent_metadata, this);
|
||||
}
|
||||
|
||||
void orders_updated(IOrderBook input) {
|
||||
_order_book = input;
|
||||
var my_orders = input.get_active_orders_for_security(_model.security.Id).ToList();
|
||||
if (_internal_orders.sync_with_setwise(my_orders)) {
|
||||
foreach (var o in orders) {
|
||||
var i = input.get_order(o.id);
|
||||
//Logger.notnull(i);
|
||||
if (i == null) {
|
||||
var msg = String.Join(" ",my_orders.Select(m => m.ID().Id));
|
||||
Logger.error(bts.log.Subsystem.Ui, $"Equality problem in order {o.id} should be in {msg}.");
|
||||
}
|
||||
if (i != null) {
|
||||
o.update(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keyboard support
|
||||
public void key_down(KeyEventArgs e) {
|
||||
var new_order_type = algo_types.FirstOrDefault(o => o.key_match(e));
|
||||
var new_order_type = order_types.FirstOrDefault(o => o.key_match(e));
|
||||
if (new_order_type != null) {
|
||||
new_order_type.is_selected = true;
|
||||
RaisePropertyChanged("selected_algo_type");
|
||||
RaisePropertyChanged(nameof(selected_order_type));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AlgoDetailsPopupControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/OrderDetailsPopupControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToInVisibility" VisibilityForTrue="Collapsed" VisibilityForFalse="Visible" />
|
||||
<converters:BooleanToObjectConverter x:Key="bool_to_margin">
|
||||
@@ -40,8 +40,8 @@
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<ComboBox Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
|
||||
<ComboBox ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}" Margin="2" />
|
||||
<uag:AlgoDetailsPopupControl ItemsSource="{Binding algo_types}" SelectedItem="{Binding selected_algo_type}" Margin="2" ExpandDirection="Left"/>
|
||||
<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>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using bts.spark;
|
||||
using bts.api.orderman;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using mbts.spark.utilities;
|
||||
@@ -7,23 +9,25 @@ using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
public class OrderTypeVM : ui.spark.algo.AlgoDetailsPopupControl.IAlgoTypeVM {
|
||||
public class OrderTypeVM : ui.spark.algo.OrderDetailsPopupControl.IOrderTypeVM
|
||||
{
|
||||
// this template is shared with the parent vm so mutations are visible
|
||||
Order _order_template;
|
||||
CustomOrderDefinition _order_template;
|
||||
IFieldAccessor _accessor;
|
||||
byte[] _details_template;
|
||||
|
||||
public OrderTypeVM(Order order_template, IMessage order, OrderMetadata meta) {
|
||||
public OrderTypeVM(CustomOrderDefinition order_template, IMessage order, OrderMetadata meta) {
|
||||
Logger.assert(order_template != null);
|
||||
Logger.assert(order != null);
|
||||
_order_template = order_template;
|
||||
this.meta = meta;
|
||||
type_name = order.Descriptor.Name;
|
||||
display_name = OrderUtils.algo_display_name(order.Descriptor.Name);
|
||||
display_name = OrderUtils.order_type_display_name(order.Descriptor.Name);
|
||||
is_bts_type = order.Descriptor.Name.StartsWith("BTS", StringComparison.CurrentCultureIgnoreCase);
|
||||
algo_type = OrderDataHelper.get_algo_type(order);
|
||||
_accessor = Order.Descriptor.Oneofs
|
||||
.First(ood => ood.Name == "AlgoOrderType")
|
||||
order_type = OrderDataHelper.get_algo_type(order);
|
||||
var vals = CustomOrderDefinition.Descriptor.Oneofs.ToList();
|
||||
_accessor = CustomOrderDefinition.Descriptor.Oneofs
|
||||
.First(ood => ood.Name == "custom")
|
||||
.Fields
|
||||
.First(f => f.MessageType == order.Descriptor)
|
||||
.Accessor;
|
||||
@@ -35,7 +39,7 @@ namespace mbts.spark {
|
||||
public string display_name { get; }
|
||||
public string type_name { get; }
|
||||
public bool is_bts_type { get; }
|
||||
public Order.AlgoOrderTypeOneofCase algo_type { get; }
|
||||
public CustomOrderDefinition.CustomOneofCase order_type { get; }
|
||||
public OrderMetadata meta { get; }
|
||||
public IMessage order_details { get; private set; }
|
||||
|
||||
@@ -51,7 +55,8 @@ namespace mbts.spark {
|
||||
get {
|
||||
// If this is set on the order we are selected
|
||||
// If anything else is set the protobuf will null this out automatically (because it's a OneOf)
|
||||
return _accessor.GetValue(_order_template) != null;
|
||||
var val = _accessor.GetValue(_order_template);
|
||||
return val != null;
|
||||
}
|
||||
set {
|
||||
// setting this value clears the other values automatically
|
||||
@@ -63,5 +68,4 @@ namespace mbts.spark {
|
||||
return key.Key == (Key.A + display_name[0] - 'A');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +1,33 @@
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using bts.api;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using security_key = System.UInt32;
|
||||
using bts.api;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
class OrderVM : ViewModelBase, IEquatable<OrderVM>
|
||||
{
|
||||
readonly LadderVM _parent;
|
||||
|
||||
namespace mbts.spark {
|
||||
class OrderVM : ViewModelBase, IEquatable<OrderVM> {
|
||||
LadderVM _parent;
|
||||
LadderModel model => _parent.model;
|
||||
OrderBookEntry _order;
|
||||
OrderRecordImmutable _order;
|
||||
Color _color, _colorbg = Colors.White, _dark, _darkbg = Color.FromRgb(0xbf, 0xbf, 0xbf);
|
||||
|
||||
public OrderVM(OrderBookEntry status, OrderMetadata meta, OrderMetadata parentmeta, LadderVM parent) {
|
||||
public OrderVM(OrderRecordImmutable order, OrderMetadata meta, OrderMetadata parentmeta, LadderVM parent) {
|
||||
Logger.notnull(meta);
|
||||
|
||||
_parent = parent;
|
||||
_order = status;
|
||||
_order = order;
|
||||
_color = parentmeta == null ? meta.Color.rgb_color() : Colors.White;
|
||||
var darker = BTSColor.darken2(_color.R, _color.G, _color.B, 0.75);
|
||||
_dark = new Color() { A = 255, R = darker.r, G = darker.g, B = darker.b };
|
||||
var fill_ratio = OrderUtils.fill_ratio(status);
|
||||
var fill_ratio = OrderUtils.fill_ratio(order);
|
||||
background = mkbrush(_color, _colorbg, fill_ratio);
|
||||
hoverbackground = mkbrush(_dark, _darkbg, fill_ratio);
|
||||
border = _order.order().Side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
border = _order.Def.Side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
}
|
||||
|
||||
Brush mkbrush(Color color, Color endcolor, double pct_complete) {
|
||||
@@ -43,8 +41,8 @@ namespace mbts.spark {
|
||||
EndPoint = new System.Windows.Point(1, 0.5)
|
||||
};
|
||||
}
|
||||
public void update(OrderBookEntry neworder) {
|
||||
Logger.notnull(neworder);
|
||||
|
||||
public void update(OrderRecordImmutable neworder) {
|
||||
if (neworder.Equals(_order)) return;
|
||||
using (detect_property_changes()) {
|
||||
// update brushes
|
||||
@@ -55,53 +53,37 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public OrderID id => _order.order().Id;
|
||||
public security_key security_key => _parent.security.Id;
|
||||
public double price => _order.order().Price;
|
||||
public uint id => _order.Key;
|
||||
public uint security_key => _parent.security.Id;
|
||||
public double price => _order.State.Price;
|
||||
|
||||
public string text => "";
|
||||
string _buy_sell_indicator => _order.Def.Side == Side.Buy ? "B" : "S";
|
||||
public string line1 => $"{_buy_sell_indicator}:{OrderUtils.filled(_order)}";
|
||||
public string line2 => $"W:{_order.State.Quantity - OrderUtils.filled(_order)}";
|
||||
|
||||
private string buy_sell_indicator => _order.order().Side == Side.Buy ? "B" : "S";
|
||||
public string summary => _order.short_description();
|
||||
public string description => _order.full_description(_parent.security);
|
||||
public bool has_parent => _order.has_parent();
|
||||
|
||||
public string line1 => $"{buy_sell_indicator}:{OrderUtils.filled(_order)}";
|
||||
public string line2 => $"W:{_order.order().Size - OrderUtils.filled(_order)}";
|
||||
|
||||
public string summary => OrderUtils.order_summary(_order);
|
||||
|
||||
string generate_desc() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Price: ");
|
||||
sb.AppendLine(TickUtils.format(_order.order().Security.ContractSpec, _order.order().Price));
|
||||
sb.AppendLine($"Filled: {OrderUtils.filled(_order)} / {_order.order().Size}");
|
||||
sb.AppendLine($"Time: {_order.order().TimeInForce}");
|
||||
sb.AppendLine(string.Join("\n", OrderUtils.order_custom_props(_order)));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string description => generate_desc();
|
||||
|
||||
// == is_child
|
||||
public bool has_parent => _order.parent_id() != null;
|
||||
|
||||
public ICommand shatter_command => new DelegateCommand(_ => model.order_gateway.shatter(_order.order().Id), _ => !has_parent);
|
||||
public ICommand cancel_command => new DelegateCommand(_ => model.order_gateway.cancel_order(new OrderID[] {_order.order().Id}), _ => !has_parent);
|
||||
public ICommand modify_command => new DelegateCommand(() => model.order_gateway.show_order_modify(_order.order().Clone()), () => !has_parent);
|
||||
public ICommand shatter_command => new DelegateCommand(_ => model.order_gateway.crack_order(_order.Key).ignore(), _ => !has_parent);
|
||||
public ICommand cancel_command => new DelegateCommand(_ => model.order_gateway.cancel_order(_order.Key).ignore(), _ => !has_parent);
|
||||
public ICommand modify_command => new DelegateCommand(() => { /*TODO*/ }, () => !has_parent);
|
||||
|
||||
public Brush foreground => Brushes.Black;
|
||||
public Brush background { get; private set; }
|
||||
public Brush hoverbackground { get; private set; }
|
||||
public Brush header_brush => _order.order().Side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
|
||||
public Brush header_brush => _order.Def.Side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public Brush border { get; }
|
||||
public double opacity => has_parent ? 0.5 : 1.0;
|
||||
|
||||
public Brush border { get; }
|
||||
|
||||
bool IEquatable<OrderVM>.Equals(OrderVM other) {
|
||||
return this.safe_equals(other, (a, b) => a.id == b.id);
|
||||
}
|
||||
bool IEquatable<OrderVM>.Equals(OrderVM other) =>
|
||||
this.safe_equals(other, (a, b) => a.id == b.id);
|
||||
|
||||
public bool try_change_price(double newprice) {
|
||||
return model.order_gateway.change_price(id, newprice);
|
||||
if (newprice == price) return false;
|
||||
_parent.model.order_gateway.update_order(_order.Key, newprice, _order.State.Quantity).ignore();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AlgoDetailsPopupControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Order/OrderDetailsPopupControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="HorizontalSpacing">8.0</sys:Double>
|
||||
<sys:Double x:Key="VerticalSpacing">4.0</sys:Double>
|
||||
@@ -99,7 +99,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
<ComboBox Grid.ColumnSpan="2" Margin="0,2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
|
||||
<ComboBox Grid.Row="1" Grid.ColumnSpan="2" Margin="0,2" ItemsSource="{Binding time_in_forces}" SelectedItem="{Binding time_in_force}"/>
|
||||
<uag:AlgoDetailsPopupControl Grid.Row="2" Margin="0,2" ItemsSource="{Binding algo_types}" SelectedItem="{Binding algo_type}"/>
|
||||
<uag:OrderDetailsPopupControl Grid.Row="2" Margin="0,2" ItemsSource="{Binding algo_types}" SelectedItem="{Binding algo_type}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -5,10 +5,8 @@ using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -32,7 +30,7 @@ namespace mbts.spark
|
||||
private IEnumerable<OrderTypeVM> _get_algo_types() {
|
||||
return OrderDataHelper.Defaults.Algos.Select(algo => {
|
||||
var meta = _model.get_metadata(algo);
|
||||
return meta != null ? new OrderTypeVM(_order, algo, meta) : null;
|
||||
return meta != null ? new OrderTypeVM(OrderDataHelper.Defaults.CustomOrderDefinition, algo, meta) : null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.spark;
|
||||
using System.Reactive.Linq;
|
||||
using mbts.ui;
|
||||
using Google.Protobuf;
|
||||
using mbts.utils;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.ui;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -140,14 +140,14 @@ namespace mbts.spark
|
||||
#region Output
|
||||
|
||||
public IObservable<TableUpdate<OrderRecordImmutable, uint>> on_orders => _service.subscribei_orders().Table();//.Publish().RefCount();
|
||||
|
||||
|
||||
public IObservable<IReadOnlyCollection<FillImmutable>> on_fills => _service.subscribei_fills().Select(u => u.all);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Input
|
||||
|
||||
public async Task<OrderKey?> send_order(OrderDefinitionImmutable order, double price, uint size) {
|
||||
public async Task<uint?> send_order(OrderDefinitionImmutable order, double price, uint size) {
|
||||
var result = await _service.create_order_async(new Create() {
|
||||
NewOrder = order.CloneToMutable(),
|
||||
Price = price,
|
||||
@@ -156,43 +156,39 @@ namespace mbts.spark
|
||||
return handle_error(result, "Error sending order: {0}");
|
||||
}
|
||||
|
||||
public Task<bool[]> cancel_orders(IEnumerable<OrderKey> orders) {
|
||||
return Task.WhenAll(
|
||||
orders.Select(cancel_order));
|
||||
}
|
||||
public async Task<bool> cancel_order(OrderKey order) {
|
||||
var result = await _service.cancel_order_async(new Cancel() { OrderKey = order.key });
|
||||
public Task<bool[]> cancel_orders(IEnumerable<uint> orders) =>
|
||||
Task.WhenAll(orders.Select(cancel_order));
|
||||
|
||||
public async Task<bool> cancel_order(uint order) {
|
||||
var result = await _service.cancel_order_async(new Cancel() { OrderKey = order });
|
||||
return handle_error(result, "Error canceling order: {0}").HasValue;
|
||||
}
|
||||
|
||||
public async Task<bool> update_order(OrderKey key, double price, uint size) {
|
||||
public async Task<bool> update_order(uint order, double price, uint size) {
|
||||
var result = await _service.update_order_async(new Update() {
|
||||
OrderKey = key.key,
|
||||
OrderKey = order,
|
||||
Price = price,
|
||||
Quantity = size
|
||||
});
|
||||
return handle_error(result, "Failed to update order: {0}").HasValue;
|
||||
}
|
||||
|
||||
public Task<bool[]> crack_orders(IEnumerable<OrderKey> orders) {
|
||||
return Task.WhenAll(
|
||||
orders.Select(crack_order));
|
||||
}
|
||||
public async Task<bool> crack_order(OrderKey order) {
|
||||
var result = await _service.crack_order_async(new Crack() { OrderKey = order.key });
|
||||
public Task<bool[]> crack_orders(IEnumerable<uint> orders) =>
|
||||
Task.WhenAll(orders.Select(crack_order));
|
||||
|
||||
public async Task<bool> crack_order(uint order) {
|
||||
var result = await _service.crack_order_async(new Crack() { OrderKey = order });
|
||||
return handle_error(result, "Failed to break order: {0}").HasValue;
|
||||
}
|
||||
|
||||
OrderKey? handle_error(Result<Response> result, string template) {
|
||||
uint? handle_error(Result<Response> result, string template) {
|
||||
if (result.success) {
|
||||
if (result.value.ErrorCode == OrderError.Ok) {
|
||||
return new OrderKey(result.value.OrderKey);
|
||||
}
|
||||
else {
|
||||
return result.value.OrderKey;
|
||||
} else {
|
||||
_error.report_error(string.Format(template, result.value.ErrorCode)).ignore();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_error.report_error(result.error_message).ignore();
|
||||
}
|
||||
return null;
|
||||
@@ -200,10 +196,52 @@ namespace mbts.spark
|
||||
|
||||
#endregion
|
||||
|
||||
public void Dispose() {
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
|
||||
// usinig new OrdersModel extensions to reduce the amount of code change needed to switch uis over to the new OrdersModel,
|
||||
// without changing any code in the actual new OrdersModel class.
|
||||
static class OrdersModelExtensions
|
||||
{
|
||||
#region Get Orders Collection
|
||||
public static ITableUpdateCollection<OrderRecordImmutable, uint> get_orders_collection(this OrdersModel orders_model) =>
|
||||
new TableUpdateCollection<OrderRecordImmutable, uint>(orders_model.on_orders.ObserveOnDispatcher());
|
||||
|
||||
public static ITableUpdateCollection<OrderRecordImmutable, uint> get_security_orders_collection(this OrdersModel orders_model, uint security) =>
|
||||
get_security_orders_collection(orders_model, new HashSet<uint>(new[] { security }));
|
||||
|
||||
public static ITableUpdateCollection<OrderRecordImmutable, uint> get_security_orders_collection(this OrdersModel orders_model, HashSet<uint> securities) =>
|
||||
new TableUpdateCollection<OrderRecordImmutable, uint>(orders_model.on_orders.ObserveOnDispatcher(), o => securities.Contains(o.Def.SecurityKey));
|
||||
#endregion
|
||||
|
||||
#region Cancel Orders
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_orders(this OrdersModel orders_model, uint security) =>
|
||||
await cancel_security_orders(orders_model, new[] { security });
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_orders(this OrdersModel orders_model, IEnumerable<uint> securities) =>
|
||||
await cancel_orders(orders_model, ori => securities.Contains(ori.Def.SecurityKey));
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_buy_orders(this OrdersModel orders_model, uint security) =>
|
||||
await cancel_security_buy_orders(orders_model, new[] { security });
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_buy_orders(this OrdersModel orders_model, IEnumerable<uint> securities) =>
|
||||
await cancel_orders(orders_model, ori => securities.Contains(ori.Def.SecurityKey) && ori.Def.Side == Side.Buy);
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_sell_orders(this OrdersModel orders_model, uint security) =>
|
||||
await cancel_security_sell_orders(orders_model, new[] { security });
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_security_sell_orders(this OrdersModel orders_model, IEnumerable<uint> securities) =>
|
||||
await cancel_orders(orders_model, ori => securities.Contains(ori.Def.SecurityKey) && ori.Def.Side == Side.Sell);
|
||||
|
||||
public static async Task<Tuple<OrderRecordImmutable, bool>[]> cancel_orders(this OrdersModel orders_model, Predicate<OrderRecordImmutable> orders_where) {
|
||||
var tu = await orders_model.on_orders.FirstAsync();
|
||||
return await Task.WhenAll(tu.state
|
||||
.Where(kv => orders_where(kv.Value))
|
||||
.Select(kv => orders_model.cancel_order(kv.Key).ContinueWith(t => Tuple.Create(kv.Value, t.IsCompleted && t.Result)))
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
class DemoOrdersModel
|
||||
|
||||
@@ -30,9 +30,9 @@ namespace mbts.spark {
|
||||
ObservableCollection<OrderRecordImmutable> _order_records;
|
||||
OrderBookRowVM wrap(OrderRecordImmutable record, SecurityImmutable s) => new OrderBookRowVM(this, _model, record, s);
|
||||
|
||||
Task<OrderKey?> t;
|
||||
Task<uint?> t;
|
||||
|
||||
private async Task<OrderKey?> send_an_order() {
|
||||
private async Task<uint?> send_an_order() {
|
||||
var result = await _model.send_order(
|
||||
new OrderDefinition() {
|
||||
Login = "W.O.P.R.",
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
<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>
|
||||
|
||||
@@ -19,5 +19,5 @@ namespace mbts.ui.spark
|
||||
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { return GenerateEditingElementInternal(cell, dataItem); }
|
||||
}
|
||||
|
||||
internal class DataGridAlgoTypeColumn : DataGridColumn<AlgoTypeItem> { }
|
||||
internal class DataGridOrderTypeColumn : DataGridColumn<OrderTypeItem> { }
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.orderman2;
|
||||
using bts.spark;
|
||||
using Google.Protobuf;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
@@ -8,12 +11,39 @@ namespace mbts.spark.utilities
|
||||
{
|
||||
internal static class OrderDataHelper
|
||||
{
|
||||
public static Order.AlgoOrderTypeOneofCase get_algo_type(IMessage algo_instance) {
|
||||
if (!Enum.TryParse(algo_instance.Descriptor.Name, true, out Order.AlgoOrderTypeOneofCase result))
|
||||
throw new ArgumentException($"Unable to match '{algo_instance?.Descriptor.Name}' to {nameof(Order.AlgoOrderTypeOneofCase)}");
|
||||
return result;
|
||||
public static CustomOrderDefinition.CustomOneofCase get_algo_type(IMessage algo_instance) {
|
||||
switch(algo_instance.Descriptor.Name) {
|
||||
case nameof(MarketOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Market;
|
||||
case nameof(LimitOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Limit;
|
||||
case nameof(StopOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Stop;
|
||||
case nameof(StopLimitOrderDefinition): return CustomOrderDefinition.CustomOneofCase.StopLimit;
|
||||
case nameof(IcebergOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Iceberg;
|
||||
case nameof(SpreaderOrderDefinition): return CustomOrderDefinition.CustomOneofCase.Spreader;
|
||||
case nameof(TimeBoxOrderDefinition): return CustomOrderDefinition.CustomOneofCase.TimeBox;
|
||||
default: throw new ArgumentException($"Unable to match '{algo_instance?.Descriptor.Name}' to {nameof(OrderType)}");
|
||||
}
|
||||
}
|
||||
|
||||
public static OrderMetadata get_metadata(IMessage order) => get_metadata(get_algo_type(order));
|
||||
public static OrderMetadata get_metadata(CustomOrderDefinition.CustomOneofCase order_type) {
|
||||
switch (order_type) {
|
||||
case CustomOrderDefinition.CustomOneofCase.Market: return new OrderMetadata { KeyBinding = "M", Color = BTSColors.yellow.rgb_color(), NoProps = true };
|
||||
case CustomOrderDefinition.CustomOneofCase.Limit: return new OrderMetadata { KeyBinding = "L", Color = BTSColors.green.rgb_color(), NoProps = true };
|
||||
case CustomOrderDefinition.CustomOneofCase.Stop: return new OrderMetadata { KeyBinding = "S", Color = BTSColors.orange.rgb_color() };
|
||||
case CustomOrderDefinition.CustomOneofCase.StopLimit: return new OrderMetadata { KeyBinding = "SL", Color = BTSColors.pale_green.rgb_color() };
|
||||
case CustomOrderDefinition.CustomOneofCase.Iceberg: return new OrderMetadata { KeyBinding = "I", Color = BTSColors.pale_blue.rgb_color() };
|
||||
case CustomOrderDefinition.CustomOneofCase.TimeBox: return new OrderMetadata { KeyBinding = "TB", Color = BTSColors.purple.rgb_color() };
|
||||
case CustomOrderDefinition.CustomOneofCase.Spreader: goto default;
|
||||
case CustomOrderDefinition.CustomOneofCase.None: goto default;
|
||||
default: return default_order_metadata;
|
||||
}
|
||||
}
|
||||
|
||||
static OrderMetadata default_order_metadata = new OrderMetadata() {
|
||||
KeyBinding = "",
|
||||
Color = BTSColors.pinkalicious
|
||||
};
|
||||
|
||||
public static class Defaults
|
||||
{
|
||||
public static QuantityMeasure QuantityMeasure => new QuantityMeasure { Absolute = 1 };
|
||||
@@ -27,17 +57,7 @@ namespace mbts.spark.utilities
|
||||
public static BTSTimedWindowParameters TimeWindow => new BTSTimedWindowParameters { Cancel = true, StartTime = OrderTime, StopTime = new OrderTime() };
|
||||
public static BTSWithATickParameters WithATick => new BTSWithATickParameters { QuantityThreshold = QuantityMeasure };
|
||||
public static BTSStopOrder BTSStopOrder => new BTSStopOrder { LimitOrder = new LimitOrder(), Price = 1, PriceTrigger = PriceTrigger, OptionalTimedParameters = TimeWindow, OptionalWithatickParameters = WithATick };
|
||||
public static BTSIcebergOrder BTSIcebergOrder => new BTSIcebergOrder { DisplayQuantity = QuantityMeasure, MarketOffset = PriceOffset, PriceTrigger = PriceTrigger, TimedWindowParameters = TimeWindow, WithatickParameters = WithATick };
|
||||
|
||||
public static IMessage[] Algos => new IMessage[] {
|
||||
new MarketOrder(),
|
||||
new LimitOrder(),
|
||||
new StopMarketOrder(),
|
||||
new StopLimitOrder(),
|
||||
new IcebergOrder(),
|
||||
BTSStopOrder,
|
||||
BTSIcebergOrder
|
||||
};
|
||||
public static BTSIcebergOrder BTSIcebergOrder => new BTSIcebergOrder { DisplayQuantity = QuantityMeasure, MarketOffset = PriceOffset, PriceTrigger = PriceTrigger, TimedWindowParameters = TimeWindow, WithatickParameters = WithATick };
|
||||
|
||||
public static Order Order(SecurityImmutable security) { return Order(security, bts.spark.Order.AlgoOrderTypeOneofCase.LimitOrder); }
|
||||
public static Order Order(SecurityImmutable security, Order.AlgoOrderTypeOneofCase algo_type) {
|
||||
@@ -56,6 +76,33 @@ namespace mbts.spark.utilities
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#region New OrderDefinition Defaults
|
||||
public static IMessage[] Algos => new IMessage[] {
|
||||
MarketOrderDefinition,
|
||||
LimitOrderDefinition,
|
||||
StopOrderDefinition,
|
||||
StopLimitOrderDefinition,
|
||||
IcebergOrderDefinition,
|
||||
TimeBoxOrderDefinition
|
||||
};
|
||||
|
||||
public static MarketOrderDefinition MarketOrderDefinition => new MarketOrderDefinition { };
|
||||
public static LimitOrderDefinition LimitOrderDefinition => new LimitOrderDefinition { };
|
||||
public static StopOrderDefinition StopOrderDefinition => new StopOrderDefinition { };
|
||||
public static StopLimitOrderDefinition StopLimitOrderDefinition => new StopLimitOrderDefinition { };
|
||||
public static IcebergOrderDefinition IcebergOrderDefinition => new IcebergOrderDefinition { };
|
||||
public static TimeBoxOrderDefinition TimeBoxOrderDefinition => new TimeBoxOrderDefinition { };
|
||||
|
||||
public static CustomOrderDefinition CustomOrderDefinition => new CustomOrderDefinition { Limit = LimitOrderDefinition };
|
||||
public static OrderDefinition OrderDefinition(SecurityImmutable security) => new OrderDefinition {
|
||||
SecurityKey = security.Id,
|
||||
Account = ImportedResources.Accounts.FirstOrDefault(),
|
||||
Side = Side.Buy,
|
||||
TimeInForce = bts.api.orderman2.TimeInForce.Day,
|
||||
CustomDef = CustomOrderDefinition
|
||||
};
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
using System;
|
||||
using bts.api.core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace mbts.ui.utility
|
||||
{
|
||||
interface IRXCollection<T> : ICollection<T>, INotifyCollectionChanged, IDisposable { }
|
||||
interface ITableUpdateCollection<T, TKey> : IRXCollection<T> where TKey : IEquatable<TKey> {
|
||||
bool TryGetValue(TKey key, out T result);
|
||||
}
|
||||
|
||||
public class RXObservableCollection<T, TCollection> : ObservableCollection<T>, IObserver<TCollection>, IRXCollection<T> where TCollection : IEnumerable<T>
|
||||
{
|
||||
public abstract class RXObservableCollectionBase<T, TData> : ObservableCollection<T>, IRXCollection<T> {
|
||||
protected RXObservableCollectionBase(IObservable<TData> data) => _data = data;
|
||||
|
||||
IObservable<TData> _data;
|
||||
IDisposable _dispose;
|
||||
|
||||
protected void connect() => _dispose = _data.Subscribe(synchronize);
|
||||
protected abstract void synchronize(TData data);
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public class RXObservableCollection<T, TCollection> : RXObservableCollectionBase<T, TCollection> where TCollection : IEnumerable<T> {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of RXObservableCollection<T, TCollection>, that will observe the source with a 1 second throttle on the current synchronization context
|
||||
/// </summary>
|
||||
@@ -27,55 +42,53 @@ namespace mbts.ui.utility
|
||||
/// <para>Initializes a new instance of RXObservableCollection<T, TCollection>, that will observe the source with the specified throttle on the specified synchronization context, and synchronize with the specified IEqualityComparer<T></para>
|
||||
/// <para>If a throttle of TimeSpan.Zero is passed, no throttle will used.</para>
|
||||
/// </summary>
|
||||
public RXObservableCollection(IObservable<TCollection> data, SynchronizationContext context, TimeSpan throttle, IEqualityComparer<T> equality_comparer) {
|
||||
public RXObservableCollection(IObservable<TCollection> data, SynchronizationContext context, TimeSpan throttle, IEqualityComparer<T> equality_comparer)
|
||||
: base(_parameterized_data(data, context, throttle)) {
|
||||
_equality_comparer = equality_comparer ?? EqualityComparer<T>.Default;
|
||||
connect();
|
||||
}
|
||||
|
||||
static IObservable<TCollection> _parameterized_data(IObservable<TCollection> data, SynchronizationContext context, TimeSpan throttle) {
|
||||
if (throttle != TimeSpan.Zero) data = data.Buffer(throttle).Where(d => d.Count > 0).Select(d => d[d.Count - 1]);
|
||||
if (context != null) data = data.ObserveOn(context);
|
||||
_sub = data.Subscribe(this);
|
||||
return data;
|
||||
}
|
||||
|
||||
private readonly IEqualityComparer<T> _equality_comparer;
|
||||
private IDisposable _sub;
|
||||
readonly IEqualityComparer<T> _equality_comparer;
|
||||
|
||||
public virtual void OnCompleted() { }
|
||||
public virtual void OnError(Exception error) { }
|
||||
public virtual void OnNext(TCollection value) {
|
||||
this.sync_with(value, _equality_comparer);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Disposable.dispose(ref _sub);
|
||||
}
|
||||
protected override void synchronize(TCollection value) => this.sync_with(value, _equality_comparer);
|
||||
}
|
||||
|
||||
public class RXObservableCollection<T> : RXObservableCollection<T, IEnumerable<T>>
|
||||
{
|
||||
public class RXObservableCollection<T> : RXObservableCollection<T, IEnumerable<T>> {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of RXObservableCollection<T>, that will observe the source with a 1 second throttle on the current synchronization context
|
||||
/// </summary>
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data) : base(data, SynchronizationContext.Current) { }
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data)
|
||||
: base(data, SynchronizationContext.Current) { }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of RXObservableCollection, that will observe the source with a 1 second throttle on the specified synchronization context
|
||||
/// </summary>
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context) : base(data, context, TimeSpan.FromSeconds(1)) { }
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context)
|
||||
: base(data, context, TimeSpan.FromSeconds(1)) { }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of RXObservableCollection, that will observe the source with a 1 second throttle on the specified synchronization context
|
||||
/// </summary>
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context, TimeSpan throttle) : base(data, context, throttle) { }
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context, TimeSpan throttle)
|
||||
: base(data, context, throttle) { }
|
||||
/// <summary>
|
||||
/// <para>Initializes a new instance of RXObservableCollection, that will observe the source with the specified throttle on the specified synchronization context, and synchronize with the specified IEqualityComparer<T></para>
|
||||
/// <para>If a throttle of TimeSpan.Zero is passed, no throttle will used.</para>
|
||||
/// </summary>
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context, TimeSpan throttle, IEqualityComparer<T> equality_comparer) : base(data, context, throttle, equality_comparer) { }
|
||||
public RXObservableCollection(IObservable<IEnumerable<T>> data, SynchronizationContext context, TimeSpan throttle, IEqualityComparer<T> equality_comparer)
|
||||
: base(data, context, throttle, equality_comparer) { }
|
||||
}
|
||||
|
||||
public class RXCircularCollection<T> : RXObservableCollection<T, IReadOnlyList<T>>
|
||||
{
|
||||
public class RXCircularCollection<T> : RXObservableCollection<T, IReadOnlyList<T>> {
|
||||
public RXCircularCollection(IObservable<IReadOnlyList<T>> data, int buffer) : base(data) => _buffer = buffer;
|
||||
|
||||
readonly int _buffer;
|
||||
|
||||
public override void OnNext(IReadOnlyList<T> ts) {
|
||||
protected override void synchronize(IReadOnlyList<T> ts) {
|
||||
if (ts.Count >= _buffer) {
|
||||
Clear();
|
||||
for (int i = ts.Count - _buffer; i < ts.Count; i++) Add(ts[i]);
|
||||
@@ -87,4 +100,23 @@ namespace mbts.ui.utility
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TableUpdateCollection<T, TKey> : RXObservableCollectionBase<T, TableUpdate<T, TKey>>, ITableUpdateCollection<T, TKey> where TKey : IEquatable<TKey> {
|
||||
public TableUpdateCollection(IObservable<TableUpdate<T, TKey>> data) : this(data, null) { }
|
||||
public TableUpdateCollection(IObservable<TableUpdate<T, TKey>> data, Predicate<T> collection_filter) : base(data) {
|
||||
_collection_filter = collection_filter == null ? _ => true : new Func<T, bool>(collection_filter);
|
||||
connect();
|
||||
}
|
||||
|
||||
readonly Func<T, bool> _collection_filter;
|
||||
IReadOnlyDictionary<TKey, T> _raw_state = new ReadOnlyDictionary<TKey, T>(new Dictionary<TKey, T>());
|
||||
|
||||
protected override void synchronize(TableUpdate<T, TKey> data) {
|
||||
_raw_state = data.state;
|
||||
foreach (T val in data.removed.Where(_collection_filter)) Remove(val);
|
||||
foreach (T val in data.added.Where(_collection_filter)) Add(val);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey key, out T result) => _raw_state.TryGetValue(key, out result);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user