Update exit message handling to gracefully handle kucoins "empty" responses

closes #7444
This commit is contained in:
Matthias 2022-09-20 20:00:08 +02:00
parent 0c01b23cba
commit 3b0874eb37
2 changed files with 13 additions and 11 deletions

View File

@ -1597,14 +1597,14 @@ class FreqtradeBot(LoggingMixin):
# second condition is for mypy only; order will always be passed during sub trade
if sub_trade and order is not None:
amount = order.safe_filled if fill else order.amount
profit_rate = order.safe_price
order_rate: float = order.safe_price
profit = trade.calc_profit(rate=profit_rate, amount=amount, open_rate=trade.open_rate)
profit_ratio = trade.calc_profit_ratio(profit_rate, amount, trade.open_rate)
profit = trade.calc_profit(rate=order_rate, amount=amount, open_rate=trade.open_rate)
profit_ratio = trade.calc_profit_ratio(order_rate, amount, trade.open_rate)
else:
profit_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested
profit = trade.calc_profit(rate=profit_rate) + (0.0 if fill else trade.realized_profit)
profit_ratio = trade.calc_profit_ratio(profit_rate)
order_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested
profit = trade.calc_profit(rate=order_rate) + (0.0 if fill else trade.realized_profit)
profit_ratio = trade.calc_profit_ratio(order_rate)
amount = trade.amount
gain = "profit" if profit_ratio > 0 else "loss"
@ -1617,11 +1617,12 @@ class FreqtradeBot(LoggingMixin):
'leverage': trade.leverage,
'direction': 'Short' if trade.is_short else 'Long',
'gain': gain,
'limit': profit_rate,
'limit': order_rate, # Deprecated
'order_rate': order_rate,
'order_type': order_type,
'amount': amount,
'open_rate': trade.open_rate,
'close_rate': profit_rate,
'close_rate': order_rate,
'current_rate': current_rate,
'profit_amount': profit,
'profit_ratio': profit_ratio,

View File

@ -286,7 +286,7 @@ class Telegram(RPCHandler):
if msg['type'] in [RPCMessageType.ENTRY_FILL]:
message += f"*Open Rate:* `{msg['open_rate']:.8f}`\n"
elif msg['type'] in [RPCMessageType.ENTRY]:
message += f"*Open Rate:* `{msg['limit']:.8f}`\n"\
message += f"*Open Rate:* `{msg['open_rate']:.8f}`\n"\
f"*Current Rate:* `{msg['current_rate']:.8f}`\n"
message += f"*Total:* `({round_coin_value(msg['stake_amount'], msg['stake_currency'])}"
@ -353,8 +353,9 @@ class Telegram(RPCHandler):
f"*Open Rate:* `{msg['open_rate']:.8f}`\n"
)
if msg['type'] == RPCMessageType.EXIT:
message += (f"*Current Rate:* `{msg['current_rate']:.8f}`\n"
f"*Exit Rate:* `{msg['limit']:.8f}`")
message += f"*Current Rate:* `{msg['current_rate']:.8f}`\n"
if msg['order_rate']:
message += f"*Exit Rate:* `{msg['order_rate']:.8f}`"
elif msg['type'] == RPCMessageType.EXIT_FILL:
message += f"*Exit Rate:* `{msg['close_rate']:.8f}`"