diff --git a/src/client/spark/Bus/SparkCommand.cs b/src/client/spark/Bus/SparkCommand.cs index 5492b9f70..be505851d 100644 --- a/src/client/spark/Bus/SparkCommand.cs +++ b/src/client/spark/Bus/SparkCommand.cs @@ -1,45 +1,58 @@ -using bts.api; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Input; -using System.Windows.Media; - -namespace bts.spark { - - public abstract class SparkCommand { - public string title { get; set; } - public ImageSource icon { get; set; } - public ICommand command { get; } - - public abstract void execute(IBus bus); - - public static SparkCommand create( - string title, ImageSource icon, ITag tag, T parameter=default(T)) { - return new SparkCommand(title, icon, tag, () => parameter); - } - public static SparkCommand create( - string title, ImageSource icon, ITag tag, Func parameter) { - return new SparkCommand(title, icon, tag, parameter); - } - } - public class SparkCommand : SparkCommand { - public SparkCommand( - string title, ImageSource icon, - ITag tag, Func param) { - this.title = title; - this.icon = icon; - this.tag = tag; - _get_parameter = param; - } - - Func _get_parameter; - public ITag tag { get; } - - public override void execute(IBus bus) { - bus.post(tag, _get_parameter()); - } - } -} +using bts.api; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using System.Windows.Media; + +namespace bts.spark { + + public abstract class SparkCommand { + public string title { get; set; } + public ImageSource icon { get; set; } + public ICommand command { get; } + + public abstract void execute(IBus bus); + + public static SparkCommand create( + string title, ImageSource icon, ITag tag) { + return new SparkCommand(title, icon, tag, null); + } + + public static SparkCommand create( + string title, ImageSource icon, ITag tag, T parameter) { + return new SparkCommand(title, icon, tag, () => parameter); + } + + public static SparkCommand create( + string title, ImageSource icon, ITag tag, Func parameter) { + return new SparkCommand(title, icon, tag, parameter); + } + + } + public class SparkCommand : SparkCommand { + public SparkCommand( + string title, ImageSource icon, + ITag tag, Func param) { + this.title = title; + this.icon = icon; + this.tag = tag; + _get_parameter = param ?? (()=>default); + } + + Func _get_parameter; + public ITag tag { get; } + + public override void execute(IBus bus) { + bus.post(tag, _get_parameter()); + } + public SparkCommand with_parameter(T parameter) { + return create(title, icon, tag, () => parameter); + } + public SparkCommand with_parameter(Func parameter) { + return create(title, icon, tag, parameter); + } + } +} diff --git a/src/client/spark/Bus/SparkCommands.cs b/src/client/spark/Bus/SparkCommands.cs new file mode 100644 index 000000000..c83be85aa --- /dev/null +++ b/src/client/spark/Bus/SparkCommands.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using mbts.ui; +using mbts.spark; + +namespace bts.spark +{ + static class SparkCommands + { + + // Market + public static SparkCommand ShowMarketView { get; } = + SparkCommand.create("Market View", Icons.Sheets, SparkTags.ShowMarketViewTag); + public static SparkCommand ShowTimeAndSales { get; } = + SparkCommand.create("Time and Sales", Icons.Clock, SparkTags.ShowTimeAndSalesTag); + + + // Trading + public static SparkCommand ShowOrders { get; } + public static SparkCommand ShowFills { get; } + public static SparkCommand ShowPAndL { get; } + public static SparkCommand ShowLadder { get; } + public static SparkCommand ShowOrderTicket { get; } + + + // Spreader + public static SparkCommand ShowSyntheticSpreads { get; } + = SparkCommand.create("Synthetic Spreads", Icons.Spreads, SparkTags.ShowNotImplemented); + + public static SparkCommand ShowLatencyReport { get; } = + SparkCommand.create("Latency Report", Icons.Analytics, SparkTags.ShowNotImplemented); + + // Settings + public static SparkCommand ShowWorkspaces { get; } = + SparkCommand.create("Workspaces", Icons.FavoriteWindow, SparkTags.ShowWorkspaces); + public static SparkCommand ShowSettings { get; } = + SparkCommand.create("Settings", Icons.Admin, SparkTags.ShowSettings); + + // Support + public static SparkCommand ShowManual { get; } = + SparkCommand.create("Manual", Icons.Book, SparkTags.ShowUri, new Uri("bts://manual")); + + public static SparkCommand ShowAuditLogs { get; } + public static SparkCommand ShowDiagnostics { get; } + public static SparkCommand ShowAboutSpans { get; } + + } +} diff --git a/src/client/spark/Bus/SparkTags.cs b/src/client/spark/Bus/SparkTags.cs index a0a2508f3..cfbb08768 100644 --- a/src/client/spark/Bus/SparkTags.cs +++ b/src/client/spark/Bus/SparkTags.cs @@ -1,48 +1,61 @@ -using bts.api; -using System.Collections.Generic; -using static mbts.spark.SparkBusData; -using SecurityList = System.Collections.Generic.IEnumerable; - -namespace mbts.spark { - static class SparkTags { - private class SparkTag : ITag { private readonly string Name; public SparkTag(string name) { Name = name; } } - private class SparkTag : ITag { private readonly string Name; public SparkTag(string name) { Name = name; } } - - #region Core Data - public static ITag> SecuritiesTag { get; } = new SparkTag>("Securities"); - public static ITag SyntheticSecuritiesTag { get; } = new SparkTag("SyntheticSecuritiesTag"); - public static ITag OrderBookTag { get; } = new SparkTag("OrderBookTag"); - public static ITag PositionsTag { get; } = new SparkTag(nameof(PositionsTag)); - #endregion - - #region Show Window - public static ITag ShowAuditLogsTag { get; } = new SparkTag(nameof(ShowAuditLogsTag)); - public static ITag ShowFillsTag { get; } = new SparkTag(nameof(ShowFillsTag)); - public static ITag ShowLadderTag { get; } = new SparkTag("Show Ladder"); - public static ITag ShowMarketViewTag { get; } = new SparkTag("Show MarketView"); - public static ITag ShowOrderBookTag { get; } = new SparkTag(nameof(ShowOrderBookTag)); - public static ITag ShowOrderDetailsTag = new SparkTag(nameof(ShowOrderDetailsTag)); - public static ITag ShowOrderModifyTag = new SparkTag(nameof(ShowOrderModifyTag)); - public static ITag ShowOrderTicketTag = new SparkTag(nameof(ShowOrderTicketTag)); - public static ITag ShowPositionsTag { get; } = new SparkTag(nameof(ShowPositionsTag)); - public static ITag ShowSpreadMatrixTag { get; } = new SparkTag(nameof(ShowSpreadMatrixTag)); - public static ITag ShowSyntheticCreateTag { get; } = new SparkTag(nameof(ShowSyntheticCreateTag)); - public static ITag ShowSyntheticStrategyTag { get; } = new SparkTag(nameof(ShowSyntheticStrategyTag)); - public static ITag ShowTimeAndSalesTag { get; } = new SparkTag("Show TimeAndSales"); - #endregion - - #region Action - public static ITag SendOrderTag = new SparkTag("SendOrderTag"); - public static ITag ChangeOrderPriceTag = new SparkTag("ChangeOrderPriceTag"); - public static ITag ChangeOrderQuantityTag = new SparkTag("ChangeOrderQuantityTag"); - public static ITag CancelOrderTag = new SparkTag("CancelOrderTag"); - #endregion - - #region Persist - public static ITag PersistCommandTag = new SparkTag("PersistCommandTag"); - public static ITag PersistedItemsTag = new SparkTag("PersistedItemsTag"); - #endregion - - public static ITag ClockTag = new SparkTag("ClockTag"); - } +using bts.api; +using System; +using System.Collections.Generic; +using static mbts.spark.SparkBusData; +using SecurityList = System.Collections.Generic.IEnumerable; + +namespace mbts.spark { + static class SparkTags { + + public struct Nothing {} + public static Nothing nothing = new Nothing(); + + private class SparkTag : ITag { private readonly string Name; public SparkTag(string name) { Name = name; } } + private class SparkTag : ITag { private readonly string Name; public SparkTag(string name) { Name = name; } } + + #region Core Data + public static ITag> SecuritiesTag { get; } = new SparkTag>("Securities"); + public static ITag SyntheticSecuritiesTag { get; } = new SparkTag("SyntheticSecuritiesTag"); + public static ITag OrderBookTag { get; } = new SparkTag("OrderBookTag"); + public static ITag PositionsTag { get; } = new SparkTag(nameof(PositionsTag)); + #endregion + + #region Show Window + public static ITag ShowAuditLogsTag { get; } = new SparkTag(nameof(ShowAuditLogsTag)); + 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 = new SparkTag(nameof(ShowOrderDetailsTag)); + public static ITag ShowOrderModifyTag = new SparkTag(nameof(ShowOrderModifyTag)); + public static ITag ShowOrderTicketTag = new SparkTag(nameof(ShowOrderTicketTag)); + public static ITag ShowPositionsTag { get; } = new SparkTag(nameof(ShowPositionsTag)); + public static ITag ShowSpreadMatrixTag { get; } = new SparkTag(nameof(ShowSpreadMatrixTag)); + public static ITag ShowSyntheticCreateTag { get; } = new SparkTag(nameof(ShowSyntheticCreateTag)); + public static ITag ShowSyntheticStrategyTag { get; } = new SparkTag(nameof(ShowSyntheticStrategyTag)); + public static ITag ShowTimeAndSalesTag { get; } = new SparkTag("Show TimeAndSales"); + + public static ITag ShowWorkspaces { get; } = new SparkTag(nameof(ShowWorkspaces)); + public static ITag ShowSettings { get; } = new SparkTag(nameof(ShowSettings)); + + public static ITag ShowNotImplemented { get; } = new SparkTag(nameof(ShowNotImplemented)); + + public static ITag ShowUri { get; } = new SparkTag("ShowUri"); + #endregion + + #region Action + public static ITag SendOrderTag = new SparkTag("SendOrderTag"); + public static ITag ChangeOrderPriceTag = new SparkTag("ChangeOrderPriceTag"); + public static ITag ChangeOrderQuantityTag = new SparkTag("ChangeOrderQuantityTag"); + public static ITag CancelOrderTag = new SparkTag("CancelOrderTag"); + #endregion + + #region Persist + public static ITag PersistCommandTag = new SparkTag("PersistCommandTag"); + public static ITag PersistedItemsTag = new SparkTag("PersistedItemsTag"); + #endregion + + public static ITag ClockTag = new SparkTag("ClockTag"); + } } \ No newline at end of file diff --git a/src/client/spark/Controls/SparkMenu.cs b/src/client/spark/Controls/SparkMenu.cs new file mode 100644 index 000000000..2f1fac1a7 --- /dev/null +++ b/src/client/spark/Controls/SparkMenu.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media; + +namespace bts.controls { + public class SparkMenu : ItemsControl { + static SparkMenu() { + //DefaultStyleKeyProperty.OverrideMetadata(typeof(SparkMenu), new System.Windows.PropertyMetadata(typeof(SparkMenu))); + } + + public SparkMenu() { + this.Background = Brushes.YellowGreen; + } + } +} diff --git a/src/client/spark/Modules/Market/LadderWindowFactory.cs b/src/client/spark/Modules/Market/LadderWindowFactory.cs new file mode 100644 index 000000000..0a541bca8 --- /dev/null +++ b/src/client/spark/Modules/Market/LadderWindowFactory.cs @@ -0,0 +1,82 @@ +using bts.api; +using mbts; +using mbts.spark; +using mbts.ui; +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; + +namespace bts.shell { + + internal class LadderWindowFactory : ShellWindowFactory { + MarketShellModule _module; + IBus _bus; + IWindowManager _wm; + IReadOnlyDictionary _securities = new Dictionary(); + + public LadderWindowFactory(MarketShellModule marketShellModule, IBus bus, IWindowManager wm) + : base("SparkLadder") { + _module = marketShellModule; + _bus = bus; + _wm = wm; + + _dispose = Disposable.Create( + bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s), + bus.subscribe(SparkTags.ShowLadderTag).ObserveOnWPFDispatcher().Subscribe(show_window), + bus.subscribe(SparkTags.ShowLinkedLadder).ObserveOnWPFDispatcher().Subscribe(show_linked) + ); + } + + public async override Task load(LadderSaveState state) { + await Wait.until_true(() => _securities.ContainsKey(state.security_key), TimeSpan.FromSeconds(15)); + if (_securities.TryGetValue(state.security_key, out SecurityMD security)) { + return create_ladder_window(security); + } + return null; + } + + IObservable 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 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); + } + + private void show_window(uint key) { + if (_securities.TryGetValue(key, out SecurityMD md)) { + var window = create_ladder_window(md); + _wm.Windows.Add(window); + } + } + private void show_linked(IObservable keystream) { + var orders = new DemoOrdersModel(_bus); + var view = new LadderView(); + IDisposable sub = null; + var window = + ShellWindow.create(_module, "loading", view, + Disposable.Create(() => { + (view.DataContext as LadderVM)?.Dispose(); + sub?.Dispose(); + }), + s => save(new LadderSaveState() { security_key = ((LadderVM)view.DataContext).security.Id }, s), + Icons.Depth); + sub = + _securities.expand(keystream) + .Select(md => new LadderVM(new LadderModel(md, orders), default_ladder_settings)) + .Aggregate((old, vm) => { old.Dispose(); return vm; }) + .Subscribe(vm => { view.DataContext = vm; window.Title = vm.security.ToString(); }); + } + } + + [ProtoContract] + class LadderSaveState { + [ProtoMember(1)] + public UInt32 security_key; + } +} \ No newline at end of file diff --git a/src/client/spark/Modules/Market/MarketShellModule.cs b/src/client/spark/Modules/Market/MarketShellModule.cs new file mode 100644 index 000000000..45158bc46 --- /dev/null +++ b/src/client/spark/Modules/Market/MarketShellModule.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using mbts.ui; +using System.ComponentModel.Composition; +using bts.api; +using bts.spark; +using mbts.spark; +using mbts.ui.shell; +using static mbts.ui.shell.ProtoBufSerializationHelper; +using mbts; + +namespace bts.shell +{ + [Export(typeof(IShellModule))] + class MarketShellModule : IShellModule { + LadderWindowFactory _lf; + MarketWindowFactory _mvf; + + [ImportingConstructor] + public MarketShellModule(IBus bus, SecuritySource ssrc, IWindowManager wm, [Import("username")]string user_name, WorkspacesModel m) { + _lf = new LadderWindowFactory(this, bus, wm); + _mvf = new MarketWindowFactory(this, bus, ssrc, wm); + } + + #region IShellModule + + public ImageSource icon => Icons.Date; + + public string name => "Market"; + + public int priority => 10; + + public IEnumerable actions => new [] { + SparkCommands.ShowMarketView, + SparkCommands.ShowTimeAndSales + }; + + public Task create(Stream load_stream) { + if (try_deserialize(load_stream, out ShellSerializationHeader header)) { + if (header.name == _lf.name) return _lf.load_window(load_stream); + if (header.name == _mvf.name) return _mvf.load_window(load_stream); + } + return null; + } + + public void Dispose() { + Disposable.dispose(ref _lf); + Disposable.dispose(ref _mvf); + } + + #endregion + } +} diff --git a/src/client/spark/Modules/Market/MarketWindowFactory.cs b/src/client/spark/Modules/Market/MarketWindowFactory.cs new file mode 100644 index 000000000..07f9933fb --- /dev/null +++ b/src/client/spark/Modules/Market/MarketWindowFactory.cs @@ -0,0 +1,72 @@ +using bts.api; +using mbts; +using mbts.spark; +using mbts.ui; +using ProtoBuf; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Reactive.Linq; +using mbts.ui.spark; +using System; + +namespace bts.shell { + internal class MarketWindowFactory : ShellWindowFactory { + MarketShellModule _module; + IBus _bus; + SecuritySource _ssrc; + IWindowManager _wm; + IReadOnlyDictionary _securities = new Dictionary(); + + public MarketWindowFactory(MarketShellModule marketShellModule, IBus bus, SecuritySource ssrc, IWindowManager wm) : base("MarketView") { + _module = marketShellModule; + _bus = bus; + _ssrc = ssrc; + _wm = wm; + + _dispose = Disposable.Create( + bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s), + bus.subscribe(SparkTags.ShowMarketViewTag).ObserveOnWPFDispatcher().Subscribe(show_market_view) + ); + } + + void show_market_view(IEnumerable securities) { + _wm.Windows.Add( + create_market_view(securities, null)); + } + + public override Task load(StartupData data) { + return Task.FromResult( + create_market_view(_securities.expand(data.securities).Select(s => s.security), data.sorting_criteria) + ); + } + + IShellWindow create_market_view(IEnumerable securities, IReadOnlyCollection sorting) { + var vm = new MarketViewVM(_bus, _ssrc, securities, sorting); + var view = new MarketViewView { DataContext = vm }; + const double two_thirds = 2.0 / 3.0; + const double title_panel_height = 32.0, col_header_height = 26 + two_thirds + 10.0; + double row_height = vm.row_height + two_thirds; + view.Height = Math.Min(title_panel_height + col_header_height + securities.Count() * row_height, System.Windows.SystemParameters.WorkArea.Height); + view.Width = 720; + return ShellWindow.create(_module, "Market View", view, stream => { + save(vm.get_startup_data(), stream); + }, Icons.Sheets); + } + + [ProtoContract] + public class StartupData { + public const int Version = 1; + public StartupData() { } + public StartupData(SecurityImmutable[] securities, SortingCriteria[] sorting_criteria) { + if (securities != null) this.securities = securities.Select(s => s.Id).ToArray(); + this.sorting_criteria = sorting_criteria; + } + [ProtoMember(1)] + public uint[] securities; + [ProtoMember(2)] + public SortingCriteria[] sorting_criteria; + } + + } +} \ No newline at end of file diff --git a/src/client/spark/Modules/Settings/SettingsShellModule.cs b/src/client/spark/Modules/Settings/SettingsShellModule.cs new file mode 100644 index 000000000..2b8cd145a --- /dev/null +++ b/src/client/spark/Modules/Settings/SettingsShellModule.cs @@ -0,0 +1,32 @@ +using mbts.ui; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using bts.spark; +using System.IO; +using System.Windows.Media; +using mbts.spark; + +namespace bts.ui +{ + class SettingsShellModule : IShellModule { + public ImageSource icon => Icons.Admin; + + public string name => "Settings"; + + public int priority => 40; + + public IEnumerable actions => new []{ + SparkCommands.ShowWorkspaces, + SparkCommands.ShowSettings + }; + + public Task create(Stream load_stream) { + throw new NotImplementedException(); + } + + public void Dispose() { } + } +} diff --git a/src/client/spark/Modules/Spreader/SpreaderShellModule.cs b/src/client/spark/Modules/Spreader/SpreaderShellModule.cs new file mode 100644 index 000000000..117d483a8 --- /dev/null +++ b/src/client/spark/Modules/Spreader/SpreaderShellModule.cs @@ -0,0 +1,32 @@ +using mbts.ui; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using bts.spark; +using System.IO; +using System.Windows.Media; + +namespace bts.shell +{ + class SpreaderShellModule : IShellModule { + public ImageSource icon => Icons.Cube3d; + + public string name => "Spreader"; + + public int priority => 30; + + public IEnumerable actions => new[] { + SparkCommands.ShowSyntheticSpreads, + SparkCommands.ShowLatencyReport + }; + + public Task create(Stream load_stream) { + throw new NotImplementedException(); + } + + public void Dispose() { + } + } +} diff --git a/src/client/spark/Modules/Support/SupportShellModule.cs b/src/client/spark/Modules/Support/SupportShellModule.cs new file mode 100644 index 000000000..2e5a23931 --- /dev/null +++ b/src/client/spark/Modules/Support/SupportShellModule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bts.Modules.Support +{ + class SupportShellModule + { + } +} diff --git a/src/client/spark/Modules/Trading/TradingShellModule.cs b/src/client/spark/Modules/Trading/TradingShellModule.cs new file mode 100644 index 000000000..714728b2f --- /dev/null +++ b/src/client/spark/Modules/Trading/TradingShellModule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bts.Modules.Trading +{ + class TradingShellModule + { + } +} diff --git a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs index fdd0f0c5b..2085e6492 100644 --- a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs @@ -13,6 +13,7 @@ using mbts; using System.Reactive.Subjects; using System.Windows.Threading; using System.Collections.Specialized; +using mbts.spark; namespace mbts { @@ -296,6 +297,7 @@ namespace mbts source.ObserveOn(SynchronizationContext.Current) : source; } + public static IObservable ObserveOnWPFDispatcher(this IObservable source) { return ObserveOnDispatcher(source); } public static string list_string(this IEnumerable vals, string separator = " ") { return list_string(vals.Select(v => v.ToString()), separator); } public static string list_string(this IEnumerable vals, string separator = " ") { @@ -415,6 +417,20 @@ namespace mbts return has_value; } + internal static IEnumerable expand(this IReadOnlyDictionary self, IEnumerable keys) { + return keys.SelectMany(key => { + if (self.TryGetValue(key, out SecurityMD md)) return new[] { md }; + return Enumerable.Empty(); + }); + } + + internal static IObservable expand(this IReadOnlyDictionary self, IObservable keys) { + return keys.SelectMany(key => { + if (self.TryGetValue(key, out SecurityMD md)) return new[] { md }; + return Enumerable.Empty(); + }); + } + } } diff --git a/src/client/spark/mspark/Core/SparkBusData.cs b/src/client/spark/mspark/Core/SparkBusData.cs index 547a3907f..d1ba0d481 100644 --- a/src/client/spark/mspark/Core/SparkBusData.cs +++ b/src/client/spark/mspark/Core/SparkBusData.cs @@ -50,9 +50,6 @@ namespace mbts.spark } public class ShowAuditLogsMessage { } public class ShowFillsMessage { } - public class ShowLinkedLadderMessage : BusMessageWrapper> { - public ShowLinkedLadderMessage(IObservable security_md) : base(security_md) { } - } public class ShowMarketViewMessage : BusMessageWrapper> { public ShowMarketViewMessage(IReadOnlyCollection securities) : base(securities) { } } diff --git a/src/client/spark/mspark/Ladder/LadderVM.cs b/src/client/spark/mspark/Ladder/LadderVM.cs index 9d1f15235..acf99cae7 100644 --- a/src/client/spark/mspark/Ladder/LadderVM.cs +++ b/src/client/spark/mspark/Ladder/LadderVM.cs @@ -25,8 +25,6 @@ namespace mbts.spark { Order _order_template; LadderSettings _settings; - public const string SAVE_NAME = "SparkLadder"; - public LadderVM(LadderModel model, IObservable settings) { _model = model; _order_template = OrderDataHelper.Defaults.Order(_model.security); @@ -237,14 +235,6 @@ namespace mbts.spark { } #endregion - internal void save_state(Stream output) { - ShellSerializationHeader header = new ShellSerializationHeader() { - version = (int)md.key, - name = SAVE_NAME - }; - ProtoBuf.Serializer.SerializeWithLengthPrefix(output, header, ProtoBuf.PrefixStyle.Fixed32); - } - protected override void Dispose(bool disposing) { _timer.Stop(); } diff --git a/src/client/spark/mspark/MarketView/MarketViewModel.cs b/src/client/spark/mspark/MarketView/MarketViewModel.cs index b4cadaf72..57e607721 100644 --- a/src/client/spark/mspark/MarketView/MarketViewModel.cs +++ b/src/client/spark/mspark/MarketView/MarketViewModel.cs @@ -34,7 +34,7 @@ namespace mbts.spark public DemoOrdersModel orders_model => _orders_model; public IObservable security_position(security_key key) { return _positions_demuxer.subscribe(key).DistinctUntilChanged(); } - public void show_ladder(SecurityImmutable security) { _bus.post(ShowLadderTag, new ShowLadderMessage(security)); } + public void show_ladder(SecurityImmutable security) { _bus.post(ShowLadderTag, security.Id); } public void show_order_modify(Order order) { _bus.post(ShowOrderModifyTag, new ShowOrderModifyMessage(order)); } public void show_order_ticket(Order order) { _orders_model.show_order_ticket(order); } public void set_securities(IEnumerable securities) { _securities_subject.OnNext(new HashSet(securities.Select(s => s.Id))); } diff --git a/src/client/spark/mspark/MarketView/MarketViewVM.cs b/src/client/spark/mspark/MarketView/MarketViewVM.cs index f47bcc885..ce1bba55c 100644 --- a/src/client/spark/mspark/MarketView/MarketViewVM.cs +++ b/src/client/spark/mspark/MarketView/MarketViewVM.cs @@ -23,10 +23,7 @@ namespace mbts.spark { internal partial class MarketViewVM : DisposableViewModelBase, IDisposable { - public const int VERSION = 1; - public const string SAVE_NAME = "MarketView"; - - public MarketViewVM(IBus bus, SecuritySource ssrc, IReadOnlyCollection securities, IReadOnlyCollection sorting_criteria) { + public MarketViewVM(IBus bus, SecuritySource ssrc, IEnumerable securities, IReadOnlyCollection sorting_criteria) { _bus = bus; _ssrc = ssrc; _resources.Add(_model = new MarketViewModel(bus)); @@ -109,21 +106,8 @@ namespace mbts.spark public DataGridCellInfo current_cell { get => _current_cell.Value; set => _current_cell.set(value); } public ContextMenuVM context_menu => _context_menu; - public StartupData get_startup_data() { return new StartupData(_rows.Select(r => r.security).ToArray(), rows_view.SortDescriptions.Select(sd => new SortingCriteria { col_name = sd.PropertyName, is_ascending = sd.Direction == ListSortDirection.Ascending }).ToArray()); } + public bts.shell.MarketWindowFactory.StartupData get_startup_data() { return new bts.shell.MarketWindowFactory.StartupData(_rows.Select(r => r.security).ToArray(), rows_view.SortDescriptions.Select(sd => new SortingCriteria { col_name = sd.PropertyName, is_ascending = sd.Direction == ListSortDirection.Ascending }).ToArray()); } protected override void Dispose(bool disposing) { Disposable.dispose(_resources); } - [ProtoContract] - public class StartupData { - public const int Version = 1; - public StartupData() { } - public StartupData(SecurityImmutable[] securities, SortingCriteria[] sorting_criteria) { - if (securities != null) this.securities = securities.Select(s => ((IImmutableMessage)s).ToByteArray()).ToArray(); - this.sorting_criteria = sorting_criteria; - } - [ProtoMember(1)] - public byte[][] securities; - [ProtoMember(2)] - public SortingCriteria[] sorting_criteria; - } } } \ No newline at end of file diff --git a/src/client/spark/mspark/MarketView/MarketViewView.xaml b/src/client/spark/mspark/MarketView/MarketViewView.xaml index d07ae060b..a558ddf99 100644 --- a/src/client/spark/mspark/MarketView/MarketViewView.xaml +++ b/src/client/spark/mspark/MarketView/MarketViewView.xaml @@ -8,9 +8,6 @@ TextElement.FontSize="11"> - - - - - - - \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/Admin/DefaultOrderParametersMenu.cs b/src/client/spark/mspark/Shell/Admin/DefaultOrderParametersMenu.cs deleted file mode 100644 index ab6090173..000000000 --- a/src/client/spark/mspark/Shell/Admin/DefaultOrderParametersMenu.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using mbts.ui.controls; -using System.ComponentModel.Composition; -using System.Collections.ObjectModel; -using mbts.ui; -using bts.api; -using System.IO; -using bts.spark; -using Google.Protobuf; - -namespace mbts.spark -{ - [Export(typeof(IAdminMenuItem))] - class DefaultOrderParametersMenu : IAdminMenuItem - { - public MenuLaunchMenuViewModel MenuItem { get; set; } - public SparkAdminShellModule Owner { get; set; } - - private IWindowManager _wm; - private IBus _bus; - - public IEnumerable default_orders - { - get - { - return new IMessage[] - { - new bts.spark.MarketOrder (), - new bts.spark.LimitOrder (), - new bts.spark.StopMarketOrder (), - new bts.spark.StopLimitOrder (), - new bts.spark.IcebergOrder (), - }; - } - } - - [ImportingConstructor] - public DefaultOrderParametersMenu(IWindowManager wm, IBus bus) - { - _wm = wm; - _bus = bus; - - MenuItem = new MenuLaunchMenuViewModel { Header = "Default Order Parameters", MenuItems = new ObservableCollection { } }; - - foreach (IMessage im in default_orders) - { - string name = OrderUtils.display_name(im); - - MenuItem.MenuItems.Add( - new MenuLaunchMenuViewModel - { - Header = name, - Command = new DelegateCommand(() => - { - var editor_dialog = new ObjectEditorDialog(im) { Title = name }; - editor_dialog.move_to_mouse(); - editor_dialog.Show(); - - editor_dialog.CommittedValues.Subscribe( - x => BTSMessageBox.Show("Write this down: {0}".fmt(x.ToString())), - ex => Logger.error(bts.log.Subsystem.Ui, "Error: {0}".fmt(ex.Message), "DefaultOrderParametersMenu.cs") - ); - }) - }); - } - - } - - public void load_state(Stream state = null) - { - - } - - public Task create(Stream load_stream) - { - return null; - } - - public void Dispose() {} - - public void get_state(Stream save_here) { } - } -} diff --git a/src/client/spark/mspark/Shell/Admin/DisplaySettingsMenu.cs b/src/client/spark/mspark/Shell/Admin/DisplaySettingsMenu.cs deleted file mode 100644 index a299098d1..000000000 --- a/src/client/spark/mspark/Shell/Admin/DisplaySettingsMenu.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using mbts.ui.controls; -using System.ComponentModel.Composition; -using mbts.ui; -using System.IO; -using bts.api; -using mbts.ui.shell; - -namespace mbts.spark -{ - [Export(typeof(IAdminMenuItem))] - class DisplaySettingsMenu : IAdminMenuItem - { - - public MenuLaunchMenuViewModel MenuItem { get; set; } - - public SparkAdminShellModule Owner { get; set; } - - IBus _bus; - IWindowManager _wm; - - [ImportingConstructor] - public DisplaySettingsMenu(IBus bus, IWindowManager wm) - { - _bus = bus; - _wm = wm; - - - MenuItem = new MenuLaunchMenuViewModel - { - Header = "Display Settings", - Command = new DelegateCommand(() => { - BTSMessageBox.Show("not here"); - }) - }; - } - - public void load_state(Stream state = null){} - - public Task create(Stream load_stream) - { - return null; - } - - public void Dispose() {} - - public void get_state(Stream save_here) { } - } -} diff --git a/src/client/spark/mspark/Shell/Admin/IAdminMenuItem.cs b/src/client/spark/mspark/Shell/Admin/IAdminMenuItem.cs deleted file mode 100644 index dea9dfbb2..000000000 --- a/src/client/spark/mspark/Shell/Admin/IAdminMenuItem.cs +++ /dev/null @@ -1,28 +0,0 @@ -using mbts.ui; -using mbts.ui.controls; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace mbts -{ - interface IAdminMenuItem: IDisposable - { - // If the MenuItems are set they will be displayed in a submenu, otherwise set the Command - MenuLaunchMenuViewModel MenuItem { get; } - - SparkAdminShellModule Owner { get; set; } - - void get_state(Stream save_here); - - Task create(Stream load_stream); - - void load_state(Stream state = null); - - - - } -} diff --git a/src/client/spark/mspark/Shell/Admin/SparkAdminShellModule.cs b/src/client/spark/mspark/Shell/Admin/SparkAdminShellModule.cs deleted file mode 100644 index dd4d220f2..000000000 --- a/src/client/spark/mspark/Shell/Admin/SparkAdminShellModule.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; -using mbts; -using mbts.ui; -using mbts.ui.shell; -using System.ComponentModel.Composition; -using System.Windows.Input; -using System.Collections.ObjectModel; -using mbts.ui.controls; -using ProtoBuf; - -namespace mbts -{ - - [Export(typeof(IShellModule))] - class SparkAdminShellModule : IShellModule - { - public ImageSource icon { get { return Icons.Admin; } } - - public string name { get { return "Admin"; } } - - public int priority { get { return 50; } } - - IEnumerable _menu_items; - MenuLaunchMenuViewModel _menu_content; - IWindowManager _wm; - - [ImportingConstructor] - public SparkAdminShellModule(IWindowManager wm, [ImportMany]IEnumerable menu_items) - { - _wm = wm; - _menu_content = new MenuLaunchMenuViewModel(); - _menu_content.MenuItems = new ObservableCollection { }; - - _menu_items = menu_items.OrderBy((IAdminMenuItem x) => x.MenuItem.Header); - - foreach (var menu in _menu_items) - { - menu.Owner = this; - _menu_content.MenuItems.Add(menu.MenuItem); - } - - - } - - public IShellWindow launch_ui - { - get - { - return new MenuLaunchMenu(_menu_content); - } - } - - public Task create(Stream load_stream) - { - ShellSerializationHeader header = ProtoBuf.Serializer.DeserializeWithLengthPrefix(load_stream, ProtoBuf.PrefixStyle.Fixed32); - - BasicAdminMenuItem comparable_menu_item = new BasicAdminMenuItem { MenuItem = new MenuLaunchMenuViewModel { Header = header.name } }; - - int item_index = _menu_items.ToList().BinarySearch(0, _menu_items.Count(), comparable_menu_item, Comparer.Create( - (x, y) => (x).GetType().Name.CompareTo(y.MenuItem.Header)) - ); - - return item_index>=0 ? _menu_items.ElementAt(item_index).create(load_stream) : null; - - } - - public void Dispose() - { - foreach (IAdminMenuItem item in _menu_items) - { - item.Dispose(); - } - } - - public void get_state(Stream save_here) - { - foreach (IAdminMenuItem item in _menu_items) - { - item.get_state(save_here); - } - } - - public void load_state(Stream state = null) - { - if (state != null) - { - foreach (IAdminMenuItem item in _menu_items) - { - item.load_state(state); - } - } - } - - public void start() { } - - private class BasicAdminMenuItem : IAdminMenuItem - { - public MenuLaunchMenuViewModel MenuItem { get; set; } - - public SparkAdminShellModule Owner { get; set; } - - public Task create(Stream load_stream) { return null;} - public void Dispose() { } - public void get_state(Stream save_here) {} - public void load_state(Stream state = null) { } - } - - } - - -} diff --git a/src/client/spark/mspark/Shell/Fills/FillsView.xaml b/src/client/spark/mspark/Shell/Fills/FillsView.xaml index 7972121ec..d953549f6 100644 --- a/src/client/spark/mspark/Shell/Fills/FillsView.xaml +++ b/src/client/spark/mspark/Shell/Fills/FillsView.xaml @@ -8,9 +8,6 @@ TextElement.FontSize="11"> - - - @@ -31,10 +28,8 @@ - - - - + diff --git a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml b/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml deleted file mode 100644 index 79f512768..000000000 --- a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml.cs b/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml.cs deleted file mode 100644 index 9c6c1a524..000000000 --- a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenu.xaml.cs +++ /dev/null @@ -1,62 +0,0 @@ -using mbts.spark; -using System; -using System.IO; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; - -namespace mbts.ui.spark -{ - /// - /// Interaction logic for LaunchMenu.xaml - /// - public partial class LaunchMenu : UserControl, IShellWindow - { - public LaunchMenu() { - InitializeComponent(); - } - - public string Title { get; set; } - public event Action TitleChanged = () => { }; - public ImageSource Icon { get; set; } - public event Action IconChanged = () => { }; - public IShellModule Owner { get; set; } - public void Dispose() { (DataContext as IDisposable)?.Dispose(); } - public void GetState(Stream save_here) { } - public ShellWindowUI GetContent() { return new ShellWindowUI(this); } - - public static readonly DependencyProperty GroupStyleProperty = DependencyProperty.RegisterAttached("GroupStyle", typeof(GroupStyle), typeof(LaunchMenu), new PropertyMetadata(null, OnGroupStyleChanged)); - private static void OnGroupStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var target = d as ItemsControl; - if (target != null) { - var old_style = e.OldValue as GroupStyle; - if (old_style != null) target.GroupStyle.Remove(old_style); - var new_style = e.NewValue as GroupStyle; - if (new_style != null) target.GroupStyle.Add(new_style); - } - } - public static GroupStyle GetGroupStyle(DependencyObject d) { return d.GetValue(GroupStyleProperty) as GroupStyle; } - public static void SetGroupStyle(DependencyObject d, GroupStyle value) { d.SetValue(GroupStyleProperty, value); } - } - - internal class LaunchMenuItemTemplateSelector : DataTemplateSelector - { - public enum Template { Action, Security, Securities, Group } - public interface IHaveTemplate { Template template_key { get; } } - - public DataTemplate ActionTemplate { get; set; } - public DataTemplate SecurityActionTemplate { get; set; } - public DataTemplate SecuritiesActionTemplate { get; set; } - public DataTemplate GroupTemplate { get; set; } - - public override DataTemplate SelectTemplate(object item, DependencyObject container) { - switch ((item as IHaveTemplate)?.template_key) { - case Template.Action: return ActionTemplate; - case Template.Security: return SecurityActionTemplate; - case Template.Securities: return SecuritiesActionTemplate; - case Template.Group: return GroupTemplate; - default: return null; - } - } - } -} \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuItemVM.cs b/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuItemVM.cs deleted file mode 100644 index ad45debb8..000000000 --- a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuItemVM.cs +++ /dev/null @@ -1,80 +0,0 @@ -using bts.api; -using mbts.ui; -using mbts.ui.utility; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Linq; -using System.Reactive.Linq; -using System.Windows.Input; -using System.Windows.Media; -using static mbts.ui.spark.LaunchMenuItemTemplateSelector; - -namespace mbts.spark.menu_items -{ - internal class LaunchMenuItemVM : MenuItemVM, IHaveTemplate, IDisposable - { - #region Static Factory - public static IList CreateMenu(SecuritySource ssrc, params IMenuItem[] models) { - return models.Select(i => Create(i, ssrc)).ToList(); - } - - public static LaunchMenuItemVM Create(IMenuItem model, SecuritySource ssrc) { - var act_mi = model as IMenuActionItem; - if (act_mi != null) return Create(act_mi); - var secs_mi = model as IMenuSecuritiesActionItem; - if (secs_mi != null) return Create(secs_mi, ssrc); - var grp_mi = model as IMenuGroupItem; - if (grp_mi != null) return Create(grp_mi, ssrc); - throw new NotImplementedException("LaunchMenuVM cannot create vm for {0} ({1}).".fmt(model?.display_name ?? "unnamed", model?.GetType().ToString() ?? "null")); - } - - public new static LaunchMenuItemVM Create(IMenuActionItem model) { - var command = new DelegateCommand(model.execute, model.can_execute); - model.can_execute_changed += () => command.RaiseCanExecuteChanged(); - return new LaunchMenuItemVM(model.display_name, model.sectional_id, model.icon, command, Template.Action, dispose:model as IDisposable); - } - - public static LaunchMenuItemVM Create(IMenuSecuritiesActionItem model, SecuritySource ssrc) { - SecurityLaunchMenuItem rv = null; - IDisposable sub = null; - IRaiseCanExecuteChangedCommand command = null; - command = new DelegateCommand(() => { - using (sub) model.execute(rv.selected_securities.ToList()); - rv.selected_securities.Clear(); - sub = rv.selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged()); - }, () => model.can_execute(rv.selected_securities)); - rv = new SecurityLaunchMenuItem(model.display_name, model.sectional_id, model.icon, command, Template.Securities, Disposable.Create(() => { (model as IDisposable)?.Dispose(); sub?.Dispose(); }), ssrc); - sub = rv.selected_securities.Subscribe((s, e) => command.RaiseCanExecuteChanged()); - model.can_execute_changed += () => command.RaiseCanExecuteChanged(); - return rv; - } - - public static LaunchMenuItemVM Create(IMenuGroupItem model, SecuritySource ssrc) { - return new LaunchMenuItemVM(model.display_name, model.sectional_id, model.icon, template_key:Template.Group, items:CreateMenu(ssrc, model.items.ToArray())); - } - #endregion - - protected LaunchMenuItemVM(string display_name, string sectional_id, ImageSource icon, ICommand command=null, Template template_key=Template.Action, IEnumerable items=null, IDisposable dispose=null) - : base(Observable.Return(display_name), sectional_id, icon, command, items, dispose) { - this.template_key = template_key; - } - - public Template template_key { get; } - } - - internal class SecurityLaunchMenuItem : LaunchMenuItemVM - { - internal SecurityLaunchMenuItem(string display_name, string sectional_id, ImageSource icon, ICommand launch_command, Template template_key, IDisposable dispose, SecuritySource src) - : base(display_name, sectional_id, icon, template_key:template_key, dispose:dispose) { - this.launch_command = launch_command; - _securities = new RXObservableCollection(src.GetObservable()); - } - private RXObservableCollection _securities; - public RXObservableCollection securities => _securities; - public ObservableCollection selected_securities { get; } = new ObservableCollection(); - public ICommand launch_command { get; } - protected override void Dispose(bool disposing) { Disposable.dispose(ref _securities); } - } -} \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuVM.cs b/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuVM.cs deleted file mode 100644 index 177ea5a7b..000000000 --- a/src/client/spark/mspark/Shell/LaunchMenu/LaunchMenuVM.cs +++ /dev/null @@ -1,18 +0,0 @@ -using mbts.spark.menu_items; -using mbts.ui.shell; -using System.ComponentModel; -using System.Windows.Data; - -namespace mbts.spark -{ - internal class LaunchMenuVM : ViewModelBase - { - public LaunchMenuVM(SecuritySource ssrc, params IMenuItem[] models) { - var vms = LaunchMenuItemVM.CreateMenu(ssrc, models); - items_view = CollectionViewSource.GetDefaultView(vms); - items_view.GroupDescriptions.Add(new PropertyGroupDescription(nameof(IMenuItem.sectional_id))); - } - - public ICollectionView items_view { get; } - } -} \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/MarketModule.cs b/src/client/spark/mspark/Shell/MarketModule.cs index e5571436f..212421f5c 100644 --- a/src/client/spark/mspark/Shell/MarketModule.cs +++ b/src/client/spark/mspark/Shell/MarketModule.cs @@ -1,195 +1,114 @@ -using bts.api; -using bts.spark; -using mbts.spark.menu_items; -using mbts.spark.utilities; -using mbts.ui; -using mbts.ui.spark; -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.IO; -using System.Linq; -using System.Reactive.Linq; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; -using static mbts.spark.SparkBusData; -using static mbts.spark.SparkTags; -using static mbts.ui.shell.ProtoBufSerializationHelper; -using SecurityKey = System.UInt32; +//using bts.api; +//using bts.spark; +//using mbts.spark.menu_items; +//using mbts.spark.utilities; +//using mbts.ui; +//using mbts.ui.spark; +//using System; +//using System.Collections.Generic; +//using System.ComponentModel.Composition; +//using System.IO; +//using System.Linq; +//using System.Reactive.Linq; +//using System.Threading.Tasks; +//using System.Windows; +//using System.Windows.Media; +//using static mbts.spark.SparkBusData; +//using static mbts.spark.SparkTags; +//using static mbts.ui.shell.ProtoBufSerializationHelper; +//using SecurityKey = System.UInt32; -namespace mbts.spark -{ - [Export(typeof(IShellModule))] - internal class MarketModule : IShellModule { - [ImportingConstructor] - public MarketModule(IBus bus, SecuritySource ssrc, IWindowManager wm, [Import("username")]string user_name) { - _bus = bus; - _ssrc = ssrc; - _wm = wm; - _user_name = user_name; - _dispose = Disposable.Create( - _bus.subscribe(SecuritiesTag).ObserveOnDispatcher().Subscribe(s => _securities = s), - _bus.subscribe(SyntheticSecuritiesTag).ObserveOnDispatcher().Subscribe(ssm => _synthetic_strategy_map = ssm.data), - _bus.subscribe(ShowMarketViewTag).ObserveOnDispatcher().Subscribe(show_market_view), - _bus.subscribe(ShowSpreadMatrixTag).ObserveOnDispatcher().Subscribe(show_spread_matrix), - _bus.subscribe(ShowLadderTag).ObserveOnDispatcher().Subscribe(show_ladder), - _bus.subscribe(ShowLadderTag).ObserveOnDispatcher().Subscribe(show_linked_ladder), - _bus.subscribe(ShowOrderModifyTag).ObserveOnDispatcher().Subscribe(show_order_modify), - _bus.subscribe(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_order_ticket), - _bus.subscribe(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_linked_order_ticket), - _bus.subscribe(ShowSyntheticCreateTag).ObserveOnDispatcher().Subscribe(show_synthetic_create_editor), - _bus.subscribe(ShowSyntheticStrategyTag).ObserveOnDispatcher().Subscribe(show_synthetic_strategy_editor) - ); - } - private readonly IBus _bus; - private readonly SecuritySource _ssrc; - private readonly IWindowManager _wm; - private readonly IDisposable _dispose; - private readonly string _user_name; - private IReadOnlyDictionary _securities = new Dictionary(); - private IDictionary _synthetic_strategy_map = new Dictionary(); +//namespace mbts.spark +//{ +// [Export(typeof(IShellModule))] +// internal class MarketModule : IShellModule { +// [ImportingConstructor] +// public MarketModule(IBus bus, SecuritySource ssrc, IWindowManager wm, [Import("username")]string user_name) { +// _bus = bus; +// _ssrc = ssrc; +// _wm = wm; +// _user_name = user_name; +// _dispose = Disposable.Create( +// _bus.subscribe(SyntheticSecuritiesTag).ObserveOnDispatcher().Subscribe(ssm => _synthetic_strategy_map = ssm.data), +// _bus.subscribe(ShowSpreadMatrixTag).ObserveOnDispatcher().Subscribe(show_spread_matrix), +// _bus.subscribe(ShowOrderModifyTag).ObserveOnDispatcher().Subscribe(show_order_modify), +// _bus.subscribe(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_order_ticket), +// _bus.subscribe(ShowOrderTicketTag).ObserveOnDispatcher().Subscribe(show_linked_order_ticket), +// _bus.subscribe(ShowSyntheticCreateTag).ObserveOnDispatcher().Subscribe(show_synthetic_create_editor), +// _bus.subscribe(ShowSyntheticStrategyTag).ObserveOnDispatcher().Subscribe(show_synthetic_strategy_editor) +// ); +// } - public int priority => 2; - public string name => "Market"; - public ImageSource icon => Icons.Date; - public IShellWindow launch_ui => new LaunchMenu { - DataContext = new LaunchMenuVM( - _ssrc, - new MarketViewMenuItem(_bus), - new SpreadMatrixMenuItem(_bus), - new LadderMenuItem(_bus), - new OrderTicketMenuItem(new DemoOrdersModel(_bus)), - MenuItemFactory.Create("Security Browser...", "sb", Icons.Coins, execute: show_security_browser)) - }; - public void load_state(Stream state = null) { } - public void get_state(Stream save_here) { } - public async Task create(Stream load_stream) { - if (try_deserialize(load_stream, out ShellSerializationHeader header)) { - switch (header.name) { - case LadderVM.SAVE_NAME: - var key = (uint)header.version; // ಠ_ಠ - await Wait.until_true(() => _securities != null && _securities.ContainsKey(key), TimeSpan.FromSeconds(15)); - if (_securities != null && _securities.TryGetValue((uint)header.version, out SecurityMD md)) return create_ladder_window(md); - else break; - case MarketViewVM.SAVE_NAME: - if (try_deserialize(load_stream, out MarketViewVM.StartupData data)) return create_market_view(data.securities.Select(x => (SecurityImmutable)deserialize(x)).ToList(), data.sorting_criteria); - else break; - } - } - return null; - } - public void start() { } - public void Dispose() { _dispose.Dispose(); } +// public IShellWindow launch_ui => new LaunchMenu { +// DataContext = new LaunchMenuVM( +// _ssrc, +// new MarketViewMenuItem(_bus), +// new SpreadMatrixMenuItem(_bus), +// new LadderMenuItem(_bus), +// new OrderTicketMenuItem(new DemoOrdersModel(_bus)), +// MenuItemFactory.Create("Security Browser...", "sb", Icons.Coins, execute: show_security_browser)) +// }; - #region SecurityBrowser - private void show_security_browser() { new SecurityBrowser { DataContext = new SecurityBrowserVM(_bus, _ssrc) }.Show(-200, -300, true); } - #endregion +// #region SpreadMatrix +// private void show_spread_matrix(ShowSpreadMatrixMessage msg) { } +// #endregion - #region MarketView - private void show_market_view(ShowMarketViewMessage msg) { _wm.Windows.Add(create_market_view(msg.data, null)); } - private IShellWindow create_market_view(IReadOnlyCollection securities, IReadOnlyCollection sorting) { - var vm = new MarketViewVM(_bus, _ssrc, securities, sorting); - var view = new MarketViewView { DataContext = vm }; - const double two_thirds = 2.0 / 3.0; - const double title_panel_height = 32.0, col_header_height = 26 + two_thirds + 10.0; - double row_height = vm.row_height + two_thirds; - view.Height = Math.Min(title_panel_height + col_header_height + securities.Count * row_height, System.Windows.SystemParameters.WorkArea.Height); - view.Width = 720; - return ShellWindow.create(this, "Market View", view, stream => { - serialize(stream, new ShellSerializationHeader { name = MarketViewVM.SAVE_NAME, version = MarketViewVM.VERSION }); - serialize(stream, vm.get_startup_data()); - }, Icons.Sheets); - } - #endregion +// #region OrderTicket +// private void show_order_modify(ShowOrderModifyMessage msg) { show_order_ticket(msg.data, true); } +// private void show_order_ticket(ShowOrderTicketMessage msg) { show_order_ticket(msg.data, false); } +// private void show_order_ticket(IReadOnlyCollection orders, bool is_modify) { +// foreach (var o in orders) { +// if (_securities.TryGetValue(o.Security.Id, out SecurityMD smd)) { +// if (string.IsNullOrEmpty(o.User)) o.User = _user_name; +// var vm = new OrderTicketVM(new DemoOrdersModel(_bus), o, _get_ladder_settings(), _bus); +// (is_modify ? (Window)new OrderModificationDialog { DataContext = vm } : new OrderTicket { DataContext = vm }).Show(-200, -160, true); +// } +// } +// } +// private void show_linked_order_ticket(ShowLinkedOrderTicketMessage msg) { +// new OrderTicket { +// DataContext = new OrderTicketVM(new DemoOrdersModel(_bus), msg.data, _get_ladder_settings(), _bus) +// }.Show(-200, -160, true); +// } +// #endregion - #region SpreadMatrix - private void show_spread_matrix(ShowSpreadMatrixMessage msg) { } - #endregion - - #region OrderTicket - private void show_order_modify(ShowOrderModifyMessage msg) { show_order_ticket(msg.data, true); } - private void show_order_ticket(ShowOrderTicketMessage msg) { show_order_ticket(msg.data, false); } - private void show_order_ticket(IReadOnlyCollection orders, bool is_modify) { - foreach (var o in orders) { - if (_securities.TryGetValue(o.Security.Id, out SecurityMD smd)) { - if (string.IsNullOrEmpty(o.User)) o.User = _user_name; - var vm = new OrderTicketVM(new DemoOrdersModel(_bus), o, _get_ladder_settings(), _bus); - (is_modify ? (Window)new OrderModificationDialog { DataContext = vm } : new OrderTicket { DataContext = vm }).Show(-200, -160, true); - } - } - } - private void show_linked_order_ticket(ShowLinkedOrderTicketMessage msg) { - new OrderTicket { - DataContext = new OrderTicketVM(new DemoOrdersModel(_bus), msg.data, _get_ladder_settings(), _bus) - }.Show(-200, -160, true); - } - #endregion - - #region Ladder - private void show_ladder(ShowLadderMessage msg) { foreach (var s in msg.data) if (_securities.TryGetValue(s.Id, out SecurityMD smd)) show_ladder(smd); } - private void show_ladder(SecurityMD sec) { _wm.Windows.Add(create_ladder_window(sec)); } - private async void show_linked_ladder(ShowLinkedLadderMessage msg) { _wm.Windows.Add(await create_ladder_window(msg.data)); } - private IShellWindow create_ladder_window(SecurityMD md) { - var model = new LadderModel(md, new DemoOrdersModel(_bus)); - var vm = new LadderVM(model, _get_ladder_settings()); - var view = new LadderView { DataContext = vm }; - return ShellWindow.create(this, md.security.ToString(null), view, vm, vm.save_state, Icons.Depth); - } - private IObservable _get_ladder_settings() { return Observable.Return(new LadderSettings()); } - private async Task create_ladder_window(IObservable security_md) { - var first_smd = await security_md.FirstAsync(); - DemoOrdersModel om = new DemoOrdersModel(_bus); - LadderVM vm = new LadderVM(new LadderModel(first_smd, om), _get_ladder_settings()); - LadderView view = new LadderView { DataContext = vm }; - IDisposable sub = null; - var sw = ShellWindow.create(this, first_smd.security.ToString(null), view, Disposable.Create(() => { sub?.Dispose(); vm.Dispose(); }), state => vm.save_state(state), Icons.Depth); - sub = security_md.ObserveOnDispatcher().Subscribe(smd => { - vm.Dispose(); - view.DataContext = vm = new LadderVM(new LadderModel(smd, om), _get_ladder_settings()); - sw.Title = smd.security.ToString(null); - }); - return sw; - } - #endregion - - #region Synthentic - private void show_synthetic_create_editor(ShowSyntheticCreateMessage msg) { - var securities = msg.data; - if (securities.Count == 0) return; - Security synthetic = null; - ExecutionStrategy strategy = null; - if (securities.Count == 1) { - var s = securities.First(); - synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), s); - strategy = _synthetic_strategy_map.TryGetValue(s.Id, out SyntheticExecutionStrategy ses) ? ses.ExecutionStrategy.Clone() : SyntheticDataHelper.Defaults.ExecutionStrategy(s); - } else { - synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), securities.Ordered(SecurityDataHelper.Comparer.Instance)); - strategy = SyntheticDataHelper.Defaults.ExecutionStrategy(securities); - } - show_synthetic_editor(synthetic, strategy); - } - private void show_synthetic_strategy_editor(ShowSyntheticStrategyMessage msg) { - if (msg.data.ContractCase != Security.ContractOneofCase.Synthetic) show_synthetic_editor_warning($"{msg.data} is not a synthetic security."); - else if (!_synthetic_strategy_map.TryGetValue(msg.data.Id, out SyntheticExecutionStrategy ses)) { - string warn_msg = $"Did not find execution strategy for {msg.data}"; - Logger.warn(bts.log.Subsystem.Ui, warn_msg); - show_synthetic_editor_warning(warn_msg); - } else show_synthetic_editor(msg.data.CloneToMutable(), ses.ExecutionStrategy); - } - private void show_synthetic_editor_warning(string warn_msg) { - BTSMessageBox.Show(warn_msg, "Synthetic Strategy", BTSMessageBoxButtons.OK, MessageBoxImage.Exclamation, true, false, true); - } - private void show_synthetic_editor(Security synthetic, ExecutionStrategy strategy) { - var dialog = new SyntheticEditorDialog { DataContext = new SyntheticEditorVM(_bus, synthetic, strategy) }.Show(-200, -300, true); - } - private string find_unique_synthetic_name() { - int i = 1; - string rv = "Synthetic{0}".fmt(i); - var synth_names = _securities.Values.Select(smd => smd.security).Where(s => s.ContractCase == Security.ContractOneofCase.Synthetic).Select(s => s.Synthetic.Name).ToList(); - while (synth_names.Contains(rv)) rv = "Synthetic{0}".fmt(++i); - return rv; - } - #endregion - } -} \ No newline at end of file +// #region Synthentic +// private void show_synthetic_create_editor(ShowSyntheticCreateMessage msg) { +// var securities = msg.data; +// if (securities.Count == 0) return; +// Security synthetic = null; +// ExecutionStrategy strategy = null; +// if (securities.Count == 1) { +// var s = securities.First(); +// synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), s); +// strategy = _synthetic_strategy_map.TryGetValue(s.Id, out SyntheticExecutionStrategy ses) ? ses.ExecutionStrategy.Clone() : SyntheticDataHelper.Defaults.ExecutionStrategy(s); +// } else { +// synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), securities.Ordered(SecurityDataHelper.Comparer.Instance)); +// strategy = SyntheticDataHelper.Defaults.ExecutionStrategy(securities); +// } +// show_synthetic_editor(synthetic, strategy); +// } +// private void show_synthetic_strategy_editor(ShowSyntheticStrategyMessage msg) { +// if (msg.data.ContractCase != Security.ContractOneofCase.Synthetic) show_synthetic_editor_warning($"{msg.data} is not a synthetic security."); +// else if (!_synthetic_strategy_map.TryGetValue(msg.data.Id, out SyntheticExecutionStrategy ses)) { +// string warn_msg = $"Did not find execution strategy for {msg.data}"; +// Logger.warn(bts.log.Subsystem.Ui, warn_msg); +// show_synthetic_editor_warning(warn_msg); +// } else show_synthetic_editor(msg.data.CloneToMutable(), ses.ExecutionStrategy); +// } +// private void show_synthetic_editor_warning(string warn_msg) { +// BTSMessageBox.Show(warn_msg, "Synthetic Strategy", BTSMessageBoxButtons.OK, MessageBoxImage.Exclamation, true, false, true); +// } +// private void show_synthetic_editor(Security synthetic, ExecutionStrategy strategy) { +// var dialog = new SyntheticEditorDialog { DataContext = new SyntheticEditorVM(_bus, synthetic, strategy) }.Show(-200, -300, true); +// } +// private string find_unique_synthetic_name() { +// int i = 1; +// string rv = "Synthetic{0}".fmt(i); +// var synth_names = _securities.Values.Select(smd => smd.security).Where(s => s.ContractCase == Security.ContractOneofCase.Synthetic).Select(s => s.Synthetic.Name).ToList(); +// while (synth_names.Contains(rv)) rv = "Synthetic{0}".fmt(++i); +// return rv; +// } +// #endregion +// } +//} \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/MenuItems/LadderMenuItem.cs b/src/client/spark/mspark/Shell/MenuItems/LadderMenuItem.cs index 00d035135..2869ae236 100644 --- a/src/client/spark/mspark/Shell/MenuItems/LadderMenuItem.cs +++ b/src/client/spark/mspark/Shell/MenuItems/LadderMenuItem.cs @@ -2,6 +2,7 @@ using mbts.ui; using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Media; using static mbts.spark.SparkBusData; using static mbts.spark.SparkTags; @@ -20,7 +21,7 @@ namespace mbts.spark.menu_items public int priority => 2; public ImageSource icon => Icons.Depth; public string sectional_id => MenuItemSections.OrderActiveWindow; - public void execute(IReadOnlyCollection securities) { _bus.post(ShowLadderTag, new ShowLadderMessage(securities)); } + public void execute(IReadOnlyCollection securities) { } public bool can_execute(IReadOnlyCollection securities) { return securities.Count > 0; } public void raise_display_name_changed() { display_name_changed?.Invoke(); } public void raise_can_execute_changed() { can_execute_changed?.Invoke(); } @@ -41,7 +42,7 @@ namespace mbts.spark.menu_items public ImageSource icon => Icons.Depth; public string sectional_id => MenuItemSections.OrderActiveWindow; public bool can_execute() { return true; } - public void execute() { _bus.post(ShowLadderTag, new ShowLinkedLadderMessage(_security_md)); } + public void execute() {} public void raise_display_name_changed() { display_name_changed?.Invoke(); } public void raise_can_execute_changed() { can_execute_changed?.Invoke(); } public event Action display_name_changed; diff --git a/src/client/spark/mspark/Shell/MenuItems/MarketViewMenuItem.cs b/src/client/spark/mspark/Shell/MenuItems/MarketViewMenuItem.cs index fd5e6a20c..9e191a840 100644 --- a/src/client/spark/mspark/Shell/MenuItems/MarketViewMenuItem.cs +++ b/src/client/spark/mspark/Shell/MenuItems/MarketViewMenuItem.cs @@ -19,7 +19,7 @@ namespace mbts.spark.menu_items public int priority => 0; public ImageSource icon => Icons.Sheets; public string sectional_id => MenuItemSections.SecurityWindow; - public void execute(IReadOnlyCollection securities) { _bus.post(SparkTags.ShowMarketViewTag, new SparkBusData.ShowMarketViewMessage(securities.ToList())); } + public void execute(IReadOnlyCollection securities) { _bus.post(SparkTags.ShowMarketViewTag, (securities.ToList())); } public bool can_execute(IReadOnlyCollection securities) { return securities.Any(); } public void raise_display_name_changed() { display_name_changed?.Invoke(); } public void raise_can_execute_changed() { can_execute_changed?.Invoke(); } diff --git a/src/client/spark/mspark/Shell/MenuItems/SyntheticCreateMenuItem.cs b/src/client/spark/mspark/Shell/MenuItems/SyntheticCreateMenuItem.cs index 398e34d9d..9ed040701 100644 --- a/src/client/spark/mspark/Shell/MenuItems/SyntheticCreateMenuItem.cs +++ b/src/client/spark/mspark/Shell/MenuItems/SyntheticCreateMenuItem.cs @@ -22,7 +22,9 @@ namespace mbts.spark.menu_items public int priority => 2; public ImageSource icon => Icons.Tetris; public string sectional_id => MenuItemSections.SecurityWindow; - public void execute(IReadOnlyCollection securities) { _bus.post(ShowSyntheticCreateTag, new ShowSyntheticCreateMessage(securities)); } + public void execute(IReadOnlyCollection securities) { + _bus.post(ShowSyntheticCreateTag, new ShowSyntheticCreateMessage(securities)); + } public bool can_execute(IReadOnlyCollection securities) { return securities.Count > 1 || (securities.Count == 1 && (securities.First().ContractCase == ContractOneofCase.Synthetic || securities.First().ContractCase == ContractOneofCase.Spread)); } diff --git a/src/client/spark/mspark/Shell/MenuItems/TimeAndSalesMenuItem.cs b/src/client/spark/mspark/Shell/MenuItems/TimeAndSalesMenuItem.cs index 25bbd6ff3..90a0f5edb 100644 --- a/src/client/spark/mspark/Shell/MenuItems/TimeAndSalesMenuItem.cs +++ b/src/client/spark/mspark/Shell/MenuItems/TimeAndSalesMenuItem.cs @@ -19,7 +19,7 @@ namespace mbts.spark.menu_items public int priority => 4; public ImageSource icon => Icons.Clock; public string sectional_id => MenuItemSections.SecurityWindow; - public void execute(IReadOnlyCollection ordered_selection) { _bus.post(SparkTags.ShowTimeAndSalesTag, new SparkBusData.ShowTimeAndSalesMessage(ordered_selection.ToList())); } + public void execute(IReadOnlyCollection ordered_selection) { _bus.post(SparkTags.ShowTimeAndSalesTag, (ordered_selection.ToList())); } public bool can_execute(IReadOnlyCollection ordered_selection) { return ordered_selection.Any(); } public void raise_display_name_changed() { display_name_changed?.Invoke(); } public void raise_can_execute_changed() { can_execute_changed?.Invoke(); } diff --git a/src/client/spark/mspark/Shell/OrderBook/OrderBookView.xaml b/src/client/spark/mspark/Shell/OrderBook/OrderBookView.xaml index 47e8d43fb..fbdee466e 100644 --- a/src/client/spark/mspark/Shell/OrderBook/OrderBookView.xaml +++ b/src/client/spark/mspark/Shell/OrderBook/OrderBookView.xaml @@ -129,9 +129,6 @@ ItemsSource="{Binding orders}" RowHeight="{Binding row_height}" SelectionMode="Extended" SelectionUnit="FullRow" SelectionChanged="_grid_SelectionChanged"> - - - @@ -185,10 +182,8 @@ - - - - + diff --git a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs index bb32bcfa8..32009279d 100644 --- a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs @@ -112,7 +112,7 @@ namespace mbts.spark public class StartupData { public const int Version = 1; public StartupData() { } - public StartupData(IReadOnlyCollection securities, SortingCriteria[] sorting_criteria) { + public StartupData(IEnumerable securities, SortingCriteria[] sorting_criteria) { if (securities != null) this.securities = securities.Select(s => ((IImmutableMessage)s).ToByteArray()).ToArray(); this.sorting_criteria = sorting_criteria; } diff --git a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesView.xaml b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesView.xaml index dde08709b..0a1bf38ba 100644 --- a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesView.xaml +++ b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesView.xaml @@ -7,9 +7,6 @@ TextElement.FontSize="11"> - - -