/// <summary> /// 連結即時報價資訊源 /// </summary> public void ConnectQuoteServer() { if (this.Bars != null) { string sDataSource = this.Bars.Request.DataFeed; AbstractQuoteService cService = QuoteManager.Manager.GetQuoteService(sDataSource); if (cService != null && cService != __cQuoteService) { __cQuoteService = cService; __cQuoteService.AddSubscribe(this.Bars.Request.Symbol); __cQuoteService.onQuote += QuoteService_onQuote; __cQuoteService.onQuoteDateTime += QuoteService_onQuoteDateTime; } } }
private void Complement(InstrumentDataRequest request, int millisecondsTimeout) { string sDataSource = request.DataFeed; if (__cDataSources.Contains(sDataSource)) { AbstractQuoteService cService = QuoteManager.Manager.GetQuoteService(sDataSource); if (cService != null) { string sSymbolId = request.Symbol; IQuote cQuote = cService.Storage.GetQuote(sSymbolId); if (cQuote != null && cQuote.ComplementStatus != ComplementStatus.Complemented) { EventWaitHandle cWaitHandle = null; lock (__cAsyncArgs) { _AsyncEventArgs cArgs = null; string sHashKey = string.Format("{0}_{1}", sDataSource, sSymbolId); if (__cAsyncArgs.TryGetValue(sHashKey, out cArgs)) { cWaitHandle = cArgs.handle; } else { if (cQuote.ComplementStatus == ComplementStatus.NotComplement) { cArgs = new _AsyncEventArgs(); cArgs.request = request; cWaitHandle = new ManualResetEvent(false); cArgs.handle = cWaitHandle; __cAsyncArgs.Add(sHashKey, cArgs); cService.AddSubscribe(sSymbolId); cService.Complement(sSymbolId); } } } if (cWaitHandle != null) { if (!cWaitHandle.WaitOne(millisecondsTimeout)) { //等待回補資訊(如果 millisecondsTimeout 為 -1 則會無限等待, 如果有設定 Timeout 在時間到了之後還沒回補完畢就直接釋放 WaitHandle 元件並移除) cWaitHandle.Dispose(); string sHashKey = string.Format("{0}_{1}", sDataSource, sSymbolId); lock (__cAsyncArgs) { __cAsyncArgs.Remove(sHashKey); } } } } } } }