【发布时间】:2021-08-04 04:12:37
【问题描述】:
我正在尝试使用 Binance API 创建测试订单,但我收到此错误消息 msg:“此请求的签名无效。”我尝试使用密钥和 timestamp = Date.now() 获取签名,但没有成功。 我的代码是:
const credentials = require('./credentials');
const crypto = require('crypto');
function testNewOrder(symbol,side,type,timeInForce,quantity,price) {
const url = credentials.urlTest;
let timeStamp = Date.now();
let signature = crypto.createHmac('sha256', credentials.secretKeyTest).update(`timestamp=${timeStamp}`).digest('hex')
console.log(signature,timeStamp,timeStamp2);
fetch(`${url}/api/v3/order/test?symbol=${symbol}&side=${side}&type=${type}&timeInForce=${timeInForce}&quantity=${quantity}&price=${price}×tamp=${timeStamp}&signature=${signature}`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"X-MBX-APIKEY": credentials.apiKeyTest
},
}).then(response => {
return response.json();
}).then( data=> {
console.log(data);
}).catch(err => {
console.log(err)
})
}
testNewOrder('BTCUSDT','SELL','LIMIT','GTC','0.02','42000');
【问题讨论】:
-
您是否有权访问说明如何创建此签名的文档?你见过github.com/binance-exchange/binance-signature-examples 准确地显示了你需要做什么,即签署整个“消息”而不仅仅是时间戳部分
-
另外,在币安网站 binance-docs.github.io/apidocs/spot/en/… 上有很好的记录 - 不知道你为什么只签署时间戳
-
@Bravo 我阅读了整个文档,我相信我正在做 node.js 文件夹 link 中显示的确切内容。
credentials.secretKeyTest有我的 apiSecret。 -
TL;DR - 做记录在案的 here 而不是一些一般解释这个概念的随机 github 页面
-
这不是一个随机存储库!是官方的。确实是您在第一条评论中发给我的那个。
标签: javascript node.js binance