Don't return None from unlimited_stake - 0 handles this just as well

This commit is contained in:
Matthias 2020-01-05 12:50:44 +01:00
parent 7e7c82cf4a
commit 7daa5bc338
2 changed files with 11 additions and 10 deletions

View File

@ -250,12 +250,13 @@ class FreqtradeBot:
return used_rate
def get_trade_stake_amount(self, pair) -> Optional[float]:
def get_trade_stake_amount(self, pair) -> float:
"""
Calculate stake amount for the trade
:return: float: Stake amount
:raise: DependencyException if the available stake amount is too low
"""
stake_amount: Optional[float]
stake_amount: float
if self.edge:
stake_amount = self.edge.stake_amount(
pair,
@ -286,20 +287,20 @@ class FreqtradeBot:
self.config['tradable_balance_ratio']) - val_tied_up
return available_amount
def _calculate_unlimited_stake_amount(self) -> Optional[float]:
def _calculate_unlimited_stake_amount(self) -> float:
"""
Calculate stake amount for "unlimited" stake amount
:return: None if max number of trades reached
:return: 0 if max number of trades reached, else stake_amount to use.
"""
free_open_trades = self.get_free_open_trades()
if not free_open_trades:
return None
return 0
available_amount = self._get_available_stake_amount()
return available_amount / free_open_trades
def _check_available_stake_amount(self, stake_amount: Optional[float]) -> Optional[float]:
def _check_available_stake_amount(self, stake_amount: float) -> float:
"""
Check if stake amount can be fulfilled with the available balance
for the stake currency
@ -307,7 +308,7 @@ class FreqtradeBot:
"""
available_amount = self._get_available_stake_amount()
if stake_amount is not None and available_amount < stake_amount:
if available_amount < stake_amount:
raise DependencyException(
f"Available balance ({available_amount} {self.config['stake_currency']}) is "
f"lower than stake amount ({stake_amount} {self.config['stake_currency']})"

View File

@ -189,13 +189,13 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
freqtrade.execute_buy('LTC/BTC', result)
result = freqtrade.get_trade_stake_amount('XRP/BTC')
assert result is None
assert result == 0
# set max_open_trades = None, so do not trade
conf['max_open_trades'] = 0
freqtrade = FreqtradeBot(conf)
result = freqtrade.get_trade_stake_amount('NEO/BTC')
assert result is None
assert result == 0
def test_edge_called_in_process(mocker, edge_conf) -> None:
@ -576,7 +576,7 @@ def test_create_trade_limit_reached(default_conf, ticker, limit_buy_order,
patch_get_signal(freqtrade)
assert not freqtrade.create_trade('ETH/BTC')
assert freqtrade.get_trade_stake_amount('ETH/BTC') is None
assert freqtrade.get_trade_stake_amount('ETH/BTC') == 0
def test_enter_positions_no_pairs_left(default_conf, ticker, limit_buy_order, fee,