Merge branch 'leverage-tiers' of https://github.com/samgermain/freqtrade into leverage-tiers
This commit is contained in:
commit
5cd2501397
@ -1856,7 +1856,7 @@ class Exchange:
|
|||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
||||||
if self.trading_mode == TradingMode.FUTURES and self._api.has['fetchLeverageTiers']:
|
if self.trading_mode == TradingMode.FUTURES and self.exchange_has('fetchLeverageTiers'):
|
||||||
try:
|
try:
|
||||||
return self._api.fetch_leverage_tiers()
|
return self._api.fetch_leverage_tiers()
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
@ -2259,7 +2259,7 @@ class Exchange:
|
|||||||
:return: (maintenance margin ratio, maintenance amount)
|
:return: (maintenance margin ratio, maintenance amount)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._api.has['fetchLeverageTiers']:
|
if self.exchange_has('fetchLeverageTiers'):
|
||||||
|
|
||||||
if pair not in self._leverage_tiers:
|
if pair not in self._leverage_tiers:
|
||||||
raise InvalidOrderException(
|
raise InvalidOrderException(
|
||||||
|
@ -70,8 +70,9 @@ class Okx(Exchange):
|
|||||||
symbols = []
|
symbols = []
|
||||||
|
|
||||||
for symbol, market in markets.items():
|
for symbol, market in markets.items():
|
||||||
if (market["swap"] and market["linear"]):
|
if (self.market_is_future(market)
|
||||||
symbols.append(market["symbol"])
|
and market['quote'] == self._config['stake_currency']):
|
||||||
|
symbols.append(symbol)
|
||||||
|
|
||||||
tiers = {}
|
tiers = {}
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
|
@ -592,6 +592,7 @@ def test_get_maintenance_ratio_and_amt_binance(
|
|||||||
mm_ratio,
|
mm_ratio,
|
||||||
amt,
|
amt,
|
||||||
):
|
):
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
exchange._leverage_tiers = leverage_tiers
|
exchange._leverage_tiers = leverage_tiers
|
||||||
(result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value)
|
(result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value)
|
||||||
|
@ -4312,6 +4312,7 @@ def test_get_maintenance_ratio_and_amt_exceptions(mocker, default_conf, leverage
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
|
||||||
exchange._leverage_tiers = leverage_tiers
|
exchange._leverage_tiers = leverage_tiers
|
||||||
@ -4348,6 +4349,7 @@ def test_get_maintenance_ratio_and_amt(
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt)
|
exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ def test_get_maintenance_ratio_and_amt_okx(
|
|||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Okx',
|
'freqtrade.exchange.Okx',
|
||||||
|
exchange_has=MagicMock(return_value=True),
|
||||||
load_leverage_tiers=MagicMock(return_value={
|
load_leverage_tiers=MagicMock(return_value={
|
||||||
'ETH/USDT:USDT': [
|
'ETH/USDT:USDT': [
|
||||||
{
|
{
|
@ -722,8 +722,8 @@ def test_process_informative_pairs_added(default_conf_usdt, ticker_usdt, mocker)
|
|||||||
(False, 'futures', 'binance', 'isolated', 0.05, 8.167171717171717),
|
(False, 'futures', 'binance', 'isolated', 0.05, 8.167171717171717),
|
||||||
(True, 'futures', 'gateio', 'isolated', 0.05, 11.7804274688304),
|
(True, 'futures', 'gateio', 'isolated', 0.05, 11.7804274688304),
|
||||||
(False, 'futures', 'gateio', 'isolated', 0.05, 8.181423084697796),
|
(False, 'futures', 'gateio', 'isolated', 0.05, 8.181423084697796),
|
||||||
(True, 'futures', 'okex', 'isolated', 0.0, 11.87413417771621),
|
(True, 'futures', 'okx', 'isolated', 0.0, 11.87413417771621),
|
||||||
(False, 'futures', 'okex', 'isolated', 0.0, 8.085708510208207),
|
(False, 'futures', 'okx', 'isolated', 0.0, 8.085708510208207),
|
||||||
])
|
])
|
||||||
def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
||||||
limit_order_open, is_short, trading_mode,
|
limit_order_open, is_short, trading_mode,
|
||||||
@ -784,7 +784,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
|||||||
get_max_leverage=MagicMock(return_value=10),
|
get_max_leverage=MagicMock(return_value=10),
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Okex',
|
'freqtrade.exchange.Okx',
|
||||||
get_max_pair_stake_amount=MagicMock(return_value=500000),
|
get_max_pair_stake_amount=MagicMock(return_value=500000),
|
||||||
)
|
)
|
||||||
pair = 'ETH/USDT'
|
pair = 'ETH/USDT'
|
||||||
|
Loading…
Reference in New Issue
Block a user