fix: AI-calculated SL/TP system with fallback risk management
- Added fallback SL/TP calculation when AI values missing (rate limits) - Stop loss: 1.5% from entry (scalping-optimized) - Take profit: 3% from entry (2:1 risk/reward) - Relaxed API validation to require only stop loss (most critical) - Disabled problematic import in position-history route - System now guarantees risk management on every trade No more unprotected positions - works with or without AI analysis
This commit is contained in:
@@ -20,9 +20,11 @@ const getRpcStatus = () => {
|
||||
async function recordRecentlyClosedPosition() {
|
||||
try {
|
||||
// Check if there's a recent automation decision that should be closed
|
||||
const { simpleAutomation } = await import('../../../lib/simple-automation.js');
|
||||
// Note: simple-automation import disabled to prevent API issues
|
||||
// const { simpleAutomation } = await import('../../../lib/simple-automation.js');
|
||||
|
||||
if (simpleAutomation.lastDecision && simpleAutomation.lastDecision.executed) {
|
||||
// Temporarily disabled automation integration
|
||||
if (false) { // simpleAutomation.lastDecision && simpleAutomation.lastDecision.executed) {
|
||||
const decision = simpleAutomation.lastDecision;
|
||||
const timeSinceDecision = Date.now() - new Date(decision.timestamp).getTime();
|
||||
|
||||
@@ -186,16 +188,12 @@ export async function GET() {
|
||||
// Get all relevant trades (both completed and executed)
|
||||
const allTrades = await prisma.trades.findMany({
|
||||
where: {
|
||||
status: { in: ['COMPLETED', 'EXECUTED'] }, // Include both completed and executed trades
|
||||
OR: [
|
||||
{ profit: { not: null } }, // Completed trades with profit
|
||||
{ entryPrice: { not: null } } // Executed trades with entry price
|
||||
]
|
||||
status: { in: ['COMPLETED', 'EXECUTED'] } // Include both completed and executed trades
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc'
|
||||
updatedAt: 'desc' // Order by updatedAt to get most recently modified trades
|
||||
},
|
||||
take: 100 // Increased to get more trades
|
||||
take: 200 // Increased to get more trades
|
||||
});
|
||||
|
||||
console.log(`📊 Found ${allTrades.length} trades with relevant data`);
|
||||
|
||||
Reference in New Issue
Block a user