Spot Order API HMAC Nodejs

Hi All,

im just trying to get HMAC working correctly with the Testnet endpoints.
Can anyone advise what’s wrong below. as I keep getting **Error: Request failed with status code 401
**

const CREATE_ORDER = 'https://testnet.binance.vision/api/v3/order'

const BINNANCE_KEY = '225HZwKyZxxeOMUcoo4KcCf1HjQtBuk9Oa850YFseKZdMM4ZuU88vWtJMOH0BYR0'

const BINNANCE_SECRET = 'JLVx4l8DVL9v261GYYLtLXTH0EGT7FD2WXIlcr4HdjbV2xVYH8vAwl84tg5hFgHL'


 const str = `symbol=LTCBTC&side=SELL&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=${Date.now()}`
const signature = createHmac('SHA256', BINNANCE_SECRET).update(str).digest('hex');
try{
   const resp = await axios.post(`${CREATE_ORDER}?${str}&signature=${signature}`,<AxiosRequestConfig>{
   header: {
       'X-MBX-APIKEY':BINNANCE_KEY
   }
   })
    console.log(resp);
}catch (e){
    console.log(e);
}

https://testnet.binance.vision/api/v3/order?symbol=LTCBTC&side=SELL&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1618812863422&signature=26d33e7864449f220a9d44b4f875f173b92966f8f15c35020612964dca6cbe6d

data: '{"header":{"X-MBX-APIKEY":"TjwFmaMtRp7HguJvENABg7nXCmtYq6clIjEoeMQquj0qgdPg7P8xjY9TN53XSBgs"}}',

You can see how to create signature with this nodejs demo: https://github.com/binance-exchange/binance-signature-examples/tree/master/nodejs

If still unsuccessful, what’s the error message you’re getting?

@aisling For now I ended up using the nodejs library ‘binance-api-node’ thanks for ya help.