Add more debugging

master
Mark Veidemanis 8 months ago
parent 542dca8324
commit 771a944a13
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -377,28 +377,30 @@ def execute_strategy(callback, strategy, func):
within_trends = checks.within_trends(strategy, symbol, direction)
if not within_trends:
return
print("Checked trends")
type = strategy.order_settings.order_type
print("Set order type")
# Get the account's balance in the native account currency
cash_balance = strategy.account.client.get_balance()
log.debug(f"Cash balance: {cash_balance}")
print("CASH", cash_balance)
# Convert the trade size, which is currently in the account's base currency,
# to the base currency of the pair we are trading
trade_size_in_base = get_trade_size_in_base(
direction, account, strategy, cash_balance, base
)
print("TRADE SIZE IN BASE", trade_size_in_base)
# Calculate TP/SL/TSL
protection = get_tp_sl(
direction, strategy, current_price, round_to=display_precision
)
print("PROTECTION", protection)
# Create object, note that the amount is rounded to the trade precision
amount_rounded = float(round(trade_size_in_base, trade_precision))
print("AMOUNT ROUNDED", amount_rounded)
new_trade = Trade.objects.create(
user=user,
account=account,
@ -414,6 +416,7 @@ def execute_strategy(callback, strategy, func):
direction=direction,
**protection,
)
print("NEW TRADE", new_trade)
new_trade.save()
if strategy.risk_model is not None:
@ -431,6 +434,7 @@ def execute_strategy(callback, strategy, func):
# Run the crossfilter to ensure we don't trade the same pair in opposite directions
filtered = crossfilter(account, symbol, direction, func)
print("FILTERED", filtered)
# TP/SL calculation and get_trade_size_in_base are wasted here, but it's important
# to record the decision in the Trade object. We can only get it after we do those.

Loading…
Cancel
Save