Feat: API route for paper trade history

This commit is contained in:
2026-03-15 13:09:22 -07:00
parent 1ccba9eef1
commit a957793be3

25
app/api/trades/route.js Normal file
View File

@@ -0,0 +1,25 @@
import { NextResponse } from 'next/server';
import Surreal from 'surrealdb';
export const dynamic = 'force-dynamic';
export async function GET() {
const url = process.env.SURREAL_URL;
if (!url) {
return NextResponse.json({ trades: [], error: 'No DB configured' });
}
try {
const client = new Surreal();
await client.connect(url);
await client.signin({ username: process.env.SURREAL_USER, password: process.env.SURREAL_PASS });
await client.use({ namespace: 'kalbot', database: 'kalbot' });
const result = await client.query('SELECT * FROM paper_positions ORDER BY entryTime DESC LIMIT 50');
const trades = result[0] || [];
return NextResponse.json({ trades });
} catch (e) {
return NextResponse.json({ trades: [], error: e.message });
}
}