feat(settings): add settings route and API updates\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This commit is contained in:
2026-05-16 20:19:35 +02:00
parent 9b63d981b0
commit 0ee89cf052
38 changed files with 1426 additions and 562 deletions
+61 -2
View File
@@ -1,6 +1,7 @@
import pkg from "bullmq";
const { Queue, Worker } = pkg as any;
import IORedis from "ioredis";
import { fetchAccount, fetchRecentCloses } from "./alpacaClient";
import { OpenRouterClient } from "./openrouter";
import { TradingGraph } from "../agents/tradingGraph";
import { db } from "./db.server";
@@ -42,7 +43,35 @@ if (REDIS_URL) {
const client = new OpenRouterClient(apiKey);
const graph = new TradingGraph(client);
const decision = await graph.propagate(ticker, input);
// Fetch latest Alpaca account and prices; abort job if unavailable so work runs on fresh data
try {
const account = await fetchAccount();
const prices = await fetchRecentCloses(ticker);
input.account = input.account || account;
input.technicalData = input.technicalData || {};
input.technicalData.prices = input.technicalData.prices && input.technicalData.prices.length ? input.technicalData.prices : prices;
} catch (e) {
console.error("[queue] Failed to fetch Alpaca data, aborting job:", e);
// Throw to mark the job as failed early
throw new Error("Failed to fetch Alpaca data: " + String(e));
}
let decision = await graph.propagate(ticker, input);
// Enrich executionPlan deterministically server-side before persisting
try {
const { enrichExecutionPlan, verifyExecutionPlanWithLLM } = await import("./execution");
decision = enrichExecutionPlan(decision, input);
if (process.env.OPENROUTER_API_KEY) {
try {
decision = await verifyExecutionPlanWithLLM(decision, input);
} catch (e) {
console.warn("[queue] LLM verification failed:", e);
}
}
} catch (e) {
console.warn("[queue] Failed to enrich execution plan:", e);
}
await db.stock.upsert({
where: { ticker },
@@ -164,7 +193,37 @@ if (REDIS_URL) {
}
const client = new OpenRouterClient(process.env.OPENROUTER_API_KEY as string);
const graph = new TradingGraph(client);
const decision = await graph.propagate(job.ticker, job.input);
// Fetch latest Alpaca account and prices; abort job if unavailable so work runs on fresh data
try {
const account = await fetchAccount();
const prices = await fetchRecentCloses(job.ticker);
job.input = job.input || {};
job.input.account = job.input.account || account;
job.input.technicalData = job.input.technicalData || {};
job.input.technicalData.prices = job.input.technicalData.prices && job.input.technicalData.prices.length ? job.input.technicalData.prices : prices;
} catch (e) {
console.error("[inproc queue] Failed to fetch Alpaca data, aborting job:", e);
// throw so the outer catch marks job as failed
throw new Error("Failed to fetch Alpaca data: " + String(e));
}
let decision = await graph.propagate(job.ticker, job.input);
// Enrich executionPlan deterministically server-side before persisting
try {
const { enrichExecutionPlan, verifyExecutionPlanWithLLM } = await import("./execution");
decision = enrichExecutionPlan(decision, job.input);
if (process.env.OPENROUTER_API_KEY) {
try {
decision = await verifyExecutionPlanWithLLM(decision, job.input);
} catch (e) {
console.warn("[inproc queue] LLM verification failed:", e);
}
}
} catch (e) {
console.warn("[inproc queue] Failed to enrich execution plan:", e);
}
job.result = decision;
job.state = "completed";
await db.stock.upsert({