Ause isclose for comparison, assign filled to variable

add some comments
This commit is contained in:
Matthias
2020-05-07 06:51:02 +02:00
parent d3a0ab8096
commit 1ba2df79c6
2 changed files with 8 additions and 3 deletions

View File

@@ -898,6 +898,7 @@ class FreqtradeBot:
Buy timeout - cancel order
:return: True if order was fully cancelled
"""
# Cancelled orders may have the status of 'canceled' or 'closed'
if order['status'] not in ('canceled', 'closed'):
reason = "cancelled due to timeout"
corder = self.exchange.cancel_order_with_result(trade.open_order_id, trade.pair,
@@ -909,7 +910,10 @@ class FreqtradeBot:
logger.info('Buy order %s for %s.', reason, trade)
if safe_value_fallback(corder, order, 'filled', 'filled') == 0.0:
# Using filled to determine the filled amount
filled_amount = safe_value_fallback(corder, order, 'filled', 'filled')
if isclose(filled_amount, 0.0, abs_tol=constants.MATH_CLOSE_PREC):
logger.info('Buy order fully cancelled. Removing %s from database.', trade)
# if trade is not partially completed, just delete the trade
Trade.session.delete(trade)
@@ -921,7 +925,7 @@ class FreqtradeBot:
# 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 = safe_value_fallback(corder, order, 'filled', 'filled')
trade.amount = filled_amount
trade.stake_amount = trade.amount * trade.open_rate
self.update_trade_state(trade, corder, trade.amount)