Skip to content
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

Bot couldn't sell because of insufficient fund #1371

Closed
pan-long opened this issue Nov 29, 2018 · 64 comments
Closed

Bot couldn't sell because of insufficient fund #1371

pan-long opened this issue Nov 29, 2018 · 64 comments
Labels
Bug CCXT Issues related to communication with ccxt (may or may not be caused by upstream issues)

Comments

@pan-long
Copy link
Contributor

I was synced to HEAD yesterday (but I had the same issue some time ago).

I had an order that the bot couldn't sell because of insufficient fund. I think it's because either the bot did wrong calculation of the amount or the exchange is doing some funny stuff.

Logs when the order was fulfilled:

2018-11-29 03:05:08,831 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=xx, pair=BCHSV/USDT, amount=xxx, open_rate=99.10000000, open_since=just now)
2018-11-29 03:05:09,740 - freqtrade.freqtradebot - WARNING - amount xxx does not match amount xxx
2018-11-29 03:05:09,740 - freqtrade.freqtradebot - WARNING - could not update trade amount: Half bought? Amounts don't match
2018-11-29 03:05:09,740 - freqtrade.persistence - INFO - Updating trade (id=xx) ...
2018-11-29 03:05:09,741 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=xx, pair=BCHSV/USDT, amount=xxx, open_rate=99.10000000, open_since=just now).

Logs when the bot was trying to sell:

2018-11-29 03:09:29,427 - freqtrade.freqtradebot - INFO - checking sell
2018-11-29 03:09:29,910 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHSV/USDT.Tried to sell amount xx at rate 100.02 (total xx).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}

The code that is throwing the error, any reason that instead of using the latest amount getting from exchange, we still choose to use the one saved when buying?

logger.warning(f"amount {amount} does not match amount {trade.amount}")

@xmatthias
Copy link
Member

i think the critical logs are in the buy section:

2018-11-29 03:05:09,740 - freqtrade.freqtradebot - WARNING - amount xxx does not match amount xxx
2018-11-29 03:05:09,740 - freqtrade.freqtradebot - WARNING - could not update trade amount: Half bought? Amounts don't match

this seems odd - could you please compare the contents of the database fort this trade with the binance UI to check what did change?

The best thing is that you have the whole logs available - this will help a TON in investigating this issue.

I wonder if it's got to do with the rounding / truncating applied (but that's just thinking out loud so i don't forget that train of thought)

@xmatthias xmatthias added Bug CCXT Issues related to communication with ccxt (may or may not be caused by upstream issues) labels Nov 29, 2018
@mishaker
Copy link
Member

@xmatthias while we are on it ... do we really need symbol_price_prec and symbol_amount_prec?
They are covered by CCXT:

def price_to_precision(self, symbol, price):
        return self.decimal_to_precision(price, ROUND, self.markets[symbol]['precision']['price'], self.precisionMode)

def amount_to_precision(self, symbol, amount):
        return self.decimal_to_precision(amount, TRUNCATE, self.markets[symbol]['precision']['amount'], self.precisionMode)

@xmatthias
Copy link
Member

xmatthias commented Nov 29, 2018

i was honestly never convince that we do, however the original PR had a solid explanation as to why ... but i don't remember that :(

will try to find the PR for reference - hopefully that'll give us some insight

pr with discussions was #1083
we then merged the code (without discussions) as #1097

ccxt does not round the same way than freqtrade does

  • symbol_price_prec always rounds up (also 10.1 is rounded to 11, 10.6 to 11)
  • ccxt.price_to_precision does round (but rounds 10.1 down to 10, 10.6 to 11).

I'm not saying one is better than the other ...
@creslinux you where the key person on the PR - any thoughts?

@pan-long
Copy link
Contributor Author

pan-long commented Dec 2, 2018

Unfortunately, I lost the full logs. I just checked my binance orders, the amount showing there is

xxx.51969

and I remember the amount showing in the logs was something like

xxx.5197xxxx

I don't think it's because of rounding/truncating because I am sure it wasn't xxx.51970000

I have actually done some local changes and the bot has been running fine for days. But I still don't know how the bot got the wrong amount though.

@mishaker
Copy link
Member

@xmatthias have tons of order failed because we don't use self.price_to_precisionand self. amount_to_precision of ccxt:

Message: binance order price is invalid, i.e. exceeds allowed price precision, exceeds min price or max price limits or is invalid float value in general, use self.price_to_precision(symbol, amount) {"code":-1013,"msg":"Filter failure: PRICE_FILTER"}

I read the PR, I am not convinced ...
If @creslinux does not react, then I think we should remplace those functions with CCXT.

@creslinux
Copy link
Contributor

creslinux commented Dec 14, 2018 via email

@creslinux
Copy link
Contributor

creslinux commented Dec 14, 2018 via email

@creslinux
Copy link
Contributor

creslinux commented Dec 14, 2018 via email

@xmatthias
Copy link
Member

@mishaker as mentioned before, i'm not tied to our logic to calculate precisions and would prefer to relie on ccxt handling that.

and yes - also the other info (min-notational, ...) will absolutely need to be considered. ccxt does have that available easily and unified - in fetch_markets() (i think)

@creslinux
Copy link
Contributor

creslinux commented Dec 14, 2018 via email

@mishaker
Copy link
Member

For the record: recent bombardments of price filter error was due to a sudden change in Binance API which is now handled in the following: ccxt/ccxt@dc3bd40

@creslinux
Copy link
Contributor

creslinux commented Dec 17, 2018 via email

@asheetov
Copy link

The same issue here binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}

It looks like a floating bug. Sometimes selling works fine, sometimes doesn't.
Good one:

2018-12-20 04:58:00,073 - freqtrade.rpc.telegram - INFO - Executing handler: _forcebuy for chat_id: 647795322
2018-12-20 04:58:00,591 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2018-12-20 04:58:01,603 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': buy, 'exchange': 'Binance', 'pair': 'BCHABC/USDT', 'market_url': 'https://www.binance.com/tradeDetail.html?symbol=BCHABC_USDT', 'limit': 157.09, 'stake_amount': 100, 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2018-12-20 04:58:02,117 - freqtrade.wallets - INFO - Wallets synced ...
2018-12-20 04:58:06,268 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=6, pair=BCHABC/USDT, amount=0.63657776, open_rate=157.09000000, open_since=just now)
2018-12-20 04:58:07,283 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=6, pair=BCHABC/USDT, amount=0.63657776, open_rate=157.09000000, open_since=just now) (from 0.63657 to 0.63593343) from Trades
2018-12-20 04:58:07,284 - freqtrade.persistence - INFO - Updating trade (id=6) ...
2018-12-20 04:58:07,284 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=6, pair=BCHABC/USDT, amount=0.63593343, open_rate=157.09000000, open_since=just now).

2018-12-20 05:16:23,409 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'exchange': 'Binance', 'pair': 'BCHABC/USDT', 'gain': 'loss', 'market_url': 'https://www.binance.com/tradeDetail.html?symbol=BCHABC_USDT', 'limit': 154.3, 'amount': 0.63593343, 'open_rate': 157.09, 'current_rate': 154.38, 'profit_amount': -1.8723788, 'profit_percent': -0.01874276, 'sell_reason': 'trailing_stop_loss', 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2018-12-20 05:16:24,093 - freqtrade.freqtradebot - INFO - executed sell, reason: SellType.TRAILING_STOP_LOSS
2018-12-20 05:16:24,215 - freqtrade.wallets - INFO - Wallets synced ...
2018-12-20 05:16:25,224 - freqtrade.wallets - INFO - Wallets synced ...
2018-12-20 05:16:26,891 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=6, pair=BCHABC/USDT, amount=0.63593343, open_rate=157.09000000, open_since=18 minutes ago)
2018-12-20 05:16:27,402 - freqtrade.persistence - INFO - Updating trade (id=6) ...
2018-12-20 05:16:27,402 - freqtrade.persistence - INFO - Marking Trade(id=6, pair=BCHABC/USDT, amount=0.63593343, open_rate=157.09000000, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.

Bad one:

2018-12-20 05:38:36,028 - freqtrade.rpc.telegram - INFO - Executing handler: _forcebuy for chat_id: 647795322
2018-12-20 05:38:36,156 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2018-12-20 05:38:37,223 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': buy, 'exchange': 'Binance', 'pair': 'BCHABC/USDT', 'market_url': 'https://www.binance.com/tradeDetail.html?symbol=BCHABC_USDT', 'limit': 157.81, 'stake_amount': 100, 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2018-12-20 05:38:38,174 - freqtrade.wallets - INFO - Wallets synced ...
2018-12-20 05:38:39,171 - freqtrade.wallets - INFO - Wallets synced ...
2018-12-20 05:38:43,063 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=7, pair=BCHABC/USDT, amount=0.63367340, open_rate=157.81000000, open_since=just now)
2018-12-20 05:38:44,072 - freqtrade.freqtradebot - WARNING - amount 0.6336700000000001 does not match amount 0.6336734047272036
2018-12-20 05:38:44,072 - freqtrade.freqtradebot - WARNING - could not update trade amount: Half bought? Amounts don't match
2018-12-20 05:38:44,075 - freqtrade.persistence - INFO - Updating trade (id=7) ...
2018-12-20 05:38:44,075 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=7, pair=BCHABC/USDT, amount=0.63367000, open_rate=157.81000000, open_since=just now).

2018-12-20 06:28:11,764 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 160.04 (total 101.4109464).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}
2018-12-20 06:28:16,623 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 160.01 (total 101.3919366).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}
2018-12-20 06:28:21,419 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 159.6 (total 101.132136).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}
2018-12-20 06:28:26,431 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 159.78 (total 101.2461948).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}
2018-12-20 06:28:31,436 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 159.67 (total 101.1764922).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}
2018-12-20 06:28:36,441 - freqtrade.freqtradebot - WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market BCHABC/USDT.Tried to sell amount 0.63366 at rate 159.

@asheetov
Copy link

asheetov commented Dec 21, 2018

The bad thing here is not wrong rounding or whatever, but fact that freqtrade reports nothing to user about the issue. Missed stoploss is just silently ignoring, and user happily losing money without any notice through RPC.

@creslinux
Copy link
Contributor

creslinux commented Dec 21, 2018 via email

@mishaker
Copy link
Member

mishaker commented Dec 21, 2018

@asheetov thanks for reporting. my take is that you are using trailing stoploss and when the bot tries to sell in bear market it is failing due to the slippage.
However setting sell order type to "market" should logically resolve the problem (see https://github.com/freqtrade/freqtrade/blob/develop/docs/configuration.md#understand-order_types)

My advice is turn the stoploss on exchange "True" and also put sell to "market".

As for your comment on bot should inform user, I cannot agree more. stoploss and trailing stoploss will undergo following refactoring:

  • If stoploss on exchange is "on" then trailing stoploss also should be on exchange => bot should cancel current stoploss limit order and replace it with a new one.
  • If stop amount does not pass MIN_NOTIONAL then buy should not happen and user should be informed (i.e. checking stop before buy happens)

but I am afraid it won't be before new year.

@asheetov
Copy link

I don't think the issue is related to slippage, because according to the logs, bot tried to sell the same (wrong) amount of currency several times at different prices. So it's not price-related issue, but amount related.

And, unfortunately, market order type doesn't help here #1428

@mishaker
Copy link
Member

@asheetov what is your ccxt version?

@asheetov
Copy link

1.17.363

@mishaker
Copy link
Member

@asheetov please update your CCXT version. as you are behind the filter correction version.
However I am not sure if it resolves the problem.
Quick question: do you use base currency to pay the fees ?

@asheetov
Copy link

I'm using BNB to pay the fees, not the base currency.

@mishaker
Copy link
Member

market order is fixed now as per #1440

@miqueet
Copy link

miqueet commented Jan 30, 2019

I believe I am having this same issue. I had to manually cancel an order(I'll open another issue as to why) On binance. Now it doesn't update my balance from binance and keeps spamming the error that I do not have enough funds.

WARNING - Unable to sell trade: Insufficient funds to create limit sell order on market PHX/BTC.Tried to sell amount 8032.0 at rate 2.48e-06 (total 0.01991936).Message: binance {"code":-2010,"msg":"Account has insufficient balance for requested action."}

@xmatthias
Copy link
Member

if you manually cancelled the order on the exchange you need to let the bot know and close / remove the trade in the database.
The documentation has a cheatsheet here on how to do that.

@miqueet
Copy link

miqueet commented Jan 30, 2019 via email

@xmatthias
Copy link
Member

bolt assumption without proof:
a) bad signals
b) rounding errors due to min-amount from the exchange (rounding up on buy - and because this is a very cheap coin that is > stoploss% - so it buys at that level and sells almost immediately (i assume in the next cycle)

I had this happen a few times with HOT - (which is since then on my blacklist ...)

@miqueet
Copy link

miqueet commented Jan 30, 2019 via email

@miqueet
Copy link

miqueet commented Jan 30, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Mar 30, 2019 via email

@konqueror1
Copy link

konqueror1 commented Mar 30, 2019

@xmatthias
the bot succeeded when I corrected the amount in the DB. The available amount in DB was wrong from the beginning.
I don't know the logic for getting info like amounts, fees etc but I believe it does not cover all the cases. I will try to debug what get_real_amount actually does.
@creslinux
I like your workaround but prefer to find the root of the problem and solve it.

@mishaker
Copy link
Member

mishaker commented Mar 31, 2019 via email

@asheetov
Copy link

Just a suggestion of different approach for selling algorithm, which works perfect for me in Zenbot (honestly I give up with freqtrade after losing money because of this issue).

Don't make the bot to calculate "exactly right" amount of selling position considering fees, rounding and whatever else. Just sell "all of them". For flexibility you can add the new config option like "sell percent of open position" and place sell orders according that percent of funds in account.

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

xmatthias added a commit that referenced this issue Mar 31, 2019
should fix bugs observed in #1371 connected to stoploss
@xmatthias xmatthias mentioned this issue Mar 31, 2019
1 task
@xmatthias
Copy link
Member

xmatthias commented Mar 31, 2019

it's not that we try to calculate the Amount, we have code in place which detects the real bought amount based on the buy order id (see my previous comment).

However, due to a bug, that code was never executed for buys which filled immediately (see #1720 for details), which caused the relevant code to be never executed during a buy - so the trade-amount was never updated.

I did multiple buys/sells with the above PR, all with BNB disabled (and the amount did update to the correct value).

Side note: Retrying with lower amounts until it works is a brute-force method, without really caring/thinking about the root problem.

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@xmatthias
Copy link
Member

xmatthias commented Mar 31, 2019

we're not ignoring the exception, but stupidly recreating the order with another amount IS NOT THE SOLUTION.

Investigating the problem, finding out WHY the amounts don't match, that is the challange.
Stupidly retrying until it works is something a schoolgirl/schoolboy can do, i don't need a bot for that.

side note: you can edit comments, no need to create multiple comments within minutes.

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@mishaker
Copy link
Member

@creslinux

The use case for triggering the scenario is.
I have 10LTC total and my stop is to sell 10LTC or my sell is to sell
10LTC. My fees are to be paid in LTC. I can't sell 10 as I need to pay the
fee too. Binance returns a insufficient funds error.

This is simply a misdiagnosis.
Fees are not extracted beforehand from Binance. (i.e. the amount is not rejected because it is more than the (amount - fees). from Binance docs, a FULL response to a sell order:

{
  "symbol": "BTCUSDT",
  "orderId": 28,
  "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  "transactTime": 1507725176595,
  "price": "1.00000000",
  "origQty": "10.00000000",
  "executedQty": "10.00000000",
  "cummulativeQuoteQty": "10.00000000",
  "status": "FILLED",
  "timeInForce": "GTC",
  "type": "MARKET",
  "side": "SELL",
  "fills": [
    {
      "price": "4000.00000000",
      "qty": "1.00000000",
      "commission": "4.00000000",
      "commissionAsset": "USDT"
    },
    {
      "price": "3999.00000000",
      "qty": "5.00000000",
      "commission": "19.99500000",
      "commissionAsset": "USDT"
    },
    {
      "price": "3998.00000000",
      "qty": "2.00000000",
      "commission": "7.99600000",
      "commissionAsset": "USDT"
    },
    {
      "price": "3997.00000000",
      "qty": "1.00000000",
      "commission": "3.99700000",
      "commissionAsset": "USDT"
    },
    {
      "price": "3995.00000000",
      "qty": "1.00000000",
      "commission": "3.99500000",
      "commissionAsset": "USDT"
    }
  ]
}

Note the origQty, executedQty (10 BTC) and the sum of all trades (1 +5 +2 +1 +1).
The safest and the most pertinent approach is to update the trade amount immediately if the fee is paid by the base currency. coded here:

if trade.pair.startswith(order['fee']['currency']): # <-- checks if the fee currency is the base currency
                new_amount = order_amount - order['fee']['cost']
                logger.info("Applying fee on amount for %s (from %s to %s) from Order",
                            trade, order['amount'], new_amount)
                return new_amount

This is what was skipped before @xmatthias found the bug today and corrected it.

The root of the problem is returned exceptions are not being handled, but
ignored. The impact of ignoring exceptions being sent is users real money
is left at risk for no reason.

Your comment is completely nonsense technically and condescending socially. start with the technical part: no exception is ignored or unhandled in this project, it is just a matter of reporting it and finding the right solution rather than coding a workaround which causes more problems. As for the social part: finally someone found the bug hanging since last November and corrected it. you didn't even take time to read it thoroughly before commenting "Me Myself and I ..." and unfortunately this is not the first time you show this attitude.

@creslinux
Copy link
Contributor

creslinux commented Mar 31, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Apr 1, 2019 via email

@creslinux
Copy link
Contributor

creslinux commented Apr 1, 2019 via email

@xmatthias
Copy link
Member

xmatthias commented Apr 1, 2019

unlike the school girl sexist comment

You are right @creslinux, edited that comment now to say "schoolgirl/schoolboy". Wasn't intendet to be sexist, sorry.

@creslinux again, please edit your comments instead of posting 3 comments in quick succession if you need to make corrections or additions right after posting. This creates 3 alerts for everyone subscribed to this issue, where on ewould be enough.
It's fine to recomment on your own answer if that was more than a day ago.

he solution being put forward by xmats is wrong btw

Please take the time to understand the solution before you post misleading comments.
My solution is not new, but was there and working before we added different time_in_force methods, which introduced the bug causing this.
The solution gathers the trades connected to the buy-order, analyzes if the fees have been payed in stake-currency or not (payed in BNB/USDT) - and then adjusts the amount eventually.

The message/ return value from @mishaker is not what is used for this calculation.
We use the "fees" element of order if it's there (hint: it's not for binance) or get the trades for this order, and use the "fee" element in this return value.

The result of the "fetch_my_trades" is something like the following:
It includes the "fees" dict, and if the currency is MTL - we subtract the amount.

Dict in case of BNB fees

[{'info': {'symbol': 'MTLETH',
   'id': 1234,
   'orderId': 1234,
   'price': '0.00527100',
   'qty': '18.96000000',
   'quoteQty': '0.09993816',
   'commission': '0.00060196',
   'commissionAsset': 'BNB',
   'time': 1554032217497,
   'isBuyer': True,
   'isMaker': False,
   'isBestMatch': True},
  'timestamp': 1554032217497,
  'datetime': '2019-03-31T11:36:57.497Z',
  'symbol': 'MTL/ETH',
  'id': '1234',
  'order': '1234',
  'type': None,
  'takerOrMaker': 'taker',
  'side': 'buy',
  'price': 0.005271,
  'amount': 18.96,
  'cost': 0.09993816,
  'fee': {'cost': 0.00060196, 'currency': 'BNB'}}]

dict in case of non-BNB fees:

[{'info': {'symbol': 'MTLETH',
   'id': 5543,
   'orderId': 5555,
   'price': '0.00428600',
   'qty': '23.33000000',
   'quoteQty': '0.09999238',
   'commission': '0.02333000',
   'commissionAsset': 'MTL',
   'time': 1554053985003,
   'isBuyer': True,
   'isMaker': False,
   'isBestMatch': True},
  'timestamp': 1554053985003,
  'datetime': '2019-03-31T17:39:45.003Z',
  'symbol': 'MTL/ETH',
  'id': '5543',
  'order': '5555',
  'type': None,
  'takerOrMaker': 'taker',
  'side': 'buy',
  'price': 0.004286,
  'amount': 23.33,
  'cost': 0.09999237999999999,
  'fee': {'cost': 0.02333, 'currency': 'MTL'}},
]

Note: There can be more than one trade per side, in which case the amount is aggregated - but there have not been in this case and for simplicity of .

The problem is by Always subtracting fees from sell amount, is when the
user HAS free to pay fees this is not desired, it leaves a fees worth of
base asset behind in every trade. Dust.

The solution as explained above does not do that.
Small dust (lower than MIN_NOTIONAL) may however remain since the effect of the fees can be that the amount is lower than MIN_NOTIONAL (or however that's called) - so rounding to that value has to be applied.

@creslinux
Copy link
Contributor

creslinux commented Apr 1, 2019 via email

@xmatthias
Copy link
Member

From your answer it's not 100% clear, but i assume you only have 10abc in your account.

Your sell-order for 10abc will succeed, since you are paying fees in the amount you receive - which is ETH in your example. So you'll not get 10abs's worth of ETH - but 10-abc's worth of ETH.

For binance, fees are paid in the currency you're about to receive (or BNB).

another calculation sample, hopefully clearer

Let's assume i have BNB disabled for this post, and for simplicity, the rate between XRP and ETH is 1.

If i buy 100 XRP, then i will receive 99.75 XRP, and have paid 0.25 XRP in feeds.
The bot detects this - and sets the amount of XRP i have to 99.75.

When trying to sell - or creating a stoploss order - I will place my order with 99.75 XRP.
I will however not receive 99.75 ETH, but 99.49 ETH, since fees are subtracted by from this.

I do not have to do this calculation myself and place the sell-order with 99.49, which is what you're suggesting, but the exchange subtracts this from the currency i am about to receive (both ways, when buying or selling).

Note: this is a fictional example, XRP ETH rate is not 1 - but it simplifies the calculation.

@creslinux
Copy link
Contributor

creslinux commented Apr 1, 2019 via email

@mishaker
Copy link
Member

mishaker commented Apr 1, 2019

yep, that is what we are trying to explain here :) fees are always taken from received amount. your mistake was you thought you have to calculate the fee beforehand cause binance it reduces from your base amount on market price of base/BNB. as you can never be sure of this rate then you came to conclusion that a loop should be baked. your hypothesis was wrong. sell amount is always fixed, fees are reduced from received asset.

@creslinux
Copy link
Contributor

creslinux commented Apr 1, 2019 via email

@mishaker
Copy link
Member

mishaker commented Apr 4, 2019

@iuvbio this one. I think it is the root of your problem on #1723

@mishaker
Copy link
Member

mishaker commented Apr 4, 2019

I am going to close this issue as I am sure it is solved by #1720
Please do not hesitate to open it if any of you think differently.

@mishaker mishaker closed this as completed Apr 4, 2019
@iuvbio
Copy link
Contributor

iuvbio commented Apr 4, 2019

Mmm, I'm not sure, I did not set FOK for time_in_force..

@xmatthias
Copy link
Member

It's not an issue with FOK - but that this applied for every trade which was immediately closed, no matter if it's IOC, FOK, or GTC (the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CCXT Issues related to communication with ccxt (may or may not be caused by upstream issues)
Projects
None yet
Development

No branches or pull requests

9 participants