- Fixed balance calculation: corrected precision factor for Drift scaledBalance (5.69 vs wrong 0,678.76) - Implemented multi-RPC failover system with 4 endpoints (Helius, Solana official, Alchemy, Ankr) - Updated automation page with balance sync, leverage-based position sizing, and removed daily trade limits - Added RPC status monitoring endpoint - Updated balance and positions APIs to use failover system - All Drift APIs now working correctly with accurate balance data
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
import { NextResponse } from 'next/server';
|
|
import { Connection } from '@solana/web3.js';
|
|
|
|
const RPC_URLS = (process.env.SOLANA_RPC_URLS || '').split(',').filter(url => url.trim());
|
|
|
|
export async function GET() {
|
|
try {
|
|
const rpcStatuses = [];
|
|
|
|
for (const rpcUrl of RPC_URLS) {
|
|
const trimmedUrl = rpcUrl.trim();
|
|
let status = {
|
|
url: trimmedUrl,
|
|
status: 'unknown',
|
|
latency: null,
|
|
error: null
|
|
};
|
|
|
|
try {
|
|
const startTime = Date.now();
|
|
const connection = new Connection(trimmedUrl);
|
|
|
|
// Test basic connection with getVersion
|
|
await connection.getVersion();
|
|
|
|
const latency = Date.now() - startTime;
|
|
status.status = 'healthy';
|
|
status.latency = latency;
|
|
|
|
} catch (error) {
|
|
status.status = 'failed';
|
|
status.error = error.message;
|
|
}
|
|
|
|
rpcStatuses.push(status);
|
|
}
|
|
|
|
const healthyCount = rpcStatuses.filter(s => s.status === 'healthy').length;
|
|
const totalCount = rpcStatuses.length;
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
summary: {
|
|
healthy: healthyCount,
|
|
total: totalCount,
|
|
healthyPercentage: totalCount > 0 ? Math.round((healthyCount / totalCount) * 100) : 0
|
|
},
|
|
endpoints: rpcStatuses,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('RPC Status Check Error:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'Failed to check RPC status',
|
|
details: error.message,
|
|
timestamp: new Date().toISOString()
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|