mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
Feat: API route for paper trade history
This commit is contained in:
25
app/api/trades/route.js
Normal file
25
app/api/trades/route.js
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user