public static Bar ToBar(HistoryBar bar, BarPeriod period) { var from = bar.Time; var to = from + period; var open = (double)bar.Open; var close = (double)bar.Close; var low = (double)bar.Low; var high = (double)bar.Hi; var volume = bar.Volume; var result = new Bar(from, to, open, close, low, high, volume); return(result); }
public static HistoryBar ToHistoryBar(Bar bar) { var result = new HistoryBar { Low = (decimal)bar.Low, Hi = (decimal)bar.High, Open = (decimal)bar.Open, Close = (decimal)bar.Close, Time = bar.From, Volume = (uint)bar.Volume }; return(result); }
public static HistoryBar ToHistoryBar(Bar bar) { var result = new HistoryBar { Low = (decimal)bar.Low, Hi = (decimal)bar.High, Open = (decimal)bar.Open, Close = (decimal)bar.Close, Time = bar.From, Volume = (uint)bar.Volume }; return result; }
public static Bar ToBar(HistoryBar bar, BarPeriod period) { var from = bar.Time; var to = from + period; var open = (double)bar.Open; var close = (double)bar.Close; var low = (double)bar.Low; var high = (double)bar.Hi; var volume = bar.Volume; var result = new Bar(from, to, open, close, low, high, volume); 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); }
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; }