From 5e059660d472d545e0e997628f4b6fb8eaa1d073 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 20 Jun 2025 20:19:20 +0200 Subject: [PATCH] chore: move remove_exchange_credentials to config module --- freqtrade/configuration/__init__.py | 2 +- freqtrade/configuration/config_secrets.py | 16 +++++++++++++++- freqtrade/exchange/__init__.py | 2 +- freqtrade/exchange/common.py | 15 --------------- freqtrade/exchange/exchange.py | 2 +- freqtrade/freqtradebot.py | 3 +-- freqtrade/rpc/api_server/api_backtest.py | 2 +- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/freqtrade/configuration/__init__.py b/freqtrade/configuration/__init__.py index aa06a70c9..cf8479919 100644 --- a/freqtrade/configuration/__init__.py +++ b/freqtrade/configuration/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa: F401 -from freqtrade.configuration.config_secrets import sanitize_config +from freqtrade.configuration.config_secrets import remove_exchange_credentials, sanitize_config from freqtrade.configuration.config_setup import setup_utils_configuration from freqtrade.configuration.config_validation import validate_config_consistency from freqtrade.configuration.configuration import Configuration diff --git a/freqtrade/configuration/config_secrets.py b/freqtrade/configuration/config_secrets.py index 5e5c44240..67f78b6d7 100644 --- a/freqtrade/configuration/config_secrets.py +++ b/freqtrade/configuration/config_secrets.py @@ -1,6 +1,6 @@ from copy import deepcopy -from freqtrade.constants import Config +from freqtrade.constants import Config, ExchangeConfig _SENSITIVE_KEYS = [ @@ -47,3 +47,17 @@ def sanitize_config(config: Config, *, show_sensitive: bool = False) -> Config: config[key] = "REDACTED" return config + + +def remove_exchange_credentials(exchange_config: ExchangeConfig, dry_run: bool) -> None: + """ + Removes exchange keys from the configuration and specifies dry-run + Used for backtesting / hyperopt and utils. + Modifies the input dict! + """ + if dry_run: + exchange_config["key"] = "" + exchange_config["apiKey"] = "" + exchange_config["secret"] = "" + exchange_config["password"] = "" + exchange_config["uid"] = "" diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 01f9d93ed..9cf3e1108 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa: F401 # isort: off -from freqtrade.exchange.common import remove_exchange_credentials, MAP_EXCHANGE_CHILDCLASS +from freqtrade.exchange.common import MAP_EXCHANGE_CHILDCLASS from freqtrade.exchange.exchange import Exchange # isort: on diff --git a/freqtrade/exchange/common.py b/freqtrade/exchange/common.py index 5e4f6bf07..3780eab06 100644 --- a/freqtrade/exchange/common.py +++ b/freqtrade/exchange/common.py @@ -5,7 +5,6 @@ from collections.abc import Callable from functools import wraps from typing import Any, TypeVar, cast, overload -from freqtrade.constants import ExchangeConfig from freqtrade.exceptions import DDosProtection, RetryableOrderError, TemporaryError from freqtrade.mixins import LoggingMixin @@ -104,20 +103,6 @@ EXCHANGE_HAS_OPTIONAL = [ ] -def remove_exchange_credentials(exchange_config: ExchangeConfig, dry_run: bool) -> None: - """ - Removes exchange keys from the configuration and specifies dry-run - Used for backtesting / hyperopt and utils. - Modifies the input dict! - """ - if dry_run: - exchange_config["key"] = "" - exchange_config["apiKey"] = "" - exchange_config["secret"] = "" - exchange_config["password"] = "" - exchange_config["uid"] = "" - - def calculate_backoff(retrycount, max_retries): """ Calculate backoff diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index ffd8cdb6d..e4c33e0f3 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -21,6 +21,7 @@ from ccxt import TICK_SIZE from dateutil import parser from pandas import DataFrame, concat +from freqtrade.configuration import remove_exchange_credentials from freqtrade.constants import ( DEFAULT_AMOUNT_RESERVE_PERCENT, DEFAULT_TRADES_COLUMNS, @@ -64,7 +65,6 @@ from freqtrade.exceptions import ( ) from freqtrade.exchange.common import ( API_FETCH_ORDER_RETRY_COUNT, - remove_exchange_credentials, retrier, retrier_async, ) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 422973167..c5605412d 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -14,7 +14,7 @@ from typing import Any from schedule import Scheduler from freqtrade import constants -from freqtrade.configuration import validate_config_consistency +from freqtrade.configuration import remove_exchange_credentials, validate_config_consistency from freqtrade.constants import BuySell, Config, EntryExecuteMode, ExchangeConfig, LongShort from freqtrade.data.converter import order_book_to_dataframe from freqtrade.data.dataprovider import DataProvider @@ -37,7 +37,6 @@ from freqtrade.exceptions import ( from freqtrade.exchange import ( ROUND_DOWN, ROUND_UP, - remove_exchange_credentials, timeframe_to_minutes, timeframe_to_next_date, timeframe_to_seconds, diff --git a/freqtrade/rpc/api_server/api_backtest.py b/freqtrade/rpc/api_server/api_backtest.py index 98a7586df..b553bc1fa 100644 --- a/freqtrade/rpc/api_server/api_backtest.py +++ b/freqtrade/rpc/api_server/api_backtest.py @@ -8,6 +8,7 @@ from typing import Any from fastapi import APIRouter, BackgroundTasks, Depends from fastapi.exceptions import HTTPException +from freqtrade.configuration import remove_exchange_credentials from freqtrade.configuration.config_validation import validate_config_consistency from freqtrade.constants import Config from freqtrade.data.btanalysis import ( @@ -20,7 +21,6 @@ from freqtrade.data.btanalysis import ( ) from freqtrade.enums import BacktestState from freqtrade.exceptions import ConfigurationError, DependencyException, OperationalException -from freqtrade.exchange.common import remove_exchange_credentials from freqtrade.ft_types import get_BacktestResultType_default from freqtrade.misc import deep_merge_dicts, is_file_in_dir from freqtrade.rpc.api_server.api_schemas import (