From 72f6ee8e8b5ed1162627623fbcd986bb2ff4f893 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 21 Jul 2024 20:09:14 +0200 Subject: [PATCH] feat: Add Orderflow -> exchange support validation --- freqtrade/exchange/exchange.py | 9 +++++++++ tests/exchange/test_exchange.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 9f7868d1c..2b6373ab8 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -328,6 +328,7 @@ class Exchange: self.validate_trading_mode_and_margin_mode(self.trading_mode, self.margin_mode) self.validate_pricing(config["exit_pricing"]) self.validate_pricing(config["entry_pricing"]) + self.validate_orderflow(config["exchange"]) def _init_ccxt( self, exchange_config: Dict[str, Any], sync: bool, ccxt_kwargs: Dict[str, Any] @@ -795,6 +796,14 @@ class Exchange: f"Time in force policies are not supported for {self.name} yet." ) + def validate_orderflow(self, exchange: Dict) -> None: + if exchange.get("use_public_trades", False) and ( + not self.exchange_has("fetchTrades") or not self._ft_has["trades_has_history"] + ): + raise ConfigurationError( + f"Trade data not available for {self.name}. Can't use orderflow feature." + ) + def validate_required_startup_candles(self, startup_candles: int, timeframe: str) -> int: """ Checks if required startup_candles is more than ohlcv_candle_limit(). diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 2d0915753..09011565d 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -326,6 +326,22 @@ def test_validate_order_time_in_force(default_conf, mocker, caplog): ex.validate_order_time_in_force(tif2) +def test_validate_orderflow(default_conf, mocker, caplog): + caplog.set_level(logging.INFO) + # Test bybit - as it doesn't support historic trades data. + ex = get_patched_exchange(mocker, default_conf, exchange="bybit") + mocker.patch(f"{EXMS}.exchange_has", return_value=True) + ex.validate_orderflow({"use_public_trades": False}) + + with pytest.raises(ConfigurationError, match=r"Trade data not available for.*"): + ex.validate_orderflow({"use_public_trades": True}) + + # Binance supports orderflow. + ex = get_patched_exchange(mocker, default_conf, exchange="binance") + ex.validate_orderflow({"use_public_trades": False}) + ex.validate_orderflow({"use_public_trades": True}) + + @pytest.mark.parametrize( "price,precision_mode,precision,expected", [