Fix position sizing and improve automation UI
Major fixes: - Fixed position size calculation: converts USD amount to SOL tokens properly - Fixed insufficient collateral error by using correct position sizing - Added proper TP/SL parameter passing through automation chain - Enhanced position sizing UI with balance percentage slider Position Sizing Fixes: - Convert 2 USD to SOL tokens using current price (2 ÷ 97.87 = ~0.162 SOL) - Remove incorrect 32 SOL token calculation (was 32,000,000,000 base units) - Use USD position value for perpetual futures trading correctly Take Profit & Stop Loss Improvements: - Pass TP/SL percentages from config through automation → trade → drift chain - Use actual config percentages instead of hardcoded 2:1 ratio - Enable proper risk management with user-defined TP/SL levels UI/UX Enhancements: - Remove redundant 'Risk Per Trade (%)' field that caused confusion - Remove conflicting 'Auto-Size (%)' dropdown - Keep clean balance percentage slider (10% - 100% of available balance) - Simplify position sizing to: Balance % → Position Size → Leverage → TP/SL Technical Changes: - Update Drift API position calculation from SOL tokens to USD conversion - Fix automation trade route parameter passing - Clean up AutomationConfig interface - Improve position size validation and safety margins These changes enable proper leveraged perpetual futures trading with correct position sizing, collateral usage, and automated TP/SL order placement.
This commit is contained in:
@@ -16,7 +16,6 @@ export interface AutomationConfig {
|
||||
stopLossPercent: number
|
||||
takeProfitPercent: number
|
||||
maxDailyTrades: number
|
||||
riskPercentage: number
|
||||
dexProvider: 'JUPITER' | 'DRIFT'
|
||||
}
|
||||
|
||||
@@ -571,7 +570,7 @@ export class AutomationService {
|
||||
console.log('⚠️ Failed to fetch balance, using fallback calculation')
|
||||
// Fallback to config amount
|
||||
let amount = Math.min(config.tradingAmount, 35) // Cap at $35 max
|
||||
const riskAdjustment = config.riskPercentage / 100
|
||||
const riskAdjustment = 0.02 // Default 2% risk
|
||||
return Math.max(amount * riskAdjustment, 5)
|
||||
}
|
||||
|
||||
@@ -585,7 +584,7 @@ export class AutomationService {
|
||||
}
|
||||
|
||||
// Calculate position size based on risk percentage of available balance
|
||||
const riskAmount = availableBalance * (config.riskPercentage / 100)
|
||||
const riskAmount = availableBalance * 0.02 // Default 2% risk
|
||||
|
||||
// Adjust based on confidence (reduce risk for low confidence signals)
|
||||
const confidenceMultiplier = Math.min(analysis.confidence / 100, 1)
|
||||
@@ -600,8 +599,7 @@ export class AutomationService {
|
||||
|
||||
console.log(`📊 Position sizing calculation:`)
|
||||
console.log(` - Available balance: $${availableBalance}`)
|
||||
console.log(` - Risk percentage: ${config.riskPercentage}%`)
|
||||
console.log(` - Risk amount: $${riskAmount.toFixed(2)}`)
|
||||
console.log(` - Risk amount: $${riskAmount.toFixed(2)} (2% default)`)
|
||||
console.log(` - Confidence multiplier: ${confidenceMultiplier}`)
|
||||
console.log(` - Leverage: ${Math.min(config.maxLeverage, 10)}x`)
|
||||
console.log(` - Final position size: $${amount.toFixed(2)}`)
|
||||
|
||||
Reference in New Issue
Block a user