diff --git a/agent/stockbroker/nodes/tools.tsx b/agent/stockbroker/nodes/tools.tsx index 03bc0e5..c6800b7 100644 --- a/agent/stockbroker/nodes/tools.tsx +++ b/agent/stockbroker/nodes/tools.tsx @@ -8,6 +8,23 @@ import { findToolCall } from "../../find-tool-call"; import { format, subDays } from "date-fns"; import { Price, Snapshot } from "../../types"; +async function getNextPageData(url: string) { + if (!process.env.FINANCIAL_DATASETS_API_KEY) { + throw new Error("Financial datasets API key not set"); + } + + const options = { + method: "GET", + headers: { "X-API-KEY": process.env.FINANCIAL_DATASETS_API_KEY }, + }; + + const response = await fetch(url, options); + if (!response.ok) { + throw new Error("Failed to fetch prices"); + } + return await response.json(); +} + async function getPricesForTicker(ticker: string): Promise<{ oneDayPrices: Price[]; thirtyDayPrices: Price[]; @@ -54,7 +71,21 @@ async function getPricesForTicker(ticker: string): Promise<{ } const { prices: pricesOneDay } = await resOneDay.json(); - const { prices: pricesThirtyDays } = await resThirtyDays.json(); + const { prices: pricesThirtyDays, next_page_url } = + await resThirtyDays.json(); + + let nextPageUrlThirtyDays = next_page_url; + + let iters = 0; + while (nextPageUrlThirtyDays) { + if (iters > 10) { + throw new Error("MAX ITERS REACHED"); + } + const nextPageData = await getNextPageData(nextPageUrlThirtyDays); + pricesThirtyDays.push(...nextPageData.prices); + nextPageUrlThirtyDays = nextPageData.next_page_url; + iters += 1; + } return { oneDayPrices: pricesOneDay, diff --git a/langgraph.json b/langgraph.json index 44bb5d7..4c8d865 100644 --- a/langgraph.json +++ b/langgraph.json @@ -1,5 +1,5 @@ { - "node_version": "22", + "node_version": "20", "graphs": { "agent": "./agent/agent.tsx:graph" },