From 8a7e2db4ac16ffecb90b57fb8d01865f2000de67 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 25 Jun 2019 19:01:57 -0500 Subject: [PATCH] SP-80 / SP-81 Synths should be private --- src/client/spark/Daemons/MDDaemon.cs | 5 ++- .../spark/Modules/Spreader/SpreaderModel.cs | 16 ++++++-- .../Modules/Spreader/VM/SyntheticEditorVM.cs | 2 +- src/client/spark_api/md/MDSource.cs | 38 +++++++++---------- src/lib/domain_model/Security.proto | 1 + 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/client/spark/Daemons/MDDaemon.cs b/src/client/spark/Daemons/MDDaemon.cs index 70361557b..058f8207d 100644 --- a/src/client/spark/Daemons/MDDaemon.cs +++ b/src/client/spark/Daemons/MDDaemon.cs @@ -15,6 +15,7 @@ using System.Collections.Concurrent; using System.Threading; using bts.api.user; using bts.md; +using mbts.ui.shell; namespace bts { [Export(typeof(IInitializable))] @@ -27,8 +28,8 @@ namespace bts { static uint get_naggle() => mbts.config.Configuration.get().naggle_ms; [ImportingConstructor] - public MDDaemon(Lazy bus, Lazy token, Lazy ss) : - base(get_naggle(), MDSourceOptions.DeferInit) { + public MDDaemon(Lazy bus, Lazy token, Lazy ss, [Import(LoginModel.Exports.UserID)]uint user_id) : + base(get_naggle(), MDSourceOptions.DeferInit, user_id) { _bus = bus; _token = token; _ss = ss; diff --git a/src/client/spark/Modules/Spreader/SpreaderModel.cs b/src/client/spark/Modules/Spreader/SpreaderModel.cs index 346f74e22..7e1d4535c 100644 --- a/src/client/spark/Modules/Spreader/SpreaderModel.cs +++ b/src/client/spark/Modules/Spreader/SpreaderModel.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.synthetic; using bts.spark; +using mbts.ui.shell; using System; using System.Collections.Generic; using System.ComponentModel.Composition; @@ -14,12 +15,14 @@ namespace mbts.spark { readonly IBus _bus; readonly SyntheticSecurityService _service; readonly ErrorReporter _error; + readonly uint _user_id; [ImportingConstructor] - public SpreaderModel(IBus bus, SyntheticSecurityService service, ErrorReporter error) { + public SpreaderModel(IBus bus, SyntheticSecurityService service, ErrorReporter error, [Import(LoginModel.Exports.UserID)]uint user_id) { _bus = bus; _service = service; _error = error; + _user_id = user_id; } public IObservable> strategy => _bus.subscribe(SparkTags.SyntheticstrategiesTag); @@ -53,8 +56,15 @@ namespace mbts.spark { return null; } - public async Task create_synthetic(SecurityImmutable? synthetic) { - var result = await _service.create_synthetic_async(synthetic.Value); + public async Task create_synthetic(SecurityImmutable synthetic) { + if (synthetic.ContractCase != Security.ContractOneofCase.Synthetic) + return null; + if (synthetic.Synthetic.UserId != _user_id) { + var msynth = synthetic.CloneToMutable(); + msynth.Synthetic.UserId = _user_id; + synthetic = new SecurityImmutable(msynth); + } + var result = await _service.create_synthetic_async(synthetic); return _error.handle_error(result, "Error creating synthetic: {0}", r => r.Error, e => e == CreateResult.Types.Error.Ok, r => new uint?(r.Key), () => null).result; } diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index 6e1ddca65..017eb24c0 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -134,7 +134,7 @@ namespace mbts.spark { _synthetic.ContractSpec.PriceBreak = double.MaxValue; _synthetic.ContractSpec.MainFraction = (uint)MathUtils.factor_out(_tick_factors.tick_base, 10); _synthetic.ContractSpec.PriceDisplayFormat = (uint)_tick_factors.display_digits(); - uint? id = await model.create_synthetic(_synthetic); + uint? id = await model.create_synthetic(new SecurityImmutable(_synthetic)); if (id.HasValue && id != 0) { if (await model.save_strategy(id.Value, get_strategy())) { var (smd, success) = await SparkUtils.get_security_md_async(bus, id.Value); diff --git a/src/client/spark_api/md/MDSource.cs b/src/client/spark_api/md/MDSource.cs index 392fc6844..7281aba04 100644 --- a/src/client/spark_api/md/MDSource.cs +++ b/src/client/spark_api/md/MDSource.cs @@ -1,36 +1,33 @@ using bts.api; -using bts.api.synthetic; using mbts; using mbts.co2; using System; -using System.Collections.Generic; -using System.Reactive.Linq; -using System.Threading.Tasks; -using System.Linq; -using SecurityKey = System.UInt32; using System.Collections.Concurrent; -using System.Threading; -using bts.api.user; +using System.Collections.Generic; using System.Reactive.Subjects; +using System.Threading.Tasks; +using SecurityKey = System.UInt32; -namespace bts.md -{ +namespace bts.md { [Flags] enum MDSourceOptions { DeferInit = 1, } class MDSource : IObserver>, IDisposable - { + { + const uint _no_user_id = 0; protected readonly MDConsumer _consumer = new MDConsumer(); protected readonly Co2RelayControl _relay; protected DateTime _version = DateTime.MinValue; protected readonly ConcurrentDictionary _exchange_sec_map = new ConcurrentDictionary(); protected List _dispose = new List(); protected readonly MDSourceOptions _options; + readonly uint _user_id; - public MDSource(uint naggle_ms, MDSourceOptions options = 0) + public MDSource(uint naggle_ms, MDSourceOptions options = 0, uint user_id = _no_user_id) { _options = options; + _user_id = user_id; _relay = new Co2RelayControl(_consumer, naggle_ms); _relay.preload_securities((co2.MDRequest.Types.Flags)0xff).ignore(); _dispose.Add(_consumer.on_security.Subscribe(this)); @@ -54,12 +51,15 @@ namespace bts.md public void OnCompleted() { } public void OnError(Exception error) => Log.Md.error(error.ToString()); - public void OnNext(List values) - { - if (values.Count > 0) - { - foreach (var v in values) - { + public void OnNext(List values) { + if (values.Count > 0) { + foreach (var v in values) { + if (_user_id != _no_user_id && + v.security.ContractCase == Security.ContractOneofCase.Synthetic && + v.security.Synthetic.UserId != _user_id && + v.security.Synthetic.UserId != _no_user_id) { + continue; + } var smd = new SecurityMD(new SecurityImmutable(v.security), v.handle); _exchange_sec_map.AddOrUpdate(smd.security.Id, smd, (_, __) => smd); } @@ -93,4 +93,4 @@ namespace bts.md } } -} \ No newline at end of file +} diff --git a/src/lib/domain_model/Security.proto b/src/lib/domain_model/Security.proto index 9e16fd9b4..52ca35299 100644 --- a/src/lib/domain_model/Security.proto +++ b/src/lib/domain_model/Security.proto @@ -143,6 +143,7 @@ message SpreadContract { message SyntheticContract { string name = 1; + uint32 user_id = 2; repeated ContractLeg legs = 20; PriceCalc price_calc = 30; enum PriceCalc {