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
This commit is contained in:
parent
6d0d67e39b
commit
f850728d44
4 changed files with 24 additions and 10 deletions
|
|
@ -3,6 +3,26 @@ import { db } from '@/lib/db';
|
|||
import { charts, candles, annotations } from '@/lib/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
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 }> }
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue