Repository: freqtrade/freqtrade

Issue:
FTX issue when backtesting spot markets
## Step 1: Have you search for this issue before posting it?

yes

## Step 2: Describe your environment

  * Operating system: linux
  * Python Version: Python 3.7.5rc1
  * CCXT version: ccxt==1.19.25 
  * Branch: Develop 
  * Last Commit ID: latest
  
## Step 3: Describe the problem:

When doing 
`freqtrade backtesting -c ftx.json --strategy-list chop ao ao2 ao3 --ticker-interval=4h`
using BTC/USD and FTT/USD markets with proper USD as stake currency, then an error pops out.

### Steps to reproduce:

  1. try to backtest using FTX as exchange, pair BTC/USD 
  2. Error pops out
  
### Observed Results:

  Error: 
```
2019-12-13 17:08:48,545 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/home/dante/freqtrade/freqtrade/main.py", line 36, in main
    return_code = args['func'](args)
  File "/home/dante/freqtrade/freqtrade/optimize/__init__.py", line 43, in start_backtesting
    backtesting = Backtesting(config)
  File "/home/dante/freqtrade/freqtrade/optimize/backtesting.py", line 68, in __init__
    self.fee = self.exchange.get_fee()
  File "/home/dante/freqtrade/freqtrade/exchange/common.py", line 113, in wrapper
    return f(*args, **kwargs)
  File "/home/dante/freqtrade/freqtrade/exchange/exchange.py", line 932, in get_fee
    price=price, takerOrMaker=taker_or_maker)['rate']
  File "/home/dante/.local/lib/python3.7/site-packages/ccxt/base/exchange.py", line 1710, in calculate_fee
    market = self.markets[symbol]
KeyError: 'ETH/BTC'

```
I was expecting a simple backtest as usual.



Discussion:
well - please use pairs that are available in your pairlist.
The error shows that your pairlist (in your configuration) contains ETH/BTC.
ETH/BTC is not available.

```
freqtrade list-pairs --exchange ftx --quote BTC

Exchange FTX has 1 active market with BTC as quote currency:
| Id      | Symbol   | Base   | Quote   | Active   | Is pair   |
|:--------|:---------|:-------|:--------|:---------|:----------|
| FTT/BTC | FTT/BTC  | FTT    | BTC     | True     | True      |

```


with BTC as quote - that's exactly one, which is FTT/BTC.

Remove ETH/BTC from the pairlist ... then it should work.

I don't have Eth btc as pair. The only pairs on my list are fttusd and btcusd. 
can confirm this,
can be reproduced with DefaultStrategy:

* `cp config_binance.json.example config_ftx.json`
* Edit config_ftx.json, set: exchange name: "ftx", pair_whitelist: ["BTC/USD", "FTT/USD"], pair_blacklist: [], stake_currency: "USD", stake_amount: 100, ticker_interval: "4h".
* `freqtrade download-data -c config_ftx.json --days 90 -t 4h`
* `freqtrade backtesting -c config_ftx.json -s DefaultStrategy`
-- fails with `KeyError: 'ETH/BTC'`

Fails at exchange initialization, before loading the strategy.
for now - use `--fee 0.001` (or whatever the fee as ratio is on FTX) as a workaround. then it'll work.

Resolving patch:
diff --git a/freqtrade/edge/__init__.py b/freqtrade/edge/__init__.py
--- a/freqtrade/edge/__init__.py
+++ b/freqtrade/edge/__init__.py
@@ -80,7 +80,7 @@ def __init__(self, config: Dict[str, Any], exchange, strategy) -> None:
         if config.get('fee'):
             self.fee = config['fee']
         else:
-            self.fee = self.exchange.get_fee()
+            self.fee = self.exchange.get_fee(symbol=self.config['exchange']['pair_whitelist'][0])
 
     def calculate(self) -> bool:
         pairs = self.config['exchange']['pair_whitelist']
diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py
--- a/freqtrade/exchange/exchange.py
+++ b/freqtrade/exchange/exchange.py
@@ -921,7 +921,7 @@ def get_trades_for_order(self, order_id: str, pair: str, since: datetime) -> Lis
             raise OperationalException(e) from e
 
     @retrier
-    def get_fee(self, symbol='ETH/BTC', type='', side='', amount=1,
+    def get_fee(self, symbol, type='', side='', amount=1,
                 price=1, taker_or_maker='maker') -> float:
         try:
             # validate that markets are loaded before trying to get fee
diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py
--- a/freqtrade/optimize/backtesting.py
+++ b/freqtrade/optimize/backtesting.py
@@ -65,7 +65,7 @@ def __init__(self, config: Dict[str, Any]) -> None:
         if config.get('fee'):
             self.fee = config['fee']
         else:
-            self.fee = self.exchange.get_fee()
+            self.fee = self.exchange.get_fee(symbol=self.config['exchange']['pair_whitelist'][0])
 
         if self.config.get('runmode') != RunMode.HYPEROPT:
             self.dataprovider = DataProvider(self.config, self.exchange)


Test patch:
diff --git a/tests/edge/test_edge.py b/tests/edge/test_edge.py
--- a/tests/edge/test_edge.py
+++ b/tests/edge/test_edge.py
@@ -334,7 +334,7 @@ def test_process_expectancy(mocker, edge_conf):
     edge_conf['edge']['min_trade_number'] = 2
     freqtrade = get_patched_freqtradebot(mocker, edge_conf)
 
-    def get_fee():
+    def get_fee(*args, **kwargs):
         return 0.001
 
     freqtrade.exchange.get_fee = get_fee
diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py
--- a/tests/exchange/test_exchange.py
+++ b/tests/exchange/test_exchange.py
@@ -1646,10 +1646,10 @@ def test_get_fee(default_conf, mocker, exchange_name):
     })
     exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
 
-    assert exchange.get_fee() == 0.025
+    assert exchange.get_fee('ETH/BTC') == 0.025
 
     ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name,
-                           'get_fee', 'calculate_fee')
+                           'get_fee', 'calculate_fee', symbol="ETH/BTC")
 
 
 def test_stoploss_limit_order_unsupported_exchange(default_conf, mocker):