币安API错误代码1102,未发送强制参数“时间戳”

编程入门 行业动态 更新时间:2024-09-25 18:32:27

币安API<a href=https://www.elefans.com/category/jswz/34/1771159.html style=错误代码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}&timestamp=${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,未发送强制参数“时间戳”

本文发布于:2024-06-16 04:43:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   参数   时间   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!