feat: add quality score display and timezone fixes

- Add qualityScore to ExecuteTradeResponse interface and response object
- Update analytics page to always show Signal Quality card (N/A if unavailable)
- Fix n8n workflow to pass context metrics and qualityScore to execute endpoint
- Fix timezone in Telegram notifications (Europe/Berlin)
- Fix symbol normalization in /api/trading/close endpoint
- Update Drift ETH-PERP minimum order size (0.002 ETH not 0.01)
- Add transaction confirmation to closePosition() to prevent phantom closes
- Add 30-second grace period for new trades in Position Manager
- Fix execution order: database save before Position Manager.addTrade()
- Update copilot instructions with transaction confirmation pattern
This commit is contained in:
mindesbunister
2025-11-01 17:00:37 +01:00
parent 7788327a4e
commit 056440bf8f
9 changed files with 110 additions and 49 deletions

View File

@@ -7,12 +7,13 @@
import { NextRequest, NextResponse } from 'next/server'
import { closePosition } from '@/lib/drift/orders'
import { initializeDriftService } from '@/lib/drift/client'
import { normalizeTradingViewSymbol } from '@/config/trading'
export const dynamic = 'force-dynamic'
export const runtime = 'nodejs'
interface CloseRequest {
symbol: string // e.g., 'SOL-PERP'
symbol: string // e.g., 'SOL-PERP' or 'SOLUSDT'
percentToClose?: number // 0-100, default 100 (close entire position)
}
@@ -46,14 +47,16 @@ export async function POST(request: NextRequest) {
)
}
console.log(`📊 Closing position: ${symbol} (${percentToClose}%)`)
// Normalize symbol (SOLUSDT -> SOL-PERP)
const driftSymbol = normalizeTradingViewSymbol(symbol)
console.log(`📊 Closing position: ${driftSymbol} (${percentToClose}%)`)
// Initialize Drift service if not already initialized
await initializeDriftService()
// Close position
const result = await closePosition({
symbol,
symbol: driftSymbol,
percentToClose,
slippageTolerance: 1.0,
})
@@ -72,7 +75,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({
success: true,
transactionSignature: result.transactionSignature,
symbol,
symbol: driftSymbol,
closePrice: result.closePrice,
closedSize: result.closedSize,
realizedPnL: result.realizedPnL,