/// <summary> /// Downloads a block of 5-second bars from a starting datetime /// </summary> /// <param name="symbol"></param> /// <param name="start"></param> /// <param name="barsPerRequest"></param> /// <returns></returns> private static async Task <List <Candle> > DownloadBars(string symbol, string start, int barsPerRequest) { if (_settings.EnableTrace) { Console.WriteLine("Requesting {0} bars for {1} from {2}", barsPerRequest, symbol, start); } var request = new CandlesRequest { instrument = symbol, granularity = EGranularity.S5, candleFormat = ECandleFormat.midpoint, count = barsPerRequest, start = Uri.EscapeDataString(start) }; var bars = await Rest.GetCandlesAsync(request); if (_settings.EnableTrace) { if (bars.Count > 0) { Console.WriteLine("Received {0} bars: {1} to {2}", bars.Count, bars[0].time, bars[bars.Count - 1].time); } else { Console.WriteLine("Received 0 bars"); } } return(bars); }
/// <summary> /// More detailed request to retrieve candles /// </summary> /// <param name="request">the request data to use when retrieving the candles</param> /// <returns>List of Candles received (or empty list)</returns> public static async Task <List <Candle> > GetCandlesAsync(CandlesRequest request) { string requestString = Server(EServer.Rates) + request.GetRequestString(); CandlesResponse candlesResponse = await MakeRequestAsync <CandlesResponse>(requestString); List <Candle> candles = new List <Candle>(); candles.AddRange(candlesResponse.candles); return(candles); }
/// <summary> /// More detailed request to retrieve candles /// </summary> /// <param name="request">the request data to use when retrieving the candles</param> /// <returns>List of Candles received (or empty list)</returns> internal static List <Candle> GetCandles(CandlesRequest request) { string requestString = Server(EServer.Rates) + request.GetRequestString(); var candles = new List <Candle>(); CandlesResponse candlesResponse = MakeRequest <CandlesResponse>(requestString); candles.AddRange(candlesResponse.Candles); return(candles); }
/// <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> /// <returns>The list of candles/bars</returns> public List <Candle> DownloadBars(string oandaSymbol, string startUtc, int barsPerRequest, EGranularity granularity) { var request = new CandlesRequest { instrument = oandaSymbol, granularity = granularity, candleFormat = ECandleFormat.midpoint, count = barsPerRequest, start = Uri.EscapeDataString(startUtc) }; return(GetCandles(request)); }
/// <summary> /// More detailed request to retrieve candles /// </summary> /// <param name="request">the request data to use when retrieving the candles</param> /// <returns>List of Candles received (or empty list)</returns> public static List <Candle> GetCandles(CandlesRequest request) { string requestString = Credentials.GetDefaultCredentials().GetServer(EServer.Rates) + request.GetRequestString(); CandlesResponse candlesResponse = MakeRequest <CandlesResponse>(requestString); List <Candle> candles = new List <Candle>(); if (candlesResponse != null) { candles.AddRange(candlesResponse.candles); } return(candles); }
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)); }
/// <summary> /// More detailed request to retrieve candles /// </summary> /// <param name="request">the request data to use when retrieving the candles</param> /// <returns>List of Candles received (or empty list)</returns> public List <Candle> GetCandles(CandlesRequest request) { var requestString = EndpointResolver.ResolveEndpoint(_environment, Server.Rates) + request.GetRequestString(); var candlesResponse = MakeRequest <CandlesResponse>(requestString); var candles = new List <Candle>(); if (candlesResponse != null) { candles.AddRange(candlesResponse.candles); } return(candles); }
public override async Task <CandlesResponse> GetCandles(CandlesRequest request, ServerCallContext context) { var candles = await _candlesHistoryService.GetCandlesHistoryAsync( request.AssetPairId, _mapper.Map <CandlePriceType>(request.Type), _mapper.Map <CandleTimeInterval>(request.Interval), request.From.ToDateTime().ToUniversalTime(), request.To.ToDateTime().ToUniversalTime()); var result = new CandlesResponse { Body = new CandlesResponse.Types.Body() }; result.Body.Candles.AddRange(_mapper.Map <List <Candle> >(candles.History)); return(result); }
public override async Task <CandlesResponse> GetCandles(CandlesRequest request, ServerCallContext context) { var symbol = request.AssetPairId; TimeSpan delta; const int defaultCountOfCandle = 1000; AntaresClientApi.Database.CandleData.Models.CandleType interval; switch (request.Interval) { //todo: implement other candle intervals; //case CandleInterval.Min5: delta = TimeSpan.FromMinutes(5); break; //case CandleInterval.Min15: delta = TimeSpan.FromMinutes(15); break; //case CandleInterval.Min30: delta = TimeSpan.FromMinutes(30); break; case CandleInterval.Hour: delta = TimeSpan.FromHours(1); interval = CandleType.Hour; break; //case CandleInterval.Hour4: delta = TimeSpan.FromHours(4); break; //case CandleInterval.Hour6: delta = TimeSpan.FromHours(6); break; //case CandleInterval.Hour12: delta = TimeSpan.FromHours(12); break; case CandleInterval.Day: delta = TimeSpan.FromDays(1); interval = CandleType.Day; break; //case CandleInterval.Week: delta = TimeSpan.FromDays(7); break; case CandleInterval.Month: delta = TimeSpan.FromDays(30); interval = CandleType.Month; break; default: { var response = new CandlesResponse(); return(response); } } var toDate = DateTime.UtcNow; var fromDate = toDate.AddSeconds(-delta.TotalSeconds * defaultCountOfCandle); if (request.From != null && request.To != null) { fromDate = request.From.ToDateTime(); toDate = request.To.ToDateTime(); } else if (request.From != null) { fromDate = request.From.ToDateTime(); toDate = fromDate.AddSeconds(delta.Seconds * defaultCountOfCandle); } else if (request.To != null) { toDate = request.To.ToDateTime(); fromDate = toDate.AddSeconds(-delta.Seconds * defaultCountOfCandle); } //todo: implement different charts for ask\bid\mig\trade //request.Type try { var candles = await _marketDataService.GetCandles(request.AssetPairId, fromDate, toDate, interval); var result = new CandlesResponse { Candles = { candles.OrderBy(c => c.Time) .Select(c => new Candle { Timestamp = Timestamp.FromDateTime(DateTime.SpecifyKind(c.Time, DateTimeKind.Utc)), Volume = "0", OppositeVolume = "0", Open = c.Open.ToString(CultureInfo.InvariantCulture), Close = c.Close.ToString(CultureInfo.InvariantCulture), High = c.High.ToString(CultureInfo.InvariantCulture), Low = c.Close.ToString(CultureInfo.InvariantCulture), LastPrice = c.Close.ToString(CultureInfo.InvariantCulture) }) } }; return(result); } catch (Exception ex) { Console.WriteLine(ex); throw; } }