mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
Feat: API route to expose worker state to frontend
This commit is contained in:
23
app/api/state/route.js
Normal file
23
app/api/state/route.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import fs from 'fs';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const STATE_FILE = '/tmp/kalbot-state.json';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const raw = fs.readFileSync(STATE_FILE, 'utf-8');
|
||||
const data = JSON.parse(raw);
|
||||
return NextResponse.json(data);
|
||||
} catch (e) {
|
||||
return NextResponse.json({
|
||||
market: null,
|
||||
paper: { balance: 1000, totalPnL: 0, wins: 0, losses: 0, winRate: 0, openPositions: [], totalTrades: 0 },
|
||||
strategies: [],
|
||||
workerUptime: 0,
|
||||
lastUpdate: null,
|
||||
error: 'Worker not running or no data yet'
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user