🤖 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

@@ -7,19 +7,22 @@
* the AI's risk/reward settings and position management decisions.
*/
const { PrismaClient } = require('@prisma/client');
const { getDB } = require('./db');
class RiskRewardLearner {
constructor() {
this.prisma = new PrismaClient();
this.learningHistory = [];
this.riskRewardPatterns = {
stopLossPatterns: [],
takeProfitPatterns: [],
optimalRatios: []
this.setupHistory = [];
this.patterns = {
optimal_rr_ratios: {},
market_condition_adjustments: {},
symbol_specific_patterns: {}
};
}
async getPrisma() {
return await getDB();
}
async log(message) {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] 🎯 RR Learner: ${message}`);
@@ -63,7 +66,8 @@ class RiskRewardLearner {
};
// Store in database
await this.prisma.riskRewardSetup.create({
const prisma = await this.getPrisma();
await prisma.riskRewardSetup.create({
data: {
id: setup.id,
tradeId: setup.tradeId,
@@ -106,7 +110,9 @@ class RiskRewardLearner {
const outcomeAnalysis = this.analyzeOutcomeQuality(outcomeData);
// Update setup record with outcome
await this.prisma.riskRewardSetup.update({
// Update setup in database
const prisma = await this.getPrisma();
await prisma.riskRewardSetup.update({
where: { id: setupId },
data: {
exitPrice,
@@ -223,7 +229,8 @@ class RiskRewardLearner {
*/
async updateRiskRewardLearning() {
try {
const recentSetups = await this.prisma.riskRewardSetup.findMany({
const prisma = await this.getPrisma();
const recentSetups = await prisma.riskRewardSetup.findMany({
where: { status: 'COMPLETED' },
orderBy: { setupTimestamp: 'desc' },
take: 100