# Buggy code
def dry_run_order(
    self,
    pair: str,
    ordertype: str,
    side: str,
    amount: float,
    rate: float,
    params: Dict = {},
) -> Dict[str, Any]:
    order_id = f"dry_run_{side}_{randint(0, 10**6)}"
    dry_order = {  # TODO: additional entry should be added for stoploss limit
        "id": order_id,
        "pair": pair,
        "price": rate,
        "amount": amount,
        "cost": amount * rate,
        "type": ordertype,
        "side": side,
        "remaining": amount,
        "datetime": arrow.utcnow().isoformat(),
        "status": "closed" if ordertype == "market" else "open",
        "fee": None,
        "info": {},
    }
    self._store_dry_order(dry_order)
    return dry_order


# Traceback (KeyError)
2019-08-06 22:44:55,366 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:44:59,196 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:45:05,099 - freqtrade.freqtradebot - INFO - Buy signal found: about create a new trade with stake_amount: 980 ...
2019-08-06 22:45:05,099 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2019-08-06 22:45:05,400 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': buy, 'exchange': 'Binance', 'pair': 'BTC/USDT', 'limit': 11642.115000000002, 'order_type': 'limit', 'stake_amount': 980, 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2019-08-06 22:45:05,928 - freqtrade.wallets - INFO - Wallets synced.
/root/freqtrade/.env/lib/python3.7/site-packages/arrow/factory.py:201: ArrowParseWarning: The .get() parsing method without a format string will parse more strictly in version 0.15.0.See https://github.com/crsmithdev/arrow/issues/612 for more details.
ArrowParseWarning,
2019-08-06 22:45:05,986 - freqtrade.wallets - INFO - Wallets synced.
2019-08-06 22:45:07,044 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now)
2019-08-06 22:45:07,045 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now) failed: myTrade-Dict empty found
2019-08-06 22:45:07,046 - freqtrade.persistence - INFO - Updating trade (id=1) ...
2019-08-06 22:45:07,046 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now).
2019-08-06 22:45:07,632 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:45:11,045 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/root/freqtrade/freqtrade/main.py", line 49, in main
worker.run()
File "/root/freqtrade/freqtrade/worker.py", line 72, in run
state = self._worker(old_state=state)
File "/root/freqtrade/freqtrade/worker.py", line 110, in _worker
self._throttle(func=self._process, min_secs=throttle_secs)
File "/root/freqtrade/freqtrade/worker.py", line 123, in _throttle
result = func(*args, **kwargs)
File "/root/freqtrade/freqtrade/worker.py", line 134, in _process
state_changed = self.freqtrade.process()
File "/root/freqtrade/freqtrade/freqtradebot.py", line 135, in process
state_changed |= self.process_maybe_execute_sell(trade)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 451, in process_maybe_execute_sell
result = self.handle_stoploss_on_exchange(trade)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 683, in handle_stoploss_on_exchange
self.handle_trailing_stoploss_on_exchange(trade, stoploss_order)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 696, in handle_trailing_stoploss_on_exchange
if trade.stop_loss > float(order['info']['stopPrice']):
KeyError: 'stopPrice'
2019-08-06 22:45:11,099 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2019-08-06 22:45:11,143 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2019-08-06 22:45:11,143 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
(.env) (base) root@vmanager6003:~/freqtrade#

# Fixed code
def dry_run_order(
    self,
    pair: str,
    ordertype: str,
    side: str,
    amount: float,
    rate: float,
    params: Dict = {},
) -> Dict[str, Any]:
    order_id = f"dry_run_{side}_{randint(0, 10**6)}"
    dry_order = {
        "id": order_id,
        "pair": pair,
        "price": rate,
        "amount": amount,
        "cost": amount * rate,
        "type": ordertype,
        "side": side,
        "remaining": amount,
        "datetime": arrow.utcnow().isoformat(),
        "status": "closed" if ordertype == "market" else "open",
        "fee": None,
        "info": {},
    }
    self._store_dry_order(dry_order)
    # Copy order and close it - so the returned order is open unless it's a market order
    return dry_order