fmp-ai-tools 0.0.10 → 0.0.11-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,317 +1,337 @@
1
- # FMP AI Tools
2
-
3
- AI tools for Financial Modeling Prep (FMP) Node API - compatible with Vercel AI SDK, OpenAI Agents, and more.
4
-
5
- This package provides pre-built AI tools that can be used with various AI frameworks. For direct API access, use the `fmp-node-api` package.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install fmp-ai-tools
11
- # or
12
- pnpm add fmp-ai-tools
13
- # or
14
- yarn add fmp-ai-tools
15
- ```
16
-
17
- ## Version Compatibility
18
-
19
- ### OpenAI Agents Compatibility
20
-
21
- **⚠️ Important**: This package requires `@openai/agents` version `^0.0.17` or higher due to breaking changes in the API.
22
-
23
- If you're using an older version, you'll encounter errors like:
24
-
25
- ```
26
- Zod field uses .optional() without .nullable() which is not supported by the API
27
- ```
28
-
29
- ## Quick Start
30
-
31
- ### Vercel AI SDK (Recommended)
32
-
33
- ```typescript
34
- import { openai } from '@ai-sdk/openai';
35
- import { streamText, convertToModelMessages, stepCountIs } from 'ai';
36
- import { fmpTools } from 'fmp-ai-tools/vercel-ai';
37
-
38
- export async function POST(req: Request) {
39
- const { messages } = await req.json();
40
-
41
- const result = streamText({
42
- model: openai('gpt-4o-mini'),
43
- messages: convertToModelMessages(messages),
44
- tools: fmpTools,
45
- stopWhen: stepCountIs(5),
46
- });
47
-
48
- return result.toUIMessageStreamResponse();
49
- }
50
- ```
51
-
52
- ### OpenAI Agents
53
-
54
- ```typescript
55
- import { Agent } from '@openai/agents';
56
- import { fmpTools } from 'fmp-ai-tools/openai';
57
-
58
- const agent = new Agent({
59
- name: 'Financial Analyst',
60
- instructions: 'You are a financial analyst with access to real-time market data.',
61
- tools: fmpTools,
62
- });
63
-
64
- const result = await agent.run({
65
- messages: [
66
- {
67
- role: 'user',
68
- content:
69
- 'Get the current stock quote for Apple (AAPL) and show me their latest balance sheet',
70
- },
71
- ],
72
- });
73
- ```
74
-
75
- ## Configuration
76
-
77
- **Important**: You must set your FMP API key as an environment variable for the tools to work:
78
-
79
- ```bash
80
- FMP_API_KEY=your_api_key_here
81
- ```
82
-
83
- The tools internally use the `fmp-node-api` library, which reads this environment variable to authenticate with the Financial Modeling Prep API.
84
-
85
- ### Debugging and Logging
86
-
87
- **⚠️ Development Only**: These logging features are intended for debugging and development, not production use.
88
-
89
- Two logging modes controlled by environment variables:
90
-
91
- #### Full Logging Mode
92
-
93
- ```bash
94
- FMP_TOOLS_LOG_API_RESULTS=true
95
- ```
96
-
97
- Logs: tool name, input parameters, result summary with token count, execution time.
98
-
99
- #### Data-Only Logging Mode
100
-
101
- ```bash
102
- FMP_TOOLS_LOG_DATA_ONLY=true
103
- ```
104
-
105
- Logs: result summary and formatted JSON response data.
106
-
107
- #### Example Output
108
-
109
- **Full Logging:**
110
-
111
- ```
112
- 🔧 getStockQuote: object (~28 tokens)
113
- ⏱️ Execution Time: 245ms
114
- ```
115
-
116
- **Data-Only Logging:**
117
-
118
- ```
119
- 📤 Result: { "symbol": "AAPL", "price": 150.25, ... }
120
- ```
121
-
122
- **Note**: Both modes are disabled by default. Use only during development.
123
-
124
- ## Available Tools
125
-
126
- ### Quote Tools
127
-
128
- - `getStockQuote` - Get real-time stock quote for a company
129
-
130
- ### Company Tools
131
-
132
- - `getCompanyProfile` - Get comprehensive company profile and information
133
-
134
- ### Financial Tools
135
-
136
- - `getBalanceSheet` - Get balance sheet statements (annual/quarterly)
137
- - `getIncomeStatement` - Get income statements (annual/quarterly)
138
- - `getCashFlowStatement` - Get cash flow statements (annual/quarterly)
139
- - `getFinancialRatios` - Get financial ratios and metrics (annual/quarterly)
140
-
141
- ### Stock Tools
142
-
143
- - `getMarketCap` - Get market capitalization for a company
144
- - `getStockSplits` - Get historical stock splits for a company
145
- - `getDividendHistory` - Get dividend history and payments for a company
146
-
147
- ### Market Tools
148
-
149
- - `getMarketPerformance` - Get overall market performance data
150
- - `getSectorPerformance` - Get sector performance data
151
- - `getGainers` - Get top gaining stocks
152
- - `getLosers` - Get top losing stocks
153
- - `getMostActive` - Get most actively traded stocks
154
-
155
- ### Economic Tools
156
-
157
- - `getTreasuryRates` - Get treasury rates and yields
158
- - `getEconomicIndicators` - Get economic indicators (GDP, CPI, unemployment, etc.)
159
-
160
- ### ETF Tools
161
-
162
- - `getETFHoldings` - Get holdings for a specific ETF
163
- - `getETFProfile` - Get ETF profile and information
164
-
165
- ### Calendar Tools
166
-
167
- - `getEarningsCalendar` - Get upcoming earnings calendar
168
- - `getEconomicCalendar` - Get economic calendar events
169
-
170
- ### Senate & House Trading Tools
171
-
172
- - `getSenateTrading` - Get recent Senate trading activity
173
- - `getHouseTrading` - Get recent House trading activity
174
- - `getSenateTradingByName` - Get Senate trading by politician name
175
- - `getHouseTradingByName` - Get House trading by politician name
176
- - `getSenateTradingRSSFeed` - Get Senate trading RSS feed
177
- - `getHouseTradingRSSFeed` - Get House trading RSS feed
178
-
179
- ### Institutional Tools
180
-
181
- - `getInstitutionalHolders` - Get institutional holders for a company
182
-
183
- ### Insider Trading Tools
184
-
185
- - `getInsiderTrading` - Get insider trading data for a company
186
-
187
- ## Using Individual Tools
188
-
189
- You can import and use specific tool categories or individual tools from either provider:
190
-
191
- ### Import Specific Categories (Vercel AI)
192
-
193
- ```typescript
194
- import { quoteTools, financialTools, marketTools } from 'fmp-ai-tools/vercel-ai';
195
-
196
- // Use only quote and financial tools
197
- const selectedTools = {
198
- ...quoteTools,
199
- ...financialTools,
200
- };
201
-
202
- // Use with Vercel AI SDK
203
- const result = streamText({
204
- model: openai('gpt-4o-mini'),
205
- messages: convertToModelMessages(messages),
206
- tools: selectedTools,
207
- });
208
- ```
209
-
210
- ### Import Specific Categories (OpenAI)
211
-
212
- ```typescript
213
- import { quoteTools, financialTools, marketTools } from 'fmp-ai-tools/openai';
214
-
215
- // Use only quote and financial tools
216
- const selectedTools = [...quoteTools, ...financialTools];
217
-
218
- // Use with OpenAI Agents
219
- const agent = new Agent({
220
- name: 'Financial Analyst',
221
- instructions: 'You are a financial analyst with access to real-time market data.',
222
- tools: selectedTools,
223
- });
224
- ```
225
-
226
- ### Import Individual Tools
227
-
228
- ```typescript
229
- // Vercel AI SDK
230
- import { getStockQuote, getCompanyProfile } from 'fmp-ai-tools/vercel-ai';
231
-
232
- // OpenAI Agents
233
- import { getStockQuote, getCompanyProfile } from 'fmp-ai-tools/openai';
234
- ```
235
-
236
- ## Example Tool Usage
237
-
238
- Here are some example prompts you can use with the tools:
239
-
240
- **Stock Analysis:**
241
-
242
- ```
243
- "Get the current stock quote for Apple (AAPL) and show me their latest balance sheet"
244
- ```
245
-
246
- **Market Research:**
247
-
248
- ```
249
- "What are the top gaining stocks today and show me the overall market performance?"
250
- ```
251
-
252
- **Economic Analysis:**
253
-
254
- ```
255
- "Get the current treasury rates and show me the latest GDP data"
256
- ```
257
-
258
- **ETF Research:**
259
-
260
- ```
261
- "Show me the holdings of SPY ETF and get its profile information"
262
- ```
263
-
264
- **Financial Analysis:**
265
-
266
- ```
267
- "Get Apple's income statement, cash flow statement, and financial ratios for the last year"
268
- ```
269
-
270
- ## Tool Parameters
271
-
272
- Each tool accepts specific parameters. Here are some common ones:
273
-
274
- - `symbol` - Stock/ETF symbol (e.g., "AAPL", "SPY")
275
- - `period` - For financial statements: "annual" or "quarter"
276
- - `from` - Start date in YYYY-MM-DD format
277
- - `to` - End date in YYYY-MM-DD format
278
- - `name` - For economic indicators: specific indicator name
279
-
280
- ## Error Handling
281
-
282
- The tools handle API errors gracefully and will return informative error messages if:
283
-
284
- - The API key is invalid or missing
285
- - The requested data is not available
286
- - Rate limits are exceeded
287
- - Invalid parameters are provided
288
-
289
- ## Testing Tools
290
-
291
- Test individual tools:
292
-
293
- ```bash
294
- # Test specific tools
295
- pnpm test:tool getStockQuote
296
- pnpm test:tool getCompanyProfile
297
- pnpm test:tool getBalanceSheet
298
- pnpm test:tool getMarketPerformance
299
- ```
300
-
301
- ## For Direct API Access
302
-
303
- If you need direct access to the FMP API without AI tools, use the `fmp-node-api` package:
304
-
305
- ```typescript
306
- import { FMP } from 'fmp-node-api';
307
-
308
- const fmp = new FMP({ apiKey: 'your_api_key_here' });
309
-
310
- // Direct API calls
311
- const quote = await fmp.quote.getQuote('AAPL');
312
- const profile = await fmp.company.getCompanyProfile('AAPL');
313
- ```
314
-
315
- ## License
316
-
317
- MIT
1
+ # FMP AI Tools
2
+
3
+ AI tools for Financial Modeling Prep (FMP) Node API - compatible with Vercel AI SDK, OpenAI Agents, and more.
4
+
5
+ This package provides pre-built AI tools that can be used with various AI frameworks. For direct API access, use the `fmp-node-api` package.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install fmp-ai-tools
11
+ # or
12
+ pnpm add fmp-ai-tools
13
+ # or
14
+ yarn add fmp-ai-tools
15
+ ```
16
+
17
+ ### Peer Dependencies
18
+
19
+ This package requires the following peer dependencies to be installed in your project:
20
+
21
+ ```bash
22
+ # For Vercel AI SDK
23
+ npm install ai zod
24
+ # or
25
+ pnpm add ai zod
26
+ # or
27
+ yarn add ai zod
28
+ ```
29
+
30
+ **Required versions:**
31
+
32
+ - `ai`: ^5.0.0
33
+ - `zod`: ^3.25.76 || ^4.0.0
34
+
35
+ **⚠️ Common Issue**: If you encounter the error `Invalid schema for function 'getStockQuote': schema must be a JSON Schema of 'type: "object"', got 'type: "None"'`, it means you have a version mismatch between `ai` and `zod`. Make sure you're using compatible versions as listed above.
36
+
37
+ ## Version Compatibility
38
+
39
+ ### OpenAI Agents Compatibility
40
+
41
+ **⚠️ Important**: This package requires `@openai/agents` version `^0.0.17` or higher due to breaking changes in the API.
42
+
43
+ If you're using an older version, you'll encounter errors like:
44
+
45
+ ```
46
+ Zod field uses .optional() without .nullable() which is not supported by the API
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### Vercel AI SDK (Recommended)
52
+
53
+ ```typescript
54
+ import { openai } from '@ai-sdk/openai';
55
+ import { streamText, convertToModelMessages, stepCountIs } from 'ai';
56
+ import { fmpTools } from 'fmp-ai-tools/vercel-ai';
57
+
58
+ export async function POST(req: Request) {
59
+ const { messages } = await req.json();
60
+
61
+ const result = streamText({
62
+ model: openai('gpt-4o-mini'),
63
+ messages: convertToModelMessages(messages),
64
+ tools: fmpTools,
65
+ stopWhen: stepCountIs(5),
66
+ });
67
+
68
+ return result.toUIMessageStreamResponse();
69
+ }
70
+ ```
71
+
72
+ ### OpenAI Agents
73
+
74
+ ```typescript
75
+ import { Agent } from '@openai/agents';
76
+ import { fmpTools } from 'fmp-ai-tools/openai';
77
+
78
+ const agent = new Agent({
79
+ name: 'Financial Analyst',
80
+ instructions: 'You are a financial analyst with access to real-time market data.',
81
+ tools: fmpTools,
82
+ });
83
+
84
+ const result = await agent.run({
85
+ messages: [
86
+ {
87
+ role: 'user',
88
+ content:
89
+ 'Get the current stock quote for Apple (AAPL) and show me their latest balance sheet',
90
+ },
91
+ ],
92
+ });
93
+ ```
94
+
95
+ ## Configuration
96
+
97
+ **Important**: You must set your FMP API key as an environment variable for the tools to work:
98
+
99
+ ```bash
100
+ FMP_API_KEY=your_api_key_here
101
+ ```
102
+
103
+ The tools internally use the `fmp-node-api` library, which reads this environment variable to authenticate with the Financial Modeling Prep API.
104
+
105
+ ### Debugging and Logging
106
+
107
+ **⚠️ Development Only**: These logging features are intended for debugging and development, not production use.
108
+
109
+ Two logging modes controlled by environment variables:
110
+
111
+ #### Full Logging Mode
112
+
113
+ ```bash
114
+ FMP_TOOLS_LOG_API_RESULTS=true
115
+ ```
116
+
117
+ Logs: tool name, input parameters, result summary with token count, execution time.
118
+
119
+ #### Data-Only Logging Mode
120
+
121
+ ```bash
122
+ FMP_TOOLS_LOG_DATA_ONLY=true
123
+ ```
124
+
125
+ Logs: result summary and formatted JSON response data.
126
+
127
+ #### Example Output
128
+
129
+ **Full Logging:**
130
+
131
+ ```
132
+ 🔧 getStockQuote: object (~28 tokens)
133
+ ⏱️ Execution Time: 245ms
134
+ ```
135
+
136
+ **Data-Only Logging:**
137
+
138
+ ```
139
+ 📤 Result: { "symbol": "AAPL", "price": 150.25, ... }
140
+ ```
141
+
142
+ **Note**: Both modes are disabled by default. Use only during development.
143
+
144
+ ## Available Tools
145
+
146
+ ### Quote Tools
147
+
148
+ - `getStockQuote` - Get real-time stock quote for a company
149
+
150
+ ### Company Tools
151
+
152
+ - `getCompanyProfile` - Get comprehensive company profile and information
153
+
154
+ ### Financial Tools
155
+
156
+ - `getBalanceSheet` - Get balance sheet statements (annual/quarterly)
157
+ - `getIncomeStatement` - Get income statements (annual/quarterly)
158
+ - `getCashFlowStatement` - Get cash flow statements (annual/quarterly)
159
+ - `getFinancialRatios` - Get financial ratios and metrics (annual/quarterly)
160
+
161
+ ### Stock Tools
162
+
163
+ - `getMarketCap` - Get market capitalization for a company
164
+ - `getStockSplits` - Get historical stock splits for a company
165
+ - `getDividendHistory` - Get dividend history and payments for a company
166
+
167
+ ### Market Tools
168
+
169
+ - `getMarketPerformance` - Get overall market performance data
170
+ - `getSectorPerformance` - Get sector performance data
171
+ - `getGainers` - Get top gaining stocks
172
+ - `getLosers` - Get top losing stocks
173
+ - `getMostActive` - Get most actively traded stocks
174
+
175
+ ### Economic Tools
176
+
177
+ - `getTreasuryRates` - Get treasury rates and yields
178
+ - `getEconomicIndicators` - Get economic indicators (GDP, CPI, unemployment, etc.)
179
+
180
+ ### ETF Tools
181
+
182
+ - `getETFHoldings` - Get holdings for a specific ETF
183
+ - `getETFProfile` - Get ETF profile and information
184
+
185
+ ### Calendar Tools
186
+
187
+ - `getEarningsCalendar` - Get upcoming earnings calendar
188
+ - `getEconomicCalendar` - Get economic calendar events
189
+
190
+ ### Senate & House Trading Tools
191
+
192
+ - `getSenateTrading` - Get recent Senate trading activity
193
+ - `getHouseTrading` - Get recent House trading activity
194
+ - `getSenateTradingByName` - Get Senate trading by politician name
195
+ - `getHouseTradingByName` - Get House trading by politician name
196
+ - `getSenateTradingRSSFeed` - Get Senate trading RSS feed
197
+ - `getHouseTradingRSSFeed` - Get House trading RSS feed
198
+
199
+ ### Institutional Tools
200
+
201
+ - `getInstitutionalHolders` - Get institutional holders for a company
202
+
203
+ ### Insider Trading Tools
204
+
205
+ - `getInsiderTrading` - Get insider trading data for a company
206
+
207
+ ## Using Individual Tools
208
+
209
+ You can import and use specific tool categories or individual tools from either provider:
210
+
211
+ ### Import Specific Categories (Vercel AI)
212
+
213
+ ```typescript
214
+ import { quoteTools, financialTools, marketTools } from 'fmp-ai-tools/vercel-ai';
215
+
216
+ // Use only quote and financial tools
217
+ const selectedTools = {
218
+ ...quoteTools,
219
+ ...financialTools,
220
+ };
221
+
222
+ // Use with Vercel AI SDK
223
+ const result = streamText({
224
+ model: openai('gpt-4o-mini'),
225
+ messages: convertToModelMessages(messages),
226
+ tools: selectedTools,
227
+ });
228
+ ```
229
+
230
+ ### Import Specific Categories (OpenAI)
231
+
232
+ ```typescript
233
+ import { quoteTools, financialTools, marketTools } from 'fmp-ai-tools/openai';
234
+
235
+ // Use only quote and financial tools
236
+ const selectedTools = [...quoteTools, ...financialTools];
237
+
238
+ // Use with OpenAI Agents
239
+ const agent = new Agent({
240
+ name: 'Financial Analyst',
241
+ instructions: 'You are a financial analyst with access to real-time market data.',
242
+ tools: selectedTools,
243
+ });
244
+ ```
245
+
246
+ ### Import Individual Tools
247
+
248
+ ```typescript
249
+ // Vercel AI SDK
250
+ import { getStockQuote, getCompanyProfile } from 'fmp-ai-tools/vercel-ai';
251
+
252
+ // OpenAI Agents
253
+ import { getStockQuote, getCompanyProfile } from 'fmp-ai-tools/openai';
254
+ ```
255
+
256
+ ## Example Tool Usage
257
+
258
+ Here are some example prompts you can use with the tools:
259
+
260
+ **Stock Analysis:**
261
+
262
+ ```
263
+ "Get the current stock quote for Apple (AAPL) and show me their latest balance sheet"
264
+ ```
265
+
266
+ **Market Research:**
267
+
268
+ ```
269
+ "What are the top gaining stocks today and show me the overall market performance?"
270
+ ```
271
+
272
+ **Economic Analysis:**
273
+
274
+ ```
275
+ "Get the current treasury rates and show me the latest GDP data"
276
+ ```
277
+
278
+ **ETF Research:**
279
+
280
+ ```
281
+ "Show me the holdings of SPY ETF and get its profile information"
282
+ ```
283
+
284
+ **Financial Analysis:**
285
+
286
+ ```
287
+ "Get Apple's income statement, cash flow statement, and financial ratios for the last year"
288
+ ```
289
+
290
+ ## Tool Parameters
291
+
292
+ Each tool accepts specific parameters. Here are some common ones:
293
+
294
+ - `symbol` - Stock/ETF symbol (e.g., "AAPL", "SPY")
295
+ - `period` - For financial statements: "annual" or "quarter"
296
+ - `from` - Start date in YYYY-MM-DD format
297
+ - `to` - End date in YYYY-MM-DD format
298
+ - `name` - For economic indicators: specific indicator name
299
+
300
+ ## Error Handling
301
+
302
+ The tools handle API errors gracefully and will return informative error messages if:
303
+
304
+ - The API key is invalid or missing
305
+ - The requested data is not available
306
+ - Rate limits are exceeded
307
+ - Invalid parameters are provided
308
+
309
+ ## Testing Tools
310
+
311
+ Test individual tools:
312
+
313
+ ```bash
314
+ # Test specific tools
315
+ pnpm test:tool getStockQuote
316
+ pnpm test:tool getCompanyProfile
317
+ pnpm test:tool getBalanceSheet
318
+ pnpm test:tool getMarketPerformance
319
+ ```
320
+
321
+ ## For Direct API Access
322
+
323
+ If you need direct access to the FMP API without AI tools, use the `fmp-node-api` package:
324
+
325
+ ```typescript
326
+ import { FMP } from 'fmp-node-api';
327
+
328
+ const fmp = new FMP({ apiKey: 'your_api_key_here' });
329
+
330
+ // Direct API calls
331
+ const quote = await fmp.quote.getQuote('AAPL');
332
+ const profile = await fmp.company.getCompanyProfile('AAPL');
333
+ ```
334
+
335
+ ## License
336
+
337
+ MIT