Remvoe pointless arguments from get_trade_stake_amount

This commit is contained in:
Matthias
2021-04-21 20:01:10 +02:00
parent ba2d4d4656
commit d8c8a8d8c2
8 changed files with 28 additions and 38 deletions

View File

@@ -472,8 +472,7 @@ class FreqtradeBot(LoggingMixin):
(buy, sell) = self.strategy.get_signal(pair, self.strategy.timeframe, analyzed_df)
if buy and not sell:
stake_amount = self.wallets.get_trade_stake_amount(pair, self.get_free_open_trades(),
self.edge)
stake_amount = self.wallets.get_trade_stake_amount(pair, self.edge)
if not stake_amount:
logger.debug(f"Stake amount is 0, ignoring possible trade for {pair}.")
return False

View File

@@ -273,11 +273,9 @@ class Backtesting:
return None
def _enter_trade(self, pair: str, row: List, max_open_trades: int,
open_trade_count: int) -> Optional[LocalTrade]:
def _enter_trade(self, pair: str, row: List) -> Optional[LocalTrade]:
try:
stake_amount = self.wallets.get_trade_stake_amount(
pair, max_open_trades - open_trade_count, None)
stake_amount = self.wallets.get_trade_stake_amount(pair, None)
except DependencyException:
return None
min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, row[OPEN_IDX], -0.05)
@@ -388,7 +386,7 @@ class Backtesting:
and tmp != end_date
and row[BUY_IDX] == 1 and row[SELL_IDX] != 1
and not PairLocks.is_pair_locked(pair, row[DATE_IDX])):
trade = self._enter_trade(pair, row, max_open_trades, open_trade_count_start)
trade = self._enter_trade(pair, row)
if trade:
# TODO: hacky workaround to avoid opening > max_open_trades
# This emulates previous behaviour - not sure if this is correct

View File

@@ -603,8 +603,7 @@ class RPC:
raise RPCException(f'position for {pair} already open - id: {trade.id}')
# gen stake amount
stakeamount = self._freqtrade.wallets.get_trade_stake_amount(
pair, self._freqtrade.get_free_open_trades())
stakeamount = self._freqtrade.wallets.get_trade_stake_amount(pair)
# execute buy
if self._freqtrade.execute_buy(pair, stakeamount, price, forcebuy=True):

View File

@@ -145,13 +145,13 @@ class Wallets:
self._config['tradable_balance_ratio']) - val_tied_up
return available_amount
def _calculate_unlimited_stake_amount(self, free_open_trades: int, available_amount: float,
def _calculate_unlimited_stake_amount(self, available_amount: float,
val_tied_up: float) -> float:
"""
Calculate stake amount for "unlimited" stake amount
:return: 0 if max number of trades reached, else stake_amount to use.
"""
if not free_open_trades or self._config['max_open_trades'] == 0:
if self._config['max_open_trades'] == 0:
return 0
possible_stake = (available_amount + val_tied_up) / self._config['max_open_trades']
@@ -182,7 +182,7 @@ class Wallets:
return stake_amount
def get_trade_stake_amount(self, pair: str, free_open_trades: int, edge=None) -> float:
def get_trade_stake_amount(self, pair: str, edge=None) -> float:
"""
Calculate stake amount for the trade
:return: float: Stake amount
@@ -205,6 +205,6 @@ class Wallets:
stake_amount = self._config['stake_amount']
if stake_amount == UNLIMITED_STAKE_AMOUNT:
stake_amount = self._calculate_unlimited_stake_amount(
free_open_trades, available_amount, val_tied_up)
available_amount, val_tied_up)
return self._check_available_stake_amount(stake_amount, available_amount)