I am getting the candle stick values from binance api and print them like following.
for i in range(0, 10):
service = BinanceSpotService()
klines = service.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_15MINUTE)
print(klines[["date", "close"]].tail(2))
each loop prints the last two datas like this:
date close
498 2022-11-13 07:45:00 16774.99
499 2022-11-13 08:00:00 16769.12
date close
498 2022-11-13 07:45:00 16774.99
499 2022-11-13 08:00:00 16769.10
date close
498 2022-11-13 07:45:00 16774.99
499 2022-11-13 08:00:00 16772.34
date close
498 2022-11-13 07:45:00 16774.99
499 2022-11-13 08:00:00 16770.48
the last item date does not change but close values are different. Why is this so?
Short Anwer: The most recent kline is still constantly changing.
In your example, you do not pass any endTime
.
This gets then passed over to the Binance API. When there is no defined endTime
, the API will return the most recent klines.
If startTime and endTime are not sent, the most recent klines are returned.
Applied to your example:
You are getting the klines data multiple times in a loop. The most recent kline (klines[-1]
) is the one, which is constantly changing, because the time window is still open and therefore changes with every trade made.