From 3d86b184929bc6d9d6f2ca75548775a87c35367d Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 13 Nov 2021 05:00:47 -0600 Subject: [PATCH 1/3] Added property _ft_has_default.ccxt_futures_name and removed subclass ccxt_config properties --- freqtrade/exchange/binance.py | 19 +------------------ freqtrade/exchange/bybit.py | 1 + freqtrade/exchange/exchange.py | 16 +++++++++++++++- freqtrade/exchange/gateio.py | 18 ------------------ freqtrade/exchange/okex.py | 18 ------------------ tests/exchange/test_exchange.py | 7 ------- 6 files changed, 17 insertions(+), 62 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index c16566fde..9a707072d 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -27,6 +27,7 @@ class Binance(Exchange): "trades_pagination": "id", "trades_pagination_arg": "fromId", "l2_limit_range": [5, 10, 20, 50, 100, 500, 1000], + "ccxt_futures_name": "future" } funding_fee_times: List[int] = [0, 8, 16] # hours of the day # but the schedule won't check within this timeframe @@ -38,24 +39,6 @@ class Binance(Exchange): # (TradingMode.FUTURES, Collateral.ISOLATED) # TODO-lev: Uncomment once supported ] - @property - def _ccxt_config(self) -> Dict: - # Parameters to add directly to ccxt sync/async initialization. - if self.trading_mode == TradingMode.MARGIN: - return { - "options": { - "defaultType": "margin" - } - } - elif self.trading_mode == TradingMode.FUTURES: - return { - "options": { - "defaultType": "future" - } - } - else: - return {} - def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool: """ Verify stop_loss against stoploss-order value (limit or price) diff --git a/freqtrade/exchange/bybit.py b/freqtrade/exchange/bybit.py index df19a671b..27deb79d7 100644 --- a/freqtrade/exchange/bybit.py +++ b/freqtrade/exchange/bybit.py @@ -21,6 +21,7 @@ class Bybit(Exchange): _ft_has: Dict = { "ohlcv_candle_limit": 200, + "ccxt_futures_name": "linear" } funding_fee_times: List[int] = [0, 8, 16] # hours of the day diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index cf7772600..5025d2396 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -69,6 +69,7 @@ class Exchange: "trades_pagination_arg": "since", "l2_limit_range": None, "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) + "ccxt_futures_name": "swap" } _ft_has: Dict = {} @@ -234,7 +235,20 @@ class Exchange: @property def _ccxt_config(self) -> Dict: # Parameters to add directly to ccxt sync/async initialization. - return {} + if self.trading_mode == TradingMode.MARGIN: + return { + "options": { + "defaultType": "margin" + } + } + elif self.trading_mode == TradingMode.FUTURES: + return { + "options": { + "defaultType": self._ft_has["ccxt_futures_name"] + } + } + else: + return {} @property def name(self) -> str: diff --git a/freqtrade/exchange/gateio.py b/freqtrade/exchange/gateio.py index 83abd1266..d7edb843c 100644 --- a/freqtrade/exchange/gateio.py +++ b/freqtrade/exchange/gateio.py @@ -35,24 +35,6 @@ class Gateio(Exchange): # (TradingMode.FUTURES, Collateral.ISOLATED) # TODO-lev: Uncomment once supported ] - @property - def _ccxt_config(self) -> Dict: - # Parameters to add directly to ccxt sync/async initialization. - if self.trading_mode == TradingMode.MARGIN: - return { - "options": { - "defaultType": "margin" - } - } - elif self.trading_mode == TradingMode.FUTURES: - return { - "options": { - "defaultType": "swap" - } - } - else: - return {} - def validate_ordertypes(self, order_types: Dict) -> None: super().validate_ordertypes(order_types) diff --git a/freqtrade/exchange/okex.py b/freqtrade/exchange/okex.py index 100bf3adf..a435ef819 100644 --- a/freqtrade/exchange/okex.py +++ b/freqtrade/exchange/okex.py @@ -25,21 +25,3 @@ class Okex(Exchange): # (TradingMode.FUTURES, Collateral.CROSS), # TODO-lev: Uncomment once supported # (TradingMode.FUTURES, Collateral.ISOLATED) # TODO-lev: Uncomment once supported ] - - @property - def _ccxt_config(self) -> Dict: - # Parameters to add directly to ccxt sync/async initialization. - if self.trading_mode == TradingMode.MARGIN: - return { - "options": { - "defaultType": "margin" - } - } - elif self.trading_mode == TradingMode.FUTURES: - return { - "options": { - "defaultType": "swap" - } - } - else: - return {} diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 8e3fdfe74..6b6900752 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3253,13 +3253,6 @@ def test_validate_trading_mode_and_collateral( ("binance", "spot", {}), ("binance", "margin", {"options": {"defaultType": "margin"}}), ("binance", "futures", {"options": {"defaultType": "future"}}), - ("kraken", "spot", {}), - ("kraken", "margin", {}), - ("kraken", "futures", {}), - ("ftx", "spot", {}), - ("ftx", "margin", {}), - ("ftx", "futures", {}), - ("bittrex", "spot", {}), ("gateio", "spot", {}), ("gateio", "margin", {"options": {"defaultType": "margin"}}), ("gateio", "futures", {"options": {"defaultType": "swap"}}), From 099bf7691e2a932ae0e980f81326a4df4d306e6a Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 13 Nov 2021 16:22:36 -0600 Subject: [PATCH 2/3] Updated bibox to combine parent _ccxt_config and minimized _ccxt_config tests --- freqtrade/exchange/bibox.py | 4 +++- tests/exchange/test_exchange.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/freqtrade/exchange/bibox.py b/freqtrade/exchange/bibox.py index e0741e34a..5574c401a 100644 --- a/freqtrade/exchange/bibox.py +++ b/freqtrade/exchange/bibox.py @@ -23,6 +23,8 @@ class Bibox(Exchange): @property def _ccxt_config(self) -> Dict: # Parameters to add directly to ccxt sync/async initialization. - return {"has": {"fetchCurrencies": False}} + config = {"has": {"fetchCurrencies": False}} + config.update(super()._ccxt_config) + return config funding_fee_times: List[int] = [0, 8, 16] # hours of the day diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 6b6900752..b92299fdd 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3253,9 +3253,10 @@ def test_validate_trading_mode_and_collateral( ("binance", "spot", {}), ("binance", "margin", {"options": {"defaultType": "margin"}}), ("binance", "futures", {"options": {"defaultType": "future"}}), - ("gateio", "spot", {}), - ("gateio", "margin", {"options": {"defaultType": "margin"}}), ("gateio", "futures", {"options": {"defaultType": "swap"}}), + ("bibox", "spot", {"has": {"fetchCurrencies": False}}), + ("bibox", "margin", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "margin"}}), + ("bibox", "futures", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "swap"}}), ]) def test__ccxt_config( default_conf, From 3ce64dd4e9ac6236400d48af88b35e7a57866a2d Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 13 Nov 2021 16:32:43 -0600 Subject: [PATCH 3/3] Added test__ccxt_config for all exchanges with subclass files on freqtrade --- tests/exchange/test_exchange.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index b92299fdd..1846b3721 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3253,10 +3253,16 @@ def test_validate_trading_mode_and_collateral( ("binance", "spot", {}), ("binance", "margin", {"options": {"defaultType": "margin"}}), ("binance", "futures", {"options": {"defaultType": "future"}}), - ("gateio", "futures", {"options": {"defaultType": "swap"}}), ("bibox", "spot", {"has": {"fetchCurrencies": False}}), ("bibox", "margin", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "margin"}}), ("bibox", "futures", {"has": {"fetchCurrencies": False}, "options": {"defaultType": "swap"}}), + ("bybit", "futures", {"options": {"defaultType": "linear"}}), + ("ftx", "futures", {"options": {"defaultType": "swap"}}), + ("gateio", "futures", {"options": {"defaultType": "swap"}}), + ("hitbtc", "futures", {"options": {"defaultType": "swap"}}), + ("kraken", "futures", {"options": {"defaultType": "swap"}}), + ("kucoin", "futures", {"options": {"defaultType": "swap"}}), + ("okex", "futures", {"options": {"defaultType": "swap"}}), ]) def test__ccxt_config( default_conf,