feat(settings): add settings route and API updates\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* TRADINGGRAPH related file */
|
||||
|
||||
// Server-only imports are loaded dynamically inside the action to avoid client bundling issues
|
||||
|
||||
export async function action({ request }: { request: Request }) {
|
||||
@@ -18,7 +20,7 @@ export async function action({ request }: { request: Request }) {
|
||||
const { OpenRouterClient } = await import("../../lib/openrouter");
|
||||
const { TradingGraph } = await import("../../agents/tradingGraph");
|
||||
const { db } = await import("../../lib/db.server");
|
||||
const { fetchAccount, fetchRecentCloses } = await import("../../lib/alpacaClient");
|
||||
const { fetchAccount, fetchRecentCloses, fetchBars } = await import("../../lib/alpacaClient");
|
||||
|
||||
const apiKey = process.env.OPENROUTER_API_KEY;
|
||||
console.log("[analyze] API key configured:", !!apiKey, apiKey?.substring(0, 10) + "...");
|
||||
@@ -63,9 +65,20 @@ export async function action({ request }: { request: Request }) {
|
||||
// Fetch latest Alpaca account and recent prices; abort if unavailable
|
||||
let account: any = undefined;
|
||||
let prices: number[] = [];
|
||||
let recentBars: any[] = [];
|
||||
try {
|
||||
account = await fetchAccount();
|
||||
prices = await fetchRecentCloses(ticker);
|
||||
// Also fetch recent intraday bars to enable deterministic execution plan calculation
|
||||
try {
|
||||
recentBars = await fetchBars(ticker, '1Min', { limit: 200 });
|
||||
// derive prices from bars if available (prefer freshest closes)
|
||||
if (recentBars && recentBars.length) {
|
||||
prices = recentBars.map((b: any) => (typeof b.ClosePrice === 'number' ? b.ClosePrice : (typeof b.c === 'number' ? b.c : 0))).filter((p: number) => p > 0);
|
||||
}
|
||||
} catch (barErr) {
|
||||
console.warn('[analyze] Failed to fetch recent bars for deterministic execution plan:', barErr);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[analyze] Failed to fetch Alpaca data before analysis:", e);
|
||||
return Response.json({ error: "Failed to fetch Alpaca data: " + String(e) }, { status: 502 });
|
||||
@@ -75,6 +88,7 @@ export async function action({ request }: { request: Request }) {
|
||||
financialData: `Financial data for ${ticker} as of ${date}`,
|
||||
technicalData: {
|
||||
prices,
|
||||
bars: recentBars,
|
||||
sma: 0,
|
||||
ema: 0,
|
||||
rsi: 0,
|
||||
@@ -119,11 +133,17 @@ export async function action({ request }: { request: Request }) {
|
||||
console.warn("Failed to enrich execution plan:", e);
|
||||
}
|
||||
|
||||
console.log("[analyze] Decision received:", JSON.stringify(decision));
|
||||
// Avoid logging potentially verbose debate rounds to server CLI
|
||||
try {
|
||||
const { debateRounds, ...decisionSafe } = decision as any;
|
||||
console.log("[analyze] Decision received (debate redacted):", JSON.stringify(decisionSafe));
|
||||
} catch (e) {
|
||||
console.log("[analyze] Decision received");
|
||||
}
|
||||
return Response.json(decision);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("[analyze] Error:", error);
|
||||
return Response.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user