Add more user feedback on rejected and dropped trades

Mark Veidemanis 1 year ago
parent a96c99b9e4
commit b7c46ba1d3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -459,17 +459,20 @@ def execute_strategy(callback, strategy, func):
# Don't be silly
if callback.exchange != account.exchange:
log.error("Market exchange differs from account exchange.")
sendmsg(user, "Market exchange differs from account exchange.", title="Error")
return
# Get the pair we are trading
symbol = get_pair(account, base, quote)
if not symbol:
sendmsg(user, f"Symbol not supported by account: {symbol}", title="Error")
log.error(f"Symbol not supported by account: {symbol}")
return
# Extract the information for the symbol
instrument = strategy.account.client.extract_instrument(instruments, symbol)
if not instrument:
sendmsg(user, f"Symbol not found: {symbol}", title="Error")
log.error(f"Symbol not found: {symbol}")
return
@ -478,6 +481,7 @@ def execute_strategy(callback, strategy, func):
trade_precision = instrument["tradeUnitsPrecision"]
display_precision = instrument["displayPrecision"]
except KeyError:
sendmsg(user, f"Precision not found for {symbol}", title="Error")
log.error(f"Precision not found for {symbol}")
return
@ -508,6 +512,11 @@ def execute_strategy(callback, strategy, func):
side = check_exit["side"]
response = account.client.close_position(side, symbol)
log.debug(f"Close position response: {response}")
sendmsg(
user,
f"Closing {side} position on exit signal: {symbol}",
title="Exit signal",
)
return
# Set the trend
@ -523,13 +532,28 @@ def execute_strategy(callback, strategy, func):
if strategy.trend_signals.exists():
if strategy.trends is None:
log.debug("Refusing to trade with no trend signals received")
sendmsg(
user,
f"Refusing to trade {symbol} with no trend signals received",
title="Trend not ready",
)
return
if symbol not in strategy.trends:
log.debug("Refusing to trade asset without established trend")
sendmsg(
user,
f"Refusing to trade {symbol} without established trend",
title="Trend not ready",
)
return
else:
if strategy.trends[symbol] != direction:
log.debug("Refusing to trade against the trend")
sendmsg(
user,
f"Refusing to trade {symbol} against the trend",
title="Trend rejection",
)
return
else:
log.debug(f"Trend check passed for {symbol} - {direction}")
@ -590,6 +614,14 @@ def execute_strategy(callback, strategy, func):
if filtered["action"] == "rejected":
new_trade.status = "rejected"
new_trade.save()
sendmsg(
user,
(
f"{direction} on {symbol} rejected due to conflicting position: "
f"{filtered['positions']}"
),
title="Trade rejected",
)
else:
info = new_trade.post()
log.debug(f"Posted trade: {info}")

Loading…
Cancel
Save