fmp-node-api 0.0.8 → 0.1.1

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
@@ -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.stock.getQuote({ symbol: 'AAPL' });
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.forex.getQuote({ symbol: 'EURUSD' });
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 (quotes, profiles, historical prices, etc.)
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.crypto`** - Cryptocurrency data
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.company`** - Company information and search
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
- ### Stock Data
154
+ ### Quote Data
82
155
 
83
156
  ```typescript
84
- // Get real-time quote
85
- const quote = await fmp.stock.getQuote({ symbol: 'AAPL' });
157
+ // Get real-time quote for any asset type
158
+ const quote = await fmp.quote.getQuote('AAPL');
86
159
 
87
- // Get company profile
88
- const profile = await fmp.stock.getCompanyProfile({ symbol: 'AAPL' });
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.stock.getHistoricalPrice({
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({ symbol: 'AAPL' });
186
+ const splits = await fmp.stock.getStockSplits('AAPL');
99
187
 
100
188
  // Get dividend history
101
- const dividends = await fmp.stock.getDividendHistory({ symbol: 'AAPL' });
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.forex.getQuote({ symbol: 'EURUSD' });
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.crypto.getQuote({ symbol: 'BTCUSD' });
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({ symbol: 'AAPL' });
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:forex
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?: T;
271
- error?: string;
272
- status?: number;
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
- symbol: 'AAPL',
284
- price: 150.25,
285
- change: 2.15,
286
- changePercent: 1.45,
287
- // ... other fields
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.stock.getQuote({ symbol: 'INVALID' });
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
- console.log('Quote:', quote.data);
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 { StockQuote, CompanyProfile, IncomeStatement } from 'fmp-node-api';
413
+ import { Quote, MarketCap, IncomeStatement } from 'fmp-node-api';
317
414
 
318
415
  // All responses are properly typed
319
- const quote: APIResponse<StockQuote[]> = await fmp.stock.getQuote({
320
- symbol: 'AAPL',
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 quote = await stockEndpoints.getQuote({ symbol: 'AAPL' });
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:forex # Forex endpoint tests only
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:forex # Run forex endpoint tests
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
- │ ├── forex.ts # Forex types
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
- │ └── company.ts # Company types
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
- │ ├── forex.ts
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
- │ └── company.ts
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
- │ │ ├── forex.test.ts
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
@@ -0,0 +1 @@
1
+ var s=class{static isValidSymbol(t){return !t||typeof t!="string"?false:/^[A-Z]{1,5}$/.test(t)}static isValidCryptoSymbol(t){return !t||typeof t!="string"?false:/^[A-Z]{2,10}(USD|EUR|GBP|JPY|CAD|AUD|CHF|CNY)$/.test(t)}static isValidForexPair(t){return !t||typeof t!="string"?false:/^[A-Z]{3}[A-Z]{3}$/.test(t)}static isValidDate(t){if(!t||typeof t!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(t))return false;let i=new Date(t);return !isNaN(i.getTime())&&i.toISOString().split("T")[0]===t}static isValidDateRange(t,e){if(!this.isValidDate(t)||!this.isValidDate(e))return false;let i=new Date(t),r=new Date(e);return i<=r}static isValidResponse(t){return !!(t&&typeof t=="object"&&typeof t.success=="boolean")}static isValidApiKey(t){return !t||typeof t!="string"?false:/^[a-zA-Z0-9]{32,}$/.test(t)}static isValidPeriod(t){return !t||typeof t!="string"?false:["annual","quarter","fy"].includes(t.toLowerCase())}static isValidLimit(t){return typeof t=="number"&&Number.isInteger(t)&&t>0&&t<=1e3}static validateQuoteParams(t){let e=[];return t?(t.symbol?!this.isValidSymbol(t.symbol)&&!this.isValidCryptoSymbol(t.symbol)&&!this.isValidForexPair(t.symbol)&&e.push("Invalid symbol format"):e.push("Symbol is required"),t.from&&!this.isValidDate(t.from)&&e.push("Invalid from date format (expected YYYY-MM-DD)"),t.to&&!this.isValidDate(t.to)&&e.push("Invalid to date format (expected YYYY-MM-DD)"),t.from&&t.to&&!this.isValidDateRange(t.from,t.to)&&e.push("From date must be before or equal to to date"),e):(e.push("Parameters object is required"),e)}static validateFinancialParams(t){let e=[];return t?(t.symbol?this.isValidSymbol(t.symbol)||e.push("Invalid symbol format"):e.push("Symbol is required"),t.period&&!this.isValidPeriod(t.period)&&e.push('Invalid period (must be "annual", "quarter", or "FY")'),t.limit&&!this.isValidLimit(t.limit)&&e.push("Invalid limit (must be a positive integer <= 1000)"),e):(e.push("Parameters object is required"),e)}static validateDateRangeParams(t){let e=[];return t?(t.from&&!this.isValidDate(t.from)&&e.push("Invalid from date format (expected YYYY-MM-DD)"),t.to&&!this.isValidDate(t.to)&&e.push("Invalid to date format (expected YYYY-MM-DD)"),t.from&&t.to&&!this.isValidDateRange(t.from,t.to)&&e.push("From date must be before or equal to to date"),e):(e.push("Parameters object is required"),e)}static throwIfInvalid(t,e="Validation"){if(t.length>0)throw new Error(`${e} failed: ${t.join(", ")}`)}};export{s as a};
@@ -0,0 +1,18 @@
1
+ interface APIResponse<T = unknown> {
2
+ success: boolean;
3
+ data: T | null;
4
+ error: string | null;
5
+ status: number;
6
+ }
7
+ interface FMPConfig {
8
+ apiKey?: string;
9
+ timeout?: number;
10
+ }
11
+ interface SymbolParams {
12
+ symbol: string;
13
+ }
14
+ interface PeriodParams {
15
+ period?: 'annual' | 'quarter';
16
+ }
17
+
18
+ export type { APIResponse as A, FMPConfig as F, PeriodParams as P, SymbolParams as S };
@@ -0,0 +1,18 @@
1
+ interface APIResponse<T = unknown> {
2
+ success: boolean;
3
+ data: T | null;
4
+ error: string | null;
5
+ status: number;
6
+ }
7
+ interface FMPConfig {
8
+ apiKey?: string;
9
+ timeout?: number;
10
+ }
11
+ interface SymbolParams {
12
+ symbol: string;
13
+ }
14
+ interface PeriodParams {
15
+ period?: 'annual' | 'quarter';
16
+ }
17
+
18
+ export type { APIResponse as A, FMPConfig as F, PeriodParams as P, SymbolParams as S };