Пример #1
0
        protected override void Subscribe(string symbol)
        {
            if (string.IsNullOrWhiteSpace(symbol) || !IsConnected)
            {
                return;
            }

            if (_dataStore.GetExistingSymbols().Exists(x => x == symbol) && !_subscriptions.ContainsKey(symbol))
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();

                _subscriptions.Add(symbol, tokenSource);

                Task.Factory.StartNew(x =>
                {
                    string subscribedSymbol = (string)x;

                    _streamingProvider.Stream(subscribedSymbol, tokenSource.Token);

                    _subscriptions.Remove(subscribedSymbol);
                }, symbol, tokenSource.Token);
            }
        }
Пример #2
0
        public override void UpdateProvider(IDataUpdateMessage dataUpdateMsg, List <DataSource> dataSources, bool updateNonDSSymbols, bool deleteNonDSSymbols)
        {
            foreach (BarDataScale scale in this._dataStore.GetExistingBarScales())
            {
                if (_cancelTokenSource != null && _cancelTokenSource.IsCancellationRequested)
                {
                    dataUpdateMsg.DisplayUpdateMessage("Обновление провайдера отменено");
                    break;
                }

                dataUpdateMsg.DisplayUpdateMessage("Обновление таймфрейма " + scale.ToString());

                var visibleSymbols = from dataSource in dataSources
                                     where dataSource.BarDataScale == scale
                                     select SymbolDescription.DeserializeList(dataSource.DSString);

                List <SymbolDescription> symbols = new List <SymbolDescription>();

                foreach (List <SymbolDescription> visibleSymbol in visibleSymbols)
                {
                    symbols.AddRange(visibleSymbol);
                }

                if (updateNonDSSymbols)
                {
                    var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval)
                                       where !symbols.Exists(x => x.FullCode == symbol)
                                       select GetSymbolDescription(symbol);

                    symbols.AddRange(nonDSSymbols);
                }

                DataSource dsVirtual = new DataSource(this);

                dsVirtual.Name         = "VirtualDSr";
                dsVirtual.BarDataScale = scale;

                dsVirtual.DSString = SymbolDescription.SerializeList(symbols);

                UpdateDataSource(dsVirtual, dataUpdateMsg);

                if (deleteNonDSSymbols)
                {
                    dataUpdateMsg.DisplayUpdateMessage("--------------");
                    dataUpdateMsg.DisplayUpdateMessage("Удаление истории инструментов не входящих ни в один набор данных данного таймфрейма:");

                    var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval)
                                       where !symbols.Exists(x => x.FullCode == symbol)
                                       select symbol;

                    foreach (string symbol in nonDSSymbols)
                    {
                        lock (_locker)
                            _dataStore.RemoveFile(symbol, scale.Scale, scale.BarInterval);
                        dataUpdateMsg.DisplayUpdateMessage(string.Format("[DELETED] Инструмент {0} - История удалена", symbol));
                    }

                    if (nonDSSymbols.Count() == 0)
                    {
                        dataUpdateMsg.DisplayUpdateMessage(string.Format("[NA] Инструменты для удаления не найдены"));
                    }
                }

                dataUpdateMsg.DisplayUpdateMessage("--------------");
            }
        }