Skip to content

Commit f8e6aaf

Browse files
cross_asset_trade for min_notional
1 parent d9c2cc8 commit f8e6aaf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Trading-Automation/trading_automation.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def patched_get_localzone():
5757
MIN_PROFIT = 0.8 # %
5858
TRAIL_STOP = 0.5 # %
5959
MAX_HOLD_TIME = 900 # seconds
60-
INVEST_AMOUNT = 10 # USD per coin
60+
INVEST_AMOUNT = 12 # USD per coin (increased to ensure min_notional compliance)
6161
TRADE_LOG_FILE = "trades_detailed.csv"
6262
YAML_SYMBOLS_FILE = "symbols.yaml"
6363
BOT_STATE_FILE = "bot_state.json"
@@ -2338,7 +2338,7 @@ def cross_asset_trade(from_asset, to_asset, amount, symbol_for_position=None):
23382338
print(f"[ERROR] Insufficient {from_asset} balance: {from_balance:.8f} < {rounded_amount:.8f} (rounded)")
23392339
return None
23402340

2341-
# ✅ STEP 2: Check minimum notional value
2341+
# ✅ STEP 2: Check minimum notional value and auto-adjust if needed
23422342
min_notional = min_notional_for(symbol)
23432343
current_price = get_latest_price(symbol)
23442344
if not current_price:
@@ -2347,8 +2347,20 @@ def cross_asset_trade(from_asset, to_asset, amount, symbol_for_position=None):
23472347

23482348
trade_value = rounded_amount * current_price
23492349
if trade_value < min_notional:
2350-
print(f"[ERROR] Trade value ${trade_value:.2f} below minimum notional ${min_notional:.2f}")
2351-
return None
2350+
print(f"[AUTO-ADJUST] Trade value ${trade_value:.2f} below minimum notional ${min_notional:.2f}")
2351+
2352+
# Calculate required amount to meet minimum notional (with 5% buffer)
2353+
required_amount = (min_notional * 1.05) / current_price
2354+
adjusted_amount = round_qty(symbol, required_amount)
2355+
2356+
# Check if we have enough balance for the adjusted amount
2357+
if balance[balance_key] >= adjusted_amount:
2358+
print(f"[AUTO-ADJUST] Increasing trade amount from {rounded_amount:.8f} to {adjusted_amount:.8f}")
2359+
rounded_amount = adjusted_amount
2360+
trade_value = rounded_amount * current_price
2361+
else:
2362+
print(f"[ERROR] Cannot meet minimum notional. Required: {adjusted_amount:.8f}, Available: {balance[balance_key]:.8f}")
2363+
return None
23522364

23532365
print(f"[CROSS-TRADE] Trade validation passed - Value: ${trade_value:.2f}, Min: ${min_notional:.2f}")
23542366

0 commit comments

Comments
 (0)