- Split QUALITY_LEVERAGE_THRESHOLD into separate LONG and SHORT variants - Added /api/drift/account-health endpoint for real-time collateral data - Updated settings UI to show separate controls for LONG/SHORT thresholds - Position size calculations now use dynamic collateral from Drift account - Updated .env and docker-compose.yml with new environment variables - LONG threshold: 95, SHORT threshold: 90 (configurable independently) Files changed: - app/api/drift/account-health/route.ts (NEW) - Account health API endpoint - app/settings/page.tsx - Added collateral state, separate threshold inputs - app/api/settings/route.ts - GET/POST handlers for LONG/SHORT thresholds - .env - Added QUALITY_LEVERAGE_THRESHOLD_LONG/SHORT variables - docker-compose.yml - Added new env vars with fallback defaults Impact: - Users can now configure quality thresholds independently for LONG vs SHORT signals - Position size display dynamically updates based on actual Drift account collateral - More flexible risk management with direction-specific leverage tiers
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { initializeDriftService } from '@/lib/drift/client'
|
|
|
|
/**
|
|
* GET /api/drift/account-health
|
|
*
|
|
* Returns current account health metrics from Drift Protocol
|
|
* Used by settings UI to dynamically display collateral and calculate position sizes
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const driftService = await initializeDriftService()
|
|
|
|
if (!driftService) {
|
|
return NextResponse.json(
|
|
{ error: 'Drift service not initialized' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
|
|
const health = await driftService.getAccountHealth()
|
|
|
|
return NextResponse.json({
|
|
totalCollateral: health.totalCollateral,
|
|
freeCollateral: health.freeCollateral,
|
|
totalLiability: health.totalLiability,
|
|
marginRatio: health.marginRatio,
|
|
})
|
|
} catch (error: any) {
|
|
console.error('❌ Error fetching account health:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch account health', details: error.message },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|