fix: Dispose market data sub in various md streams

This commit is contained in:
John Colvin committed 2025-08-24 13:46:48 -04:00
1 parent cd833ceb36
commit 765e45d95a
4 files changed
+20 -9

No files matched your search

@@ -11,6 +11,7 @@ namespace bts.BlueOrb {
using System.Reactive.Linq;
using bts.api.core;
using Spark.Api.MarketData;
using Spark.Core.Disposables;
using SecurityKey = System.UInt32;
@@ -116,6 +117,7 @@ namespace bts.BlueOrb {
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()
@@ -131,10 +133,9 @@ namespace bts.BlueOrb {
}
protected override void myOnFirstSubscriber() {
_vsd.addWorker(this);
_md_client.books().Subscribe(_on_books);
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) {
@@ -156,6 +157,7 @@ namespace bts.BlueOrb {
}
protected override void myOnLastSubscriber() {
Disposable.dispose(ref subscription);
_vsd?.removeWorker(this);
}
@@ -2,8 +2,10 @@ namespace bts.BlueOrb{
using BCG.Utilities.General;
using BCG;
using bts;
using bts.md;
using Spark.Core.Disposables;
using Spark.Core.Reactive;
using System;
@@ -33,6 +35,7 @@ namespace bts.BlueOrb{
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()
@@ -46,9 +49,9 @@ namespace bts.BlueOrb{
}
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) {
@@ -69,6 +72,7 @@ namespace bts.BlueOrb{
}
protected override void myOnLastSubscriber() {
Disposable.dispose(ref subscription);
_vsd.removeWorker(this);
}
@@ -1,10 +1,12 @@
namespace bts.BlueOrb {
using BCG.Utilities.General;
using bts;
using bts.api;
using bts.md;
using BCG;
using Spark.Core.Disposables;
using Spark.Core.Reactive;
using System;
@@ -37,6 +39,7 @@ namespace bts.BlueOrb {
Tuple.Create("strike", TypeCode.Double),
Tuple.Create("callput", TypeCode.String)
);
IDisposable? subscription;
// TODO: add cons for symbol, exchange etc
public InstrumentsStream()
@@ -50,9 +53,9 @@ namespace bts.BlueOrb {
}
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) {
@@ -70,6 +73,7 @@ namespace bts.BlueOrb {
}
protected override void myOnLastSubscriber() {
Disposable.dispose(ref subscription);
_vsd.removeWorker(this);
}
@@ -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() {