refactor: Impl 'market_data' fn w/ SecurityCriteria filter
This commit is contained in:
1 parent
a31368f08d
commit
5339d4ff93
1 file changed
+6
-11
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
namespace bts.md {
|
||||
using bts.api.core;
|
||||
|
||||
@@ -23,13 +24,7 @@ namespace bts.md {
|
||||
_poll_interval = poll_interval;
|
||||
_num_depth_levels = num_depth_levels;
|
||||
}
|
||||
IObservable<List<Book>> security_market_data(SecurityCriteria cr, uint security_id) {
|
||||
return market_data()
|
||||
.Select(table => {
|
||||
var b = table.state.Values.Take(3).ToList();
|
||||
return b;
|
||||
});
|
||||
}
|
||||
|
||||
public IObservable<Book> security_market_data(uint security_id) =>
|
||||
market_data()
|
||||
.Select(table => {
|
||||
@@ -39,19 +34,19 @@ namespace bts.md {
|
||||
})
|
||||
.DistinctUntilChanged();
|
||||
|
||||
public IObservable<TableUpdate<Book, uint>> market_data() {
|
||||
public IObservable<TableUpdate<Book, uint>> market_data(SecurityCriteria? criteria = null) {
|
||||
// This MDSource's IObservable provides callbacks when a security is added or removed, but
|
||||
// doesn't detect book changes. To avoid maintaining complicated state, create a brand new
|
||||
// IObservable of book updates whenever the securities change.
|
||||
return _source.subscribe_securities()
|
||||
return criteria.subscribe_md(_source.subscribe_securities())
|
||||
.Select(fixed_sec_market_data)
|
||||
.FlattenTableSeries();
|
||||
|
||||
IObservable<TableUpdate<Book, uint>> fixed_sec_market_data(
|
||||
IReadOnlyDictionary<uint, SecurityMD> security_mds) {
|
||||
IEnumerable<SecurityMD> security_mds) {
|
||||
// Convert 'security_mds' to a list of PollableBooks.
|
||||
var cached_books = security_mds
|
||||
.Select(kv => new PollableBook(kv.Value, _num_depth_levels))
|
||||
.Select(s => new PollableBook(s, _num_depth_levels))
|
||||
.ToList();
|
||||
|
||||
return Observable.Interval(_poll_interval).Scan(
|
||||
|
||||
Reference in new issue
Block a user