UNPKG

fmp-ai-tools

Version:

AI tools for FMP Node API - compatible with Vercel AI SDK, Langchain, OpenAI, and more

512 lines (507 loc) 18.9 kB
'use strict'; var zod = require('zod'); var fmpNodeApi = require('fmp-node-api'); var ai = require('ai'); // src/providers/vercel-ai/quote.ts function getFMPClient() { return new fmpNodeApi.FMP(); } function createTool(config) { const { name, description, inputSchema, execute } = config; return ai.tool({ name, description, inputSchema, execute }); } // src/providers/vercel-ai/quote.ts var quoteTools = { getStockQuote: createTool({ name: "getStockQuote", description: "Get the stock quote for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The symbol of the company to get the stock quote for") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const stockQuote = await fmp.quote.getQuote(symbol); const response = JSON.stringify(stockQuote.data, null, 2); return response; } }) }; var companyTools = { getCompanyProfile: createTool({ name: "getCompanyProfile", description: "Get the company profile", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock ticker symbol (e.g., AAPL)") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const companyProfile = await fmp.company.getCompanyProfile(symbol); const response = JSON.stringify(companyProfile.data, null, 2); return response; } }) }; var financialTools = { getBalanceSheet: createTool({ name: "getBalanceSheet", description: "Get balance sheet for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get balance sheet for"), period: zod.z.enum(["annual", "quarter"]).default("annual").describe("The period type (annual or quarter)") }), execute: async ({ symbol, period }) => { const fmp = getFMPClient(); const balanceSheet = await fmp.financial.getBalanceSheet({ symbol, period }); const response = JSON.stringify(balanceSheet.data, null, 2); return response; } }), getIncomeStatement: createTool({ name: "getIncomeStatement", description: "Get income statement for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get income statement for"), period: zod.z.enum(["annual", "quarter"]).default("annual").describe("The period type (annual or quarter)") }), execute: async ({ symbol, period }) => { const fmp = getFMPClient(); const incomeStatement = await fmp.financial.getIncomeStatement({ symbol, period }); const response = JSON.stringify(incomeStatement.data, null, 2); return response; } }), getCashFlowStatement: createTool({ name: "getCashFlowStatement", description: "Get cash flow statement for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get cash flow statement for"), period: zod.z.enum(["annual", "quarter"]).default("annual").describe("The period type (annual or quarter)") }), execute: async ({ symbol, period }) => { const fmp = getFMPClient(); const cashFlowStatement = await fmp.financial.getCashFlowStatement({ symbol, period }); const response = JSON.stringify(cashFlowStatement.data, null, 2); return response; } }), getFinancialRatios: createTool({ name: "getFinancialRatios", description: "Get financial ratios for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get financial ratios for"), period: zod.z.enum(["annual", "quarter"]).default("annual").describe("The period type (annual or quarter)") }), execute: async ({ symbol, period }) => { const fmp = getFMPClient(); const financialRatios = await fmp.financial.getFinancialRatios({ symbol, period }); const response = JSON.stringify(financialRatios.data, null, 2); return response; } }) }; var calendarTools = { getEarningsCalendar: createTool({ name: "getEarningsCalendar", description: "Get earnings calendar", inputSchema: zod.z.object({ from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format"), to: zod.z.string().optional().describe("End date in YYYY-MM-DD format") }), execute: async ({ from, to }) => { const fmp = getFMPClient(); const earningsCalendar = await fmp.calendar.getEarningsCalendar({ from, to }); const response = JSON.stringify(earningsCalendar.data, null, 2); return response; } }), getEconomicCalendar: createTool({ name: "getEconomicCalendar", description: "Get economic calendar", inputSchema: zod.z.object({ from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format"), to: zod.z.string().optional().describe("End date in YYYY-MM-DD format") }), execute: async ({ from, to }) => { const fmp = getFMPClient(); const economicCalendar = await fmp.calendar.getEconomicsCalendar({ from, to }); const response = JSON.stringify(economicCalendar.data, null, 2); return response; } }) }; var economicTools = { getTreasuryRates: createTool({ name: "getTreasuryRates", description: "Get treasury rates", inputSchema: zod.z.object({ from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format"), to: zod.z.string().optional().describe("End date in YYYY-MM-DD format") }), execute: async ({ from, to }) => { const fmp = getFMPClient(); const treasuryRates = await fmp.economic.getTreasuryRates({ from, to }); const response = JSON.stringify(treasuryRates.data, null, 2); return response; } }), getEconomicIndicators: createTool({ name: "getEconomicIndicators", description: "Get economic indicators", inputSchema: zod.z.object({ name: zod.z.enum([ "GDP", "realGDP", "nominalPotentialGDP", "realGDPPerCapita", "federalFunds", "CPI", "inflationRate", "inflation", "retailSales", "consumerSentiment", "durableGoods", "unemploymentRate", "totalNonfarmPayroll", "initialClaims", "industrialProductionTotalIndex", "newPrivatelyOwnedHousingUnitsStartedTotalUnits", "totalVehicleSales", "retailMoneyFunds", "smoothedUSRecessionProbabilities", "3MonthOr90DayRatesAndYieldsCertificatesOfDeposit", "commercialBankInterestRateOnCreditCardPlansAllAccounts", "30YearFixedRateMortgageAverage", "15YearFixedRateMortgageAverage" ]).describe("The name of the economic indicator"), from: zod.z.string().optional().describe("Start date in YYYY-MM-DD format"), to: zod.z.string().optional().describe("End date in YYYY-MM-DD format") }), execute: async ({ name, from, to }) => { const fmp = getFMPClient(); const economicIndicators = await fmp.economic.getEconomicIndicators({ name, from, to }); const response = JSON.stringify(economicIndicators.data, null, 2); return response; } }) }; var etfTools = { getETFHoldings: createTool({ name: "getETFHoldings", description: "Get ETF holdings for a specific ETF symbol", inputSchema: zod.z.object({ symbol: zod.z.string().describe("ETF symbol (e.g., SPY, QQQ, VTI)"), date: zod.z.string().optional().describe("Date for holdings (YYYY-MM-DD format)") }), execute: async ({ symbol, date }) => { const fmp = getFMPClient(); const params = { symbol }; if (date) { params.date = date; } const etfHoldings = await fmp.etf.getHoldings(params); const response = JSON.stringify(etfHoldings.data, null, 2); return response; } }), getETFProfile: createTool({ name: "getETFProfile", description: "Get ETF profile information", inputSchema: zod.z.object({ symbol: zod.z.string().describe("ETF symbol (e.g., SPY, QQQ, VTI)") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const etfProfile = await fmp.etf.getProfile(symbol); const response = JSON.stringify(etfProfile.data, null, 2); return response; } }) }; var insiderTools = { getInsiderTrading: createTool({ name: "getInsiderTrading", description: "Get insider trading data for a specific stock symbol", inputSchema: zod.z.object({ symbol: zod.z.string().describe("Stock symbol (e.g., AAPL, MSFT, GOOGL)"), page: zod.z.number().default(0).describe("Page number for pagination") }), execute: async ({ symbol, page }) => { const fmp = getFMPClient(); const insiderTrading = await fmp.insider.getInsiderTradesBySymbol(symbol, page); const response = JSON.stringify(insiderTrading.data, null, 2); return response; } }) }; var institutionalTools = { getInstitutionalHolders: createTool({ name: "getInstitutionalHolders", description: "Get institutional holders for a specific stock symbol", inputSchema: zod.z.object({ symbol: zod.z.string().describe("Stock symbol (e.g., AAPL, MSFT, GOOGL)") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const institutionalHolders = await fmp.institutional.getInstitutionalHolders({ symbol }); const response = JSON.stringify(institutionalHolders.data, null, 2); return response; } }) }; var marketTools = { getMarketPerformance: createTool({ name: "getMarketPerformance", description: "Get overall market performance data", inputSchema: zod.z.object({}), execute: async () => { const fmp = getFMPClient(); const marketPerformance = await fmp.market.getMarketPerformance(); const response = JSON.stringify(marketPerformance.data, null, 2); return response; } }), getSectorPerformance: createTool({ name: "getSectorPerformance", description: "Get sector performance data", inputSchema: zod.z.object({}), execute: async () => { const fmp = getFMPClient(); const sectorPerformance = await fmp.market.getSectorPerformance(); const response = JSON.stringify(sectorPerformance.data, null, 2); return response; } }), getGainers: createTool({ name: "getGainers", description: "Get top gaining stocks", inputSchema: zod.z.object({}), execute: async () => { const fmp = getFMPClient(); const gainers = await fmp.market.getGainers(); const response = JSON.stringify(gainers.data, null, 2); return response; } }), getLosers: createTool({ name: "getLosers", description: "Get top losing stocks", inputSchema: zod.z.object({}), execute: async () => { const fmp = getFMPClient(); const losers = await fmp.market.getLosers(); const response = JSON.stringify(losers.data, null, 2); return response; } }), getMostActive: createTool({ name: "getMostActive", description: "Get most active stocks", inputSchema: zod.z.object({}), execute: async () => { const fmp = getFMPClient(); const mostActive = await fmp.market.getMostActive(); const response = JSON.stringify(mostActive.data, null, 2); return response; } }) }; var senateHouseTools = { getSenateTrading: createTool({ name: "getSenateTrading", description: "Get senate trading data for a specific stock symbol", inputSchema: zod.z.object({ symbol: zod.z.string().describe("Stock symbol (e.g., AAPL, MSFT, GOOGL)") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const senateTrading = await fmp.senateHouse.getSenateTrading({ symbol }); const response = JSON.stringify(senateTrading.data, null, 2); return response; } }), getHouseTrading: createTool({ name: "getHouseTrading", description: "Get house trading data for a specific stock symbol", inputSchema: zod.z.object({ symbol: zod.z.string().describe("Stock symbol (e.g., AAPL, MSFT, GOOGL)") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const houseTrading = await fmp.senateHouse.getHouseTrading({ symbol }); const response = JSON.stringify(houseTrading.data, null, 2); return response; } }), getSenateTradingByName: createTool({ name: "getSenateTradingByName", description: "Get senate trading data for a specific senator by name", inputSchema: zod.z.object({ name: zod.z.string().describe("The name of the senator to get trading data for") }), execute: async ({ name }) => { const fmp = getFMPClient(); const senateTradingByName = await fmp.senateHouse.getSenateTradingByName({ name }); const response = JSON.stringify(senateTradingByName.data, null, 2); return response; } }), getHouseTradingByName: createTool({ name: "getHouseTradingByName", description: "Get house trading data for a specific representative by name", inputSchema: zod.z.object({ name: zod.z.string().describe("The name of the representative to get trading data for") }), execute: async ({ name }) => { const fmp = getFMPClient(); const houseTradingByName = await fmp.senateHouse.getHouseTradingByName({ name }); const response = JSON.stringify(houseTradingByName.data, null, 2); return response; } }), getSenateTradingRSSFeed: createTool({ name: "getSenateTradingRSSFeed", description: "Get senate trading data through RSS feed with pagination", inputSchema: zod.z.object({ page: zod.z.number().default(0).describe("Page number for pagination") }), execute: async ({ page = 0 }) => { const fmp = getFMPClient(); const senateTradingRSSFeed = await fmp.senateHouse.getSenateTradingRSSFeed({ page }); const response = JSON.stringify(senateTradingRSSFeed.data, null, 2); return response; } }), getHouseTradingRSSFeed: createTool({ name: "getHouseTradingRSSFeed", description: "Get house trading data through RSS feed with pagination", inputSchema: zod.z.object({ page: zod.z.number().default(0).describe("Page number for pagination") }), execute: async ({ page = 0 }) => { const fmp = getFMPClient(); const houseTradingRSSFeed = await fmp.senateHouse.getHouseTradingRSSFeed({ page }); const response = JSON.stringify(houseTradingRSSFeed.data, null, 2); return response; } }) }; var stockTools = { getMarketCap: createTool({ name: "getMarketCap", description: "Get market capitalization for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get market cap for") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const marketCap = await fmp.stock.getMarketCap(symbol); const response = JSON.stringify(marketCap.data, null, 2); return response; } }), getStockSplits: createTool({ name: "getStockSplits", description: "Get stock splits history for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get stock splits for") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const stockSplits = await fmp.stock.getStockSplits(symbol); const response = JSON.stringify(stockSplits.data, null, 2); return response; } }), getDividendHistory: createTool({ name: "getDividendHistory", description: "Get dividend history for a company", inputSchema: zod.z.object({ symbol: zod.z.string().describe("The stock symbol to get dividend history for") }), execute: async ({ symbol }) => { const fmp = getFMPClient(); const dividendHistory = await fmp.stock.getDividendHistory(symbol); const response = JSON.stringify(dividendHistory.data, null, 2); return response; } }) }; // src/providers/vercel-ai/index.ts var { getCompanyProfile } = companyTools; var { getEarningsCalendar, getEconomicCalendar } = calendarTools; var { getTreasuryRates, getEconomicIndicators } = economicTools; var { getETFHoldings, getETFProfile } = etfTools; var { getBalanceSheet, getIncomeStatement, getCashFlowStatement, getFinancialRatios } = financialTools; var { getInsiderTrading } = insiderTools; var { getInstitutionalHolders } = institutionalTools; var { getMarketPerformance, getSectorPerformance, getGainers, getLosers, getMostActive } = marketTools; var { getStockQuote } = quoteTools; var { getSenateTrading, getHouseTrading, getSenateTradingByName, getHouseTradingByName, getSenateTradingRSSFeed, getHouseTradingRSSFeed } = senateHouseTools; var { getMarketCap, getStockSplits, getDividendHistory } = stockTools; var fmpTools = { ...quoteTools, ...companyTools, ...financialTools, ...calendarTools, ...economicTools, ...etfTools, ...insiderTools, ...institutionalTools, ...marketTools, ...senateHouseTools, ...stockTools }; exports.calendarTools = calendarTools; exports.companyTools = companyTools; exports.economicTools = economicTools; exports.etfTools = etfTools; exports.financialTools = financialTools; exports.fmpTools = fmpTools; exports.getBalanceSheet = getBalanceSheet; exports.getCashFlowStatement = getCashFlowStatement; exports.getCompanyProfile = getCompanyProfile; exports.getDividendHistory = getDividendHistory; exports.getETFHoldings = getETFHoldings; exports.getETFProfile = getETFProfile; exports.getEarningsCalendar = getEarningsCalendar; exports.getEconomicCalendar = getEconomicCalendar; exports.getEconomicIndicators = getEconomicIndicators; exports.getFinancialRatios = getFinancialRatios; exports.getGainers = getGainers; exports.getHouseTrading = getHouseTrading; exports.getHouseTradingByName = getHouseTradingByName; exports.getHouseTradingRSSFeed = getHouseTradingRSSFeed; exports.getIncomeStatement = getIncomeStatement; exports.getInsiderTrading = getInsiderTrading; exports.getInstitutionalHolders = getInstitutionalHolders; exports.getLosers = getLosers; exports.getMarketCap = getMarketCap; exports.getMarketPerformance = getMarketPerformance; exports.getMostActive = getMostActive; exports.getSectorPerformance = getSectorPerformance; exports.getSenateTrading = getSenateTrading; exports.getSenateTradingByName = getSenateTradingByName; exports.getSenateTradingRSSFeed = getSenateTradingRSSFeed; exports.getStockQuote = getStockQuote; exports.getStockSplits = getStockSplits; exports.getTreasuryRates = getTreasuryRates; exports.insiderTools = insiderTools; exports.institutionalTools = institutionalTools; exports.marketTools = marketTools; exports.quoteTools = quoteTools; exports.senateHouseTools = senateHouseTools; exports.stockTools = stockTools; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map