コード例 #1
0
        public Bar[] GetBars(string symbol, PriceType priceType, BarPeriod period, DateTime startTime, DateTime endTime)
        {
            try
            {
                var forexPeriodicity = StorageConvert.ToPeriodicity(period);
                var forexPriceType   = StorageConvert.ToFxPriceType(priceType);
                var manager          = this.storage.GetOrCreateHistoryManager(symbol);

                if (this.source != null)
                {
                    // online mode
                    if (!manager.BarsAreSynchronized(this.source, symbol, forexPeriodicity, forexPriceType, startTime, endTime, false))
                    {
                        manager.SynchronizeBars(this.source, symbol, forexPeriodicity, forexPriceType, startTime, endTime, false, NullCallback);
                    }
                }

                var bars = new List <HistoryBar>();
                if (startTime < endTime)
                {
                    ForwardFillBars(manager, symbol, forexPeriodicity, forexPriceType, startTime, endTime, bars);
                }
                else
                {
                    BackwardFillBars(manager, symbol, forexPeriodicity, forexPriceType, startTime, endTime, bars);
                }

                var result = bars.Select(o => StorageConvert.ToBar(o, period)).ToArray();
                return(result);
            }
            catch (StorageHistoryNotFoundException ex)
            {
                throw new HistoryNotFoundException("GetBars", ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// The method synchronizes bars.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="priceType"></param>
        /// <param name="period"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public void Synchronize(string symbol, PriceType priceType, BarPeriod period, DateTime startTime, DateTime endTime)
        {
            if (this.source == null)
            {
                throw new InvalidOperationException("Can't synchronize in offline mode.");
            }

            var manager     = this.GetOrCreateHistoryManager(symbol);
            var periodicity = StorageConvert.ToPeriodicity(period);
            var fxPriceType = StorageConvert.ToFxPriceType(priceType);

            manager.SynchronizeBars(this.source, symbol, periodicity, fxPriceType, startTime, endTime, false, NullCallback);
        }
コード例 #3
0
        /// <summary>
        /// Imports bars to storage.
        /// </summary>
        /// <param name="symbol">Symbol of importing bars</param>
        /// <param name="period">Period of importing bars</param>
        /// <param name="bars">Importing bars</param>
        /// <param name="priceType">Price type of importing bars</param>
        /// <param name="overwriteBarChainsWithEqualTime"></param>
        public void Import(string symbol, BarPeriod period, IEnumerable <Bar> bars, PriceType priceType, bool overwriteBarChainsWithEqualTime)
        {
            var provider    = this.GetOrCreateHistoryManager(symbol);
            var fxPeriod    = StorageConvert.ToPeriodicity(period);
            var fxPriceType = StorageConvert.ToFxPriceType(priceType);
            var fxBars      = bars.Select(StorageConvert.ToHistoryBar);

            provider.ImportBars(
                fxBars,
                symbol,
                fxPeriod,
                fxPriceType,
                true,
                overwriteBarChainsWithEqualTime ? BarsImportRules.Replace : BarsImportRules.Skip,
                null
                );
        }
コード例 #4
0
        public HistoryInfo GetBarsInfo(string symbol, PriceType priceType, BarPeriod period)
        {
            try
            {
                var source      = this.GetRemoteOrLocalSource(symbol);
                var periodicity = StorageConvert.ToPeriodicity(period);
                var priceTypeEx = StorageConvert.ToFxPriceType(priceType);
                var info        = source.GetBarsHistoryInfo(symbol, periodicity, priceTypeEx);

                var result = new HistoryInfo(info.AvailableFrom.Value, info.AvailableTo.Value);
                return(result);
            }
            catch (StorageHistoryNotFoundException ex)
            {
                throw new HistoryNotFoundException("GetBarsInfo", ex);
            }
        }