feat: add analysis API route

This commit is contained in:
2026-05-14 08:06:24 +02:00
parent 0930e11495
commit bd033a5d84
2 changed files with 48 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
import { OpenRouterClient } from "../../lib/openrouter";
import { TradingGraph } from "../../agents/tradingGraph";
export async function action({ request }: { request: Request }) {
const formData = await request.formData();
const ticker = formData.get("ticker") as string;
const date = formData.get("date") as string;
if (!ticker) {
return Response.json({ error: "ticker is required" }, { status: 400 });
}
const apiKey = process.env.OPENROUTER_API_KEY;
if (!apiKey) {
return Response.json({ error: "OPENROUTER_API_KEY not configured" }, { status: 500 });
}
const client = new OpenRouterClient(apiKey);
const graph = new TradingGraph(client);
const input = {
financialData: `Financial data for ${ticker} as of ${date || "latest"}`,
technicalData: {
prices: [100, 102, 101, 103, 105],
sma: 102,
ema: 103,
rsi: 55,
macd: 0.5,
},
sentimentData: {
headlines: [`${ticker} showing positive momentum`],
source: "news" as const,
},
};
try {
const decision = await graph.propagate(ticker, input);
return Response.json({ decision, ticker, date });
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";
return Response.json({ error: message }, { status: 500 });
}
}
+5
View File
@@ -0,0 +1,5 @@
import { test, expect } from "vitest";
test("placeholder test", () => {
expect(true).toBe(true);
});