From 4a097bd64449a8debc04613f46d0f8c2481ea5c1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 19 Mar 2024 07:13:17 +0100 Subject: [PATCH] More usages for ConfigurationError --- freqtrade/commands/deploy_commands.py | 4 ++-- freqtrade/data/btanalysis.py | 4 ++-- freqtrade/exchange/exchange.py | 30 ++++++++++++++------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/freqtrade/commands/deploy_commands.py b/freqtrade/commands/deploy_commands.py index 75da2552e..c87f55e43 100644 --- a/freqtrade/commands/deploy_commands.py +++ b/freqtrade/commands/deploy_commands.py @@ -9,7 +9,7 @@ from freqtrade.configuration import setup_utils_configuration from freqtrade.configuration.directory_operations import copy_sample_files, create_userdata_dir from freqtrade.constants import USERPATH_STRATEGIES from freqtrade.enums import RunMode -from freqtrade.exceptions import OperationalException +from freqtrade.exceptions import ConfigurationError, OperationalException from freqtrade.util import render_template, render_template_with_fallback @@ -89,7 +89,7 @@ def start_new_strategy(args: Dict[str, Any]) -> None: deploy_new_strategy(args['strategy'], new_path, args['template']) else: - raise OperationalException("`new-strategy` requires --strategy to be set.") + raise ConfigurationError("`new-strategy` requires --strategy to be set.") def clean_ui_subdir(directory: Path): diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 9d9b17552..ef92d4db6 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -11,7 +11,7 @@ import numpy as np import pandas as pd from freqtrade.constants import LAST_BT_RESULT_FN, IntOrInf -from freqtrade.exceptions import OperationalException +from freqtrade.exceptions import ConfigurationError, OperationalException from freqtrade.misc import file_dump_json, json_load from freqtrade.optimize.backtest_caching import get_backtest_metadata_filename from freqtrade.persistence import LocalTrade, Trade, init_db @@ -106,7 +106,7 @@ def get_latest_hyperopt_file( directory = Path(directory) if predef_filename: if Path(predef_filename).is_absolute(): - raise OperationalException( + raise ConfigurationError( "--hyperopt-filename expects only the filename, not an absolute path.") return directory / predef_filename return directory / get_latest_hyperopt_filename(directory) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 84b4212bd..07c1c2809 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -24,9 +24,10 @@ from freqtrade.constants import (DEFAULT_AMOUNT_RESERVE_PERCENT, NON_OPEN_EXCHAN ListPairsWithTimeframes, MakerTaker, OBLiteral, PairWithTimeframe) from freqtrade.data.converter import clean_ohlcv_dataframe, ohlcv_to_dataframe, trades_dict_to_list from freqtrade.enums import OPTIMIZE_MODES, CandleType, MarginMode, PriceType, RunMode, TradingMode -from freqtrade.exceptions import (DDosProtection, ExchangeError, InsufficientFundsError, - InvalidOrderException, OperationalException, PricingError, - RetryableOrderError, TemporaryError) +from freqtrade.exceptions import (ConfigurationError, DDosProtection, ExchangeError, + InsufficientFundsError, InvalidOrderException, + OperationalException, PricingError, RetryableOrderError, + TemporaryError) from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, remove_exchange_credentials, retrier, retrier_async) from freqtrade.exchange.exchange_utils import (ROUND, ROUND_DOWN, ROUND_UP, CcxtModuleType, @@ -527,7 +528,7 @@ class Exchange: ) quote_currencies = self.get_quote_currencies() if stake_currency not in quote_currencies: - raise OperationalException( + raise ConfigurationError( f"{stake_currency} is not available as stake on {self.name}. " f"Available currencies are: {', '.join(quote_currencies)}") @@ -595,7 +596,7 @@ class Exchange: f"is therefore not supported. ccxt fetchOHLCV: {self.exchange_has('fetchOHLCV')}") if timeframe and (timeframe not in self.timeframes): - raise OperationalException( + raise ConfigurationError( f"Invalid timeframe '{timeframe}'. This exchange supports: {self.timeframes}") if ( @@ -603,7 +604,7 @@ class Exchange: and self._config['runmode'] != RunMode.UTIL_EXCHANGE and timeframe_to_minutes(timeframe) < 1 ): - raise OperationalException("Timeframes < 1m are currently not supported by Freqtrade.") + raise ConfigurationError("Timeframes < 1m are currently not supported by Freqtrade.") def validate_ordertypes(self, order_types: Dict) -> None: """ @@ -611,7 +612,7 @@ class Exchange: """ if any(v == 'market' for k, v in order_types.items()): if not self.exchange_has('createMarketOrder'): - raise OperationalException( + raise ConfigurationError( f'Exchange {self.name} does not support market orders.') self.validate_stop_ordertypes(order_types) @@ -621,7 +622,7 @@ class Exchange: """ if (order_types.get("stoploss_on_exchange") and not self._ft_has.get("stoploss_on_exchange", False)): - raise OperationalException( + raise ConfigurationError( f'On exchange stoploss is not supported for {self.name}.' ) if self.trading_mode == TradingMode.FUTURES: @@ -631,17 +632,17 @@ class Exchange: and 'stoploss_price_type' in order_types and order_types['stoploss_price_type'] not in price_mapping ): - raise OperationalException( + raise ConfigurationError( f'On exchange stoploss price type is not supported for {self.name}.' ) def validate_pricing(self, pricing: Dict) -> None: if pricing.get('use_order_book', False) and not self.exchange_has('fetchL2OrderBook'): - raise OperationalException(f'Orderbook not available for {self.name}.') + raise ConfigurationError(f'Orderbook not available for {self.name}.') if (not pricing.get('use_order_book', False) and ( not self.exchange_has('fetchTicker') or not self._ft_has['tickers_have_price'])): - raise OperationalException(f'Ticker pricing not available for {self.name}.') + raise ConfigurationError(f'Ticker pricing not available for {self.name}.') def validate_order_time_in_force(self, order_time_in_force: Dict) -> None: """ @@ -649,7 +650,7 @@ class Exchange: """ if any(v.upper() not in self._ft_has["order_time_in_force"] for k, v in order_time_in_force.items()): - raise OperationalException( + raise ConfigurationError( f'Time in force policies are not supported for {self.name} yet.') def validate_required_startup_candles(self, startup_candles: int, timeframe: str) -> int: @@ -671,12 +672,12 @@ class Exchange: if required_candle_call_count > 5: # Only allow 5 calls per pair to somewhat limit the impact - raise OperationalException( + raise ConfigurationError( f"This strategy requires {startup_candles} candles to start, " "which is more than 5x " f"the amount of candles {self.name} provides for {timeframe}.") elif required_candle_call_count > 1: - raise OperationalException( + raise ConfigurationError( f"This strategy requires {startup_candles} candles to start, which is more than " f"the amount of candles {self.name} provides for {timeframe}.") if required_candle_call_count > 1: @@ -3094,3 +3095,4 @@ class Exchange: # describes the min amt for a tier, and the lowest tier will always go down to 0 else: raise ExchangeError(f"Cannot get maintenance ratio using {self.name}") + raise ExchangeError(f"Cannot get maintenance ratio using {self.name}")