From 736cb21e4df31be35677bcebb77f1e4fe0bb14f6 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Thu, 3 Mar 2022 14:44:06 -0500 Subject: [PATCH] Changed the tag/data to request archived vols --- .../AW2/Bus/VolSurfaceBlackboardManager.cs | 11 +-- .../NMSheetArchivedVolProvider.cs | 72 ++++++++++++------- src/client/spark/core/Bus/SparkTags.cs | 7 +- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs index a8b4542d2..1d6eb07e1 100644 --- a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs +++ b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs @@ -62,7 +62,7 @@ namespace mbts.spark { private readonly ITag _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag; private readonly ITag _in_bb_exp_params_tag = SparkTags.ExpirationParametersInputTag; - private readonly ITag _in_bb_req_vol = SparkTags.RequestArchivedVols; + private readonly ITag _in_bb_req_vol = SparkTags.RequestArchivedVols; // state private SystemContractData _contract_data = null; private IDictionary _vs_manager_map = @@ -192,19 +192,22 @@ namespace mbts.spark { _bb.post(SparkTags.VolSurfaceNonVolInputTag, new mbts.analytics.VolSurfaceNonVolInput(exp_param_map.exp_map.ToDictionary())); } else if (_in_bb_req_vol.Equals(tag)) { - ArchivedTheoRetrieval ret = _bb.read_state(_in_bb_req_vol); + ClientArchivedVolRequest client_req = _bb.read_state(_in_bb_req_vol); + ArchivedTheoRetrieval ret = client_req.ret; if (ret == null || ret.SecTup == null) { bts.Log.Ui.warn($"VolSurfaceBusManager malformed ArchivedTheoRetrieval"); + ArchivedTheoList empty = new ArchivedTheoList(); + _bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, empty)); return; } - bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval save_time: {ret.SaveTime} " + + bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval id: {client_req.id} save_time: {ret.SaveTime} " + $"sec_tup: {ret.SecTup.Venue}_{ret.SecTup.Type}_{ret.SecTup.Symbol}"); _timer.start(); ArchivedTheoList arch_theos = _analytics_service.get_archived_theos(ret); _timer.stop(); bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval time: {_timer.lastIntervalTime} " + $"n_entries: {arch_theos.SecTheo.Count}"); - _bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(ret.SaveTime, arch_theos)); + _bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, arch_theos)); } } diff --git a/src/client/spark/NMSheets/DataProviders/NMSheetArchivedVolProvider.cs b/src/client/spark/NMSheets/DataProviders/NMSheetArchivedVolProvider.cs index eba621eea..4982f728a 100644 --- a/src/client/spark/NMSheets/DataProviders/NMSheetArchivedVolProvider.cs +++ b/src/client/spark/NMSheets/DataProviders/NMSheetArchivedVolProvider.cs @@ -14,8 +14,27 @@ using mbts.analytics; using bts.api.analytics; namespace mbts.spark { - // This is created by the NMSheetDataCoalescer, it subsribes to the - // bbo for each BCG.NMSheetSymbol and keeps the data around + public class ClientArchivedVolRequest { + public readonly int id; + public readonly ArchivedTheoRetrieval ret; + public ClientArchivedVolRequest(Int32 id, ArchivedTheoRetrieval ret) { + this.id = id; + this.ret = ret; + } + private static int _id = 0; + public static int get_new_id() { + int rv = 0; + lock (typeof(ClientArchivedVolRequest)) { + rv = ++_id; + } + return rv; + } + public override string ToString() { + return $"id: {id} sym: {ret.SecTup.Symbol} vol_time: {ret.SaveTime}"; + } + } + // This is created by the NMSheetSingleOptionMainDataSource - it downloads the + // archived theos and provides access to it public class NMSheetArchivedVolProvider : IDisposable { private readonly ThreadedBlackboard _bb; private readonly NMSheetSymbol _sym; @@ -23,16 +42,16 @@ namespace mbts.spark { private Action _cb = () => { }; private readonly ITag _sc_tag = SparkTags.SystemContractsTag; private readonly ITag _settings_tag; - private readonly ITag> _response_tag = - SparkTags.ResponseArchivedVols; - private UInt64 _vol_time = 0; + private readonly ITag> + _response_tag = SparkTags.ResponseArchivedVols; private bool _waiting_for_reponse = false; - Tuple _cached_data = null; + private ClientArchivedVolRequest _last_req; + bts.api.analytics.ArchivedTheoList _cached_data = null; public NMSheetArchivedVolProvider(string req_id, ThreadedBlackboard bb, NMSheetSymbol symbol, Action cb) { - bts.Log.Ui.info($"NMSheetArchivedVolProvider res_id: {req_id} symbol: {symbol}"); + bts.Log.Ui.info($"NMSheetArchivedVolProvider req_id: {req_id} symbol: {symbol}"); _bb = bb; _sym = symbol; _sec_tup = new bts.api.SecurityTuple() { @@ -40,6 +59,12 @@ namespace mbts.spark { Type = SecurityType.Option, Symbol = _sym.option_name }; + _last_req = new ClientArchivedVolRequest( + 0, + new ArchivedTheoRetrieval() { + SaveTime = 0, + SecTup = _sec_tup + }); _cb = cb; _settings_tag = SparkTags.TC2Tags.NMSheetSettingsTag(req_id); _bb.subscribe(_sc_tag); @@ -74,15 +99,16 @@ namespace mbts.spark { NMSheetSettings settings = _bb.read_state(_settings_tag); if (settings != null && settings.setting_layout != null) { UInt64 vol_time = _get_vol_time(settings); - if (force || _vol_time != vol_time) { - _vol_time = vol_time; + if (force || _last_req.ret.SaveTime != vol_time) { + _last_req = new ClientArchivedVolRequest( + ClientArchivedVolRequest.get_new_id(), + new ArchivedTheoRetrieval() { + SaveTime = vol_time, + SecTup = _sec_tup + }); _waiting_for_reponse = true; - _bb.post(SparkTags.RequestArchivedVols, - new ArchivedTheoRetrieval() { - SaveTime = _vol_time, - SecTup = _sec_tup - } - ); + bts.Log.Gen.info($"NMSheetArchivedVolProvider._check_and_send_request req: {_last_req}"); + _bb.post(SparkTags.RequestArchivedVols, _last_req); } } } @@ -96,18 +122,16 @@ namespace mbts.spark { _check_and_send_request(); } else if (_response_tag.Equals(tag)) { if (_waiting_for_reponse) { - Tuple vol_data = + Tuple resp = _bb.read_state(_response_tag); - if (vol_data != null) { - if (vol_data.Item1 == _vol_time) { + if (resp != null) { + ClientArchivedVolRequest responsed_req = resp.Item1; + if (responsed_req.id == _last_req.id) { // got we were looking for - _cached_data = vol_data; + _cached_data = resp.Item2; _waiting_for_reponse = false; + bts.Log.Gen.info($"NMSheetArchivedVolProvider._on_data recvd data, req: {_last_req}"); _compute_and_post(); - } else { - // since all sheet instances are using the same tag, if they overwrite - // each other, we need to resend it. They will eventually converge - _check_and_send_request(true); } } } @@ -121,7 +145,7 @@ namespace mbts.spark { if (_cached_data != null && sc_data != null) { OptionContractKeyedData rv = new OptionContractKeyedData(); - foreach (var v in _cached_data.Item2.SecTheo) { + foreach (var v in _cached_data.SecTheo) { var sec_md = sc_data.get_sec_md(v.Id); try { if (sec_md != null) { diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index 1646d0ce6..68a4ba44a 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -313,10 +313,11 @@ namespace mbts.spark { public static ITag ShowGlobalAlertsTag { get; } = _mk_tag(); - public static ITag RequestArchivedVols { get; } = _mk_tag(); + public static ITag RequestArchivedVols { get; } = _mk_tag(); - public static ITag> ResponseArchivedVols { get; } = - _mk_tag>(); + public static ITag> + ResponseArchivedVols { get; } = + _mk_tag>(); static SparkTag _mk_tag([CallerMemberName] string name = null) => new(name ?? throw new ArgumentNullException(nameof(name)));