From c2914feb123dd71fb15154bc8ffa96c6a562e6cb Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 17 Oct 2022 09:54:58 +0000 Subject: [PATCH] Don't fail contract size repopulation if pair is no longer available --- freqtrade/exchange/exchange.py | 6 ++++-- tests/exchange/test_exchange.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 53a3960b1..2054d44e9 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -412,9 +412,11 @@ class Exchange: def get_contract_size(self, pair: str) -> float: if self.trading_mode == TradingMode.FUTURES: - market = self.markets[pair] + market = self.markets.get(pair, {}) contract_size: float = 1.0 - if market['contractSize'] is not None: + if not market: + return None + if market.get('contractSize') is not None: # ccxt has contractSize in markets as string contract_size = float(market['contractSize']) return contract_size diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 07aad80ff..a48cb05e0 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -4341,9 +4341,10 @@ def test__fetch_and_calculate_funding_fees_datetime_called( ('XLTCUSDT', 1, 'spot'), ('LTC/USD', 1, 'futures'), ('XLTCUSDT', 0.01, 'futures'), - ('ETH/USDT:USDT', 10, 'futures') + ('ETH/USDT:USDT', 10, 'futures'), + ('TORN/USDT:USDT', None, 'futures'), # Don't fail for unavailable pairs. ]) -def est__get_contract_size(mocker, default_conf, pair, expected_size, trading_mode): +def test__get_contract_size(mocker, default_conf, pair, expected_size, trading_mode): api_mock = MagicMock() default_conf['trading_mode'] = trading_mode default_conf['margin_mode'] = 'isolated'