【问题标题】:Invalid signature : FTX GET wallet/balances无效签名:FTX GET 钱包/余额
【发布时间】:2022-06-30 12:20:37
【问题描述】:

我收到了 /wallet/balances 的错误 data: { success: false, error: 'Not logged in: Invalid signature' }。有趣的是,对于 FTX REST API 的 /wallet/coins 和 /markets 运行相同的代码。代码在 JS 中 请帮忙!!

  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)
  })

【问题讨论】:

    标签: javascript node.js rest cryptojs hmac


    【解决方案1】:

    在标题中添加这两行,

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

    它对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2021-03-23
      • 2021-08-31
      • 1970-01-01
      • 2022-09-26
      • 2019-10-11
      • 1970-01-01
      相关资源
      最近更新 更多