Merge pull request #6170 from freqtrade/contract_workaround

contractSize is a string coming from ccxt
This commit is contained in:
Matthias 2022-01-06 16:25:19 +01:00 committed by GitHub
commit 173524ea5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -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

View File

@ -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,

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)
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)