Remove unused class TimeAndSalesModel
This commit is contained in:
1 parent
96cd807720
commit
cb4bf8f5f4
1 file changed
-99
@@ -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<IObservable<IReadOnlyList<TradeInfo>>> _trades;
|
||||
IDisposable _dispose;
|
||||
|
||||
public TimeAndSalesModel(IBus bus, MDConsumer consumer, IObservable<SecurityCriteria> security_criteria) {
|
||||
var curr_channels = new Dictionary<ChannelKey, ChannelConsumer>();
|
||||
_trades = new Lazy<IObservable<IReadOnlyList<TradeInfo>>>(() => 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<ChannelKey, ChannelConsumer>(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<uint, SecurityMD> 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<ChannelKey, KeyValuePair<uint, SecurityMD>> 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<ChannelKey, ChannelConsumer> channel_kv, IEnumerable<KeyValuePair<uint, SecurityMD>> security_kvs) =>
|
||||
channel_kv.Value.set_securities(security_kvs);
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyList<TradeInfo>> trades => _trades.Value;
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
|
||||
private class ChannelKey : IEquatable<ChannelKey> {
|
||||
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<uint, SecurityImmutable> _securities = new Dictionary<uint, SecurityImmutable>();
|
||||
long _cursor = 0;
|
||||
|
||||
public ChannelConsumer(MDConsumerChannel channel) =>
|
||||
_channel = channel;
|
||||
|
||||
public void set_securities(IEnumerable<KeyValuePair<uint, SecurityMD>> securities) =>
|
||||
_securities = securities.ToDictionary(kv => kv.Key, kv => kv.Value.security);
|
||||
|
||||
public IEnumerable<TradeInfo> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user