Merge pull request #6170 from freqtrade/contract_workaround
contractSize is a string coming from ccxt
This commit is contained in:
commit
173524ea5b
@ -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
|
||||||
|
@ -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,
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user