Try to verify available amount on the exchange
This commit is contained in:
parent
f44e3dc319
commit
5db883906a
@ -889,6 +889,27 @@ class FreqtradeBot:
|
||||
# TODO: figure out how to handle partially complete sell orders
|
||||
return False
|
||||
|
||||
def _safe_sell_amount(self, pair: str, amount: float) -> float:
|
||||
"""
|
||||
Get sellable amount.
|
||||
Should be trade.amount - but will fall back to the available amount if necessary.
|
||||
This should cover cases where get_real_amount() was not able to update the amount
|
||||
for whatever reason.
|
||||
:param pair: pair - used for logging
|
||||
:param amount: amount we expect to be available
|
||||
:return: amount to sell
|
||||
:raise: DependencyException: if available balance is not within 2% of the available amount.
|
||||
"""
|
||||
wallet_amount = self.wallets.get_free(pair)
|
||||
logger.info(f"Amounts: {wallet_amount} - {amount}")
|
||||
if wallet_amount > amount:
|
||||
return amount
|
||||
elif wallet_amount > amount * 0.98:
|
||||
logger.info(f"{pair} - Falling back to wallet-amount.")
|
||||
return wallet_amount
|
||||
else:
|
||||
raise DependencyException("Not enough amount to sell.")
|
||||
|
||||
def execute_sell(self, trade: Trade, limit: float, sell_reason: SellType) -> None:
|
||||
"""
|
||||
Executes a limit sell for the given trade and limit
|
||||
@ -919,10 +940,12 @@ class FreqtradeBot:
|
||||
# Emergencysells (default to market!)
|
||||
ordertype = self.strategy.order_types.get("emergencysell", "market")
|
||||
|
||||
amount = self._safe_sell_amount(trade.pair, trade.amount)
|
||||
|
||||
# Execute sell and update trade record
|
||||
order = self.exchange.sell(pair=str(trade.pair),
|
||||
ordertype=ordertype,
|
||||
amount=trade.amount, rate=limit,
|
||||
amount=amount, rate=limit,
|
||||
time_in_force=self.strategy.order_time_in_force['sell']
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user