kline historical volumes mismatch

I’m comparing some kline data I retrieved from the API vs the historical kline data a few days later.
I retrieved the kline from the API every 1 minute.
Eg.
https://fapi.binance.com/fapi/v1/klines?symbol=BCHUSDT&interval=1m&startTime={query_start}&endTime={query_end}

query_start and query_end will specify a period over 5 minutes.

The issue I’m having is when I validate the volumes from bars I received from this api, it does not add up to those from https://data.binance.vision/?prefix=data/futures/um/daily/klines/BCHUSDT/15m/

As an example, I selected one of my 1m bars and summed up the previous 15 minutes worth of traded volume. With this bar’s closing time matching that from the historical data, I would expect the traded volumes to match, but they don’t.

Eg. For the date 2021-09-29 and bar time 1632700800000:
sum_of_1m_bar_base_volume = 1373.85
historical_volume = 5469.171

I can not understand why this is different.
What instrument(s) does the data from https://data.binance.vision/?prefix=data/futures/um/daily/klines/BCHUSDT/15m/ represent ? My understanding is this should be the perpetual future contract trading data. Is this correct ?

Hi.
Thanks for the investigation. We checked it from our end by summing up the records in 1m csv file and then comparing the records with 15 m csv file. The data matched. Please provide some raw data examples if we missed out anything.
Also, do note that when querying the API, it is possible to get the incomplete last candle stick. To prevent from this situation, please check if the query time is after the closing time of that candle stick.

Unfortunately I have not got the raw data atm. However I do believe I have it recorded correctly

See below:
Data I’ve captured

Expected data from 1m files snapshot

The start and end times as well as prices match perfectly with that of the 1m files.
However the volumes and trade count appear different over that same interval

Hi.
Is it possible for you to mark which rows are collected in a single API call and when did you query them?

Let me collect a new set of raw data. This should make comparison easier for us.
We can do a comparison in a few days when the historical data becomes available. Many thanks

I’ve found a few examples here. This time on the instrument BALUSDT:

GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346102519&endTime=1633346162744

RESPONSE [1633346160000, ‘21.690’, ‘21.690’, ‘21.690’, ‘21.690’, ‘0.0’, 1633346219999, ‘0.0000’, 0, ‘0.0’, ‘0.0000’, ‘0’]

GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346162744&endTime=1633346223285

[1633346220000, ‘21.713’, ‘21.713’, ‘21.713’, ‘21.713’, ‘1.5’, 1633346279999, ‘32.5695’, 1, ‘0.0’, ‘0.0000’, ‘0’]

GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346283620&endTime=1633346343852
[1633346340000, ‘21.738’, ‘21.738’, ‘21.732’, ‘21.735’, ‘4.9’, 1633346399999, ‘106.5015’, 4, ‘0.7’, ‘15.2145’, ‘0’]

These 1m bars received do not seem to match that of https://data.binance.vision/data/futures/um/daily/klines/BALUSDT/1m/BALUSDT-1m-2021-10-04.zip

Would you know why this is ?

Hi. May I know how and when did you query the API?

We use curl to query and the results are different from what you provided. But it’s consistent with the csv file.

// command
curl https://fapi.binance.com/fapi/v1/klines\?symbol\=BALUSDT\&interval\=1m\&startTime\=1633346102519\&endTime\=1633346162744

// result
[[1633346160000,"21.689","21.720","21.662","21.708","490.2",1633346219999,"10632.5637",89,"415.5","9012.4873","0"]]

// command
curl https://fapi.binance.com/fapi/v1/klines\?symbol\=BALUSDT\&interval\=1m\&startTime\=1633346162744\&endTime\=1633346223285

// result
[[1633346220000,"21.713","21.727","21.705","21.723","241.6",1633346279999,"5247.3345",76,"174.8","3796.9177","0"]]

// command
curl https://fapi.binance.com/fapi/v1/klines\?symbol\=BALUSDT\&interval\=1m\&startTime\=1633346283620\&endTime\=1633346343852 
// result
[[1633346340000,"21.738","21.751","21.731","21.749","552.3",1633346399999,"12010.7050",62,"450.1","9788.5735","0"]]

Thanks for the response. I’ve attached the query log lines. Log line times are in Sydney Australia time zone.

[22:16:02.744] [INFO] [request ] GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346102519&endTime=1633346162744

[22:17:03.285] [INFO] [request ] GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346162744&endTime=1633346223285 retries=0

[22:18:03.620] [INFO] [request ] GET https://fapi.binance.com/fapi/v1/klines?symbol=BALUSDT&interval=1m&startTime=1633346223285&endTime=1633346283620 retries=0

Now the thing is very clear. The time you queried the API is earlier than the end time of that candle stick.
For example, 22:16:02.744 Sydney time is earlier than 1633346219999 UTC timestamp. The time you collect the data is too early to have every trade included inside. I would suggest you to query 2 candle sticks at a time but discard the latest candle stick to prevent from the same situation. Alternatively, you can subscribe the websocket market data stream. ( https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-streams )

1 Like

That explains it - many thanks. Much appreciated