Add more debugging

This commit is contained in:
Mark Veidemanis 2023-08-24 17:50:55 +00:00
parent 542dca8324
commit 771a944a13
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 6 additions and 2 deletions

View File

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