Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BybitRestClientApi.GetKlinesAsync() erroneously sets ExchangeWebResult.NextPageToken to null #254

Closed
vladimir-range opened this issue Feb 19, 2025 · 1 comment

Comments

@vladimir-range
Copy link

vladimir-range commented Feb 19, 2025

NextPageToken is set to null when the number of klines returned is less than the number requested. It should be set to null when the number returned is 0, because entries for some timestamps are missing on the server.

to reproduce run the following:

using Bybit.Net;
using Bybit.Net.Clients;
using CryptoExchange.Net.SharedApis;
using System.Diagnostics;

SharedSymbol symbol = new(TradingMode.Spot, "BTC", "USDT");
BybitRestClient restClient = new(options => {options.Environment = BybitEnvironment.Testnet;});

var klineClient = restClient.V5Api.SharedClient;
var interval = SharedKlineInterval.OneMinute;
var limit = klineClient.GetKlinesOptions.MaxLimit;


DateTime endTime = new(2022, 9, 9, 17, 14, 0, DateTimeKind.Utc);
GetKlinesRequest request = new(symbol, interval, endTime: endTime, limit: limit);
var res = await klineClient.GetKlinesAsync(request);
Debug.Assert(res.NextPageToken == null);

var data = res.Data.ToArray();
Debug.Assert(data.Length == 995); // less than 1000 entries has been retrieved
Debug.Assert(data[657].OpenTime == new DateTime(2022, 9, 9, 6, 17, 0, DateTimeKind.Utc));
Debug.Assert(data[658].OpenTime == new DateTime(2022, 9, 9, 6, 11, 0, DateTimeKind.Utc)); // 5 entries are missing (12-16 minutes), so Data contains fewer entries

endTime = data[994].OpenTime.AddMinutes(-1);
request = new(symbol, interval, endTime: endTime, limit: limit);
res = await klineClient.GetKlinesAsync(request);
Debug.Assert(res.Data.Count() == 1000); // however there are more records on the server
@JKorf
Copy link
Owner

JKorf commented Feb 19, 2025

Hi, thanks for the clear reproduction scenario. It's a bit weird that there is no data there, but nevertheless I've updated the logic in the latest version to work correctly.

@JKorf JKorf closed this as completed Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants