I would like to add another solution which handles the connection and configuration part under the hood.
Using Mida, a JavaScript framework for connecting to exchanges/brokers to get data and/or trade automatically.
https://github.com/Reiryoku-Technologies/Mida
First we need to login to Binance
import { login, } from "@reiryoku/mida";
const myAccount = await login("Binance/Spot", {
apiKey: "***",
apiSecrect: "***",
});
Then to watch ETHUSDT live prices and candles we just use the market watcher API
import { MidaMarketWatcher, MidaTimeframe, } from "@reiryoku/mida";
const marketWatcher = new MidaMarketWatcher({ tradingAccount: myAccount, });
await marketWatcher.watch("ETHUSDT", {
watchPeriods: true,
timeframes: [ MidaTimeframe.M30, ],
});
// Listen M30 candlesticks being closed
marketWatcher.on("period-close", (event) => {
const candle = event.descriptor.period;
console.log("M30 candle closed at " + candle.close);
});