diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 323f05d0f..668dbca15 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -14,6 +14,8 @@ insert_anchor_links = "right" - Fixed a bug that cause cause a failure on startup if the user loaded a workspace with a Ladder that had a dynamic order type selected by default + - Increased width of login panel to better show login error messages + - Added optional 'Maker/Taker' pricing to Spreader algo ### Internal changes - Made it easier to generate simple UI's for new order types ### API Changes @@ -362,7 +364,8 @@ insert_anchor_links = "right" - The zoom slider can be enabled from Ladder Form -> Settings button -> Left Pane tab -> check Zoom Slider checkbox - The zoom functionality can also be performed via hotkey and mouse wheel combinations - Zoom In = CTRL + Mouse wheel up - - Zoom Out = CTRL + Mouse wheel down + - Zoom Out = CTRL + Mouse wheel down + - Reset zoom = CTRL + Mouse wheel click or double click on the zoom slider ### Exchange simulator - Improved the exchange simulator to track real market data more closely diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs index 5f4d64a32..c49712bae 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamRowsHelper.cs @@ -10,7 +10,7 @@ using System.Reactive.Disposables; namespace mbts.spark { static class AlgoParamRowsHelper { public static IDisposable connect(AlgoDefinitionVM algo, ObservableAggregateCollection rows, bool include_algo_type_rows) => - algo == null ? null : new CompositeDisposable(algo.observe_algo_root().SubscribeEach(a => { + algo == null ? null : new CompositeDisposable(algo.observe_algo_root().OnDispatcher().SubscribeEach(a => { rows.clear_collections(); if (a == null) return Disposable.empty; @@ -77,7 +77,7 @@ namespace mbts.spark { include_algo_type_rows ? (ObservableCollection)new ObservableAppendCollection(child_rows, selector_wrapper) : child_rows, - s.subscribe_selected_algo().SubscribeEach(a => { + s.subscribe_selected_algo().OnDispatcher().SubscribeEach(a => { s.value = a; child_rows.clear_collections(); return _wrap_rows(a, selector_wrapper, child_rows, include_algo_type_rows); diff --git a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs index 6f2a442c4..a26f626ae 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs @@ -194,20 +194,27 @@ namespace mbts.spark { readonly bts.persist.algo.AlgoPersistedKey[] _favorite_algos; [ProtoMember(2)] public readonly int column_count; + [ProtoMember(3)] + readonly bts.persist.algo.AlgoPersistedKey[] _stickied_algos; - public LadderFavoriteAlgosSettings(AlgoKey[] favorite_algos, int column_count) - : this(ArrayHelper.safe_convert(favorite_algos, k => new bts.persist.algo.AlgoPersistedKey(k.persisted)), column_count) { } + public LadderFavoriteAlgosSettings(AlgoKey[] favorite_algos, int column_count, AlgoKey[] stickied_algos) + : this(ArrayHelper.safe_convert(favorite_algos, k => new bts.persist.algo.AlgoPersistedKey(k.persisted)), + column_count, + ArrayHelper.safe_convert(stickied_algos, k => new bts.persist.algo.AlgoPersistedKey(k.persisted))) { } - LadderFavoriteAlgosSettings(bts.persist.algo.AlgoPersistedKey[] favorite_algos, int column_count) { + LadderFavoriteAlgosSettings(bts.persist.algo.AlgoPersistedKey[] favorite_algos, int column_count, bts.persist.algo.AlgoPersistedKey[] stickied_algos) { _favorite_algos = favorite_algos; this.column_count = column_count; + _stickied_algos = stickied_algos; } public IReadOnlyList favorite_algos => ArrayHelper.safe_convert(_favorite_algos, k => k.to_algo_key()); + public IReadOnlyList stickied_algos => ArrayHelper.safe_convert(_stickied_algos, k => k.to_algo_key()); public bool Equals(LadderFavoriteAlgosSettings other) => column_count == other.column_count && - favorite_algos.SequenceEqual(other.favorite_algos); + favorite_algos.SequenceEqual(other.favorite_algos) && + stickied_algos.SequenceEqual(other.stickied_algos); public override bool Equals(object obj) => EqualityComparer.equals_obj(this, obj); @@ -215,7 +222,8 @@ namespace mbts.spark { public override int GetHashCode() => EqualityComparer.aggregate_hash( column_count, - EqualityComparer.aggregate_hash_limited(favorite_algos)); + EqualityComparer.aggregate_hash_limited(favorite_algos), + EqualityComparer.aggregate_hash_limited(stickied_algos)); public static bool operator ==(LadderFavoriteAlgosSettings a, LadderFavoriteAlgosSettings b) => a.Equals(b); public static bool operator !=(LadderFavoriteAlgosSettings a, LadderFavoriteAlgosSettings b) => !a.Equals(b); @@ -273,7 +281,7 @@ namespace mbts.spark { order_entry_panel_initial_width = _default_order_entry_panel_width; zoom_factor = _default_zoom_factor; use_defaults = true; - favorite_algos = new LadderFavoriteAlgosSettings(null, 2); + favorite_algos = new LadderFavoriteAlgosSettings(null, 2, null); show_warn_on_cross = _default_show_warn_on_cross; } diff --git a/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs index 3ab614a21..0b5030b0b 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs @@ -11,6 +11,7 @@ using ProtoBuf; using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.IO; using System.Linq; using System.Reactive.Linq; using System.Reactive.Subjects; @@ -22,6 +23,7 @@ using LadderSettings = mbts.spark.LadderSettings; namespace bts.shell { class LadderWindowFactory : ShellWindowFactory { const string _window_type = "ladder"; + const int _version_where_stickied_algos_introduced = 2; readonly LadderConfig _ladder_conf; readonly IBus _bus; readonly IWindowManager _wm; @@ -38,7 +40,7 @@ namespace bts.shell { OrdersModel orders_model, MBOService mbo) - : base(owner, "SparkLadder") { + : base(owner, "SparkLadder", 2) { _bus = bus; _wm = wm; _settings_hub = settings_hub; @@ -60,6 +62,16 @@ namespace bts.shell { return null; } + protected override Task try_upgrade_state(Stream load_stream, int version) { + var state = ProtoBuf.Serializer.DeserializeWithLengthPrefix(load_stream, ProtoBuf.PrefixStyle.Fixed32); + if (version < _version_where_stickied_algos_introduced) { + // We want to assign any existing favorite algos to stickied algos upon setting upgrade + var favorite_algos_array = state.settings.favorite_algos.favorite_algos.ToArray(); + state.settings.favorite_algos = new LadderFavoriteAlgosSettings(favorite_algos_array, state.settings.favorite_algos.column_count, favorite_algos_array); + } + return load(state); + } + LadderSaveState _get_state(LadderVM vm, uint id) { LadderSettings s = vm.get_save_state(); if (id != 0) { diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs index d7847884f..97db476d3 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs @@ -2,6 +2,7 @@ using bts.api; using bts.api.orderman; using bts.collections; +using bts.persist.algo; using bts.shell.orderbook; using bts.utils; using mbts.collections; @@ -723,12 +724,15 @@ namespace mbts.spark { readonly IObservableCollection _algo_definitions; readonly ObservableCollection _raw_items = new ObservableCollection(); int _column_count = 2; + HashSet _sticky_algo_keys; + IDisposable _sticky_algos_hook; public FavoriteAlgosVM(IObservableCollection algo_definitions) { _algo_definitions = algo_definitions; items = new ObservableAggregateCollection(_raw_items, new ObservableCollection { FavoriteAlgoItem.AddButtonPlaceholderItem }); add_item_cmd = new DelegateCommand(() => _raw_items.Add(_item_factory())); remove_item_cmd = new DelegateCommand(fai => _raw_items.Remove(fai)); + _dispose = Disposable.Create(() => Disposable.dispose(ref _sticky_algos_hook)); } public ObservableCollection items { get; } @@ -745,6 +749,17 @@ namespace mbts.spark { fai.selector.try_select(k); return fai; })); + _sticky_algo_keys = new HashSet(value.stickied_algos.Where(k => k.is_persisted).Select(x => new AlgoPersistedKey(x.persisted))); + Disposable.replace(ref _sticky_algos_hook, + ObservableAutoWrapper.connect_item_hooks(_raw_items, x => + x.selector.subscribe_value().Subscribe(algo => { + if (algo != null && + algo.key.is_persisted && + (x.is_sticky = _sticky_algo_keys.Remove(new AlgoPersistedKey(algo.key.persisted))) && + _sticky_algo_keys.Count == 0) + // + Disposable.dispose(ref _sticky_algos_hook); + }))); } public LadderFavoriteAlgosSettings create() => @@ -753,7 +768,13 @@ namespace mbts.spark { .Where(k => k.HasValue && k.Value.is_persisted) .Select(k => k.Value) .ToArray(), - column_count); + column_count, + _raw_items + .Where(fai => fai.is_sticky) + .Select(fai => fai.algo_definition?.key ?? fai.selector.desired_key) + .Where(k => k.HasValue && k.Value.is_persisted) + .Select(k => k.Value) + .ToArray()); FavoriteAlgoItem _item_factory() => new FavoriteAlgoItem(_algo_definitions, new ListCollectionView(_algo_definitions) { @@ -766,6 +787,7 @@ namespace mbts.spark { public static readonly FavoriteAlgoItem AddButtonPlaceholderItem = new _AddButtonPlaceholderItem(); internal readonly KeyedItemSelector selector; + bool _is_sticky; protected FavoriteAlgoItem() { } @@ -776,6 +798,7 @@ namespace mbts.spark { public ICollectionView algo_definitions_view { get; } public AlgoDefinitionVM algo_definition { get => selector.value; set => selector.value = value; } + public bool is_sticky { get => _is_sticky; set => Set(ref _is_sticky, value); } class _AddButtonPlaceholderItem : FavoriteAlgoItem, ITemplateSelectorKey { public string key => LadderSettingsView.FavoriteAlgoAddButtonTemplateKey; diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index 506835d9c..c985e6381 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -1,9 +1,11 @@ using bts.api; using bts.api.orderman; +using bts.collections; using bts.shell; using bts.spark; using bts.utils; using mbts.co2; +using mbts.spark.utilities; using mbts.ui; using mbts.ui.shell; using mbts.utils; @@ -32,6 +34,7 @@ namespace mbts.spark { _show_tif, _show_order_type, _show_size_preset, _show_auto_clear, _show_clear, _show_cancel_buys, _show_cancel_sells, _show_cancel_all, _show_zoom; readonly PropertyAutoWrapper _bid_background, _bid_foreground, _ask_background, _ask_foreground; + readonly HashSet _sticky_algos = new HashSet(); double _position, _day_position; bool _show_account_position, _show_day_position; ulong _misc_time = 0; @@ -133,7 +136,7 @@ namespace mbts.spark { //_window_height = backing(nameof(window_height), settings_manager.subscribe_current().OnDispatcher().Select(s => s.zoom_factor), (scale) => scale * 600); //_window_width = backing(nameof(window_width), settings_manager.subscribe_current().OnDispatcher().Select(s => s.zoom_factor), (scale) => scale * 420); position_click_command = new DelegateCommand(() => size_calculator.value = DoubleHelper.safe_convert_to_uint(Math.Abs(_show_day_position ? day_position : position))); - send_order_command = new DelegateCommand<(double price, Side? side, MouseButton button)>(send_order); + send_order_command = new AsyncCommand<(double price, Side? side, MouseButton button)>(send_order_async); cancel_command = new AsyncCommand(_model.cancel_orders, true); show_book_command = new DelegateCommand(_show_book); show_ticket_command = new DelegateCommand(_show_ticket); @@ -223,7 +226,10 @@ namespace mbts.spark { .SelectManyInSeries(a => _model.order_gateway.on_security_positions(security.Id) .Select(table => table.state.Values.FirstOrDefault(pos => pos.Item2.Account == a, tup => tup.Item2, (bts.api.position.PositionUnitImmutable?)null))); return Disposable.Create( - settings.OnDispatcher().Subscribe(s => order_properties_vm.on_favorite_algos(s.favorite_algos)), + settings.OnDispatcher().Subscribe(s => { + _sticky_algos.SetItems(s.favorite_algos.stickied_algos); + order_properties_vm.on_favorite_algos(s.favorite_algos); + }), order_properties_vm, position_src.OnDispatcher().Subscribe(pos => { double total, day; @@ -400,20 +406,19 @@ namespace mbts.spark { settings_invalidated?.Invoke(); } - public void send_order((double price, Side? side, MouseButton button) args) { - if (order_properties_vm == null || args.button == MouseButton.Middle) - return; - var size_from_alternate = args.button == MouseButton.Right; - if (DoubleHelper.IsNaNOrInfinity(args.price) || !args.side.HasValue || HasErrors || order_properties_vm.HasErrors || (size_from_alternate && current_settings.alternate_order_size == 0)) { - return; - } - if (!size_from_alternate && (!size_calculator.value.HasValue || size_calculator.value.Value == 0)) { - size_calculator.flash_error(); - } - else { - uint size = size_from_alternate ? current_settings.alternate_order_size : (uint)Math.Abs(size_calculator.value ?? 0); - send_order_async(args.side.Value, size, args.price).ignore(); + public Task send_order_async((double price, Side? side, MouseButton button) args) { + if (order_properties_vm != null && args.button != MouseButton.Middle) { + var size_from_alternate = args.button == MouseButton.Right; + if (!DoubleHelper.IsNaNOrInfinity(args.price) && args.side.HasValue && !HasErrors && !order_properties_vm.HasErrors && (!size_from_alternate || current_settings.alternate_order_size > 0)) { + if (!size_from_alternate && (!size_calculator.value.HasValue || size_calculator.value.Value == 0)) { + size_calculator.flash_error(); + } else { + uint size = size_from_alternate ? current_settings.alternate_order_size : (uint)Math.Abs(size_calculator.value ?? 0); + return send_order_async(args.side.Value, size, args.price); + } + } } + return Task.CompletedTask; } public async Task send_order_async(Side side, uint size, double price) { @@ -433,6 +438,13 @@ namespace mbts.spark { await _model.order_gateway.send_order(order, price, size); if (auto_clear) size_calculator.value = 0; + var fav_algo = order_properties_vm.selected_favorite_algo_definition; + if (fav_algo != null && !_sticky_algos.Contains(fav_algo.key) && !order_properties_vm.try_pop_selected_algo_definition()) { + var key = new AlgoKey(OrderDataHelper.get_default_algo(OrderDataHelper.get_algo_format(security.ContractCase))); + if (order_properties_vm.try_get_algo_definition(key, out var r)) { + order_properties_vm.selected_algo_definition = r; + } + } } void _update_header() { diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml index 67ed2b074..92ab62e4d 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml @@ -805,6 +805,7 @@ + diff --git a/src/client/spark/Orders/OrderPropertiesEditorVM.cs b/src/client/spark/Orders/OrderPropertiesEditorVM.cs index 31ff1fc1b..e5a90d0e1 100644 --- a/src/client/spark/Orders/OrderPropertiesEditorVM.cs +++ b/src/client/spark/Orders/OrderPropertiesEditorVM.cs @@ -60,6 +60,7 @@ namespace mbts.spark { readonly ListCollectionView _algo_definitions_view, _favorite_algo_definitions_view; readonly TableUpdateBuffer _definitions_buffer = new TableUpdateBuffer(d => d.key); readonly ObservableAggregateCollection _algo_param_rows = new ObservableAggregateCollection(); + readonly AlgoDefinitionVM the_anchor_algo_def_vm; IReadOnlyDictionary _algo_metadata = DictionaryHelper.empty(); IReadOnlyDictionary _favorite_algos_index = DictionaryHelper.empty(); IDisposable _algo_param_rows_hook; @@ -68,6 +69,7 @@ namespace mbts.spark { public OrderPropertiesEditorVM(OrdersModel model, IObservable security_md_source, IObservable order_properties) { _model = model; + the_anchor_algo_def_vm = AlgoDefinitionVM.create(_model, OrderDataHelper.Defaults.AlgoData(CustomOrderDefinition.CustomOneofCase.Limit)); var security_source = security_md_source.Select(smd => smd.security); _security = backing(nameof(security), security_source, SecurityDataHelper.Defaults.SecurityImmutable); security_source = _security.observe_current(true); @@ -237,11 +239,15 @@ namespace mbts.spark { void _selected_algo_definition_Changed(AlgoDefinitionVM old_value, AlgoDefinitionVM new_value, SelectionReason reason) { Disposable.dispose(ref _algo_param_rows_hook); + if (old_value != null) + // Taha feels that we should always revert to a Limit order either when the user explicity unchecks a sticky button + // or when a non-sticky button is pressed. Rather than completely remove the stack at this time (b/c it may be come + // back in the future), let's just always push a specfic def_vm.key onto it [Limit] ;) + //_selected_algo_stack.Push(old_value.key); + _selected_algo_stack.Push(the_anchor_algo_def_vm.key); if (new_value != null) { if (use_algo_param_grid) _algo_param_rows_hook = _connect_algo_param_rows(new_value, _algo_param_rows); - if (reason != SelectionReason.Explicit) - _selected_algo_stack.Push(new_value.key); } if (open_algo_popup_on_select) { if (reason == SelectionReason.UserSelectedNewValue && new_value?.algo_root is IAlgoVM ar && ar.can_expand) @@ -277,6 +283,18 @@ namespace mbts.spark { get => _selected_algo_definition.selected_item; set => _selected_algo_definition.selected_item = value; } + + public bool try_get_algo_definition(AlgoKey a, out AlgoDefinitionVM result) => + _algo_definitions.TryGetValue(a, out result); + + public bool try_pop_selected_algo_definition() { + if (_selected_algo_stack.TryPop(out AlgoKey k) && _algo_definitions.TryGetValue(k, out AlgoDefinitionVM vm)) { + _selected_algo_definition.select_explicit(vm); + return true; + } + return false; + } + public AlgoDefinitionVM selected_favorite_algo_definition { get => selected_algo_definition?.is_favorite ?? false ? selected_algo_definition : null; set { @@ -353,6 +371,7 @@ namespace mbts.spark { d.favorite_index = _get_favorite_algo_index(d.key); } favorite_algos_column_count = value.column_count; + RaisePropertyChanged(nameof(selected_favorite_algo_definition)); } static IDisposable _connect_algo_param_rows(AlgoDefinitionVM def, ObservableAggregateCollection rows) => @@ -371,4 +390,4 @@ namespace mbts.spark { algo_definitions_view.Refresh(); } } -} +} \ No newline at end of file diff --git a/src/client/spark/core/ShellInterface/IShellWindowFactory.cs b/src/client/spark/core/ShellInterface/IShellWindowFactory.cs index c5ceff2c4..f29218124 100644 --- a/src/client/spark/core/ShellInterface/IShellWindowFactory.cs +++ b/src/client/spark/core/ShellInterface/IShellWindowFactory.cs @@ -34,13 +34,14 @@ namespace bts.shell { Disposable.dispose(ref _dispose); } public abstract Task load(T state); + protected virtual Task try_upgrade_state(Stream load_stream, int version) => null; public Task load_window(Stream load_stream, int version) { if (version == this.version) { var t = ProtoBuf.Serializer.DeserializeWithLengthPrefix(load_stream, ProtoBuf.PrefixStyle.Fixed32); return load(t); } - return null; + return try_upgrade_state(load_stream, version); } public void save(T data, Stream output) { var header = new ShellSerializationHeader() { diff --git a/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml b/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml index d07248c08..656513fc3 100644 --- a/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml +++ b/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml @@ -687,7 +687,10 @@ - Tick Offset + + Tick Offset + + - Max Show Quantity + + Max Show Quantity + + @@ -944,7 +950,10 @@ - Show Quantity + + Show Quantity + + - Expose Quantity + + Expose Quantity + + - Max Order Quantity + + + Max Order Quantity + + command.Execute(parameter)); + return Task.Run(() => command.Execute(parameter)); } public static void TryExecuteIfCan(this ICommand command, object parameter) { diff --git a/src/client/spark/view/Shell/Login/LoginView.xaml b/src/client/spark/view/Shell/Login/LoginView.xaml index 741efc3fb..9461e25ad 100644 --- a/src/client/spark/view/Shell/Login/LoginView.xaml +++ b/src/client/spark/view/Shell/Login/LoginView.xaml @@ -10,8 +10,8 @@ xmlns:autocomplete="clr-namespace:WPFTextBoxAutoComplete;assembly=WPFTextBoxAutoComplete" xmlns:sys="clr-namespace:System;assembly=mscorlib" x:Name="_login_view" - Width="460" - Height="254" + Width="520" + Height="230" WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" @@ -27,7 +27,7 @@ - 40 + 10 10 22 @@ -206,7 +206,7 @@ x:Name="_error_control" Grid.Column="1" VerticalAlignment="Center" - HorizontalAlignment="Center" + HorizontalAlignment="Left" Visibility="Hidden" Opacity="0" > @@ -251,10 +251,10 @@ - - diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs b/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs index 398d994a4..a85da8c0c 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs @@ -136,8 +136,8 @@ namespace mbts.spark { var skip_local = profiles.WrapSkip(1); var skip_local_wrapper = skip_local.WrapSelector( p => new SettingsProfile(p.id, p.name, p.value.create(), p.security_criteria), - ns => new ProfileVM(ns.id, vm_factory(ns.value), ns.name, ns.security_criteria)); - profiles.Add(_local_profile = new ProfileVM(0, vm_factory(init), "Custom", template_key: ShellSettingsDialog.LocalProfileItemTemplateKey)); + ns => new ProfileVM(ns.id, vm_factory(ns.value), ns.name, ns.security_criteria, target_value: ns.value)); + profiles.Add(_local_profile = new ProfileVM(0, vm_factory(init), "Custom", template_key: ShellSettingsDialog.LocalProfileItemTemplateKey, target_value: init)); _selected_profile = backing(nameof(selected_profile), _local_profile); // dialog skirt items _apply_item = new DialogSkirtItem("Apply", new DelegateCommand(apply)); @@ -325,26 +325,37 @@ namespace mbts.spark { // SecurityCriteria _security_criteria; SettingsProfile _committed, _last_result; + T _target_value; string _name, _template_key; bool _is_selected; IDisposable _dispose; - public ProfileVM(uint id, TVM value, string name, SecurityCriteria security_criteria = null, string template_key = null) { + public ProfileVM(uint id, TVM value, string name, SecurityCriteria security_criteria = null, string template_key = null, T target_value = null) { this.id = id; this.value = value; _name = name; _security_criteria = security_criteria; _template_key = template_key; + _target_value = target_value; _committed = _last_result = create(); _is_dirty = backing(nameof(is_dirty), () => !_last_result.Equals(_committed)); _refresh_is_dirty = new DeferrableActionWrapper(_is_dirty.refresh); var sub = value.Subscribe(v => { _last_result = _last_result.with(value: v); _refresh_is_dirty.execute(); + _on_value_changed(); }); _dispose = value is IDisposable d ? Disposable.Create(sub, d) : sub; } + void _on_value_changed() { + if (_target_value != null && is_dirty && _last_result.value.Equals(_target_value)) { + _target_value = null; + _committed = _last_result; + _refresh_is_dirty.execute(); + } + } + public uint id { get; } public TVM value { get; } public string name { @@ -380,21 +391,26 @@ namespace mbts.spark { /// assign directly to , to capture props that aren't visible in the dialog (i.e., props that are manipulated in the main window) _last_result = data; } + _on_value_changed(); } public void load_value_from(T value) { using (_refresh_is_dirty.defer_execution()) this.value.load_from(value); + _on_value_changed(); } public void commit(SettingsProfile data) { using (_refresh_is_dirty.defer_execution()) _load_from(_committed = data); + _on_value_changed(); } public void commit_current() { _committed = _last_result; + _target_value = _committed.value; _refresh_is_dirty.execute(); + _on_value_changed(); } public void revert() { @@ -402,6 +418,7 @@ namespace mbts.spark { _load_from(_committed); _last_result = _committed; } + _on_value_changed(); } public IObservable subscribe_is_dirty() => _is_dirty.observe_current(true); @@ -414,6 +431,7 @@ namespace mbts.spark { public override string ToString() => _name; void _load_from(SettingsProfile data) { + _target_value = data.value; name = data.name; security_criteria = data.security_criteria; value.load_from(data.value); diff --git a/src/client/spark_test/api/ApiTests.cs b/src/client/spark_test/api/ApiTests.cs index 69b63f8f0..22be985fd 100644 --- a/src/client/spark_test/api/ApiTests.cs +++ b/src/client/spark_test/api/ApiTests.cs @@ -20,7 +20,6 @@ namespace mbts.api.Test { ApiTestService[] test_services() { return new[] { _mtest, _ntest }; } public ApiTests() { - config.Configuration.initialize(); _context = ServiceContextTestHelpers.create_private_context(); _native_server = ApiTestsNativeMethods.apitest_start_apitest_service(_context.native_context); _managed_server = new ApiTestServiceServer(_context); @@ -34,7 +33,7 @@ namespace mbts.api.Test { Disposable.dispose(ref _context); } - [Test, Ignore("Times out")] + [Test] public void test_empty_reply_is_not_null() { foreach (var svc in test_services()) { Assert.IsNotNull( @@ -43,7 +42,6 @@ namespace mbts.api.Test { } [Test] - [Ignore("Fixme")] public void hello_server_test() { _mtest.run_hello_service(null); _mtest.run_shout_service(null); diff --git a/src/lib/api/core/ApiServerInterop.cpp b/src/lib/api/core/ApiServerInterop.cpp index 8b57c72dd..46a224b4e 100644 --- a/src/lib/api/core/ApiServerInterop.cpp +++ b/src/lib/api/core/ApiServerInterop.cpp @@ -59,18 +59,16 @@ CAPI TableHandle api_server_create_table(ApiServerCore* pserver, const char* met } CAPI void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count) { - if (change_count > 0) { - bts_assert(htable); - qbus::TablePublisher* ptable = reinterpret_cast(htable); - std::vector changes(change_count); - for (int x = 0; x < change_count; ++x) { - StreamUpdate& ch = raw_changes[x]; - std::string buffer(ch.buffer, ch.buffer_len); - qbus::RecordPtr record = std::make_shared(std::move(buffer)); - changes[x] = qbus::Change((qbus::Change::Type)ch.type, qbus::RecordKey(ch.key), record); - } - ptable->publish(std::move(changes)); + bts_assert(htable); + qbus::TablePublisher* ptable = reinterpret_cast(htable); + std::vector changes(change_count); + for (int x = 0; x < change_count; ++x) { + StreamUpdate& ch = raw_changes[x]; + std::string buffer(ch.buffer, ch.buffer_len); + qbus::RecordPtr record = std::make_shared(std::move(buffer)); + changes[x] = qbus::Change((qbus::Change::Type)ch.type, qbus::RecordKey(ch.key), record); } + ptable->publish(std::move(changes)); } CAPI void api_server_destroy_table(qbus::TablePublisher* ptable) { diff --git a/src/sdk/README.md b/src/sdk/README.md index 809037be5..13aacec16 100644 --- a/src/sdk/README.md +++ b/src/sdk/README.md @@ -150,11 +150,6 @@ In gdb: ``` (gdb) break order_plugin_example.cpp:366 ``` - -#### In Depth Algo Descriptions - - * [Spark Algo Descriptions](doc/algos.md) - * Send us an email for help: api_support@bluetradesys.com #### Spark windows client * Download spark windows executable here: diff --git a/src/sdk/doc/algos.md b/src/sdk/doc/algos.md deleted file mode 100644 index 7ec2f9517..000000000 --- a/src/sdk/doc/algos.md +++ /dev/null @@ -1,46 +0,0 @@ -+++ -title = "BTS Basic Algos" -weight = 3 -sort_by = "weight" -insert_anchor_links = "right" -+++ - - -## Lean - -The goal of the lean order is to watch the opposite-inside market size and cross when that size goes below the threshold (this also implies a cross if that size goes to zero and the market trades away from you) If the market trades toward you, you can opt into several different behaviors - -##### Parameters - * Cross Thresh - size thresh in absolute or ratio terms - * Max Chase Ticks - max levels to pay up, in ticks - - -## Join -The goal of the join order is to watch the opposite-inside market and join when the market flips (that is, when the best offer becomes the best bid) and has at least threshold size. - -##### Parameters - * Join Thresh - size thresh in absolute or ratio terms - - -## Top - -The goal of the top order is to not trade by yourself, but the intent at the time of order entry is to get filled.If the order is on the market (say current bid price) AND the quantity on that bid price is below top thresh then cancel the order else remain working. - -##### Parameters - * Top Thresh - size thresh in absolute or ratio terms - - -## Cover -A Cover order’s purpose is to fire a hedge order (of any type) in response to fills from it’s child order on the opposite side of the market N ticks away - -##### Parameters - * Profit Ticks - ticks above or below fill price to place profit / cover order - - -## OCO -An OCO order creates a relationship between a child order and a 'stop' or 'other' order such that when one of these is cancelled, both cancel, or when one is filled, the other order's size is debited in the amount of the fill. - -Composing this order with Cover simulates scalping functionality - -##### Parameters - * Stop Ticks - ticks below or above main order to place stop / other order \ No newline at end of file