From cb4bf8f5f4ae00def65d4e756ebfbeb31d79126e Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 28 Mar 2022 12:49:37 -0400 Subject: [PATCH] Remove unused class TimeAndSalesModel --- .../Market/TimeAndSales/TimeAndSalesModel.cs | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs deleted file mode 100644 index 4adec8e4f..000000000 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs +++ /dev/null @@ -1,99 +0,0 @@ -using bts.api; -using bts.co2; - -using mbts; -using mbts.co2; -using mbts.spark; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reactive.Linq; - -namespace bts.shell.time_and_sales { - class TimeAndSalesModel : IDisposable { - static readonly TimeSpan _poll_interval = TimeSpan.FromSeconds(0.4); - Lazy>> _trades; - IDisposable _dispose; - - public TimeAndSalesModel(IBus bus, MDConsumer consumer, IObservable security_criteria) { - var curr_channels = new Dictionary(); - _trades = new Lazy>>(() => Observable.Interval(_poll_interval).Select(_ => { - var copy = curr_channels; - return copy.Values.SelectMany(c => c.read_trades()).ToList(); - })); - _dispose = security_criteria.SelectManyInSeries(sc => sc.subscribe_md_map(bus)).Subscribe( - md_map => { - var copy = new Dictionary(curr_channels); - copy.sync_with_demux(md_map, get_channel_key, get_channel_consumer, update_channel_consumer); - curr_channels = copy; - }); - - ChannelKey get_channel_key(KeyValuePair md_kv) => - new ChannelKey(md_kv.Value.security.Symbol, md_kv.Value.security.security_type(), md_kv.Value.security.Exchange); - - ChannelConsumer get_channel_consumer(IGrouping> channel_sec_group) { - var key = channel_sec_group.Key; - var rv = new ChannelConsumer(consumer.get_channel(key.symbol, key.type, key.exchange)); - rv.set_securities(channel_sec_group); - return rv; - } - - void update_channel_consumer(KeyValuePair channel_kv, IEnumerable> security_kvs) => - channel_kv.Value.set_securities(security_kvs); - } - - public IObservable> trades => _trades.Value; - - public void Dispose() => Disposable.dispose(ref _dispose); - - private class ChannelKey : IEquatable { - public readonly string symbol; - public readonly SecurityType type; - public readonly Venue exchange; - - public ChannelKey(string symbol, SecurityType type, Venue exchange) { - this.symbol = symbol; - this.type = type; - this.exchange = exchange; - } - - public bool Equals(ChannelKey other) => - other != null && - other.symbol == symbol && - other.type == type && - other.exchange == exchange; - - public override bool Equals(object obj) => - Equals(obj as ChannelKey); - - public override int GetHashCode() => - symbol.GetHashCode() ^ - type.GetHashCode() ^ - exchange.GetHashCode(); - } - - private class ChannelConsumer { - readonly MDConsumerChannel _channel; - Dictionary _securities = new Dictionary(); - long _cursor = 0; - - public ChannelConsumer(MDConsumerChannel channel) => - _channel = channel; - - public void set_securities(IEnumerable> securities) => - _securities = securities.ToDictionary(kv => kv.Key, kv => kv.Value.security); - - public IEnumerable read_trades() { - var copy = _securities; - foreach (var tm in _channel.read_trades(ref _cursor)) { - if (tm != null) { - if (copy.TryGetValue(tm.Key, out SecurityImmutable sec)) { - yield return new TradeInfo(sec, new TradeMessageImmutable(tm)); - } - } - } - } - } - } -}