43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { OpenRouterClient } from "../../lib/openrouter";
|
|
import { TradingGraph } from "../../agents/tradingGraph";
|
|
|
|
export async function action({ request }: { request: Request }) {
|
|
const body = await request.json();
|
|
const ticker = body.ticker?.toUpperCase();
|
|
const date = body.date || new Date().toISOString().split("T")[0];
|
|
|
|
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}`,
|
|
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);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
return Response.json({ error: message }, { status: 500 });
|
|
}
|
|
} |