bitforexapi / API_Doc_en

BitForex API Document
12 stars 9 forks source link

Node JS SignData Invalid for API placeOrder #15

Open BronacusAmmon opened 4 years ago

BronacusAmmon commented 4 years ago

Hello, Im trying to make a trading API for Bitforex but I am running into signData invalid problem, I see this thread https://github.com/bitforexapi/API_Doc_en/issues/10 had a similar problem and a poster recommended re-ordering the parameters, I tried alphabetizing and encodingURI like https://github.com/bitforexapi/API_Doc_en/issues/5 thread recommends and still get the same error, does anyone have ideas? Below is my code

const Crypto = require('crypto') // Standard JavaScript cryptography library const request = require('request') // "Request" HTTP req library const config = require('./config') const bitforex =https://api.bitforex.com`; const api = "API"; const apiSecretUnencoded = "API_Secret"; let apiSecret = encodeURI(apiSecretUnencoded) let price = 0; let amount = 0; let tradeType = 1; // tradeType 1 is buy , tradeType 2 is sell let symbol = "coin-usdt-eth";

let nonce = Date.now(); let apiPath = /api/v1/trade/placeOrder?amount=${amount}&accessKey=${api}&nonce=${nonce}&price=${price}&symbol=${symbol}&tradeType=${tradeType}&signData= const message = ${bitforex}${apiPath}; console.log("apiPath: "+ apiPath);

const signData = Crypto.createHmac('sha256', apiSecret).digest('hex');// The authentication signature is hashed using the private key let fullData = ${bitforex}${apiPath}${signData}; console.log("signdata: " + signData); console.log(""); console.log(${fullData}); const body = {} const options = { url: fullData, headers: { 'content-type': 'application/json', }, json: true }

request.post(options, (error, response, body) => { console.log(body); // Logs the response body })`

BronacusAmmon commented 4 years ago

In the event anyone needs this in the future the signData const does work properly, doubled checked it against a working python version. Using the same Nonce Im still getting different hashes though, now checking into if the byte array that works on python is parsed differently than the string here