🤖 COMPLETE: Learning-Enhanced AI with HTTP Compatibility

LEARNING INTEGRATION:
- Enhanced AI analysis service feeds historical data into OpenAI prompts
- Symbol/timeframe specific learning optimization
- Pattern recognition from past trade outcomes
- Confidence adjustment based on success rates

 HTTP COMPATIBILITY SYSTEM:
- HttpUtil with automatic curl/no-curl detection
- Node.js fallback for Docker environments without curl
- Updated all automation systems to use HttpUtil
- Production-ready error handling

 AUTONOMOUS RISK MANAGEMENT:
- Enhanced risk manager with learning integration
- Simplified learners using existing AILearningData schema
- Real-time position monitoring every 30 seconds
- Smart stop-loss decisions with AI learning

 INFRASTRUCTURE:
- Database utility for shared Prisma connections
- Beach mode status display system
- Complete error handling and recovery
- Docker container compatibility tested

Historical performance flows into OpenAI prompts before every trade.
This commit is contained in:
mindesbunister
2025-07-25 13:38:24 +02:00
parent 2dd7cb2d66
commit 08f9a9b541
14 changed files with 1071 additions and 56 deletions

View File

@@ -5,8 +5,9 @@
* risk/reward setups and make smarter position management decisions.
*/
const StopLossDecisionLearner = require('./stop-loss-decision-learner');
const RiskRewardLearner = require('./risk-reward-learner');
const SimplifiedStopLossLearner = require('./simplified-stop-loss-learner');
const SimplifiedRiskRewardLearner = require('./simplified-risk-reward-learner');
const HttpUtil = require('./http-util');
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);
@@ -14,8 +15,8 @@ const execAsync = util.promisify(exec);
class EnhancedAutonomousRiskManager {
constructor() {
this.isActive = false;
this.learner = new StopLossDecisionLearner();
this.rrLearner = new RiskRewardLearner(); // NEW: Complete R/R learning
this.learner = new SimplifiedStopLossLearner();
this.rrLearner = new SimplifiedRiskRewardLearner(); // NEW: Complete R/R learning
this.emergencyThreshold = 1.0; // Will be updated by learning system
this.riskThreshold = 2.0;
this.mediumRiskThreshold = 5.0;
@@ -477,8 +478,7 @@ class EnhancedAutonomousRiskManager {
async checkPositionStatus(symbol) {
// Check if position is still active
try {
const { stdout } = await execAsync('curl -s http://localhost:9001/api/automation/position-monitor');
const data = JSON.parse(stdout);
const data = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
if (data.success && data.monitor?.hasPosition && data.monitor.position?.symbol === symbol) {
return data.monitor;
@@ -547,8 +547,7 @@ class EnhancedAutonomousRiskManager {
async getCurrentPositionStatus(symbol) {
try {
const { stdout } = await execAsync('curl -s http://localhost:9001/api/automation/position-monitor');
const data = JSON.parse(stdout);
const data = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
if (data.success && data.monitor?.hasPosition) {
return {
@@ -605,8 +604,7 @@ class EnhancedAutonomousRiskManager {
async analyzeMarketConditions(symbol) {
// Enhanced market analysis for better decision making
try {
const { stdout } = await execAsync('curl -s http://localhost:9001/api/automation/position-monitor');
const data = JSON.parse(stdout);
const data = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
if (data.success && data.monitor?.position) {
const pnl = data.monitor.position.unrealizedPnl;
@@ -653,8 +651,7 @@ class EnhancedAutonomousRiskManager {
try {
// Check current positions
const { stdout } = await execAsync('curl -s http://localhost:9001/api/automation/position-monitor');
const data = JSON.parse(stdout);
const data = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
if (data.success) {
const decision = await this.analyzePosition(data.monitor);
@@ -665,7 +662,7 @@ class EnhancedAutonomousRiskManager {
await this.assessDecisionOutcomes();
} catch (error) {
await this.log(`Error in beach mode cycle: ${error.message}`);
await this.log(`Error in beach mode: ${error.message}`);
}
// Schedule next check