Merge branch 'develop' into fix_merge_informative_pair

This commit is contained in:
Matthias
2025-10-12 09:51:43 +02:00
113 changed files with 13747 additions and 6416 deletions

View File

@@ -1,6 +1,6 @@
"""Freqtrade bot"""
__version__ = "2025.9-dev"
__version__ = "2025.10-dev"
if "dev" in __version__:
from pathlib import Path

View File

@@ -49,6 +49,7 @@ ARGS_BACKTEST = [
*ARGS_COMMON_OPTIMIZE,
"position_stacking",
"enable_protections",
"enable_dynamic_pairlist",
"dry_run_wallet",
"timeframe_detail",
"strategy_list",
@@ -164,6 +165,7 @@ ARGS_DOWNLOAD_DATA = [
"days",
"new_pairs_days",
"include_inactive",
"no_parallel_download",
"timerange",
"download_trades",
"convert_trades",
@@ -259,7 +261,12 @@ ARGS_LOOKAHEAD_ANALYSIS = [
a
for a in ARGS_BACKTEST
if a not in ("position_stacking", "backtest_cache", "backtest_breakdown", "backtest_notes")
] + ["minimum_trade_amount", "targeted_trade_amount", "lookahead_analysis_exportfilename"]
] + [
"minimum_trade_amount",
"targeted_trade_amount",
"lookahead_analysis_exportfilename",
"lookahead_allow_limit_orders",
]
ARGS_RECURSIVE_ANALYSIS = ["timeframe", "timerange", "dataformat_ohlcv", "pairs", "startup_candle"]

View File

@@ -184,12 +184,20 @@ AVAILABLE_CLI_OPTIONS = {
"enable_protections": Arg(
"--enable-protections",
"--enableprotections",
help="Enable protections for backtesting."
help="Enable protections for backtesting. "
"Will slow backtesting down by a considerable amount, but will include "
"configured protections",
action="store_true",
default=False,
),
"enable_dynamic_pairlist": Arg(
"--enable-dynamic-pairlist",
help="Enables dynamic pairlist refreshes in backtesting. "
"The pairlist will be generated for each new candle if you're using a "
"pairlist handler that supports this feature, for example, ShuffleFilter.",
action="store_true",
default=False,
),
"strategy_list": Arg(
"--strategy-list",
help="Provide a space-separated list of strategies to backtest. "
@@ -454,6 +462,11 @@ AVAILABLE_CLI_OPTIONS = {
help="Also download data from inactive pairs.",
action="store_true",
),
"no_parallel_download": Arg(
"--no-parallel-download",
help="Disable parallel startup download. Only use this if you experience issues.",
action="store_true",
),
"new_pairs_days": Arg(
"--new-pairs-days",
help="Download data of new pairs for given number of days. Default: `%(default)s`.",
@@ -801,6 +814,14 @@ AVAILABLE_CLI_OPTIONS = {
help="Specify startup candles to be checked (`199`, `499`, `999`, `1999`).",
nargs="+",
),
"lookahead_allow_limit_orders": Arg(
"--allow-limit-orders",
help=(
"Allow limit orders in lookahead analysis (could cause false positives "
"in lookahead analysis results)."
),
action="store_true",
),
"show_sensitive": Arg(
"--show-sensitive",
help="Show secrets in the output.",

View File

@@ -66,7 +66,7 @@ def start_list_exchanges(args: dict[str, Any]) -> None:
if exchange["is_alias"]:
name.stylize("strike")
classname.stylize("strike")
classname.append(f" (use {exchange['alias_for']})", style="italic")
classname.append(f"\n -> use {exchange['alias_for']}", style="italic")
trade_modes = Text(
", ".join(

View File

@@ -1142,6 +1142,15 @@ CONF_SCHEMA = {
"type": "boolean",
"default": False,
},
"override_exchange_check": {
"description": (
"Override the exchange check to force FreqAI to use exchanges "
"that may not have enough historic data. Turn this to True if "
"you know your FreqAI model and strategy do not require historical data."
),
"type": "boolean",
"default": False,
},
"feature_parameters": {
"description": "The parameters used to engineer the feature set",
"type": "object",

View File

@@ -113,7 +113,6 @@ def _validate_price_config(conf: dict[str, Any]) -> None:
"""
When using market orders, price sides must be using the "other" side of the price
"""
# TODO: The below could be an enforced setting when using market orders
if conf.get("order_types", {}).get("entry") == "market" and conf.get("entry_pricing", {}).get(
"price_side"
) not in ("ask", "other"):

View File

@@ -12,13 +12,16 @@ from typing import Any
from freqtrade import constants
from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings
from freqtrade.configuration.directory_operations import create_datadir, create_userdata_dir
from freqtrade.configuration.environment_vars import enironment_vars_to_dict
from freqtrade.configuration.environment_vars import environment_vars_to_dict
from freqtrade.configuration.load_config import load_file, load_from_files
from freqtrade.constants import Config
from freqtrade.enums import (
NON_UTIL_MODES,
TRADE_MODES,
CandleType,
MarginMode,
RunMode,
TradingMode,
)
from freqtrade.exceptions import OperationalException
from freqtrade.loggers import setup_logging
@@ -77,7 +80,7 @@ class Configuration:
from freqtrade.commands.arguments import NO_CONF_ALLOWED
if self.args.get("command") not in NO_CONF_ALLOWED:
env_data = enironment_vars_to_dict()
env_data = environment_vars_to_dict()
config = deep_merge_dicts(env_data, config)
# Normalize config
@@ -230,6 +233,9 @@ class Configuration:
config["exportdirectory"] = config["user_data_dir"] / "backtest_results"
if not config.get("exportfilename"):
config["exportfilename"] = None
if config.get("exportfilename"):
# ensure exportfilename is a Path object
config["exportfilename"] = Path(config["exportfilename"])
config["exportdirectory"] = Path(config["exportdirectory"])
if self.args.get("show_sensitive"):
@@ -256,7 +262,13 @@ class Configuration:
self._args_to_config(
config,
argname="enable_protections",
logstring="Parameter --enable-protections detected, enabling Protections. ...",
logstring="Parameter --enable-protections detected, enabling Protections ...",
)
self._args_to_config(
config,
argname="enable_dynamic_pairlist",
logstring="Parameter --enable-dynamic-pairlist detected, enabling dynamic pairlist ...",
)
if self.args.get("max_open_trades"):
@@ -312,7 +324,6 @@ class Configuration:
"recursive_strategy_search",
"Recursively searching for a strategy in the strategies folder.",
),
("timeframe", "Overriding timeframe with Command line argument"),
("export", "Parameter --export detected: {} ..."),
("backtest_breakdown", "Parameter --breakdown detected ..."),
("backtest_cache", "Parameter --cache={} detected ..."),
@@ -391,6 +402,7 @@ class Configuration:
("timeframes", "timeframes --timeframes: {}"),
("days", "Detected --days: {}"),
("include_inactive", "Detected --include-inactive-pairs: {}"),
("no_parallel_download", "Detected --no-parallel-download: {}"),
("download_trades", "Detected --dl-trades: {}"),
("convert_trades", "Detected --convert: {} - Converting Trade data to OHCV {}"),
("dataformat_ohlcv", 'Using "{}" to store OHLCV data.'),
@@ -406,6 +418,14 @@ class Configuration:
self._args_to_config(
config, argname="trading_mode", logstring="Detected --trading-mode: {}"
)
# TODO: The following 3 lines (candle_type_def, trading_mode, margin_mode) are actually
# set in the exchange class. They're however necessary as fallback to avoid
# random errors in commands that don't initialize an exchange.
config["candle_type_def"] = CandleType.get_default(
config.get("trading_mode", "spot") or "spot"
)
config["trading_mode"] = TradingMode(config.get("trading_mode", "spot") or "spot")
config["margin_mode"] = MarginMode(config.get("margin_mode", "") or "")
self._args_to_config(
config, argname="candle_types", logstring="Detected --candle-types: {}"
)

View File

@@ -73,7 +73,7 @@ def _flat_vars_to_nested_dict(env_dict: dict[str, Any], prefix: str) -> dict[str
return relevant_vars
def enironment_vars_to_dict() -> dict[str, Any]:
def environment_vars_to_dict() -> dict[str, Any]:
"""
Read environment variables and return a nested dict for relevant variables
Relevant variables must follow the FREQTRADE__{section}__{key} pattern

View File

@@ -80,6 +80,9 @@ class TimeRange:
val = stopdt.strftime(DATETIME_PRINT_FORMAT)
return val
def __repr__(self) -> str:
return f"TimeRange({self.timerange_str})"
def __eq__(self, other):
"""Override the default Equals behavior"""
return (

View File

@@ -49,6 +49,7 @@ AVAILABLE_PAIRLISTS = [
"RemotePairList",
"MarketCapPairList",
"AgeFilter",
"DelistFilter",
"FullTradesFilter",
"OffsetFilter",
"PerformanceFilter",

View File

@@ -181,7 +181,6 @@ def trim_dataframes(
def order_book_to_dataframe(bids: list, asks: list) -> DataFrame:
"""
TODO: This should get a dedicated test
Gets order book list, returns dataframe with below format per suggested by creslin
-------------------------------------------------------------------
b_sum b_size bids asks a_size a_sum

View File

@@ -23,7 +23,7 @@ from freqtrade.data.history import get_datahandler, load_pair_history
from freqtrade.enums import CandleType, RPCMessageType, RunMode, TradingMode
from freqtrade.exceptions import ExchangeError, OperationalException
from freqtrade.exchange import Exchange, timeframe_to_prev_date, timeframe_to_seconds
from freqtrade.exchange.exchange_types import OrderBook
from freqtrade.exchange.exchange_types import FundingRate, OrderBook
from freqtrade.misc import append_candles_to_dataframe
from freqtrade.rpc import RPCManager
from freqtrade.rpc.rpc_types import RPCAnalyzedDFMsg
@@ -548,6 +548,7 @@ class DataProvider:
def ticker(self, pair: str):
"""
Return last ticker data from exchange
Warning: Performs a network request - so use with common sense.
:param pair: Pair to get the data for
:return: Ticker dict from exchange or empty dict if ticker is not available for the pair
"""
@@ -561,7 +562,7 @@ class DataProvider:
def orderbook(self, pair: str, maximum: int) -> OrderBook:
"""
Fetch latest l2 orderbook data
Warning: Does a network request - so use with common sense.
Warning: Performs a network request - so use with common sense.
:param pair: pair to get the data for
:param maximum: Maximum number of orderbook entries to query
:return: dict including bids/asks with a total of `maximum` entries.
@@ -570,6 +571,23 @@ class DataProvider:
raise OperationalException(NO_EXCHANGE_EXCEPTION)
return self._exchange.fetch_l2_order_book(pair, maximum)
def funding_rate(self, pair: str) -> FundingRate:
"""
Return Funding rate from the exchange
Warning: Performs a network request - so use with common sense.
:param pair: Pair to get the data for
:return: Funding rate dict from exchange or empty dict if funding rate is not available
If available, the "fundingRate" field will contain the funding rate.
"fundingTimestamp" and "fundingDatetime" will contain the next funding times.
Actually filled fields may vary between exchanges.
"""
if self._exchange is None:
raise OperationalException(NO_EXCHANGE_EXCEPTION)
try:
return self._exchange.fetch_funding_rate(pair)
except ExchangeError:
return {}
def send_msg(self, message: str, *, always_send: bool = False) -> None:
"""
Send custom RPC Notifications from your bot.
@@ -586,3 +604,19 @@ class DataProvider:
if always_send or message not in self.__msg_cache:
self._msg_queue.append(message)
self.__msg_cache[message] = True
def check_delisting(self, pair: str) -> datetime | None:
"""
Check if a pair gonna be delisted on the exchange.
Will only return datetime if the pair is gonna be delisted.
:param pair: Pair to check
:return: Datetime of the pair's delisting, None otherwise
"""
if self._exchange is None:
raise OperationalException(NO_EXCHANGE_EXCEPTION)
try:
return self._exchange.check_delisting_time(pair)
except ExchangeError:
logger.warning(f"Could not fetch market data for {pair}. Assuming no delisting.")
return None

View File

@@ -6,7 +6,14 @@ from pathlib import Path
from pandas import DataFrame, concat
from freqtrade.configuration import TimeRange
from freqtrade.constants import DATETIME_PRINT_FORMAT, DL_DATA_TIMEFRAMES, DOCS_LINK, Config
from freqtrade.constants import (
DATETIME_PRINT_FORMAT,
DL_DATA_TIMEFRAMES,
DOCS_LINK,
Config,
ListPairsWithTimeframes,
PairWithTimeframe,
)
from freqtrade.data.converter import (
clean_ohlcv_dataframe,
convert_trades_to_ohlcv,
@@ -17,6 +24,7 @@ from freqtrade.data.history.datahandlers import IDataHandler, get_datahandler
from freqtrade.enums import CandleType, TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.exchange import Exchange
from freqtrade.exchange.exchange_utils import date_minus_candles
from freqtrade.plugins.pairlist.pairlist_helpers import dynamic_expand_pairlist
from freqtrade.util import dt_now, dt_ts, format_ms_time, format_ms_time_det
from freqtrade.util.migrations import migrate_data
@@ -226,6 +234,7 @@ def _download_pair_history(
candle_type: CandleType,
erase: bool = False,
prepend: bool = False,
pair_candles: DataFrame | None = None,
) -> bool:
"""
Download latest candles from the exchange for the pair and timeframe passed in parameters
@@ -238,6 +247,7 @@ def _download_pair_history(
:param timerange: range of time to download
:param candle_type: Any of the enum CandleType (must match trading mode!)
:param erase: Erase existing data
:param pair_candles: Optional with "1 call" pair candles.
:return: bool with success state
"""
data_handler = get_datahandler(datadir, data_handler=data_handler)
@@ -271,21 +281,40 @@ def _download_pair_history(
"Current End: %s",
f"{data.iloc[-1]['date']:{DATETIME_PRINT_FORMAT}}" if not data.empty else "None",
)
# Default since_ms to 30 days if nothing is given
new_dataframe = exchange.get_historic_ohlcv(
pair=pair,
timeframe=timeframe,
since_ms=(
since_ms
if since_ms
else int((datetime.now() - timedelta(days=new_pairs_days)).timestamp()) * 1000
),
is_new_pair=data.empty,
candle_type=candle_type,
until_ms=until_ms if until_ms else None,
# used to check if the passed in pair_candles (parallel downloaded) covers since_ms.
# If we need more data, we have to fall back to the standard method.
pair_candles_since_ms = (
dt_ts(pair_candles.iloc[0]["date"])
if pair_candles is not None and len(pair_candles.index) > 0
else 0
)
logger.info(f"Downloaded data for {pair} with length {len(new_dataframe)}.")
if (
pair_candles is None
or len(pair_candles.index) == 0
or data.empty
or prepend is True
or erase is True
or pair_candles_since_ms > (since_ms if since_ms else 0)
):
new_dataframe = exchange.get_historic_ohlcv(
pair=pair,
timeframe=timeframe,
since_ms=(
since_ms
if since_ms
else int((datetime.now() - timedelta(days=new_pairs_days)).timestamp()) * 1000
),
is_new_pair=data.empty,
candle_type=candle_type,
until_ms=until_ms if until_ms else None,
)
logger.info(f"Downloaded data for {pair} with length {len(new_dataframe)}.")
else:
new_dataframe = pair_candles
logger.info(
f"Downloaded data for {pair} with length {len(new_dataframe)}. Parallel Method."
)
if data.empty:
data = new_dataframe
else:
@@ -330,6 +359,7 @@ def refresh_backtest_ohlcv_data(
data_format: str | None = None,
prepend: bool = False,
progress_tracker: CustomProgress | None = None,
no_parallel_download: bool = False,
) -> list[str]:
"""
Refresh stored ohlcv data for backtesting and hyperopt operations.
@@ -339,6 +369,7 @@ def refresh_backtest_ohlcv_data(
progress_tracker = retrieve_progress_tracker(progress_tracker)
pairs_not_available = []
fast_candles: dict[PairWithTimeframe, DataFrame] = {}
data_handler = get_datahandler(datadir, data_format)
candle_type = CandleType.get_default(trading_mode)
with progress_tracker as progress:
@@ -355,6 +386,30 @@ def refresh_backtest_ohlcv_data(
logger.info(f"Skipping pair {pair}...")
continue
for timeframe in timeframes:
# Get fast candles via parallel method on first loop through per timeframe
# and candle type. Downloads all the pairs in the list and stores them.
if (
not no_parallel_download
and exchange.get_option("download_data_parallel_quick", True)
and (
((pair, timeframe, candle_type) not in fast_candles)
and (erase is False)
and (prepend is False)
)
):
fast_candles.update(
_download_all_pairs_history_parallel(
exchange=exchange,
pairs=pairs,
timeframe=timeframe,
candle_type=candle_type,
timerange=timerange,
)
)
# get the already downloaded pair candles if they exist
pair_candles = fast_candles.pop((pair, timeframe, candle_type), None)
progress.update(timeframe_task, description=f"Timeframe {timeframe}")
logger.debug(f"Downloading pair {pair}, {candle_type}, interval {timeframe}.")
_download_pair_history(
@@ -368,6 +423,7 @@ def refresh_backtest_ohlcv_data(
candle_type=candle_type,
erase=erase,
prepend=prepend,
pair_candles=pair_candles, # optional pass of dataframe of parallel candles
)
progress.update(timeframe_task, advance=1)
if trading_mode == "futures":
@@ -404,6 +460,41 @@ def refresh_backtest_ohlcv_data(
return pairs_not_available
def _download_all_pairs_history_parallel(
exchange: Exchange,
pairs: list[str],
timeframe: str,
candle_type: CandleType,
timerange: TimeRange | None = None,
) -> dict[PairWithTimeframe, DataFrame]:
"""
Allows to use the faster parallel async download method for many coins
but only if the data is short enough to be retrieved in one call.
Used by freqtrade download-data subcommand.
:return: Candle pairs with timeframes
"""
candles: dict[PairWithTimeframe, DataFrame] = {}
since = 0
if timerange:
if timerange.starttype == "date":
since = timerange.startts * 1000
candle_limit = exchange.ohlcv_candle_limit(timeframe, candle_type)
one_call_min_time_dt = dt_ts(date_minus_candles(timeframe, candle_limit))
# check if we can get all candles in one go, if so then we can download them in parallel
if since > one_call_min_time_dt:
logger.info(
f"Downloading parallel candles for {timeframe} for all pairs "
f"since {format_ms_time(since)}"
)
needed_pairs: ListPairsWithTimeframes = [
(p, timeframe, candle_type) for p in [p for p in pairs]
]
candles = exchange.refresh_latest_ohlcv(needed_pairs, since_ms=since, cache=False)
return candles
def _download_trades_history(
exchange: Exchange,
pair: str,
@@ -702,6 +793,7 @@ def download_data(
trading_mode=config.get("trading_mode", "spot"),
prepend=config.get("prepend_data", False),
progress_tracker=progress_tracker,
no_parallel_download=config.get("no_parallel_download", False),
)
finally:
if pairs_not_available:

View File

@@ -11,6 +11,7 @@ from freqtrade.exchange.bitmart import Bitmart
from freqtrade.exchange.bitpanda import Bitpanda
from freqtrade.exchange.bitvavo import Bitvavo
from freqtrade.exchange.bybit import Bybit
from freqtrade.exchange.coinex import Coinex
from freqtrade.exchange.cryptocom import Cryptocom
from freqtrade.exchange.exchange_utils import (
ROUND_DOWN,

View File

@@ -5,10 +5,11 @@ from datetime import UTC, datetime
from pathlib import Path
import ccxt
from cachetools import TTLCache
from pandas import DataFrame
from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS
from freqtrade.enums import CandleType, MarginMode, PriceType, TradingMode
from freqtrade.enums import TRADE_MODES, CandleType, MarginMode, PriceType, RunMode, TradingMode
from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError
from freqtrade.exchange import Exchange
from freqtrade.exchange.binance_public_data import (
@@ -40,6 +41,7 @@ class Binance(Exchange):
"fetch_orders_limit_minutes": None,
"l2_limit_range": [5, 10, 20, 50, 100, 500, 1000],
"ws_enabled": True,
"has_delisting": True,
}
_ft_has_futures: FtHas = {
"funding_fee_candle_limit": 1000,
@@ -68,6 +70,10 @@ class Binance(Exchange):
(TradingMode.FUTURES, MarginMode.ISOLATED),
]
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._spot_delist_schedule_cache: TTLCache = TTLCache(maxsize=100, ttl=300)
def get_proxy_coin(self) -> str:
"""
Get the proxy coin for the given coin
@@ -391,7 +397,7 @@ class Binance(Exchange):
async def _async_get_trade_history_id(
self, pair: str, until: int, since: int, from_id: str | None = None
) -> tuple[str, list[list]]:
logger.info(f"Fetching trades from Binance, {from_id=}, {since=}, {until=}")
logger.info(f"Fetching trades for {pair} from Binance, {from_id=}, {since=}, {until=}")
if not self._config["exchange"].get("only_from_ccxt", False):
if from_id is None or not since:
@@ -432,3 +438,105 @@ class Binance(Exchange):
return await super()._async_get_trade_history_id(
pair, until=until, since=since, from_id=from_id
)
def _check_delisting_futures(self, pair: str) -> datetime | None:
delivery_time = self.markets.get(pair, {}).get("info", {}).get("deliveryDate", None)
if delivery_time:
if isinstance(delivery_time, str) and (delivery_time != ""):
delivery_time = int(delivery_time)
# Binance set a very high delivery time for all perpetuals.
# We compare with delivery time of BTC/USDT:USDT which assumed to never be delisted
btc_delivery_time = (
self.markets.get("BTC/USDT:USDT", {}).get("info", {}).get("deliveryDate", None)
)
if delivery_time == btc_delivery_time:
return None
delivery_time = dt_from_ts(delivery_time)
return delivery_time
def check_delisting_time(self, pair: str) -> datetime | None:
"""
Check if the pair gonna be delisted.
By default, it returns None.
:param pair: Market symbol
:return: Datetime if the pair gonna be delisted, None otherwise
"""
if self._config["runmode"] not in TRADE_MODES:
return None
if self.trading_mode == TradingMode.FUTURES:
return self._check_delisting_futures(pair)
return self._get_spot_pair_delist_time(pair, refresh=False)
def _get_spot_delist_schedule(self):
"""
Get the delisting schedule for spot pairs
Only works in live mode as it requires API keys,
Return sample:
[{
"delistTime": "1759114800000",
"symbols": [
"OMNIBTC",
"OMNIFDUSD",
"OMNITRY",
"OMNIUSDC",
"OMNIUSDT"
]
}]
"""
try:
delist_schedule = self._api.sapi_get_spot_delist_schedule()
return delist_schedule
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.NetworkError, ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get delist schedule {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
def _get_spot_pair_delist_time(self, pair: str, refresh: bool = False) -> datetime | None:
"""
Get the delisting time for a pair if it will be delisted
:param pair: Pair to get the delisting time for
:param refresh: true if you need fresh data
:return: int: delisting time None if not delisting
"""
if not pair or not self._config["runmode"] == RunMode.LIVE:
# Endpoint only works in live mode as it requires API keys
return None
cache = self._spot_delist_schedule_cache
if not refresh:
if delist_time := cache.get(pair, None):
return delist_time
delist_schedule = self._get_spot_delist_schedule()
if delist_schedule is None:
return None
for schedule in delist_schedule:
delist_dt = dt_from_ts(int(schedule["delistTime"]))
for symbol in schedule["symbols"]:
ft_symbol = next(
(
pair
for pair, market in self.markets.items()
if market.get("id", None) == symbol
),
None,
)
if ft_symbol is None:
continue
cache[ft_symbol] = delist_dt
return cache.get(pair, None)

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,6 @@
import logging
from ccxt import DECIMAL_PLACES
from freqtrade.exchange import Exchange
from freqtrade.exchange.exchange_types import FtHas
@@ -24,11 +22,3 @@ class Bitvavo(Exchange):
_ft_has: FtHas = {
"ohlcv_candle_limit": 1440,
}
@property
def precisionMode(self) -> int:
"""
Exchange ccxt precisionMode
Override due to https://github.com/ccxt/ccxt/issues/20408
"""
return DECIMAL_PLACES

View File

@@ -0,0 +1,24 @@
import logging
from freqtrade.exchange import Exchange
from freqtrade.exchange.exchange_types import FtHas
logger = logging.getLogger(__name__)
class Coinex(Exchange):
"""
CoinEx exchange class. Contains adjustments needed for Freqtrade to work
with this exchange.
Please note that this exchange is not included in the list of exchanges
officially supported by the Freqtrade development team. So some features
may still not work as expected.
"""
_ft_has: FtHas = {
"l2_limit_range": [5, 10, 20, 50],
"tickers_have_bid_ask": False,
"tickers_have_quoteVolume": False,
}

View File

@@ -73,6 +73,7 @@ from freqtrade.exchange.exchange_types import (
CcxtOrder,
CcxtPosition,
FtHas,
FundingRate,
OHLCVResponse,
OrderBook,
Ticker,
@@ -137,6 +138,7 @@ class Exchange:
"ohlcv_has_history": True, # Some exchanges (Kraken) don't provide history via ohlcv
"ohlcv_partial_candle": True,
"ohlcv_require_since": False,
"download_data_parallel_quick": True,
"always_require_api_keys": False, # purge API keys for Dry-run. Must default to false.
# Check https://github.com/ccxt/ccxt/issues/10767 for removal of ohlcv_volume_currency
"ohlcv_volume_currency": "base", # "base" or "quote"
@@ -164,6 +166,7 @@ class Exchange:
"proxy_coin_mapping": {}, # Mapping for proxy coins
# Expected to be in the format {"fetchOHLCV": True} or {"fetchOHLCV": False}
"ws_enabled": False, # Set to true for exchanges with tested websocket support
"has_delisting": False, # Set to true for exchanges that have delisting pair checks
}
_ft_has: FtHas = {}
_ft_has_futures: FtHas = {}
@@ -690,12 +693,13 @@ class Exchange:
# Reload async markets, then assign them to sync api
retrier(self._load_async_markets, retries=retries)(reload=True)
self._markets = self._api_async.markets
self._api.set_markets(self._api_async.markets, self._api_async.currencies)
self._api.set_markets_from_exchange(self._api_async)
# Assign options array, as it contains some temporary information from the exchange.
# TODO: investigate with ccxt if it's safe to remove `.options`
self._api.options = self._api_async.options
if self._exchange_ws:
# Set markets to avoid reloading on websocket api
self._ws_async.set_markets(self._api.markets, self._api.currencies)
self._ws_async.set_markets_from_exchange(self._api_async)
self._ws_async.options = self._api.options
self._last_markets_refresh = dt_ts()
@@ -828,10 +832,16 @@ class Exchange:
def validate_freqai(self, config: Config) -> None:
freqai_enabled = config.get("freqai", {}).get("enabled", False)
if freqai_enabled and not self._ft_has["ohlcv_has_history"]:
override = config.get("freqai", {}).get("override_exchange_checks", False)
if not override and freqai_enabled and not self._ft_has["ohlcv_has_history"]:
raise ConfigurationError(
f"Historic OHLCV data not available for {self.name}. Can't use freqAI."
)
elif override and freqai_enabled and not self._ft_has["ohlcv_has_history"]:
logger.warning(
"Overriding exchange checks for freqAI. Make sure that your exchange supports "
"fetching historic OHLCV data, otherwise freqAI will not work."
)
def validate_required_startup_candles(self, startup_candles: int, timeframe: str) -> int:
"""
@@ -890,6 +900,19 @@ class Exchange:
f"Freqtrade does not support '{mm_value}' '{trading_mode}' on {self.name}."
)
@classmethod
def combine_ft_has(cls, include_futures: bool) -> FtHas:
"""
Combine all ft_has options from the class hierarchy.
Child classes override parent classes.
Doesn't apply overrides from the configuration.
"""
_ft_has = deep_merge_dicts(cls._ft_has, deepcopy(cls._ft_has_default))
if include_futures:
_ft_has = deep_merge_dicts(cls._ft_has_futures, _ft_has)
return _ft_has
def build_ft_has(self, exchange_conf: ExchangeConfig) -> None:
"""
Deep merge ft_has with default ft_has options
@@ -897,9 +920,8 @@ class Exchange:
This is called on initialization of the exchange object.
It must be called before ft_has is used.
"""
self._ft_has = deep_merge_dicts(self._ft_has, deepcopy(self._ft_has_default))
if self.trading_mode == TradingMode.FUTURES:
self._ft_has = deep_merge_dicts(self._ft_has_futures, self._ft_has)
self._ft_has = self.combine_ft_has(include_futures=self.trading_mode == TradingMode.FUTURES)
if exchange_conf.get("_ft_has_params"):
self._ft_has = deep_merge_dicts(exchange_conf.get("_ft_has_params"), self._ft_has)
logger.info("Overriding exchange._ft_has with config params, result: %s", self._ft_has)
@@ -2001,6 +2023,30 @@ class Exchange:
except ccxt.BaseError as e:
raise OperationalException(e) from e
@retrier
def fetch_funding_rate(self, pair: str) -> FundingRate:
"""
Get current Funding rate from exchange.
On Futures markets, this is the interest rate for holding a position.
Won't work for non-futures markets
"""
try:
if pair not in self.markets or self.markets[pair].get("active", False) is False:
raise ExchangeError(f"Pair {pair} not available")
return self._api.fetch_funding_rate(pair)
except ccxt.NotSupported as e:
raise OperationalException(
f"Exchange {self._api.name} does not support fetching funding rate. Message: {e}"
) from e
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
raise TemporaryError(
f"Could not get funding rate due to {e.__class__.__name__}. Message: {e}"
) from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
@staticmethod
def get_next_limit_in_list(
limit: int,
@@ -2456,7 +2502,14 @@ class Exchange:
data.extend(new_data)
# Sort data again after extending the result - above calls return in "async order"
data = sorted(data, key=lambda x: x[0])
return pair, timeframe, candle_type, data, self._ohlcv_partial_candle
return (
pair,
timeframe,
candle_type,
data,
# funding_rates are always complete, so never need to be dropped.
self._ohlcv_partial_candle if candle_type != CandleType.FUNDING_RATE else False,
)
def _try_build_from_websocket(
self, pair: str, timeframe: str, candle_type: CandleType
@@ -2566,14 +2619,24 @@ class Exchange:
input_coroutines: list[Coroutine[Any, Any, OHLCVResponse]] = []
cached_pairs = []
for pair, timeframe, candle_type in set(pair_list):
if timeframe not in self.timeframes and candle_type in (
invalid_funding = (
candle_type == CandleType.FUNDING_RATE
and timeframe != self.get_option("funding_fee_timeframe")
)
invalid_timeframe = timeframe not in self.timeframes and candle_type in (
CandleType.SPOT,
CandleType.FUTURES,
):
)
if invalid_timeframe or invalid_funding:
timeframes_ = (
", ".join(self.timeframes)
if candle_type != CandleType.FUNDING_RATE
else self.get_option("funding_fee_timeframe")
)
logger.warning(
f"Cannot download ({pair}, {timeframe}) combination as this timeframe is "
f"not available on {self.name}. Available timeframes are "
f"{', '.join(self.timeframes)}."
f"Cannot download ({pair}, {timeframe}, {candle_type}) combination as this "
f"timeframe is not available on {self.name}. Available timeframes are "
f"{timeframes_}."
)
continue
@@ -2756,7 +2819,7 @@ class Exchange:
timeframe, candle_type=candle_type, since_ms=since_ms
)
if candle_type and candle_type != CandleType.SPOT:
if candle_type and candle_type not in (CandleType.SPOT, CandleType.FUTURES):
params.update({"price": candle_type.value})
if candle_type != CandleType.FUNDING_RATE:
data = await self._api_async.fetch_ohlcv(
@@ -2771,8 +2834,6 @@ class Exchange:
since_ms=since_ms,
)
# Some exchanges sort OHLCV in ASC order and others in DESC.
# Ex: Bittrex returns the list of OHLCV in ASC order (oldest first, newest last)
# while GDAX returns the list of OHLCV in DESC order (newest first, oldest last)
# Only sort if necessary to save computing time
try:
if data and data[0][0] > data[-1][0]:
@@ -2781,7 +2842,14 @@ class Exchange:
logger.exception("Error loading %s. Result was %s.", pair, data)
return pair, timeframe, candle_type, [], self._ohlcv_partial_candle
logger.debug("Done fetching pair %s, %s interval %s...", pair, candle_type, timeframe)
return pair, timeframe, candle_type, data, self._ohlcv_partial_candle
return (
pair,
timeframe,
candle_type,
data,
# funding_rates are always complete, so never need to be dropped.
self._ohlcv_partial_candle if candle_type != CandleType.FUNDING_RATE else False,
)
except ccxt.NotSupported as e:
raise OperationalException(
@@ -3229,7 +3297,7 @@ class Exchange:
for sig in [signal.SIGINT, signal.SIGTERM]:
try:
self.loop.add_signal_handler(sig, task.cancel)
except NotImplementedError:
except (NotImplementedError, RuntimeError):
# Not all platforms implement signals (e.g. windows)
pass
return self.loop.run_until_complete(task)
@@ -3811,7 +3879,10 @@ class Exchange:
"""
market = self.markets[pair]
taker_fee_rate = market["taker"]
# default to some default fee if not available from exchange
taker_fee_rate = market["taker"] or self._api.describe().get("fees", {}).get(
"trading", {}
).get("taker", 0.001)
mm_ratio, _ = self.get_maintenance_ratio_and_amt(pair, stake_amount)
if self.trading_mode == TradingMode.FUTURES and self.margin_mode == MarginMode.ISOLATED:
@@ -3863,3 +3934,14 @@ 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}")
def check_delisting_time(self, pair: str) -> datetime | None:
"""
Check if the pair gonna be delisted.
This function should be overridden by the exchange class if the exchange
provides such information.
By default, it returns None.
:param pair: Market symbol
:return: Datetime if the pair gonna be delisted, None otherwise
"""
return None

View File

@@ -1,5 +1,8 @@
from typing import Any, Literal, TypedDict
# Re-export for easier use
from ccxt.base.types import FundingRate # noqa: F401
from freqtrade.enums import CandleType
@@ -25,6 +28,8 @@ class FtHas(TypedDict, total=False):
ohlcv_volume_currency: str
ohlcv_candle_limit_per_timeframe: dict[str, int]
always_require_api_keys: bool
# allow disabling of parallel download-data for specific exchanges
download_data_parallel_quick: bool
# Tickers
tickers_have_quoteVolume: bool
tickers_have_percentage: bool
@@ -58,6 +63,9 @@ class FtHas(TypedDict, total=False):
# Websocket control
ws_enabled: bool
# Delisting check
has_delisting: bool
class Ticker(TypedDict):
symbol: str

View File

@@ -28,6 +28,7 @@ class Hyperliquid(Exchange):
"stoploss_on_exchange": False,
"exchange_has_overrides": {"fetchTrades": False},
"marketOrderRequiresPrice": True,
"download_data_parallel_quick": False,
"ws_enabled": True,
}
_ft_has_futures: FtHas = {
@@ -43,6 +44,7 @@ class Hyperliquid(Exchange):
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
(TradingMode.SPOT, MarginMode.NONE),
(TradingMode.FUTURES, MarginMode.ISOLATED),
(TradingMode.FUTURES, MarginMode.CROSS),
]
@property
@@ -98,7 +100,6 @@ class Hyperliquid(Exchange):
'SOL/USDC:USDC': 43}}
"""
# Defining/renaming variables to match the documentation
isolated_margin = wallet_balance
position_size = amount
price = open_rate
position_value = price * position_size
@@ -116,8 +117,14 @@ class Hyperliquid(Exchange):
# 3. Divide this by 2
maintenance_margin_required = position_value / max_leverage / 2
# Docs: margin_available (isolated) = isolated_margin - maintenance_margin_required
margin_available = isolated_margin - maintenance_margin_required
if self.margin_mode == MarginMode.ISOLATED:
# Docs: margin_available (isolated) = isolated_margin - maintenance_margin_required
margin_available = stake_amount - maintenance_margin_required
elif self.margin_mode == MarginMode.CROSS:
# Docs: margin_available (cross) = account_value - maintenance_margin_required
margin_available = wallet_balance - maintenance_margin_required
else:
raise OperationalException("Unsupported margin mode for liquidation price calculation")
# Docs: The maintenance margin is half of the initial margin at max leverage
# The docs don't explicitly specify maintenance leverage, but this works.

View File

@@ -65,15 +65,22 @@ class Okx(Exchange):
"""
Exchange ohlcv candle limit
OKX has the following behaviour:
* 300 candles for up-to-date data
* 100 candles for historic data
* 100 candles for additional candles (not futures or spot).
* spot and futures:
* 300 candles for regular candles
* mark and premium-index:
* 300 candles for up-to-date data
* 100 candles for historic data
* additional data:
* 100 candles for additional candles
:param timeframe: Timeframe to check
:param candle_type: Candle-type
:param since_ms: Starting timestamp
:return: Candle limit as integer
"""
if candle_type in (CandleType.FUTURES, CandleType.SPOT) and (
if candle_type in (CandleType.FUTURES, CandleType.SPOT):
return 300
if candle_type in (CandleType.MARK, CandleType.PREMIUMINDEX) and (
not since_ms or since_ms > (date_minus_candles(timeframe, 300).timestamp() * 1000)
):
return 300

View File

@@ -1617,7 +1617,9 @@ class FreqtradeBot(LoggingMixin):
f"Emergency exiting trade {trade}, as the exit order "
f"timed out {max_timeouts} times. force selling {order['amount']}."
)
self.emergency_exit(trade, order["price"], order["amount"])
# Trade.session.refresh(order_obj)
self.emergency_exit(trade, order["price"], order_obj.safe_remaining)
return canceled
def emergency_exit(

View File

@@ -5,14 +5,26 @@ from pydantic import TypeAdapter
from typing_extensions import TypedDict
class AnnotationType(TypedDict, total=False):
type: Required[Literal["area"]]
class _BaseAnnotationType(TypedDict, total=False):
start: str | datetime
end: str | datetime
y_start: float
y_end: float
color: str
label: str
z_level: int
AnnotationTypeTA = TypeAdapter(AnnotationType)
class AreaAnnotationType(_BaseAnnotationType, total=False):
type: Required[Literal["area"]]
class LineAnnotationType(_BaseAnnotationType, total=False):
type: Required[Literal["line"]]
width: int
line_style: Literal["solid", "dashed", "dotted"]
AnnotationType = AreaAnnotationType | LineAnnotationType
AnnotationTypeTA: TypeAdapter[AnnotationType] = TypeAdapter(AnnotationType)

View File

@@ -145,9 +145,19 @@ class LookaheadAnalysisSubFunctions:
config["enable_protections"] = False
logger.info(
"Protections were enabled. "
"Disabling protections now "
"since they could otherwise produce false positives."
"Disabling protections now since they can produce false positives."
)
if not config.get("lookahead_allow_limit_orders", False):
logger.info("Forced order_types to market orders.")
config["order_types"] = {
"entry": "market",
"exit": "market",
"stoploss": "market",
"stoploss_on_exchange": False,
}
else:
logger.info("Using configured order_types, skipping order_types override.")
if config["targeted_trade_amount"] < config["minimum_trade_amount"]:
# this combo doesn't make any sense.
raise OperationalException(

View File

@@ -37,10 +37,12 @@ class RecursiveAnalysis(BaseAnalysis):
self.dict_recursive: dict[str, Any] = dict()
self.pair_to_used: str | None = None
# For recursive bias check
# analyzes two data frames with processed indicators and shows differences between them.
def analyze_indicators(self):
pair_to_check = self.local_config["pairs"][0]
pair_to_check = self.pair_to_used
logger.info("Start checking for recursive bias")
# check and report signals
@@ -85,7 +87,7 @@ class RecursiveAnalysis(BaseAnalysis):
# For lookahead bias check
# analyzes two data frames with processed indicators and shows differences between them.
def analyze_indicators_lookahead(self):
pair_to_check = self.local_config["pairs"][0]
pair_to_check = self.pair_to_used
logger.info("Start checking for lookahead bias on indicators only")
part = self.partial_varHolder_lookahead_array[0]
@@ -138,7 +140,13 @@ class RecursiveAnalysis(BaseAnalysis):
backtesting = Backtesting(prepare_data_config, self.exchange)
self.exchange = backtesting.exchange
if self.pair_to_used is None:
self.pair_to_used = backtesting.pairlists.whitelist[0]
logger.info(
f"Using pair {self.pair_to_used} only for recursive analysis. Replacing whitelist."
)
self.local_config["candle_type_def"] = prepare_data_config["candle_type_def"]
backtesting.pairlists._whitelist = [self.pair_to_used]
backtesting._set_strategy(backtesting.strategylist[0])
strat = backtesting.strategy

View File

@@ -211,6 +211,7 @@ class Backtesting:
self._can_short = self.trading_mode != TradingMode.SPOT
self._position_stacking: bool = self.config.get("position_stacking", False)
self.enable_protections: bool = self.config.get("enable_protections", False)
self.dynamic_pairlist: bool = self.config.get("enable_dynamic_pairlist", False)
migrate_data(config, self.exchange)
self.init_backtest()
@@ -966,7 +967,7 @@ class Backtesting:
)
)
def get_valid_price_and_stake(
def get_valid_entry_price_and_stake(
self,
pair: str,
row: tuple,
@@ -1089,18 +1090,20 @@ class Backtesting:
stake_amount_ = stake_amount or (trade.stake_amount if trade else 0.0)
precision_price, precision_mode_price = self.get_pair_precision(pair, current_time)
propose_rate, stake_amount, leverage, min_stake_amount = self.get_valid_price_and_stake(
pair,
row,
row[OPEN_IDX],
stake_amount_,
direction,
current_time,
entry_tag,
trade,
order_type,
precision_price,
precision_mode_price,
propose_rate, stake_amount, leverage, min_stake_amount = (
self.get_valid_entry_price_and_stake(
pair,
row,
row[OPEN_IDX],
stake_amount_,
direction,
current_time,
entry_tag,
trade,
order_type,
precision_price,
precision_mode_price,
)
)
# replace proposed rate if another rate was requested
@@ -1582,6 +1585,11 @@ class Backtesting:
for current_time in self._time_generator(start_date, end_date):
# Loop for each main candle.
self.check_abort()
if self.dynamic_pairlist and self.pairlists:
self.pairlists.refresh_pairlist()
pairs = self.pairlists.whitelist
# Reset open trade count for this candle
# Critical to avoid exceeding max_open_trades in backtesting
# when timeframe-detail is used and trades close within the opening candle.

View File

@@ -0,0 +1,95 @@
"""
Delist pair list filter
"""
import logging
from datetime import UTC, datetime, timedelta
from freqtrade.exceptions import ConfigurationError
from freqtrade.exchange.exchange_types import Ticker
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
from freqtrade.util import format_date
logger = logging.getLogger(__name__)
class DelistFilter(IPairList):
supports_backtesting = SupportsBacktesting.NO
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._max_days_from_now = self._pairlistconfig.get("max_days_from_now", 0)
if self._max_days_from_now < 0:
raise ConfigurationError("DelistFilter requires max_days_from_now to be >= 0")
if not self._exchange._ft_has["has_delisting"]:
raise ConfigurationError(
"DelistFilter doesn't support this exchange and trading mode combination.",
)
@property
def needstickers(self) -> bool:
"""
Boolean property defining if tickers are necessary.
If no Pairlist requires tickers, an empty Dict is passed
as tickers argument to filter_pairlist
"""
return False
def short_desc(self) -> str:
"""
Short whitelist method description - used for startup-messages
"""
return (
f"{self.name} - Filtering pairs that will be delisted"
+ (
f" in the next {self._max_days_from_now} days"
if self._max_days_from_now > 0
else ""
)
+ "."
)
@staticmethod
def description() -> str:
return "Filter pairs that will be delisted on exchange."
@staticmethod
def available_parameters() -> dict[str, PairlistParameter]:
return {
"max_days_from_now": {
"type": "number",
"default": 0,
"description": "Max days from now",
"help": (
"Remove pairs that will be delisted in the next X days. Set to 0 to remove all."
),
},
}
def _validate_pair(self, pair: str, ticker: Ticker | None) -> bool:
"""
Check if pair will be delisted.
:param pair: Pair that's currently validated
:param ticker: ticker dict as returned from ccxt.fetch_ticker
:return: True if the pair can stay, false if it should be removed
"""
delist_date = self._exchange.check_delisting_time(pair)
if delist_date is not None:
remove_pair = self._max_days_from_now == 0
if self._max_days_from_now > 0:
current_datetime = datetime.now(UTC)
max_delist_date = current_datetime + timedelta(days=self._max_days_from_now)
remove_pair = delist_date <= max_delist_date
if remove_pair:
self.log_once(
f"Removed {pair} from whitelist, because it will be delisted on "
f"{format_date(delist_date)}.",
logger.info,
)
return False
return True

View File

@@ -93,6 +93,8 @@ class ShuffleFilter(IPairList):
return pairlist_new
# Shuffle is done inplace
self._random.shuffle(pairlist)
self.__pairlist_cache[pairlist_bef] = pairlist
if self._config.get("runmode") in (RunMode.LIVE, RunMode.DRY_RUN):
self.__pairlist_cache[pairlist_bef] = pairlist
return pairlist

View File

@@ -7,6 +7,9 @@ Provides pair white list as it configured in config
import logging
from copy import deepcopy
from cachetools import LRUCache
from freqtrade.enums import RunMode
from freqtrade.exchange.exchange_types import Tickers
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
@@ -22,6 +25,8 @@ class StaticPairList(IPairList):
super().__init__(*args, **kwargs)
self._allow_inactive = self._pairlistconfig.get("allow_inactive", False)
# Pair cache - only used for optimize modes
self._bt_pair_cache: LRUCache = LRUCache(maxsize=1)
@property
def needstickers(self) -> bool:
@@ -60,15 +65,23 @@ class StaticPairList(IPairList):
:param tickers: Tickers (from exchange.get_tickers). May be cached.
:return: List of pairs
"""
wl = self.verify_whitelist(
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
)
if self._allow_inactive:
return wl
else:
# Avoid implicit filtering of "verify_whitelist" to keep
# proper warnings in the log
return self._whitelist_for_active_markets(wl)
pairlist = self._bt_pair_cache.get("pairlist")
if not pairlist:
wl = self.verify_whitelist(
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
)
if self._allow_inactive:
pairlist = wl
else:
# Avoid implicit filtering of "verify_whitelist" to keep
# proper warnings in the log
pairlist = self._whitelist_for_active_markets(wl)
if self._config["runmode"] in (RunMode.BACKTEST, RunMode.HYPEROPT):
self._bt_pair_cache["pairlist"] = pairlist.copy()
return pairlist
def filter_pairlist(self, pairlist: list[str], tickers: Tickers) -> list[str]:
"""

View File

@@ -247,7 +247,6 @@ class VolumePairList(IPairList):
* 1000
)
# todo: utc date output for starting date
self.log_once(
f"Using volume range of {self._lookback_period} candles, timeframe: "
f"{self._lookback_timeframe}, starting from {format_ms_time(since_ms)} "

View File

@@ -5,7 +5,7 @@ PairList manager class
import logging
from functools import partial
from cachetools import TTLCache, cached
from cachetools import LRUCache, TTLCache, cached
from freqtrade.constants import Config, ListPairsWithTimeframes
from freqtrade.data.dataprovider import DataProvider
@@ -56,6 +56,7 @@ class PairListManager(LoggingMixin):
)
self._check_backtest()
self._not_expiring_cache: LRUCache = LRUCache(maxsize=1)
refresh_period = config.get("pairlist_refresh_period", 3600)
LoggingMixin.__init__(self, logger, refresh_period)
@@ -109,7 +110,15 @@ class PairListManager(LoggingMixin):
@property
def expanded_blacklist(self) -> list[str]:
"""The expanded blacklist (including wildcard expansion)"""
return expand_pairlist(self._blacklist, self._exchange.get_markets().keys())
eblacklist = self._not_expiring_cache.get("eblacklist")
if not eblacklist:
eblacklist = expand_pairlist(self._blacklist, self._exchange.get_markets().keys())
if self._config["runmode"] in (RunMode.BACKTEST, RunMode.HYPEROPT):
self._not_expiring_cache["eblacklist"] = eblacklist.copy()
return eblacklist
@property
def name_list(self) -> list[str]:
@@ -157,16 +166,17 @@ class PairListManager(LoggingMixin):
:param logmethod: Function that'll be called, `logger.info` or `logger.warning`.
:return: pairlist - blacklisted pairs
"""
try:
blacklist = self.expanded_blacklist
except ValueError as err:
logger.error(f"Pair blacklist contains an invalid Wildcard: {err}")
return []
log_once = partial(self.log_once, logmethod=logmethod)
for pair in pairlist.copy():
if pair in blacklist:
log_once(f"Pair {pair} in your blacklist. Removing it from whitelist...")
pairlist.remove(pair)
if self._blacklist:
try:
blacklist = self.expanded_blacklist
except ValueError as err:
logger.error(f"Pair blacklist contains an invalid Wildcard: {err}")
return []
log_once = partial(self.log_once, logmethod=logmethod)
for pair in pairlist.copy():
if pair in blacklist:
log_once(f"Pair {pair} in your blacklist. Removing it from whitelist...")
pairlist.remove(pair)
return pairlist
def verify_whitelist(

View File

@@ -87,7 +87,7 @@ class StrategyResolver(IResolver):
# Loop this list again to have output combined
for attribute, _ in attributes:
if attribute in config:
logger.info("Strategy using %s: %s", attribute, config[attribute])
logger.info(f"Strategy using {attribute}: {config[attribute]}")
StrategyResolver._normalize_attributes(strategy)
@@ -109,9 +109,8 @@ class StrategyResolver(IResolver):
# Ensure Properties are not overwritten
setattr(strategy, attribute, config[attribute])
logger.info(
"Override strategy '%s' with value in config file: %s.",
attribute,
config[attribute],
f"Override strategy '{attribute}' with value from the configuration: "
f"{config[attribute]}.",
)
elif hasattr(strategy, attribute):
val = getattr(strategy, attribute)

View File

@@ -63,7 +63,7 @@ def __run_backtest_bg(btconfig: Config):
ApiBG.bt["bt"] = Backtesting(btconfig)
else:
ApiBG.bt["bt"].config = btconfig
ApiBG.bt["bt"].config = deep_merge_dicts(btconfig, ApiBG.bt["bt"].config)
ApiBG.bt["bt"].init_backtest()
# Only reload data if timeframe changed.
if (

View File

@@ -57,7 +57,8 @@ def pairlists_evaluate(
config_loc = deepcopy(config)
config_loc["stake_currency"] = ""
config_loc["pairs"] = payload.pairs
config_loc["timerange"] = payload.timerange
if payload.timerange:
config_loc["timerange"] = payload.timerange
config_loc["days"] = payload.days
config_loc["timeframes"] = payload.timeframes
config_loc["erase"] = payload.erase

View File

@@ -229,6 +229,7 @@ class ShowConfig(BaseModel):
api_version: float
dry_run: bool
trading_mode: str
margin_mode: str
short_allowed: bool
stake_currency: str
stake_amount: str

View File

@@ -136,6 +136,7 @@ class RPC:
"strategy_version": strategy_version,
"dry_run": config["dry_run"],
"trading_mode": config.get("trading_mode", "spot"),
"margin_mode": config.get("margin_mode", ""),
"short_allowed": config.get("trading_mode", "spot") != "spot",
"stake_currency": config["stake_currency"],
"stake_currency_decimals": decimals_per_coin(config["stake_currency"]),

View File

@@ -360,11 +360,9 @@ class Telegram(RPCHandler):
await asyncio.sleep(2)
if self._app.updater:
await self._app.updater.start_polling(
bootstrap_retries=-1,
bootstrap_retries=10,
timeout=20,
# read_latency=60, # Assumed transmission latency
drop_pending_updates=True,
# stop_signals=[], # Necessary as we don't run on the main thread
)
while True:
await asyncio.sleep(10)

View File

@@ -100,7 +100,7 @@ def _create_and_merge_informative_pair(
dataframe: DataFrame,
metadata: dict,
inf_data: InformativeData,
populate_indicators: PopulateIndicators,
populate_indicators_fn: PopulateIndicators,
):
asset = inf_data.asset or ""
timeframe = inf_data.timeframe
@@ -133,7 +133,12 @@ def _create_and_merge_informative_pair(
inf_metadata = {"pair": asset, "timeframe": timeframe}
inf_dataframe = strategy.dp.get_pair_dataframe(asset, timeframe, candle_type)
inf_dataframe = populate_indicators(strategy, inf_dataframe, inf_metadata)
if inf_dataframe.empty:
raise ValueError(
f"Informative dataframe for ({asset}, {timeframe}, {candle_type}) is empty. "
"Can't populate informative indicators."
)
inf_dataframe = populate_indicators_fn(strategy, inf_dataframe, inf_metadata)
formatter: Any = None
if callable(fmt):

View File

@@ -152,7 +152,7 @@ class IStrategy(ABC, HyperStrategyMixin):
def __init__(self, config: Config) -> None:
self.config = config
# Dict to determine if analysis is necessary
self._last_candle_seen_per_pair: dict[str, datetime] = {}
self.__last_candle_seen_per_pair: dict[str, datetime] = {}
super().__init__(config)
# Gather informative pairs from @informative-decorated methods.
@@ -1209,14 +1209,14 @@ class IStrategy(ABC, HyperStrategyMixin):
"""
pair = str(metadata.get("pair"))
new_candle = self._last_candle_seen_per_pair.get(pair, None) != dataframe.iloc[-1]["date"]
new_candle = self.__last_candle_seen_per_pair.get(pair, None) != dataframe.iloc[-1]["date"]
# Test if seen this pair and last candle before.
# always run if process_only_new_candles is set to false
if not self.process_only_new_candles or new_candle:
# Defs that only make change on new candle data.
dataframe = self.analyze_ticker(dataframe, metadata)
self._last_candle_seen_per_pair[pair] = dataframe.iloc[-1]["date"]
self.__last_candle_seen_per_pair[pair] = dataframe.iloc[-1]["date"]
candle_type = self.config.get("candle_type_def", CandleType.SPOT)
self.dp._set_cached_df(pair, self.timeframe, dataframe, candle_type=candle_type)

View File

@@ -78,5 +78,5 @@ def format_duration(td: timedelta) -> str:
"""
d = td.days
h, r = divmod(td.seconds, 3600)
m, s = divmod(r, 60)
m, _ = divmod(r, 60)
return f"{d}d {h:02d}:{m:02d}"