币安期货API:签名无效

问题描述 投票:0回答:1

我目前正在开发一个交易机器人来娱乐,但是当我想使用 axios 发送 POST 请求时,我收到以下错误作为响应:

{code: -1022, msg: 'Signature for this request is not valid.'}

我使用node.js加密包创建一个hmac sha256哈希,就像binance api文档和我见过的所有其他教程中提到的那样。

我也已经创建了一个新的 API,所以我的密钥和秘密是正确的!

这是代码:

let querystring = `symbol=LTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=0.05&price=${price}&recvWindow=5000&timestamp=${new Date().getTime()}`;
            let signature = crypto
                .createHmac('sha256', credentials.secret)
                .update(querystring)
                .digest('hex');

            axios
                .post(
                    `https://fapi.binance.com/fapi/v1/order?${querystring}&signature=${signature}`,
                    {},
                    {
                        headers: {
                            'X-MBX-APIKEY': credentials.key,
                            'content-type': 'application/x-www-form-urlencoded',
                        },
                    }
                )
                .then((response) => {
                    console.log(response.data);
                    resolve(response);
                })
                .catch(function (error) {
                    if (error.response) {
                        // Request made and server responded
                        console.log(error.response.data);
                        console.log(error.response.status);
                        console.log(error.response.headers);
                    } else if (error.request) {
                        // The request was made but no response was received
                        console.log(error.request);
                    } else {
                        // Something happened in setting up the request that triggered an Error
                        console.log('Error', error.message);
                    }
                });
javascript node.js cryptography binance
1个回答
0
投票

您可以在那里看到工作示例https://github.com/AndreyMashukov/go-crypto-bot/tree/main

© www.soinside.com 2019 - 2024. All rights reserved.