/// <summary> /// Преобразовать <see cref="Security"/> в <see cref="HydraTaskSecurity"/>. /// </summary> /// <param name="task">Задача.</param> /// <param name="securities">Исходные инструменты.</param> /// <returns>Сконвертированные инструменты.</returns> public static IEnumerable <HydraTaskSecurity> ToHydraSecurities(this IHydraTask task, IEnumerable <Security> securities) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (securities == null) { throw new ArgumentNullException(nameof(securities)); } var allSec = task.GetAllSecurity(); var secMap = task.Settings.Securities.ToDictionary(s => s.Security, s => s); return(securities.Where(s => s != allSec.Security).Select(s => secMap.TryGetValue(s) ?? new HydraTaskSecurity { Security = s, Settings = task.Settings, MarketDataTypes = allSec == null ? ArrayHelper.Empty <Type>() : allSec.MarketDataTypes, })); }
private void InitTask(IHydraTask task, HydraTaskSettings settings) { Core.Extensions.Tasks.Add(task); task.Init(settings); _logManager.Sources.Add(task); task.DataLoaded += (security, dataType, arg, time, count) => { if (dataType == typeof(NewsMessage)) { LoadedNews += count; return; } var allSecurity = _taskAllSecurities.SafeAdd(task, key => task.GetAllSecurity()); var taskSecurity = _taskSecurityCache.SafeAdd(task).SafeAdd(security, key => task.Settings.Securities.FirstOrDefault(s => s.Security == key)); HydraTaskSecurity.TypeInfo info; HydraTaskSecurity.TypeInfo allInfo; if (dataType == typeof(ExecutionMessage)) { switch ((ExecutionTypes)arg) { case ExecutionTypes.Tick: { info = taskSecurity?.TradeInfo; allInfo = allSecurity?.TradeInfo; LoadedTrades += count; break; } case ExecutionTypes.OrderLog: { info = taskSecurity?.OrderLogInfo; allInfo = allSecurity?.OrderLogInfo; LoadedOrderLog += count; break; } case ExecutionTypes.Order: case ExecutionTypes.Trade: { info = taskSecurity?.TransactionInfo; allInfo = allSecurity?.TransactionInfo; LoadedTransactions += count; break; } default: throw new ArgumentOutOfRangeException(nameof(arg)); } } else if (dataType == typeof(QuoteChangeMessage)) { info = taskSecurity?.DepthInfo; allInfo = allSecurity?.DepthInfo; LoadedDepths += count; } else if (dataType == typeof(Level1ChangeMessage)) { info = taskSecurity?.Level1Info; allInfo = allSecurity?.Level1Info; LoadedLevel1 += count; } else if (dataType.IsCandleMessage()) { info = taskSecurity?.CandleInfo; allInfo = allSecurity?.CandleInfo; LoadedCandles += count; } else throw new ArgumentOutOfRangeException(nameof(dataType), dataType, LocalizedStrings.Str1018); if (allInfo != null) { allInfo.Count += count; allInfo.LastTime = time.LocalDateTime; task.Settings.Securities.Update(allSecurity); } if (info == null) return; info.Count += count; info.LastTime = time.LocalDateTime; task.Settings.Securities.Update(taskSecurity); }; }
private void InitTask(IHydraTask task, HydraTaskSettings settings) { Core.Extensions.Tasks.Add(task); task.Init(settings); _logManager.Sources.Add(task); task.DataLoaded += (security, dataType, arg, time, count) => { if (dataType == typeof(NewsMessage)) { LoadedNews += count; return; } var allSecurity = _taskAllSecurities.SafeAdd(task, key => task.GetAllSecurity()); var taskSecurity = _taskSecurityCache.SafeAdd(task).SafeAdd(security, key => task.Settings.Securities.FirstOrDefault(s => s.Security == key)); HydraTaskSecurity.TypeInfo info; HydraTaskSecurity.TypeInfo allInfo; if (dataType == typeof(ExecutionMessage)) { switch ((ExecutionTypes)arg) { case ExecutionTypes.Tick: { info = taskSecurity == null ? null : taskSecurity.TradeInfo; allInfo = allSecurity == null ? null : allSecurity.TradeInfo; LoadedTrades += count; break; } case ExecutionTypes.OrderLog: { info = taskSecurity == null ? null : taskSecurity.OrderLogInfo; allInfo = allSecurity == null ? null : allSecurity.OrderLogInfo; LoadedOrderLog += count; break; } case ExecutionTypes.Order: case ExecutionTypes.Trade: { info = taskSecurity == null ? null : taskSecurity.ExecutionInfo; allInfo = allSecurity == null ? null : allSecurity.ExecutionInfo; LoadedExecutions += count; break; } default: throw new ArgumentOutOfRangeException("arg"); } } else if (dataType == typeof(QuoteChangeMessage)) { info = taskSecurity == null ? null : taskSecurity.DepthInfo; allInfo = allSecurity == null ? null : allSecurity.DepthInfo; LoadedDepths += count; } else if (dataType == typeof(Level1ChangeMessage)) { info = taskSecurity == null ? null : taskSecurity.Level1Info; allInfo = allSecurity == null ? null : allSecurity.Level1Info; LoadedLevel1 += count; } else if (dataType.IsSubclassOf(typeof(CandleMessage))) { info = taskSecurity == null ? null : taskSecurity.CandleInfo; allInfo = allSecurity == null ? null : allSecurity.CandleInfo; LoadedCandles += count; } else { throw new ArgumentOutOfRangeException("dataType", dataType, LocalizedStrings.Str1018); } if (allInfo != null) { allInfo.Count += count; allInfo.LastTime = time.LocalDateTime; task.Settings.Securities.Update(allSecurity); } if (info == null) { return; } info.Count += count; info.LastTime = time.LocalDateTime; task.Settings.Securities.Update(taskSecurity); }; }