/// <summary> /// Обработать сообщение. /// </summary> /// <param name="message">Сообщение.</param> protected override void OnProcessMessage(Message message) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message); return; } var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); NewCandles.SafeInvoke(series, new[] { candle }); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } }
/// <summary> /// Process message. /// </summary> /// <param name="message">Message.</param> protected override void OnProcessMessage(Message message) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message); return; } var series = _series.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); // тиковый ТФ if (candleMsg.TotalVolume == 0) { candle.TotalVolume = (candle.OpenVolume + candle.CloseVolume) ?? 0; candle.HighPrice = candle.OpenPrice.Max(candle.ClosePrice); candle.LowPrice = candle.OpenPrice.Min(candle.ClosePrice); } NewCandles.SafeInvoke(series, new[] { candle }); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } }
/// <summary> /// Process message. /// </summary> /// <param name="message">Message.</param> protected override void OnProcessMessage(Message message) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message); return; } var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); // сообщение с IsFinished = true не содержит данные по свече, // только флаг, что получение исторических данных завершено if (!candleMsg.IsFinished) { NewCandles.SafeInvoke(series, new[] { candle }); } else { _candleSeries.Remove(candleMsg.OriginalTransactionId); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } } }
/// <summary> /// Обработать сообщение, содержащее рыночные данные. /// </summary> /// <param name="message">Сообщение, содержащее рыночные данные.</param> /// <param name="adapterType">Тип адаптера, от которого пришло сообщение.</param> /// <param name="direction">Направление сообщения.</param> protected override void OnProcessMessage(Message message, MessageAdapterTypes adapterType, MessageDirections direction) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message, adapterType, direction); return; } var series = _series.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); // тиковый ТФ if (candleMsg.TotalVolume == 0) { candle.TotalVolume = candle.OpenVolume + candle.CloseVolume; candle.HighPrice = candle.OpenPrice.Max(candle.ClosePrice); candle.LowPrice = candle.OpenPrice.Min(candle.ClosePrice); } NewCandles.SafeInvoke(series, new[] { candle }); }
/// <summary> /// Обработать сообщение. /// </summary> /// <param name="message">Сообщение.</param> protected override void OnProcessMessage(Message message) { switch (message.Type) { case MessageTypes.Connect: if (((ConnectMessage)message).Error == null) { _candlesTimer = this.StartRealTime(_realTimeSeries, RealTimeCandleOffset, (series, range) => RequestCandles(series.Security, (TimeSpan)series.Arg, range.Min, range.Max, _series.TryGetKey(series)), TimeSpan.FromSeconds(3)); } break; case MessageTypes.Disconnect: if (((DisconnectMessage)message).Error == null && _candlesTimer != null) { _candlesTimer.Dispose(); _candlesTimer = null; } break; default: { var candleMsg = message as CandleMessage; if (candleMsg == null) { break; } var series = _series.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); NewCandles.SafeInvoke(series, new[] { candle }); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } return; // base class throws exception } } base.OnProcessMessage(message); }
/// <summary> /// Обработать сообщение. /// </summary> /// <param name="message">Сообщение.</param> protected override void OnProcessMessage(Message message) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message); return; } var series = _series[candleMsg.OriginalTransactionId]; NewCandles.SafeInvoke(series, new[] { candleMsg.ToCandle(series) }); }
/// <summary> /// Обработать сообщение, содержащее рыночные данные. /// </summary> /// <param name="message">Сообщение, содержащее рыночные данные.</param> /// <param name="adapterType">Тип адаптера, от которого пришло сообщение.</param> /// <param name="direction">Направление сообщения.</param> protected override void OnProcessMessage(Message message, MessageAdapterTypes adapterType, MessageDirections direction) { var candleMsg = message as CandleMessage; if (candleMsg == null) { base.OnProcessMessage(message, adapterType, direction); return; } var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); NewCandles.SafeInvoke(series, new[] { candle }); }
/// <summary> /// Process message. /// </summary> /// <param name="message">Message.</param> protected override void OnProcessMessage(Message message) { switch (message.Type) { case MessageTypes.Connect: case MessageTypes.Disconnect: { PulseWaiting(); break; } case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.Error != null) { var candleInfo = _candleInfo.TryGetValue(mdMsg.OriginalTransactionId); if (candleInfo != null) { lock (candleInfo.Second) { candleInfo.Third = true; candleInfo.Second.Pulse(); } _candleInfo.Remove(mdMsg.OriginalTransactionId); } var l1Info = _ticksInfo.TryGetValue(mdMsg.OriginalTransactionId); if (l1Info != null) { lock (l1Info.Second) { l1Info.Third = true; l1Info.Second.Pulse(); } _ticksInfo.Remove(mdMsg.OriginalTransactionId); } } break; } case MessageTypes.CandleTimeFrame: { var candleMsg = (CandleMessage)message; var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); NewCandles.SafeInvoke(series, new[] { candle }); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } var info = _candleInfo.TryGetValue(candleMsg.OriginalTransactionId); if (info != null) { if (candleMsg.IsFinished) { lock (info.Second) { info.Third = true; info.Fifth = true; info.Second.Pulse(); } _candleInfo.Remove(candleMsg.OriginalTransactionId); } else { info.First.Add(candleMsg); } } // DO NOT send historical data to Connector return; } case MessageTypes.Execution: { var execMsg = (ExecutionMessage)message; if (execMsg.ExecutionType == ExecutionTypes.Tick) { var info = _ticksInfo.TryGetValue(execMsg.OriginalTransactionId); // IsFinished = true message do not contains any data, // just mark historical data gathering as finished if (execMsg.GetValue <bool>("IsFinished")) { if (info == null) { this.AddWarningLog(LocalizedStrings.Str2149Params.Put(execMsg.OriginalTransactionId)); return; } lock (info.Second) { info.Third = true; info.Fifth = true; info.Second.Pulse(); } _ticksInfo.Remove(execMsg.OriginalTransactionId); } else { // streaming l1 message (non historical) if (info == null) { break; } info.First.Add(execMsg); } // DO NOT send historical data to Connector return; } break; } } base.OnProcessMessage(message); }
/// <summary> /// Process message. /// </summary> /// <param name="message">Message.</param> protected override void OnProcessMessage(Message message) { switch (message.Type) { case MessageTypes.Connect: case MessageTypes.Disconnect: { PulseWaiting(); break; } case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.Error != null) { var candleInfo = _candleInfo.TryGetValue(mdMsg.OriginalTransactionId); if (candleInfo != null) { lock (candleInfo.Second) { candleInfo.Third = true; candleInfo.Second.Pulse(); } _candleInfo.Remove(mdMsg.OriginalTransactionId); } var l1Info = _level1Info.TryGetValue(mdMsg.OriginalTransactionId); if (l1Info != null) { lock (l1Info.Second) { l1Info.Third = true; l1Info.Second.Pulse(); } _level1Info.Remove(mdMsg.OriginalTransactionId); } } break; } case MessageTypes.CandleRange: case MessageTypes.CandleTick: case MessageTypes.CandleTimeFrame: case MessageTypes.CandleVolume: { var candleMsg = (CandleMessage)message; var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series == null) { return; } var candle = candleMsg.ToCandle(series); // сообщение с IsFinished = true не содержит данные по свече, // только флаг, что получение исторических данных завершено if (!candleMsg.IsFinished) { NewCandles.SafeInvoke(series, new[] { candle }); } else { if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } } var info = _candleInfo.TryGetValue(candleMsg.OriginalTransactionId); if (info != null) { if (candleMsg.IsFinished) { lock (info.Second) { info.Third = true; info.Fifth = true; info.Second.Pulse(); } _candleInfo.Remove(candleMsg.OriginalTransactionId); } else { info.First.Add(candle); } } // DO NOT send historical data to Connector return; } case MessageTypes.Level1Change: { var l1Msg = (Level1ChangeMessage)message; var transactionId = l1Msg.GetRequestId(); var info = _level1Info.TryGetValue(transactionId); // IsFinished = true message do not contains any data, // just mark historical data gathering as finished if (l1Msg.GetValue <bool>("IsFinished")) { if (info == null) { this.AddWarningLog(LocalizedStrings.Str2149Params.Put(transactionId)); return; } lock (info.Second) { info.Third = true; info.Fifth = true; info.Second.Pulse(); } _level1Info.Remove(transactionId); } else { // streaming l1 message (non historical) if (info == null) { break; } info.First.Add((Level1ChangeMessage)l1Msg.Clone()); } // DO NOT send historical data to Connector return; } case ExtendedMessageTypes.System: { var msg = (IQFeedSystemMessage)message; if (msg.Feed.Address == NativeAdapter.LookupAddress) { PulseWaiting(); } return; } } base.OnProcessMessage(message); }
/// <summary> /// Process message. /// </summary> /// <param name="message">Message.</param> protected override void OnProcessMessage(Message message) { switch (message.Type) { case ExtendedMessageTypes.Scanner: { var scannerMsg = (ScannerResultMessage)message; var state = (ScannerFilter)_states[scannerMsg.OriginalTransactionId]; NewScannerResults.SafeInvoke(state, scannerMsg.Results); break; } case ExtendedMessageTypes.ScannerParameters: { var scannerMsg = (ScannerParametersMessage)message; NewScannerParameters.SafeInvoke(scannerMsg.Parameters); break; } case ExtendedMessageTypes.FinancialAdvise: { var adviseMsg = (FinancialAdviseMessage)message; NewFinancialAdvise.SafeInvoke(adviseMsg.AdviseType, adviseMsg.Data); break; } case ExtendedMessageTypes.FundamentalReport: { var reportMsg = (FundamentalReportMessage)message; var state = (Tuple <Security, FundamentalReports>)_states[reportMsg.OriginalTransactionId]; NewFundamentalReport.SafeInvoke(state.Item1, state.Item2, reportMsg.Data); break; } default: { var candleMsg = message as CandleMessage; if (candleMsg == null) { break; } var series = _candleSeries.TryGetValue(candleMsg.OriginalTransactionId); if (series != null) { var candle = candleMsg.ToCandle(series); NewCandles.SafeInvoke(series, new[] { candle }); if (candleMsg.IsFinished) { Stopped.SafeInvoke(series); } } return; } } base.OnProcessMessage(message); }
/// <summary> /// Вызвать событие <see cref="NewCandles"/> /// </summary> /// <param name="candleSeries">Серия свечек.</param> /// <param name="candles">Свечи.</param> protected virtual void RaiseNewCandles(CandleSeries candleSeries, IEnumerable <TimeFrameCandle> candles) { NewCandles.SafeInvoke(candleSeries, candles); }