Problem: Bot trying to use exact 100% of collateral causes InsufficientCollateral errors due to Drift's margin calculation including fees, slippage buffers, etc. Example: - Collateral: $85.55 - Bot tries: $85.55 (100%) - Margin required: $85.58 (includes fees) - Result: Insufficient by $0.03 → Rejected Drift UI works because it automatically applies safety buffer internally. Solution: When user configures 100% position size, apply 99% safety buffer to leave room for fees and slippage calculations. Code change (config/trading.ts calculateActualPositionSize): - Check if configuredSize >= 100 - Use 99% (0.99) instead of 100% (1.0) - Log warning about safety buffer application Impact: Bot can now use 'full' collateral without InsufficientCollateral errors. Position size: $85.55 × 99% = $84.69 (well within margin requirements) Math proof (from user's Drift UI): - Available: $85.55 - UI max: $1,282.57 (15x leverage) - Bot now: $84.69 × 15 = $1,270.35 (safe margin)
21 KiB
21 KiB