Repository: freqtrade/freqtrade

Issue:
emergency_sell reported profit not correct
<!-- 
Have you searched for similar issues before posting it?

If you have discovered a bug in the bot, please [search our issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue). 
If it hasn't been reported, please create a new issue.

Please do not use bug reports to request new features.
-->

## Describe your environment

  * Operating system: _ubuntu___
  * Python Version: __3.8___ (`python -V`)
  * CCXT version: _____ (`pip freeze | grep ccxt`)
  * Freqtrade Version: _dev___ (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)
  
Note: All issues other than enhancement requests will be closed without further comment if the above template is deleted or not filled out.

## Describe the problem:

A trade for the pair VIDT/BTC bought using limit order on binance got filled by freqtrade at 2702sats price. After some minutes freqtrade initiated an emergency sell (probably due stop-loss-on-exchnage not taken in consideration for some reason).
The market emergency sell went at 2791sats and filled in one trade. telegram bot reports a profit of -10.83%. how can be?
This is the telegram message:
`❌ Binance: Selling VIDT/BTC
Amount: 13.00000000
Open Rate: 0.00002702
Current Rate: 0.00002801
Close Rate: 0.00002791
Sell Reason: emergency_sell
Duration: 2:13:32 (133.5 min)
Profit: -10.83% (loss: -0.00003805 BTC / -0.520 USD)`




profit is wrong in some cases
## Describe your environment

  * Operating system: ubuntu server
  * Python Version: 3.6.9
  * CCXT version: 1.34.59
  * Freqtrade Version: develop-fe588e57
  
## Describe the problem:

Some trades (not all, far from it), show a negative profit while it's clearly not the case. 

![image](https://user-images.githubusercontent.com/9531438/99935276-a5667e00-2d60-11eb-993d-52a05eea6535.png)


### Steps to reproduce:

Have no idea how to reproduce
  
### Observed Results:

### Relevant code exceptions or logs

  ```
2020-11-23 02:18:22,242 - freqtrade.freqtradebot - INFO - Executing Sell for ETH/USDT. Reason: trailing_stop_loss
2020-11-23 02:18:22,775 - freqtrade.wallets - INFO - Wallets synced.
2020-11-23 02:18:23,260 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=2020-11-23 01:15:54)
2020-11-23 02:18:23,747 - freqtrade.freqtradebot - INFO - Fee for Trade Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=2020-11-23 01:15:54) [sell]: 0.05030694 B$
2020-11-23 02:18:23,747 - freqtrade.persistence.models - INFO - Updating trade (id=69) ...
2020-11-23 02:18:23,747 - freqtrade.persistence.models - INFO - MARKET_SELL has been fulfilled for Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=2020-11-23 01:$
2020-11-23 02:18:23,748 - freqtrade.persistence.models - INFO - Marking Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=closed) as closed as the trade is fulfill$
2020-11-23 02:18:24,332 - freqtrade.wallets - INFO - Wallets synced.
2020-11-23 02:18:24,333 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'trade_id': 69, 'exchange': 'Binance', 'pair': 'ETH/USDT', 'gain': 'loss', 'limit': 563.2200022388$
2020-11-23 02:18:25,840 - freqtrade.wallets - INFO - Wallets synced.

  ```



Discussion:
Please provide the logs for the period in question (or at least for the period a few minutes before the sell occured), otherwise there is no way to analyze what happened and i will have to close this issue.

here it is filtered out of not interesting data...

```
Nov  2 10:15:48 ssh freqtrade[20407]: 2020-11-02 10:15:48,664 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=30, pair=VIDT/BTC, amount=79.64523983, open_rate=0.00002702, open_since=2020-11-02 10:00:59)
Nov  2 10:16:06 ssh freqtrade[20407]: 2020-11-02 10:16:06,006 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=30, pair=VIDT/BTC, amount=79.64523983, open_rate=0.00002702, open_since=2020-11-02 10:00:59)
Nov  2 10:16:06 ssh freqtrade[20407]: 2020-11-02 10:16:06,507 - freqtrade.freqtradebot - INFO - Buy order cancelled due to timeout for Trade(id=30, pair=VIDT/BTC, amount=79.64523983, open_rate=0.00002702, open_since=2020-11-02 10:00:59).
Nov  2 10:16:06 ssh freqtrade[20407]: 2020-11-02 10:16:06,507 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59)
Nov  2 10:16:07 ssh freqtrade[20407]: 2020-11-02 10:16:07,507 - freqtrade.persistence.models - INFO - LIMIT_BUY has been fulfilled for Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59).
Nov  2 10:16:07 ssh freqtrade[20407]: 2020-11-02 10:16:07,517 - freqtrade.freqtradebot - INFO - Partial buy order timeout for Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59).
Nov  2 10:16:08 ssh freqtrade[20407]: 2020-11-02 10:16:08,022 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'trade_id': 30, 'type': buy_cancel, 'exchange': 'Binance', 'pair': 'VIDT/BTC', 'limit': 2.702e-05, 'order_type': 'limit', 'stake_amount': 0.00035126, 'stake_currency': 'BTC', 'fiat_currency': 'USD', 'amount': 13.0, 'open_date': datetime.datetime(2020, 11, 2, 10, 0, 59, 271576), 'current_rate': 2.702e-05, 'reason': 'cancelled due to timeout, partially filled'}
Nov  2 10:16:18 ssh freqtrade[20407]: 2020-11-02 10:16:18,524 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.302e-05. limit: 2.279e-05
Nov  2 10:17:23 ssh freqtrade[20407]: 2020-11-02 10:17:23,208 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2500039) in order to add another one ...
Nov  2 10:17:24 ssh freqtrade[20407]: 2020-11-02 10:17:24,346 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.303e-05. limit: 2.28e-05
Nov  2 10:39:48 ssh freqtrade[20407]: 2020-11-02 10:39:48,143 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2500055) in order to add another one ...
Nov  2 10:39:48 ssh freqtrade[20407]: 2020-11-02 10:39:48,871 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.308e-05. limit: 2.285e-05
Nov  2 10:44:26 ssh freqtrade[20407]: 2020-11-02 10:44:26,585 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2500686) in order to add another one ...
Nov  2 10:44:27 ssh freqtrade[20407]: 2020-11-02 10:44:27,572 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.31e-05. limit: 2.287e-05
Nov  2 11:59:28 ssh freqtrade[20407]: 2020-11-02 11:59:28,315 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2500893) in order to add another one ...
Nov  2 11:59:29 ssh freqtrade[20407]: 2020-11-02 11:59:29,310 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.311e-05. limit: 2.288e-05
Nov  2 12:02:16 ssh freqtrade[20407]: 2020-11-02 12:02:16,605 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2505484) in order to add another one ...
Nov  2 12:02:17 ssh freqtrade[20407]: 2020-11-02 12:02:17,604 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.313e-05. limit: 2.29e-05
Nov  2 12:13:22 ssh freqtrade[20407]: 2020-11-02 12:13:22,285 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2505601) in order to add another one ...
Nov  2 12:13:23 ssh freqtrade[20407]: 2020-11-02 12:13:23,250 - freqtrade.exchange.binance - INFO - stoploss limit order added for VIDT/BTC. stop price: 2.314e-05. limit: 2.291e-05
Nov  2 12:14:29 ssh freqtrade[20407]: 2020-11-02 12:14:29,845 - freqtrade.freqtradebot - INFO - Cancelling current stoploss on exchange for pair VIDT/BTC (orderid:2506314) in order to add another one ...
Nov  2 12:14:30 ssh freqtrade[20407]: 2020-11-02 12:14:30,823 - freqtrade.freqtradebot - ERROR - Unable to place a stoploss order on exchange. Could not create stop_loss_limit sell order on market VIDT/BTC. Tried to sell amount 13.0 at rate 2.774e-05. Message: binance Order would trigger immediately.
Nov  2 12:14:31 ssh freqtrade[20407]: 2020-11-02 12:14:31,822 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59)
Nov  2 12:14:31 ssh freqtrade[20407]: 2020-11-02 12:14:31,823 - freqtrade.freqtradebot - INFO - Fee for Trade Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59) [sell]: 4.931e-05 BTC - rate: 0.1359226
Nov  2 12:14:31 ssh freqtrade[20407]: 2020-11-02 12:14:31,825 - freqtrade.persistence.models - INFO - MARKET_SELL has been fulfilled for Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=2020-11-02 10:00:59).
Nov  2 12:14:31 ssh freqtrade[20407]: 2020-11-02 12:14:31,826 - freqtrade.persistence.models - INFO - Marking Trade(id=30, pair=VIDT/BTC, amount=13.00000000, open_rate=0.00002702, open_since=closed) as closed as the trade is fulfilled and found no open orders for it.
Nov  2 12:14:32 ssh freqtrade[20407]: 2020-11-02 12:14:32,367 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'trade_id': 30, 'exchange': 'Binance', 'pair': 'VIDT/BTC', 'gain': 'loss', 'limit': 2.7906153846153844e-05, 'order_type': 'market', 'amount': 13.0, 'open_rate': 2.702e-05, 'current_rate': 2.801e-05, 'profit_amount': -3.805e-05, 'profit_ratio': -0.10825288, 'sell_reason': 'emergency_sell', 'open_date': datetime.datetime(2020, 11, 2, 10, 0, 59, 271576), 'close_date': datetime.datetime(2020, 11, 2, 12, 14, 31, 826209), 'stake_currency': 'BTC', 'fiat_currency': 'USD'}
Nov  2 12:14:32 ssh freqtrade[20407]: 2020-11-02 12:14:32,500 - freqtrade.freqtradebot - WARNING - Could not create trailing stoploss order for pair VIDT/BTC.
Nov  2 12:14:33 ssh freqtrade[20407]: 2020-11-02 12:14:33,899 - freqtrade.freqtradebot - INFO - Pair VIDT/BTC is currently locked.
Nov  2 12:14:49 ssh freqtrade[20407]: 2020-11-02 12:14:49,042 - freqtrade.freqtradebot - INFO - Pair VIDT/BTC is currently locked.
Nov  2 12:15:04 ssh freqtrade[20407]: 2020-11-02 12:15:04,802 - freqtrade.freqtradebot - INFO - Pair VIDT/BTC is currently locked.
```
maybe here is better: https://pastebin.com/vHhi2vUT
well the emergency sell happened because of a very quick spike / drop - which means that the adjusted order could not be placed anymore as it would trigger immediately.

Since it's a stoploss first and foremost, this assumes that you're risking bigger losses, and therefore initiates the emergency sell.

Now regarding the profit reported i'm not sure - for market orders this can sometimes be off a bit in telegram, as the order can adjust after the message slightly.

I think the following command (adapt to fit your environment) should help figure out what is in the database:

```
freqtrade show-trades --db-url sqlite:///tradesv3.sqlite --trade-ids 30 --print-json
```


```
[
    {
        "trade_id": 30,
        "pair": "VIDT/BTC",
        "is_open": false,
        "exchange": "binance",
        "amount": 13.0,
        "amount_requested": 79.64523983,
        "stake_amount": 0.00035126,
        "strategy": "QQE",
        "ticker_interval": 120,
        "timeframe": 120,
        "fee_open": 0.00074994,
        "fee_open_cost": 0.00012428,
        "fee_open_currency": "BNB",
        "fee_close": 0.1359226,
        "fee_close_cost": 4.931e-05,
        "fee_close_currency": "BTC",
        "open_date_hum": "5 hours ago",
        "open_date": "2020-11-02 10:00:59",
        "open_timestamp": 1604311259271,
        "open_rate": 2.702e-05,
        "open_rate_requested": 2.702e-05,
        "open_trade_price": 0.00035152,
        "close_date_hum": "2 hours ago",
        "close_date": "2020-11-02 12:14:31",
        "close_timestamp": 1604319271826,
        "close_rate": 2.7906153846153844e-05,
        "close_rate_requested": 2.8016433999999998e-05,
        "close_profit": -0.10825288,
        "close_profit_abs": -3.805e-05,
        "sell_reason": "emergency_sell",
        "sell_order_status": "closed",
        "stop_loss": 2.8016433999999998e-05,
        "stop_loss_abs": 2.8016433999999998e-05,
        "stop_loss_ratio": -0.01002,
        "stop_loss_pct": -1.002,
        "stoploss_order_id": null,
        "stoploss_last_update": "2020-11-02 12:13:23",
        "stoploss_last_update_timestamp": 1604319203747,
        "initial_stop_loss": 2.3019689e-05,
        "initial_stop_loss_abs": 2.3019689e-05,
        "initial_stop_loss_ratio": -0.14805,
        "initial_stop_loss_pct": -14.804999999999998,
        "min_rate": 2.662e-05,
        "max_rate": 2.83e-05,
        "open_order_id": null
    }
]
```
The problem seems to be your closing fee.

the column "fee_close" a relative value - so that's 13%.
Now obviously, even though your trade seems to have been positive from open / close numbers, with THAT amount of fees, it's kinda easy to be red again.

```
"fee_close": 0.1359226,
"fee_close_cost": 4.931e-05,
"fee_close_currency": "BTC",
```

Based on the numbers, the real profit is not wrong.

Would be great however if you you could check the fee for that closing trade on the exchange - maybe there's some problem - or maybe it really was that high (according to the logs, updating fees was done correctly) - that's difficult to tell just by looking at your data
The problem seems to be related to fees paid in BNB and not in BTC, look at the exchange data:
![image](https://user-images.githubusercontent.com/508111/97915938-95a3dd00-1d52-11eb-8afb-15c02ffb86ab.png)

i don't really understand how/why it can be mixed like this... you either have BNB (so fees are paid in BNB) or you're not and fees are in BTC. 
to me, all fees should be in BNB unless you run out - but it seems a broad mix of how fees are paid in your case
From what I've seen, when you convert small balances to BNB, BNB is used if there is enough to pay the fee, so in this case BNB was used and not enough for the 2 trades...so one time was used BNB and one time BTC.
What freqtrade done, is sum both numeric fees and consider it like BTC, so a very high fee (not true in real life).
I have my doubts that the problem really came from freqtrade's way of handling this, but with the way the exchange returns this - as it's a very strange constellation.

Could you please run the following (in a python shell within the environment that has ccxt installed) and post the output?

``` python
import ccxt
ct = ccxt.binance({
        'apiKey': 'YOUR_API_KEY',
        'secret': 'YOUR_SECRET',
})
order = ct.fetch_order('<orderid>', 'VIDA/BTC')
print(order)
```


You'll need your apikey/secret (don't post them here!) - as well as the order id.

You should be able to get the order id by looking at the database with the following query. 
Best use sqlitebrowser or sqlite3 to open the database

`select * from orders where ft_trade_id 30`

The order-id you're looking at should be the one with the highest id ... the one that's "filled" on the sell side.


Ok from the database I got the order id, for info I paste here the DB record (order id = 2506771)
![image](https://user-images.githubusercontent.com/508111/98082687-6fc52800-1e79-11eb-800f-706e9bd3c5ba.png)
And here the output of your script:
```
{'info': {'symbol': 'VIDTBTC', 'orderId': 2506771, 'orderListId': -1, 'clientOrderId': 'zlfMnjQGuN0D0mdZFgvROy', 'price': '0.00000000', 'origQty': '13.00000000', 'executedQty': '13.00000000', 'cummulativeQuoteQty': '0.00036278', 'status': 'FILLED', 'timeInForce': 'GTC', 'type': 'MARKET', 'side': 'SELL', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1604319271709, 'updateTime': 1604319271709, 'isWorking': True, 'origQuoteOrderQty': '0.00000000'}, 'id': '2506771', 'clientOrderId': 'zlfMnjQGuN0D0mdZFgvROy', 'timestamp': 1604319271709, 'datetime': '2020-11-02T12:14:31.709Z', 'lastTradeTimestamp': None, 'symbol': 'VIDT/BTC', 'type': 'market', 'side': 'sell', 'price': 2.7906153846153844e-05, 'amount': 13.0, 'cost': 0.00036278, 'average': 2.7906153846153844e-05, 'filled': 13.0, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': None}
```


The trade is confirmed by Binance: 

![image](https://user-images.githubusercontent.com/9531438/99936116-a4cee700-2d62-11eb-96da-a47450fa06d0.png)

Based on the symptoms (and the screenshot) - i suspect this is a duplicate of #3922.

Unfortunately, the KEY log message for this (`2020-11-23 02:18:23,747 - freqtrade.freqtradebot - INFO - Fee for Trade Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=2020-11-23 01:15:54) [sell]: 0.05030694 B$`) seems cut off - as this should include the fee currency, and the fee rate (which it doesn't - so maybe you're able to provide the remainder of this line).


Sorry, here's the full line (not very good with nano :D)
`2020-11-23 02:18:23,747 - freqtrade.freqtradebot - INFO - Fee for Trade Trade(id=69, pair=ETH/USDT, amount=0.08933000, open_rate=559.36000000, open_since=2020-11-23 01:15:54) [sell]: 0.05030694 BNB - rate: 0.03058935`
Ok this is a fee issue, the bot thinks it's BNB fees while it's a USD. There's a ~x30 ratio issue here (BNB price today)
What happens here I think it the bot is taking the first order currency (BNB), then sums up both
(0.00000013 + 0.05030681 = 0.05030694). All orders should have their own ratio to USD calculation
Feel free to submit a PR (including tests and such) that will fix this if you think it's that easy to fix.

The theory of what's happening is rather clear, but so far, i'm yet to get a full API response that includes this problem - which makes recreating it very difficult, as the `fetch_order` call you can do for the order placed now will not include the response included right after the order creation (see the other issue for this).

with that, all we can do is guess / try to recreate this.

It's not unfixable, but it'll take some time.


Sure thing, understanding the root cause is a first step.
At least it's not impacting the strategy, only the results/statistics. That's not too critical.
And that also only in very rare cases - as I've only seen 2 cases in over 3 years with this problem.
I guess the problem is just BNB balance. If you have dust they'll be consumed first, and then the rest is taken on currency sold.
no, BNB will be taken first, even if you own dust ..., unless you're out of BNB / have disabled BNB fees.

that's why i don't understand why you can have part of the order using BNB, and part in USDT assuming you've still got BNB left in the account...
`no, BNB will be taken first, even if you own dust ..., unless you're out of BNB`
That's what I'm saying by "dust", not enough to pay the whole fees

Could you please run the following (in a python shell within the environment that has ccxt installed) and post the output?

``` python
import ccxt
ct = ccxt.binance({
        'apiKey': 'YOUR_API_KEY',
        'secret': 'YOUR_SECRET',
})
--ct.verbose = True
order = ct.fetch_order('<orderid>', 'ETH/USDT')
print(order)
```


You'll need your apikey/secret (don't post them here!) - as well as the order id.

You should be able to get the order id by looking at the database with the following query. 
Best use sqlitebrowser or sqlite3 to open the database

`select * from orders where ft_trade_id = 69`

The order-id you're looking at should be the one with the highest id ... the one that's "filled" on the sell side.

I suspect the response will be similar to what we got in #3922 - which was not helpful as fee was not included ... but it's worth a try nonetheless.


I have another one. 
![image](https://user-images.githubusercontent.com/9531438/99990571-42063b80-2db4-11eb-9906-6eb5985412c4.png)

I'll try to get the binance ID, but it's not really immediate. I'll see what I can do.

Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -1448,13 +1448,16 @@ def get_real_amount(self, trade: Trade, order: Dict) -> float:
             fee_cost, fee_currency, fee_rate = self.exchange.extract_cost_curr_rate(order)
             logger.info(f"Fee for Trade {trade} [{order.get('side')}]: "
                         f"{fee_cost:.8g} {fee_currency} - rate: {fee_rate}")
-
-            trade.update_fee(fee_cost, fee_currency, fee_rate, order.get('side', ''))
-            if trade_base_currency == fee_currency:
-                # Apply fee to amount
-                return self.apply_fee_conditional(trade, trade_base_currency,
-                                                  amount=order_amount, fee_abs=fee_cost)
-            return order_amount
+            if fee_rate is None or fee_rate < 0.02:
+                # Reject all fees that report as > 2%.
+                # These are most likely caused by a parsing bug in ccxt
+                # due to multiple trades (https://github.com/ccxt/ccxt/issues/8025)
+                trade.update_fee(fee_cost, fee_currency, fee_rate, order.get('side', ''))
+                if trade_base_currency == fee_currency:
+                    # Apply fee to amount
+                    return self.apply_fee_conditional(trade, trade_base_currency,
+                                                      amount=order_amount, fee_abs=fee_cost)
+                return order_amount
         return self.fee_detection_from_trades(trade, order, order_amount)
 
     def fee_detection_from_trades(self, trade: Trade, order: Dict, order_amount: float) -> float:


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1588,16 +1588,7 @@ def fetch_trades_result():
 
 @pytest.fixture(scope="function")
 def trades_for_order2():
-    return [{'info': {'id': 34567,
-                      'orderId': 123456,
-                      'price': '0.24544100',
-                      'qty': '8.00000000',
-                      'commission': '0.00800000',
-                      'commissionAsset': 'LTC',
-                      'time': 1521663363189,
-                      'isBuyer': True,
-                      'isMaker': False,
-                      'isBestMatch': True},
+    return [{'info': {},
              'timestamp': 1521663363189,
              'datetime': '2018-03-21T20:16:03.189Z',
              'symbol': 'LTC/ETH',
@@ -1609,16 +1600,7 @@ def trades_for_order2():
              'cost': 1.963528,
              'amount': 4.0,
              'fee': {'cost': 0.004, 'currency': 'LTC'}},
-            {'info': {'id': 34567,
-                      'orderId': 123456,
-                      'price': '0.24544100',
-                      'qty': '8.00000000',
-                      'commission': '0.00800000',
-                      'commissionAsset': 'LTC',
-                      'time': 1521663363189,
-                      'isBuyer': True,
-                      'isMaker': False,
-                      'isBestMatch': True},
+            {'info': {},
              'timestamp': 1521663363189,
              'datetime': '2018-03-21T20:16:03.189Z',
              'symbol': 'LTC/ETH',
@@ -1632,6 +1614,14 @@ def trades_for_order2():
              'fee': {'cost': 0.004, 'currency': 'LTC'}}]
 
 
+@pytest.fixture(scope="function")
+def trades_for_order3(trades_for_order2):
+    # Different fee currencies for each trade
+    trades_for_order = deepcopy(trades_for_order2)
+    trades_for_order[0]['fee'] = {'cost': 0.02, 'currency': 'BNB'}
+    return trades_for_order
+
+
 @pytest.fixture
 def buy_order_fee():
     return {
diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py
--- a/tests/test_freqtradebot.py
+++ b/tests/test_freqtradebot.py
@@ -3718,6 +3718,48 @@ def test_get_real_amount_multi(default_conf, trades_for_order2, buy_order_fee, c
                    'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.992).',
                    caplog)
 
+    assert trade.fee_open == 0.001
+    assert trade.fee_close == 0.001
+    assert trade.fee_open_cost is not None
+    assert trade.fee_open_currency is not None
+    assert trade.fee_close_cost is None
+    assert trade.fee_close_currency is None
+
+
+def test_get_real_amount_multi2(default_conf, trades_for_order3, buy_order_fee, caplog, fee,
+                                mocker, markets):
+    # Different fee currency on both trades
+    mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order3)
+    amount = float(sum(x['amount'] for x in trades_for_order3))
+    default_conf['stake_currency'] = 'ETH'
+    trade = Trade(
+        pair='LTC/ETH',
+        amount=amount,
+        exchange='binance',
+        fee_open=fee.return_value,
+        fee_close=fee.return_value,
+        open_rate=0.245441,
+        open_order_id="123456"
+    )
+    # Fake markets entry to enable fee parsing
+    markets['BNB/ETH'] = markets['ETH/BTC']
+    freqtrade = get_patched_freqtradebot(mocker, default_conf)
+    mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
+    mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
+                 return_value={'ask': 0.19, 'last': 0.2})
+
+    # Amount is reduced by "fee"
+    assert freqtrade.get_real_amount(trade, buy_order_fee) == amount - (amount * 0.0005)
+    assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
+                   'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996).',
+                   caplog)
+    # Overall fee is average of both trade's fee
+    assert trade.fee_open == 0.001518575
+    assert trade.fee_open_cost is not None
+    assert trade.fee_open_currency is not None
+    assert trade.fee_close_cost is None
+    assert trade.fee_close_currency is None
+
 
 def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee, fee,
                                    caplog, mocker):
@@ -4264,7 +4306,7 @@ def test_update_closed_trades_without_assigned_fees(mocker, default_conf, fee):
     freqtrade = get_patched_freqtradebot(mocker, default_conf)
 
     def patch_with_fee(order):
-        order.update({'fee': {'cost': 0.1, 'rate': 0.2,
+        order.update({'fee': {'cost': 0.1, 'rate': 0.01,
                       'currency': order['symbol'].split('/')[0]}})
         return order