fix: Dispose market data sub in various md streams
This commit is contained in:
1 parent
9de21a3116
commit
23771909fd
4 files changed
+22
-10
No files matched your search
@@ -30,6 +30,7 @@ namespace BCG {
|
||||
using SecurityKey = System.UInt32;
|
||||
using System.Data;
|
||||
using System.Reflection.Metadata;
|
||||
using bts;
|
||||
|
||||
[DataStreamUserRespresentation("bbo")]
|
||||
public class BBOStream : ViewStream, IWorker {
|
||||
@@ -47,6 +48,7 @@ namespace BCG {
|
||||
Tuple.Create("bid_sz", TypeCode.Single),
|
||||
Tuple.Create("ask_price", TypeCode.Double),
|
||||
Tuple.Create("ask_sz", TypeCode.Single));
|
||||
IDisposable? subscription;
|
||||
|
||||
// TODO: add cons for symbol, exchange etc
|
||||
public BBOStream()
|
||||
@@ -60,9 +62,9 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
Log.isnull(subscription);
|
||||
_vsd.addWorker(this);
|
||||
_md_client.books().Subscribe(_on_books);
|
||||
|
||||
subscription = _md_client.books().Subscribe(_on_books);
|
||||
}
|
||||
|
||||
private void _log_updates(TableUpdate<BookTuple, uint> update) {
|
||||
@@ -84,6 +86,7 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
Disposable.dispose(ref subscription);
|
||||
_vsd.removeWorker(this);
|
||||
}
|
||||
|
||||
@@ -123,4 +126,4 @@ namespace BCG {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
namespace BCG {
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using bts;
|
||||
using bts.md;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reactive;
|
||||
|
||||
using System;
|
||||
@@ -32,6 +34,7 @@ namespace BCG {
|
||||
Tuple.Create("bid_sz", TypeCode.Single),
|
||||
Tuple.Create("ask_price", TypeCode.Double),
|
||||
Tuple.Create("ask_sz", TypeCode.Single));
|
||||
IDisposable? subscription;
|
||||
|
||||
// TODO: add cons for symbol, exchange etc
|
||||
public BookStream()
|
||||
@@ -45,9 +48,9 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
Log.isnull(subscription);
|
||||
_vsd.addWorker(this);
|
||||
_md_client.books().Subscribe(_on_books);
|
||||
|
||||
subscription = _md_client.books().Subscribe(_on_books);
|
||||
}
|
||||
|
||||
private void _log_updates(TableUpdate<BookTuple, uint> update) {
|
||||
@@ -68,6 +71,7 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
Disposable.dispose(ref subscription);
|
||||
_vsd.removeWorker(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
namespace BCG {
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.md;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reactive;
|
||||
|
||||
using System;
|
||||
@@ -35,6 +37,7 @@ namespace BCG {
|
||||
Tuple.Create("strike", TypeCode.Double),
|
||||
Tuple.Create("callput", TypeCode.String)
|
||||
);
|
||||
IDisposable? subscription;
|
||||
|
||||
// TODO: add cons for symbol, exchange etc
|
||||
public InstrumentsStream()
|
||||
@@ -48,9 +51,9 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
Log.isnull(subscription);
|
||||
_vsd.addWorker(this);
|
||||
_md_client.securities().Subscribe(_on_instruments);
|
||||
|
||||
subscription = _md_client.securities().Subscribe(_on_instruments);
|
||||
}
|
||||
|
||||
private void _log_updates(IReadOnlyDictionary<uint, SecurityImmutable> state) {
|
||||
@@ -68,6 +71,7 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
Disposable.dispose(ref subscription);
|
||||
_vsd.removeWorker(this);
|
||||
}
|
||||
|
||||
@@ -117,4 +121,4 @@ namespace BCG {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace BCG {
|
||||
using SecurityKey = System.UInt32;
|
||||
using System.Data;
|
||||
using System.Reflection.Metadata;
|
||||
using bts;
|
||||
|
||||
[DataStreamUserRespresentation("price_stats")]
|
||||
public class PriceStatsStream : ViewStream, IWorker {
|
||||
@@ -40,7 +41,6 @@ namespace BCG {
|
||||
IReadOnlyDictionary<SecurityKey, PriceStats> _cached_state = null;
|
||||
MarketDataClient _md_client;
|
||||
private bool _dirty = false;
|
||||
private IDisposable _sub = null;
|
||||
private readonly IBlueTableSchema _pstats_scheam = BlueDataUtility.form_schema("bbo",
|
||||
Tuple.Create("id", TypeCode.Int32),
|
||||
Tuple.Create("sec_key", TypeCode.UInt32),
|
||||
@@ -63,6 +63,7 @@ namespace BCG {
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber() {
|
||||
Log.isnull(subscription);
|
||||
_vsd.addWorker(this);
|
||||
subscription = _md_client.price_stats().Subscribe(_on_price_stats);
|
||||
}
|
||||
@@ -88,7 +89,7 @@ namespace BCG {
|
||||
|
||||
protected override void myOnLastSubscriber() {
|
||||
_vsd.removeWorker(this);
|
||||
Disposable.dispose(ref _sub);
|
||||
Disposable.dispose(ref subscription);
|
||||
}
|
||||
|
||||
private void _scan() {
|
||||
|
||||
Reference in new issue
Block a user