feat: Add on-chain TP/SL order placement

- Add placeExitOrders() to create reduce-only LIMIT orders for TP1, TP2, and SL
- Orders now visible in Drift UI
- Tested with real tiny position (0 base x 5x = 0)
- All 3 exit orders placed successfully on-chain
- Position manager continues monitoring as backup
- Added test script and results documentation
This commit is contained in:
mindesbunister
2025-10-26 13:30:07 +01:00
parent 993ae64c64
commit 4cc294baef
6 changed files with 365 additions and 17 deletions

26
.env
View File

@@ -61,36 +61,36 @@ PYTH_HERMES_URL=https://hermes.pyth.network
# Position sizing
# Base position size in USD (default: 50 for safe testing)
# Example: 50 with 10x leverage = $500 notional position
MAX_POSITION_SIZE_USD=75
MAX_POSITION_SIZE_USD=10
# Leverage multiplier (1-20, default: 10)
# Higher leverage = bigger gains AND bigger losses
LEVERAGE=8
LEVERAGE=5
# Risk parameters (as percentages)
# Stop Loss: Close 100% of position when price drops this much
# Example: -1.5% on 10x = -15% account loss
STOP_LOSS_PERCENT=-2
STOP_LOSS_PERCENT=-0.9
# Take Profit 1: Close 50% of position at this profit level
# Example: +0.7% on 10x = +7% account gain
TAKE_PROFIT_1_PERCENT=1
TAKE_PROFIT_1_PERCENT=0.5
# Take Profit 1 Size: What % of position to close at TP1
# Example: 50 = close 50% of position
TAKE_PROFIT_1_SIZE_PERCENT=60
TAKE_PROFIT_1_SIZE_PERCENT=75
# Take Profit 2: Close remaining 50% at this profit level
# Example: +1.5% on 10x = +15% account gain
TAKE_PROFIT_2_PERCENT=2
TAKE_PROFIT_2_PERCENT=2.5
# Take Profit 2 Size: What % of remaining position to close at TP2
# Example: 100 = close all remaining position
TAKE_PROFIT_2_SIZE_PERCENT=40
TAKE_PROFIT_2_SIZE_PERCENT=100
# Emergency Stop: Hard stop if this level is breached
# Example: -2.0% on 10x = -20% account loss (rare but protects from flash crashes)
EMERGENCY_STOP_PERCENT=-3
EMERGENCY_STOP_PERCENT=-2
# Dynamic stop-loss adjustments
# Move SL to breakeven when profit reaches this level
@@ -105,19 +105,19 @@ PROFIT_LOCK_PERCENT=0.5
# Risk limits
# Stop trading if daily loss exceeds this amount (USD)
# Example: -150 = stop trading after losing $150 in a day
MAX_DAILY_DRAWDOWN=-100
MAX_DAILY_DRAWDOWN=-50
# Maximum number of trades allowed per hour (prevents overtrading)
MAX_TRADES_PER_HOUR=8
MAX_TRADES_PER_HOUR=20
# Minimum time between trades in seconds (cooldown period)
# Example: 600 = 10 minutes between trades
MIN_TIME_BETWEEN_TRADES=300
MIN_TIME_BETWEEN_TRADES=0
# DEX execution settings
# Maximum acceptable slippage on market orders (percentage)
# Example: 1.0 = accept up to 1% slippage
SLIPPAGE_TOLERANCE=1.5
SLIPPAGE_TOLERANCE=1
# How often to check prices (milliseconds)
# Example: 2000 = check every 2 seconds
@@ -237,7 +237,7 @@ DEBUG=drift:*,pyth:*,trading:*
# Enable dry run mode (simulate trades without executing)
# Set to 'true' for testing without real money
DRY_RUN=true
DRY_RUN=false
# API server port (default: 3000)
PORT=3000