feat: implement 24/7 server-side automation with AI learning integration
Core Features: - True 24/7 automation runs without browser dependency - Server-side process in Docker container - Auto-executes paper trades with ≥60% confidence - Integrates with existing AI learning system - Safe paper trading mode only (zero real money risk) - working-24x7.js: Main automation process (currently running) - check-automation.js: Status monitoring and health checks - app/api/safe-paper-trading/create-trade/route.js: Paper trade API - app/api/automation-24x7/route.js: Automation control API - Fixed continuous learning state persistence issues - Added force enable function for debugging: window.forceEnableLearning() - Enhanced state restoration logic with immediate and delayed checks - Auto-execute toggle now properly unlocks when continuous learning active - System running successfully (PID: 3922502) - Already executed first automated paper trade (80% confidence SELL) - Scheduled to run every 60 minutes automatically - Logs all activity for monitoring and debugging ical Implementation: - Uses curl for HTTP requests (no fetch dependencies) - Background process with proper signal handling - Comprehensive error handling and logging - Integration with existing analysis pipeline - Maintains compatibility with browser-based safe paper trading This completes the 24/7 automation requirement - system now runs continuously in Docker container without requiring browser tabs to remain open.
This commit is contained in:
76
app/api/automation-24x7/route.js
Normal file
76
app/api/automation-24x7/route.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
// Import the 24/7 automation service
|
||||
let automation24x7
|
||||
try {
|
||||
const automationModule = require('../../../../start-24-7-automation.js')
|
||||
automation24x7 = automationModule.automation24x7
|
||||
} catch (error) {
|
||||
console.error('❌ Could not load 24/7 automation service:', error.message)
|
||||
}
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
if (!automation24x7) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '24/7 automation service not available'
|
||||
}, { status: 500 })
|
||||
}
|
||||
|
||||
const { action, config } = await request.json()
|
||||
|
||||
if (action === 'start') {
|
||||
// Update config if provided
|
||||
if (config) {
|
||||
Object.assign(automation24x7.config, config)
|
||||
}
|
||||
|
||||
const result = await automation24x7.start()
|
||||
return NextResponse.json(result)
|
||||
|
||||
} else if (action === 'stop') {
|
||||
const result = await automation24x7.stop()
|
||||
return NextResponse.json(result)
|
||||
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: 'Invalid action. Use "start" or "stop"'
|
||||
}, { status: 400 })
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 24/7 automation control error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: 'Failed to control automation',
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request) {
|
||||
try {
|
||||
if (!automation24x7) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '24/7 automation service not available'
|
||||
}, { status: 500 })
|
||||
}
|
||||
|
||||
const status = automation24x7.getStatus()
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
automation: status
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 24/7 automation status error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: 'Failed to get automation status',
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user