Ejemplo n.º 1
0
        /// <summary>
        /// Сохранить свечи по инструменту в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="candles">Свечи.</param>
        protected void SaveCandles(HydraTaskSecurity security, IEnumerable <CandleMessage> candles)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            SaveCandles(security.Security, candles);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Сохранить лог заявок по инструменту в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="items">Лог заявок.</param>
        protected void SaveOrderLog(HydraTaskSecurity security, IEnumerable <ExecutionMessage> items)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            SaveOrderLog(security.Security, items);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Сохранить изменения по инструменту в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="messages">Изменения.</param>
        protected void SaveLevel1Changes(HydraTaskSecurity security, IEnumerable <Level1ChangeMessage> messages)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            SaveLevel1Changes(security.Security, messages);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Проверить, является ли дата торгуемой.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="date">Передаваемая дата, которую необходимо проверить.</param>
        /// <returns><see langword="true"/>, если торгуемая дата, иначе, неторгуемая.</returns>
        public static bool IsTradeDate(this HydraTaskSecurity security, DateTime date)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            return(security.Security.Board.IsTradeDate(date.ApplyTimeZone(security.Security.Board.TimeZone), true));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Проверить, является ли дата торгуемой.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="date">Передаваемая дата, которую необходимо проверить.</param>
        /// <returns><see langword="true"/>, если торгуемая дата, иначе, неторгуемая.</returns>
        public static bool IsTradeDate(this HydraTaskSecurity security, DateTime date)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            return(security.Security.Board.WorkingTime.IsTradeDate(date, true));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Проверить, включена ли закачка данных тиков для инструмента.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <returns>Результат проверки.</returns>
        public static bool IsTicksEnabled(this HydraTaskSecurity security)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            return(security.DataTypesSet.Contains(DataType.Create(typeof(ExecutionMessage), ExecutionTypes.Tick)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Получить серии свечек.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <returns>Серии свечек.</returns>
        public static IEnumerable <DataType> GetCandleSeries(this HydraTaskSecurity security)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            return(security.DataTypes.Where(t => t.MessageType.IsCandleMessage()));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Сохранить стаканы в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="depths">Стаканы.</param>
        protected void SaveDepths(HydraTaskSecurity security, IEnumerable <QuoteChangeMessage> depths)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            SaveDepths(security.Security, depths);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Проверить, включена ли закачка данных <see cref="Level1ChangeMessage"/> для инструмента.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <returns>Результат проверки.</returns>
        public static bool IsLevel1Enabled(this HydraTaskSecurity security)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            return(security.DataTypesSet.Contains(DataType.Create(typeof(Level1ChangeMessage), null)));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Сохранить лог заявок по инструменту в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="items">Лог заявок.</param>
        protected void SaveOrderLog(HydraTaskSecurity security, IEnumerable <OrderLogItem> items)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            SaveOrderLog(security.Security, items);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Сохранить стаканы в хранилище.
        /// </summary>
        /// <param name="security">Инструмент.</param>
        /// <param name="depths">Стаканы.</param>
        protected void SaveDepths(HydraTaskSecurity security, IEnumerable <MarketDepth> depths)
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            SaveDepths(security.Security, depths);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Сохранить свечи по инструменту в хранилище.
        /// </summary>
        /// <typeparam name="TCandle">Тип свечи.</typeparam>
        /// <param name="security">Инструмент.</param>
        /// <param name="candles">Свечи.</param>
        protected void SaveCandles <TCandle>(HydraTaskSecurity security, IEnumerable <TCandle> candles)
            where TCandle : Candle
        {
            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            SaveCandles(security.Security, candles);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Запустить загрузку данных.
        /// </summary>
        protected override void OnStarting()
        {
            var connectorSettings = (ConnectorHydraTaskSettings)Settings;

            var settings = Connector.ReConnectionSettings;

            if (connectorSettings == null)
            {
                settings.AttemptCount   = -1;
                settings.ReAttemptCount = -1;
            }
            else
            {
                settings.Load(connectorSettings.ReConnectionSettings.Save());

                Connector.LogLevel = LogLevel;
            }

            Adapter  = GetAdapter(Connector.TransactionIdGenerator);
            _adapter = new BufferMessageAdapter(Adapter);

            Connector.Adapter.InnerAdapters.Clear();
            Connector.Adapter.InnerAdapters.Add(_adapter);

            // если фильтр по инструментам выключен (выбран инструмент все инструменты)
            _allSecurity = this.GetAllSecurity();

            _securityMap.Clear();
            _associatedSecurityCodes.Clear();

            if (_allSecurity == null)
            {
                _securityMap.AddRange(Settings.Securities.ToDictionary(s => s.Security, s => s));

                var associatedSecurities = Settings
                                           .Securities
                                           .Where(p => p.Security.Board == ExchangeBoard.Associated)
                                           .DistinctBy(sec => sec.Security.Code);

                _associatedSecurityCodes.AddRange(associatedSecurities.ToDictionary(s => s.Security.Code, s => s));
            }

            _adapter.SendInMessage(new ConnectMessage());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Запустить загрузку данных.
        /// </summary>
        protected override void OnStarting()
        {
            // если фильтр по инструментам выключен (выбран инструмент все инструменты)
            _allSecurity = this.GetAllSecurity();

            _securityMap.Clear();
            _associatedSecurityCodes.Clear();

            if (_allSecurity == null)
            {
                _securityMap.AddRange(Settings.Securities.ToDictionary(s => s.Security, s => s));

                var associatedSecurities = Settings
                                           .Securities
                                           .Where(p => p.Security.Board == ExchangeBoard.Associated)
                                           .DistinctBy(sec => sec.Security.Code);

                _associatedSecurityCodes.AddRange(associatedSecurities.ToDictionary(s => s.Security.Code, s => s));
            }

            Connector.Start();
        }
Ejemplo n.º 15
0
		private static bool IsQuandl(HydraTaskSecurity taskSecurity)
		{
			var security = taskSecurity.Security;

			return security.ExtensionInfo.ContainsKey(QuandlHistorySource.SecurityCodeField)
				&& security.ExtensionInfo.ContainsKey(QuandlHistorySource.SourceCodeField);
		}
Ejemplo n.º 16
0
		private bool DownloadData(HydraTaskSecurity security, Type dataType, object arg, RemoteStorageClient client)
		{
			var localStorage = StorageRegistry.GetStorage(security.Security, dataType, arg, _settings.Drive, _settings.StorageFormat);

			var remoteStorage = client.GetRemoteStorage(security.Security.ToSecurityId(), dataType, arg, _settings.StorageFormat);

			var endDate = DateTime.Today - TimeSpan.FromDays(_settings.Offset);
			var dates = remoteStorage.Dates.Where(date => date >= _settings.StartFrom && date <= endDate).Except(localStorage.Dates).ToArray();

			if (dates.IsEmpty())
			{
				if (!CanProcess())
					return false;
			}
			else
			{
				this.AddInfoLog(LocalizedStrings.Str2308Params.Put(dataType.Name));

				foreach (var date in dates)
				{
					if (!CanProcess())
						return false;

					if (_settings.IgnoreWeekends && !security.IsTradeDate(date))
					{
						this.AddDebugLog(LocalizedStrings.WeekEndDate, date);
						continue;
					}

					this.AddDebugLog(LocalizedStrings.StartDownloding, dataType, arg, date, security.Security.Id);

					using (var stream = remoteStorage.LoadStream(date))
					{
						if (stream == Stream.Null)
						{
							this.AddDebugLog(LocalizedStrings.NoData);
							continue;
						}

						this.AddInfoLog(LocalizedStrings.Str2309Params.Put(date));

						localStorage.Drive.SaveStream(date, stream);

						var info = localStorage.Serializer.CreateMetaInfo(date);

						stream.Position = 0;
						info.Read(stream);

						if (dataType == typeof(Trade))
						{
							dataType = typeof(ExecutionMessage);
							arg = ExecutionTypes.Tick;
						}
						else if (dataType == typeof(OrderLogItem))
						{
							dataType = typeof(ExecutionMessage);
							arg = ExecutionTypes.OrderLog;
						}
						else if (dataType.IsSubclassOf(typeof(Candle)))
						{
							dataType = dataType.ToCandleMessageType();
						}

						RaiseDataLoaded(security.Security, dataType, arg, date, info.Count);
					}
				}
			}

			return true;
		}
Ejemplo n.º 17
0
 /// <summary>
 /// Сохранить сделки в хранилище.
 /// </summary>
 /// <param name="security">Инструмент.</param>
 /// <param name="trades">Сделки.</param>
 protected void SaveTrades(HydraTaskSecurity security, IEnumerable <Trade> trades)
 {
     SaveTrades(security.Security, trades);
 }
Ejemplo n.º 18
0
		private static bool IsMfd(HydraTaskSecurity taskSecurity)
		{
			var security = taskSecurity.Security;

			return security.ExtensionInfo.ContainsKey(MfdHistorySource.MarketIdField)
				&& security.ExtensionInfo.ContainsKey(MfdHistorySource.SecurityIdField);
		}
Ejemplo n.º 19
0
 /// <summary>
 /// Сохранить тиковые сделки в хранилище.
 /// </summary>
 /// <param name="security">Инструмент.</param>
 /// <param name="ticks">Тиковые сделки.</param>
 protected void SaveTicks(HydraTaskSecurity security, IEnumerable <ExecutionMessage> ticks)
 {
     SaveTicks(security.Security, ticks);
 }