public MarketHistoryItemsReport <HistoryBar> QueryBarHistory(DateTime to, int maxBars, string symbol, string periodicity, FxPriceType priceType) { var type = FxPriceType.Bid == priceType ? PriceType.Bid : PriceType.Ask; var period = new BarPeriod(periodicity); var info = this.dataFeed.Server.GetHistoryBars(symbol, to, -maxBars, type, period); var result = new MarketHistoryItemsReport <HistoryBar> { Items = info.Bars.Select(StorageConvert.ToHistoryBar).ToList(), AvailableFrom = info.FromAll, AvailableTo = info.ToAll, From = info.From.Value, To = info.To.Value, LastTickId = !string.IsNullOrEmpty(info.LastTickId) ? FeedTickId.Parse(info.LastTickId) : default(FeedTickId?), Symbol = symbol }; return(result); }
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); }