Skip to content

Node JS SignData Invalid for API placeOrder #15

Open

Description

@BronacusAmmon

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

Activity

  1. BronacusAmmon commented on Mar 25, 2020

    @BronacusAmmon
    Author

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions