private IEnumerableEx <QuoteChangeMessage> GetDepths() { int maxDepth; if (!int.TryParse(Depth.Text, out maxDepth)) { maxDepth = int.MaxValue; } if (maxDepth <= 0) { maxDepth = 1; } var interval = TimeSpan.FromMilliseconds(DepthGenerationInterval.Value ?? 0); switch (BuildFrom.SelectedIndex) { case 0: { var retVal = StorageRegistry .GetQuoteMessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); return(retVal .Select(md => { md.Bids = md.Bids.Take(maxDepth).ToArray(); md.Asks = md.Asks.Take(maxDepth).ToArray(); return md; }) .WhereWithPrevious((prev, curr) => (curr.ServerTime - prev.ServerTime) >= interval) .ToEx(retVal.Count)); } case 1: { return(StorageRegistry .GetOrderLogMessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From + new TimeSpan(18, 45, 0), To + TimeHelper.LessOneDay + new TimeSpan(18, 45, 0)) // TODO .ToMarketDepths(OrderLogBuilders.Plaza2.CreateBuilder(SelectedSecurity.ToSecurityId()), interval, maxDepth)); } case 2: { var level1 = StorageRegistry .GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); return(level1.ToOrderBooks()); } default: throw new InvalidOperationException(); } }
private IEnumerableEx <CandleMessage> GetCandles() { var from = From.Value; var to = To.Value.EndOfDay(); switch (BuildFrom.SelectedIndex) { case 0: return(StorageRegistry .GetCandleMessageStorage(CandleSeries.CandleType.ToCandleMessageType(), CandleSeries.Security, CandleSeries.Arg, Drive, StorageFormat) .Load(from, to)); case 1: return(StorageRegistry .GetExecutionStorage(SelectedSecurity, ExecutionTypes.Tick, Drive, StorageFormat) .Load(from, to) .ToCandles(CandleSeries)); case 2: return(StorageRegistry .GetExecutionStorage(SelectedSecurity, ExecutionTypes.OrderLog, Drive, StorageFormat) .Load(from, to) .ToTicks() .ToCandles(CandleSeries)); case 3: return(StorageRegistry .GetQuoteMessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(from, to) .ToCandles(CandleSeries)); case 4: return(StorageRegistry .GetExecutionStorage(SelectedSecurity, ExecutionTypes.OrderLog, Drive, StorageFormat) .Load(from, to) .ToMarketDepths(OrderLogBuilders.Plaza2.CreateBuilder(SelectedSecurity.ToSecurityId())) .ToCandles(CandleSeries)); case 5: return(StorageRegistry .GetCandleMessageStorage(typeof(TimeFrameCandleMessage), SelectedSecurity, TimeSpan.FromMinutes(1), Drive, StorageFormat) .Load(from, to) .ToTrades(SelectedSecurity.VolumeStep ?? 1m) .ToCandles(CandleSeries)); case 6: return(StorageRegistry .GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(from, to) .ToTicks() .ToCandles(CandleSeries)); default: throw new InvalidOperationException(LocalizedStrings.Str2874Params.Put(BuildFrom.SelectedIndex)); } }
private IEnumerableEx <Level1ChangeMessage> GetMessages() { var types = new HashSet <Level1Fields>(Level1FieldsCtrl.SelectedFields); var messages = StorageRegistry .GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); return(messages .Where(m => types.IsSupersetOf(m.Changes.Keys)) .ToEx(messages.Count)); }
private IEnumerableEx <ExecutionMessage> GetTrades() { switch (BuildFrom.SelectedIndex) { case 0: { var trades = StorageRegistry .GetExecutionStorage(SelectedSecurity, ExecutionTypes.Tick, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); if (IsNonSystem.IsChecked == false) { trades = trades.Where(t => t.IsSystem != false).ToEx(trades.Count); } return(trades); } case 1: { var orderLog = StorageRegistry .GetExecutionStorage(SelectedSecurity, ExecutionTypes.OrderLog, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); if (IsNonSystem.IsChecked == false) { orderLog = orderLog.Where(i => i.IsSystem != false).ToEx(orderLog.Count); } return(orderLog.ToTicks()); } case 2: { var level1 = StorageRegistry .GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); return(level1.ToTicks()); } default: throw new InvalidOperationException(); } }
private IEnumerableEx <Level1ChangeMessage> GetMessages() { var excludedTypes = Enumerator .GetValues <Level1Fields>() .Except(Level1FieldsCtrl.SelectedFields) .ToArray(); var messages = StorageRegistry .GetLevel1MessageStorage(SelectedSecurity, Drive, StorageFormat) .Load(From, To + TimeHelper.LessOneDay); return(messages .Select(m => { excludedTypes.ForEach(t => m.Changes.Remove(t)); return m; }) .Where(m => m.Changes.Any()) .ToEx(messages.Count)); }
protected override TimeSpan OnProcess() { var allSecurity = this.GetAllSecurity(); // если фильтр по инструментам выключен (выбран инструмент все инструменты) IEnumerable <HydraTaskSecurity> selectedSecurities = (allSecurity != null ? this.ToHydraSecurities(EntityRegistry.Securities.Filter(ExchangeBoard.MBTrading)) : Settings.Securities ).ToArray(); var source = CreateSource(); if (_settings.UseTemporaryFiles != TempFiles.NotUse) { source.DumpFolder = GetTempPath(); } if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2289); source.Refresh(EntityRegistry.Securities, new Security(), SaveSecurity, () => !CanProcess(false)); selectedSecurities = this.ToHydraSecurities(EntityRegistry.Securities.Filter(ExchangeBoard.MBTrading)); } if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2292); return(TimeSpan.MaxValue); } var startDate = _settings.StartFrom; var endDate = DateTime.Today - TimeSpan.FromDays(_settings.DayOffset); var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray(); foreach (var security in selectedSecurities) { if (!CanProcess()) { break; } if ((allSecurity ?? security).MarketDataTypesSet.Contains(typeof(Level1ChangeMessage))) { var storage = StorageRegistry.GetLevel1MessageStorage(security.Security, _settings.Drive, _settings.StorageFormat); var emptyDates = allDates.Except(storage.Dates).ToArray(); if (emptyDates.IsEmpty()) { this.AddInfoLog(LocalizedStrings.Str2293Params, security.Security.Id); } else { var secId = security.Security.ToSecurityId(); foreach (var emptyDate in emptyDates) { if (!CanProcess()) { break; } try { this.AddInfoLog(LocalizedStrings.Str2294Params, emptyDate, security.Security.Id); var ticks = source.LoadTickMessages(secId, emptyDate, emptyDate); if (ticks.Any()) { SaveLevel1Changes(security, ticks); } else { this.AddDebugLog(LocalizedStrings.NoData); } if (_settings.UseTemporaryFiles == TempFiles.UseAndDelete) { File.Delete(source.GetDumpFile(security.Security, emptyDate, emptyDate, typeof(Level1ChangeMessage), null)); } } catch (Exception ex) { HandleError(new InvalidOperationException(LocalizedStrings.Str2295Params .Put(emptyDate, security.Security.Id), ex)); } } } } else { this.AddDebugLog(LocalizedStrings.MarketDataNotEnabled, security.Security.Id, typeof(Level1ChangeMessage).Name); } if (!CanProcess()) { break; } } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); } return(base.OnProcess()); }
private void ProcessMarketDataMessage(MarketDataMessage message) { var securityId = message.SecurityId; var security = SecurityProvider.LookupById(securityId.ToStringId()); if (security == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str704Params.Put(securityId))); return; } if (StorageRegistry == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str1117Params.Put(message.DataType, securityId))); return; } var history = message as HistorySourceMessage; var storages = BasketStorage.InnerStorages; Exception error = null; switch (message.DataType) { case MarketDataTypes.Level1: { if (message.IsSubscribe) { if (history == null) { storages.Add(StorageRegistry.GetLevel1MessageStorage(security, Drive, StorageFormat)); storages.Add(new InMemoryMarketDataStorage <ClearingMessage>(security, null, date => new[] { new ClearingMessage { LocalTime = date.Date + security.Board.ExpiryTime, SecurityId = securityId, ClearMarketDepth = true } })); } else { storages.Add(new InMemoryMarketDataStorage <Level1ChangeMessage>(security, null, history.GetMessages)); } } else { RemoveStorage <IMarketDataStorage <Level1ChangeMessage> >(security, MessageTypes.Level1Change, null); RemoveStorage <InMemoryMarketDataStorage <ClearingMessage> >(security, ExtendedMessageTypes.Clearing, null); } break; } case MarketDataTypes.MarketDepth: { if (message.IsSubscribe) { if (history == null) { storages.Add((IMarketDataStorage <QuoteChangeMessage>)StorageRegistry.GetMarketDepthStorage(security, Drive, StorageFormat)); } else { storages.Add(new InMemoryMarketDataStorage <QuoteChangeMessage>(security, null, history.GetMessages)); } } else { RemoveStorage <IMarketDataStorage <QuoteChangeMessage> >(security, MessageTypes.QuoteChange, null); } break; } case MarketDataTypes.Trades: { if (message.IsSubscribe) { if (history == null) { storages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetTradeStorage(security, Drive, StorageFormat)); } else { storages.Add(new InMemoryMarketDataStorage <ExecutionMessage>(security, null, history.GetMessages)); } } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, ExecutionTypes.Tick); } break; } case MarketDataTypes.OrderLog: { if (message.IsSubscribe) { if (history == null) { storages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetOrderLogStorage(security, Drive, StorageFormat)); } else { storages.Add(new InMemoryMarketDataStorage <ExecutionMessage>(security, null, history.GetMessages)); } } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, ExecutionTypes.OrderLog); } break; } case MarketDataTypes.CandleTimeFrame: case MarketDataTypes.CandleTick: case MarketDataTypes.CandleVolume: case MarketDataTypes.CandleRange: case MarketDataTypes.CandlePnF: case MarketDataTypes.CandleRenko: { var msgType = message.DataType.ToCandleMessageType(); if (message.IsSubscribe) { var candleType = message.DataType.ToCandleMessage(); if (history == null) { storages.Add(StorageRegistry.GetCandleMessageStorage(candleType, security, message.Arg, Drive, StorageFormat)); } else { storages.Add(new InMemoryMarketDataStorage <CandleMessage>(security, message.Arg, history.GetMessages, candleType)); } } else { RemoveStorage <IMarketDataStorage <CandleMessage> >(security, msgType, message.Arg); } break; } default: error = new InvalidOperationException(LocalizedStrings.Str1118Params.Put(message.DataType)); break; } RaiseMarketDataMessage(message, error); }
protected override TimeSpan OnProcess() { // если фильтр по инструментам выключен (выбран инструмент все инструменты) if (this.GetAllSecurity() != null) { //throw new InvalidOperationException("Источник не поддерживает закачку данных по всем инструментам."); this.AddWarningLog(LocalizedStrings.Str2292); return(TimeSpan.MaxValue); } var source = new OandaHistorySource(); var startDate = _settings.StartFrom; var endDate = DateTime.Today - TimeSpan.FromDays(_settings.Offset); var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray(); foreach (var security in GetWorkingSecurities()) { if (!CanProcess()) { break; } if (!security.MarketDataTypesSet.Contains(typeof(Level1ChangeMessage))) { this.AddDebugLog(LocalizedStrings.MarketDataNotEnabled, security.Security.Id, typeof(Level1ChangeMessage).Name); break; } var storage = StorageRegistry.GetLevel1MessageStorage(security.Security, _settings.Drive, _settings.StorageFormat); var emptyDates = allDates.Except(storage.Dates).ToArray(); foreach (var emptyDate in emptyDates) { if (!CanProcess()) { break; } try { this.AddInfoLog(LocalizedStrings.Str3838Params, emptyDate, security.Security.Id); var rates = source.LoadRates(security.Security, emptyDate, emptyDate); if (rates.Any()) { SaveLevel1Changes(security, rates); } else { this.AddDebugLog(LocalizedStrings.NoData); } } catch (Exception ex) { HandleError(new InvalidOperationException(LocalizedStrings.Str3839Params .Put(emptyDate, security.Security.Id), ex)); } } } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); } return(base.OnProcess()); }
protected override TimeSpan OnProcess() { var hasSecurities = false; this.AddInfoLog(LocalizedStrings.Str2306Params.Put(_settings.StartFrom)); foreach (var s in GetWorkingSecurities()) { var security = s.Security; hasSecurities = true; if (!CanProcess()) { break; } //this.AddInfoLog("Обработка инструмента {0}. Конвертация {1}.".Put(security.Security.Id, mode)); IMarketDataStorage fromStorage; IMarketDataStorage toStorage; switch (_settings.ConvertMode) { case ConvertModes.OrderLogToTicks: fromStorage = StorageRegistry.GetOrderLogMessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetTickMessageStorage(security, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.OrderLogToOrderBooks: fromStorage = StorageRegistry.GetOrderLogMessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetQuoteMessageStorage(security, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.OrderLogToCandles: fromStorage = StorageRegistry.GetOrderLogMessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetCandleMessageStorage(_settings.CandleSettings.CandleType.ToCandleMessageType(), security, _settings.CandleSettings.Arg, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.TicksToCandles: fromStorage = StorageRegistry.GetTickMessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetCandleMessageStorage(_settings.CandleSettings.CandleType.ToCandleMessageType(), security, _settings.CandleSettings.Arg, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.OrderBooksToCandles: fromStorage = StorageRegistry.GetQuoteMessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetCandleMessageStorage(_settings.CandleSettings.CandleType.ToCandleMessageType(), security, _settings.CandleSettings.Arg, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.Level1ToTicks: fromStorage = StorageRegistry.GetLevel1MessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetTickMessageStorage(security, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.Level1ToCandles: fromStorage = StorageRegistry.GetLevel1MessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetCandleMessageStorage(_settings.CandleSettings.CandleType.ToCandleMessageType(), security, _settings.CandleSettings.Arg, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; case ConvertModes.Level1ToOrderBooks: fromStorage = StorageRegistry.GetLevel1MessageStorage(security, _settings.Drive, _settings.StorageFormat); toStorage = StorageRegistry.GetQuoteMessageStorage(security, _settings.DestinationDrive, _settings.DestinationStorageFormat); break; default: throw new ArgumentOutOfRangeException(); } var from = fromStorage.GetFromDate(); var to = fromStorage.GetToDate(); if (from == null || to == null) { //this.AddInfoLog("Нет данных для конвертации."); continue; } from = _settings.StartFrom.Max(from.Value); to = (DateTime.Today - TimeSpan.FromDays(_settings.Offset)).Min(to.Value); foreach (var date in from.Value.Range(to.Value, TimeSpan.FromDays(1)).Except(toStorage.Dates)) { if (!CanProcess()) { break; } this.AddInfoLog(LocalizedStrings.Str3786Params.Put(security.Id, _settings.ConvertMode, date)); try { switch (_settings.ConvertMode) { case ConvertModes.OrderLogToTicks: { var ticks = ((IMarketDataStorage <ExecutionMessage>)fromStorage) .Load(date) .ToTicks(); toStorage.Save(ticks); RaiseDataLoaded(security, typeof(ExecutionMessage), ExecutionTypes.Tick, date, ticks.Count); break; } case ConvertModes.OrderLogToOrderBooks: { var depths = ((IMarketDataStorage <ExecutionMessage>)fromStorage) .Load(date) .ToMarketDepths(_settings.MarketDepthBuilder.CreateBuilder(security.ToSecurityId()), _settings.MarketDepthInterval, _settings.MarketDepthMaxDepth); toStorage.Save(depths); RaiseDataLoaded(security, typeof(QuoteChangeMessage), null, date, depths.Count); break; } case ConvertModes.OrderLogToCandles: { var candles = ((IMarketDataStorage <ExecutionMessage>)fromStorage) .Load(date) .ToTicks() .ToCandles(new CandleSeries(_settings.CandleSettings.CandleType, security, _settings.CandleSettings.Arg)); toStorage.Save(candles); RaiseDataLoaded(security, _settings.CandleSettings.CandleType, _settings.CandleSettings.Arg, date, candles.Count); break; } case ConvertModes.TicksToCandles: { var candles = ((IMarketDataStorage <ExecutionMessage>)fromStorage) .Load(date) .ToCandles(new CandleSeries(_settings.CandleSettings.CandleType, security, _settings.CandleSettings.Arg)); toStorage.Save(candles); RaiseDataLoaded(security, _settings.CandleSettings.CandleType, _settings.CandleSettings.Arg, date, candles.Count); break; } case ConvertModes.OrderBooksToCandles: { var candles = ((IMarketDataStorage <QuoteChangeMessage>)fromStorage) .Load(date) .ToCandles(new CandleSeries(_settings.CandleSettings.CandleType, security, _settings.CandleSettings.Arg)); toStorage.Save(candles); RaiseDataLoaded(security, _settings.CandleSettings.CandleType, _settings.CandleSettings.Arg, date, candles.Count); break; } case ConvertModes.Level1ToTicks: { var ticks = ((IMarketDataStorage <Level1ChangeMessage>)fromStorage) .Load(date) .ToTicks(); toStorage.Save(ticks); RaiseDataLoaded(security, typeof(ExecutionMessage), ExecutionTypes.Tick, date, ticks.Count); break; } case ConvertModes.Level1ToCandles: { var candles = ((IMarketDataStorage <Level1ChangeMessage>)fromStorage) .Load(date) .ToTicks() .ToCandles(new CandleSeries(_settings.CandleSettings.CandleType, security, _settings.CandleSettings.Arg)); toStorage.Save(candles); RaiseDataLoaded(security, _settings.CandleSettings.CandleType, _settings.CandleSettings.Arg, date, candles.Count); break; } case ConvertModes.Level1ToOrderBooks: { var orderBooks = ((IMarketDataStorage <Level1ChangeMessage>)fromStorage) .Load(date) .ToOrderBooks(); toStorage.Save(orderBooks); RaiseDataLoaded(security, typeof(QuoteChangeMessage), null, date, orderBooks.Count); break; } default: throw new ArgumentOutOfRangeException(); } } catch (Exception ex) { HandleError(ex); } } } if (!hasSecurities) { this.AddWarningLog(LocalizedStrings.Str2292); return(TimeSpan.MaxValue); } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); } return(base.OnProcess()); }
private void ProcessMarketDataMessage(MarketDataMessage message) { var security = _sessionHolder.SecurityProvider.LookupById(message.SecurityId.SecurityCode + "@" + message.SecurityId.BoardCode); if (security == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str704Params.Put(message.SecurityId))); return; } if (TryGetGenerator(message) != null) { RaiseMarketDataMessage(message, null); return; } if (StorageRegistry == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str1117Params.Put(message.DataType, message.SecurityId))); return; } Exception error = null; switch (message.DataType) { case MarketDataTypes.Level1: { if (message.IsSubscribe) { _basketStorage.InnerStorages.Add(StorageRegistry.GetLevel1MessageStorage(security, Drive, StorageFormat)); _basketStorage.InnerStorages.Add(new InMemoryMarketDataStorage <ClearingMessage>(date => new[] { new ClearingMessage { LocalTime = date.Date + security.Board.ExpiryTime, SecurityId = message.SecurityId, ClearMarketDepth = true } })); } else { RemoveStorage <IMarketDataStorage <Level1ChangeMessage> >(security, MessageTypes.Level1Change, message.Arg); RemoveStorage <InMemoryMarketDataStorage <ClearingMessage> >(security, ExtendedMessageTypes.Clearing, message.Arg); } break; } case MarketDataTypes.MarketDepth: { if (message.IsSubscribe) { _basketStorage.InnerStorages.Add((IMarketDataStorage <QuoteChangeMessage>)StorageRegistry.GetMarketDepthStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <QuoteChangeMessage> >(security, MessageTypes.QuoteChange, message.Arg); } break; } case MarketDataTypes.Trades: { if (message.IsSubscribe) { _basketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetTradeStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.OrderLog: { if (message.IsSubscribe) { //var msg = "OrderLog".ValidateLicense(); //if (msg == null) _basketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetOrderLogStorage(security, Drive, StorageFormat)); //else // SessionHolder.AddErrorLog(msg); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.CandleTimeFrame: case MarketDataTypes.CandleTick: case MarketDataTypes.CandleVolume: case MarketDataTypes.CandleRange: case MarketDataTypes.CandlePnF: case MarketDataTypes.CandleRenko: { Type candleMessageType; MessageTypes msgType; switch (message.DataType) { case MarketDataTypes.CandleTimeFrame: msgType = MessageTypes.CandleTimeFrame; candleMessageType = typeof(TimeFrameCandleMessage); break; case MarketDataTypes.CandleTick: msgType = MessageTypes.CandleTick; candleMessageType = typeof(TickCandleMessage); break; case MarketDataTypes.CandleVolume: msgType = MessageTypes.CandleVolume; candleMessageType = typeof(VolumeCandleMessage); break; case MarketDataTypes.CandleRange: msgType = MessageTypes.CandleRange; candleMessageType = typeof(RangeCandleMessage); break; case MarketDataTypes.CandlePnF: msgType = MessageTypes.CandlePnF; candleMessageType = typeof(PnFCandleMessage); break; case MarketDataTypes.CandleRenko: msgType = MessageTypes.CandleRenko; candleMessageType = typeof(RenkoCandleMessage); break; default: throw new InvalidOperationException(); } if (message.IsSubscribe) { _basketStorage.InnerStorages.Add(StorageRegistry.GetCandleMessageStorage(candleMessageType, security, message.Arg, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <CandleMessage> >(security, msgType, message.Arg); } break; } default: error = new InvalidOperationException(LocalizedStrings.Str1118Params.Put(message.DataType)); break; } RaiseMarketDataMessage(message, error); }
private void ProcessMarketDataMessage(MarketDataMessage message) { var generatorMessage = message as GeneratorMarketDataMessage; if (generatorMessage != null) { if (generatorMessage.Generator == null) { throw new ArgumentException("message"); } var tradeGen = generatorMessage.Generator as TradeGenerator; if (tradeGen != null) { if (generatorMessage.IsSubscribe) { _tradeGenerators.Add(generatorMessage.SecurityId, tradeGen); } else { _tradeGenerators.Remove(generatorMessage.SecurityId); } } else { var depthGen = generatorMessage.Generator as MarketDepthGenerator; if (depthGen != null) { if (generatorMessage.IsSubscribe) { _depthGenerators.Add(generatorMessage.SecurityId, depthGen); } else { _depthGenerators.Remove(generatorMessage.SecurityId); } } else { var olGen = generatorMessage.Generator as OrderLogGenerator; if (olGen != null) { if (generatorMessage.IsSubscribe) { _orderLogGenerators.Add(generatorMessage.SecurityId, olGen); } else { _orderLogGenerators.Remove(generatorMessage.SecurityId); } } else { throw new InvalidOperationException(); } } } return; } var security = SecurityProvider.LookupById(message.SecurityId.SecurityCode + "@" + message.SecurityId.BoardCode); if (security == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str704Params.Put(message.SecurityId))); return; } if (TryGetGenerator(message) != null) { RaiseMarketDataMessage(message, null); return; } if (StorageRegistry == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str1117Params.Put(message.DataType, message.SecurityId))); return; } Exception error = null; switch (message.DataType) { case MarketDataTypes.Level1: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add(StorageRegistry.GetLevel1MessageStorage(security, Drive, StorageFormat)); BasketStorage.InnerStorages.Add(new InMemoryMarketDataStorage <ClearingMessage>(date => new[] { new ClearingMessage { LocalTime = date.Date + security.Board.ExpiryTime, SecurityId = message.SecurityId, ClearMarketDepth = true } })); } else { RemoveStorage <IMarketDataStorage <Level1ChangeMessage> >(security, MessageTypes.Level1Change, message.Arg); RemoveStorage <InMemoryMarketDataStorage <ClearingMessage> >(security, ExtendedMessageTypes.Clearing, message.Arg); } break; } case MarketDataTypes.MarketDepth: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <QuoteChangeMessage>)StorageRegistry.GetMarketDepthStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <QuoteChangeMessage> >(security, MessageTypes.QuoteChange, message.Arg); } break; } case MarketDataTypes.Trades: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetTradeStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.OrderLog: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetOrderLogStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.CandleTimeFrame: case MarketDataTypes.CandleTick: case MarketDataTypes.CandleVolume: case MarketDataTypes.CandleRange: case MarketDataTypes.CandlePnF: case MarketDataTypes.CandleRenko: { Type candleMessageType; MessageTypes msgType; switch (message.DataType) { case MarketDataTypes.CandleTimeFrame: msgType = MessageTypes.CandleTimeFrame; candleMessageType = typeof(TimeFrameCandleMessage); break; case MarketDataTypes.CandleTick: msgType = MessageTypes.CandleTick; candleMessageType = typeof(TickCandleMessage); break; case MarketDataTypes.CandleVolume: msgType = MessageTypes.CandleVolume; candleMessageType = typeof(VolumeCandleMessage); break; case MarketDataTypes.CandleRange: msgType = MessageTypes.CandleRange; candleMessageType = typeof(RangeCandleMessage); break; case MarketDataTypes.CandlePnF: msgType = MessageTypes.CandlePnF; candleMessageType = typeof(PnFCandleMessage); break; case MarketDataTypes.CandleRenko: msgType = MessageTypes.CandleRenko; candleMessageType = typeof(RenkoCandleMessage); break; default: throw new InvalidOperationException(); } if (message.IsSubscribe) { BasketStorage.InnerStorages.Add(StorageRegistry.GetCandleMessageStorage(candleMessageType, security, message.Arg, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <CandleMessage> >(security, msgType, message.Arg); } break; } default: error = new InvalidOperationException(LocalizedStrings.Str1118Params.Put(message.DataType)); break; } RaiseMarketDataMessage(message, error); }