Binance API, I'm trying to buy coin with BTC

Viewed 833

I'm using this code to buy NEO:

enter image description here

if I'll run this code, I'll buy 0.05 NEO with market price, but I want to buy some amount of Neo with 0.05 BTC.

for example: if NEO price is 0.01 so I'll buy 5 NEO, if NEO price is 0.025 so I'll buy 2 NEO.

Anyone knows how to do it?

Thanks,

2 Answers

From the context, I see that you're using binance-api-node package.

Unfortunately this package doesn't support the "quote order quantity" (quoteOrderQty defined in the official REST API docs). This parameter would allow you to define the amount in the quote currency (in case of NEO/BTC that would be BTC).


I don't recommend getting the current market price and submitting order afterwards (as the comment to your question and the other answer suggest), because it's not going to be very precise and it's going to bring some unexepected consequences.

If the market price drops (between when Binance generates the market price info as response to your request and when they receive your order), you'd simply buy for higher price than you could have. And if the market prices rises, you'd be buying less of the base currency than you could have.


Instead, I'd recommend calling the POST /api/v3/order endpoint directly and using the quoteOrderQty param. Or using a different NPM package that supports the param, such as ccxt.

Related