错误代码1102,未发送强制参数“时间戳”"/>
币安API错误代码1102,未发送强制参数“时间戳”
我正在尝试使用 Binance API 在 Linux 服务器上进行交易。
我不知道我的代码有什么问题。
我确实发送了时间戳,但仍然出现错误。
(我知道我可以使用ccxt,但想知道为什么会出现这个错误)
我收到此错误:
{
code: -1102,
msg: "Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."
}
API文档
下面是我的代码,谢谢
// settings
const setting = require('./json/binance.json');
// packages
const axios = require('axios');
const crypto = require('crypto');
const apiKey = setting.apiKey;
const apiSecret = setting.secret;
// Headers
const headers = {
'X-MBX-APIKEY': apiKey,
};
// Signature
function generateSignature(params) {
return crypto.createHmac('sha256', apiSecret).update(params).digest('hex');
}
function placeFuturesOrder(req) {
const symbol = req.body.symbol;
const side = req.body.side;
const type = 'MARKET';
const quantity = req.body.amount
const baseUrl = '';
const endpoint = '/fapi/v1/order';
const timestamp = Date.now();
const params = `symbol=${symbol}&side=${side}&type=${type}&quantity=${quantity}×tamp=${timestamp}`;
const signature = generateSignature(params);
const postData = {
symbol,
side,
type,
quantity,
timestamp,
signature,
};
return axios.post(baseUrl + endpoint, postData, { headers });
}
回答如下:
尝试将所有参数放入 url 中,应该可以。 您可以从此 github 代码片段中看到示例 https://github/binance/binance-signature-examples/blob/master/python/futures/um_futures.py#L116
更多推荐
币安API错误代码1102,未发送强制参数“时间戳”
发布评论