示例#1
0
        public BarsHistoryCache(string symbol, Periodicity periodicity, FxPriceType priceType, QuoteHistoryClient historyClient) : base(symbol)
        {
            _historyClient = historyClient;

            Periodicity = periodicity;
            PriceType   = priceType;
        }
示例#2
0
        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);
		}
示例#3
0
 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);
     }
 }
示例#4
0
        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);
        }
示例#5
0
        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());
        }
示例#6
0
文件: SmartStorage.cs 项目: ifzz/FDK
        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)
            {
            }
        }
示例#7
0
        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);
        }
示例#8
0
		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);
			}
		}
示例#9
0
        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);
        }
示例#10
0
 public List <HistoryBar> QueryBarHistoryCache(DateTime to, int maxBars, string symbol, string periodicity, FxPriceType priceType)
 {
     throw new NotImplementedException();
 }
示例#11
0
        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));
        }
示例#12
0
        public MarketHistoryMetaFileReport QueryBarHistoryMetaFile(string symbol, string periodicity, FxPriceType priceType)
        {
            var result = new MarketHistoryMetaFileReport
            {
                FileBytes = this.GetBarMetadataFile(symbol, periodicity, priceType)
            };

            return(result);
        }
示例#13
0
        /// <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));
        }
示例#14
0
文件: SmartStorage.cs 项目: ifzz/FDK
 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();
 }
示例#15
0
        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));
        }
示例#16
0
        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)
            {
            }
        }
示例#17
0
 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();
 }