2019-07-11 18:23:23 +00:00
|
|
|
import logging
|
2022-09-24 14:38:56 +00:00
|
|
|
from collections import Counter
|
2020-01-02 09:38:59 +00:00
|
|
|
from copy import deepcopy
|
2019-07-11 18:23:23 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
from jsonschema import Draft4Validator, validators
|
|
|
|
from jsonschema.exceptions import ValidationError, best_match
|
|
|
|
|
2019-12-30 14:02:17 +00:00
|
|
|
from freqtrade import constants
|
2022-03-08 05:59:14 +00:00
|
|
|
from freqtrade.configuration.deprecated_settings import process_deprecated_setting
|
2022-03-07 06:09:01 +00:00
|
|
|
from freqtrade.enums import RunMode, TradingMode
|
2024-03-19 05:41:23 +00:00
|
|
|
from freqtrade.exceptions import ConfigurationError
|
2019-07-11 18:23:23 +00:00
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2019-07-11 18:23:23 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def _extend_validator(validator_class):
|
|
|
|
"""
|
|
|
|
Extended validator for the Freqtrade configuration JSON Schema.
|
|
|
|
Currently it only handles defaults for subschemas.
|
|
|
|
"""
|
2024-05-12 14:29:24 +00:00
|
|
|
validate_properties = validator_class.VALIDATORS["properties"]
|
2019-07-11 18:23:23 +00:00
|
|
|
|
|
|
|
def set_defaults(validator, properties, instance, schema):
|
|
|
|
for prop, subschema in properties.items():
|
2024-05-12 14:29:24 +00:00
|
|
|
if "default" in subschema:
|
|
|
|
instance.setdefault(prop, subschema["default"])
|
2019-07-11 18:23:23 +00:00
|
|
|
|
2023-03-19 16:57:56 +00:00
|
|
|
yield from validate_properties(validator, properties, instance, schema)
|
2019-07-11 18:23:23 +00:00
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
return validators.extend(validator_class, {"properties": set_defaults})
|
2019-07-11 18:23:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
FreqtradeValidator = _extend_validator(Draft4Validator)
|
|
|
|
|
|
|
|
|
2022-05-01 07:53:34 +00:00
|
|
|
def validate_config_schema(conf: Dict[str, Any], preliminary: bool = False) -> Dict[str, Any]:
|
2019-07-11 18:23:23 +00:00
|
|
|
"""
|
|
|
|
Validate the configuration follow the Config Schema
|
|
|
|
:param conf: Config in JSON format
|
|
|
|
:return: Returns the config if valid, otherwise throw an exception
|
|
|
|
"""
|
2020-01-02 09:38:59 +00:00
|
|
|
conf_schema = deepcopy(constants.CONF_SCHEMA)
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("runmode", RunMode.OTHER) in (RunMode.DRY_RUN, RunMode.LIVE):
|
|
|
|
conf_schema["required"] = constants.SCHEMA_TRADE_REQUIRED
|
|
|
|
elif conf.get("runmode", RunMode.OTHER) in (RunMode.BACKTEST, RunMode.HYPEROPT):
|
2022-05-01 07:53:34 +00:00
|
|
|
if preliminary:
|
2024-05-12 14:29:24 +00:00
|
|
|
conf_schema["required"] = constants.SCHEMA_BACKTEST_REQUIRED
|
2022-05-01 07:53:34 +00:00
|
|
|
else:
|
2024-05-12 14:29:24 +00:00
|
|
|
conf_schema["required"] = constants.SCHEMA_BACKTEST_REQUIRED_FINAL
|
|
|
|
elif conf.get("runmode", RunMode.OTHER) == RunMode.WEBSERVER:
|
|
|
|
conf_schema["required"] = constants.SCHEMA_MINIMAL_WEBSERVER
|
2020-01-02 09:38:59 +00:00
|
|
|
else:
|
2024-05-12 14:29:24 +00:00
|
|
|
conf_schema["required"] = constants.SCHEMA_MINIMAL_REQUIRED
|
2019-07-11 18:23:23 +00:00
|
|
|
try:
|
2020-01-02 09:38:59 +00:00
|
|
|
FreqtradeValidator(conf_schema).validate(conf)
|
2019-07-11 18:23:23 +00:00
|
|
|
return conf
|
|
|
|
except ValidationError as e:
|
2024-05-12 14:29:24 +00:00
|
|
|
logger.critical(f"Invalid configuration. Reason: {e}")
|
|
|
|
raise ValidationError(best_match(Draft4Validator(conf_schema).iter_errors(conf)).message)
|
2019-08-18 14:10:10 +00:00
|
|
|
|
|
|
|
|
2023-12-11 19:35:49 +00:00
|
|
|
def validate_config_consistency(conf: Dict[str, Any], *, preliminary: bool = False) -> None:
|
2019-08-18 14:10:10 +00:00
|
|
|
"""
|
|
|
|
Validate the configuration consistency.
|
|
|
|
Should be ran after loading both configuration and strategy,
|
|
|
|
since strategies can set certain configuration settings too.
|
|
|
|
:param conf: Config in JSON format
|
2024-03-19 05:41:23 +00:00
|
|
|
:return: Returns None if everything is ok, otherwise throw an ConfigurationError
|
2019-08-18 14:10:10 +00:00
|
|
|
"""
|
2019-11-23 14:49:46 +00:00
|
|
|
|
2019-08-18 14:10:10 +00:00
|
|
|
# validating trailing stoploss
|
|
|
|
_validate_trailing_stoploss(conf)
|
2021-03-20 10:48:39 +00:00
|
|
|
_validate_price_config(conf)
|
2019-08-18 14:19:24 +00:00
|
|
|
_validate_edge(conf)
|
2019-10-25 05:07:01 +00:00
|
|
|
_validate_whitelist(conf)
|
2020-12-07 09:21:03 +00:00
|
|
|
_validate_protections(conf)
|
2020-01-03 06:07:59 +00:00
|
|
|
_validate_unlimited_amount(conf)
|
2021-06-25 18:36:39 +00:00
|
|
|
_validate_ask_orderbook(conf)
|
2022-09-07 14:11:31 +00:00
|
|
|
_validate_freqai_hyperopt(conf)
|
2022-09-26 02:14:00 +00:00
|
|
|
_validate_freqai_backtest(conf)
|
2023-12-11 19:32:37 +00:00
|
|
|
_validate_freqai_include_timeframes(conf, preliminary=preliminary)
|
2022-09-24 14:38:56 +00:00
|
|
|
_validate_consumers(conf)
|
2022-03-07 06:09:01 +00:00
|
|
|
validate_migrated_strategy_settings(conf)
|
2019-08-18 14:10:10 +00:00
|
|
|
|
2019-11-25 06:05:18 +00:00
|
|
|
# validate configuration before returning
|
2024-05-12 14:29:24 +00:00
|
|
|
logger.info("Validating configuration ...")
|
2022-05-01 07:53:34 +00:00
|
|
|
validate_config_schema(conf, preliminary=preliminary)
|
2019-11-25 06:05:18 +00:00
|
|
|
|
2019-08-18 14:10:10 +00:00
|
|
|
|
2020-01-03 06:07:59 +00:00
|
|
|
def _validate_unlimited_amount(conf: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
If edge is disabled, either max_open_trades or stake_amount need to be set.
|
2024-03-19 05:41:23 +00:00
|
|
|
:raise: ConfigurationError if config validation failed
|
2020-01-03 06:07:59 +00:00
|
|
|
"""
|
2024-05-12 14:29:24 +00:00
|
|
|
if (
|
|
|
|
not conf.get("edge", {}).get("enabled")
|
|
|
|
and conf.get("max_open_trades") == float("inf")
|
|
|
|
and conf.get("stake_amount") == constants.UNLIMITED_STAKE_AMOUNT
|
|
|
|
):
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError("`max_open_trades` and `stake_amount` cannot both be unlimited.")
|
2020-01-03 06:07:59 +00:00
|
|
|
|
|
|
|
|
2021-03-20 10:48:39 +00:00
|
|
|
def _validate_price_config(conf: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
When using market orders, price sides must be using the "other" side of the price
|
|
|
|
"""
|
2022-03-28 17:24:57 +00:00
|
|
|
# TODO: The below could be an enforced setting when using market orders
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("order_types", {}).get("entry") == "market" and conf.get("entry_pricing", {}).get(
|
|
|
|
"price_side"
|
|
|
|
) not in ("ask", "other"):
|
|
|
|
raise ConfigurationError('Market entry orders require entry_pricing.price_side = "other".')
|
|
|
|
|
|
|
|
if conf.get("order_types", {}).get("exit") == "market" and conf.get("exit_pricing", {}).get(
|
|
|
|
"price_side"
|
|
|
|
) not in ("bid", "other"):
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError('Market exit orders require exit_pricing.price_side = "other".')
|
2021-03-20 10:48:39 +00:00
|
|
|
|
|
|
|
|
2019-08-18 14:10:10 +00:00
|
|
|
def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("stoploss") == 0.0:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"The config stoploss needs to be different from 0 to avoid problems with sell orders."
|
2021-08-06 22:19:36 +00:00
|
|
|
)
|
2019-08-18 14:10:10 +00:00
|
|
|
# Skip if trailing stoploss is not activated
|
2024-05-12 14:29:24 +00:00
|
|
|
if not conf.get("trailing_stop", False):
|
2019-08-18 14:10:10 +00:00
|
|
|
return
|
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
tsl_positive = float(conf.get("trailing_stop_positive", 0))
|
|
|
|
tsl_offset = float(conf.get("trailing_stop_positive_offset", 0))
|
|
|
|
tsl_only_offset = conf.get("trailing_only_offset_is_reached", False)
|
2019-08-18 14:10:10 +00:00
|
|
|
|
|
|
|
if tsl_only_offset:
|
|
|
|
if tsl_positive == 0.0:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"The config trailing_only_offset_is_reached needs "
|
|
|
|
"trailing_stop_positive_offset to be more than 0 in your config."
|
|
|
|
)
|
2019-08-18 14:10:10 +00:00
|
|
|
if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"The config trailing_stop_positive_offset needs "
|
|
|
|
"to be greater than trailing_stop_positive in your config."
|
|
|
|
)
|
2019-08-18 14:19:24 +00:00
|
|
|
|
2019-08-22 17:49:50 +00:00
|
|
|
# Fetch again without default
|
2024-05-12 14:29:24 +00:00
|
|
|
if "trailing_stop_positive" in conf and float(conf["trailing_stop_positive"]) == 0.0:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"The config trailing_stop_positive needs to be different from 0 "
|
|
|
|
"to avoid problems with sell orders."
|
2019-08-22 17:49:50 +00:00
|
|
|
)
|
|
|
|
|
2019-08-18 14:19:24 +00:00
|
|
|
|
|
|
|
def _validate_edge(conf: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Edge and Dynamic whitelist should not both be enabled, since edge overrides dynamic whitelists.
|
|
|
|
"""
|
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
if not conf.get("edge", {}).get("enabled"):
|
2019-08-18 14:19:24 +00:00
|
|
|
return
|
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
if not conf.get("use_exit_signal", True):
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2022-04-05 18:07:58 +00:00
|
|
|
"Edge requires `use_exit_signal` to be True, otherwise no sells will happen."
|
2020-11-24 06:47:35 +00:00
|
|
|
)
|
2019-10-25 05:07:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_whitelist(conf: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Dynamic whitelist does not require pair_whitelist to be set - however StaticWhitelist does.
|
|
|
|
"""
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("runmode", RunMode.OTHER) in [
|
|
|
|
RunMode.OTHER,
|
|
|
|
RunMode.PLOT,
|
|
|
|
RunMode.UTIL_NO_EXCHANGE,
|
|
|
|
RunMode.UTIL_EXCHANGE,
|
|
|
|
]:
|
2019-10-25 05:07:01 +00:00
|
|
|
return
|
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
for pl in conf.get("pairlists", [{"method": "StaticPairList"}]):
|
|
|
|
if (
|
|
|
|
isinstance(pl, dict)
|
|
|
|
and pl.get("method") == "StaticPairList"
|
|
|
|
and not conf.get("exchange", {}).get("pair_whitelist")
|
|
|
|
):
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError("StaticPairList requires pair_whitelist to be set.")
|
2020-12-07 09:21:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_protections(conf: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Validate protection configuration validity
|
|
|
|
"""
|
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
for prot in conf.get("protections", []):
|
|
|
|
if "stop_duration" in prot and "stop_duration_candles" in prot:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2020-12-07 09:21:03 +00:00
|
|
|
"Protections must specify either `stop_duration` or `stop_duration_candles`.\n"
|
|
|
|
f"Please fix the protection {prot.get('method')}"
|
2021-08-06 22:19:36 +00:00
|
|
|
)
|
2020-12-07 09:21:03 +00:00
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
if "lookback_period" in prot and "lookback_period_candles" in prot:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2020-12-07 09:21:03 +00:00
|
|
|
"Protections must specify either `lookback_period` or `lookback_period_candles`.\n"
|
|
|
|
f"Please fix the protection {prot.get('method')}"
|
|
|
|
)
|
2021-06-25 18:36:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_ask_orderbook(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
ask_strategy = conf.get("exit_pricing", {})
|
|
|
|
ob_min = ask_strategy.get("order_book_min")
|
|
|
|
ob_max = ask_strategy.get("order_book_max")
|
|
|
|
if ob_min is not None and ob_max is not None and ask_strategy.get("use_order_book"):
|
2021-06-25 18:36:39 +00:00
|
|
|
if ob_min != ob_max:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2022-03-28 05:03:10 +00:00
|
|
|
"Using order_book_max != order_book_min in exit_pricing is no longer supported."
|
2021-06-25 18:36:39 +00:00
|
|
|
"Please pick one value and use `order_book_top` in the future."
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# Move value to order_book_top
|
2024-05-12 14:29:24 +00:00
|
|
|
ask_strategy["order_book_top"] = ob_min
|
2021-06-25 18:36:39 +00:00
|
|
|
logger.warning(
|
|
|
|
"DEPRECATED: "
|
|
|
|
"Please use `order_book_top` instead of `order_book_min` and `order_book_max` "
|
2022-03-28 05:03:10 +00:00
|
|
|
"for your `exit_pricing` configuration."
|
2021-06-25 18:36:39 +00:00
|
|
|
)
|
2022-03-07 06:09:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def validate_migrated_strategy_settings(conf: Dict[str, Any]) -> None:
|
|
|
|
_validate_time_in_force(conf)
|
2022-03-08 05:59:14 +00:00
|
|
|
_validate_order_types(conf)
|
2022-03-26 10:55:11 +00:00
|
|
|
_validate_unfilledtimeout(conf)
|
2022-03-27 16:58:46 +00:00
|
|
|
_validate_pricing_rules(conf)
|
2022-04-05 18:00:35 +00:00
|
|
|
_strategy_settings(conf)
|
2022-03-07 06:09:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_time_in_force(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
time_in_force = conf.get("order_time_in_force", {})
|
|
|
|
if "buy" in time_in_force or "sell" in time_in_force:
|
|
|
|
if conf.get("trading_mode", TradingMode.SPOT) != TradingMode.SPOT:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Please migrate your time_in_force settings to use 'entry' and 'exit'."
|
|
|
|
)
|
2022-03-07 06:09:01 +00:00
|
|
|
else:
|
|
|
|
logger.warning(
|
|
|
|
"DEPRECATED: Using 'buy' and 'sell' for time_in_force is deprecated."
|
|
|
|
"Please migrate your time_in_force settings to use 'entry' and 'exit'."
|
|
|
|
)
|
2022-03-09 05:40:12 +00:00
|
|
|
process_deprecated_setting(
|
2024-05-12 14:29:24 +00:00
|
|
|
conf, "order_time_in_force", "buy", "order_time_in_force", "entry"
|
|
|
|
)
|
2022-03-09 05:40:12 +00:00
|
|
|
|
|
|
|
process_deprecated_setting(
|
2024-05-12 14:29:24 +00:00
|
|
|
conf, "order_time_in_force", "sell", "order_time_in_force", "exit"
|
|
|
|
)
|
2022-03-08 05:59:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_order_types(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
order_types = conf.get("order_types", {})
|
|
|
|
old_order_types = [
|
|
|
|
"buy",
|
|
|
|
"sell",
|
|
|
|
"emergencysell",
|
|
|
|
"forcebuy",
|
|
|
|
"forcesell",
|
|
|
|
"emergencyexit",
|
|
|
|
"forceexit",
|
|
|
|
"forceentry",
|
|
|
|
]
|
2022-04-07 18:33:54 +00:00
|
|
|
if any(x in order_types for x in old_order_types):
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("trading_mode", TradingMode.SPOT) != TradingMode.SPOT:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Please migrate your order_types settings to use the new wording."
|
|
|
|
)
|
2022-03-08 05:59:14 +00:00
|
|
|
else:
|
|
|
|
logger.warning(
|
|
|
|
"DEPRECATED: Using 'buy' and 'sell' for order_types is deprecated."
|
2022-03-08 06:08:10 +00:00
|
|
|
"Please migrate your order_types settings to use 'entry' and 'exit' wording."
|
2022-03-08 05:59:14 +00:00
|
|
|
)
|
|
|
|
for o, n in [
|
2024-05-12 14:29:24 +00:00
|
|
|
("buy", "entry"),
|
|
|
|
("sell", "exit"),
|
|
|
|
("emergencysell", "emergency_exit"),
|
|
|
|
("forcesell", "force_exit"),
|
|
|
|
("forcebuy", "force_entry"),
|
|
|
|
("emergencyexit", "emergency_exit"),
|
|
|
|
("forceexit", "force_exit"),
|
|
|
|
("forceentry", "force_entry"),
|
2022-03-08 05:59:14 +00:00
|
|
|
]:
|
2024-05-12 14:29:24 +00:00
|
|
|
process_deprecated_setting(conf, "order_types", o, "order_types", n)
|
2022-03-26 10:55:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_unfilledtimeout(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
unfilledtimeout = conf.get("unfilledtimeout", {})
|
|
|
|
if any(x in unfilledtimeout for x in ["buy", "sell"]):
|
|
|
|
if conf.get("trading_mode", TradingMode.SPOT) != TradingMode.SPOT:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Please migrate your unfilledtimeout settings to use the new wording."
|
|
|
|
)
|
2022-03-26 10:55:11 +00:00
|
|
|
else:
|
|
|
|
logger.warning(
|
|
|
|
"DEPRECATED: Using 'buy' and 'sell' for unfilledtimeout is deprecated."
|
|
|
|
"Please migrate your unfilledtimeout settings to use 'entry' and 'exit' wording."
|
|
|
|
)
|
|
|
|
for o, n in [
|
2024-05-12 14:29:24 +00:00
|
|
|
("buy", "entry"),
|
|
|
|
("sell", "exit"),
|
2022-03-26 10:55:11 +00:00
|
|
|
]:
|
2024-05-12 14:29:24 +00:00
|
|
|
process_deprecated_setting(conf, "unfilledtimeout", o, "unfilledtimeout", n)
|
2022-03-27 16:58:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _validate_pricing_rules(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("ask_strategy") or conf.get("bid_strategy"):
|
|
|
|
if conf.get("trading_mode", TradingMode.SPOT) != TradingMode.SPOT:
|
|
|
|
raise ConfigurationError("Please migrate your pricing settings to use the new wording.")
|
2022-03-27 16:58:46 +00:00
|
|
|
else:
|
|
|
|
logger.warning(
|
|
|
|
"DEPRECATED: Using 'ask_strategy' and 'bid_strategy' is deprecated."
|
|
|
|
"Please migrate your settings to use 'entry_pricing' and 'exit_pricing'."
|
|
|
|
)
|
2024-05-12 14:29:24 +00:00
|
|
|
conf["entry_pricing"] = {}
|
|
|
|
for obj in list(conf.get("bid_strategy", {}).keys()):
|
|
|
|
if obj == "ask_last_balance":
|
|
|
|
process_deprecated_setting(
|
|
|
|
conf, "bid_strategy", obj, "entry_pricing", "price_last_balance"
|
|
|
|
)
|
2022-03-28 17:48:45 +00:00
|
|
|
else:
|
2024-05-12 14:29:24 +00:00
|
|
|
process_deprecated_setting(conf, "bid_strategy", obj, "entry_pricing", obj)
|
|
|
|
del conf["bid_strategy"]
|
|
|
|
|
|
|
|
conf["exit_pricing"] = {}
|
|
|
|
for obj in list(conf.get("ask_strategy", {}).keys()):
|
|
|
|
if obj == "bid_last_balance":
|
|
|
|
process_deprecated_setting(
|
|
|
|
conf, "ask_strategy", obj, "exit_pricing", "price_last_balance"
|
|
|
|
)
|
2022-03-28 17:48:45 +00:00
|
|
|
else:
|
2024-05-12 14:29:24 +00:00
|
|
|
process_deprecated_setting(conf, "ask_strategy", obj, "exit_pricing", obj)
|
|
|
|
del conf["ask_strategy"]
|
2022-04-05 18:00:35 +00:00
|
|
|
|
|
|
|
|
2022-09-07 14:11:31 +00:00
|
|
|
def _validate_freqai_hyperopt(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
freqai_enabled = conf.get("freqai", {}).get("enabled", False)
|
|
|
|
analyze_per_epoch = conf.get("analyze_per_epoch", False)
|
2022-09-07 17:42:05 +00:00
|
|
|
if analyze_per_epoch and freqai_enabled:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Using analyze-per-epoch parameter is not supported with a FreqAI strategy."
|
|
|
|
)
|
2022-09-07 14:11:31 +00:00
|
|
|
|
|
|
|
|
2023-12-11 19:32:37 +00:00
|
|
|
def _validate_freqai_include_timeframes(conf: Dict[str, Any], preliminary: bool) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
freqai_enabled = conf.get("freqai", {}).get("enabled", False)
|
2022-10-09 12:36:12 +00:00
|
|
|
if freqai_enabled:
|
2024-05-12 14:29:24 +00:00
|
|
|
main_tf = conf.get("timeframe", "5m")
|
|
|
|
freqai_include_timeframes = (
|
|
|
|
conf.get("freqai", {}).get("feature_parameters", {}).get("include_timeframes", [])
|
|
|
|
)
|
2022-10-09 12:36:12 +00:00
|
|
|
|
|
|
|
from freqtrade.exchange import timeframe_to_seconds
|
2024-05-12 14:29:24 +00:00
|
|
|
|
2022-10-09 12:36:12 +00:00
|
|
|
main_tf_s = timeframe_to_seconds(main_tf)
|
|
|
|
offending_lines = []
|
|
|
|
for tf in freqai_include_timeframes:
|
|
|
|
tf_s = timeframe_to_seconds(tf)
|
|
|
|
if tf_s < main_tf_s:
|
|
|
|
offending_lines.append(tf)
|
|
|
|
if offending_lines:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2022-10-09 12:36:12 +00:00
|
|
|
f"Main timeframe of {main_tf} must be smaller or equal to FreqAI "
|
2024-05-12 14:29:24 +00:00
|
|
|
f"`include_timeframes`.Offending include-timeframes: {', '.join(offending_lines)}"
|
|
|
|
)
|
2022-10-09 12:36:12 +00:00
|
|
|
|
2022-12-05 20:54:15 +00:00
|
|
|
# Ensure that the base timeframe is included in the include_timeframes list
|
2023-12-11 19:32:37 +00:00
|
|
|
if not preliminary and main_tf not in freqai_include_timeframes:
|
2024-05-12 14:29:24 +00:00
|
|
|
feature_parameters = conf.get("freqai", {}).get("feature_parameters", {})
|
2022-12-05 20:54:15 +00:00
|
|
|
include_timeframes = [main_tf] + freqai_include_timeframes
|
2024-05-12 14:29:24 +00:00
|
|
|
conf.get("freqai", {}).get("feature_parameters", {}).update(
|
|
|
|
{**feature_parameters, "include_timeframes": include_timeframes}
|
|
|
|
)
|
2022-12-05 20:54:15 +00:00
|
|
|
|
2022-10-09 12:36:12 +00:00
|
|
|
|
2022-09-26 02:14:00 +00:00
|
|
|
def _validate_freqai_backtest(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
if conf.get("runmode", RunMode.OTHER) == RunMode.BACKTEST:
|
|
|
|
freqai_enabled = conf.get("freqai", {}).get("enabled", False)
|
|
|
|
timerange = conf.get("timerange")
|
|
|
|
freqai_backtest_live_models = conf.get("freqai_backtest_live_models", False)
|
2022-09-28 11:48:32 +00:00
|
|
|
if freqai_backtest_live_models and freqai_enabled and timerange:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Using timerange parameter is not supported with "
|
|
|
|
"--freqai-backtest-live-models parameter."
|
|
|
|
)
|
2022-09-26 02:14:00 +00:00
|
|
|
|
2022-09-28 11:48:32 +00:00
|
|
|
if freqai_backtest_live_models and not freqai_enabled:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Using --freqai-backtest-live-models parameter is only "
|
|
|
|
"supported with a FreqAI strategy."
|
|
|
|
)
|
2022-09-28 11:48:32 +00:00
|
|
|
|
|
|
|
if freqai_enabled and not freqai_backtest_live_models and not timerange:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
"Please pass --timerange if you intend to use FreqAI for backtesting."
|
|
|
|
)
|
2022-09-26 02:14:00 +00:00
|
|
|
|
|
|
|
|
2022-09-24 14:38:56 +00:00
|
|
|
def _validate_consumers(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
emc_conf = conf.get("external_message_consumer", {})
|
|
|
|
if emc_conf.get("enabled", False):
|
|
|
|
if len(emc_conf.get("producers", [])) < 1:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError("You must specify at least 1 Producer to connect to.")
|
2022-09-24 14:38:56 +00:00
|
|
|
|
2024-05-12 14:29:24 +00:00
|
|
|
producer_names = [p["name"] for p in emc_conf.get("producers", [])]
|
2022-09-24 14:38:56 +00:00
|
|
|
duplicates = [item for item, count in Counter(producer_names).items() if count > 1]
|
|
|
|
if duplicates:
|
2024-03-19 05:41:23 +00:00
|
|
|
raise ConfigurationError(
|
2024-05-12 14:29:24 +00:00
|
|
|
f"Producer names must be unique. Duplicate: {', '.join(duplicates)}"
|
|
|
|
)
|
|
|
|
if conf.get("process_only_new_candles", True):
|
2022-09-24 14:38:56 +00:00
|
|
|
# Warning here or require it?
|
2024-05-12 14:29:24 +00:00
|
|
|
logger.warning(
|
|
|
|
"To receive best performance with external data, "
|
|
|
|
"please set `process_only_new_candles` to False"
|
|
|
|
)
|
2022-09-24 14:38:56 +00:00
|
|
|
|
|
|
|
|
2022-04-05 18:00:35 +00:00
|
|
|
def _strategy_settings(conf: Dict[str, Any]) -> None:
|
2024-05-12 14:29:24 +00:00
|
|
|
process_deprecated_setting(conf, None, "use_sell_signal", None, "use_exit_signal")
|
|
|
|
process_deprecated_setting(conf, None, "sell_profit_only", None, "exit_profit_only")
|
|
|
|
process_deprecated_setting(conf, None, "sell_profit_offset", None, "exit_profit_offset")
|
|
|
|
process_deprecated_setting(
|
|
|
|
conf, None, "ignore_roi_if_buy_signal", None, "ignore_roi_if_entry_signal"
|
|
|
|
)
|