Fix price extraction bug and remove debugging statements

This commit is contained in:
2023-08-26 11:05:28 +00:00
parent cd32dff779
commit e10c6f5c46
6 changed files with 10 additions and 25 deletions

View File

@@ -376,33 +376,27 @@ def execute_strategy(callback, strategy, func):
# Check if we are trading against the trend
within_trends = checks.within_trends(strategy, symbol, direction)
if not within_trends:
print("NOT WITHIN TRENDS")
return
print("IS WITHIN TRENDS")
type = strategy.order_settings.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,
@@ -418,7 +412,6 @@ def execute_strategy(callback, strategy, func):
direction=direction,
**protection,
)
print("NEW TRADE", new_trade)
new_trade.save()
if strategy.risk_model is not None:
@@ -436,7 +429,6 @@ 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.