binance-connector npm package

The trade example code on the binance javascript connector node (GitHub - binance/binance-connector-node: A simple connector to Binance Public API) does not work.

    client.newOrder('BNBUSDT', 'BUY', 'LIMIT', {
        price: '100',
        quantity: 1,
        timeInForce: 'GTC'
        }).then(response => console.log(response.data))
        .catch(error => console.log(error))

catches an error, which is: ‘Error: Request failed with status code 400’

According to the docs, this means the request was malformed so I am not sure where to go from here when even the basic example does not work. My API/Secret are valid, since the account() command example does work.

The example code is for demonstrating how to use the method from the library. It can not guarantee the value of the parameter can be used to send to server. The potential problem could be:

  • There is not enough funds in your account
  • The price is not allowed due to the current market condition.
  • etc

Print out the error message, it will give more hints for how you can adjust the parameters.

I am printing the error,

.catch(error => console.log(error))

=>

‘Error: Request failed with status code 400’

Am I doing this wrong? If I had a more detailed error message that would be great.

I do note that the official api docs say that a parameter ‘timestamp’ is required on this endpoint - I am assuming that the connector node automatically appends a timestamp parameter to calls that need it?

I read up more and realized there is the error.response object which can give more detailed information!

.catch(err => {

            console.log(err);
            console.log(err.response.headers) // full response header
            console.log(err.response.status) // HTTP status code 400
            console.log(err.response.data) // includes both error code and message
            console.log(err.response.config) // includes request's config
       

        })

In my case, it was indeed insufficient account balance. Problem solved, thanks for your response Dino.

1 Like