Fix 'remaining' bug when handling buy timeout
This commit is contained in:
parent
7f119a28e7
commit
9aac080414
@ -787,7 +787,7 @@ class FreqtradeBot:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Check if trade is still actually open
|
# Check if trade is still actually open
|
||||||
if float(order['remaining']) == 0.0:
|
if float(order.get('remaining', 0.0)) == 0.0:
|
||||||
self.wallets.update()
|
self.wallets.update()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -813,7 +813,8 @@ class FreqtradeBot:
|
|||||||
})
|
})
|
||||||
|
|
||||||
def handle_timedout_limit_buy(self, trade: Trade, order: Dict) -> bool:
|
def handle_timedout_limit_buy(self, trade: Trade, order: Dict) -> bool:
|
||||||
"""Buy timeout - cancel order
|
"""
|
||||||
|
Buy timeout - cancel order
|
||||||
:return: True if order was fully cancelled
|
:return: True if order was fully cancelled
|
||||||
"""
|
"""
|
||||||
reason = "cancelled due to timeout"
|
reason = "cancelled due to timeout"
|
||||||
@ -824,18 +825,21 @@ class FreqtradeBot:
|
|||||||
corder = order
|
corder = order
|
||||||
reason = "canceled on Exchange"
|
reason = "canceled on Exchange"
|
||||||
|
|
||||||
if corder['remaining'] == corder['amount']:
|
if corder.get('remaining', order['remaining']) == order['amount']:
|
||||||
# if trade is not partially completed, just delete the trade
|
# if trade is not partially completed, just delete the trade
|
||||||
self.handle_buy_order_full_cancel(trade, reason)
|
self.handle_buy_order_full_cancel(trade, reason)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# if trade is partially complete, edit the stake details for the trade
|
# if trade is partially complete, edit the stake details for the trade
|
||||||
# and close the order
|
# and close the order
|
||||||
trade.amount = corder['amount'] - corder['remaining']
|
# cancel_order may not contain the full order dict, so we need to fallback
|
||||||
|
# to the order dict aquired before cancelling.
|
||||||
|
# we need to fall back to the values from order if corder does not contain these keys.
|
||||||
|
trade.amount = order['amount'] - corder.get('remaining', order['remaining'])
|
||||||
trade.stake_amount = trade.amount * trade.open_rate
|
trade.stake_amount = trade.amount * trade.open_rate
|
||||||
# verify if fees were taken from amount to avoid problems during selling
|
# verify if fees were taken from amount to avoid problems during selling
|
||||||
try:
|
try:
|
||||||
new_amount = self.get_real_amount(trade, corder, trade.amount)
|
new_amount = self.get_real_amount(trade, order, trade.amount)
|
||||||
if not isclose(order['amount'], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
if not isclose(order['amount'], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
|
||||||
trade.amount = new_amount
|
trade.amount = new_amount
|
||||||
# Fee was applied, so set to 0
|
# Fee was applied, so set to 0
|
||||||
|
Loading…
Reference in New Issue
Block a user