Repository: freqtrade/freqtrade

Issue:
WhiteList question Followed by an error
Bittrex

Since some minutes (after a filled order), I have this message : 

`freqtrade.freqtradebot - INFO - No currency pair in active pair whitelist, but checking to sell open trades.`

What does it mean ? I've restarted but same message.

Found it :
`# Remove pairs for currently opened trades from the whitelist`


Discussion:
And 2 hours after : 
```
2020-05-20 18:46:26,404 - freqtrade.freqtradebot - INFO - No currency pair in active pair whitelist, but checking to sell open trades.
2020-05-20 18:46:26,405 - freqtrade.worker - INFO - Bot heartbeat. PID=106, version='develop-d438af34', state='RUNNING'
2020-05-20 18:46:30,917 - freqtrade.freqtradebot - INFO - No currency pair in active pair whitelist, but checking to sell open trades.
2020-05-20 18:46:40,402 - freqtrade.commands.trade_commands - ERROR - '>' not supported between instances of 'float' and 'NoneType'
2020-05-20 18:46:40,403 - freqtrade.commands.trade_commands - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/home/speedoo/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
    worker.run()
  File "/home/speedoo/freqtrade/freqtrade/worker.py", line 73, in run
    state = self._worker(old_state=state)
  File "/home/speedoo/freqtrade/freqtrade/worker.py", line 107, in _worker
    self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
  File "/home/speedoo/freqtrade/freqtrade/worker.py", line 128, in _throttle
    result = func(*args, **kwargs)
  File "/home/speedoo/freqtrade/freqtrade/worker.py", line 141, in _process_running
    self.freqtrade.process()
  File "/home/speedoo/freqtrade/freqtrade/freqtradebot.py", line 163, in process
    self.exit_positions(trades)
  File "/home/speedoo/freqtrade/freqtrade/freqtradebot.py", line 621, in exit_positions
    if trade.open_order_id is None and trade.is_open and self.handle_trade(trade):
  File "/home/speedoo/freqtrade/freqtrade/freqtradebot.py", line 712, in handle_trade
    if self._check_and_execute_sell(trade, sell_rate, buy, sell):
  File "/home/speedoo/freqtrade/freqtrade/freqtradebot.py", line 837, in _check_and_execute_sell
    should_sell = self.strategy.should_sell(
  File "/home/speedoo/freqtrade/freqtrade/strategy/interface.py", line 368, in should_sell
    trade.adjust_min_max_rates(high or current_rate)
  File "/home/speedoo/freqtrade/freqtrade/persistence.py", line 290, in adjust_min_max_rates
    self.max_rate = max(current_price, self.max_rate or self.open_rate)
TypeError: '>' not supported between instances of 'float' and 'NoneType'
2020-05-20 18:46:40,505 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
```
Well this issue is missing almost all information.

what exchange did this happen with? 
which pair was/is the trade causing this error?

Also - i don't think the two issues are related ... 
Bittrex. No error on the 3 markets I use.
I included all the error I have and displayed
No indication of the pair that caused the issue. Bot waiting for a sell signal (the INFO)
I've the 'correct' INFO since 2 hours, and subitly the error without any other indication

seems like current_price is empty ... 

what's your configuration for `ask_strategy` (please post the whole substructure) ? 

```
"ask_strategy": {
        "price_side": "ask",
        "use_order_book": false,
        "order_book_min": 1,
        "order_book_max": 1
    },
```

I relaunched it, and wait.
with this configuration it's using fetch_ticker. 

I think above the logs you showed above, there must be other errors (most likely related to networking) - otherwise i cannot explain how this might be possible, as the price is passed back "as is" from the `fetch_ticker()['ask']` (<- this is simplified) side.

Sorry @xmatthias, i've not see any other errors before, and no backup for that.

I've sometimes some networking errors, yes, and this error not happen again for now.

But it's an error that can happain again 



Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -676,6 +676,8 @@ def get_sell_rate(self, pair: str, refresh: bool) -> float:
                 raise PricingError from e
         else:
             rate = self.exchange.fetch_ticker(pair)[ask_strategy['price_side']]
+        if rate is None:
+            raise PricingError(f"Sell-Rate for {pair} was empty.")
         self._sell_rate_cache[pair] = rate
         return rate
 


Test patch:
diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py
--- a/tests/test_freqtradebot.py
+++ b/tests/test_freqtradebot.py
@@ -3931,6 +3931,28 @@ def test_get_sell_rate_orderbook_exception(default_conf, mocker, caplog):
     assert log_has("Sell Price at location from orderbook could not be determined.", caplog)
 
 
+def test_get_sell_rate_exception(default_conf, mocker, caplog):
+    # Ticker on one side can be empty in certain circumstances.
+    default_conf['ask_strategy']['price_side'] = 'ask'
+    pair = "ETH/BTC"
+    mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
+                 return_value={'ask': None, 'bid': 0.12})
+    ft = get_patched_freqtradebot(mocker, default_conf)
+    with pytest.raises(PricingError, match=r"Sell-Rate for ETH/BTC was empty."):
+        ft.get_sell_rate(pair, True)
+
+    ft.config['ask_strategy']['price_side'] = 'bid'
+    assert ft.get_sell_rate(pair, True) == 0.12
+    # Reverse sides
+    mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
+                 return_value={'ask': 0.13, 'bid': None})
+    with pytest.raises(PricingError, match=r"Sell-Rate for ETH/BTC was empty."):
+        ft.get_sell_rate(pair, True)
+
+    ft.config['ask_strategy']['price_side'] = 'ask'
+    assert ft.get_sell_rate(pair, True) == 0.13
+
+
 def test_startup_state(default_conf, mocker):
     default_conf['pairlist'] = {'method': 'VolumePairList',
                                 'config': {'number_assets': 20}