public BarsHistoryCache(string symbol, Periodicity periodicity, FxPriceType priceType, QuoteHistoryClient historyClient) : base(symbol) { _historyClient = historyClient; Periodicity = periodicity; PriceType = priceType; }
public static PriceType ToPriceType(FxPriceType type) { if (type == FxPriceType.Bid) return PriceType.Bid; if (type == FxPriceType.Ask) return PriceType.Ask; var message = string.Format("Incorrect price type: expected Bid or Ask, but received = {0}", type); throw new ArgumentException("type", message); }
void FillRecords(FxPriceType type, QuoteEntry[] entries) { for (var index = 0; index < entries.Length; ++index) { var entry = entries[index]; var record = new FeedLevel2Record { Price = RoundPrice(entry.Price), Volume = entry.Volume, Type = type }; this.records.Add(record); } }
public static PriceType ToPriceType(FxPriceType type) { if (type == FxPriceType.Bid) { return(PriceType.Bid); } if (type == FxPriceType.Ask) { return(PriceType.Ask); } var message = string.Format("Incorrect price type: expected Bid or Ask, but received = {0}", type); throw new ArgumentException("type", message); }
public string DumpBarsIntervals(string symbol, Periodicity periodicity, FxPriceType priceType) { BarsHistoryCache cache; try { _lock.EnterReadLock(); var key = new Tuple <string, Periodicity, FxPriceType>(symbol, periodicity, priceType); if (!_cachedBars.TryGetValue(key, out cache) || (cache == null)) { throw new HistoryNotFoundException(); } } finally { _lock.ExitReadLock(); } return(cache.DumpIntervals()); }
static void ForwardFillBars(IHistoryManager cache, string symbol, Periodicity periodicity, FxPriceType priceType, DateTime startTime, DateTime endTime, ICollection<HistoryBar> bars) { try { for (var current = startTime; current < endTime; ) { var report = cache.QueryBarHistory(current, -RequestedBarsNumber, symbol, periodicity.ToString(), priceType); var items = report.Items; foreach (var element in report.Items) { if (element.Time >= endTime) { return; } bars.Add(element); } if (items.Count == 0) { return; } current = items.Last().Time; current = current + periodicity; } } catch (StorageHistoryNotFoundException) { } }
public TickTraderHistoryInfo GetBarsHistoryInfo(string symbol, Periodicity periodicity, FxPriceType priceType) { var apiPriceType = StorageConvert.ToPriceType(priceType); var apiPeriodicity = StorageConvert.ToBarPeriod(periodicity); var info = this.dataFeed.Server.GetBarsHistoryFiles(symbol, ZeroDateTime, apiPriceType, apiPeriodicity.ToString()); var result = new TickTraderHistoryInfo { AvailableFrom = info.FromAll, AvailableTo = info.ToAll }; return(result); }
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 List <HistoryBar> QueryBarHistoryCache(DateTime to, int maxBars, string symbol, string periodicity, FxPriceType priceType) { throw new NotImplementedException(); }
public MarketBarHistoryFileReport QueryBarHistoryFile(DateTime from, DateTime to, string symbol, string periodicity, FxPriceType priceType) { if (to != from) { throw new Exception("Range bar history queries are unsupported"); } var type = StorageConvert.ToPriceType(priceType); return(this.Attempt(this.DoQueryBarHistoryFile, from, symbol, periodicity, type)); }
public MarketHistoryMetaFileReport QueryBarHistoryMetaFile(string symbol, string periodicity, FxPriceType priceType) { var result = new MarketHistoryMetaFileReport { FileBytes = this.GetBarMetadataFile(symbol, periodicity, priceType) }; return(result); }
/// <summary> /// Reads data chunk for a specified symbol. /// </summary> /// <param name="symbol">Can not be null.</param> /// <param name="periodicity">Can not be null.</param> /// <param name="priceType"></param> /// <returns>Can not be null</returns> byte[] GetBarMetadataFile(string symbol, string periodicity, FxPriceType priceType) { var type = StorageConvert.ToPriceType(priceType); return(this.Attempt(this.DoGetBarMetadataFile, symbol, type, periodicity)); }
static void BackwardFillBars(IHistoryManager cache, string symbol, Periodicity periodicity, FxPriceType priceType, DateTime startTime, DateTime endTime, List<HistoryBar> bars) { ForwardFillBars(cache, symbol, periodicity, priceType, endTime, startTime, bars); bars.Reverse(); }
public List <HistoryBar> GetBarsHistory(string symbol, Periodicity periodicity, FxPriceType priceType, DateTime timestamp, int count) { BarsHistoryCache cache; try { _lock.EnterReadLock(); var key = new Tuple <string, Periodicity, FxPriceType>(symbol, periodicity, priceType); if (!_cachedBars.TryGetValue(key, out cache) || (cache == null)) { throw new HistoryNotFoundException(); } } finally { _lock.ExitReadLock(); } return(cache.GetHistory(timestamp, count)); }
static void ForwardFillBars(IHistoryManager cache, string symbol, Periodicity periodicity, FxPriceType priceType, DateTime startTime, DateTime endTime, ICollection <HistoryBar> bars) { try { for (var current = startTime; current < endTime;) { var report = cache.QueryBarHistory(current, -RequestedBarsNumber, symbol, periodicity.ToString(), priceType); var items = report.Items; foreach (var element in report.Items) { if (element.Time >= endTime) { return; } bars.Add(element); } if (items.Count == 0) { return; } current = items.Last().Time; current = current + periodicity; } } catch (StorageHistoryNotFoundException) { } }
static void BackwardFillBars(IHistoryManager cache, string symbol, Periodicity periodicity, FxPriceType priceType, DateTime startTime, DateTime endTime, List <HistoryBar> bars) { ForwardFillBars(cache, symbol, periodicity, priceType, endTime, startTime, bars); bars.Reverse(); }