Place Market price order with all the money I have in the account?

Hi, I am trying to place an order market type. I am using node-binance-api.

The function I am using need several parameter such as the market crypto price, and the quantity. I estimate the quantity by dividing the my current balance over the market price. But I am keep getting an error. Please, any help, it’s greatly appreciated!

 binance.prices(function (error, ticker) {

         var price = ticker.BNBBTC;
         Getting list of current balances
        binance.balance(function (error, balances) {
            //console.log("balances()", balances);
            if (typeof balances.ETH !== "undefined") {
                var CurBala = balances.ETH.available;
				var quantity=CurBala/price;

                //binance.buy(symbol, quantity, price, type);
                 binance.buy("ETHBTC", quantity, price, "MARKET")
                 
		}   }
    });
  1. There’s a function called marketBuy
  2. I’m confused about how you calculate your quantity, shouldn’t it be the qty of BTC since you get the price of BNBBTC?
  3. Need to pay attention to decimal part since you use divide to get your qty

Thank you for your answer!

Could you please give me more details, I really appreciate your help!

1. There’s a function called marketBuy: is this function exist in node-binance-api package or where? Could you guide me to a resource explain this function?
2.----
3. Need to pay attention to decimal part since you use divide to get your qty: sorry I am not sure how I need to pay attention to that?

Thanks

is this function exist in node-binance-api package or where? Could you guide me to a resource explain this function? - Yes; Please read through https://github.com/jaggedsoft/node-binance-api/blob/master/node-binance-api.js; The code is 3rd-party so you need to review the code and take all the risk on your own

Need to pay attention to decimal part since you use divide to get your qty: sorry I am not sure how I need to pay attention to that? - For e.g., if the quantity is 1.001 after dividing but if that trading pair can only allow two digit decimal, this’d be rejected. You can get the details from /api/v3/exchangeInfo regarding the step size.

Thank you so much, great help!