fmp-node-api 0.0.5 → 0.0.7

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/dist/index.mjs CHANGED
@@ -7,13 +7,22 @@ function unwrapSingleObject(data) {
7
7
  }
8
8
  return data;
9
9
  }
10
+ function normalizeArrayResponse(data) {
11
+ if (Array.isArray(data)) return data;
12
+ if (data == null) return [];
13
+ return data;
14
+ }
15
+ function normalizeObjectResponse(data) {
16
+ if (data == null) return {};
17
+ return data;
18
+ }
10
19
  var FMPClient = class {
11
20
  constructor(config) {
12
21
  this.apiKey = config.apiKey;
13
22
  this.v3Client = this.createClient("https://financialmodelingprep.com/api/v3", config.timeout);
14
23
  this.v4Client = this.createClient("https://financialmodelingprep.com/api/v4", config.timeout);
15
24
  this.stableClient = this.createClient(
16
- "https://financialmodelingprep.com/api/stable",
25
+ "https://financialmodelingprep.com/stable",
17
26
  config.timeout
18
27
  );
19
28
  }
@@ -29,14 +38,23 @@ var FMPClient = class {
29
38
  });
30
39
  return client;
31
40
  }
32
- // Standard get method - returns raw API response
41
+ /**
42
+ * Standard get method - returns raw API response
43
+ *
44
+ * For endpoints that return arrays, this will always return an array (possibly empty) for `data` when success is true.
45
+ * For endpoints that return objects, data is returned as-is.
46
+ */
33
47
  async get(endpoint, version = "v3", params) {
34
48
  const client = this.getClientForVersion(version);
35
49
  try {
36
50
  const response = await client.get(endpoint, { params });
51
+ let data = response.data;
52
+ if (Array.isArray(data) || data == null) {
53
+ data = normalizeArrayResponse(data);
54
+ }
37
55
  return {
38
56
  success: true,
39
- data: response.data,
57
+ data,
40
58
  status: response.status
41
59
  };
42
60
  } catch (error) {
@@ -47,14 +65,19 @@ var FMPClient = class {
47
65
  };
48
66
  }
49
67
  }
50
- // Get method for single-object endpoints - unwraps single-item arrays
68
+ /**
69
+ * Get method for single-object endpoints - unwraps single-item arrays
70
+ *
71
+ * For endpoints that return single objects, this will always return an object (possibly empty) for `data` when success is true.
72
+ */
51
73
  async getSingle(endpoint, version = "v3", params) {
52
74
  const client = this.getClientForVersion(version);
53
75
  try {
54
76
  const response = await client.get(endpoint, { params });
77
+ const data = normalizeObjectResponse(unwrapSingleObject(response.data));
55
78
  return {
56
79
  success: true,
57
- data: unwrapSingleObject(response.data),
80
+ data,
58
81
  status: response.status
59
82
  };
60
83
  } catch (error) {
@@ -202,6 +225,79 @@ var StockEndpoints = class {
202
225
  }) {
203
226
  return this.client.getSingle(`/historical-price-full/stock_dividend/${symbol}`, "v3");
204
227
  }
228
+ /**
229
+ * Get stock real time price
230
+ * @param symbol - The stock symbol to get the real time price for
231
+ * @returns The real time price for the stock
232
+ */
233
+ async getRealTimePrice({
234
+ symbols
235
+ }) {
236
+ const url = `stock/real-time-price/${symbols.join(",")}`;
237
+ const result = await this.client.get(url, "v3");
238
+ if (result.success && result.data && !Array.isArray(result.data)) {
239
+ const data = result.data;
240
+ if (typeof data === "object" && data !== null && "companiesPriceList" in data && Array.isArray(data.companiesPriceList)) {
241
+ const filteredData2 = data.companiesPriceList.filter((item) => item && item.symbol);
242
+ if (filteredData2.length > 0) {
243
+ return { ...result, data: filteredData2 };
244
+ }
245
+ }
246
+ if (typeof data === "object" && data !== null && "stockList" in data && Array.isArray(data.stockList)) {
247
+ const filteredData2 = data.stockList.filter((item) => item && item.symbol);
248
+ if (filteredData2.length > 0) {
249
+ return { ...result, data: filteredData2 };
250
+ }
251
+ }
252
+ if (data.symbol) {
253
+ return { ...result, data: [data] };
254
+ }
255
+ if (symbols.length === 1) {
256
+ console.warn(`No real-time price data found for symbol: ${symbols[0]}`);
257
+ }
258
+ return { ...result, data: [] };
259
+ }
260
+ const filteredData = result.data.filter((item) => item && item.symbol);
261
+ return { ...result, data: filteredData };
262
+ }
263
+ /**
264
+ * Get stock real time price full
265
+ * https://site.financialmodelingprep.com/developer/docs#real-time-full-price-quote
266
+ * @param symbols - The stock symbols to get the real time price for
267
+ * @returns The real time price for the stocks
268
+ */
269
+ async getRealTimePriceForMultipleStocks({
270
+ symbols
271
+ }) {
272
+ const url = `stock/full/real-time-price/${symbols.join(",")}`;
273
+ const result = await this.client.get(url, "v3");
274
+ if (result.success && result.data && !Array.isArray(result.data)) {
275
+ const data = result.data;
276
+ if (typeof data === "object" && data !== null && "companiesPriceList" in data && Array.isArray(data.companiesPriceList)) {
277
+ const filteredData2 = data.companiesPriceList.filter((item) => item && item.symbol);
278
+ if (filteredData2.length > 0) {
279
+ return { ...result, data: filteredData2 };
280
+ }
281
+ }
282
+ if (typeof data === "object" && data !== null && "stockList" in data && Array.isArray(data.stockList)) {
283
+ const filteredData2 = data.stockList.filter((item) => item && item.symbol);
284
+ if (filteredData2.length > 0) {
285
+ return { ...result, data: filteredData2 };
286
+ }
287
+ }
288
+ if (data.symbol) {
289
+ return { ...result, data: [data] };
290
+ }
291
+ if (symbols.length === 1) {
292
+ console.warn(`No full real-time price data found for symbol: ${symbols[0]}`);
293
+ }
294
+ return { ...result, data: [] };
295
+ }
296
+ const filteredData = result.data.filter(
297
+ (item) => item && item.symbol
298
+ );
299
+ return { ...result, data: filteredData };
300
+ }
205
301
  };
206
302
 
207
303
  // src/endpoints/financial.ts
@@ -436,21 +532,6 @@ var ForexEndpoints = class {
436
532
  if (to) params.to = to;
437
533
  return this.client.get(`/historical-price-full/${symbol}`, "v3", params);
438
534
  }
439
- /**
440
- * Get forex rates for a specific base currency
441
- * @param baseCurrency - The base currency to get forex rates for
442
- * @returns Forex rates data
443
- */
444
- async getForexRates(baseCurrency = "USD") {
445
- return this.client.get(`/forex/${baseCurrency}`, "v3");
446
- }
447
- /**
448
- * Get all forex rates
449
- * @returns All forex rates data
450
- */
451
- async getAllForexRates() {
452
- return this.client.get("/forex", "v3");
453
- }
454
535
  };
455
536
 
456
537
  // src/endpoints/crypto.ts
@@ -589,50 +670,13 @@ var MutualFundEndpoints = class {
589
670
  return this.client.get("/quote", "v3", params);
590
671
  }
591
672
  /**
592
- * Get mutual fund profile
593
- */
594
- async getProfile(params) {
595
- return this.client.get("/profile", "v3", params);
596
- }
597
- /**
598
- * Get mutual fund holdings
599
- */
600
- async getHoldings(params) {
601
- return this.client.get("/holdings", "v3", params);
602
- }
603
- };
604
-
605
- // src/endpoints/bond.ts
606
- var BondEndpoints = class {
607
- constructor(client) {
608
- this.client = client;
609
- }
610
- /**
611
- * Get bond quote
612
- * @deprecated Use `fmp.quote.getQuote()` instead. This method will be removed in a future release.
613
- * @param params - Parameters for the bond quote request
614
- * @returns Bond quote data
615
- */
616
- async getQuote(params) {
617
- return this.client.get("/quote", "v3", params);
618
- }
619
- /**
620
- * Get historical bond prices
621
- * @deprecated Use `fmp.quote.getHistoricalPrice()` instead. This method will be removed in a future release.
622
- * @param symbol - The bond symbol to get the historical prices for
623
- * @param from - The start date to get the historical prices for
624
- * @param to - The end date to get the historical prices for
625
- * @returns Historical bond price data
673
+ * Get mutual fund holders
674
+ * https://site.financialmodelingprep.com/developer/docs#mutual-fund-holder-mutual-funds-holdings
675
+ * @param symbol - The symbol of the mutual fund to get the holders for
676
+ * @returns Mutual fund holders data
626
677
  */
627
- async getHistoricalPrice({
628
- symbol,
629
- from,
630
- to
631
- }) {
632
- const params = {};
633
- if (from) params.from = from;
634
- if (to) params.to = to;
635
- return this.client.get(`/historical-price-full/${symbol}`, "v3", params);
678
+ async getHolders({ symbol }) {
679
+ return this.client.get(`/mutual-fund-holder/${symbol}`, "v3");
636
680
  }
637
681
  };
638
682
 
@@ -643,33 +687,32 @@ var EconomicEndpoints = class {
643
687
  }
644
688
  /**
645
689
  * Get treasury rates
690
+ * https://site.financialmodelingprep.com/developer/docs#treasury-rates-economics-data
691
+ * @param from - The start date to get the treasury rates for
692
+ * @param to - The end date to get the treasury rates for
693
+ * @returns Treasury rates data
646
694
  */
647
- async getTreasuryRates(params = {}) {
648
- return this.client.get("/treasury-rates", "v3", params);
649
- }
650
- /**
651
- * Get federal funds rate
652
- */
653
- async getFederalFundsRate(params = {}) {
654
- return this.client.get("/federal-funds-rate", "v3", params);
655
- }
656
- /**
657
- * Get CPI data
658
- */
659
- async getCPI(params = {}) {
660
- return this.client.get("/economic/cpi", "v3", params);
661
- }
662
- /**
663
- * Get GDP data
664
- */
665
- async getGDP(params = {}) {
666
- return this.client.get("/economic/gdp", "v3", params);
695
+ async getTreasuryRates(params) {
696
+ const { from, to } = params;
697
+ const queryParams = {};
698
+ if (from) queryParams.from = from;
699
+ if (to) queryParams.to = to;
700
+ return this.client.get("/treasury", "v4", queryParams);
667
701
  }
668
702
  /**
669
- * Get unemployment data
703
+ * Get economic indicators
704
+ * https://site.financialmodelingprep.com/developer/docs#economic-indicators-economics-data
705
+ * @param name - GDP, realGDP, nominalPotentialGDP, realGDPPerCapita, federalFunds, CPI, inflationRate, inflation, retailSales, consumerSentiment, durableGoods, unemploymentRate, totalNonfarmPayroll, initialClaims, industrialProductionTotalIndex, newPrivatelyOwnedHousingUnitsStartedTotalUnits, totalVehicleSales, retailMoneyFunds, smoothedUSRecessionProbabilities, 3MonthOr90DayRatesAndYieldsCertificatesOfDeposit, commercialBankInterestRateOnCreditCardPlansAllAccounts, 30YearFixedRateMortgageAverage, 15YearFixedRateMortgageAverage
706
+ * @param from - The start date to get the economic indicators for
707
+ * @param to - The end date to get the economic indicators for
708
+ * @returns Provides real-time and historical economic data for a variety of economic indicators, such as GDP, unemployment, and inflation.
670
709
  */
671
- async getUnemployment(params = {}) {
672
- return this.client.get("/economic/unemployment", "v3", params);
710
+ async getEconomicIndicators(params) {
711
+ const { name, from, to } = params;
712
+ const queryParams = { name };
713
+ if (from) queryParams.from = from;
714
+ if (to) queryParams.to = to;
715
+ return this.client.get(`/economic`, "v4", queryParams);
673
716
  }
674
717
  };
675
718
 
@@ -795,6 +838,19 @@ var CalendarEndpoints = class {
795
838
  if (to) params.to = to;
796
839
  return this.client.get("/earning_calendar", "v3", params);
797
840
  }
841
+ /**
842
+ * Get earnings confirmed
843
+ * https://site.financialmodelingprep.com/developer/docs#earnings-confirmed-earnings
844
+ * @param from - The start date to get the earnings confirmed for
845
+ * @param to - The end date to get the earnings confirmed for
846
+ * @returns The earnings confirmed
847
+ */
848
+ async getEarningsConfirmed({ from, to } = {}) {
849
+ const params = {};
850
+ if (from) params.from = from;
851
+ if (to) params.to = to;
852
+ return this.client.get("/earning-calendar-confirmed", "v4", params);
853
+ }
798
854
  /**
799
855
  * Get dividends calendar
800
856
  * https://site.financialmodelingprep.com/developer/docs#dividends-calendar-dividends
@@ -860,9 +916,7 @@ var CompanyEndpoints = class {
860
916
  * @param symbol - The stock symbol to get the profile for
861
917
  * @returns Get a comprehensive overview of a company with our Company Profile endpoint. This endpoint provides key information such as price, beta, market capitalization, description, headquarters, and more.
862
918
  */
863
- async getCompanyProfile({
864
- symbol
865
- }) {
919
+ async getCompanyProfile({ symbol }) {
866
920
  return this.client.getSingle(`/profile/${symbol}`, "v3");
867
921
  }
868
922
  /**
@@ -883,9 +937,7 @@ var CompanyEndpoints = class {
883
937
  * @param symbol - The stock symbol to get the notes for
884
938
  * @returns Stay up-to-date on a company's financial condition, operations, and risks with our Company Notes endpoint. This endpoint provides information about notes reported by a company in their financial statements.
885
939
  */
886
- async getCompanyNotes({
887
- symbol
888
- }) {
940
+ async getCompanyNotes({ symbol }) {
889
941
  const params = { symbol };
890
942
  return this.client.get(`/company-notes`, "v4", params);
891
943
  }
@@ -939,6 +991,18 @@ var CompanyEndpoints = class {
939
991
  const params = { year, quarter };
940
992
  return this.client.getSingle(`/earning_call_transcript/${symbol}`, "v3", params);
941
993
  }
994
+ /**
995
+ * Get company transcript dates
996
+ * https://site.financialmodelingprep.com/developer/docs#transcript-dates-earnings-transcripts
997
+ * @param symbol - The stock symbol to get the transcript data for
998
+ * @returns The FMP Company Transcript Data endpoint provides the transcript data for a company's earnings call.
999
+ */
1000
+ async getCompanyTranscriptData({
1001
+ symbol
1002
+ }) {
1003
+ const params = { symbol };
1004
+ return this.client.getSingle(`/earning_call_transcript`, "v4", params);
1005
+ }
942
1006
  };
943
1007
 
944
1008
  // src/endpoints/quote.ts
@@ -990,6 +1054,69 @@ var QuoteEndpoints = class {
990
1054
  }
991
1055
  };
992
1056
 
1057
+ // src/endpoints/senate-house.ts
1058
+ var SenateHouseEndpoints = class {
1059
+ constructor(client) {
1060
+ this.client = client;
1061
+ }
1062
+ /**
1063
+ * Get senate trading data only
1064
+ * https://site.financialmodelingprep.com/developer/docs#senate-trading
1065
+ * @param symbol - The stock symbol to get the senate trading data for
1066
+ * @returns Senate trading data only
1067
+ */
1068
+ async getSenateTrading(params) {
1069
+ const { symbol } = params;
1070
+ return this.client.get(`/senate-trading`, "v4", { symbol });
1071
+ }
1072
+ /** Get senate trading RSS feed
1073
+ * https://site.financialmodelingprep.com/developer/docs#senate-trading-rss-feed-senate
1074
+ * @param page - The page number to get
1075
+ * @returns Senate trading RSS feed
1076
+ */
1077
+ async getSenateTradingRSSFeed(params) {
1078
+ const { page } = params;
1079
+ return this.client.get("/senate-trading-rss-feed", "v4", { page });
1080
+ }
1081
+ /** Get Senate trades by name
1082
+ * https://site.financialmodelingprep.com/developer/docs/stable#senate-trading-by-name
1083
+ * @param name - The name of the senator to get the trades for
1084
+ * @returns Senate trades by name
1085
+ */
1086
+ async getSenateTradingByName(params) {
1087
+ const { name } = params;
1088
+ return this.client.get("/senate-trades-by-name", "stable", { name });
1089
+ }
1090
+ /**
1091
+ * Get house trading data only
1092
+ * https://site.financialmodelingprep.com/developer/docs#house-disclosure
1093
+ * @param symbol - The stock symbol to get the house trading data for
1094
+ * @returns House trading data only
1095
+ */
1096
+ async getHouseTrading(params) {
1097
+ const { symbol } = params;
1098
+ return this.client.get("/senate-disclosure", "v4", { symbol });
1099
+ }
1100
+ /** Get house trading RSS feed
1101
+ * https://site.financialmodelingprep.com/developer/docs#house-disclosure-rss-feed-senate
1102
+ * @param page - The page number to get
1103
+ * @returns House trading RSS feed
1104
+ */
1105
+ async getHouseTradingRSSFeed(params) {
1106
+ const { page } = params;
1107
+ return this.client.get("/senate-disclosure-rss-feed", "v4", { page });
1108
+ }
1109
+ /** Get house trading by name
1110
+ * https://site.financialmodelingprep.com/developer/docs/stable#house-trading-by-name
1111
+ * @param name - The name of the representative to get the trades for
1112
+ * @returns House trading by name
1113
+ */
1114
+ async getHouseTradingByName(params) {
1115
+ const { name } = params;
1116
+ return this.client.get("/house-trades-by-name", "stable", { name });
1117
+ }
1118
+ };
1119
+
993
1120
  // src/fmp.ts
994
1121
  var FMP = class {
995
1122
  constructor(config) {
@@ -1004,9 +1131,9 @@ var FMP = class {
1004
1131
  this.calendar = new CalendarEndpoints(client);
1005
1132
  this.company = new CompanyEndpoints(client);
1006
1133
  this.quote = new QuoteEndpoints(client);
1134
+ this.senateHouse = new SenateHouseEndpoints(client);
1007
1135
  this.forex = new ForexEndpoints(client);
1008
1136
  this.economic = new EconomicEndpoints(client);
1009
- this.bond = new BondEndpoints(client);
1010
1137
  this.mutualFund = new MutualFundEndpoints(client);
1011
1138
  }
1012
1139
  /**
@@ -1154,6 +1281,6 @@ var HTTP_STATUS = {
1154
1281
  INTERNAL_SERVER_ERROR: 500
1155
1282
  };
1156
1283
 
1157
- export { BondEndpoints, COUNTRIES, CalendarEndpoints, CompanyEndpoints, CryptoEndpoints, DEFAULT_LIMIT, DEFAULT_TIMEOUT, ERROR_MESSAGES, ETFEndpoints, EXCHANGES, EconomicEndpoints, Exchange, FMP, FMPClient, FinancialEndpoints, ForexEndpoints, HTTP_STATUS, ListEndpoints, MAX_LIMIT, MarketEndpoints, MutualFundEndpoints, PERIODS, Period, QuoteEndpoints, SECTORS, StockEndpoints, formatCurrency, formatDate, formatLargeNumber, formatNumber, formatPercentage, formatReadableDate, formatTimestamp, formatVolume, validateApiKey, validateDate, validateLimit, validatePage, validatePeriod, validateSymbol };
1284
+ export { COUNTRIES, CalendarEndpoints, CompanyEndpoints, CryptoEndpoints, DEFAULT_LIMIT, DEFAULT_TIMEOUT, ERROR_MESSAGES, ETFEndpoints, EXCHANGES, EconomicEndpoints, Exchange, FMP, FMPClient, FinancialEndpoints, ForexEndpoints, HTTP_STATUS, ListEndpoints, MAX_LIMIT, MarketEndpoints, MutualFundEndpoints, PERIODS, Period, QuoteEndpoints, SECTORS, SenateHouseEndpoints, StockEndpoints, formatCurrency, formatDate, formatLargeNumber, formatNumber, formatPercentage, formatReadableDate, formatTimestamp, formatVolume, validateApiKey, validateDate, validateLimit, validatePage, validatePeriod, validateSymbol };
1158
1285
  //# sourceMappingURL=index.mjs.map
1159
1286
  //# sourceMappingURL=index.mjs.map