🤖 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:
46
lib/db.js
Normal file
46
lib/db.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Database utility for Prisma client
|
||||
*
|
||||
* Provides a global Prisma instance to avoid connection issues
|
||||
*/
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
|
||||
// Global Prisma instance
|
||||
let prisma = null;
|
||||
|
||||
/**
|
||||
* Get the global Prisma database instance
|
||||
*/
|
||||
async function getDB() {
|
||||
if (!prisma) {
|
||||
prisma = new PrismaClient();
|
||||
|
||||
// Test the connection
|
||||
try {
|
||||
await prisma.$connect();
|
||||
console.log('✅ Database connection established');
|
||||
} catch (error) {
|
||||
console.error('❌ Database connection failed:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return prisma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the database connection
|
||||
*/
|
||||
async function closeDB() {
|
||||
if (prisma) {
|
||||
await prisma.$disconnect();
|
||||
prisma = null;
|
||||
console.log('✅ Database connection closed');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDB,
|
||||
closeDB
|
||||
};
|
||||
Reference in New Issue
Block a user