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

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 FMP Node Wrapper
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 FMP Node Wrapper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,317 +1,317 @@
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
+ ## 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