diff --git a/src/client/spark/Daemons/SecurityPickerDaemon.cs b/src/client/spark/Daemons/SecurityPickerDaemon.cs index 5fb3866d4..36674029a 100644 --- a/src/client/spark/Daemons/SecurityPickerDaemon.cs +++ b/src/client/spark/Daemons/SecurityPickerDaemon.cs @@ -10,6 +10,7 @@ using System.ComponentModel.Composition; using mbts; using System.Windows; using System.Windows.Input; +using bts.spark; namespace bts { [Export, Export(typeof(IShellDaemon))] @@ -26,13 +27,13 @@ namespace bts { ); } - void show_pick_one(SparkBusData.ContractPickerOneMessage message) { + void show_pick_one(PartialCommand message) { var vm = new ContractPickerModel(_bus, false, null); var view = new ContractPickerView(vm); Window picker = new Window { Content = view, - Title = $" {message.window_title} security selection", + Title = $" {message.title} security selection", Icon = message.icon, Height = view.Height, Width = view.Width @@ -43,20 +44,20 @@ namespace bts { vm.close_action = () => { picker.Close(); - _bus.post(message.next, vm.result); + message.complete(vm.result).execute(_bus); }; picker.move_to_mouse(); picker.Show(); } - void show_pick_multiple(SparkBusData.ContractPickerNMessage message) { + void show_pick_multiple(PartialCommand message) { var vm = new ContractPickerModel(_bus, true, null); var view = new ContractPickerView(vm); Window picker = new Window { Content = view, - Title = $" {message.window_title} security selection", + Title = $" {message.title} security selection", Icon = message.icon, Height = view.Height, Width = view.Width, @@ -67,7 +68,7 @@ namespace bts { vm.close_action = () => { picker.Close(); - _bus.post(message.next, vm.result_criteria); + message.complete(vm.result_criteria).execute(_bus); }; picker.move_to_mouse(); picker.Show(); diff --git a/src/client/spark/Modules/Market/MarketShellModule.cs b/src/client/spark/Modules/Market/MarketShellModule.cs index 9497a7d37..19b1f73e3 100644 --- a/src/client/spark/Modules/Market/MarketShellModule.cs +++ b/src/client/spark/Modules/Market/MarketShellModule.cs @@ -36,8 +36,8 @@ namespace bts.shell public int priority => 10; public IEnumerable actions => new [] { - SparkCommands.ShowMarketView, - SparkCommands.ShowTimeAndSales + SparkCommands.PickMarketView, + SparkCommands.PickTimeAndSales }; public Task create(Stream load_stream) { diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs index 155e57dd4..1353abad1 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs @@ -47,7 +47,8 @@ namespace mbts.spark { public override UIElement Content => _view; public override IEnumerable Commands => new[] { - SparkCommands.ShowLadder + SparkCommands.PickLadder + //SparkCommands.ShowLadderDirect.parameterize(selected_security ; // linked ladder // OrderTicket // LinkedOrderTicket diff --git a/src/client/spark/Modules/Market/TimeAndSalesWindowFactory.cs b/src/client/spark/Modules/Market/TimeAndSalesWindowFactory.cs index fea81521c..afac3140f 100644 --- a/src/client/spark/Modules/Market/TimeAndSalesWindowFactory.cs +++ b/src/client/spark/Modules/Market/TimeAndSalesWindowFactory.cs @@ -24,7 +24,7 @@ namespace bts.shell { ); } public override async Task load(TimeAndSalesStartupData state) { - return await TimeAndSalesWindow.create(this, _bus, state, SparkCommands.ShowTimeAndSales.icon); + return await TimeAndSalesWindow.create(this, _bus, state, SparkCommands.PickTimeAndSales.icon); } public async void show(SecurityCriteria criteria) { diff --git a/src/client/spark/Modules/Support/SupportShellModule.cs b/src/client/spark/Modules/Support/SupportShellModule.cs index 625f97fd2..af10d6a87 100644 --- a/src/client/spark/Modules/Support/SupportShellModule.cs +++ b/src/client/spark/Modules/Support/SupportShellModule.cs @@ -35,7 +35,7 @@ namespace bts.Modules.Support { SparkCommands.ShowManual, SparkCommands.ShowAuditLogs, SparkCommands.ShowDiagnostics, - SparkCommands.ShowReportIssue, + SparkCommands.ShowReportIssue.complete("Create Support Ticket"), SparkCommands.ShowAboutSpark }; diff --git a/src/client/spark/Modules/Trading/FillsWindowFactory.cs b/src/client/spark/Modules/Trading/FillsWindowFactory.cs index 097f6bcb2..245bffb58 100644 --- a/src/client/spark/Modules/Trading/FillsWindowFactory.cs +++ b/src/client/spark/Modules/Trading/FillsWindowFactory.cs @@ -21,7 +21,7 @@ namespace bts.shell { } - void show_fills_window(IEnumerable secs) { + void show_fills_window(SecurityCriteria secs) { } IShellWindow create_fills_window(IEnumerable secs, IEnumerable sort) { var vm = new FillsVM(this, _bus, new DemoOrdersModel(_bus), _ssrc, secs, sort); diff --git a/src/client/spark/Modules/Trading/ShowOrderTicketHandler.cs b/src/client/spark/Modules/Trading/ShowOrderTicketHandler.cs index 9f0345d8d..46fa5992b 100644 --- a/src/client/spark/Modules/Trading/ShowOrderTicketHandler.cs +++ b/src/client/spark/Modules/Trading/ShowOrderTicketHandler.cs @@ -21,11 +21,13 @@ namespace bts.shell { Disposable.dispose(ref _dispose); } - private void show_order_ticket(OneOf t) { - var vm = - t.Match( - md => null, - order => new OrderTicketVM(new DemoOrdersModel(_bus), order, null, _bus)); + private void show_order_ticket(SecurityMD md) { + // This is temporary until the new-new Order type comes in + var vm = + new OrderTicketVM( + new DemoOrdersModel(_bus), + new Order() { Security = md.security.CloneToMutable() }, + null, _bus); var ui = new OrderTicket() { DataContext = vm }; ui.Show(-200, -160, true); diff --git a/src/client/spark/Modules/Trading/TradingShellModule.cs b/src/client/spark/Modules/Trading/TradingShellModule.cs index 03e30f46f..a8f56e25e 100644 --- a/src/client/spark/Modules/Trading/TradingShellModule.cs +++ b/src/client/spark/Modules/Trading/TradingShellModule.cs @@ -38,12 +38,12 @@ namespace bts.shell { public int priority => 20; - public IEnumerable actions => new[] { + public IEnumerable actions => new [] { SparkCommands.ShowOrders, - SparkCommands.ShowFills, + SparkCommands.PickFills, SparkCommands.ShowPAndL, - SparkCommands.ShowLadder, - SparkCommands.ShowOrderTicket + SparkCommands.PickLadder, + SparkCommands.PickOrderTicket }; IEnumerable window_factories() { diff --git a/src/client/spark/core/Bus/SparkCommand.cs b/src/client/spark/core/Bus/SparkCommand.cs index f2c9e13f4..2348c4d37 100644 --- a/src/client/spark/core/Bus/SparkCommand.cs +++ b/src/client/spark/core/Bus/SparkCommand.cs @@ -1,4 +1,6 @@ using bts.api; +using mbts; +using mbts.spark; using mbts.ui; using System; using System.Collections.Generic; @@ -7,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Media; +using static mbts.spark.SparkTags; namespace bts.spark { @@ -21,46 +24,65 @@ namespace bts.spark { public abstract void execute(IBus bus); public virtual bool canExecute() { return true; } - public static SparkCommand create( - string title, ImageSource icon, ITag tag) { - return new SparkCommand(title, icon, tag, null, null); + public static PartialCommand create(string title, ImageSource icon, ITag tag) { + return new PartialCommand(title, icon, tag); + } + internal static SparkCommand create(string title, ImageSource icon, ITag tag) { + return new SparkCommand(title, icon, tag, () => null, null); } - public static SparkCommand create( - string title, ImageSource icon, ITag tag, T parameter) { + public static SparkCommand create(string title, ImageSource icon, ITag tag, T parameter) { return new SparkCommand(title, icon, tag, () => parameter, null); } - public static SparkCommand create( - string title, ImageSource icon, ITag tag, Func parameter, Func can_execute) { - return new SparkCommand(title, icon, tag, parameter, can_execute); + public static SparkCommand create(string title, ImageSource icon, ITag tag, Func parameter) { + return new SparkCommand(title, icon, tag, parameter, null); } - } + + public class PartialCommand { + public PartialCommand(string title, ImageSource icon, ITag tag) { + this.title = title; + this.icon = icon; + this.tag = tag; + } + public string title { get; } + public ImageSource icon { get; } + public ITag tag { get; } + + public SparkCommand complete(T value) { + return SparkCommand.create(title, icon, tag, () => value); + } + public SparkCommand complete(Func value) { + return SparkCommand.create(title, icon, tag, value); + } + public SparkCommand complete() { + return SparkCommand.create(title, icon, tag, ()=>default); + } + } + public class SparkCommand : SparkCommand { public SparkCommand( - string title, ImageSource icon, - ITag tag, Func param, Func can_execute) : base(title, icon) { + string title, ImageSource icon, + ITag tag, Func param, Func can_execute) : base(title, icon) { this.tag = tag; - _get_parameter = param ?? (()=>default); + _get_parameter = param ?? (() => default); _can_execute = can_execute; } Func _get_parameter; - Func _can_execute; + Func _can_execute; public ITag tag { get; } public override void execute(IBus bus) { bus.post(tag, _get_parameter()); } public override bool canExecute() { - return _can_execute?.Invoke() ?? base.canExecute(); + return _can_execute?.Invoke(_get_parameter()) ?? base.canExecute(); } - public SparkCommand with_parameter(T parameter, Func can_execute=null) { - return create(title, icon, tag, () => parameter, can_execute); - } - public SparkCommand with_parameter(Func parameter, Func can_execute=null) { - return create(title, icon, tag, parameter, can_execute); + + public SparkCommand conditional(Func can_execute) { + return new SparkCommand(title, icon, tag, _get_parameter, can_execute); } } @@ -78,6 +100,7 @@ namespace bts.spark { } } + public class SparkCommandVM : mbts.ui.shell.ViewModelBase, ICommand { readonly SparkCommand _cmd; readonly IBus _bus; diff --git a/src/client/spark/core/Bus/SparkCommands.cs b/src/client/spark/core/Bus/SparkCommands.cs index f304e5882..fbd4cfd8a 100644 --- a/src/client/spark/core/Bus/SparkCommands.cs +++ b/src/client/spark/core/Bus/SparkCommands.cs @@ -13,50 +13,65 @@ namespace bts.spark { // Market - public static SparkCommand ShowMarketView { get; } = - SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowPickMultiple, new ContractPickerNMessage(SparkTags.ShowMarketViewTag, "Market View", Icons.Sheets)); - public static SparkCommand ShowTimeAndSales { get; } = - SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowPickMultiple, new ContractPickerNMessage(SparkTags.ShowTimeAndSalesTag, "Time and Sales", Icons.Clock)); + public static PartialCommand ShowMarketView => + SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowMarketViewTag); + public static SparkCommand PickMarketView => + SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowPickMultiple, ShowMarketView); + + public static PartialCommand ShowTimeAndSales => + SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowTimeAndSalesTag); + public static SparkCommand PickTimeAndSales => + SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowPickMultiple, ShowTimeAndSales); // Trading - public static SparkCommand ShowOrders { get; } = + public static SparkCommand ShowOrders => SparkCommand.create("Order Book", Icons.Book, SparkTags.ShowOrderBookTag); - public static SparkCommand ShowFills { get; } = + + public static PartialCommand ShowFills => SparkCommand.create("Fills", Icons.Payment, SparkTags.ShowFillsTag); - public static SparkCommand ShowPAndL { get; } = + public static SparkCommand PickFills => + SparkCommand.create("Fills", Icons.Payment, SparkTags.ShowPickMultiple, ShowFills); + + public static SparkCommand ShowPAndL => SparkCommand.create("Position/P&L", Icons.Accounting, SparkTags.ShowPositionsTag); - public static SparkCommand ShowLadder { get; } - = SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowPickOne, new ContractPickerOneMessage(SparkTags.ShowLadderTag, "Ladder", Icons.Depth)); - public static SparkCommand ShowOrderTicket { get; } = + + public static SparkCommand PickLadder => + SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowPickOne, ShowLadder); + public static PartialCommand ShowLadder => + SparkCommand.create("Ladder", Icons.Depth, SparkTags.ShowLadderTag); + + public static PartialCommand ShowOrderTicket => SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowOrderTicketTag); + public static SparkCommand PickOrderTicket => + SparkCommand.create("Order Ticket", Icons.Ticket, SparkTags.ShowPickOne, ShowOrderTicket); // Spreader - public static SparkCommand ShowSyntheticSpreads { get; } - = SparkCommand.create("Synthetic Spreads", Icons.Spreads, SparkTags.NotImplemented); + public static SparkCommand ShowSyntheticSpreads => + SparkCommand.create("Synthetic Spreads", Icons.Spreads, SparkTags.NotImplemented); - public static SparkCommand ShowLatencyReport { get; } = + public static SparkCommand ShowLatencyReport => SparkCommand.create("Latency Report", Icons.Analytics, SparkTags.NotImplemented); // Settings - public static SparkCommand ShowWorkspaces { get; } = + public static SparkCommand ShowWorkspaces => SparkCommand.create("Workspaces", Icons.FavoriteWindow, SparkTags.ShowWorkspaces); - public static SparkCommand ShowSettings { get; } = + public static SparkCommand ShowSettings => SparkCommand.create("Settings", Icons.Admin, SparkTags.ShowSettings); // Support - public static SparkCommand ShowManual { get; } = + public static SparkCommand ShowManual => SparkCommand.create("Manual", Icons.Book, SparkTags.ShowUri, new Uri("bts://m/")); - public static SparkCommand ShowAuditLogs { get; } = + public static SparkCommand ShowAuditLogs => SparkCommand.create("Audit Logs", Icons.Book, SparkTags.NotImplemented); - public static SparkCommand ShowDiagnostics { get; } = + public static SparkCommand ShowDiagnostics => SparkCommand.create("Diagnostics", Icons.Target, SparkTags.NotImplemented); - public static SparkCommand ShowAboutSpark { get; } = + public static SparkCommand ShowAboutSpark => SparkCommand.create("About Spark", Icons.Support, SparkTags.About); - public static SparkCommand ShowReportIssue { get; } = + public static PartialCommand ShowReportIssue => SparkCommand.create("Contact Support", Icons.Support, SparkTags.Support); } diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index 1b8034c1e..c87823065 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -24,14 +24,14 @@ namespace mbts.spark { #region Show Window public static ITag ShowAuditLogsTag { get; } = new SparkTag(nameof(ShowAuditLogsTag)); - public static ITag ShowFillsTag { get; } = new SparkTag(nameof(ShowFillsTag)); + public static ITag ShowFillsTag { get; } = new SparkTag(nameof(ShowFillsTag)); public static ITag ShowLadderTag { get; } = new SparkTag("Show Ladder"); public static ITag> ShowLinkedLadder { get; } = new SparkTag>("Linked Ladder"); public static ITag ShowMarketViewTag { get; } = new SparkTag("Show MarketView"); public static ITag ShowOrderBookTag { get; } = new SparkTag(nameof(ShowOrderBookTag)); public static ITag ShowOrderDetailsTag { get; } = new SparkTag(nameof(ShowOrderDetailsTag)); public static ITag ShowOrderModifyTag { get; } = new SparkTag(nameof(ShowOrderModifyTag)); - public static ITag> ShowOrderTicketTag = new SparkTag>(nameof(ShowOrderTicketTag)); + public static ITag ShowOrderTicketTag = new SparkTag(nameof(ShowOrderTicketTag)); public static ITag ShowLinkedOrderTicketTag = new SparkTag(nameof(ShowLinkedOrderTicketTag)); public static ITag ShowPositionsTag { get; } = new SparkTag(nameof(ShowPositionsTag)); public static ITag ShowSpreadMatrixTag { get; } = new SparkTag(nameof(ShowSpreadMatrixTag)); @@ -49,8 +49,8 @@ namespace mbts.spark { public static ITag ShowWindow { get; } = new SparkTag("Show Window"); - public static ITag ShowPickMultiple { get; } = new SparkTag("PickN"); - public static ITag ShowPickOne { get; } = new SparkTag("Pick1"); + public static ITag> ShowPickMultiple { get; } = new SparkTag>("PickN"); + public static ITag> ShowPickOne { get; } = new SparkTag>("Pick1"); public static ITag Support { get; } = new SparkTag(nameof(Support)); public static ITag About { get; } = new SparkTag("About"); diff --git a/src/client/spark/view/Spark/ContractPicker/ContractPickerView.xaml.cs b/src/client/spark/view/Spark/ContractPicker/ContractPickerView.xaml.cs index c0e61691c..b67cbee4b 100644 --- a/src/client/spark/view/Spark/ContractPicker/ContractPickerView.xaml.cs +++ b/src/client/spark/view/Spark/ContractPicker/ContractPickerView.xaml.cs @@ -120,7 +120,7 @@ namespace mbts.spark public IEnumerable actions => new[] { new SparkCommandCommand("Go!", Icons.Tetris, new DelegateCommand(start)), - SparkCommands.ShowLadder + SparkCommands.PickLadder }; public Task create(Stream load_stream) { diff --git a/src/client/spark/view/Spark/Core/SparkBusData.cs b/src/client/spark/view/Spark/Core/SparkBusData.cs index a30be891b..089ee3f3d 100644 --- a/src/client/spark/view/Spark/Core/SparkBusData.cs +++ b/src/client/spark/view/Spark/Core/SparkBusData.cs @@ -45,32 +45,6 @@ namespace mbts.spark public OrderBookMessage(OrderBook order_book) { this.order_book = order_book; } } - public class ContractPickerOneMessage - { - public readonly ITag next; - public readonly string window_title; - public readonly System.Windows.Media.ImageSource icon; - - public ContractPickerOneMessage(ITag next, string window_title, System.Windows.Media.ImageSource icon) { - this.next = next; - this.window_title = window_title; - this.icon = icon; - } - } - - public class ContractPickerNMessage - { - public readonly ITag next; - public readonly string window_title; - public readonly System.Windows.Media.ImageSource icon; - - public ContractPickerNMessage(ITag next, string window_title, System.Windows.Media.ImageSource icon) { - this.next = next; - this.window_title = window_title; - this.icon = icon; - } - } - public class SyntheticSecuritiesMessage : BusMessageWrapper> { public SyntheticSecuritiesMessage(IDictionary m) : base(m) { } } @@ -84,10 +58,6 @@ namespace mbts.spark public ShowOrderModifyMessage(Order order) : base(new[] { order }) { } public ShowOrderModifyMessage(IReadOnlyCollection orders) : base(orders) { } } - public class ShowOrderTicketMessage : BusMessageWrapper> { - public ShowOrderTicketMessage(Order order) : base(new[] { order }) { } - public ShowOrderTicketMessage(IReadOnlyCollection orders) : base(orders) { } - } public class ShowLinkedOrderTicketMessage : BusMessageWrapper> { public ShowLinkedOrderTicketMessage(IObservable order) : base(order) { } }