-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to trade with all available balance ? #5464
Comments
Hi @frodoe7, I do not think you need to take the fees into consideration, as the exchange will do that for you and give you an amount after taking fees. So here you want to buy 0.15 ETH.
where 0.004 / 0.0267 = 0.15 ETHamount / ETHBTCprice = BTCamount a cool way to think about markets is as a fraction. so ETH/BTC is literally ETH over BTC (or ETH per BTC). If you do these calculations you should be able to sell most of your crypto. These is no flag for most exchanges "sell everything", however I agree it would be nice. And if an exchange supports such an option you would be able to do it using https://github.com/ccxt/ccxt/wiki/Manual#implicit-api-methods |
Or, alternatively, https://github.com/ccxt/ccxt/wiki/Manual#overriding-unified-api-params
In general, because of limits and precision, you won't be able to spend everything to a cent, some dust will always remain there, unless your amounts are large enough to avoid the rounding entirely. |
Hi, I'm having the exact same issue. Whenever i calculate some amount to buy, it sometimes gives me error that i dont have enough balance for requested operation. I think this is because I calculated the amount on a price which was increased at the time of order execution. I'm executing market orders and i cant use limit orders because I need it to be closed immediately. Any suggestions how I can handle this? Thanks. |
Hi @mr-asad92
Do you take the fees and the fee side (base/quote) into account when you calculate the values for your market orders? In any case, there may be price slippage, since orders are not processed immediately. Even if you calculate everything right, you might still hit a limit. Some exchanges, however, support the "timeInForce" option which basically allows you to control the lifetime of your limit orders. The most common values for
So, I'd suggest to look into those options, depending on the exchange in question. Another way to approach this is to introduce a "buffer" into your strategy, so that you trade 90%, 99%, 99.9999% (whatever works for you), not 100%... |
Thanks for your response. Yes i'm already changing strategy to use 99% amount. I'll see how that performs, otherwise i'll take a look at Thanks again for your time and reply. :) |
Just a quick update: we have added the support for total cost for market orders with Binance here: #6391 (comment) |
Hey! |
This is more a question than issue
I manually fetch the user available balance then make some complicated calculations to calculate the amount to buy or sell
these calculations include fetching all available balance , converting to another coin , calculating the fees ratio , deducting from the amount to buy or sell and so on ..
however my calculations is not very accurate ,
the final amount result is above or less than the expected by very small amount
for example , I have .004 BTC and would like to buy ETH
now I need to calculate the .004 BTC in ETH and also remove the fees , which sometimes (.2%) , let's assume the amount should be 0.15 ETH
sometimes my result is .151 > then it fires error : insufficient balance
sometimes my result is .149 > then it goes well but it keeps a tiny amount in my BTC balance , and I don't need this behavior
my issue with this last parameter (amount)
exchange.createOrder(market , 'market' , side , amount)
any way to tell the exchange , that I'd like to trade with all my available balance ?
The text was updated successfully, but these errors were encountered: