From 82cdc9fc325c261942441bb2cf75c99ec3379de0 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 27 Feb 2018 15:08:19 -0500 Subject: [PATCH] Spark-340 Return of MDConsumerHandle --- .../spark/view/Spark/Core/SecurityMD.cs | 4 +-- .../spark/view/Spark/Ladder/LadderModel.cs | 2 +- .../spark/view/Spark/Ladder/LadderVM.cs | 2 +- .../view/Spark/Ladder/RecenterCountdown.cs | 2 +- .../view/Spark/Utilities/ISecurityMDPump.cs | 18 +++++----- .../Spark/Utilities/MDHandleExtensions.cs | 2 +- src/client/spark_core/Co2/IMDHandle.cs | 36 ------------------- src/client/spark_core/Co2/MDConsumerHandle.cs | 2 +- 8 files changed, 16 insertions(+), 52 deletions(-) delete mode 100644 src/client/spark_core/Co2/IMDHandle.cs diff --git a/src/client/spark/view/Spark/Core/SecurityMD.cs b/src/client/spark/view/Spark/Core/SecurityMD.cs index 00263a7e5..d059f7d07 100644 --- a/src/client/spark/view/Spark/Core/SecurityMD.cs +++ b/src/client/spark/view/Spark/Core/SecurityMD.cs @@ -9,9 +9,9 @@ using System.Threading.Tasks; namespace mbts.spark { struct SecurityMD : IEquatable { public SecurityImmutable security { get; } - public IMDHandle md { get; } + public MDConsumerHandle md { get; } - public SecurityMD(SecurityImmutable security, IMDHandle md) { + public SecurityMD(SecurityImmutable security, MDConsumerHandle md) { this.security = security; this.md = md; } diff --git a/src/client/spark/view/Spark/Ladder/LadderModel.cs b/src/client/spark/view/Spark/Ladder/LadderModel.cs index 2dbccaa6b..3977b83d8 100644 --- a/src/client/spark/view/Spark/Ladder/LadderModel.cs +++ b/src/client/spark/view/Spark/Ladder/LadderModel.cs @@ -16,7 +16,7 @@ namespace mbts.spark { public enum CancelType { All, Bids, Asks } public SecurityImmutable security { get; } - public IMDHandle md { get; } + public MDConsumerHandle md { get; } public OrdersModel order_gateway => _order_gateway; public async Task<(OrderRecordImmutable def, bool success, string error)[]> cancel_orders(CancelType ct) { diff --git a/src/client/spark/view/Spark/Ladder/LadderVM.cs b/src/client/spark/view/Spark/Ladder/LadderVM.cs index ee321c5b4..4101b70fd 100644 --- a/src/client/spark/view/Spark/Ladder/LadderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderVM.cs @@ -122,7 +122,7 @@ namespace mbts.spark { public event Action on_tick; public SecurityImmutable security => _model.security; - public IMDHandle md => _model.md; + public MDConsumerHandle md => _model.md; public bool is_synthetic => _model.security.ContractCase == Security.ContractOneofCase.Synthetic; public CalculatorLogic calculator { get; } public LogViewerMessageCollection log_messages { get; } = new LogViewerMessageCollection(); diff --git a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs index cefded3b7..54903e305 100644 --- a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs +++ b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs @@ -16,7 +16,7 @@ namespace mbts.spark { Interval = TimeSpan.FromSeconds(1) }; SecurityImmutable? _security; - IMDHandle _handle; + MDConsumerHandle _handle; LadderSettings _settings; DateTime _last_recenter = DateTime.MaxValue; double _last_mid = 0.0; diff --git a/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs b/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs index 70a0e7d65..f6b9c9994 100644 --- a/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs +++ b/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs @@ -39,12 +39,12 @@ namespace mbts.spark.utilities public SecurityMDPump(IObservable security, IBus bus) : this(security, SparkUtils.DefaultPollInterval, bus) { } public SecurityMDPump(IObservable security, TimeSpan poll_interval, IBus bus) : this(security, Observable.Interval(poll_interval), bus) { } public SecurityMDPump(IObservable security, IObservable poll, IBus bus) : this(security.CombineLatest(bus.subscribe(SparkTags.SecuritiesTag), (s, m) => m.GetValueOrDefault(s).md).Where(md => md != null), poll) { } - public SecurityMDPump(IMDHandle md) : this(Observable.Return(md)) { } - public SecurityMDPump(IMDHandle md, TimeSpan poll_interval) : this(Observable.Return(md), poll_interval) { } - public SecurityMDPump(IMDHandle md, IObservable poll) : this(Observable.Return(md), poll) { } - public SecurityMDPump(IObservable md_source) : this(md_source, SparkUtils.DefaultPollInterval) { } - public SecurityMDPump(IObservable md_source, TimeSpan poll_interval) : this(md_source, Observable.Interval(poll_interval)) { } - public SecurityMDPump(IObservable md_source, IObservable poll) { + public SecurityMDPump(MDConsumerHandle md) : this(Observable.Return(md)) { } + public SecurityMDPump(MDConsumerHandle md, TimeSpan poll_interval) : this(Observable.Return(md), poll_interval) { } + public SecurityMDPump(MDConsumerHandle md, IObservable poll) : this(Observable.Return(md), poll) { } + public SecurityMDPump(IObservable md_source) : this(md_source, SparkUtils.DefaultPollInterval) { } + public SecurityMDPump(IObservable md_source, TimeSpan poll_interval) : this(md_source, Observable.Interval(poll_interval)) { } + public SecurityMDPump(IObservable md_source, IObservable poll) { _root_pump = poll.CombineLatest(md_source, (_, md) => md); _bbo_pump = _root_pump.Select(_refresh_bbo).Where(r => r).Publish(); _last_pump = _root_pump.Select(_refresh_last).Where(r => r).Publish(); @@ -52,7 +52,7 @@ namespace mbts.spark.utilities _connections.Add(_last_pump.Connect()); } - private readonly IObservable _root_pump; + private readonly IObservable _root_pump; private readonly IConnectableObservable _bbo_pump; private readonly IConnectableObservable _last_pump; private readonly IList _connections= new List(); @@ -63,7 +63,7 @@ namespace mbts.spark.utilities private ulong _volume; private DateTime _last_time; - private bool _refresh_bbo(IMDHandle md) { + private bool _refresh_bbo(MDConsumerHandle md) { if (md.get_bbo(ref _bbo_ref, out NativePriceSize b, out NativePriceSize a)) { _bid_price = b.price; _bid_size = b.size; @@ -74,7 +74,7 @@ namespace mbts.spark.utilities return false; } - private bool _refresh_last(IMDHandle md) { + private bool _refresh_last(MDConsumerHandle md) { if (md.get_last_trade(ref _last_ref, out NativePriceSize ps, out DateTime ts, out ulong v)) { _last_price = ps.price; _last_size = ps.size; diff --git a/src/client/spark/view/Spark/Utilities/MDHandleExtensions.cs b/src/client/spark/view/Spark/Utilities/MDHandleExtensions.cs index 418bebc0f..7b4c3a68d 100644 --- a/src/client/spark/view/Spark/Utilities/MDHandleExtensions.cs +++ b/src/client/spark/view/Spark/Utilities/MDHandleExtensions.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace mbts.co2 { static class MDHandleExtensions { - public static double mid(this IMDHandle handle) { + public static double mid(this MDConsumerHandle handle) { ulong unused = 0; handle.get_bbo(ref unused, out NativePriceSize bid, out NativePriceSize ask); if (bid == NativePriceSize.no_market) return ask.price; diff --git a/src/client/spark_core/Co2/IMDHandle.cs b/src/client/spark_core/Co2/IMDHandle.cs deleted file mode 100644 index 771ecfcd0..000000000 --- a/src/client/spark_core/Co2/IMDHandle.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using bts.co2; - -namespace mbts.co2 { - interface IMDHandle { - DateTime close_date { get; } - double close_price { get; } - bool has_depth { get; } - bool is_heart_beating { get; } - uint key { get; } - ulong market_timestamp { get; } - ulong misc_timestamp { get; } - ulong numeric_id { get; } - DateTime open_date { get; } - double open_interest { get; } - double open_price { get; } - DateTime previous_settlement_date { get; } - double previous_settlement_price { get; } - double session_high { get; } - double session_high_bid { get; } - double session_low { get; } - double session_low_offer { get; } - DateTime settlement_date { get; } - double settlement_price { get; } - //CoconutSecurityStatus.type status { get; } - ulong total_volume { get; } - ulong trade_timestamp { get; } - - bool get_bbo(ref ulong time, out NativePriceSize bid, out NativePriceSize ask); - bool get_depth(ref ulong time, ref NativePriceSize[] bids, ref NativePriceSize[] asks); - void get_depth(ref NativePriceSize[] bids, ref NativePriceSize[] asks); - bool get_last_trade(ref ulong time, out NativePriceSize ps, out DateTime timestamp, out ulong total_volume); - MiscMessage get_misc(); - } -} \ No newline at end of file diff --git a/src/client/spark_core/Co2/MDConsumerHandle.cs b/src/client/spark_core/Co2/MDConsumerHandle.cs index e4b03b4d9..689eb0005 100644 --- a/src/client/spark_core/Co2/MDConsumerHandle.cs +++ b/src/client/spark_core/Co2/MDConsumerHandle.cs @@ -12,7 +12,7 @@ using bts.api; namespace mbts.co2 { - unsafe class MDConsumerHandle : IMDHandle { + unsafe class MDConsumerHandle { // Once is_initialized goes true it never goes false public bool is_heart_beating { get { return Co2NativeMethods.md_consumer_is_heart_beating(_header); } }