Bittrex api V3 newOrder (UNAUTHORIZED)

Viewed 238

The problem is with bittrex's API V3(link). I can get balances but when I try to use post and I use content object and post methods it gives me the error unauthorized. I think problem is with contentHash but so far I'm out of ideas about what to do.

require('dotenv').config();
const { error } = require("console");
var CryptoJS = require("crypto-js");
const axios = require('axios').default;

var timestamp = new Date().getTime();


method='POST'
   
var key =process.env.key;
var apiSecret =process.env.apiSecret;

content = {
    "marketSymbol": "ETH-BTC",
    "direction": "BUY",
    "type": "LIMIT",
    "quantity": "1",
    "limit": "0.0001",
    "timeInForce": "GOOD_TIL_CANCELLED"
   }
   var contentHash = CryptoJS.SHA512(content).toString(CryptoJS.enc.Hex)
var uri = 'https://api.bittrex.com/v3/orders';
var preSign = [timestamp, uri, method, contentHash,''].join('');
var signature = CryptoJS.HmacSHA512(preSign, apiSecret).toString(CryptoJS.enc.Hex);
 
const res =  axios.post(uri, {
    'headers': {
        'Api-Key'         : key,
        'Api-Timestamp'   : timestamp,
        'Api-Content-Hash': contentHash,
        'Api-Signature'   : signature, //Hex-encode a HmacSHA512, using your API secret as the signing secret. 
        'Content-Type'    :'application/json',
        'Accept'          :'application/json'  
  }
}).then(function(res){
   console.log(res)
}).catch(function (err) {
  // handle error
  console.log(err.response.data);
})

I did fix the problem: Add JSON.stringify(content) to var contentHash = CryptoJS.SHA512(JSON.stringify(content)).toString(CryptoJS.enc.Hex)

0 Answers
Related