diff --git a/src/client/spark/AW2/Bus/AnalyticsParametersManager.cs b/src/client/spark/AW2/Bus/AnalyticsParametersManager.cs index d0a5a403b..397d5b9b3 100644 --- a/src/client/spark/AW2/Bus/AnalyticsParametersManager.cs +++ b/src/client/spark/AW2/Bus/AnalyticsParametersManager.cs @@ -31,7 +31,7 @@ namespace mbts.spark { .ObserveOn(SynchronizationContext.Current) .Subscribe(_on_exp_parameters); _disposables.Add(exp_params_sub); - _bb.add_to_subscription_list(_in_bb_exp_params_commit_tag); + _bb.subscribe(_in_bb_exp_params_commit_tag); _bb.data_callback += _on_bb_data; } diff --git a/src/client/spark/AW2/Bus/SingleOptionDriverPricePublisher.cs b/src/client/spark/AW2/Bus/SingleOptionDriverPricePublisher.cs index 4deb8f17f..846151a9f 100644 --- a/src/client/spark/AW2/Bus/SingleOptionDriverPricePublisher.cs +++ b/src/client/spark/AW2/Bus/SingleOptionDriverPricePublisher.cs @@ -27,7 +27,8 @@ namespace mbts.spark { ThreadedBlackboard bb) { _sec_tup = sec_tup; _bb = bb; - _bb.add_to_subscription_list(_in_bb_exp_params_tag, _in_bb_contracts_tag); + _bb.subscribe(_in_bb_exp_params_tag); + _bb.subscribe(_in_bb_contracts_tag); _bb.data_callback += _on_bb_data; _bb.timer_callback += _on_bb_timer; } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs index 432462adb..bf48d6bb4 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceClientPrecomputedTheosPublisher.cs @@ -8,6 +8,7 @@ using System.Collections.Concurrent; using System.IO; using System.IO.Compression; using bts; +using bts.api; namespace mbts.spark { /// @@ -29,8 +30,13 @@ namespace mbts.spark { public class SingleVolSurfaceClientPrecomputedTheosPublisher : IDisposable { private readonly int _vs_id; private readonly IEnumerable _sym_map; - private readonly ThreadedBlackboard _threaded_bb; - private readonly object _in_vs_input_tag, _in_vs_nonvol_input_tag, _in_vs_contracts_tag, _in_vs_driver_price_map_tag, _in_vs_standard_time_tag, _in_ui_up_tag;//, _in_active_sheet_exps_tag, _in_bb_settings_tag; + private readonly ThreadedBlackboard _bb; + private readonly ITag _in_vs_input_tag; + private ITag _in_vs_nonvol_input_tag; + private ITag _in_vs_contracts_tag; + private ITag> _in_vs_driver_price_map_tag; + private ITag _in_vs_standard_time_tag; + private ITag _in_ui_up_tag; private VolSurfacePrecomputedTheosProducer _theo_producer = new VolSurfacePrecomputedTheosProducer(); private readonly SingleVolSurfaceClientTheosPublishHelper _local_publish_helper; private readonly string _user; @@ -40,7 +46,7 @@ namespace mbts.spark { public SingleVolSurfaceClientPrecomputedTheosPublisher(int vs_id, ThreadedBlackboard threaded_bb, IEnumerable symbols) { _vs_id = vs_id; _sym_map = symbols; - _threaded_bb = threaded_bb; + _bb = threaded_bb; // TODO //_user = BlackboardSetup.current_user; _user = String.Empty; @@ -55,23 +61,28 @@ namespace mbts.spark { //_in_active_sheet_exps_tag = new NMSheetTags.NMSheetActiveExpirationsTag(); _local_publish_helper = new SingleVolSurfaceClientTheosPublishHelper(vs_id, threaded_bb); //_in_bb_settings_tag = new ClickTradeSettingsTag(); - _threaded_bb.add_to_subscription_list(_in_vs_input_tag, _in_vs_nonvol_input_tag, _in_vs_contracts_tag, _in_vs_driver_price_map_tag, _in_vs_standard_time_tag, _in_ui_up_tag/*, _in_active_sheet_exps_tag, _in_bb_settings_tag*/); - _threaded_bb.data_callback += _on_bb_data; + _bb.subscribe(_in_vs_input_tag); + _bb.subscribe(_in_vs_nonvol_input_tag); + _bb.subscribe(_in_vs_contracts_tag); + _bb.subscribe(_in_vs_driver_price_map_tag); + _bb.subscribe(_in_vs_standard_time_tag); + _bb.subscribe(_in_ui_up_tag); + _bb.data_callback += _on_bb_data; } #region Blackboard Callbacks private void _on_bb_data(object tag, object data) { if (_in_vs_input_tag.Equals(tag)) { - _vs_input = _threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceInput; + _vs_input = _bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceInput; _theo_producer.set_vol_data(_vs_input); } else if (_in_vs_nonvol_input_tag.Equals(tag)) - _theo_producer.set_nonvol_parameters((_threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceNonVolInput).exp_input_map); + _theo_producer.set_nonvol_parameters((_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceNonVolInput).exp_input_map); else if (_in_vs_contracts_tag.Equals(tag)) // || _in_active_sheet_exps_tag.Equals(tag)) _set_contracts(); else if (_in_vs_driver_price_map_tag.Equals(tag)) - _theo_producer.set_driver_price(_threaded_bb.sec_thread_retrieve_from_cache(tag) as IDictionary); + _theo_producer.set_driver_price(_bb.sec_thread_retrieve_from_cache(tag) as IDictionary); else if (_in_vs_standard_time_tag.Equals(tag)) - _theo_producer.set_system_vol_time(_threaded_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceStandardTime); + _theo_producer.set_system_vol_time(_bb.sec_thread_retrieve_from_cache(tag) as VolSurfaceStandardTime); } private void _set_contracts() { @@ -124,7 +135,7 @@ namespace mbts.spark { #region IDisposable public void Dispose() { - _threaded_bb.data_callback -= _on_bb_data; + _bb.data_callback -= _on_bb_data; } #endregion } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs index 1b5edeb06..bf095c165 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceCommittedOutputRetriever.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using mbts.analytics; +using bts.api; -namespace mbts.spark -{ +namespace mbts.spark { /// /// Publishes the vol outputs for a single vol surface. /// Despite of the name Retriever, this class computes the vols @@ -17,49 +17,46 @@ namespace mbts.spark /// 3. VS nonvol Data /// Pubs : /// 1. VS Out - public class SingleVolSurfaceCommittedOutputRetriever : IDisposable - { - private readonly object _in_bb_vs_input_tag, - _in_bb_nonvol_data_tag, - _in_vs_standard_time_tag, - _out_bb_computed_vol_tag; + public class SingleVolSurfaceCommittedOutputRetriever : IDisposable { + private readonly ITag _in_bb_vs_input_tag; + private readonly ITag _in_bb_nonvol_data_tag; + private readonly ITag _in_vs_standard_time_tag; + private readonly ITag _out_bb_computed_vol_tag; private readonly ThreadedBlackboard _bb; private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly PerfStatsLogger _logger = new PerfStatsLogger(50, 100); private readonly string _log_id; - public SingleVolSurfaceCommittedOutputRetriever(int volsurface_id, ThreadedBlackboard threaded_bb, IEnumerable symbols) - { + public SingleVolSurfaceCommittedOutputRetriever(int volsurface_id, ThreadedBlackboard threaded_bb, IEnumerable symbols) { _bb = threaded_bb; _in_bb_vs_input_tag = SparkTags.VolSurfaceCommittedInputTag(volsurface_id); _in_bb_nonvol_data_tag = SparkTags.VolSurfaceNonVolDataTag(volsurface_id); _in_vs_standard_time_tag = SparkTags.VolSurfaceStandardTimeTag(volsurface_id); _out_bb_computed_vol_tag = SparkTags.VolSurfaceCommittedOutputTag(volsurface_id); _log_id = String.Format("SingleVolSurfaceCommittedOutputRetriever {0}", volsurface_id); - _bb.add_to_subscription_list(_in_bb_vs_input_tag, _in_bb_nonvol_data_tag, _in_vs_standard_time_tag); + _bb.subscribe(_in_bb_vs_input_tag); + _bb.subscribe(_in_bb_nonvol_data_tag); + _bb.subscribe(_in_vs_standard_time_tag); _bb.data_callback += _on_bb_data; _recompute_and_publish(); } - private void _on_bb_data(object tag, object data) - { - if (_in_bb_vs_input_tag.Equals(tag) || _in_bb_nonvol_data_tag.Equals(tag) || _in_vs_standard_time_tag.Equals (tag)) + private void _on_bb_data(object tag, object data) { + if (_in_bb_vs_input_tag.Equals(tag) || _in_bb_nonvol_data_tag.Equals(tag) || _in_vs_standard_time_tag.Equals(tag)) _recompute_and_publish(); } - private void _recompute_and_publish() - { + private void _recompute_and_publish() { VolSurfaceInput vs_input = _bb.sec_thread_retrieve_from_cache(_in_bb_vs_input_tag) as VolSurfaceInput; VolSurfaceNonVolData vs_nonvol_data = _bb.sec_thread_retrieve_from_cache(_in_bb_nonvol_data_tag) as VolSurfaceNonVolData; VolSurfaceStandardTime vs_standard_time = _bb.sec_thread_retrieve_from_cache(_in_vs_standard_time_tag) as VolSurfaceStandardTime; - if (vs_input != null && vs_nonvol_data != null && vs_standard_time != null) - { + if (vs_input != null && vs_nonvol_data != null && vs_standard_time != null) { _timer.start(); IDictionary aux_data_map = VolSurfaceUtilityFunctions.compute_aux_data(vs_input, vs_nonvol_data.input, vs_nonvol_data.driver_price_map, vs_standard_time); VolSurfaceOutput vs_output = GeneralVolSurfaceCalculator.compute(vs_input, vs_nonvol_data.contracts, aux_data_map); _timer.stop(); _logger.log(_log_id, _log_id, _timer.lastIntervalTime); - _bb.sec_thread_write(_out_bb_computed_vol_tag, vs_output); + _bb.sec_thread_write(_out_bb_computed_vol_tag, vs_output); } } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceDataSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceDataSource.cs index 51485b0ad..30887afc0 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceDataSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceDataSource.cs @@ -9,17 +9,14 @@ using bts.utils; using bts.api; -namespace mbts.spark -{ +namespace mbts.spark { /// Listens to the input (either committed or candidate depending on the arg) /// and creates the actual source that is immutable wrt the symbol list. /// (Making the real sources immutable wrt to the symbol list simplifies /// things a lot. Symbol lists rarely every change, but its a pain to /// handle such changes) - public class SingleVolSurfaceDataSource : IDisposable - { - public enum SymbolListType - { + public class SingleVolSurfaceDataSource : IDisposable { + public enum SymbolListType { Committed, Candidate, Combined, @@ -28,54 +25,46 @@ namespace mbts.spark private readonly int _vs_id; private readonly ThreadedBlackboard _bb; private readonly Func, IDisposable> _create_func; - private readonly object _in_bb_committed_data_tag, _in_bb_calc_req_tag; - + private readonly ITag _in_bb_committed_data_tag; + private readonly ITag _in_bb_calc_req_tag; + private HashSet _option_symbols = new HashSet(); private IDisposable _source = null; public SingleVolSurfaceDataSource(SymbolListType list_type, int vs_id, ThreadedBlackboard threaded_bb, - Func, IDisposable> create_func) - { + Func, IDisposable> create_func) { Log.Gen.info(String.Format("SingleVolSurfaceDataSource constructed vs_id {0}", vs_id)); _list_type = list_type; - _vs_id = vs_id; + _vs_id = vs_id; _bb = threaded_bb; _create_func = create_func; _in_bb_committed_data_tag = SparkTags.VolSurfaceCommittedInputTag(vs_id); _in_bb_calc_req_tag = SparkTags.VolSurfaceCalculationRequestTag(vs_id); - _bb.add_to_subscription_list(_in_bb_committed_data_tag, _in_bb_calc_req_tag); + _bb.subscribe(_in_bb_committed_data_tag); + _bb.subscribe(_in_bb_calc_req_tag); _bb.data_callback += _on_bb_data; _recompute(); } - private void _on_bb_data(object tag, object data) - { + private void _on_bb_data(object tag, object data) { if (_in_bb_committed_data_tag.Equals(tag) || _in_bb_calc_req_tag.Equals(tag)) _recompute(); } - private void _recompute() - { + private void _recompute() { VolSurfaceCalculationRequest vs_calc_req = _bb.sec_thread_retrieve_from_cache(_in_bb_calc_req_tag) as VolSurfaceCalculationRequest; VolSurfaceInput vs_comm_inp = _bb.sec_thread_retrieve_from_cache(_in_bb_committed_data_tag) as VolSurfaceInput; - if (_list_type == SymbolListType.Candidate) - { - if (vs_calc_req != null && vs_calc_req.volsurface_input != null) - { + if (_list_type == SymbolListType.Candidate) { + if (vs_calc_req != null && vs_calc_req.volsurface_input != null) { HashSet new_sym_map = new HashSet(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input)); _create_if_needed(new_sym_map); } - } - else if (_list_type == SymbolListType.Committed) - { - if (vs_comm_inp != null) - { + } else if (_list_type == SymbolListType.Committed) { + if (vs_comm_inp != null) { HashSet new_sym_map = new HashSet(VolSurfaceDataFunctions.get_symbols(vs_comm_inp)); _create_if_needed(new_sym_map); } - } - else if (_list_type == SymbolListType.Combined) - { + } else if (_list_type == SymbolListType.Combined) { List new_sym_list = new List(); if (vs_calc_req != null && vs_calc_req.volsurface_input != null) new_sym_list.AddRange(VolSurfaceDataFunctions.get_symbols(vs_calc_req.volsurface_input)); @@ -85,23 +74,20 @@ namespace mbts.spark } } - private void _create_if_needed(HashSet new_sym_map) - { - if (!CollectionHelper.hashset_equals(_option_symbols, new_sym_map)) - { + private void _create_if_needed(HashSet new_sym_map) { + if (!CollectionHelper.hashset_equals(_option_symbols, new_sym_map)) { _option_symbols = new HashSet(new_sym_map); if (_source != null) _source.Dispose(); _source = _create_func(_option_symbols); - _bb.sec_thread_write(SparkTags.AquireTag (Guid.NewGuid().ToString()), + _bb.sec_thread_write(SparkTags.AquireTag(Guid.NewGuid().ToString()), new SymbolResourceAllocationUnit( _option_symbols.Select(i => new mbts.SecurityTuple(SecurityType.Option, i, Venue.Unset)), this, true)); } } #region IDisposable - public void Dispose() - { + public void Dispose() { if (_source != null) _source.Dispose(); _bb.data_callback -= _on_bb_data; diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs index 31b9645f7..9583cd766 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceGateway.cs @@ -8,6 +8,7 @@ using bts; using bts.api.analytics; using System.Reactive.Linq; using System.Threading; +using bts.api; using System.Collections; namespace mbts.spark { @@ -20,7 +21,7 @@ namespace mbts.spark { public class SingleVolSurfaceGateway : IDisposable { private readonly int _volsurface_id; private readonly ThreadedBlackboard _threaded_bb; - private readonly object _in_bb_committ_tag; + private readonly ITag _in_bb_committ_tag; private AnalyticsService _analytics_service; private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private readonly string _user; @@ -35,7 +36,7 @@ namespace mbts.spark { _user = String.Empty; //BlackboardSetup.current_user; // TODO _in_bb_committ_tag = SparkTags.VolSurfaceCommitTag(volsurface_id); _analytics_service = analytics_service; - _threaded_bb.add_to_subscription_list(_in_bb_committ_tag); + _threaded_bb.subscribe(_in_bb_committ_tag); _threaded_bb.data_callback += _on_bb_data; var vs_sub = _analytics_service.subscribei_volsurfaces() .ObserveOn(SynchronizationContext.Current) diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs index 3704d9621..a958ce772 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceManager.cs @@ -5,19 +5,20 @@ using System.Text; using System.Threading.Tasks; using bts.api.analytics; +using bts.api; using mbts.analytics; namespace mbts.spark { public class SingleVolSurfaceManager : IDisposable { private IEnumerable _resources; - private readonly object _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag; + private readonly ITag _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag; private readonly ThreadedBlackboard _threaded_bb; public SingleVolSurfaceManager(int vs_id, ThreadedBlackboard t_bb, bts.api.IBus global_bus, AnalyticsService analytics_service) { _threaded_bb = t_bb; - _threaded_bb.add_to_subscription_list(_in_bb_delete_tag); + _threaded_bb.subscribe(_in_bb_delete_tag); _threaded_bb.data_callback += _on_data; _resources = new IDisposable[] { diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs index 78f4b1e61..ff85fdbd1 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceMarketImpliedVolSource.cs @@ -55,13 +55,13 @@ namespace mbts.spark { } #endregion private readonly int _vs_id; - private readonly object _in_bb_sec_map_tag, - _in_bb_committed_output_tag, - _in_bb_calc_resp_tag, - _in_bb_inp_dirty_tag, - _in_bb_selected_exp_tag, - _in_bb_market_impliedvol_side_tag, - _in_bb_ignore_market_implied_vol_source_settings_tag; + private readonly ITag> _in_bb_sec_map_tag; + private readonly ITag _in_bb_committed_output_tag; + private readonly ITag _in_bb_calc_resp_tag; + private readonly ITag _in_bb_inp_dirty_tag; + private readonly ITag> _in_bb_selected_exp_tag; + private readonly ITag _in_bb_market_impliedvol_side_tag; + private readonly ITag _in_bb_ignore_market_implied_vol_source_settings_tag; private CachedExpMD _cached_exp_md = new CachedExpMD(); private readonly ThreadedBlackboard _bb; private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); @@ -78,9 +78,12 @@ namespace mbts.spark { _in_bb_selected_exp_tag = SparkTags.VolSurfaceGridSelectionTag(_vs_id); _in_bb_market_impliedvol_side_tag = SparkTags.VolSurfaceMarketImpliedVolSide(_vs_id); _in_bb_ignore_market_implied_vol_source_settings_tag = SparkTags.VolSurfaceIgnoreImpliedVolSettingsTag(volsurface_id); - _bb.add_to_subscription_list(_in_bb_committed_output_tag, _in_bb_calc_resp_tag, - _in_bb_inp_dirty_tag, _in_bb_selected_exp_tag, - _in_bb_market_impliedvol_side_tag, _in_bb_ignore_market_implied_vol_source_settings_tag); + _bb.subscribe(_in_bb_committed_output_tag); + _bb.subscribe(_in_bb_calc_resp_tag); + _bb.subscribe(_in_bb_inp_dirty_tag); + _bb.subscribe(_in_bb_selected_exp_tag); + _bb.subscribe(_in_bb_market_impliedvol_side_tag); + _bb.subscribe(_in_bb_ignore_market_implied_vol_source_settings_tag); _bb.data_callback += _on_bb_data; _bb.timer_callback += _on_bb_timer; } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceNonVolDataSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceNonVolDataSource.cs index 2c4f9d073..b9a336668 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceNonVolDataSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceNonVolDataSource.cs @@ -3,31 +3,30 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using mbts.analytics; -namespace mbts.spark -{ +using mbts.analytics; +using bts.api; + +namespace mbts.spark { /// Subs : /// 1. Securities (AllBasicSecuritiesTag) /// 2. Driver prices (VolSurfaceOptionDriverTag) /// 3. NonVolInput (VolSurfaceNonVolInputTag) /// Publishes : /// 1. VolSurfaceNonVolData which is simply a union of the 3 inputs - public class SingleVolSurfaceNonVolDataSource : IDisposable - { + public class SingleVolSurfaceNonVolDataSource : IDisposable { private readonly IEnumerable _option_symbols; private readonly ThreadedBlackboard _bb; - private readonly object _in_bb_contract_data_tag, - _in_bb_vs_nonvol_input_tag, - _in_bb_driver_price_tag, - _out_bb_vs_nonvol_data_tag, - _out_bb_vs_contracts_tag; + private readonly ITag _in_bb_contract_data_tag; + private readonly ITag _in_bb_vs_nonvol_input_tag; + private readonly ITag> _in_bb_driver_price_tag; + private readonly ITag _out_bb_vs_nonvol_data_tag; + private readonly ITag _out_bb_vs_contracts_tag; /// This is the only cached data to avoid computing it /// when more frequently changing data move around private IDictionary> _sec_map = new Dictionary>(); - public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable option_symbols, ThreadedBlackboard bb) - { + public SingleVolSurfaceNonVolDataSource(int vs_id, IEnumerable option_symbols, ThreadedBlackboard bb) { _option_symbols = option_symbols; _bb = bb; _in_bb_contract_data_tag = SparkTags.SystemContractsTag; @@ -35,14 +34,14 @@ namespace mbts.spark _in_bb_driver_price_tag = SparkTags.VolSurfaceOptionDriverTag(vs_id); _out_bb_vs_nonvol_data_tag = SparkTags.VolSurfaceNonVolDataTag(vs_id); _out_bb_vs_contracts_tag = SparkTags.VolSurfaceContractsTag(vs_id); - _bb.add_to_subscription_list(_in_bb_contract_data_tag, _in_bb_vs_nonvol_input_tag, _in_bb_driver_price_tag); + _bb.subscribe(_in_bb_contract_data_tag); + _bb.subscribe(_in_bb_vs_nonvol_input_tag); + _bb.subscribe(_in_bb_driver_price_tag); _bb.data_callback += _on_bb_data; } - private void _on_bb_data(object tag, object data) - { - if (_in_bb_contract_data_tag.Equals(tag)) - { + private void _on_bb_data(object tag, object data) { + if (_in_bb_contract_data_tag.Equals(tag)) { SystemContractData contract_data = _bb.sec_thread_retrieve_from_cache(_in_bb_contract_data_tag) as SystemContractData; _sec_map.Clear(); if (contract_data != null) @@ -51,13 +50,11 @@ namespace mbts.spark _sec_map[new VolSurfaceExpiration() { symbol = s, expiration = kv.Key }] = kv.Value; _bb.sec_thread_write(_out_bb_vs_contracts_tag, _sec_map.ToDictionary(kv => kv.Key, kv => kv.Value.ToList() as IEnumerable)); _recompute_and_fire(); - } - else if (_in_bb_vs_nonvol_input_tag.Equals(tag) || _in_bb_driver_price_tag.Equals(tag)) + } else if (_in_bb_vs_nonvol_input_tag.Equals(tag) || _in_bb_driver_price_tag.Equals(tag)) _recompute_and_fire(); } - private void _recompute_and_fire() - { + private void _recompute_and_fire() { VolSurfaceNonVolInput vs_nonvol_input = _bb.sec_thread_retrieve_from_cache(_in_bb_vs_nonvol_input_tag) as VolSurfaceNonVolInput; var price_map = _bb.sec_thread_retrieve_from_cache(_in_bb_driver_price_tag) as IDictionary; if (_sec_map != null && vs_nonvol_input != null && price_map != null) diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceOptionDriverSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceOptionDriverSource.cs index b35e70221..79517fc33 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceOptionDriverSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceOptionDriverSource.cs @@ -21,7 +21,8 @@ namespace mbts.spark { private IDictionary _option_driver_price_map = new Dictionary(); private bool _option_driver_dirty = false; - private HashSet _option_driver_price_tags = new HashSet(); + private HashSet> _option_driver_price_tags = + new HashSet>(); public SingleVolSurfaceOptionDriverSource(int vs_id, @@ -34,7 +35,7 @@ namespace mbts.spark { foreach (string o in _option_symbols) { var tag = SparkTags.OptionDriverBBOTag(o); _option_driver_price_tags.Add(tag); - _threaded_bb.add_to_subscription_list(tag); + _threaded_bb.subscribe(tag); } _threaded_bb.data_callback += _on_bb_data; _threaded_bb.timer_callback += _on_timer; diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs index 5b97c8a46..98d6fb7e3 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceRequestCalculator.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using bts.api; + using mbts.analytics; namespace mbts.spark { @@ -21,7 +23,11 @@ namespace mbts.spark { private readonly int _vs_id; private readonly HashSet _symbols; private readonly ThreadedBlackboard _threaded_bb; - private readonly object _in_bb_request_tag, _in_bb_dirty_tag, _in_bb_nonvol_data_tag, _in_bb_vs_standard_time_tag, _in_bb_market_impliedvol_side_tag; + private readonly ITag _in_bb_request_tag; + private readonly ITag _in_bb_nonvol_data_tag; + private readonly ITag _in_bb_vs_standard_time_tag; + private readonly ITag _in_bb_market_impliedvol_side_tag; + private readonly ITag _in_bb_dirty_tag; private HighPerformanceTimer _timer = new HighPerformanceTimer(); /// data private VolSurfaceOutput _last_output; @@ -35,7 +41,11 @@ namespace mbts.spark { _in_bb_vs_standard_time_tag = SparkTags.VolSurfaceStandardTimeTag(vs_id); _in_bb_market_impliedvol_side_tag = SparkTags.VolSurfaceMarketImpliedVolSide(vs_id); _in_bb_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(vs_id); - _threaded_bb.add_to_subscription_list(_in_bb_request_tag, _in_bb_nonvol_data_tag, _in_bb_vs_standard_time_tag, _in_bb_vs_standard_time_tag, _in_bb_dirty_tag); + _threaded_bb.subscribe(_in_bb_request_tag); + _threaded_bb.subscribe(_in_bb_nonvol_data_tag); + _threaded_bb.subscribe(_in_bb_vs_standard_time_tag); + _threaded_bb.subscribe(_in_bb_vs_standard_time_tag); + _threaded_bb.subscribe(_in_bb_dirty_tag); _threaded_bb.data_callback += _on_bb_data; _recompute_and_publish(true); } diff --git a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs index ed9ea6355..c3e40e320 100644 --- a/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs +++ b/src/client/spark/AW2/Bus/SingleVolSurfaceTheoSource.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using mbts.analytics; using bts; +using bts.api; namespace mbts.spark { /// Publishes the committed and candidate greeks in the @@ -18,21 +19,27 @@ namespace mbts.spark { /// 1. VolSurfaceTheoData (cand and comm theos) public class SingleVolSurfaceTheoSource : IDisposable { private readonly int _volsurface_id; - private readonly ThreadedBlackboard _threaded_bb; - private readonly object _in_committed_vol_output_tag, _in_candidate_vol_output_tag, _in_input_dirty_tag, _in_window_state_tag; + private readonly ThreadedBlackboard _bb; + private readonly ITag _in_committed_vol_output_tag; + private readonly ITag _in_candidate_vol_output_tag; + private readonly ITag _in_input_dirty_tag; + private readonly ITag _in_window_state_tag; private readonly HighPerformanceTimer _timer = new HighPerformanceTimer(); private bool _is_dirty = true; public SingleVolSurfaceTheoSource(int volsurface_id, ThreadedBlackboard threaded_bb) { _volsurface_id = volsurface_id; - _threaded_bb = threaded_bb; + _bb = threaded_bb; _in_committed_vol_output_tag = SparkTags.VolSurfaceCommittedOutputTag(_volsurface_id); _in_candidate_vol_output_tag = SparkTags.VolSurfaceCalculationResponseTag(_volsurface_id); _in_input_dirty_tag = SparkTags.VolSurfaceDirtyStateTag(_volsurface_id); _in_window_state_tag = SparkTags.VolSurfaceTheoWindowStateTag(_volsurface_id); - _threaded_bb.add_to_subscription_list(_in_committed_vol_output_tag, _in_candidate_vol_output_tag, _in_input_dirty_tag, _in_window_state_tag); - _threaded_bb.data_callback += _on_data; - _threaded_bb.timer_callback += _on_timer; + _bb.subscribe(_in_committed_vol_output_tag); + _bb.subscribe(_in_candidate_vol_output_tag); + _bb.subscribe(_in_input_dirty_tag); + _bb.subscribe(_in_window_state_tag); + _bb.data_callback += _on_data; + _bb.timer_callback += _on_timer; } #region Blackboard @@ -55,9 +62,9 @@ namespace mbts.spark { private static readonly IDictionary> _empty_theos = new Dictionary>(); private VolSurfaceTheoData _last_data = new VolSurfaceTheoData(new Dictionary>(), _empty_theos, _empty_theos, false); private void _compute_and_publish(bool is_active_candidate, bool is_active_theos_window) { - VolSurfaceCalculationResponse calc_resp = _threaded_bb.sec_thread_retrieve_from_cache(_in_candidate_vol_output_tag) as VolSurfaceCalculationResponse; + VolSurfaceCalculationResponse calc_resp = _bb.sec_thread_retrieve_from_cache(_in_candidate_vol_output_tag) as VolSurfaceCalculationResponse; VolSurfaceOutput candidate_output = calc_resp != null ? calc_resp.volsurface_calculation_output : null, - committed_output = _threaded_bb.sec_thread_retrieve_from_cache(_in_committed_vol_output_tag) as VolSurfaceOutput; + committed_output = _bb.sec_thread_retrieve_from_cache(_in_committed_vol_output_tag) as VolSurfaceOutput; IDictionary> secs = _get_securities(committed_output, candidate_output); IDictionary> comm_theo_map = _empty_theos, cand_theo_map = _empty_theos; if (is_active_theos_window) { @@ -70,7 +77,7 @@ namespace mbts.spark { } var new_data = new VolSurfaceTheoData(secs, comm_theo_map, cand_theo_map, is_active_candidate); if (_is_valid_update(new_data)) - _threaded_bb.sec_thread_write(SparkTags.VolSurfaceTheoOutputTag(_volsurface_id), new_data); + _bb.sec_thread_write(SparkTags.VolSurfaceTheoOutputTag(_volsurface_id), new_data); } private bool _is_valid_update(VolSurfaceTheoData new_data) { @@ -109,19 +116,19 @@ namespace mbts.spark { /// If the details window is not active, the calculations are suspended private bool _is_active_theos_window() { - object rv_obj = _threaded_bb.sec_thread_retrieve_from_cache(_in_window_state_tag); + object rv_obj = _bb.sec_thread_retrieve_from_cache(_in_window_state_tag); return rv_obj != null && (bool)rv_obj; } private bool _is_active_candidate() { - object rv_obj = _threaded_bb.sec_thread_retrieve_from_cache(_in_input_dirty_tag); + object rv_obj = _bb.sec_thread_retrieve_from_cache(_in_input_dirty_tag); return rv_obj != null && (bool)rv_obj; } #region IDisposable public void Dispose() { - _threaded_bb.data_callback -= _on_data; - _threaded_bb.timer_callback -= _on_timer; + _bb.data_callback -= _on_data; + _bb.timer_callback -= _on_timer; } #endregion } diff --git a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs index 16fa80f1a..6661a1971 100644 --- a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs +++ b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs @@ -32,10 +32,10 @@ namespace mbts.spark { private ThreadedBlackboard _threaded_bb; private IVolSurfaceBroker _broker; private bts.api.analytics.AnalyticsService _analytics_service; - private readonly object _in_bb_create_tag = SparkTags.VolSurfaceCreateTag, - _in_bb_contract_data_tag = SparkTags.SystemContractsTag, - _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag, - _in_bb_exp_params_tag = SparkTags.ExpirationParametersInputTag; + private readonly ITag _in_bb_create_tag = SparkTags.VolSurfaceCreateTag; + private readonly ITag _in_bb_contract_data_tag = SparkTags.SystemContractsTag; + private readonly ITag _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag; + private readonly ITag _in_bb_exp_params_tag = SparkTags.ExpirationParametersInputTag; private IDictionary _vs_manager_map = new Dictionary(); private Queue _waiting_creations = new Queue(); private bts.api.IBus _bus; @@ -48,9 +48,10 @@ namespace mbts.spark { _broker = broker; _analytics_service = analytics_service; // subs to bb - _threaded_bb.add_to_subscription_list(_in_bb_contract_data_tag, - _in_bb_create_tag, _in_bb_delete_tag, - _in_bb_exp_params_tag); + _threaded_bb.subscribe(_in_bb_contract_data_tag); + _threaded_bb.subscribe(_in_bb_create_tag); + _threaded_bb.subscribe(_in_bb_delete_tag); + _threaded_bb.subscribe(_in_bb_exp_params_tag); _threaded_bb.data_callback += _on_bb_update; _threaded_bb.timer_callback += _on_timer; // sub to service diff --git a/src/client/spark/AW2/Misc/ThreadedBlackboard.cs b/src/client/spark/AW2/Misc/ThreadedBlackboard.cs index 23b72e9b8..465290e91 100644 --- a/src/client/spark/AW2/Misc/ThreadedBlackboard.cs +++ b/src/client/spark/AW2/Misc/ThreadedBlackboard.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reactive.Linq; using System.Security.AccessControl; using System.Text; +using System.Threading.Tasks; using bts.api; @@ -34,30 +35,34 @@ namespace mbts.spark { public OnBBData data_callback; public Action timer_callback; - public void add_to_subscription_list(params object[] tags) { - } - + #region Templatized sub/write public void add_to_subscription_list(ITag tag) { var observable = _bus.subscribe(tag).OnDispatcher().Subscribe( data => _on_bus_data(tag, data)); } + public void subscribe(ITag tag) { + var observable = _bus.subscribe(tag).OnDispatcher().Subscribe( + data => _on_bus_data(tag, data)); + } + + public void sec_thread_write(ITag tag, T data, bool block_until_written = false) { + _bus.post(tag, data); + } + private void _on_bus_data(ITag tag, T data) { data_callback(tag, data); } + #endregion - // public void add_to_subscription_list(Func sub_func) { } - + // public void add_to_subscription_list(params object[] tags) { + // } public void sec_thread_write(object tag, object value) { sec_thread_write(tag, value, false); } public void sec_thread_write(object tag, object value, bool block_until_written) { } - public void sec_thread_write(ITag tag, T data, bool block_until_written) { - _bus.post(tag, data); - } - public void sec_thread_dowork() { } public object sec_thread_retrieve_from_cache(object tag) { diff --git a/src/client/spark/AW2/VolSurfaceLocalTheosManager.cs b/src/client/spark/AW2/VolSurfaceLocalTheosManager.cs index 20b134ec5..ac92c8f5b 100644 --- a/src/client/spark/AW2/VolSurfaceLocalTheosManager.cs +++ b/src/client/spark/AW2/VolSurfaceLocalTheosManager.cs @@ -27,7 +27,7 @@ namespace mbts.spark { public VolSurfaceLocalTheosManager(ThreadedBlackboard bb) { _bb = bb; _in_bb_volsurface_usage_tag = SparkTags.VolSurfaceUsageTag; - _bb.add_to_subscription_list(_in_bb_volsurface_usage_tag); + _bb.subscribe(_in_bb_volsurface_usage_tag); _bb.data_callback += _on_data; _analyze_usages(); } @@ -50,7 +50,7 @@ namespace mbts.spark { if (!_vs_theo_tags.ContainsKey(vs_id)) { var vs_loc_theo_tag = SparkTags.VolSurfaceLocalTheosTag(vs_id); _vs_theo_tags.Add(vs_id, vs_loc_theo_tag); - _bb.add_to_subscription_list(vs_loc_theo_tag); + _bb.subscribe(vs_loc_theo_tag); } _read_theos_and_publish(vs_id); }