diff --git a/src/client/spark/Analytics/SupportingData/VolSurfaceNonVolInput.cs b/src/client/spark/Analytics/SupportingData/VolSurfaceNonVolInput.cs index 4b6f4df59..8a9f274ae 100644 --- a/src/client/spark/Analytics/SupportingData/VolSurfaceNonVolInput.cs +++ b/src/client/spark/Analytics/SupportingData/VolSurfaceNonVolInput.cs @@ -63,5 +63,9 @@ namespace mbts.analytics { return get_cpp_list().ToDictionary( t => new mbts.SecurityTuple(t.Item1, t.Item2, Venue.Unset), t => t.Item3); } + + public IDictionary get_roll_map(Func filter) { + return exp_input_map.Where(kv => filter(kv.Key)).ToDictionary(kv => kv.Key, kv => kv.Value.roll_target); + } } } \ No newline at end of file diff --git a/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs b/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs index 87fae250f..f090b6cd6 100644 --- a/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs +++ b/src/client/spark/NMSheets/DataProviders/NMSheetSingleOptionMainDataSource.cs @@ -96,13 +96,13 @@ namespace BCG { if (_is_main_sheet_active()) { HighPerformanceTimer timer = new HighPerformanceTimer(); timer.start(); - NMSheetDataRequest data_request = (NMSheetDataRequest)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_main_sheet_request_tag) ?? new NMSheetDataRequest(new List>()); + NMSheetDataRequest data_request = _threaded_bb.read_state(_in_bb_main_sheet_request_tag) ?? new NMSheetDataRequest(new List>()); data_request = NMSheetDataRequest.restrict_for_symbol(data_request, _nmsheet_symbol); - OptionDriverPriceMap live_driver_map = (OptionDriverPriceMap)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_live_driver_bbo_tag); + OptionDriverPriceMap live_driver_map = _threaded_bb.read_state(_in_bb_live_driver_bbo_tag); IDictionary> sym_presaved_aw2_theos = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_presaved_aw2_theos_tag) as IDictionary>; ExpStrikeKeyedData presaved_aw2_theos = (sym_presaved_aw2_theos != null && sym_presaved_aw2_theos.TryGetValue(_nmsheet_symbol, out presaved_aw2_theos)) ? presaved_aw2_theos : null; - NMSheetSettings sheet_settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_sheet_settings_tag) ?? new NMSheetSettings(); - ExpStrikeKeyedData shared_live_theo_data_map = (ExpStrikeKeyedData)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_live_theos_tag); + NMSheetSettings sheet_settings = _threaded_bb.read_state(_in_bb_sheet_settings_tag) ?? new NMSheetSettings(); + ExpStrikeKeyedData shared_live_theo_data_map = _threaded_bb.read_state(_in_bb_live_theos_tag); if (data_request != null && live_driver_map != null && shared_live_theo_data_map != null) { ExpStrikeKeyedData output_theo_data_map = _limit_to_requested_securities(shared_live_theo_data_map, data_request, sheet_settings); @@ -122,7 +122,7 @@ namespace BCG { _get_position_map(), presaved_aw2_theos, _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_option_driver_detailed_price_tag)/* as IDictionary ?? new Dictionary()*/, - _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_secmap_tag) as ExchangeSecurityMap, + _threaded_bb.read_state(_in_bb_secmap_tag), sheet_settings); timer.stop(); _cb(new Pair(_nmsheet_symbol, theo_data)); @@ -132,8 +132,7 @@ namespace BCG { } private bool _is_main_sheet_active() { - object rv = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_main_sheet_visibility_tag); - return rv == null || (bool)rv; + return _threaded_bb.read_state(_in_bb_main_sheet_visibility_tag, true); } private ExpStrikeKeyedData _limit_to_requested_securities(ExpStrikeKeyedData theo_data, NMSheetDataRequest data_request, NMSheetSettings sheet_settings) { @@ -149,7 +148,7 @@ namespace BCG { private ExpStrikeKeyedData> _attach_sec_keys(ExpStrikeKeyedData theo_map) { theo_map = theo_map ?? new ExpStrikeKeyedData(); - ExchangeSecurityMap sec_map = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_secmap_tag) as ExchangeSecurityMap; + ExchangeSecurityMap sec_map = _threaded_bb.read_state(_in_bb_secmap_tag); if (sec_map != null) return sec_map.attach_sec_keys(theo_map, _electronic_equivelant_symbol, _nmsheet_symbol.option_exchange); else { @@ -210,8 +209,11 @@ namespace BCG { } private IDictionary _get_atm_data(ExpStrikeKeyedData theo_data) { - NMSheetSettings sheet_settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_sheet_settings_tag) ?? new NMSheetSettings(); - IDictionary option_exp_roll_data = (_threaded_bb.sec_thread_retrieve_from_cache(_in_exp_param_tag) as IDictionary) ?? new Dictionary(); + NMSheetSettings sheet_settings = _threaded_bb.read_state(_in_bb_sheet_settings_tag) ?? new NMSheetSettings(); + VolSurfaceNonVolInput vs_nvinp = _threaded_bb.read_state(_in_exp_param_tag); + IDictionary option_exp_roll_data = vs_nvinp != null ? + vs_nvinp.get_roll_map((exp) => exp.symbol == _nmsheet_symbol.option_name).ToDictionary(kv => kv.Key.expiration, kv => kv.Value) : + new Dictionary(); IDictionary atm_data = OptionATMDataSource.compute_atm_data(_nmsheet_symbol.option_name, _get_onefive(), theo_data, option_exp_roll_data); if (sheet_settings.setting_atm.select_atm_nearest_strike_only) foreach (ATMData exp_atm_data in atm_data.Values) @@ -236,12 +238,12 @@ namespace BCG { #region Vol Shift private void _add_vol_shift(ExpStrikeKeyedData theo_data) { - object obj_map = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_vol_shift_tag); - if (obj_map != null) - add_vol_shift(_nmsheet_symbol, theo_data, obj_map as Dictionary); + var vshift_map = _threaded_bb.read_state(_in_bb_vol_shift_tag); + if (vshift_map != null) + add_vol_shift(_nmsheet_symbol, theo_data, vshift_map); } - internal static void add_vol_shift(NMSheetSymbol apply_to_symbol, ExpStrikeKeyedData theo_data, Dictionary exp_shift_map) { + internal static void add_vol_shift(NMSheetSymbol apply_to_symbol, ExpStrikeKeyedData theo_data, IDictionary exp_shift_map) { foreach (KeyValuePair p in exp_shift_map) { if (p.Key.nmsheet_symbol.Equals(apply_to_symbol)) { DateTime option_expiration = p.Key.option_expiration; diff --git a/src/client/spark/NMSheets/NMSheetDataCoalescer.cs b/src/client/spark/NMSheets/NMSheetDataCoalescer.cs index a7055699c..d28a25b54 100644 --- a/src/client/spark/NMSheets/NMSheetDataCoalescer.cs +++ b/src/client/spark/NMSheets/NMSheetDataCoalescer.cs @@ -47,7 +47,7 @@ namespace BCG { TaskingConsolidatedData d = null;//_threaded_bb.sec_thread_retrieve_from_cache (TaskingTags.ConsolidatedDataTag) as TaskingConsolidatedData; NMSheetData rv = new NMSheetData(_main_data_source.get_data(), _bbo_data_source.get_all_data(), _ticker_data_source.get_data(), d ?? TaskingConsolidatedData.empty); - rv = _filter_data(rv, _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_settings_tag) as NMSheetSettings); + rv = _filter_data(rv, _threaded_bb.read_state(_in_bb_settings_tag)); _timer.stop(); _stats_logger.log(String.Format("NMSheetDataCoalescer_{0}", _req_id), "NMSheetData.cons", _timer.lastIntervalTime); return rv; diff --git a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs index 8148c8786..fc888cd4d 100644 --- a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs +++ b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderControl/NMSheetExpirationHeaderControlStrip.cs @@ -24,7 +24,7 @@ namespace BCG { /// should corresponds to the expiration list in the theos public partial class NMSheetExpirationHeaderControlStrip : UserControl { private SortedList _vol_controls = new SortedList(); - private readonly ITag _in_bb_nmsheet_viewable_area_tag; + private readonly ITag _in_bb_nmsheet_viewable_area_tag; private readonly ITag _in_bb_nmsheet_settings_tag; private readonly ITag> _out_bb_vol_shift_tag; private ThreadedBlackboard _threaded_bb; @@ -40,7 +40,7 @@ namespace BCG { BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; BackColor = Color.Transparent; _in_bb_nmsheet_settings_tag = SparkTags.TC2Tags.NMSheetSettingsTag(req_id.ToString()); - _in_bb_nmsheet_viewable_area_tag = SparkTags.TC2Tags.NMSheetVisibilityTag(req_id.ToString()); + _in_bb_nmsheet_viewable_area_tag = SparkTags.TC2Tags.NMSheetViewableAreaTag(req_id.ToString()); _out_bb_vol_shift_tag = SparkTags.TC2Tags.VolShiftTag(req_id.ToString()); _threaded_bb = threaded_bb; _scroll_to_atm_cb = scroll_to_atm_cb; @@ -52,20 +52,20 @@ namespace BCG { private void _react_to_bb(object tag, object value) { if (_in_bb_nmsheet_viewable_area_tag.Equals(tag)) - _reallign_controls(this, _vol_controls.Values, _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_viewable_area_tag) as double[]); + _reallign_controls(this, _vol_controls.Values, _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag)); else if (_in_bb_nmsheet_settings_tag.Equals(tag)) _handle_setting_changes(); } private void _handle_setting_changes() { - NMSheetSettings settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); + NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); _set_ui_properties(_vol_controls.Values, settings); } public void set_header_data(IDictionary header_data) { _timer.start(); _header_data = header_data; - NMSheetSettings settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); + NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); bool control_list_modified = false; foreach (KeyValuePair p in _header_data) { NMSheetExpiration nmsheet_exp = p.Key; @@ -92,7 +92,7 @@ namespace BCG { } } if (control_list_modified) { - _reallign_controls(this, _vol_controls.Values, _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_viewable_area_tag) as double[]); + _reallign_controls(this, _vol_controls.Values, _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag)); _publish_vol_shift_data(); } _timer.stop(); diff --git a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs index cbdb9648b..72ce0ee28 100644 --- a/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs +++ b/src/client/spark/NMSheets/UIComponents/ExpirationHeaderDriverControl/NMSheetDriverControlStrip.cs @@ -39,7 +39,7 @@ namespace BCG { private ThreadedBlackboard _threaded_bb; private readonly ITag _in_bb_nmsheet_settings_tag; - private readonly ITag _in_bb_nmsheet_viewable_area_tag; + private readonly ITag _in_bb_nmsheet_viewable_area_tag; private readonly ITag _in_contract_data_tag = SparkTags.SystemContractsTag; private readonly ITag _out_bb_theo_request_tag; private readonly List _nmsheet_symbol_list; @@ -56,7 +56,7 @@ namespace BCG { _threaded_bb = threaded_bb; _nmsheet_symbol_list = nmsheet_symbol_list; _in_bb_nmsheet_settings_tag = SparkTags.TC2Tags.NMSheetSettingsTag(req_id.ToString()); - _in_bb_nmsheet_viewable_area_tag = SparkTags.TC2Tags.NMSheetVisibilityTag(req_id.ToString()); + _in_bb_nmsheet_viewable_area_tag = SparkTags.TC2Tags.NMSheetViewableAreaTag(req_id.ToString()); _out_bb_theo_request_tag = SparkTags.TC2Tags.NMSheetDataRequestTag(req_id.ToString()); _threaded_bb.data_callback += _react_to_bb; @@ -76,7 +76,7 @@ namespace BCG { } private void _handle_setting_changes() { - NMSheetSettings settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); + NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); _set_ui_properties(_price_controls.Values, settings); _send_new_theo_request(); } @@ -86,7 +86,7 @@ namespace BCG { } private void _handle_grid_changes() { - double[] coords = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_viewable_area_tag) as double[]; + double[] coords = _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag); if (coords != null && coords.Length > 0) { if (_grid_coords == null || _grid_coords[0] != coords[0] || _grid_coords[4] != coords[4]) { _grid_coords = coords; @@ -101,8 +101,8 @@ namespace BCG { /// 3. When a price is frozen/unfrozen private void _send_new_theo_request() { /// requests are always based on settings - NMSheetSettings settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); - mbts.spark.SystemContractData contract_data = _threaded_bb.sec_thread_retrieve_from_cache(_in_contract_data_tag) as mbts.spark.SystemContractData ?? mbts.spark.SystemContractData.empty; + NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); + mbts.spark.SystemContractData contract_data = _threaded_bb.read_state(_in_contract_data_tag) ?? mbts.spark.SystemContractData.empty; List selected_nmsheet_exp_list = NMSheetExpirationMapper.filter_expirations(contract_data, _nmsheet_symbol_list, settings.setting_unselected_expirations); List> req_list = new List>(); foreach (NMSheetExpiration nm_exp in selected_nmsheet_exp_list) { @@ -126,7 +126,7 @@ namespace BCG { private void _handle_sheet_theo_data(NMSheetData nmsheet_data) { _timer.start(); bool control_list_modified = false; - NMSheetSettings settings = (NMSheetSettings)_threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); + NMSheetSettings settings = _threaded_bb.read_state(_in_bb_nmsheet_settings_tag) ?? new NMSheetSettings(); if (nmsheet_data != null) { IDictionary driver_data_map = nmsheet_data.get_driver_data(); foreach (KeyValuePair driver_data_map_elem in driver_data_map) { @@ -157,7 +157,7 @@ namespace BCG { } } if (control_list_modified) { - _reallign_controls(_price_controls, _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_nmsheet_viewable_area_tag) as double[]); + _reallign_controls(_price_controls, _threaded_bb.read_state(_in_bb_nmsheet_viewable_area_tag)); } _timer.stop(); _logger.log(_log_id, "NMSheetDriverControlStrip._handle_sheet_data", _timer.lastIntervalTime); diff --git a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs index 67f5746a2..8b38219be 100644 --- a/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs +++ b/src/client/spark/NMSheets/UIComponents/MainSheet/NMSheetControl.cs @@ -359,7 +359,7 @@ namespace BCG { #endregion private void _launch_setting_form(object args = null) { - mbts.spark.SystemContractData contract_data = _threaded_bb.sec_thread_retrieve_from_cache(_in_bb_contract_data_tag) as mbts.spark.SystemContractData ?? mbts.spark.SystemContractData.empty; + SystemContractData contract_data = _threaded_bb.read_state(_in_bb_contract_data_tag, SystemContractData.empty); System.Windows.Threading.Dispatcher ui_thread_dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; Action settings_form_cb = (new_settings) => { ui_thread_dispatcher.InvokeAsync(() => { _set_new_settings(new_settings); }); }; System.Windows.Application.Current.Dispatcher.InvokeAsync(() => {