mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
Don't use config['stake_amount'] in wallets
This commit is contained in:
@@ -580,7 +580,8 @@ class FreqtradeBot(LoggingMixin):
|
||||
else:
|
||||
self.log_once(f"Pair {pair} is currently locked.", logger.info)
|
||||
return False
|
||||
stake_amount = self.wallets.get_trade_stake_amount(pair, self.edge)
|
||||
stake_amount = self.wallets.get_trade_stake_amount(
|
||||
pair, self.config['max_open_trades'], self.edge)
|
||||
|
||||
bid_check_dom = self.config.get('entry_pricing', {}).get('check_depth_of_market', {})
|
||||
if ((bid_check_dom.get('enabled', False)) and
|
||||
|
||||
@@ -798,7 +798,8 @@ class Backtesting:
|
||||
leverage = trade.leverage if trade else 1.0
|
||||
if not pos_adjust:
|
||||
try:
|
||||
stake_amount = self.wallets.get_trade_stake_amount(pair, None, update=False)
|
||||
stake_amount = self.wallets.get_trade_stake_amount(
|
||||
pair, self.strategy.max_open_trades, update=False)
|
||||
except DependencyException:
|
||||
return 0, 0, 0, 0
|
||||
|
||||
|
||||
@@ -914,7 +914,8 @@ class RPC:
|
||||
|
||||
if not stake_amount:
|
||||
# gen stake amount
|
||||
stake_amount = self._freqtrade.wallets.get_trade_stake_amount(pair)
|
||||
stake_amount = self._freqtrade.wallets.get_trade_stake_amount(
|
||||
pair, self._config['max_open_trades'])
|
||||
|
||||
# execute buy
|
||||
if not order_type:
|
||||
|
||||
@@ -6,7 +6,7 @@ from copy import deepcopy
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, NamedTuple, Optional
|
||||
|
||||
from freqtrade.constants import UNLIMITED_STAKE_AMOUNT, Config
|
||||
from freqtrade.constants import UNLIMITED_STAKE_AMOUNT, Config, IntOrInf
|
||||
from freqtrade.enums import RunMode, TradingMode
|
||||
from freqtrade.exceptions import DependencyException
|
||||
from freqtrade.exchange import Exchange
|
||||
@@ -262,15 +262,15 @@ class Wallets:
|
||||
return min(self.get_total_stake_amount() - Trade.total_open_trades_stakes(), free)
|
||||
|
||||
def _calculate_unlimited_stake_amount(self, available_amount: float,
|
||||
val_tied_up: float) -> float:
|
||||
val_tied_up: float, max_open_trades: IntOrInf) -> float:
|
||||
"""
|
||||
Calculate stake amount for "unlimited" stake amount
|
||||
:return: 0 if max number of trades reached, else stake_amount to use.
|
||||
"""
|
||||
if self._config['max_open_trades'] == 0:
|
||||
if max_open_trades == 0:
|
||||
return 0
|
||||
|
||||
possible_stake = (available_amount + val_tied_up) / self._config['max_open_trades']
|
||||
possible_stake = (available_amount + val_tied_up) / max_open_trades
|
||||
# Theoretical amount can be above available amount - therefore limit to available amount!
|
||||
return min(possible_stake, available_amount)
|
||||
|
||||
@@ -298,7 +298,8 @@ class Wallets:
|
||||
|
||||
return stake_amount
|
||||
|
||||
def get_trade_stake_amount(self, pair: str, edge=None, update: bool = True) -> float:
|
||||
def get_trade_stake_amount(
|
||||
self, pair: str, max_open_trades: IntOrInf, edge=None, update: bool = True) -> float:
|
||||
"""
|
||||
Calculate stake amount for the trade
|
||||
:return: float: Stake amount
|
||||
@@ -322,7 +323,7 @@ class Wallets:
|
||||
stake_amount = self._config['stake_amount']
|
||||
if stake_amount == UNLIMITED_STAKE_AMOUNT:
|
||||
stake_amount = self._calculate_unlimited_stake_amount(
|
||||
available_amount, val_tied_up)
|
||||
available_amount, val_tied_up, max_open_trades)
|
||||
|
||||
return self._check_available_stake_amount(stake_amount, available_amount)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user