fmp-node-api 0.0.2
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 +21 -0
- package/README.md +622 -0
- package/dist/index.d.mts +1431 -0
- package/dist/index.d.ts +1431 -0
- package/dist/index.js +762 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +717 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
// src/client.ts
|
|
4
|
+
var FMPClient = class {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.apiKey = config.apiKey;
|
|
7
|
+
this.baseURL = config.baseURL || "https://financialmodelingprep.com/api/v3";
|
|
8
|
+
this.client = axios.create({
|
|
9
|
+
baseURL: this.baseURL,
|
|
10
|
+
timeout: config.timeout || 1e4,
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json"
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
this.client.interceptors.request.use((config2) => {
|
|
16
|
+
config2.params = {
|
|
17
|
+
...config2.params,
|
|
18
|
+
apikey: this.apiKey
|
|
19
|
+
};
|
|
20
|
+
return config2;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Make a GET request to the API
|
|
25
|
+
*/
|
|
26
|
+
async get(endpoint, params) {
|
|
27
|
+
try {
|
|
28
|
+
const response = await this.client.get(endpoint, { params });
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
data: response.data,
|
|
32
|
+
status: response.status
|
|
33
|
+
};
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
error: error.message || "Unknown error occurred",
|
|
38
|
+
status: error.response?.status || 500
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Make a POST request to the API
|
|
44
|
+
*/
|
|
45
|
+
async post(endpoint, data, config) {
|
|
46
|
+
try {
|
|
47
|
+
const response = await this.client.post(endpoint, data, config);
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
data: response.data,
|
|
51
|
+
status: response.status
|
|
52
|
+
};
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: error.message || "Unknown error occurred",
|
|
57
|
+
status: error.response?.status || 500
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the underlying axios instance for advanced usage
|
|
63
|
+
*/
|
|
64
|
+
getAxiosInstance() {
|
|
65
|
+
return this.client;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/shared.ts
|
|
70
|
+
var FMPError = class extends Error {
|
|
71
|
+
constructor(message, status, code) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.status = status;
|
|
74
|
+
this.code = code;
|
|
75
|
+
this.name = "FMPError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function validateApiKey(apiKey) {
|
|
79
|
+
if (!apiKey || typeof apiKey !== "string") {
|
|
80
|
+
throw new FMPError("API key is required and must be a string");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateSymbol(symbol) {
|
|
84
|
+
if (!symbol || typeof symbol !== "string") {
|
|
85
|
+
throw new FMPError("Symbol is required and must be a string");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var FMP_BASE_URL = "https://financialmodelingprep.com/api/v3";
|
|
89
|
+
var FMP_BASE_URL_V4 = "https://financialmodelingprep.com/api/v4";
|
|
90
|
+
var Period = /* @__PURE__ */ ((Period2) => {
|
|
91
|
+
Period2["ANNUAL"] = "annual";
|
|
92
|
+
Period2["QUARTER"] = "quarter";
|
|
93
|
+
return Period2;
|
|
94
|
+
})(Period || {});
|
|
95
|
+
var Exchange = /* @__PURE__ */ ((Exchange2) => {
|
|
96
|
+
Exchange2["NYSE"] = "NYSE";
|
|
97
|
+
Exchange2["NASDAQ"] = "NASDAQ";
|
|
98
|
+
Exchange2["AMEX"] = "AMEX";
|
|
99
|
+
Exchange2["TSX"] = "TSX";
|
|
100
|
+
Exchange2["LSE"] = "LSE";
|
|
101
|
+
return Exchange2;
|
|
102
|
+
})(Exchange || {});
|
|
103
|
+
|
|
104
|
+
// src/utils/validation.ts
|
|
105
|
+
function validateApiKey2(apiKey) {
|
|
106
|
+
if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
|
|
107
|
+
throw new FMPError("API key is required and must be a non-empty string");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function validateDate(date) {
|
|
111
|
+
if (!date || typeof date !== "string") {
|
|
112
|
+
throw new FMPError("Date is required and must be a string");
|
|
113
|
+
}
|
|
114
|
+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
115
|
+
if (!dateRegex.test(date)) {
|
|
116
|
+
throw new FMPError("Invalid date format. Use YYYY-MM-DD format");
|
|
117
|
+
}
|
|
118
|
+
const parsedDate = new Date(date);
|
|
119
|
+
if (isNaN(parsedDate.getTime())) {
|
|
120
|
+
throw new FMPError("Invalid date");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function validatePeriod(period) {
|
|
124
|
+
if (period && !["annual", "quarter"].includes(period)) {
|
|
125
|
+
throw new FMPError('Period must be either "annual" or "quarter"');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function validateLimit(limit) {
|
|
129
|
+
if (limit !== void 0 && (typeof limit !== "number" || limit < 1 || limit > 1e3)) {
|
|
130
|
+
throw new FMPError("Limit must be a number between 1 and 1000");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function validatePage(page) {
|
|
134
|
+
if (page !== void 0 && (typeof page !== "number" || page < 0)) {
|
|
135
|
+
throw new FMPError("Page must be a non-negative number");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/endpoints/stock.ts
|
|
140
|
+
var StockEndpoints = class {
|
|
141
|
+
constructor(client) {
|
|
142
|
+
this.client = client;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get real-time stock quote
|
|
146
|
+
*/
|
|
147
|
+
async getQuote({ symbol }) {
|
|
148
|
+
return this.client.get(`/quote/${symbol}`);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get company profile
|
|
152
|
+
*/
|
|
153
|
+
async getCompanyProfile({ symbol }) {
|
|
154
|
+
return this.client.get(`/profile/${symbol}`);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get historical stock prices
|
|
158
|
+
*/
|
|
159
|
+
async getHistoricalPrice({
|
|
160
|
+
symbol,
|
|
161
|
+
from,
|
|
162
|
+
to
|
|
163
|
+
}) {
|
|
164
|
+
const params = new URLSearchParams();
|
|
165
|
+
if (from) params.append("from", from);
|
|
166
|
+
if (to) params.append("to", to);
|
|
167
|
+
const queryString = params.toString();
|
|
168
|
+
return this.client.get(
|
|
169
|
+
`/historical-price-full/${symbol}${queryString ? `?${queryString}` : ""}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get list of all stocks
|
|
174
|
+
*/
|
|
175
|
+
async getStockList() {
|
|
176
|
+
return this.client.get("/stock/list");
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get market capitalization
|
|
180
|
+
*/
|
|
181
|
+
async getMarketCap({ symbol }) {
|
|
182
|
+
return this.client.get(`/market-capitalization/${symbol}`);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get earnings calendar
|
|
186
|
+
*/
|
|
187
|
+
async getEarningsCalendar(params) {
|
|
188
|
+
const queryParams = {};
|
|
189
|
+
if (params.from) queryParams.from = params.from;
|
|
190
|
+
if (params.to) queryParams.to = params.to;
|
|
191
|
+
return this.client.get("/earning_calendar", queryParams);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get stock splits
|
|
195
|
+
*/
|
|
196
|
+
async getStockSplits({ symbol }) {
|
|
197
|
+
return this.client.get(`/stock_split_calendar/${symbol}`);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get dividend history
|
|
201
|
+
*/
|
|
202
|
+
async getDividendHistory({ symbol }) {
|
|
203
|
+
const response = await this.client.get(`/historical-price-full/stock_dividend/${symbol}`);
|
|
204
|
+
return {
|
|
205
|
+
...response,
|
|
206
|
+
data: response.success && response.data && Array.isArray(response.data.historical) ? response.data.historical : []
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/endpoints/financial.ts
|
|
212
|
+
var FinancialEndpoints = class {
|
|
213
|
+
constructor(client) {
|
|
214
|
+
this.client = client;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get income statement
|
|
218
|
+
*/
|
|
219
|
+
async getIncomeStatement({
|
|
220
|
+
symbol,
|
|
221
|
+
period = "annual",
|
|
222
|
+
limit = 5
|
|
223
|
+
}) {
|
|
224
|
+
return this.client.get(`/income-statement/${symbol}?period=${period}&limit=${limit}`);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get balance sheet
|
|
228
|
+
*/
|
|
229
|
+
async getBalanceSheet({
|
|
230
|
+
symbol,
|
|
231
|
+
period = "annual",
|
|
232
|
+
limit = 5
|
|
233
|
+
}) {
|
|
234
|
+
return this.client.get(`/balance-sheet-statement/${symbol}?period=${period}&limit=${limit}`);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get cash flow statement
|
|
238
|
+
*/
|
|
239
|
+
async getCashFlowStatement({
|
|
240
|
+
symbol,
|
|
241
|
+
period = "annual",
|
|
242
|
+
limit = 5
|
|
243
|
+
}) {
|
|
244
|
+
return this.client.get(`/cash-flow-statement/${symbol}?period=${period}&limit=${limit}`);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get key metrics
|
|
248
|
+
*/
|
|
249
|
+
async getKeyMetrics({
|
|
250
|
+
symbol,
|
|
251
|
+
period = "annual",
|
|
252
|
+
limit = 5
|
|
253
|
+
}) {
|
|
254
|
+
return this.client.get(`/key-metrics/${symbol}?period=${period}&limit=${limit}`);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get financial ratios
|
|
258
|
+
*/
|
|
259
|
+
async getFinancialRatios({
|
|
260
|
+
symbol,
|
|
261
|
+
period = "annual",
|
|
262
|
+
limit = 5
|
|
263
|
+
}) {
|
|
264
|
+
return this.client.get(`/ratios/${symbol}?period=${period}&limit=${limit}`);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get enterprise value
|
|
268
|
+
*/
|
|
269
|
+
async getEnterpriseValue({
|
|
270
|
+
symbol,
|
|
271
|
+
period = "annual",
|
|
272
|
+
limit = 5
|
|
273
|
+
}) {
|
|
274
|
+
return this.client.get(`/enterprise-value/${symbol}?period=${period}&limit=${limit}`);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// src/endpoints/forex.ts
|
|
279
|
+
var ForexEndpoints = class {
|
|
280
|
+
constructor(client) {
|
|
281
|
+
this.client = client;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get real-time forex quote
|
|
285
|
+
*/
|
|
286
|
+
async getQuote(params) {
|
|
287
|
+
return this.client.get(`/quote/${params.symbol}`);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get historical forex data
|
|
291
|
+
*/
|
|
292
|
+
async getHistoricalPrice(params) {
|
|
293
|
+
const queryParams = {};
|
|
294
|
+
if (params.from) queryParams.from = params.from;
|
|
295
|
+
if (params.to) queryParams.to = params.to;
|
|
296
|
+
if (params.timeseries) queryParams.timeseries = params.timeseries;
|
|
297
|
+
return this.client.get(`/historical-price-full/${params.symbol}`, queryParams);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get list of all forex pairs
|
|
301
|
+
* Using the forex-specific endpoint
|
|
302
|
+
*/
|
|
303
|
+
async getForexList() {
|
|
304
|
+
try {
|
|
305
|
+
const response = await this.client.get("/forex-list");
|
|
306
|
+
if (!response.success || !response.data) {
|
|
307
|
+
const fallbackResponse = await this.client.get("/forex");
|
|
308
|
+
return {
|
|
309
|
+
...fallbackResponse,
|
|
310
|
+
data: Array.isArray(fallbackResponse.data) ? fallbackResponse.data : Array.isArray(fallbackResponse.data?.forexList) ? fallbackResponse.data.forexList : []
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
...response,
|
|
315
|
+
data: Array.isArray(response.data) ? response.data : Array.isArray(response.data?.forexList) ? response.data.forexList : []
|
|
316
|
+
};
|
|
317
|
+
} catch (error) {
|
|
318
|
+
return {
|
|
319
|
+
success: false,
|
|
320
|
+
error: "Failed to fetch forex pairs",
|
|
321
|
+
status: 500,
|
|
322
|
+
data: []
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get forex rates for a specific currency
|
|
328
|
+
*/
|
|
329
|
+
async getForexRates(baseCurrency = "USD") {
|
|
330
|
+
return this.client.get(`/forex/${baseCurrency}`);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get forex rates for all currencies
|
|
334
|
+
*/
|
|
335
|
+
async getAllForexRates() {
|
|
336
|
+
return this.client.get("/forex");
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/endpoints/crypto.ts
|
|
341
|
+
var CryptoEndpoints = class {
|
|
342
|
+
constructor(client) {
|
|
343
|
+
this.client = client;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get real-time crypto quote
|
|
347
|
+
*/
|
|
348
|
+
async getQuote(params) {
|
|
349
|
+
return this.client.get(`/quote/${params.symbol}`);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Get historical crypto data
|
|
353
|
+
*/
|
|
354
|
+
async getHistoricalPrice(params) {
|
|
355
|
+
const queryParams = {};
|
|
356
|
+
if (params.from) queryParams.from = params.from;
|
|
357
|
+
if (params.to) queryParams.to = params.to;
|
|
358
|
+
if (params.timeseries) queryParams.timeseries = params.timeseries;
|
|
359
|
+
return this.client.get(`/historical-price-full/${params.symbol}`, queryParams);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Get list of all cryptocurrencies
|
|
363
|
+
*/
|
|
364
|
+
async getCryptoList() {
|
|
365
|
+
return this.client.get("/cryptocurrency");
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// src/endpoints/etf.ts
|
|
370
|
+
var ETFEndpoints = class {
|
|
371
|
+
constructor(client) {
|
|
372
|
+
this.client = client;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get real-time ETF quote
|
|
376
|
+
*/
|
|
377
|
+
async getQuote(params) {
|
|
378
|
+
return this.client.get(`/quote/${params.symbol}`);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get ETF profile
|
|
382
|
+
*/
|
|
383
|
+
async getProfile(params) {
|
|
384
|
+
return this.client.get(`/profile/${params.symbol}`);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get ETF holdings
|
|
388
|
+
*/
|
|
389
|
+
async getHoldings(params) {
|
|
390
|
+
const queryParams = {};
|
|
391
|
+
if (params.limit) queryParams.limit = params.limit;
|
|
392
|
+
if (params.page) queryParams.page = params.page;
|
|
393
|
+
return this.client.get(`/etf-holder/${params.symbol}`, queryParams);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get list of all ETFs
|
|
397
|
+
*/
|
|
398
|
+
async getETFList() {
|
|
399
|
+
return this.client.get("/etf/list");
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/endpoints/mutual-fund.ts
|
|
404
|
+
var MutualFundEndpoints = class {
|
|
405
|
+
constructor(client) {
|
|
406
|
+
this.client = client;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Get real-time mutual fund quote
|
|
410
|
+
*/
|
|
411
|
+
async getQuote(params) {
|
|
412
|
+
return this.client.get(`/quote/${params.symbol}`);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Get mutual fund profile
|
|
416
|
+
*/
|
|
417
|
+
async getProfile(params) {
|
|
418
|
+
return this.client.get(`/profile/${params.symbol}`);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Get mutual fund holdings
|
|
422
|
+
*/
|
|
423
|
+
async getHoldings(params) {
|
|
424
|
+
const queryParams = {};
|
|
425
|
+
if (params.limit) queryParams.limit = params.limit;
|
|
426
|
+
if (params.page) queryParams.page = params.page;
|
|
427
|
+
return this.client.get(`/mutual-fund-holder/${params.symbol}`, queryParams);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Get list of all mutual funds
|
|
431
|
+
*/
|
|
432
|
+
async getMutualFundList() {
|
|
433
|
+
return this.client.get("/mutual-fund/list");
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// src/endpoints/bond.ts
|
|
438
|
+
var BondEndpoints = class {
|
|
439
|
+
constructor(client) {
|
|
440
|
+
this.client = client;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Get real-time bond quote
|
|
444
|
+
*/
|
|
445
|
+
async getQuote(params) {
|
|
446
|
+
return this.client.get(`/quote/${params.symbol}`);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get historical bond data
|
|
450
|
+
*/
|
|
451
|
+
async getHistoricalPrice(params) {
|
|
452
|
+
const queryParams = {};
|
|
453
|
+
if (params.from) queryParams.from = params.from;
|
|
454
|
+
if (params.to) queryParams.to = params.to;
|
|
455
|
+
if (params.timeseries) queryParams.timeseries = params.timeseries;
|
|
456
|
+
return this.client.get(`/historical-price-full/${params.symbol}`, queryParams);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get list of all bonds
|
|
460
|
+
*/
|
|
461
|
+
async getBondList() {
|
|
462
|
+
return this.client.get("/bond/list");
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// src/endpoints/economic.ts
|
|
467
|
+
var EconomicEndpoints = class {
|
|
468
|
+
constructor(client) {
|
|
469
|
+
this.client = client;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Get treasury rates
|
|
473
|
+
*/
|
|
474
|
+
async getTreasuryRates(params = {}) {
|
|
475
|
+
const queryParams = {};
|
|
476
|
+
if (params.from) queryParams.from = params.from;
|
|
477
|
+
if (params.to) queryParams.to = params.to;
|
|
478
|
+
return this.client.get("/treasury-rates", queryParams);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Get federal funds rate
|
|
482
|
+
*/
|
|
483
|
+
async getFederalFundsRate(params = {}) {
|
|
484
|
+
const queryParams = {};
|
|
485
|
+
if (params.from) queryParams.from = params.from;
|
|
486
|
+
if (params.to) queryParams.to = params.to;
|
|
487
|
+
return this.client.get("/federal-funds-rate", queryParams);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Get CPI data
|
|
491
|
+
*/
|
|
492
|
+
async getCPI(params = {}) {
|
|
493
|
+
const queryParams = {};
|
|
494
|
+
if (params.from) queryParams.from = params.from;
|
|
495
|
+
if (params.to) queryParams.to = params.to;
|
|
496
|
+
return this.client.get("/economic-indicator/cpi", queryParams);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Get GDP data
|
|
500
|
+
*/
|
|
501
|
+
async getGDP(params = {}) {
|
|
502
|
+
const queryParams = {};
|
|
503
|
+
if (params.from) queryParams.from = params.from;
|
|
504
|
+
if (params.to) queryParams.to = params.to;
|
|
505
|
+
return this.client.get("/economic-indicator/gdp", queryParams);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Get unemployment data
|
|
509
|
+
*/
|
|
510
|
+
async getUnemployment(params = {}) {
|
|
511
|
+
const queryParams = {};
|
|
512
|
+
if (params.from) queryParams.from = params.from;
|
|
513
|
+
if (params.to) queryParams.to = params.to;
|
|
514
|
+
return this.client.get("/economic-indicator/unemployment", queryParams);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/endpoints/market.ts
|
|
519
|
+
var MarketEndpoints = class {
|
|
520
|
+
constructor(client) {
|
|
521
|
+
this.client = client;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Get market hours
|
|
525
|
+
*/
|
|
526
|
+
async getMarketHours() {
|
|
527
|
+
return this.client.get("/market-hours");
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Get market performance
|
|
531
|
+
*/
|
|
532
|
+
async getMarketPerformance() {
|
|
533
|
+
return this.client.get("/market-performance");
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Get market gainers
|
|
537
|
+
*/
|
|
538
|
+
async getGainers() {
|
|
539
|
+
return this.client.get("/gainers");
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Get market losers
|
|
543
|
+
*/
|
|
544
|
+
async getLosers() {
|
|
545
|
+
return this.client.get("/losers");
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Get most active stocks
|
|
549
|
+
*/
|
|
550
|
+
async getMostActive() {
|
|
551
|
+
return this.client.get("/most-active");
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get sector performance
|
|
555
|
+
*/
|
|
556
|
+
async getSectorPerformance() {
|
|
557
|
+
return this.client.get("/sector-performance");
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Get market index data
|
|
561
|
+
*/
|
|
562
|
+
async getMarketIndex(params = {}) {
|
|
563
|
+
const queryParams = {};
|
|
564
|
+
if (params.from) queryParams.from = params.from;
|
|
565
|
+
if (params.to) queryParams.to = params.to;
|
|
566
|
+
return this.client.get("/market-index", queryParams);
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// src/fmp.ts
|
|
571
|
+
var FMP = class {
|
|
572
|
+
constructor(config) {
|
|
573
|
+
validateApiKey2(config.apiKey);
|
|
574
|
+
const client = new FMPClient(config);
|
|
575
|
+
this.stock = new StockEndpoints(client);
|
|
576
|
+
this.financial = new FinancialEndpoints(client);
|
|
577
|
+
this.forex = new ForexEndpoints(client);
|
|
578
|
+
this.crypto = new CryptoEndpoints(client);
|
|
579
|
+
this.etf = new ETFEndpoints(client);
|
|
580
|
+
this.mutualFund = new MutualFundEndpoints(client);
|
|
581
|
+
this.bond = new BondEndpoints(client);
|
|
582
|
+
this.economic = new EconomicEndpoints(client);
|
|
583
|
+
this.market = new MarketEndpoints(client);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Get the underlying client instance for advanced usage
|
|
587
|
+
*/
|
|
588
|
+
getClient() {
|
|
589
|
+
return this.stock["client"];
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
// src/types/common.ts
|
|
594
|
+
var FMP_STABLE_URL = "https://financialmodelingprep.com/stable";
|
|
595
|
+
|
|
596
|
+
// src/utils/formatting.ts
|
|
597
|
+
function formatCurrency(value, currency = "USD") {
|
|
598
|
+
return new Intl.NumberFormat("en-US", {
|
|
599
|
+
style: "currency",
|
|
600
|
+
currency
|
|
601
|
+
}).format(value);
|
|
602
|
+
}
|
|
603
|
+
function formatPercentage(value, decimals = 2) {
|
|
604
|
+
return `${value.toFixed(decimals)}%`;
|
|
605
|
+
}
|
|
606
|
+
function formatLargeNumber(value) {
|
|
607
|
+
if (value >= 1e12) {
|
|
608
|
+
return `${(value / 1e12).toFixed(2)}T`;
|
|
609
|
+
} else if (value >= 1e9) {
|
|
610
|
+
return `${(value / 1e9).toFixed(2)}B`;
|
|
611
|
+
} else if (value >= 1e6) {
|
|
612
|
+
return `${(value / 1e6).toFixed(2)}M`;
|
|
613
|
+
} else if (value >= 1e3) {
|
|
614
|
+
return `${(value / 1e3).toFixed(2)}K`;
|
|
615
|
+
}
|
|
616
|
+
return value.toString();
|
|
617
|
+
}
|
|
618
|
+
function formatDate(date) {
|
|
619
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
620
|
+
return d.toISOString().split("T")[0];
|
|
621
|
+
}
|
|
622
|
+
function formatReadableDate(date) {
|
|
623
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
624
|
+
return d.toLocaleDateString("en-US", {
|
|
625
|
+
year: "numeric",
|
|
626
|
+
month: "long",
|
|
627
|
+
day: "numeric"
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
function formatTimestamp(timestamp) {
|
|
631
|
+
const date = new Date(timestamp * 1e3);
|
|
632
|
+
return date.toLocaleString("en-US");
|
|
633
|
+
}
|
|
634
|
+
function formatNumber(value, decimals = 2) {
|
|
635
|
+
return value.toFixed(decimals);
|
|
636
|
+
}
|
|
637
|
+
function formatVolume(volume) {
|
|
638
|
+
if (volume >= 1e9) {
|
|
639
|
+
return `${(volume / 1e9).toFixed(2)}B`;
|
|
640
|
+
} else if (volume >= 1e6) {
|
|
641
|
+
return `${(volume / 1e6).toFixed(2)}M`;
|
|
642
|
+
} else if (volume >= 1e3) {
|
|
643
|
+
return `${(volume / 1e3).toFixed(2)}K`;
|
|
644
|
+
}
|
|
645
|
+
return volume.toString();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/utils/constants.ts
|
|
649
|
+
var DEFAULT_TIMEOUT = 1e4;
|
|
650
|
+
var DEFAULT_LIMIT = 100;
|
|
651
|
+
var MAX_LIMIT = 1e3;
|
|
652
|
+
var PERIODS = {
|
|
653
|
+
ANNUAL: "annual",
|
|
654
|
+
QUARTER: "quarter"
|
|
655
|
+
};
|
|
656
|
+
var EXCHANGES = {
|
|
657
|
+
NYSE: "NYSE",
|
|
658
|
+
NASDAQ: "NASDAQ",
|
|
659
|
+
AMEX: "AMEX",
|
|
660
|
+
TSX: "TSX",
|
|
661
|
+
LSE: "LSE",
|
|
662
|
+
ASX: "ASX",
|
|
663
|
+
NSE: "NSE",
|
|
664
|
+
BSE: "BSE"
|
|
665
|
+
};
|
|
666
|
+
var SECTORS = {
|
|
667
|
+
TECHNOLOGY: "Technology",
|
|
668
|
+
HEALTHCARE: "Healthcare",
|
|
669
|
+
FINANCIAL: "Financial",
|
|
670
|
+
CONSUMER_DISCRETIONARY: "Consumer Discretionary",
|
|
671
|
+
CONSUMER_STAPLES: "Consumer Staples",
|
|
672
|
+
INDUSTRIALS: "Industrials",
|
|
673
|
+
ENERGY: "Energy",
|
|
674
|
+
MATERIALS: "Materials",
|
|
675
|
+
UTILITIES: "Utilities",
|
|
676
|
+
REAL_ESTATE: "Real Estate",
|
|
677
|
+
COMMUNICATION_SERVICES: "Communication Services"
|
|
678
|
+
};
|
|
679
|
+
var COUNTRIES = {
|
|
680
|
+
US: "US",
|
|
681
|
+
CA: "CA",
|
|
682
|
+
GB: "GB",
|
|
683
|
+
AU: "AU",
|
|
684
|
+
IN: "IN",
|
|
685
|
+
DE: "DE",
|
|
686
|
+
FR: "FR",
|
|
687
|
+
JP: "JP",
|
|
688
|
+
CN: "CN",
|
|
689
|
+
BR: "BR"
|
|
690
|
+
};
|
|
691
|
+
var ERROR_MESSAGES = {
|
|
692
|
+
API_KEY_REQUIRED: "API key is required",
|
|
693
|
+
SYMBOL_REQUIRED: "Symbol is required",
|
|
694
|
+
INVALID_SYMBOL: "Invalid symbol format",
|
|
695
|
+
INVALID_DATE: "Invalid date format. Use YYYY-MM-DD",
|
|
696
|
+
INVALID_PERIOD: 'Period must be either "annual" or "quarter"',
|
|
697
|
+
INVALID_LIMIT: "Limit must be between 1 and 1000",
|
|
698
|
+
INVALID_PAGE: "Page must be a non-negative number",
|
|
699
|
+
REQUEST_FAILED: "Request failed",
|
|
700
|
+
RATE_LIMIT_EXCEEDED: "Rate limit exceeded",
|
|
701
|
+
UNAUTHORIZED: "Unauthorized - Invalid API key",
|
|
702
|
+
NOT_FOUND: "Resource not found"
|
|
703
|
+
};
|
|
704
|
+
var HTTP_STATUS = {
|
|
705
|
+
OK: 200,
|
|
706
|
+
CREATED: 201,
|
|
707
|
+
BAD_REQUEST: 400,
|
|
708
|
+
UNAUTHORIZED: 401,
|
|
709
|
+
FORBIDDEN: 403,
|
|
710
|
+
NOT_FOUND: 404,
|
|
711
|
+
TOO_MANY_REQUESTS: 429,
|
|
712
|
+
INTERNAL_SERVER_ERROR: 500
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
export { BondEndpoints, COUNTRIES, CryptoEndpoints, DEFAULT_LIMIT, DEFAULT_TIMEOUT, ERROR_MESSAGES, ETFEndpoints, EXCHANGES, EconomicEndpoints, Exchange, FMP, FMPClient, FMPError, FMP_BASE_URL, FMP_BASE_URL_V4, FMP_STABLE_URL, FinancialEndpoints, ForexEndpoints, HTTP_STATUS, MAX_LIMIT, MarketEndpoints, MutualFundEndpoints, PERIODS, Period, SECTORS, StockEndpoints, formatCurrency, formatDate, formatLargeNumber, formatNumber, formatPercentage, formatReadableDate, formatTimestamp, formatVolume, validateApiKey, validateDate, validateLimit, validatePage, validatePeriod, validateSymbol };
|
|
716
|
+
//# sourceMappingURL=index.mjs.map
|
|
717
|
+
//# sourceMappingURL=index.mjs.map
|