/// <summary> /// Закачать новые инструменты. /// </summary> /// <param name="storage">Хранилище информации об инструментах.</param> /// <param name="criteria">Инструмент, поля которого будут использоваться в качестве фильтра.</param> /// <param name="newSecurity">Обработчик, через который будет передан новый инструмент.</param> /// <param name="isCancelled">Обработчик, возвращающий признак отмены поиска.</param> public void Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { lock (_refreshSync) _isRefreshed = false; if (_connector == null) { _criteria = criteria; _newSecurity = newSecurity; _wasConnected = false; Start(); lock (_refreshSync) { if (!_isRefreshed) { _refreshSync.Wait(TimeSpan.FromMinutes(1)); } } } else { ProcessLookupSecurities(criteria, newSecurity, true); } }
public Worker() { storage = new StorageRegistry(); securityStorage = storage.GetSecurityStorage(); connectors = new List<IQFeedTrader>(); }
/// <summary> /// Initializes a new instance of the <see cref="StorageMetaInfoMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">The adapter, to which messages will be directed.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="positionStorage">Position storage.</param> /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param> public StorageMetaInfoMessageAdapter(IMessageAdapter innerAdapter, ISecurityStorage securityStorage, IPositionStorage positionStorage, IExchangeInfoProvider exchangeInfoProvider) : base(innerAdapter) { _securityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); _positionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage)); _exchangeInfoProvider = exchangeInfoProvider ?? throw new ArgumentNullException(nameof(_exchangeInfoProvider)); }
IEnumerable <Security> ISecurityProvider.Lookup(Security criteria) { if (criteria.Code == "*") { return(_securitiesById.Values); } var security = _securitiesById.TryGetValue(criteria.Id); if (security != null) { return new[] { security } } ; return(_securitiesByCode.TryGetValue(criteria.Code) ?? Enumerable.Empty <Security>()); } object ISecurityProvider.GetNativeId(Security security) { throw new NotSupportedException(); } void ISecurityStorage.Save(Security security) { _securitiesByCode.SafeAdd(security.Code).Add(security); _securitiesById[security.Id] = security; } IEnumerable <string> ISecurityStorage.GetSecurityIds() { return(_securitiesById.Keys); }
/// <summary> /// Initializes a new instance of the <see cref="CsvImporter"/>. /// </summary> /// <param name="dataType">Data type info.</param> /// <param name="fields">Importing fields.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param> /// <param name="drive">The storage. If a value is <see langword="null" />, <see cref="IStorageRegistry.DefaultDrive"/> will be used.</param> /// <param name="storageFormat">The format type. By default <see cref="StorageFormats.Binary"/> is passed.</param> public CsvImporter(DataType dataType, IEnumerable <FieldMapping> fields, ISecurityStorage securityStorage, IExchangeInfoProvider exchangeInfoProvider, IMarketDataDrive drive, StorageFormats storageFormat) : base(dataType, fields) { _securityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); _exchangeInfoProvider = exchangeInfoProvider ?? throw new ArgumentNullException(nameof(exchangeInfoProvider)); _drive = drive; _storageFormat = storageFormat; }
public StorageEntityFactory(ISecurityStorage securityStorage) { if (securityStorage == null) throw new ArgumentNullException("securityStorage"); _securityStorage = securityStorage; _securities = _securityStorage.LookupAll().ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Initializes a new instance of the <see cref="StorageMetaInfoMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">The adapter, to which messages will be directed.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="positionStorage">Position storage.</param> /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param> /// <param name="storageRegistry">The storage of market data.</param> /// <param name="snapshotRegistry">Snapshot storage registry.</param> /// <param name="candleBuilderProvider">Candle builders provider.</param> public StorageMetaInfoMessageAdapter(IMessageAdapter innerAdapter, ISecurityStorage securityStorage, IPositionStorage positionStorage, IExchangeInfoProvider exchangeInfoProvider, IStorageRegistry storageRegistry, SnapshotRegistry snapshotRegistry, CandleBuilderProvider candleBuilderProvider) : base(innerAdapter, storageRegistry, snapshotRegistry, candleBuilderProvider) { _securityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); _positionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage)); _exchangeInfoProvider = exchangeInfoProvider ?? throw new ArgumentNullException(nameof(_exchangeInfoProvider)); }
private void MockSecurityStorage() { var context = this.mockSecurityDataContext.Object; Func <ISecurityDataContext> createSecurityDataContext = () => { return(context); }; var dbsecurityStorage = new DatabaseSecurityStorage(createSecurityDataContext); var cachePrvoider = new HttpCache(); this.securityStorage = new CachedSecurityStorage(dbsecurityStorage, cachePrvoider); }
public void AttachToStorage(ISecurityStorage storage) { if (storage != null) { _storageSynchronizer = new StorageSynchronizer(this, storage); } else { _storageSynchronizer = null; } }
private void MockSecurityStorage() { var context = _MockSecurityDataContext.Object; Func <ISecurityDataContext> createSecurityDataContext = () => { return(context); }; _SecurityStorage = new DatabaseSecurityStorage (createSecurityDataContext); }
/// <summary> /// Initializes a new instance of the <see cref="Connector"/>. /// </summary> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="positionStorage">Position storage.</param> /// <param name="storageRegistry">The storage of market data.</param> /// <param name="snapshotRegistry">Snapshot storage registry.</param> /// <param name="initManagers">Initialize managers.</param> public Connector(ISecurityStorage securityStorage, IPositionStorage positionStorage, IStorageRegistry storageRegistry, SnapshotRegistry snapshotRegistry, bool initManagers = true) : this(false, true, storageRegistry, snapshotRegistry, initManagers) { _entityCache.ExchangeInfoProvider = storageRegistry.ExchangeInfoProvider; SecurityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); PositionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage)); InitAdapter(storageRegistry, snapshotRegistry); }
private void MockSecurityStorage() { var context = _MockSecurityDataContext.Object; Func<ISecurityDataContext> createSecurityDataContext = () => { return context; }; _SecurityStorage = new DatabaseSecurityStorage (createSecurityDataContext); }
/// <summary> /// Initializes a new instance of the <see cref="MultiSecurityStorage"/>. /// </summary> /// <param name="regular">Security storage of <see cref="Security"/>.</param> /// <param name="index">Security storage of <see cref="IndexSecurity"/>.</param> /// <param name="continuous">Security storage of <see cref="ContinuousSecurity"/>.</param> public MultiSecurityStorage(ISecurityStorage regular, ISecurityStorage index, ISecurityStorage continuous) { _regular = regular ?? throw new ArgumentNullException(nameof(regular)); _index = index ?? throw new ArgumentNullException(nameof(index)); _continuous = continuous ?? throw new ArgumentNullException(nameof(continuous)); _regular.Added += OnSecuritiesAdded; _regular.Removed += OnSecuritiesRemoved; _index.Added += OnSecuritiesAdded; _index.Removed += OnSecuritiesRemoved; _continuous.Added += OnSecuritiesAdded; _continuous.Removed += OnSecuritiesRemoved; }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="entityRegistry">The storage of trade objects.</param> /// <param name="storageRegistry">The storage of market data.</param> public StorageEntityFactory(IEntityRegistry entityRegistry, IStorageRegistry storageRegistry) { if (entityRegistry == null) throw new ArgumentNullException("entityRegistry"); if (storageRegistry == null) throw new ArgumentNullException("storageRegistry"); _entityRegistry = entityRegistry; _storageRegistry = storageRegistry; _securityStorage = storageRegistry.GetSecurityStorage(); _securities = _securityStorage.LookupAll() .ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Delete instrument by identifier. /// </summary> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="securityId">Identifier.</param> public static void DeleteById(this ISecurityStorage securityStorage, string securityId) { if (securityStorage == null) { throw new ArgumentNullException(nameof(securityStorage)); } if (securityId.IsEmpty()) { throw new ArgumentNullException(nameof(securityId)); } securityStorage.DeleteBy(new Security { Id = securityId }); }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="entityRegistry">The storage of trade objects.</param> /// <param name="storageRegistry">The storage of market data.</param> public StorageEntityFactory(IEntityRegistry entityRegistry, IStorageRegistry storageRegistry) { if (entityRegistry == null) { throw new ArgumentNullException("entityRegistry"); } if (storageRegistry == null) { throw new ArgumentNullException("storageRegistry"); } _entityRegistry = entityRegistry; _storageRegistry = storageRegistry; _securityStorage = storageRegistry.GetSecurityStorage(); _securities = _securityStorage.LookupAll() .ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); }
/// <summary> /// Initialize <see cref="RemoteStorage"/>. /// </summary> /// <param name="storageRegistry">Market-data storage.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="extendedInfoStorage">Extended info <see cref="Message.ExtensionInfo"/> storage.</param> /// <param name="exchangeInfoProvider">The exchange boards provider.</param> protected RemoteStorage(IStorageRegistry storageRegistry, ISecurityStorage securityStorage, IExtendedInfoStorage extendedInfoStorage, IExchangeInfoProvider exchangeInfoProvider) { StorageRegistry = storageRegistry ?? throw new ArgumentNullException(nameof(storageRegistry)); SecurityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); ExtendedInfoStorage = extendedInfoStorage ?? throw new ArgumentNullException(nameof(extendedInfoStorage)); ExchangeInfoProvider = exchangeInfoProvider ?? throw new ArgumentNullException(nameof(exchangeInfoProvider)); AddDataType(typeof(ExecutionMessage)); AddDataType(typeof(Level1ChangeMessage)); AddDataType(typeof(QuoteChangeMessage)); AddDataType(typeof(NewsMessage)); foreach (var candleType in StockSharp.Messages.Extensions.AllCandleTypes) { AddDataType(candleType); } AddDataType(typeof(PositionChangeMessage)); }
/// <summary> /// Initialize <see cref="RemoteStorage"/>. /// </summary> /// <param name="storageRegistry">Market-data storage.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="extendedInfoStorage">Extended info <see cref="Message.ExtensionInfo"/> storage.</param> /// <param name="exchangeInfoProvider">The exchange boards provider.</param> protected RemoteStorage(IStorageRegistry storageRegistry, ISecurityStorage securityStorage, IExtendedInfoStorage extendedInfoStorage, IExchangeInfoProvider exchangeInfoProvider) { StorageRegistry = storageRegistry ?? throw new ArgumentNullException(nameof(storageRegistry)); SecurityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); ExtendedInfoStorage = extendedInfoStorage ?? throw new ArgumentNullException(nameof(extendedInfoStorage)); ExchangeInfoProvider = exchangeInfoProvider ?? throw new ArgumentNullException(nameof(exchangeInfoProvider)); AddDataType(typeof(ExecutionMessage)); AddDataType(typeof(Level1ChangeMessage)); AddDataType(typeof(QuoteChangeMessage)); AddDataType(typeof(NewsMessage)); AddDataType(typeof(TimeFrameCandleMessage)); AddDataType(typeof(RangeCandleMessage)); AddDataType(typeof(RenkoCandleMessage)); AddDataType(typeof(PnFCandleMessage)); AddDataType(typeof(TickCandleMessage)); AddDataType(typeof(VolumeCandleMessage)); AddDataType(typeof(PositionChangeMessage)); }
public static IEnumerable <T> GetItems <T>(this ISecurityStorage storage) where T : IStorageEntity { return(storage.GetItems(typeof(T)).Cast <T>()); }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { new DukasCopySource().Refresh(EntityRegistry.Securities, criteria, newSecurity, isCancelled); }
public UserActivityController(ISecurityStorage securityStorage) { this.SecurityStorage = securityStorage; }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { using (var client = CreateClient()) client.Refresh(storage, criteria, newSecurity, isCancelled); }
public CachedSecurityStorage(ISecurityStorage storage, ICacheProvider cacheProvider) { this.storage = storage; this.cacheProvider = cacheProvider; }
public SecurityManager(ISecurityStorage SecurityStorage) { _SecurityStorage = SecurityStorage; }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="positionStorage">Position storage.</param> /// <param name="trackPositions">Track positions.</param> public StorageEntityFactory(ISecurityStorage securityStorage, IPositionStorage positionStorage, bool trackPositions) { _securityStorage = securityStorage ?? throw new ArgumentNullException(nameof(securityStorage)); _positionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage)); _trackPositions = trackPositions; }
public UserActivityController(ISecurityStorage securityStorage) { this.SecurityStorage = securityStorage; }
public void Refresh(ISecurityStorage storage, Security criteria, Action<Security> newSecurity, Func<bool> isCancelled) { CreateSource().Refresh(_quandlSecurityStorage, criteria, newSecurity, isCancelled); }
public StorageSynchronizer(SecurityStore store, ISecurityStorage securityStorage) { _store = store; _securityStorage = securityStorage; Sync(); }
public FormsSecurityManager(ISecurityStorage SecurityStorage) : base(SecurityStorage) { }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action<Security> newSecurity, Func<bool> isCancelled) { new OandaHistorySource().Refresh(storage, criteria, newSecurity, isCancelled); }
public CachedSecurityStorage(ISecurityStorage storage, ICacheProvider cacheProvider) { this.storage = storage; this.cacheProvider = cacheProvider; }
public FormsSecurityManager(ISecurityStorage SecurityStorage) : base(SecurityStorage) { }
public void Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { CreateSource().Refresh(_quandlSecurityStorage, criteria, newSecurity, isCancelled); }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { new MfdHistorySource().Refresh(_mfdSecurityStorage, criteria, newSecurity, isCancelled); }
private void SaveSecurity(Security security, ISecurityStorage securityStorage) { securityStorage.Save(security); }
public SecurityManager(ISecurityStorage SecurityStorage) { _SecurityStorage=SecurityStorage; }
/// <summary> /// Synchronize securities with storage. /// </summary> /// <param name="drives">Storage drives.</param> /// <param name="securityStorage">Securities meta info storage.</param> /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param> /// <param name="newSecurity">The handler through which a new instrument will be passed.</param> /// <param name="updateProgress">The handler through which a progress change will be passed.</param> /// <param name="logsReceiver">Logs receiver.</param> /// <param name="isCancelled">The handler which returns an attribute of search cancel.</param> public static void SynchronizeSecurities(this IEnumerable <IMarketDataDrive> drives, ISecurityStorage securityStorage, IExchangeInfoProvider exchangeInfoProvider, Action <Security> newSecurity, Action <int, int> updateProgress, Func <bool> isCancelled, ILogReceiver logsReceiver) { if (drives == null) { throw new ArgumentNullException(nameof(drives)); } if (securityStorage == null) { throw new ArgumentNullException(nameof(securityStorage)); } if (exchangeInfoProvider == null) { throw new ArgumentNullException(nameof(exchangeInfoProvider)); } if (newSecurity == null) { throw new ArgumentNullException(nameof(newSecurity)); } if (updateProgress == null) { throw new ArgumentNullException(nameof(updateProgress)); } if (isCancelled == null) { throw new ArgumentNullException(nameof(isCancelled)); } if (logsReceiver == null) { throw new ArgumentNullException(nameof(logsReceiver)); } var securityPaths = new List <string>(); var progress = 0; foreach (var dir in drives.Select(drive => drive.Path).Distinct()) { foreach (var letterDir in InteropHelper.GetDirectories(dir)) { if (isCancelled()) { break; } var name = Path.GetFileName(letterDir); if (name == null || name.Length != 1) { continue; } securityPaths.AddRange(InteropHelper.GetDirectories(letterDir)); } if (isCancelled()) { break; } } if (isCancelled()) { return; } // кол-во проходов по директории для создания инструмента var iterCount = securityPaths.Count; updateProgress(0, iterCount); var securities = securityStorage.LookupAll().ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase); foreach (var securityPath in securityPaths) { if (isCancelled()) { break; } var securityId = Path.GetFileName(securityPath).FolderNameToSecurityId(); var isNew = false; var security = securities.TryGetValue(securityId); if (security == null) { var firstDataFile = Directory.EnumerateDirectories(securityPath) .SelectMany(d => Directory.EnumerateFiles(d, "*.bin") .Concat(Directory.EnumerateFiles(d, "*.csv")) .OrderBy(f => Path.GetExtension(f).CompareIgnoreCase(".bin") ? 0 : 1)) .FirstOrDefault(); if (firstDataFile != null) { var id = securityId.ToSecurityId(); decimal priceStep; if (Path.GetExtension(firstDataFile).CompareIgnoreCase(".bin")) { try { priceStep = File.ReadAllBytes(firstDataFile).Range(6, 16).To <decimal>(); } catch (Exception ex) { throw new InvalidOperationException(LocalizedStrings.Str2929Params.Put(firstDataFile), ex); } } else { priceStep = 0.01m; } security = new Security { Id = securityId, PriceStep = priceStep, Name = id.SecurityCode, Code = id.SecurityCode, Board = exchangeInfoProvider.GetOrCreateBoard(id.BoardCode), }; securities.Add(securityId, security); securityStorage.Save(security, false); newSecurity(security); isNew = true; } } updateProgress(progress++, iterCount); if (isNew) { logsReceiver.AddInfoLog(LocalizedStrings.Str2930Params, security); } } }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action<Security> newSecurity, Func<bool> isCancelled) { new DukasCopySource().Refresh(EntityRegistry.Securities, criteria, newSecurity, isCancelled); }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action<Security> newSecurity, Func<bool> isCancelled) { using (var client = CreateClient()) client.Refresh(storage, criteria, newSecurity, isCancelled); }
void ISecurityDownloader.Refresh(ISecurityStorage storage, Security criteria, Action <Security> newSecurity, Func <bool> isCancelled) { CreateSource().Refresh(storage, criteria, newSecurity, isCancelled); }
private void MockSecurityStorage() { var context = this.mockSecurityDataContext.Object; Func<ISecurityDataContext> createSecurityDataContext = () => { return context; }; var dbsecurityStorage = new DatabaseSecurityStorage(createSecurityDataContext); var cachePrvoider = new HttpCache(); this.securityStorage = new CachedSecurityStorage(dbsecurityStorage, cachePrvoider); }