首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无效签名: FTX获取钱包/余额

无效签名: FTX获取钱包/余额
EN

Stack Overflow用户
提问于 2022-03-14 18:09:27
回答 1查看 545关注 0票数 1

我得到了错误的data: { success: false, error: 'Not logged in: Invalid signature' } /钱包/余额。有趣的是,相同的代码运行于/钱包/硬币和FTX的/markets。代码在JS中,请帮助!!

代码语言:javascript
复制
  const url = "https://ftx.us/api/wallet/balances" 
  const path = "/api/wallet/balances"
  const timestamp = Date.now()
  const method = "GET"
  const payload = `{timestamp}{method}{url}`
  const hash = CryptoJS.HmacSHA256(payload, process.env.FTX_API_SECRET)
  // var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, "Secret Passphrase");
  // hmac.update(JSON.stringify(timestamp));
  // hmac.update(method);
  // hmac.update(path);
  // var hash = hmac.finalize();
  const hash2 = crypto.createHmac('sha256', process.env.FTX_API_SECRET).update(payload).digest("hex")
  console.log("API KEY ", process.env.FTX_API_KEY)
  axios({
      method: "get",
      headers: {
          "FTXUS-SIGN": CryptoJS.enc.Hex.stringify(hash),
          // "FTXUS-SIGN": hash2,
          "FTXUS-KEY": process.env.FTX_API_KEY,
          "FTXUS-TS": timestamp,
      },
      url: url
  })
  .then( (response) => {
      if (response.data.success) {
          callback(null, response.data.result)
      } else {
          // error handling here for the api 
          callback(result.data.error)
      }
      
  })
  .catch ( (e) => {
      console.log("exception in request ", e)
  })
EN

回答 1

Stack Overflow用户

发布于 2022-06-30 04:20:37

将这2行添加到标题中,

代码语言:javascript
复制
{
   "FTXUS-SIGN": CryptoJS.enc.Hex.stringify(hash),
   "FTXUS-KEY": process.env.FTX_API_KEY,
   "FTXUS-TS": timestamp,
   "Content-Type": "application/json",
   "Accepts": "application/json",
 }

对我来说很管用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71472343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档