const axios = require("axios");
const BASE_URL = "https://api.binance.com";
async function getPrices(symbol) {
try {
const res = await axios.get(`${BASE_URL}/api/v3/klines`, {
params: { symbol, interval: "1m", limit: 100 },
});
return res.data.map((c) => parseFloat(c[4]));
} catch (err) {
console.dir(err, { depth: null });
return [];
}
}
getPrices("DOGEUSDT");
i’m always getting data: { error: 403 }
Hi @Zam-J_Id, are those 403s happening regularly or permanently? Have you checked if your IP is rate limited, due to a spam of requests?
data: { error: 403 }
because Binance is blocking your request — and this usually happens due to missing headers, incorrect domain, or rate-limiting! Binance’s public REST API requires a proper User-Agent header for some endpoints (especially /api/v3/klines) so… your current code is missing that.
Working Solution:
const axios = require(“axios”);
const BASE_URL = “https://api.binance.com”;
async function getPrices(symbol) {
try {
const res = await axios.get(${BASE_URL}/api/v3/klines
, {
headers: {
“User-Agent”: “Mozilla/5.0”,
},
params: {
symbol,
interval: “1m”,
limit: 100,
},
});
return res.data.map((c) => parseFloat(c[4])); // Closing price
} catch (err) {
console.dir(err.response?.data || err, { depth: null });
return ;
}
}
getPrices(“DOGEUSDT”).then((prices) => console.log(prices));
Hope it will helps!! Where you see square where it says return, in my code , you must replace the square with: brackets (left square bracket and right square bracket) but without space between them.