contractSize is a string comming from ccxt

This commit is contained in:
Matthias 2022-01-06 10:40:31 +01:00
parent c1d981749e
commit 431fcdd76f
3 changed files with 13 additions and 11 deletions

View File

@ -370,12 +370,13 @@ class Exchange:
else: else:
return DataFrame() return DataFrame()
def _get_contract_size(self, pair: str) -> int: def _get_contract_size(self, pair: str) -> float:
if self.trading_mode == TradingMode.FUTURES: if self.trading_mode == TradingMode.FUTURES:
market = self.markets[pair] market = self.markets[pair]
contract_size = 1 contract_size: float = 1.0
if 'contractSize' in market and market['contractSize'] is not None: 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 return contract_size
else: else:
return 1 return 1

View File

@ -939,7 +939,7 @@ def get_markets():
'active': True, 'active': True,
'spot': False, 'spot': False,
'type': 'swap', 'type': 'swap',
'contractSize': 0.01, 'contractSize': '0.01',
'precision': { 'precision': {
'amount': 8, 'amount': 8,
'price': 8 'price': 8
@ -1010,7 +1010,8 @@ def get_markets():
'percentage': True, 'percentage': True,
'taker': 0.0006, 'taker': 0.0006,
'maker': 0.0002, 'maker': 0.0002,
'contractSize': 10, # TODO-lev: `contractSize` should be numeric - this is an open bug in ccxt.
'contractSize': '10',
'active': True, 'active': True,
'expiry': None, 'expiry': None,
'expiryDatetime': None, 'expiryDatetime': None,

View File

@ -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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
assert isclose(result, expected_result/12) 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['trading_mode'] = 'futures'
default_conf['collateral'] = 'isolated' default_conf['collateral'] = 'isolated'
exchange = get_patched_exchange(mocker, default_conf, id="binance") 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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
assert isclose(result, expected_result * 0.01) assert isclose(result, expected_result * 0.01)
markets["ETH/BTC"]["contractSize"] = 10 markets["ETH/BTC"]["contractSize"] = '10'
mocker.patch( mocker.patch(
'freqtrade.exchange.Exchange.markets', 'freqtrade.exchange.Exchange.markets',
PropertyMock(return_value=markets) PropertyMock(return_value=markets)
@ -3697,14 +3697,14 @@ def test__get_contract_size(mocker, default_conf, pair, expected_size, trading_m
}, },
'XLTCUSDT': { 'XLTCUSDT': {
'symbol': 'XLTCUSDT', 'symbol': 'XLTCUSDT',
'contractSize': 0.01, 'contractSize': '0.01',
}, },
'LTC/ETH': { 'LTC/ETH': {
'symbol': 'LTC/ETH', 'symbol': 'LTC/ETH',
}, },
'ETH/USDT:USDT': { 'ETH/USDT:USDT': {
'symbol': 'ETH/USDT:USDT', 'symbol': 'ETH/USDT:USDT',
'contractSize': 10, 'contractSize': '10',
} }
}) })
exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange = get_patched_exchange(mocker, default_conf, api_mock)
@ -3857,14 +3857,14 @@ def test__amount_to_contracts(
}, },
'XLTCUSDT': { 'XLTCUSDT': {
'symbol': 'XLTCUSDT', 'symbol': 'XLTCUSDT',
'contractSize': 0.01, 'contractSize': '0.01',
}, },
'LTC/ETH': { 'LTC/ETH': {
'symbol': 'LTC/ETH', 'symbol': 'LTC/ETH',
}, },
'ETH/USDT:USDT': { 'ETH/USDT:USDT': {
'symbol': 'ETH/USDT:USDT', 'symbol': 'ETH/USDT:USDT',
'contractSize': 10, 'contractSize': '10',
} }
}) })
exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange = get_patched_exchange(mocker, default_conf, api_mock)