# Buggy code
def _get_min_pair_stake_amount(self, pair: str, price: float) -> Optional[float]:
    markets = self.exchange.get_markets()
    markets = [m for m in markets if m["symbol"] == pair]
    if not markets:
        raise ValueError(f"Can't get market information for symbol {pair}")

    market = markets[0]

    if "limits" not in market:
        return None

    min_stake_amounts = []
    if "cost" in market["limits"] and "min" in market["limits"]["cost"]:
        min_stake_amounts.append(market["limits"]["cost"]["min"])

    if "amount" in market["limits"] and "min" in market["limits"]["amount"]:
        min_stake_amounts.append(market["limits"]["amount"]["min"] * price)

    if not min_stake_amounts:
        return None

    amount_reserve_percent = 1 - 0.05  # reserve 5% + stoploss
    if self.analyze.get_stoploss() is not None:
        amount_reserve_percent += self.analyze.get_stoploss()
    # it should not be more than 50%
    amount_reserve_percent = max(amount_reserve_percent, 0.5)
    return min(min_stake_amounts) / amount_reserve_percent


# Traceback (ccxt.base.errors.ExchangeError)
2018-06-26 10:53:11,366 - freqtrade.rpc.telegram - INFO - Executing handler: _balance for chat_id: 537131708
2018-06-26 10:53:11,632 - freqtrade.exchange - INFO - returning cached ticker-data for ABT/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for BDG/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for BRD/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for CMT/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for DENT/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for DXT/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for ETH/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - INFO - returning cached ticker-data for FXT/BTC
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - get_ticker() returned exception: "Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC"
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - retrying get_ticker() still for 3 times
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - get_ticker() returned exception: "Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC"
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - retrying get_ticker() still for 2 times
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - get_ticker() returned exception: "Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC"
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - retrying get_ticker() still for 1 times
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - get_ticker() returned exception: "Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC"
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - retrying get_ticker() still for 0 times
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - get_ticker() returned exception: "Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC"
2018-06-26 10:53:11,633 - freqtrade.exchange - WARNING - Giving up retrying: get_ticker()
2018-06-26 10:53:11,633 - freqtrade.rpc.telegram - ERROR - Exception occurred within Telegram module
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 261, in get_ticker
data = self._api.fetch_ticker(pair)
File "/usr/local/lib/python3.6/site-packages/ccxt/cobinhood.py", line 267, in fetch_ticker
market = self.market(symbol)
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1271, in market
self.raise_error(ExchangeError, details='No market symbol ' + str(symbol))
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 290, in raise_error
raise exception_type(output)
ccxt.base.errors.ExchangeError: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 32, in wrapper
return f(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 272, in get_ticker
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}')
freqtrade.TemporaryError: Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 261, in get_ticker
data = self._api.fetch_ticker(pair)
File "/usr/local/lib/python3.6/site-packages/ccxt/cobinhood.py", line 267, in fetch_ticker
market = self.market(symbol)
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1271, in market
self.raise_error(ExchangeError, details='No market symbol ' + str(symbol))
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 290, in raise_error
raise exception_type(output)
ccxt.base.errors.ExchangeError: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 32, in wrapper
return f(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 272, in get_ticker
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}')
freqtrade.TemporaryError: Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 261, in get_ticker
data = self._api.fetch_ticker(pair)
File "/usr/local/lib/python3.6/site-packages/ccxt/cobinhood.py", line 267, in fetch_ticker
market = self.market(symbol)
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1271, in market
self.raise_error(ExchangeError, details='No market symbol ' + str(symbol))
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 290, in raise_error
raise exception_type(output)
ccxt.base.errors.ExchangeError: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 32, in wrapper
return f(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 272, in get_ticker
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}')
freqtrade.TemporaryError: Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 261, in get_ticker
data = self._api.fetch_ticker(pair)
File "/usr/local/lib/python3.6/site-packages/ccxt/cobinhood.py", line 267, in fetch_ticker
market = self.market(symbol)
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1271, in market
self.raise_error(ExchangeError, details='No market symbol ' + str(symbol))
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 290, in raise_error
raise exception_type(output)
ccxt.base.errors.ExchangeError: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 32, in wrapper
return f(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 272, in get_ticker
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}')
freqtrade.TemporaryError: Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/exchange/__init__.py", line 261, in get_ticker
data = self._api.fetch_ticker(pair)
File "/usr/local/lib/python3.6/site-packages/ccxt/cobinhood.py", line 267, in fetch_ticker
market = self.market(symbol)
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1271, in market
self.raise_error(ExchangeError, details='No market symbol ' + str(symbol))
File "/usr/local/lib/python3.6/site-packages/ccxt/base/exchange.py", line 290, in raise_error
raise exception_type(output)
ccxt.base.errors.ExchangeError: cobinhood No market symbol HQX/BTC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/freqtrade/freqtrade/rpc/telegram.py", line 48, in wrapper
return command_handler(self, *args, **kwargs)
File "/freqtrade/freqtrade/rpc/telegram.py", line 243, in _balance
self._rpc_balance(self._config['fiat_display_currency'])
File "/freqtrade/freqtrade/rpc/rpc.py", line 270, in _rpc_balance
rate = self._freqtrade.exchange.get_ticker(coin + '/BTC', False)['bid']
File "/freqtrade/freqtrade/exchange/__init__.py", line 39, in wrapper
return wrapper(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 39, in wrapper
return wrapper(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 39, in wrapper
return wrapper(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 42, in wrapper
raise ex
File "/freqtrade/freqtrade/exchange/__init__.py", line 32, in wrapper
return f(*args, **kwargs)
File "/freqtrade/freqtrade/exchange/__init__.py", line 272, in get_ticker
f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}')
freqtrade.TemporaryError: Could not load ticker history due to ExchangeError. Message: cobinhood No market symbol HQX/BTC

# Fixed code
def _get_min_pair_stake_amount(self, pair: str, price: float) -> Optional[float]:
    markets = self.exchange.get_markets()
    markets = [m for m in markets if m["symbol"] == pair]
    if not markets:
        raise ValueError(f"Can't get market information for symbol {pair}")

    market = markets[0]

    if "limits" not in market:
        return None

    min_stake_amounts = []
    limits = market["limits"]
    if (
        "cost" in limits
        and "min" in limits["cost"]
        and limits["cost"]["min"] is not None
    ):
        min_stake_amounts.append(limits["cost"]["min"])

    if (
        "amount" in limits
        and "min" in limits["amount"]
        and limits["amount"]["min"] is not None
    ):
        min_stake_amounts.append(limits["amount"]["min"] * price)

    if not min_stake_amounts:
        return None

    amount_reserve_percent = 1 - 0.05  # reserve 5% + stoploss
    if self.analyze.get_stoploss() is not None:
        amount_reserve_percent += self.analyze.get_stoploss()
    # it should not be more than 50%
    amount_reserve_percent = max(amount_reserve_percent, 0.5)
    return min(min_stake_amounts) / amount_reserve_percent