exchange.get_max_pair_stake_amount hard set leverage to 0
This commit is contained in:
parent
c0a593280e
commit
8b57827676
@ -690,9 +690,8 @@ class Exchange:
|
||||
self,
|
||||
pair: str,
|
||||
price: float,
|
||||
stoploss: float
|
||||
) -> float:
|
||||
max_stake_amount = self._get_stake_amount_limit(pair, price, stoploss, 'max')
|
||||
max_stake_amount = self._get_stake_amount_limit(pair, price, 0.0, 'max')
|
||||
if max_stake_amount is None:
|
||||
# * Should never be executed
|
||||
raise OperationalException(f'{self.name}.get_max_pair_stake_amount should'
|
||||
|
@ -543,9 +543,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair,
|
||||
current_rate,
|
||||
self.strategy.stoploss)
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(trade.pair,
|
||||
current_rate,
|
||||
self.strategy.stoploss)
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(trade.pair, current_rate)
|
||||
stake_available = self.wallets.get_available_stake_amount()
|
||||
logger.debug(f"Calling adjust_trade_position for pair {trade.pair}")
|
||||
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
|
||||
@ -852,8 +850,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
# edge-case for now.
|
||||
min_stake_amount = self.exchange.get_min_pair_stake_amount(
|
||||
pair, enter_limit_requested, self.strategy.stoploss)
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(
|
||||
pair, enter_limit_requested, self.strategy.stoploss)
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(pair, enter_limit_requested)
|
||||
|
||||
if not self.edge and trade is None:
|
||||
stake_available = self.wallets.get_available_stake_amount()
|
||||
|
@ -417,7 +417,7 @@ class Backtesting:
|
||||
# TODO: Write tests
|
||||
current_profit = trade.calc_profit_ratio(row[OPEN_IDX])
|
||||
min_stake = self.exchange.get_min_pair_stake_amount(trade.pair, row[OPEN_IDX], -0.1)
|
||||
max_stake = self.exchange.get_max_pair_stake_amount(trade.pair, row[OPEN_IDX], -0.1)
|
||||
max_stake = self.exchange.get_max_pair_stake_amount(trade.pair, row[OPEN_IDX])
|
||||
stake_available = self.wallets.get_available_stake_amount()
|
||||
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
|
||||
default_retval=None)(
|
||||
@ -557,7 +557,7 @@ class Backtesting:
|
||||
propose_rate = min(max(propose_rate, row[LOW_IDX]), row[HIGH_IDX])
|
||||
|
||||
min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, propose_rate, -0.05) or 0
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(pair, propose_rate, -0.05)
|
||||
max_stake_amount = self.exchange.get_max_pair_stake_amount(pair, propose_rate)
|
||||
stake_available = self.wallets.get_available_stake_amount()
|
||||
|
||||
pos_adjust = trade is not None
|
||||
|
@ -367,7 +367,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
)
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||
assert result is None
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 1)
|
||||
assert result == float('inf')
|
||||
|
||||
# min/max cost is set
|
||||
@ -387,7 +387,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss, 3.0)
|
||||
assert isclose(result, expected_result/3)
|
||||
# max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 10000
|
||||
|
||||
# min amount is set
|
||||
@ -406,7 +406,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 5.0)
|
||||
assert isclose(result, expected_result/5)
|
||||
# max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 20000
|
||||
|
||||
# min amount and cost are set (cost is minimal)
|
||||
@ -441,7 +441,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 7.0)
|
||||
assert isclose(result, expected_result/7.0)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 1000
|
||||
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4)
|
||||
@ -451,7 +451,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4, 8.0)
|
||||
assert isclose(result, expected_result/8.0)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 1000
|
||||
|
||||
# Really big stoploss
|
||||
@ -462,7 +462,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
||||
assert isclose(result, expected_result/12)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 1000
|
||||
|
||||
markets["ETH/BTC"]["contractSize"] = '0.01'
|
||||
@ -478,7 +478,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
||||
assert isclose(result, expected_result * 0.01)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, -1)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 10
|
||||
|
||||
markets["ETH/BTC"]["contractSize"] = '10'
|
||||
@ -490,7 +490,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
||||
assert isclose(result, (expected_result/12) * 10.0)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2, -1)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2)
|
||||
assert result == 10000
|
||||
|
||||
|
||||
@ -512,7 +512,7 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
||||
expected_result = max(0.0001, 0.001 * 0.020405) * (1+0.05) / (1-abs(stoploss))
|
||||
assert round(result, 8) == round(expected_result, 8)
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2.0, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 2.0)
|
||||
assert result == 4000
|
||||
|
||||
# Leverage
|
||||
@ -525,7 +525,7 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
||||
assert round(result, 8) == round((expected_result/3), 8)
|
||||
|
||||
# Max
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 12.0, stoploss)
|
||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 12.0)
|
||||
assert result == 4000
|
||||
|
||||
|
||||
@ -4196,14 +4196,14 @@ def test_get_max_pair_stake_amount(
|
||||
}
|
||||
|
||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
||||
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0, 0.0) == 20000
|
||||
assert exchange.get_max_pair_stake_amount('LTC/USDT:USDT', 2.0, 0.0) == float('inf')
|
||||
assert exchange.get_max_pair_stake_amount('ETH/USDT:USDT', 2.0, 0.0) == 200
|
||||
assert exchange.get_max_pair_stake_amount('DOGE/USDT:USDT', 2.0, 0.0) == 500
|
||||
assert exchange.get_max_pair_stake_amount('LUNA/USDT:USDT', 2.0, 0.0) == 5.0
|
||||
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0) == 20000
|
||||
assert exchange.get_max_pair_stake_amount('LTC/USDT:USDT', 2.0) == float('inf')
|
||||
assert exchange.get_max_pair_stake_amount('ETH/USDT:USDT', 2.0) == 200
|
||||
assert exchange.get_max_pair_stake_amount('DOGE/USDT:USDT', 2.0) == 500
|
||||
assert exchange.get_max_pair_stake_amount('LUNA/USDT:USDT', 2.0) == 5.0
|
||||
|
||||
default_conf['trading_mode'] = 'spot'
|
||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
||||
assert exchange.get_max_pair_stake_amount('BTC/USDT', 2.0, 0.0) == 20000
|
||||
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0, 0.0) == 500
|
||||
assert exchange.get_max_pair_stake_amount('BTC/USDT', 2.0) == 20000
|
||||
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500
|
||||
|
Loading…
Reference in New Issue
Block a user