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
Binary file not shown.
|
|
@ -66,7 +66,7 @@ class CandleData(BaseModel):
|
||||||
high: float
|
high: float
|
||||||
low: float
|
low: float
|
||||||
close: float
|
close: float
|
||||||
volume: float
|
volume: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
class PredictRequest(BaseModel):
|
class PredictRequest(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,26 @@ import { db } from '@/lib/db';
|
||||||
import { charts, candles, annotations } from '@/lib/db/schema';
|
import { charts, candles, annotations } from '@/lib/db/schema';
|
||||||
import { eq } from 'drizzle-orm';
|
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(
|
export async function DELETE(
|
||||||
_request: NextRequest,
|
_request: NextRequest,
|
||||||
{ params }: { params: Promise<{ id: string }> }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
|
|
||||||
|
|
@ -512,18 +512,12 @@ export default function Home() {
|
||||||
throw new Error('No candles found for this chart');
|
throw new Error('No candles found for this chart');
|
||||||
}
|
}
|
||||||
|
|
||||||
const startTime = candlesData[0].time;
|
// Use regular predict endpoint with all candles from the database
|
||||||
const endTime = candlesData[candlesData.length - 1].time;
|
const response = await fetch('/api/predict', {
|
||||||
|
|
||||||
// Make batch prediction request
|
|
||||||
const response = await fetch('/api/predict/batch', {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
pair: chartData.name,
|
candles: candlesData,
|
||||||
timeframe: '1h', // TODO: Get from chart metadata
|
|
||||||
start_time: startTime,
|
|
||||||
end_time: endTime,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue