Repository: freqtrade/freqtrade

Issue:
FTX - "trade commands" error
## Step 1: Have you search for this issue before posting it?



## Step 2: Describe your environment

  * Operating system:Ubuntu 18.04
  * Python Version: 3.7.3
  * CCXT version: ccxt==1.23.30
  * Branch: Develop
  * Last Commit ID: 77944175e27bcd7851a83863f5df15f3577d61de

  
## Step 3: Describe the problem:

started FT as usually, most of the trades the bot is doing ok on FTX. I started the bot on dry-run with FTX, all good. Today I switched to live - error happened 2x

### Steps to reproduce:

  1. _____
  2. _____
  3. _____
  
### Observed Results:

BEAR/USD is causing some issues, see below

### Relevant code exceptions or logs:


```
2020-03-19 10:40:19,048 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=EOSBEAR/USD, amount=0.17200000, open_rate=58.07500000, open_since=2020-03-19 09:30:17)
2020-03-19 10:40:19,331 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=4, pair=XRPBEAR/USD, amount=0.00830000, open_rate=1196.00000000, open_since=2020-03-19 09:30:19)
2020-03-19 10:40:19,616 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=5, pair=BNBBEAR/USD, amount=0.06620324, open_rate=151.05000000, open_since=2020-03-19 09:30:20)
2020-03-19 10:40:20,216 - freqtrade.freqtradebot - INFO - Pair BEAR/USD is currently locked.
2020-03-19 10:40:20,216 - freqtrade.freqtradebot - INFO - Pair ETHBEAR/USD is currently locked.
2020-03-19 10:40:22,234 - freqtrade.freqtradebot - INFO - Buy order cancelled due to timeout for Trade(id=5, pair=BNBBEAR/USD, amount=0.06620324, open_rate=151.05000000, open_since=2020-03-19 09:30:20).
2020-03-19 10:40:22,235 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2020-03-19 10:40:22,235 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2020-03-19 10:40:22,278 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2020-03-19 10:40:22,279 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2020-03-19 10:40:39,202 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/root/freqtrade/freqtrade/main.py", line 36, in main
    return_code = args['func'](args)
  File "/root/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
    worker.run()
  File "/root/freqtrade/freqtrade/worker.py", line 66, in run
    state = self._worker(old_state=state)
  File "/root/freqtrade/freqtrade/worker.py", line 104, in _worker
    self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
  File "/root/freqtrade/freqtrade/worker.py", line 125, in _throttle
    result = func(*args, **kwargs)
  File "/root/freqtrade/freqtrade/worker.py", line 139, in _process_running
    self.freqtrade.process()
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 158, in process
    self.check_handle_timedout()
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 874, in check_handle_timedout
    self.handle_timedout_limit_buy(trade, order)
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 901, in handle_timedout_limit_buy
    if corder.get('remaining', order['remaining']) == order['amount']:
AttributeError: 'str' object has no attribute 'get'
2020-03-19 10:40:42,122 - freqtrade.loggers - INFO - Verbosity set to 0
2020-03-19 10:40:42,123 - freqtrade.configuration.configuration - INFO - Runmode set to live.
```



  ```
  2020-03-19 13:40:00,791 - freqtrade.freqtradebot - INFO - Pair ETHBEAR/USD is currently locked.
2020-03-19 13:40:01,521 - freqtrade.freqtradebot - INFO - Buy order cancelled due to timeout for Trade(id=13, pair=BEAR/USD, amount=0.46114826, open_rate=21.68500000, open_since=2020-03-19 12:30:00).
2020-03-19 13:40:01,522 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2020-03-19 13:40:01,522 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2020-03-19 13:40:01,659 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2020-03-19 13:40:01,659 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2020-03-19 13:40:10,112 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/root/freqtrade/freqtrade/main.py", line 36, in main
    return_code = args['func'](args)
  File "/root/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
    worker.run()
  File "/root/freqtrade/freqtrade/worker.py", line 66, in run
    state = self._worker(old_state=state)
  File "/root/freqtrade/freqtrade/worker.py", line 104, in _worker
    self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
  File "/root/freqtrade/freqtrade/worker.py", line 125, in _throttle
    result = func(*args, **kwargs)
  File "/root/freqtrade/freqtrade/worker.py", line 139, in _process_running
    self.freqtrade.process()
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 158, in process
    self.check_handle_timedout()
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 874, in check_handle_timedout
    self.handle_timedout_limit_buy(trade, order)
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 901, in handle_timedout_limit_buy
    if corder.get('remaining', order['remaining']) == order['amount']:
AttributeError: 'str' object has no attribute 'get'
2020-03-19 13:40:13,544 - freqtrade.loggers - INFO - Verbosity set to 0
2020-03-19 13:40:13,545 - freqtrade.configuration.configuration - INFO - Runmode set to live.
  ```



Discussion:
what ordertypes are you using? 
following the corresponding part of my config:

```
    "unfilledtimeout": {
        "buy": 10,
        "sell": 30
    
    },

    "bid_strategy": {
        "price_side": "bid",
        "use_order_book": false,
        "ask_last_balance": 0.5,
        "order_book_top": 1,
        "check_depth_of_market": {
            "enabled": false,
            "bids_to_ask_delta": 1
        }
    },
    "ask_strategy":{
        "price_side": "ask",
        "use_order_book": false,
        "order_book_min": 1,
        "order_book_max": 1,
        "use_sell_signal": true,
        "sell_profit_only": false,
        "ignore_roi_if_buy_signal": false
    },

    "order_types": {
    "buy": "limit",
    "sell": "limit",
    "emergencysell": "market",
    "stoploss": "limit",
    "stoploss_on_exchange": false,
    "stoploss_on_exchange_interval": 60
    },


	"order_time_in_force": {
	    "buy": "gtc",
	    "sell": "gtc"
	},

```

Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -891,6 +891,9 @@ def handle_timedout_limit_buy(self, trade: Trade, order: Dict) -> bool:
         if order['status'] != 'canceled':
             reason = "cancelled due to timeout"
             corder = self.exchange.cancel_order(trade.open_order_id, trade.pair)
+            # Some exchanges don't return a dict here.
+            if not isinstance(corder, dict):
+                corder = {}
             logger.info('Buy order %s for %s.', reason, trade)
         else:
             # Order was cancelled already, so we can reuse the existing dict


Test patch:
diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py
--- a/tests/test_freqtradebot.py
+++ b/tests/test_freqtradebot.py
@@ -2228,10 +2228,16 @@ def test_handle_timedout_limit_buy(mocker, default_conf, limit_buy_order) -> Non
     assert cancel_order_mock.call_count == 1
 
 
-def test_handle_timedout_limit_buy_corder_empty(mocker, default_conf, limit_buy_order) -> None:
+@pytest.mark.parametrize('cancelorder', [
+    {},
+    'String Return value',
+    123
+])
+def test_handle_timedout_limit_buy_corder_empty(mocker, default_conf, limit_buy_order,
+                                                cancelorder) -> None:
     patch_RPCManager(mocker)
     patch_exchange(mocker)
-    cancel_order_mock = MagicMock(return_value={})
+    cancel_order_mock = MagicMock(return_value=cancelorder)
     mocker.patch.multiple(
         'freqtrade.exchange.Exchange',
         cancel_order=cancel_order_mock