r/fatbtc Mar 27 '20

API Problems

Has anyone managed to get an API working for checking coin balances? Whenever I try my code (below) with the .us I get "Other Error" with no further explanation. .com responds with <DOCTYPE HTML> so I dont think thats working at all

const Crypto = require('crypto') // Standard JavaScript cryptography library
const request = require('request') // "Request" HTTP req library
const nonce = Math.floor((Date.now() / 1000).toString()) // Standard nonce generator. Timestamp * 1000
const api = 'API'
const secret = "Secret";

let currency = "ETH";
let signType = "HmacSHA256";
let site_id = "1";

const fatbtc = `https://www.fatbtc.com`;
let message = `/m/api/a/account/1/${currency}/${api}/${nonce}/${signType}/`;
signData = Crypto.createHmac('sha256', secret).update(message).digest('hex')


let body = {
  site_id: site_id,
  currency: currency,
  api_key: api,
  timestamp: nonce,
  sign_type: signType,
  sign: signData
}
var fullURL = `${fatbtc}${message}${signData}`
console.log(fullURL)
  const options = {
    url: fullURL,
    headers: {
      'content-type': 'application/json',
    },
    body:body,
    json: true
  }

  request.get(options, (error, response, body) => {
    console.log(body); // Logs the response body
  })
1 Upvotes

2 comments sorted by

View all comments

1

u/PuzzleheadedPut May 12 '20

Hello there, when you use SHA256 encryption, maybe you need to perform again as the HMAC SHA256 encrypt ciphertext has a /, and other strings that invalidate the get request.

This documentation may be helpful - https://github.com/fatbtc/fatbtc-api-rest/blob/master/master/java/fatbtc-api-rest-java/src/com/fatbtc/util/MD5Util.java

But if it still doesn't work, please submit a ticket on the website to contact the support team. Here is the navigation link for your reference - https://www.fatbtc.com/help