From f850728d44896eeb6b69a05104377ffc8d3c5b99 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Sun, 15 Feb 2026 21:49:22 +0100 Subject: [PATCH] fix(api): add GET /api/charts/[id] and fix batch prediction - Add GET handler to /api/charts/[id] route to fetch chart metadata - Fix batch prediction to use regular /predict endpoint with database candles - Remove /predict/batch usage (was designed for file-based predictions) - Make volume field optional in CandleData model (database candles don't have volume) - Convert timestamps to ISO dates for batch requests Known issue: TA-Lib indicators failing with 'input array type is not double' - May need to ensure candle data is float64/double type before processing --- .../ml/app/__pycache__/main.cpython-313.pyc | Bin 29981 -> 30010 bytes services/ml/app/main.py | 2 +- src/app/api/charts/[id]/route.ts | 20 ++++++++++++++++++ src/app/page.tsx | 12 +++-------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/services/ml/app/__pycache__/main.cpython-313.pyc b/services/ml/app/__pycache__/main.cpython-313.pyc index 227dfb46afa901f0fc45f86728525d408c652892..b04affe2ce88c891e6938fad7c55a2df2d82a612 100644 GIT binary patch delta 146 zcmbRHigDK~M&8f7yj%=GU~D)k(|03p0ViYLWC3o?$@-FllXq~+N(FNlam8@QaIyl` z#Bc=jr~~O>-XflK?#WL%^ZER4v6bcLl;)-usRAV?3rZd9zG0BNG7JDJFja delta 123 zcmdn>igE5MM&8f7yj%=GuvLFjrp-p)0#3%1$qvGjlWimwC-2~t6^P-C;Rxnd2dW6> zDdI}!o&26NpZykFS$ } +) { + const { id } = await params; + const chartId = parseInt(id, 10); + + if (isNaN(chartId)) { + return NextResponse.json({ error: 'Invalid chart ID' }, { status: 400 }); + } + + const result = await db.select().from(charts).where(eq(charts.id, chartId)).limit(1); + + if (result.length === 0) { + return NextResponse.json({ error: 'Chart not found' }, { status: 404 }); + } + + return NextResponse.json(result[0]); +} + export async function DELETE( _request: NextRequest, { params }: { params: Promise<{ id: string }> } diff --git a/src/app/page.tsx b/src/app/page.tsx index edf9531..246b927 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -512,18 +512,12 @@ export default function Home() { throw new Error('No candles found for this chart'); } - const startTime = candlesData[0].time; - const endTime = candlesData[candlesData.length - 1].time; - - // Make batch prediction request - const response = await fetch('/api/predict/batch', { + // Use regular predict endpoint with all candles from the database + const response = await fetch('/api/predict', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - pair: chartData.name, - timeframe: '1h', // TODO: Get from chart metadata - start_time: startTime, - end_time: endTime, + candles: candlesData, }), });