Fix #3130 - when corder['remaining'] contains none-type
This commit is contained in:
parent
cbf5bf6735
commit
f39706cabd
@ -20,6 +20,7 @@ from freqtrade.data.dataprovider import DataProvider
|
|||||||
from freqtrade.edge import Edge
|
from freqtrade.edge import Edge
|
||||||
from freqtrade.exceptions import DependencyException, InvalidOrderException
|
from freqtrade.exceptions import DependencyException, InvalidOrderException
|
||||||
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_next_date
|
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_next_date
|
||||||
|
from freqtrade.misc import safe_value_fallback
|
||||||
from freqtrade.pairlist.pairlistmanager import PairListManager
|
from freqtrade.pairlist.pairlistmanager import PairListManager
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
||||||
@ -892,18 +893,23 @@ class FreqtradeBot:
|
|||||||
"""
|
"""
|
||||||
if order['status'] != 'canceled':
|
if order['status'] != 'canceled':
|
||||||
reason = "cancelled due to timeout"
|
reason = "cancelled due to timeout"
|
||||||
|
try:
|
||||||
corder = self.exchange.cancel_order(trade.open_order_id, trade.pair)
|
corder = self.exchange.cancel_order(trade.open_order_id, trade.pair)
|
||||||
# Some exchanges don't return a dict here.
|
# Some exchanges don't return a dict here.
|
||||||
if not isinstance(corder, dict):
|
if not isinstance(corder, dict):
|
||||||
corder = {}
|
corder = {}
|
||||||
logger.info('Buy order %s for %s.', reason, trade)
|
logger.info('Buy order %s for %s.', reason, trade)
|
||||||
|
except InvalidOrderException:
|
||||||
|
corder = {}
|
||||||
|
logger.exception(
|
||||||
|
f"Could not cancel buy order {trade.open_order_id} for pair {trade.pair}")
|
||||||
else:
|
else:
|
||||||
# Order was cancelled already, so we can reuse the existing dict
|
# Order was cancelled already, so we can reuse the existing dict
|
||||||
corder = order
|
corder = order
|
||||||
reason = "cancelled on exchange"
|
reason = "cancelled on exchange"
|
||||||
logger.info('Buy order %s for %s.', reason, trade)
|
logger.info('Buy order %s for %s.', reason, trade)
|
||||||
|
|
||||||
if corder.get('remaining', order['remaining']) == order['amount']:
|
if safe_value_fallback(corder, order, 'remaining', 'remaining') == order['amount']:
|
||||||
logger.info('Buy order removed from database %s', trade)
|
logger.info('Buy order removed from database %s', trade)
|
||||||
# if trade is not partially completed, just delete the trade
|
# if trade is not partially completed, just delete the trade
|
||||||
Trade.session.delete(trade)
|
Trade.session.delete(trade)
|
||||||
@ -915,7 +921,8 @@ class FreqtradeBot:
|
|||||||
# cancel_order may not contain the full order dict, so we need to fallback
|
# cancel_order may not contain the full order dict, so we need to fallback
|
||||||
# to the order dict aquired before cancelling.
|
# to the order dict aquired before cancelling.
|
||||||
# we need to fall back to the values from order if corder does not contain these keys.
|
# 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.amount = order['amount'] - safe_value_fallback(corder, order,
|
||||||
|
'remaining', '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:
|
||||||
|
Loading…
Reference in New Issue
Block a user