Extract amount checking to wallets, implement for futures
This commit is contained in:
@@ -1063,14 +1063,11 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
"""
|
"""
|
||||||
trades_closed = 0
|
trades_closed = 0
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
# TODO: get_total currently fails for futures!
|
|
||||||
wallet_amount = self.wallets.get_total(trade.safe_base_currency)
|
|
||||||
|
|
||||||
if wallet_amount < trade.amount:
|
if not self.wallets.check_exit_amount(trade):
|
||||||
#
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f'Not enough {trade.safe_base_currency} in wallet to exit {trade.pair}. '
|
f'Not enough {trade.safe_base_currency} in wallet to exit {trade}. '
|
||||||
f'Amount needed: {trade.amount}, amount available: {wallet_amount}')
|
'Trying to recover.')
|
||||||
self.handle_onexchange_order(trade)
|
self.handle_onexchange_order(trade)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -181,6 +181,35 @@ class Wallets:
|
|||||||
def get_all_positions(self) -> Dict[str, PositionWallet]:
|
def get_all_positions(self) -> Dict[str, PositionWallet]:
|
||||||
return self._positions
|
return self._positions
|
||||||
|
|
||||||
|
def _check_exit_amount(self, trade: Trade) -> bool:
|
||||||
|
if trade.trading_mode != TradingMode.FUTURES:
|
||||||
|
# Slightly higher offset than in safe_exit_amount.
|
||||||
|
wallet_amount: float = self.get_total(trade.safe_base_currency) * 0.981
|
||||||
|
else:
|
||||||
|
# wallet_amount: float = self.wallets.get_free(trade.safe_base_currency)
|
||||||
|
position = self._positions.get(trade.pair)
|
||||||
|
if position is None:
|
||||||
|
# We don't own anything :O
|
||||||
|
return False
|
||||||
|
wallet_amount = position.position
|
||||||
|
|
||||||
|
if wallet_amount >= trade.amount:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_exit_amount(self, trade: Trade) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if the exit amount is available in the wallet.
|
||||||
|
:param trade: Trade to check
|
||||||
|
:return: True if the exit amount is available, False otherwise
|
||||||
|
"""
|
||||||
|
if not self._check_exit_amount(trade):
|
||||||
|
# Update wallets just to make sure
|
||||||
|
self.update()
|
||||||
|
return self._check_exit_amount(trade)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def get_starting_balance(self) -> float:
|
def get_starting_balance(self) -> float:
|
||||||
"""
|
"""
|
||||||
Retrieves starting balance - based on either available capital,
|
Retrieves starting balance - based on either available capital,
|
||||||
|
|||||||
Reference in New Issue
Block a user