diff --git a/app/routes/api/analyze.ts b/app/routes/api/analyze.ts new file mode 100644 index 0000000..467fcfa --- /dev/null +++ b/app/routes/api/analyze.ts @@ -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 }); + } +} \ No newline at end of file diff --git a/tests/api/analyze.test.ts b/tests/api/analyze.test.ts new file mode 100644 index 0000000..c3d47c8 --- /dev/null +++ b/tests/api/analyze.test.ts @@ -0,0 +1,5 @@ +import { test, expect } from "vitest"; + +test("placeholder test", () => { + expect(true).toBe(true); +}); \ No newline at end of file