public RemoteExtendedStorage(RemoteStorageClient client, string storageName) { if (storageName.IsEmpty()) { throw new ArgumentNullException(nameof(storageName)); } _client = client ?? throw new ArgumentNullException(nameof(client)); _storageName = storageName; }
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; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteMarketDataDrive"/>. /// </summary> /// <param name="client">The client for access to the history server <see cref="IRemoteStorage"/>.</param> public RemoteMarketDataDrive(RemoteStorageClient client) { Client = client; Client.Drive = this; }
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.IsCandle()) { dataType = dataType.ToCandleMessageType(); } RaiseDataLoaded(security.Security, dataType, arg, date, info.Count); } } } return(true); }
private void InitializeCommands() { var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <OpenMarketDataSettingsCommand>(this, true, cmd => OpenMarketDataPanel(cmd.Settings)); cmdSvc.Register <RefreshSecurities>(this, false, cmd => ThreadingHelper .Thread(() => { var entityRegistry = ConfigManager.GetService <IEntityRegistry>(); var count = 0; var progress = 0; try { using (var client = new RemoteStorageClient(new Uri(cmd.Settings.Path))) { var credentials = cmd.Settings.Credentials; client.Credentials.Login = credentials.Login; client.Credentials.Password = credentials.Password; foreach (var secType in cmd.Types.TakeWhile(secType => !cmd.IsCancelled())) { if (secType == SecurityTypes.Future) { var from = DateTime.Today.AddMonths(-4); var to = DateTime.Today.AddMonths(4); var expiryDates = from.GetExpiryDates(to); foreach (var expiryDate in expiryDates.TakeWhile(d => !cmd.IsCancelled())) { client.Refresh(entityRegistry.Securities, new Security { Type = secType, ExpiryDate = expiryDate }, s => { entityRegistry.Securities.Save(s); _connector.SendOutMessage(s.ToMessage()); count++; }, cmd.IsCancelled); } } else { // для акций передаем фиктивное значение ExpiryDate, чтобы получить инструменты без даты экспирации var expiryDate = secType == SecurityTypes.Stock ? DateTime.Today : (DateTime?)null; client.Refresh(entityRegistry.Securities, new Security { Type = secType, ExpiryDate = expiryDate }, s => { entityRegistry.Securities.Save(s); _connector.SendOutMessage(s.ToMessage()); count++; }, cmd.IsCancelled); } cmd.ProgressChanged(++progress); } } } catch (Exception ex) { ex.LogError(); } if (cmd.IsCancelled()) { return; } try { cmd.WhenFinished(count); } catch (Exception ex) { ex.LogError(); } }) .Launch()); cmdSvc.Register <CreateSecurityCommand>(this, true, cmd => { var entityRegistry = ConfigManager.GetService <IEntityRegistry>(); ISecurityWindow wnd; if (cmd.SecurityType == typeof(Security)) { wnd = new SecurityCreateWindow(); } else { throw new InvalidOperationException(LocalizedStrings.Str2140Params.Put(cmd.SecurityType)); } wnd.ValidateId = id => { if (entityRegistry.Securities.ReadById(id) != null) { return(LocalizedStrings.Str2927Params.Put(id)); } return(null); }; if (!((Window)wnd).ShowModal(Application.Current.GetActiveOrMainWindow())) { return; } entityRegistry.Securities.Save(wnd.Security); _connector.SendOutMessage(wnd.Security.ToMessage()); cmd.Security = wnd.Security; }); cmdSvc.Register <SetDefaultEmulationSettingsCommand>(this, false, cmd => { _emulationSettings.Load(cmd.Settings.Save()); _layoutManager.FlushSettings(); }); }
private void InitializeCommands() { var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <OpenMarketDataSettingsCommand>(this, true, cmd => OpenMarketDataPanel(cmd.Settings)); cmdSvc.Register <RefreshSecurities>(this, false, cmd => ThreadingHelper .Thread(() => { var entityRegistry = ConfigManager.GetService <IEntityRegistry>(); var count = 0; var progress = 0; try { using (var client = new RemoteStorageClient(new Uri(cmd.Settings.Path))) { var credentials = cmd.Settings.Credentials; client.Credentials.Login = credentials.Login; client.Credentials.Password = credentials.Password; foreach (var secType in cmd.Types.TakeWhile(secType => !cmd.IsCancelled())) { if (secType == SecurityTypes.Future) { var from = DateTime.Today.AddMonths(-4); var to = DateTime.Today.AddMonths(4); var expiryDates = from.GetExpiryDates(to); foreach (var expiryDate in expiryDates.TakeWhile(d => !cmd.IsCancelled())) { client.Refresh(entityRegistry.Securities, new Security { Type = secType, ExpiryDate = expiryDate }, s => { entityRegistry.Securities.Save(s); _connector.SendOutMessage(s.ToMessage()); count++; }, cmd.IsCancelled); } } else { // для акций передаем фиктивное значение ExpiryDate, чтобы получить инструменты без даты экспирации var expiryDate = secType == SecurityTypes.Stock ? DateTime.Today : (DateTime?)null; client.Refresh(entityRegistry.Securities, new Security { Type = secType, ExpiryDate = expiryDate }, s => { entityRegistry.Securities.Save(s); _connector.SendOutMessage(s.ToMessage()); count++; }, cmd.IsCancelled); } cmd.ProgressChanged(++progress); } } } catch (Exception ex) { ex.LogError(); } if (cmd.IsCancelled()) { return; } try { cmd.WhenFinished(count); } catch (Exception ex) { ex.LogError(); } }) .Launch()); }