示例#1
0
        public async Task <List <PriceBar> > GetPriceBars(List <Tuple <string, EGranularity> > barSpecsList, int count, ECandleFormat priceFormat = ECandleFormat.midpoint)
        {
            List <PriceBar> bars = new List <PriceBar>();

            foreach (var spec in barSpecsList)
            {
                Func <CandlesRequest> request = () => new CandlesRequest
                {
                    instrument   = spec.Item1,
                    granularity  = spec.Item2,
                    candleFormat = priceFormat,
                    count        = count
                };

                List <Candle> pollCandles = null;

                pollCandles = await Rest.GetCandlesAsync(request());

                if (pollCandles != null && pollCandles.Count > 0)
                {
                    pollCandles.OrderBy(c => Convert.ToDateTime(c.time).ToUniversalTime());

                    foreach (var candle in pollCandles)
                    {
                        var bar = new PriceBar()
                        {
                            instrument = spec.Item1, granularity = spec.Item2.ToString()
                        };
                        bar.InjectWith(candle, false);
                        bars.Add(bar);
                    }
                }
            }

            return(bars);
        }
示例#2
0
        /// <summary>
        /// Downloads a list of bars at the requested resolution from a starting datetime
        /// </summary>
        /// <param name="oandaSymbol">The Oanda symbol</param>
        /// <param name="startUtc">The starting time (UTC)</param>
        /// <param name="barsPerRequest">The number of bars requested (max=5000)</param>
        /// <param name="granularity">The granularity (Oanda resolution)</param>
        /// <param name="candleFormat">The Oanda candle format (bidask or midpoint)</param>
        /// <returns>The list of candles/bars</returns>
        public List <Candle> DownloadBars(string oandaSymbol, string startUtc, int barsPerRequest, EGranularity granularity, ECandleFormat candleFormat)
        {
            var request = new CandlesRequest
            {
                instrument   = oandaSymbol,
                granularity  = granularity,
                candleFormat = candleFormat,
                count        = barsPerRequest,
                start        = Uri.EscapeDataString(startUtc)
            };

            return(GetCandles(request));
        }
示例#3
0
        private IEnumerable <Candle> GetCandles(string oandaSymbol, string startUtc, int barsPerRequest, Resolution resolution, ECandleFormat candleFormat)
        {
            var request = new CandlesRequest
            {
                instrument   = oandaSymbol,
                granularity  = ToGranularity(resolution),
                candleFormat = candleFormat,
                count        = barsPerRequest,
                start        = Uri.EscapeDataString(startUtc)
            };

            return(GetCandles(request));
        }
示例#4
0
        public async Task <List <PriceBar> > GetPriceBars(List <Tuple <string, EGranularity> > barSpecsList, int count, ECandleFormat priceFormat = ECandleFormat.midpoint)
        {
            List <PriceBar> bars = null;

            if (_apiConnectionStatus == ApiConnectionStatus.Connected || _apiConnectionStatus == ApiConnectionStatus.Streaming)
            {
                try
                {
                    bars = await RatesDataSource.Instance.GetPriceBars(barSpecsList, count);
                }
                catch (Exception e)
                {
                    OnConnectionStatusChanged(ApiConnectionStatus.Faulted, null);

                    // try to recover
                    RecoverApiConnection("DataManager did not receive bars from RatesDataSource.", null);

                    return(null);
                }
            }

            return(bars);
        }