feat: implement strategy-aware analysis intervals and remove manual leverage controls

- Remove manual leverage field from automation v2 page since AI now handles leverage automatically
- Fix scalping strategy analysis intervals from 60 minutes to 2 minutes for proper high-frequency trading
- Implement intelligent interval detection based on selected timeframes:
  * Scalping: 2 minutes (5m, 3m, or multiple short timeframes)
  * Day trading: 5 minutes (1h, 2h timeframes)
  * Swing trading: 15 minutes (4h, daily timeframes)
- Fix Drift SDK API calls: replace getTotalPerpPositionValue() with getFreeCollateral()
- Clean up UI by removing manual controls since AI systems handle optimization
- Fix syntax errors in automation service and balance API
- Ensure proper margin calculations using correct Drift Protocol methods

Tested: Scalping strategy now correctly analyzes every 2 minutes instead of 60 minutes
This commit is contained in:
mindesbunister
2025-07-24 13:25:41 +02:00
parent 29d0516a07
commit 451a8248d8
4 changed files with 62 additions and 31 deletions

View File

@@ -21,7 +21,6 @@ export default function AutomationPageV2() {
selectedTimeframes: ['60'], // Multi-timeframe support
tradingAmount: 100,
balancePercentage: 50, // Default to 50% of available balance
maxLeverage: 5
// stopLossPercent and takeProfitPercent removed - AI calculates these automatically
})
@@ -268,22 +267,6 @@ export default function AutomationPageV2() {
</div>
</div>
<div className="space-y-3">
<label className="block text-sm font-bold text-purple-400">Leverage</label>
<select
className="w-full p-3 bg-gray-700 border border-gray-600 rounded-lg text-white focus:border-purple-400"
value={config.maxLeverage}
onChange={(e) => setConfig({...config, maxLeverage: parseInt(e.target.value)})}
disabled={status?.isActive}
>
<option value="1">1x - Spot</option>
<option value="2">2x</option>
<option value="3">3x</option>
<option value="5">5x</option>
<option value="10">10x</option>
<option value="20">20x</option>
</select>
</div>
</div>
{/* Symbol and Position Size */}
@@ -336,11 +319,6 @@ export default function AutomationPageV2() {
<span>50%</span>
<span>100%</span>
</div>
{balance && config.maxLeverage > 1 && (
<p className="text-xs text-green-400 mt-1">
With {config.maxLeverage}x leverage: ${(config.tradingAmount * config.maxLeverage).toFixed(2)} position exposure
</p>
)}
</div>
</div>
@@ -524,10 +502,6 @@ export default function AutomationPageV2() {
{config.selectedTimeframes.map(tf => timeframes.find(t => t.value === tf)?.label).filter(Boolean).join(', ')}
</span>
</div>
<div className="flex justify-between">
<span className="text-gray-300">Leverage:</span>
<span className="text-yellow-400 font-semibold">{config.maxLeverage}x</span>
</div>
</div>
) : (
<p className="text-gray-400">Loading bot status...</p>
@@ -653,7 +627,33 @@ export default function AutomationPageV2() {
></div>
</div>
<div className="text-xs text-gray-400 text-center">
Analysis Interval: {Math.floor((status.analysisInterval || 0) / 60)}m
Analysis Interval: {(() => {
const intervalSec = status.analysisInterval || 0
const intervalMin = Math.floor(intervalSec / 60)
// Determine strategy type for display
if (status.selectedTimeframes) {
const timeframes = status.selectedTimeframes
const isScalping = timeframes.includes('5') || timeframes.includes('3') ||
(timeframes.length > 1 && timeframes.every(tf => ['1', '3', '5', '15', '30'].includes(tf)))
if (isScalping) {
return '2m (Scalping Mode)'
}
const isDayTrading = timeframes.includes('60') || timeframes.includes('120')
if (isDayTrading) {
return '5m (Day Trading Mode)'
}
const isSwingTrading = timeframes.includes('240') || timeframes.includes('D')
if (isSwingTrading) {
return '15m (Swing Trading Mode)'
}
}
return `${intervalMin}m`
})()}
</div>
</div>
</div>