exchange.get_max_pair_stake_amount hard set leverage to 0

This commit is contained in:
Sam Germain 2022-02-04 14:26:15 -06:00
parent c0a593280e
commit 8b57827676
4 changed files with 22 additions and 26 deletions

View File

@ -690,9 +690,8 @@ class Exchange:
self, self,
pair: str, pair: str,
price: float, price: float,
stoploss: float
) -> 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: if max_stake_amount is None:
# * Should never be executed # * Should never be executed
raise OperationalException(f'{self.name}.get_max_pair_stake_amount should' raise OperationalException(f'{self.name}.get_max_pair_stake_amount should'

View File

@ -543,9 +543,7 @@ class FreqtradeBot(LoggingMixin):
min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair, min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair,
current_rate, current_rate,
self.strategy.stoploss) self.strategy.stoploss)
max_stake_amount = self.exchange.get_max_pair_stake_amount(trade.pair, max_stake_amount = self.exchange.get_max_pair_stake_amount(trade.pair, current_rate)
current_rate,
self.strategy.stoploss)
stake_available = self.wallets.get_available_stake_amount() stake_available = self.wallets.get_available_stake_amount()
logger.debug(f"Calling adjust_trade_position for pair {trade.pair}") logger.debug(f"Calling adjust_trade_position for pair {trade.pair}")
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
@ -852,8 +850,7 @@ class FreqtradeBot(LoggingMixin):
# edge-case for now. # edge-case for now.
min_stake_amount = self.exchange.get_min_pair_stake_amount( min_stake_amount = self.exchange.get_min_pair_stake_amount(
pair, enter_limit_requested, self.strategy.stoploss) pair, enter_limit_requested, self.strategy.stoploss)
max_stake_amount = self.exchange.get_max_pair_stake_amount( max_stake_amount = self.exchange.get_max_pair_stake_amount(pair, enter_limit_requested)
pair, enter_limit_requested, self.strategy.stoploss)
if not self.edge and trade is None: if not self.edge and trade is None:
stake_available = self.wallets.get_available_stake_amount() stake_available = self.wallets.get_available_stake_amount()

View File

@ -417,7 +417,7 @@ class Backtesting:
# TODO: Write tests # TODO: Write tests
current_profit = trade.calc_profit_ratio(row[OPEN_IDX]) 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) 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_available = self.wallets.get_available_stake_amount()
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
default_retval=None)( default_retval=None)(
@ -557,7 +557,7 @@ class Backtesting:
propose_rate = min(max(propose_rate, row[LOW_IDX]), row[HIGH_IDX]) 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 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() stake_available = self.wallets.get_available_stake_amount()
pos_adjust = trade is not None pos_adjust = trade is not None

View File

@ -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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
assert result is None 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') assert result == float('inf')
# min/max cost is set # 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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss, 3.0)
assert isclose(result, expected_result/3) assert isclose(result, expected_result/3)
# max # 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 assert result == 10000
# min amount is set # 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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 5.0)
assert isclose(result, expected_result/5) assert isclose(result, expected_result/5)
# max # 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 assert result == 20000
# min amount and cost are set (cost is minimal) # 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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss, 7.0)
assert isclose(result, expected_result/7.0) assert isclose(result, expected_result/7.0)
# Max # 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 assert result == 1000
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4) 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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -0.4, 8.0)
assert isclose(result, expected_result/8.0) assert isclose(result, expected_result/8.0)
# Max # 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 assert result == 1000
# Really big stoploss # 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) 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)
# Max # 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 assert result == 1000
markets["ETH/BTC"]["contractSize"] = '0.01' 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) 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)
# Max # 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 assert result == 10
markets["ETH/BTC"]["contractSize"] = '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) result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
assert isclose(result, (expected_result/12) * 10.0) assert isclose(result, (expected_result/12) * 10.0)
# Max # 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 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)) expected_result = max(0.0001, 0.001 * 0.020405) * (1+0.05) / (1-abs(stoploss))
assert round(result, 8) == round(expected_result, 8) assert round(result, 8) == round(expected_result, 8)
# Max # 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 assert result == 4000
# Leverage # 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) assert round(result, 8) == round((expected_result/3), 8)
# Max # 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 assert result == 4000
@ -4196,14 +4196,14 @@ def test_get_max_pair_stake_amount(
} }
mocker.patch('freqtrade.exchange.Exchange.markets', markets) 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('XRP/USDT:USDT', 2.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('LTC/USDT:USDT', 2.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('ETH/USDT:USDT', 2.0) == 200
assert exchange.get_max_pair_stake_amount('DOGE/USDT:USDT', 2.0, 0.0) == 500 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, 0.0) == 5.0 assert exchange.get_max_pair_stake_amount('LUNA/USDT:USDT', 2.0) == 5.0
default_conf['trading_mode'] = 'spot' default_conf['trading_mode'] = 'spot'
exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange = get_patched_exchange(mocker, default_conf, api_mock)
mocker.patch('freqtrade.exchange.Exchange.markets', markets) 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('BTC/USDT', 2.0) == 20000
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0, 0.0) == 500 assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500