private void subscribeToLiveInstrument(LiveInstrument inst_, bool do_ = true)
    {
      if (inst_ == null)
        return;

      inst_.ChangeChanged -= handleLiveInstrumentChanged;

      if (!do_) return;

      inst_.ChangeChanged += handleLiveInstrumentChanged;
    }
 public void Dispose()
 {
   subscribeToLiveInstrument(m_liveInstrument, false);
   m_liveInstrument = null;
 }
 internal async Task Start(CarbonClient cc_)
 {
   m_liveInstrument = await LiveInstrument.Get(m_exposureId, cc_);
   subscribeToLiveInstrument(m_liveInstrument);
   OnPnlUpdated(new ValueUpdatedEventArgs<double>(Pnl));
 }
    public static async Task<LiveInstrument> Get(string exposureName_, CarbonClient cc_)
    {
      if (_cache.ContainsKey(exposureName_))
        return _cache[exposureName_];

      var ticker = await BbgTickers.GetLiveTicker(exposureName_, cc_);

      if (string.IsNullOrEmpty(ticker))
      {
        Logger.Error(string.Format("Could not determine ticker for [{0}]", exposureName_), typeof(LiveInstrument));
        _cache[exposureName_] = null;
        return null;
      }

      //var year2 = DateTime.Today.Year % 100;
      //var year1 = DateTime.Today.Year % 10;
      //ticker = ticker.Replace(year2.ToString("00"), year1.ToString("0"));

      double convention = 1d;
      var method = PnlMethod.Geometric;

      var secMaster = await SecMasters.Get(exposureName_, cc_);
      {
        if (secMaster == null)
        {
          Logger.Info(string.Format("Could not find secmaster for {0}.  Assuming it's not inverted...", exposureName_),
            typeof (LiveInstrument));
        }
        else
        {
          convention = secMaster.Invert ? -1d : 1d;
          method = secMaster.Method;
        }
      }

      var instance = new LiveInstrument(exposureName_)
      {
        m_convention = convention,
        m_method=method
      };

      // if the pricing method is 'swap' then 
      if (instance.m_method == PnlMethod.Swap )
      {
        var rd = BbgTalk.HistoryRequester.GetReferenceData(ticker, "DUR_ADJ_MID", null);
        if (rd != null && rd.AllResult.Count > 0)
          instance.m_mult = rd.GetValue<double>("DUR_ADJ_MID");
      }
      else if (instance.m_method == PnlMethod.Credit)
      {
        var rd = BbgTalk.HistoryRequester.GetReferenceData(ticker, new[] {"SW_CNV_BPV", "SW_REC_NOTL_AMT"}, null);

        if (rd != null && rd.AllResult.Count == 2)
        {
          instance.m_mult = rd.GetValue<double>("SW_CNV_BPV")/rd.GetValue<double>("SW_REC_NOTL_AMT");
        }
      }

      await instance.ReadFix(cc_);
      instance.subscribeToThis(BbgTalk.Core.Instance.GetLiveSecurity(ticker, new[] { LIVE_FIELD }.ToList(), 3d));

      _cache[exposureName_] = instance;

      return instance;
    }