feat: Add customizable TP size percentages and fix settings save

**New Features:**
- Added TAKE_PROFIT_1_SIZE_PERCENT (default: 50%)
- Added TAKE_PROFIT_2_SIZE_PERCENT (default: 50%)
- Users can now control WHAT % to close at each TP level
- Risk calculator now shows actual TP sizes dynamically

**Bug Fixes:**
- Fixed settings save failure by mounting .env file to container
- Added .env volume mount in docker-compose.yml
- Fixed permission issues (.env must be chmod 666)

**UI Changes:**
- Split TP controls into Price % and Size %
- TP1 Price: When to exit first partial
- TP1 Size: What % of position to close (1-100%)
- TP2 Price: When to exit second partial
- TP2 Size: What % of remaining to close (1-100%)
- Risk calculator displays dynamic percentages

**Example:**
- TP1 at +1% price, close 60% of position
- TP2 at +2% price, close 40% of remaining (24% of original)
- Total exit: 84% of position at TP levels
This commit is contained in:
mindesbunister
2025-10-24 15:35:36 +02:00
parent 285737488b
commit 1c4cc5d1fb
4 changed files with 61 additions and 25 deletions

36
.env
View File

@@ -61,55 +61,63 @@ 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=50
MAX_POSITION_SIZE_USD=75
# Leverage multiplier (1-20, default: 10)
# Higher leverage = bigger gains AND bigger losses
LEVERAGE=5
LEVERAGE=8
# 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=-1.5
STOP_LOSS_PERCENT=-2
# Take Profit 1: Close 50% of position at this profit level
# Example: +0.7% on 10x = +7% account gain
TAKE_PROFIT_1_PERCENT=0.7
TAKE_PROFIT_1_PERCENT=1
# 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 2: Close remaining 50% at this profit level
# Example: +1.5% on 10x = +15% account gain
TAKE_PROFIT_2_PERCENT=1.5
TAKE_PROFIT_2_PERCENT=2
# Take Profit 2 Size: What % of remaining position to close at TP2
# Example: 100 = close all remaining position
TAKE_PROFIT_2_SIZE_PERCENT=40
# 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=-2.0
EMERGENCY_STOP_PERCENT=-3
# Dynamic stop-loss adjustments
# Move SL to breakeven when profit reaches this level
BREAKEVEN_TRIGGER_PERCENT=0.4
BREAKEVEN_TRIGGER_PERCENT=0.5
# Lock in profit when price reaches this level
PROFIT_LOCK_TRIGGER_PERCENT=1.0
PROFIT_LOCK_TRIGGER_PERCENT=1.2
# How much profit to lock (move SL to this profit level)
PROFIT_LOCK_PERCENT=0.4
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=-50
MAX_DAILY_DRAWDOWN=-100
# Maximum number of trades allowed per hour (prevents overtrading)
MAX_TRADES_PER_HOUR=6
MAX_TRADES_PER_HOUR=8
# Minimum time between trades in seconds (cooldown period)
# Example: 600 = 10 minutes between trades
MIN_TIME_BETWEEN_TRADES=600
MIN_TIME_BETWEEN_TRADES=300
# DEX execution settings
# Maximum acceptable slippage on market orders (percentage)
# Example: 1.0 = accept up to 1% slippage
SLIPPAGE_TOLERANCE=1.0
SLIPPAGE_TOLERANCE=1.5
# How often to check prices (milliseconds)
# Example: 2000 = check every 2 seconds
@@ -229,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=false
DRY_RUN=true
# API server port (default: 3000)
PORT=3000