Exemplo n.º 1
0
        public void Disconnect()
        {
            if (_historyManager != null)
            {
                _historyManager.Flush();
                _historyManager.Dispose();
                _historyManager = null;
            }

            if (_historyStore != null)
            {
                _historyStore.Dispose();
                _historyStore = null;
            }

            if (_historyServiceClient != null)
            {
                _historyServiceClient = new HistoryServiceClient(Address);
            }

            if (_historySource == null)
            {
                _historySource = _historyServiceClient.ChannelFactory.CreateChannel();
            }
        }
Exemplo n.º 2
0
        public void Disconnect()
        {
            if (_historyManager != null)
            {
                _historyManager.Flush();
                _historyManager.Dispose();
                _historyManager = null;
            }

            if (_historyStore != null)
            {
                _historyStore.Dispose();
                _historyStore = null;
            }

            if (_historyServiceClient != null)
			{
				_historyServiceClient = new HistoryServiceClient(Address);
            }

            if (_historySource == null)
			{
				_historySource = _historyServiceClient.ChannelFactory.CreateChannel();
            }
        }
Exemplo n.º 3
0
        public HistoryBar GetHistory(string symbol, DateTime dateTime)
        {
            HistoryBar historyBar = new HistoryBar();

            if (!IsConnected)
            {
                if (!Connect())
                {
                    return(historyBar);
                }
            }

            if (string.IsNullOrEmpty(StorageFolderName))
            {
                return(historyBar);
            }

            List <string> symbolNames = GetSymbols();

            if (symbolNames == null || symbolNames.Count == 0)
            {
                _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to get symbols.");
                return(historyBar);
            }

            try
            {
                if (_historyStore == null)
                {
                    string   assemblyFileName = GetType().Assembly.Location;
                    FileInfo fileInfo         = new FileInfo(assemblyFileName);

                    int historySourceVersion = _historySource.GetHistoryVersion();
                    _historyStore = new NtfsHistoryStore(Path.Combine(fileInfo.DirectoryName, "DCQuotesStorage", StorageFolderName + "_v" + historySourceVersion), new NullMonitoringService());
                    StoreStatus storeStatus = _historyStore.OpenOrCreate(historySourceVersion, false);

                    if (storeStatus != StoreStatus.Ok)
                    {
                        _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to open or create quotes storage. Store status: {0}", storeStatus);
                        return(historyBar);
                    }
                }

                if (_historyManager == null)
                {
                    Dictionary <Periodicity, TimeInterval> periodicityMap = new Dictionary <Periodicity, TimeInterval>();
                    periodicityMap.Add(new Periodicity(TimeInterval.Second), TimeInterval.Hour);
                    periodicityMap.Add(new Periodicity(TimeInterval.Second, 10), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 5), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 15), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 30), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Hour), TimeInterval.Month);
                    periodicityMap.Add(new Periodicity(TimeInterval.Hour, 4), TimeInterval.Month);
                    periodicityMap.Add(new Periodicity(TimeInterval.Day), TimeInterval.Year);
                    periodicityMap.Add(new Periodicity(TimeInterval.Week), TimeInterval.Year);
                    periodicityMap.Add(new Periodicity(TimeInterval.Month), TimeInterval.Year);

                    _historyManager = HistoryManager.Create(_historyStore, new SortedSet <string>(symbolNames),
                                                            periodicityMap, true,
                                                            Cache.ClientInstance("CacheInstance"), true, true, new NullMonitoringService(), null);
                }

                if (!_historyManager.BarsAreSynchronized(_historySource, symbol, new Periodicity(TimeInterval.Minute),
                                                         TickTrader.Common.Business.FxPriceType.Bid,
                                                         new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0),
                                                         new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour + 1, 0, 0), true))
                {
                    _historyManager.SynchronizeBars(_historySource, symbol, new Periodicity(TimeInterval.Minute),
                                                    TickTrader.Common.Business.FxPriceType.Bid,
                                                    new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0),
                                                    new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour + 1, 0, 0), true,
                                                    delegate(int completed, int total, DateTime start, TimeSpan length) { });
                }

                MarketHistoryItemsReport <HistoryBar> report = _historyManager.QueryBarHistory(dateTime, 1, symbol,
                                                                                               new Periodicity(TimeInterval.Minute).ToString(), TickTrader.Common.Business.FxPriceType.Bid);

                if (report.Items.Count > 0)
                {
                    historyBar = report.Items[0];
                }
                else
                {
                    _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to query bar history (empry collection returned).");
                }
            }
            catch (Exception ex)
            {
                _logger.Debug(ex, "QuotesHistoryConnector.GetHistory(): Failed to query bar history (exception): {0}", ex.Message);
            }

            return(historyBar);
        }
Exemplo n.º 4
0
        public HistoryBar GetHistory(string symbol, DateTime dateTime)
        {
            HistoryBar historyBar = new HistoryBar();

            if (!IsConnected)
            {
                if (!Connect())
                {
                    return historyBar;
                }
            }

            if (string.IsNullOrEmpty(StorageFolderName))
            {
                return historyBar;
            }

            List<string> symbolNames = GetSymbols();
            if (symbolNames == null || symbolNames.Count == 0)
            {
                _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to get symbols.");
                return historyBar;
            }

            try
            {
                if (_historyStore == null)
                {
                    string assemblyFileName = GetType().Assembly.Location;
                    FileInfo fileInfo = new FileInfo(assemblyFileName);

                    int historySourceVersion = _historySource.GetHistoryVersion();
                    _historyStore = new NtfsHistoryStore(Path.Combine(fileInfo.DirectoryName, "DCQuotesStorage", StorageFolderName + "_v" + historySourceVersion), new NullMonitoringService());
                    StoreStatus storeStatus = _historyStore.OpenOrCreate(historySourceVersion, false);

                    if (storeStatus != StoreStatus.Ok)
                    {
                        _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to open or create quotes storage. Store status: {0}", storeStatus);
                        return historyBar;
                    }
                }

                if (_historyManager == null)
                {
                    Dictionary<Periodicity, TimeInterval> periodicityMap = new Dictionary<Periodicity, TimeInterval>();
                    periodicityMap.Add(new Periodicity(TimeInterval.Second), TimeInterval.Hour);
                    periodicityMap.Add(new Periodicity(TimeInterval.Second, 10), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 5), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 15), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Minute, 30), TimeInterval.Day);
                    periodicityMap.Add(new Periodicity(TimeInterval.Hour), TimeInterval.Month);
                    periodicityMap.Add(new Periodicity(TimeInterval.Hour, 4), TimeInterval.Month);
                    periodicityMap.Add(new Periodicity(TimeInterval.Day), TimeInterval.Year);
                    periodicityMap.Add(new Periodicity(TimeInterval.Week), TimeInterval.Year);
                    periodicityMap.Add(new Periodicity(TimeInterval.Month), TimeInterval.Year);

                    _historyManager = HistoryManager.Create(_historyStore, new SortedSet<string>(symbolNames),
                        periodicityMap, true,
                        Cache.ClientInstance("CacheInstance"), true, true, new NullMonitoringService(), null);
                }

                if (!_historyManager.BarsAreSynchronized(_historySource, symbol, new Periodicity(TimeInterval.Minute),
                        TickTrader.Common.Business.FxPriceType.Bid,
                        new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0),
                        new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour + 1, 0, 0), true))
                {
                    _historyManager.SynchronizeBars(_historySource, symbol, new Periodicity(TimeInterval.Minute),
                        TickTrader.Common.Business.FxPriceType.Bid,
                        new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0),
                        new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour + 1, 0, 0), true,
                        delegate (int completed, int total, DateTime start, TimeSpan length) { });
                }

                MarketHistoryItemsReport<HistoryBar> report = _historyManager.QueryBarHistory(dateTime, 1, symbol,
                    new Periodicity(TimeInterval.Minute).ToString(), TickTrader.Common.Business.FxPriceType.Bid);

                if (report.Items.Count > 0)
                {
                    historyBar = report.Items[0];
                }
                else
                {
                    _logger.Debug("QuotesHistoryConnector.GetHistory(): Failed to query bar history (empry collection returned).");
                }
            }
            catch (Exception ex)
            {
                _logger.Debug(ex, "QuotesHistoryConnector.GetHistory(): Failed to query bar history (exception): {0}", ex.Message);
            }

            return historyBar;
        }