style: update analyze API to use JSON body
This commit is contained in:
@@ -4,4 +4,5 @@ export default [
|
|||||||
index("routes/landing.tsx"),
|
index("routes/landing.tsx"),
|
||||||
route("api/alpaca/account", "routes/api/alpaca/account.ts"),
|
route("api/alpaca/account", "routes/api/alpaca/account.ts"),
|
||||||
route("stocks", "routes/stocks.tsx"),
|
route("stocks", "routes/stocks.tsx"),
|
||||||
|
route("analyze", "routes/analyze.tsx"),
|
||||||
] satisfies RouteConfig;
|
] satisfies RouteConfig;
|
||||||
@@ -2,9 +2,9 @@ import { OpenRouterClient } from "../../lib/openrouter";
|
|||||||
import { TradingGraph } from "../../agents/tradingGraph";
|
import { TradingGraph } from "../../agents/tradingGraph";
|
||||||
|
|
||||||
export async function action({ request }: { request: Request }) {
|
export async function action({ request }: { request: Request }) {
|
||||||
const formData = await request.formData();
|
const body = await request.json();
|
||||||
const ticker = formData.get("ticker") as string;
|
const ticker = body.ticker?.toUpperCase();
|
||||||
const date = formData.get("date") as string;
|
const date = body.date || new Date().toISOString().split("T")[0];
|
||||||
|
|
||||||
if (!ticker) {
|
if (!ticker) {
|
||||||
return Response.json({ error: "ticker is required" }, { status: 400 });
|
return Response.json({ error: "ticker is required" }, { status: 400 });
|
||||||
@@ -19,7 +19,7 @@ export async function action({ request }: { request: Request }) {
|
|||||||
const graph = new TradingGraph(client);
|
const graph = new TradingGraph(client);
|
||||||
|
|
||||||
const input = {
|
const input = {
|
||||||
financialData: `Financial data for ${ticker} as of ${date || "latest"}`,
|
financialData: `Financial data for ${ticker} as of ${date}`,
|
||||||
technicalData: {
|
technicalData: {
|
||||||
prices: [100, 102, 101, 103, 105],
|
prices: [100, 102, 101, 103, 105],
|
||||||
sma: 102,
|
sma: 102,
|
||||||
@@ -35,7 +35,7 @@ export async function action({ request }: { request: Request }) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const decision = await graph.propagate(ticker, input);
|
const decision = await graph.propagate(ticker, input);
|
||||||
return Response.json({ decision, ticker, date });
|
return Response.json(decision);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : "Unknown error";
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
return Response.json({ error: message }, { status: 500 });
|
return Response.json({ error: message }, { status: 500 });
|
||||||
|
|||||||
Reference in New Issue
Block a user