protected virtual async Task <WebCallResult <BtcTurkKline[]> > GetPriceGraphHistoryCoreAsync(string endpoint, string symbol, BtcTurkPeriod period, DateTime?startTime = null, DateTime?endTime = null, CancellationToken ct = default) { var parameters = new Dictionary <string, object> { { "symbol", symbol }, { "resolution", JsonConvert.SerializeObject(period, new PeriodEnumConverter(false)) } }; parameters.AddOptionalParameter("from", startTime != null ? startTime.Value.ToUnixTimeSeconds().ToString() : "1"); parameters.AddOptionalParameter("to", endTime != null ? endTime.Value.ToUnixTimeSeconds().ToString() : DateTime.UtcNow.ToUnixTimeSeconds().ToString()); var result = await SendRequest <BtcTurkKlineData>(GetUrl(endpoint, PublicVersion), method : HttpMethod.Get, cancellationToken : ct, parameters : parameters, checkResult : false).ConfigureAwait(false); if (!result.Success || result.Data == null || result.Data.Times == null || result.Data.Opens == null || result.Data.Highs == null || result.Data.Lows == null || result.Data.Closes == null || result.Data.Volumes == null) { return(new WebCallResult <BtcTurkKline[]>(result.ResponseStatusCode, result.ResponseHeaders, null, result.Error)); } // Parse Result List <BtcTurkKline> response = new List <BtcTurkKline>(); var maxRows = Math.Min(result.Data.Times.Length, result.Data.Opens.Length); maxRows = Math.Min(maxRows, result.Data.Highs.Length); maxRows = Math.Min(maxRows, result.Data.Lows.Length); maxRows = Math.Min(maxRows, result.Data.Closes.Length); maxRows = Math.Min(maxRows, result.Data.Volumes.Length); for (int i = 0; i < maxRows; i++) { response.Add(new BtcTurkKline { OpenDateTime = result.Data.Times[i].FromUnixTimeSeconds(), Open = result.Data.Opens[i], High = result.Data.Highs[i], Low = result.Data.Lows[i], Close = result.Data.Closes[i], Volume = result.Data.Volumes[i], }); } return(new WebCallResult <BtcTurkKline[]>(result.ResponseStatusCode, result.ResponseHeaders, response.ToArray(), null)); }
public async Task <WebCallResult <BtcTurkKline[]> > GetPriceGraphMobileHistoryAsync(string symbol, BtcTurkPeriod period, DateTime?startTime = null, DateTime?endTime = null, CancellationToken ct = default) => await GetPriceGraphHistoryCoreAsync(PriceGraph_MobileHistory_Endpoint, symbol, period, startTime, endTime, ct);
public async Task <CallResult <UpdateSubscription> > SubscribeToKlinesAsync(string symbol, BtcTurkPeriod period, Action <BtcTurkStreamKline> onData) { var request = new BtcTurkSocketRequest(151, "tradeview", $"{symbol}_{JsonConvert.SerializeObject(period, new PeriodEnumConverter(false))}", true); var internalHandler = new Action <BtcTurkSocketResponse>(data => onData(JsonConvert.DeserializeObject <BtcTurkStreamKline>(data.Data))); return(await Subscribe(request.RequestObject(), null, false, internalHandler).ConfigureAwait(false)); }
public WebCallResult <BtcTurkKline[]> GetPriceGraphMobileHistory(string symbol, BtcTurkPeriod period, DateTime?startTime = null, DateTime?endTime = null, CancellationToken ct = default) => GetPriceGraphMobileHistoryAsync(symbol, period, startTime, endTime, ct).Result;
public CallResult <UpdateSubscription> SubscribeToKlines(string symbol, BtcTurkPeriod period, Action <BtcTurkStreamKline> onData) => SubscribeToKlinesAsync(symbol, period, onData).Result;