/// <summary> /// Retrives candlestick data between two dates given a symbol id /// </summary> /// <param name="id">Symbol ID number</param> /// <param name="start">Start date</param> /// <param name="end">End Date</param> /// <param name="gran">Data granularity</param> /// <param name="cancellationTokenSource">Cancellation token source</param> /// <param name="cancellationTokenSourceList">Cancellation token sourc list. Will remove cancelation token from list once finished canceling.</param> public void GetCandlesAsync(string id, DateTime start, DateTime end, HistoricalGrandularity gran, CancellationTokenSource cancellationTokenSource) { CancellationToken ct = cancellationTokenSource.Token; Task.Run(() => { ct.ThrowIfCancellationRequested(); var obj = ApiGet <Candles>(apiClient, string.Format("v1/markets/candles/{0}?startTime={1}&endTime={2}&interval={3}", id, DateTimeToString(start), DateTimeToString(end), gran.ToString()), ct); //obj.Wait(ct); if (obj.isSuccess && !ct.IsCancellationRequested) { var arg = new APICandleReturnArgs(); arg.candles = obj.q_obj; arg.NumCallsLeft = obj.NumCallsLeft; arg.RateReset = obj.RateReset; arg.id = int.Parse(id); arg.startTime = start; arg.endTime = end; arg.interval = gran; OnCandleRecieved(this, arg); } }, ct); }
private static void QTrade_OnCandleRecieved(object sender, APICandleReturnArgs e) { var candleReq = e.candles; Console.WriteLine("\nOpen\tHigh\tLow\tClose\tVolume\n--------------------------------------------------------------"); for (int i = 0; i < candleReq.candles.Length; i++) { Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t", candleReq.candles[i].open, candleReq.candles[i].high, candleReq.candles[i].low, candleReq.candles[i].close, candleReq.candles[i].volume)); } }