diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 43ce37051..9b1605a24 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -370,12 +370,13 @@ class Exchange: else: return DataFrame() - def _get_contract_size(self, pair: str) -> int: + def _get_contract_size(self, pair: str) -> float: if self.trading_mode == TradingMode.FUTURES: market = self.markets[pair] - contract_size = 1 + contract_size: float = 1.0 if 'contractSize' in market and market['contractSize'] is not None: - contract_size = market['contractSize'] + # ccxt has contractSize in markets as string + contract_size = float(market['contractSize']) return contract_size else: return 1 diff --git a/tests/conftest.py b/tests/conftest.py index d3836af59..f5c5d5f6e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -939,7 +939,7 @@ def get_markets(): 'active': True, 'spot': False, 'type': 'swap', - 'contractSize': 0.01, + 'contractSize': '0.01', 'precision': { 'amount': 8, 'price': 8 @@ -1010,7 +1010,8 @@ def get_markets(): 'percentage': True, 'taker': 0.0006, 'maker': 0.0002, - 'contractSize': 10, + # TODO-lev: `contractSize` should be numeric - this is an open bug in ccxt. + 'contractSize': '10', 'active': True, 'expiry': None, 'expiryDatetime': None, diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index bd7b449b2..db273faf7 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -484,7 +484,7 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None: result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0) assert isclose(result, expected_result/12) - markets["ETH/BTC"]["contractSize"] = 0.01 + markets["ETH/BTC"]["contractSize"] = '0.01' default_conf['trading_mode'] = 'futures' default_conf['collateral'] = 'isolated' exchange = get_patched_exchange(mocker, default_conf, id="binance") @@ -497,7 +497,7 @@ def test_get_min_pair_stake_amount(mocker, default_conf) -> None: result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1) assert isclose(result, expected_result * 0.01) - markets["ETH/BTC"]["contractSize"] = 10 + markets["ETH/BTC"]["contractSize"] = '10' mocker.patch( 'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets) @@ -3697,14 +3697,14 @@ def test__get_contract_size(mocker, default_conf, pair, expected_size, trading_m }, 'XLTCUSDT': { 'symbol': 'XLTCUSDT', - 'contractSize': 0.01, + 'contractSize': '0.01', }, 'LTC/ETH': { 'symbol': 'LTC/ETH', }, 'ETH/USDT:USDT': { 'symbol': 'ETH/USDT:USDT', - 'contractSize': 10, + 'contractSize': '10', } }) exchange = get_patched_exchange(mocker, default_conf, api_mock) @@ -3857,14 +3857,14 @@ def test__amount_to_contracts( }, 'XLTCUSDT': { 'symbol': 'XLTCUSDT', - 'contractSize': 0.01, + 'contractSize': '0.01', }, 'LTC/ETH': { 'symbol': 'LTC/ETH', }, 'ETH/USDT:USDT': { 'symbol': 'ETH/USDT:USDT', - 'contractSize': 10, + 'contractSize': '10', } }) exchange = get_patched_exchange(mocker, default_conf, api_mock)