diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 88c06c111..54d564f04 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -59,7 +59,7 @@ def init_ccxt(exchange_config: dict) -> ccxt.Exchange: name = exchange_config['name'] if name not in ccxt.exchanges: - raise OperationalException('Exchange {} is not supported'.format(name)) + raise OperationalException(f'Exchange {name} is not supported') try: api = getattr(ccxt, name.lower())({ 'apiKey': exchange_config.get('key'), @@ -69,7 +69,7 @@ def init_ccxt(exchange_config: dict) -> ccxt.Exchange: 'enableRateLimit': True, }) except (KeyError, AttributeError): - raise OperationalException('Exchange {} is not supported'.format(name)) + raise OperationalException(f'Exchange {name} is not supported') return api @@ -118,11 +118,10 @@ def validate_pairs(pairs: List[str]) -> None: # TODO: add a support for having coins in BTC/USDT format if not pair.endswith(stake_cur): raise OperationalException( - 'Pair {} not compatible with stake_currency: {}'.format(pair, stake_cur) - ) + f'Pair {pair} not compatible with stake_currency: {stake_cur}') if pair not in markets: raise OperationalException( - 'Pair {} is not available at {}'.format(pair, get_name())) + f'Pair {pair} is not available at {get_name()}') def exchange_has(endpoint: str) -> bool: @@ -138,7 +137,7 @@ def exchange_has(endpoint: str) -> bool: def buy(pair: str, rate: float, amount: float) -> Dict: if _CONF['dry_run']: global _DRY_RUN_OPEN_ORDERS - order_id = 'dry_run_buy_{}'.format(randint(0, 10**6)) + order_id = f'dry_run_buy_{randint(0, 10**6)}' _DRY_RUN_OPEN_ORDERS[order_id] = { 'pair': pair, 'price': rate, @@ -156,20 +155,17 @@ def buy(pair: str, rate: float, amount: float) -> Dict: return _API.create_limit_buy_order(pair, amount, rate) except ccxt.InsufficientFunds as e: raise DependencyException( - 'Insufficient funds to create limit buy order on market {}.' - 'Tried to buy amount {} at rate {} (total {}).' - 'Message: {}'.format(pair, amount, rate, rate*amount, e) - ) + f'Insufficient funds to create limit buy order on market {pair}.' + f'Tried to buy amount {amount} at rate {rate} (total {rate*amount}).' + f'Message: {e}') except ccxt.InvalidOrder as e: raise DependencyException( - 'Could not create limit buy order on market {}.' - 'Tried to buy amount {} at rate {} (total {}).' - 'Message: {}'.format(pair, amount, rate, rate*amount, e) - ) + f'Could not create limit buy order on market {pair}.' + f'Tried to buy amount {amount} at rate {rate} (total {rate*amount}).' + f'Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not place buy order due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not place buy order due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -177,7 +173,7 @@ def buy(pair: str, rate: float, amount: float) -> Dict: def sell(pair: str, rate: float, amount: float) -> Dict: if _CONF['dry_run']: global _DRY_RUN_OPEN_ORDERS - order_id = 'dry_run_sell_{}'.format(randint(0, 10**6)) + order_id = f'dry_run_sell_{randint(0, 10**6)}' _DRY_RUN_OPEN_ORDERS[order_id] = { 'pair': pair, 'price': rate, @@ -194,20 +190,17 @@ def sell(pair: str, rate: float, amount: float) -> Dict: return _API.create_limit_sell_order(pair, amount, rate) except ccxt.InsufficientFunds as e: raise DependencyException( - 'Insufficient funds to create limit sell order on market {}.' - 'Tried to sell amount {} at rate {} (total {}).' - 'Message: {}'.format(pair, amount, rate, rate*amount, e) - ) + f'Insufficient funds to create limit sell order on market {pair}.' + f'Tried to sell amount {amount} at rate {rate} (total {rate*amount}).' + f'Message: {e}') except ccxt.InvalidOrder as e: raise DependencyException( - 'Could not create limit sell order on market {}.' - 'Tried to sell amount {} at rate {} (total {}).' - 'Message: {}'.format(pair, amount, rate, rate*amount, e) - ) + f'Could not create limit sell order on market {pair}.' + f'Tried to sell amount {amount} at rate {rate} (total {rate*amount}).' + f'Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not place sell order due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -222,8 +215,7 @@ def get_balance(currency: str) -> float: balance = balances.get(currency) if balance is None: raise TemporaryError( - 'Could not get {} balance due to malformed exchange response: {}'.format( - currency, balances)) + f'Could not get {currency} balance due to malformed exchange response: {balances}') return balance['free'] @@ -243,8 +235,7 @@ def get_balances() -> dict: return balances except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not get balance due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not get balance due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -255,13 +246,11 @@ def get_tickers() -> Dict: return _API.fetch_tickers() except ccxt.NotSupported as e: raise OperationalException( - 'Exchange {} does not support fetching tickers in batch.' - 'Message: {}'.format(_API.name, e) - ) + f'Exchange {_API.name} does not support fetching tickers in batch.' + f'Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not load tickers due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not load tickers due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -282,8 +271,7 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict: return data except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not load ticker history due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) else: @@ -327,15 +315,13 @@ def get_ticker_history(pair: str, tick_interval: str, since_ms: Optional[int] = return data except ccxt.NotSupported as e: raise OperationalException( - 'Exchange {} does not support fetching historical candlestick data.' - 'Message: {}'.format(_API.name, e) - ) + f'Exchange {_API.name} does not support fetching historical candlestick data.' + f'Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not load ticker history due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not load ticker history due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: - raise OperationalException('Could not fetch ticker data. Msg: {}'.format(e)) + raise OperationalException(f'Could not fetch ticker data. Msg: {e}') @retrier @@ -347,12 +333,10 @@ def cancel_order(order_id: str, pair: str) -> None: return _API.cancel_order(order_id, pair) except ccxt.InvalidOrder as e: raise DependencyException( - 'Could not cancel order. Message: {}'.format(e) - ) + f'Could not cancel order. Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not cancel order due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not cancel order due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -369,12 +353,10 @@ def get_order(order_id: str, pair: str) -> Dict: return _API.fetch_order(order_id, pair) except ccxt.InvalidOrder as e: raise DependencyException( - 'Could not get order. Message: {}'.format(e) - ) + f'Could not get order. Message: {e}') except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not get order due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not get order due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -393,8 +375,7 @@ def get_trades_for_order(order_id: str, pair: str, since: datetime) -> List: except ccxt.NetworkError as e: raise TemporaryError( - 'Could not get trades due to networking error. Message: {}'.format(e) - ) + f'Could not get trades due to networking error. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -416,8 +397,7 @@ def get_markets() -> List[dict]: return _API.fetch_markets() except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not load markets due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not load markets due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e) @@ -442,8 +422,7 @@ def get_fee(symbol='ETH/BTC', type='', side='', amount=1, price=price, takerOrMaker=taker_or_maker)['rate'] except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( - 'Could not get fee info due to {}. Message: {}'.format( - e.__class__.__name__, e)) + f'Could not get fee info due to {e.__class__.__name__}. Message: {e}') except ccxt.BaseError as e: raise OperationalException(e)