Repository: freqtrade/freqtrade

Issue:
no Telegram Status Table update
    Python Version: 3.6.7
    CCXT version: 1.18.347
    Branch: Master

## Step 3: Describe the problem:

the status table on Telegram is "static", showing same values. I was relaoding the config and the values being updated. Otherwise the values are not changing.

PS: just seen that the same porblem is with the "performance" - same values if checking several times after same waiting period, static ...

### Relevant code exceptions or logs:

no error message



Discussion:
I have solved the problem - seems to be a bug:

when I change the ask strategy "use_order_book" to "false" it is working, before I was running on true

    "ask_strategy":{
        "use_order_book": false,
        "order_book_min": 1,
        "order_book_max": 10
so order_book does impact the telegram reporting messages ... ? that's surely not how it should be ...
yes, for sure not ... can you reproduce this error?
yes - it happens because get_ticker is never called when orderbook is on.




Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -579,6 +579,25 @@ def get_real_amount(self, trade: Trade, order: Dict) -> float:
                         f"(from {order_amount} to {real_amount}) from Trades")
         return real_amount
 
+    def get_sell_rate(self, pair: str, refresh: bool) -> float:
+        """
+        Get sell rate - either using get-ticker bid or first bid based on orderbook
+        The orderbook portion is only used for rpc messaging, which would otherwise fail
+        for BitMex (has no bid/ask in get_ticker)
+        or remain static in any other case since it's not updating.
+        :return: Bid rate
+        """
+        config_ask_strategy = self.config.get('ask_strategy', {})
+        if config_ask_strategy.get('use_order_book', False):
+            logger.debug('Using order book to get sell rate')
+
+            order_book = self.exchange.get_order_book(pair, 1)
+            rate = order_book['bids'][0][0]
+
+        else:
+            rate = self.exchange.get_ticker(pair, refresh)['bid']
+        return rate
+
     def handle_trade(self, trade: Trade) -> bool:
         """
         Sells the current pair if the threshold is reached and updates the trade record.
@@ -615,7 +634,7 @@ def handle_trade(self, trade: Trade) -> bool:
 
         else:
             logger.debug('checking sell')
-            sell_rate = self.exchange.get_ticker(trade.pair)['bid']
+            sell_rate = self.get_sell_rate(trade.pair, True)
             if self.check_sell(trade, sell_rate, buy, sell):
                 return True
 
@@ -858,7 +877,8 @@ def notify_sell(self, trade: Trade):
         """
         profit_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested
         profit_trade = trade.calc_profit(rate=profit_rate)
-        current_rate = self.exchange.get_ticker(trade.pair)['bid']
+        # Use cached ticker here - it was updated seconds ago.
+        current_rate = self.get_sell_rate(trade.pair, False)
         profit_percent = trade.calc_profit_percent(profit_rate)
         gain = "profit" if profit_percent > 0 else "loss"
 
diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py
--- a/freqtrade/rpc/rpc.py
+++ b/freqtrade/rpc/rpc.py
@@ -94,7 +94,7 @@ def _rpc_trade_status(self) -> List[Dict[str, Any]]:
                     order = self._freqtrade.exchange.get_order(trade.open_order_id, trade.pair)
                 # calculate profit and send message to user
                 try:
-                    current_rate = self._freqtrade.exchange.get_ticker(trade.pair, False)['bid']
+                    current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
                 except DependencyException:
                     current_rate = NAN
                 current_profit = trade.calc_profit_percent(current_rate)
@@ -125,7 +125,7 @@ def _rpc_status_table(self) -> DataFrame:
             for trade in trades:
                 # calculate profit and send message to user
                 try:
-                    current_rate = self._freqtrade.exchange.get_ticker(trade.pair, False)['bid']
+                    current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
                 except DependencyException:
                     current_rate = NAN
                 trade_perc = (100 * trade.calc_profit_percent(current_rate))
@@ -213,7 +213,7 @@ def _rpc_trade_statistics(
             else:
                 # Get current rate
                 try:
-                    current_rate = self._freqtrade.exchange.get_ticker(trade.pair, False)['bid']
+                    current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
                 except DependencyException:
                     current_rate = NAN
                 profit_percent = trade.calc_profit_percent(rate=current_rate)
@@ -280,9 +280,9 @@ def _rpc_balance(self, fiat_display_currency: str) -> Dict:
             else:
                 try:
                     if coin == 'USDT':
-                        rate = 1.0 / self._freqtrade.exchange.get_ticker('BTC/USDT', False)['bid']
+                        rate = 1.0 / self._freqtrade.get_sell_rate('BTC/USDT', False)
                     else:
-                        rate = self._freqtrade.exchange.get_ticker(coin + '/BTC', False)['bid']
+                        rate = self._freqtrade.get_sell_rate(coin + '/BTC', False)
                 except (TemporaryError, DependencyException):
                     continue
             est_btc: float = rate * balance['total']
@@ -356,7 +356,7 @@ def _exec_forcesell(trade: Trade) -> None:
                     return
 
             # Get current rate and execute sell
-            current_rate = self._freqtrade.exchange.get_ticker(trade.pair, False)['bid']
+            current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
             self._freqtrade.execute_sell(trade, current_rate, SellType.FORCE_SELL)
         # ---- EOF def _exec_forcesell ----
 


Test patch:
diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py
--- a/freqtrade/tests/test_freqtradebot.py
+++ b/freqtrade/tests/test_freqtradebot.py
@@ -2962,6 +2962,31 @@ def test_order_book_ask_strategy(default_conf, limit_buy_order, limit_sell_order
     assert freqtrade.handle_trade(trade) is True
 
 
+def test_get_sell_rate(default_conf, mocker, ticker, order_book_l2) -> None:
+
+    mocker.patch.multiple(
+        'freqtrade.exchange.Exchange',
+        get_order_book=order_book_l2,
+        get_ticker=ticker,
+    )
+    pair = "ETH/BTC"
+
+    # Test regular mode
+    ft = get_patched_freqtradebot(mocker, default_conf)
+    rate = ft.get_sell_rate(pair, True)
+    assert isinstance(rate, float)
+    assert rate == 0.00001098
+
+    # Test orderbook mode
+    default_conf['ask_strategy']['use_order_book'] = True
+    default_conf['ask_strategy']['order_book_min'] = 1
+    default_conf['ask_strategy']['order_book_max'] = 2
+    ft = get_patched_freqtradebot(mocker, default_conf)
+    rate = ft.get_sell_rate(pair, True)
+    assert isinstance(rate, float)
+    assert rate == 0.043936
+
+
 def test_startup_messages(default_conf, mocker):
     default_conf['pairlist'] = {'method': 'VolumePairList',
                                 'config': {'number_assets': 20}