Hi guys, i am experiencing issues with server timestamp when i call the accountInfo function but not when i call the trade function. can someone help me figure out what is wrong?
Hi guys, thanks for coming around to help, i realised i was not using the right library. however now i am doing it with the correct one, i am still struggling to get the data like i want to.
export async function GET() {
const res = await fetch('https://api.binance.com/api/v3/account', {
headers: {
'Content-Type': 'application/json',
'API-Key': apiKey,
'API-Secret': apiSecret,
'signature': null,
'timestamp': Date.now(),
'recvWindow': '60000'
},
});
const data = await res.json();
return NextResponse.json({ data });
}
i get error message data": {
“code”: -1102,
“msg”: “Mandatory parameter ‘signature’ was not sent, was empty/null, or malformed.”
} any clue of what value is expected in signature, please?
Binance has a connector library for Node.js (@binance/connector), but it won’t work on the Web. You’ll need to use Web Cryptography API for signatures.
i did refer to the documentation Binance signature documentation link for signature then implemented it as below however i am having error message ““data”: {
“code”: -1102,
“msg”: “Mandatory parameter ‘signature’ was not sent, was empty/null, or malformed.”
}”
export async function GET() {
if (!apiSecret) {
throw new Error('API secret is not defined!');
}
const timestamp = Date.now();
const signature = (timestamp:any) => {
return crypto.createHmac('sha256', apiSecret)
.update(`timestamp=${timestamp}`)
.digest('hex');
}
const computedSignature = signature(timestamp);
console.log(typeof(computedSignature))
console.log("hashing the string: ");
console.log(`timestamp=${timestamp}`);
console.log("and return:");
const res = await fetch('https://api.binance.com/api/v3/account', {
headers: {
'Content-Type': 'application/json',
'API-Key': apiKey,
'X-MBX-APIKEY': apiSecret,
'signature': computedSignature,
'recvWindow': '60000'
},
});
const data = await res.json();
return NextResponse.json({ data });
}```
These parameters should be passed in the query string, not as headers. Add them to the URL. You also need to include timestamp as a parameter, and sign all the parameters.