From eaf13f96f7760de4b06752904c88666a3c6e5769 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 12:48:28 +0100 Subject: [PATCH 1/6] Use exchange_has to check for ccxt properties --- freqtrade/exchange/exchange.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 45d66db06..8af81ad47 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1856,7 +1856,7 @@ class Exchange: raise OperationalException(e) from e def load_leverage_tiers(self) -> Dict[str, List[Dict]]: - if self.trading_mode == TradingMode.FUTURES and self._api.has['fetchLeverageTiers']: + if self.trading_mode == TradingMode.FUTURES and self.exchange_has('fetchLeverageTiers'): try: return self._api.fetch_leverage_tiers() except ccxt.DDoSProtection as e: @@ -2259,7 +2259,7 @@ class Exchange: :return: (maintenance margin ratio, maintenance amount) """ - if self._api.has['fetchLeverageTiers']: + if self.exchange_has('fetchLeverageTiers'): if pair not in self._leverage_tiers: raise InvalidOrderException( From 7f0cedc769e8395e315f7e8208f40c8dbf582fb1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 12:54:49 +0100 Subject: [PATCH 2/6] Use "is_future" to check for futures markets --- freqtrade/exchange/okx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py index b11627bb1..03d66fb3d 100644 --- a/freqtrade/exchange/okx.py +++ b/freqtrade/exchange/okx.py @@ -70,8 +70,8 @@ class Okx(Exchange): symbols = [] for symbol, market in markets.items(): - if (market["swap"] and market["linear"]): - symbols.append(market["symbol"]) + if self.market_is_future(market): + symbols.append(symbol) tiers = {} for symbol in symbols: From b98297786c5db69ccacd35c381c24a0111c47b49 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 12:56:32 +0100 Subject: [PATCH 3/6] Update failing mock --- tests/test_freqtradebot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index f9e75bb05..93920a163 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -722,8 +722,8 @@ def test_process_informative_pairs_added(default_conf_usdt, ticker_usdt, mocker) (False, 'futures', 'binance', 'isolated', 0.05, 8.167171717171717), (True, 'futures', 'gateio', 'isolated', 0.05, 11.7804274688304), (False, 'futures', 'gateio', 'isolated', 0.05, 8.181423084697796), - (True, 'futures', 'okex', 'isolated', 0.0, 11.87413417771621), - (False, 'futures', 'okex', 'isolated', 0.0, 8.085708510208207), + (True, 'futures', 'okx', 'isolated', 0.0, 11.87413417771621), + (False, 'futures', 'okx', 'isolated', 0.0, 8.085708510208207), ]) def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, limit_order_open, is_short, trading_mode, @@ -784,7 +784,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, get_max_leverage=MagicMock(return_value=10), ) mocker.patch.multiple( - 'freqtrade.exchange.Okex', + 'freqtrade.exchange.Okx', get_max_pair_stake_amount=MagicMock(return_value=500000), ) pair = 'ETH/USDT' From bc855b2a326f65dda8af50f4c29c00c31f49a358 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 13:00:38 +0100 Subject: [PATCH 4/6] Update some missing mocks --- tests/exchange/test_binance.py | 1 + tests/exchange/test_exchange.py | 2 ++ tests/exchange/test_okex.py | 1 + 3 files changed, 4 insertions(+) diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index 30ffeeae0..631b7e8c0 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -593,6 +593,7 @@ def test_get_maintenance_ratio_and_amt_binance( mm_ratio, amt, ): + mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True) exchange = get_patched_exchange(mocker, default_conf, id="binance") exchange._leverage_tiers = leverage_tiers (result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 032473062..fda3f6ea2 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -4311,6 +4311,7 @@ def test_get_maintenance_ratio_and_amt_exceptions(mocker, default_conf, leverage api_mock = MagicMock() default_conf['trading_mode'] = 'futures' default_conf['margin_mode'] = 'isolated' + mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True) exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange._leverage_tiers = leverage_tiers @@ -4347,6 +4348,7 @@ def test_get_maintenance_ratio_and_amt( api_mock = MagicMock() default_conf['trading_mode'] = 'futures' default_conf['margin_mode'] = 'isolated' + mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True) exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt) diff --git a/tests/exchange/test_okex.py b/tests/exchange/test_okex.py index a9f7b8099..f9a93c569 100644 --- a/tests/exchange/test_okex.py +++ b/tests/exchange/test_okex.py @@ -13,6 +13,7 @@ def test_get_maintenance_ratio_and_amt_okx( default_conf['dry_run'] = False mocker.patch.multiple( 'freqtrade.exchange.Okx', + exchange_has=MagicMock(return_value=True), load_leverage_tiers=MagicMock(return_value={ 'ETH/USDT:USDT': [ { From 96df31124459f26e8e329e07ceaf084dbf12fcf2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 13:01:01 +0100 Subject: [PATCH 5/6] Rename test_okex to test_okx --- tests/exchange/{test_okex.py => test_okx.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/exchange/{test_okex.py => test_okx.py} (100%) diff --git a/tests/exchange/test_okex.py b/tests/exchange/test_okx.py similarity index 100% rename from tests/exchange/test_okex.py rename to tests/exchange/test_okx.py From ad801e05f7ed98aaeed8f96aa65248d99366b529 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 13 Feb 2022 13:04:55 +0100 Subject: [PATCH 6/6] Filter loadable leverage tiers to stake-currency pairs --- freqtrade/exchange/okx.py | 3 ++- tests/exchange/test_binance.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py index 03d66fb3d..bd2913932 100644 --- a/freqtrade/exchange/okx.py +++ b/freqtrade/exchange/okx.py @@ -70,7 +70,8 @@ class Okx(Exchange): symbols = [] for symbol, market in markets.items(): - if self.market_is_future(market): + if (self.market_is_future(market) + and market['quote'] == self._config['stake_currency']): symbols.append(symbol) tiers = {} diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index 631b7e8c0..64c16d5e7 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -1,5 +1,4 @@ from datetime import datetime, timezone -from math import isclose from random import randint from unittest.mock import MagicMock, PropertyMock