fmp-node-api 0.0.8 → 0.1.0
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 +155 -51
- package/dist/index.d.mts +2960 -773
- package/dist/index.d.ts +2960 -773
- package/dist/index.js +3324 -790
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3321 -783
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -32,10 +32,17 @@ pnpm add fmp-node-api
|
|
|
32
32
|
```typescript
|
|
33
33
|
import { FMP } from 'fmp-node-api';
|
|
34
34
|
|
|
35
|
+
// Option 1: Use environment variable (recommended)
|
|
36
|
+
const fmp = new FMP(); // Automatically uses FMP_API_KEY from environment
|
|
37
|
+
|
|
38
|
+
// Option 2: Provide API key directly
|
|
35
39
|
const fmp = new FMP({ apiKey: 'your-api-key' });
|
|
36
40
|
|
|
41
|
+
// Option 3: Provide partial config with environment variable fallback
|
|
42
|
+
const fmp = new FMP({ timeout: 15000 }); // Uses FMP_API_KEY from environment
|
|
43
|
+
|
|
37
44
|
// Get stock quote
|
|
38
|
-
const quote = await fmp.
|
|
45
|
+
const quote = await fmp.quote.getQuote('AAPL');
|
|
39
46
|
|
|
40
47
|
// Get financial statements
|
|
41
48
|
const incomeStatement = await fmp.financial.getIncomeStatement({
|
|
@@ -44,7 +51,66 @@ const incomeStatement = await fmp.financial.getIncomeStatement({
|
|
|
44
51
|
});
|
|
45
52
|
|
|
46
53
|
// Get forex data
|
|
47
|
-
const forexQuote = await fmp.
|
|
54
|
+
const forexQuote = await fmp.quote.getQuote('EURUSD');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
The FMP client supports multiple ways to configure your API key:
|
|
60
|
+
|
|
61
|
+
### Environment Variable (Recommended)
|
|
62
|
+
|
|
63
|
+
Set the `FMP_API_KEY` environment variable in your `.env` file or system environment:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# .env file
|
|
67
|
+
FMP_API_KEY=your-api-key-here
|
|
68
|
+
|
|
69
|
+
# Or set in your system
|
|
70
|
+
export FMP_API_KEY=your-api-key-here
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Then initialize the client without any parameters:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { FMP } from 'fmp-node-api';
|
|
77
|
+
|
|
78
|
+
const fmp = new FMP(); // Automatically uses FMP_API_KEY
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Direct Configuration
|
|
82
|
+
|
|
83
|
+
Provide the API key directly in the constructor:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { FMP } from 'fmp-node-api';
|
|
87
|
+
|
|
88
|
+
const fmp = new FMP({
|
|
89
|
+
apiKey: 'your-api-key-here',
|
|
90
|
+
timeout: 10000, // optional
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Mixed Configuration
|
|
95
|
+
|
|
96
|
+
You can provide partial configuration and let the client fall back to environment variables:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { FMP } from 'fmp-node-api';
|
|
100
|
+
|
|
101
|
+
const fmp = new FMP({
|
|
102
|
+
timeout: 15000, // custom timeout
|
|
103
|
+
// apiKey will be loaded from FMP_API_KEY environment variable
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Configuration Options
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
interface FMPConfig {
|
|
111
|
+
apiKey?: string; // Optional: API key (falls back to FMP_API_KEY env var)
|
|
112
|
+
timeout?: number; // Optional: Request timeout in milliseconds (default: 10000)
|
|
113
|
+
}
|
|
48
114
|
```
|
|
49
115
|
|
|
50
116
|
## API Structure
|
|
@@ -56,6 +122,10 @@ The library is organized into logical modules for easy navigation and usage:
|
|
|
56
122
|
```typescript
|
|
57
123
|
import { FMP } from 'fmp-node-api';
|
|
58
124
|
|
|
125
|
+
// Using environment variable (recommended)
|
|
126
|
+
const fmp = new FMP();
|
|
127
|
+
|
|
128
|
+
// Or with explicit configuration
|
|
59
129
|
const fmp = new FMP({
|
|
60
130
|
apiKey: 'your-api-key',
|
|
61
131
|
timeout: 10000, // optional
|
|
@@ -65,40 +135,68 @@ const fmp = new FMP({
|
|
|
65
135
|
### Available Modules
|
|
66
136
|
|
|
67
137
|
- **`fmp.quote`** - Quote data for stocks, forex, crypto, commodities, and ETFs
|
|
68
|
-
- **`fmp.stock`** - Stock market data (
|
|
138
|
+
- **`fmp.stock`** - Stock market data (market cap, splits, dividends, real-time prices)
|
|
69
139
|
- **`fmp.financial`** - Financial statements (income, balance sheet, cash flow)
|
|
70
|
-
- **`fmp.
|
|
140
|
+
- **`fmp.company`** - Company information and profiles
|
|
71
141
|
- **`fmp.etf`** - ETF data and holdings
|
|
72
142
|
- **`fmp.mutualFund`** - Mutual fund data
|
|
73
143
|
- **`fmp.economic`** - Economic indicators
|
|
74
144
|
- **`fmp.market`** - Market-wide data and performance
|
|
75
145
|
- **`fmp.list`** - Stock lists and indices
|
|
76
146
|
- **`fmp.calendar`** - Earnings and economic calendar
|
|
77
|
-
- **`fmp.
|
|
147
|
+
- **`fmp.senateHouse`** - Congressional trading data
|
|
148
|
+
- **`fmp.institutional`** - Form 13F filings and institutional ownership
|
|
149
|
+
- **`fmp.insider`** - Insider trading data
|
|
150
|
+
- **`fmp.sec`** - SEC filings and industry classification
|
|
78
151
|
|
|
79
152
|
## Usage Examples
|
|
80
153
|
|
|
81
|
-
###
|
|
154
|
+
### Quote Data
|
|
82
155
|
|
|
83
156
|
```typescript
|
|
84
|
-
// Get real-time quote
|
|
85
|
-
const quote = await fmp.
|
|
157
|
+
// Get real-time quote for any asset type
|
|
158
|
+
const quote = await fmp.quote.getQuote('AAPL');
|
|
86
159
|
|
|
87
|
-
// Get
|
|
88
|
-
const
|
|
160
|
+
// Get multiple quotes
|
|
161
|
+
const quotes = await fmp.quote.getQuotes(['AAPL', 'MSFT', 'GOOGL']);
|
|
89
162
|
|
|
90
163
|
// Get historical prices
|
|
91
|
-
const historical = await fmp.
|
|
164
|
+
const historical = await fmp.quote.getHistoricalPrice({
|
|
92
165
|
symbol: 'AAPL',
|
|
93
166
|
from: '2024-01-01',
|
|
94
167
|
to: '2024-12-31',
|
|
95
168
|
});
|
|
96
169
|
|
|
170
|
+
// Get intraday data
|
|
171
|
+
const intraday = await fmp.quote.getIntraday({
|
|
172
|
+
symbol: 'AAPL',
|
|
173
|
+
interval: '1hour',
|
|
174
|
+
from: '2024-01-01',
|
|
175
|
+
to: '2024-01-02',
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Stock Data
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// Get market capitalization
|
|
183
|
+
const marketCap = await fmp.stock.getMarketCap('AAPL');
|
|
184
|
+
|
|
97
185
|
// Get stock splits
|
|
98
|
-
const splits = await fmp.stock.getStockSplits(
|
|
186
|
+
const splits = await fmp.stock.getStockSplits('AAPL');
|
|
99
187
|
|
|
100
188
|
// Get dividend history
|
|
101
|
-
const dividends = await fmp.stock.getDividendHistory(
|
|
189
|
+
const dividends = await fmp.stock.getDividendHistory('AAPL');
|
|
190
|
+
|
|
191
|
+
// Get real-time price data
|
|
192
|
+
const realTimePrice = await fmp.stock.getRealTimePrice(['AAPL', 'MSFT', 'GOOGL']);
|
|
193
|
+
|
|
194
|
+
// Get full real-time price data
|
|
195
|
+
const fullRealTimeData = await fmp.stock.getRealTimePriceForMultipleStocks([
|
|
196
|
+
'AAPL',
|
|
197
|
+
'MSFT',
|
|
198
|
+
'GOOGL',
|
|
199
|
+
]);
|
|
102
200
|
```
|
|
103
201
|
|
|
104
202
|
### Financial Statements
|
|
@@ -176,12 +274,10 @@ const unemployment = await fmp.economic.getUnemployment();
|
|
|
176
274
|
|
|
177
275
|
```typescript
|
|
178
276
|
// Forex
|
|
179
|
-
const forexQuote = await fmp.
|
|
180
|
-
const forexList = await fmp.forex.getForexList();
|
|
277
|
+
const forexQuote = await fmp.quote.getQuote('EURUSD');
|
|
181
278
|
|
|
182
279
|
// Cryptocurrency
|
|
183
|
-
const cryptoQuote = await fmp.
|
|
184
|
-
const cryptoList = await fmp.crypto.getCryptoList();
|
|
280
|
+
const cryptoQuote = await fmp.quote.getQuote('BTCUSD');
|
|
185
281
|
|
|
186
282
|
// Stock lists and indices
|
|
187
283
|
const sp500 = await fmp.list.getSP500();
|
|
@@ -204,7 +300,7 @@ const economic = await fmp.calendar.getEconomicCalendar({
|
|
|
204
300
|
const companies = await fmp.company.searchCompany({ query: 'Apple' });
|
|
205
301
|
|
|
206
302
|
// Company profile
|
|
207
|
-
const companyProfile = await fmp.company.getCompanyProfile(
|
|
303
|
+
const companyProfile = await fmp.company.getCompanyProfile('AAPL');
|
|
208
304
|
```
|
|
209
305
|
|
|
210
306
|
## Testing
|
|
@@ -244,7 +340,7 @@ pnpm test:integration
|
|
|
244
340
|
pnpm test:stock
|
|
245
341
|
pnpm test:financial
|
|
246
342
|
pnpm test:market
|
|
247
|
-
pnpm test:
|
|
343
|
+
pnpm test:quote
|
|
248
344
|
pnpm test:economic
|
|
249
345
|
pnpm test:list
|
|
250
346
|
pnpm test:calendar
|
|
@@ -267,9 +363,9 @@ All API methods return a standardized response format:
|
|
|
267
363
|
```typescript
|
|
268
364
|
interface APIResponse<T> {
|
|
269
365
|
success: boolean;
|
|
270
|
-
data
|
|
271
|
-
error
|
|
272
|
-
status
|
|
366
|
+
data: T | null;
|
|
367
|
+
error: string | null;
|
|
368
|
+
status: number;
|
|
273
369
|
}
|
|
274
370
|
```
|
|
275
371
|
|
|
@@ -278,15 +374,14 @@ interface APIResponse<T> {
|
|
|
278
374
|
```typescript
|
|
279
375
|
{
|
|
280
376
|
success: true,
|
|
281
|
-
data:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
],
|
|
377
|
+
data: {
|
|
378
|
+
symbol: 'AAPL',
|
|
379
|
+
price: 150.25,
|
|
380
|
+
change: 2.15,
|
|
381
|
+
changePercent: 1.45,
|
|
382
|
+
// ... other fields
|
|
383
|
+
},
|
|
384
|
+
error: null,
|
|
290
385
|
status: 200
|
|
291
386
|
}
|
|
292
387
|
```
|
|
@@ -295,14 +390,16 @@ interface APIResponse<T> {
|
|
|
295
390
|
|
|
296
391
|
```typescript
|
|
297
392
|
try {
|
|
298
|
-
const quote = await fmp.
|
|
393
|
+
const quote = await fmp.quote.getQuote('INVALID');
|
|
299
394
|
|
|
300
395
|
if (!quote.success) {
|
|
301
396
|
console.error('API Error:', quote.error);
|
|
302
397
|
return;
|
|
303
398
|
}
|
|
304
399
|
|
|
305
|
-
|
|
400
|
+
if (quote.data) {
|
|
401
|
+
console.log('Quote:', quote.data);
|
|
402
|
+
}
|
|
306
403
|
} catch (error) {
|
|
307
404
|
console.error('Network Error:', error);
|
|
308
405
|
}
|
|
@@ -313,15 +410,11 @@ try {
|
|
|
313
410
|
The library provides full TypeScript support with comprehensive type definitions:
|
|
314
411
|
|
|
315
412
|
```typescript
|
|
316
|
-
import {
|
|
413
|
+
import { Quote, MarketCap, IncomeStatement } from 'fmp-node-api';
|
|
317
414
|
|
|
318
415
|
// All responses are properly typed
|
|
319
|
-
const quote: APIResponse<
|
|
320
|
-
|
|
321
|
-
});
|
|
322
|
-
const profile: APIResponse<CompanyProfile[]> = await fmp.stock.getCompanyProfile({
|
|
323
|
-
symbol: 'AAPL',
|
|
324
|
-
});
|
|
416
|
+
const quote: APIResponse<Quote> = await fmp.quote.getQuote('AAPL');
|
|
417
|
+
const marketCap: APIResponse<MarketCap> = await fmp.stock.getMarketCap('AAPL');
|
|
325
418
|
const income: APIResponse<IncomeStatement[]> = await fmp.financial.getIncomeStatement({
|
|
326
419
|
symbol: 'AAPL',
|
|
327
420
|
});
|
|
@@ -359,6 +452,12 @@ const formattedTimestamp = formatTimestamp(1705276800); // "1/15/2024, 12:00:00
|
|
|
359
452
|
```typescript
|
|
360
453
|
import { FMPClient } from 'fmp-node-api';
|
|
361
454
|
|
|
455
|
+
// Using environment variable
|
|
456
|
+
const client = new FMPClient({
|
|
457
|
+
timeout: 15000, // optional, apiKey from FMP_API_KEY env var
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// Or with explicit API key
|
|
362
461
|
const client = new FMPClient({
|
|
363
462
|
apiKey: 'your-api-key',
|
|
364
463
|
timeout: 15000, // optional
|
|
@@ -366,7 +465,7 @@ const client = new FMPClient({
|
|
|
366
465
|
|
|
367
466
|
// Use individual endpoint classes
|
|
368
467
|
const stockEndpoints = new StockEndpoints(client);
|
|
369
|
-
const
|
|
468
|
+
const marketCap = await stockEndpoints.getMarketCap('AAPL');
|
|
370
469
|
```
|
|
371
470
|
|
|
372
471
|
### Direct API Calls
|
|
@@ -393,7 +492,7 @@ pnpm test:endpoints # All endpoint tests
|
|
|
393
492
|
pnpm test:stock # Stock endpoint tests only
|
|
394
493
|
pnpm test:financial # Financial endpoint tests only
|
|
395
494
|
pnpm test:market # Market endpoint tests only
|
|
396
|
-
pnpm test:
|
|
495
|
+
pnpm test:quote # Quote endpoint tests only
|
|
397
496
|
pnpm test:economic # Economic endpoint tests only
|
|
398
497
|
pnpm test:list # List endpoint tests only
|
|
399
498
|
pnpm test:calendar # Calendar endpoint tests only
|
|
@@ -458,7 +557,7 @@ pnpm test:endpoints # Run all endpoint tests
|
|
|
458
557
|
pnpm test:stock # Run stock endpoint tests
|
|
459
558
|
pnpm test:financial # Run financial endpoint tests
|
|
460
559
|
pnpm test:market # Run market endpoint tests
|
|
461
|
-
pnpm test:
|
|
560
|
+
pnpm test:quote # Run quote endpoint tests
|
|
462
561
|
pnpm test:economic # Run economic endpoint tests
|
|
463
562
|
pnpm test:list # Run list endpoint tests
|
|
464
563
|
pnpm test:calendar # Run calendar endpoint tests
|
|
@@ -488,28 +587,34 @@ src/
|
|
|
488
587
|
│ ├── common.ts # Common types
|
|
489
588
|
│ ├── stock.ts # Stock types
|
|
490
589
|
│ ├── financial.ts # Financial types
|
|
491
|
-
│ ├──
|
|
492
|
-
│ ├── crypto.ts # Crypto types
|
|
590
|
+
│ ├── quote.ts # Quote types
|
|
493
591
|
│ ├── etf.ts # ETF types
|
|
494
592
|
│ ├── mutual-fund.ts # Mutual fund types
|
|
495
593
|
│ ├── economic.ts # Economic types
|
|
496
594
|
│ ├── market.ts # Market types
|
|
497
595
|
│ ├── list.ts # List types
|
|
498
596
|
│ ├── calendar.ts # Calendar types
|
|
499
|
-
│
|
|
597
|
+
│ ├── company.ts # Company types
|
|
598
|
+
│ ├── senate-house.ts # Senate house types
|
|
599
|
+
│ ├── institutional.ts # Institutional types
|
|
600
|
+
│ ├── insider.ts # Insider types
|
|
601
|
+
│ └── sec.ts # SEC types
|
|
500
602
|
├── endpoints/ # API endpoint classes
|
|
501
603
|
│ ├── index.ts
|
|
502
604
|
│ ├── stock.ts
|
|
503
605
|
│ ├── financial.ts
|
|
504
|
-
│ ├──
|
|
505
|
-
│ ├── crypto.ts
|
|
606
|
+
│ ├── quote.ts
|
|
506
607
|
│ ├── etf.ts
|
|
507
608
|
│ ├── mutual-fund.ts
|
|
508
609
|
│ ├── economic.ts
|
|
509
610
|
│ ├── market.ts
|
|
510
611
|
│ ├── list.ts
|
|
511
612
|
│ ├── calendar.ts
|
|
512
|
-
│
|
|
613
|
+
│ ├── company.ts
|
|
614
|
+
│ ├── senate-house.ts
|
|
615
|
+
│ ├── institutional.ts
|
|
616
|
+
│ ├── insider.ts
|
|
617
|
+
│ └── sec.ts
|
|
513
618
|
├── utils/ # Utility functions
|
|
514
619
|
│ ├── index.ts
|
|
515
620
|
│ ├── validation.ts # Input validation
|
|
@@ -523,9 +628,8 @@ src/
|
|
|
523
628
|
│ │ ├── stock.test.ts
|
|
524
629
|
│ │ ├── financial.test.ts
|
|
525
630
|
│ │ ├── market.test.ts
|
|
526
|
-
│ │ ├──
|
|
631
|
+
│ │ ├── quote.test.ts
|
|
527
632
|
│ │ ├── economic.test.ts
|
|
528
|
-
│ │ ├── crypto.test.ts
|
|
529
633
|
│ │ ├── etf.test.ts
|
|
530
634
|
│ │ ├── mutual-fund.test.ts
|
|
531
635
|
│ │ ├── list.test.ts
|