Kline for the last X intervals?

Hi,

I’m using WebSocket to retrieve in real time Kline for a given Symbol, this way:

webSocket = async () => {
	const instrument = "BTCUSDT";
	const interval = "15m";

	const ws = new WebSocket("wss://stream.binance.com:9443/ws/" + instrument.toLowerCase() + "@kline_" + interval);
	ws.on('message', function incoming(response) {
		let data = JSON.parse(response);
		let instrumentName = data.k.s;
		let time = moment(data.k.t).format('YYYY-MM-DD HH:mm:ss');
		let closeValue = data.k.c

		console.log(time + " - " + instrumentName + " - " + closeValue);

	});
}

It works nice, but return only the “last” 15 min step. What if I need the last 12’s 15min? i.e. the Kline of the last hour (one for each interval).

Is it possible with WebSocket?

Thanks

Restful kline endpoint is what you are looking for.

It can only take one symbol at time.
If I need all it will take long time to download them.

Also rest are very limited on ip request…

Tried now with REST API without any ms interval.
It tooks 4 minutes for 650 symbols… :open_mouth:

If you wish to download historical klines, then you should check this gem:

https://data.binance.vision

Uhm… not sure how this would help.

Daily is the previous day right? So if I need klines of last hour (and update from that point with stream), I won’t get any data :frowning:

Can’t get “Daily” and “Current day”? Or at least last 24h?

I mean, I can (today, 2022/06/30) only do:
https://data.binance.vision/data/spot/daily/klines/BTCUSDT/1h/BTCUSDT-1h-2022-06-29.zip
https://data.binance.vision/data/spot/monthly/klines/BTCUSDT/1h/BTCUSDT-1h-2022-05.zip

So not data of today… which is useless…

then you will need to download by yourself from the restful endpoints.