Fix database persistence and add analytics
- Fixed Prisma client not being available in Docker container - Added isTestTrade flag to exclude test trades from analytics - Created analytics views for net positions (matches Drift UI netting) - Added API endpoints: /api/analytics/positions and /api/analytics/stats - Added test trade endpoint: /api/trading/test-db - Updated Dockerfile to properly copy Prisma client from builder stage - Database now successfully stores all trades with full details - Supports position netting calculations to match Drift perpetuals behavior
This commit is contained in:
32
app/api/analytics/stats/route.ts
Normal file
32
app/api/analytics/stats/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Trading Statistics API
|
||||
*
|
||||
* Performance analytics excluding test trades
|
||||
* GET /api/analytics/stats?days=30
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getTradingStats } from '@/lib/database/views'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const days = parseInt(searchParams.get('days') || '30')
|
||||
|
||||
const stats = await getTradingStats(days)
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
stats,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('❌ Error getting trading stats:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user