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.js CHANGED
@@ -13,13 +13,22 @@ function unwrapSingleObject(data) {
13
13
  }
14
14
  return data;
15
15
  }
16
+ function normalizeArrayResponse(data) {
17
+ if (Array.isArray(data)) return data;
18
+ if (data == null) return [];
19
+ return data;
20
+ }
21
+ function normalizeObjectResponse(data) {
22
+ if (data == null) return {};
23
+ return data;
24
+ }
16
25
  var FMPClient = class {
17
26
  constructor(config) {
18
27
  this.apiKey = config.apiKey;
19
28
  this.v3Client = this.createClient("https://financialmodelingprep.com/api/v3", config.timeout);
20
29
  this.v4Client = this.createClient("https://financialmodelingprep.com/api/v4", config.timeout);
21
30
  this.stableClient = this.createClient(
22
- "https://financialmodelingprep.com/api/stable",
31
+ "https://financialmodelingprep.com/stable",
23
32
  config.timeout
24
33
  );
25
34
  }
@@ -35,14 +44,23 @@ var FMPClient = class {
35
44
  });
36
45
  return client;
37
46
  }
38
- // Standard get method - returns raw API response
47
+ /**
48
+ * Standard get method - returns raw API response
49
+ *
50
+ * For endpoints that return arrays, this will always return an array (possibly empty) for `data` when success is true.
51
+ * For endpoints that return objects, data is returned as-is.
52
+ */
39
53
  async get(endpoint, version = "v3", params) {
40
54
  const client = this.getClientForVersion(version);
41
55
  try {
42
56
  const response = await client.get(endpoint, { params });
57
+ let data = response.data;
58
+ if (Array.isArray(data) || data == null) {
59
+ data = normalizeArrayResponse(data);
60
+ }
43
61
  return {
44
62
  success: true,
45
- data: response.data,
63
+ data,
46
64
  status: response.status
47
65
  };
48
66
  } catch (error) {
@@ -53,14 +71,19 @@ var FMPClient = class {
53
71
  };
54
72
  }
55
73
  }
56
- // Get method for single-object endpoints - unwraps single-item arrays
74
+ /**
75
+ * Get method for single-object endpoints - unwraps single-item arrays
76
+ *
77
+ * For endpoints that return single objects, this will always return an object (possibly empty) for `data` when success is true.
78
+ */
57
79
  async getSingle(endpoint, version = "v3", params) {
58
80
  const client = this.getClientForVersion(version);
59
81
  try {
60
82
  const response = await client.get(endpoint, { params });
83
+ const data = normalizeObjectResponse(unwrapSingleObject(response.data));
61
84
  return {
62
85
  success: true,
63
- data: unwrapSingleObject(response.data),
86
+ data,
64
87
  status: response.status
65
88
  };
66
89
  } catch (error) {
@@ -208,6 +231,79 @@ var StockEndpoints = class {
208
231
  }) {
209
232
  return this.client.getSingle(`/historical-price-full/stock_dividend/${symbol}`, "v3");
210
233
  }
234
+ /**
235
+ * Get stock real time price
236
+ * @param symbol - The stock symbol to get the real time price for
237
+ * @returns The real time price for the stock
238
+ */
239
+ async getRealTimePrice({
240
+ symbols
241
+ }) {
242
+ const url = `stock/real-time-price/${symbols.join(",")}`;
243
+ const result = await this.client.get(url, "v3");
244
+ if (result.success && result.data && !Array.isArray(result.data)) {
245
+ const data = result.data;
246
+ if (typeof data === "object" && data !== null && "companiesPriceList" in data && Array.isArray(data.companiesPriceList)) {
247
+ const filteredData2 = data.companiesPriceList.filter((item) => item && item.symbol);
248
+ if (filteredData2.length > 0) {
249
+ return { ...result, data: filteredData2 };
250
+ }
251
+ }
252
+ if (typeof data === "object" && data !== null && "stockList" in data && Array.isArray(data.stockList)) {
253
+ const filteredData2 = data.stockList.filter((item) => item && item.symbol);
254
+ if (filteredData2.length > 0) {
255
+ return { ...result, data: filteredData2 };
256
+ }
257
+ }
258
+ if (data.symbol) {
259
+ return { ...result, data: [data] };
260
+ }
261
+ if (symbols.length === 1) {
262
+ console.warn(`No real-time price data found for symbol: ${symbols[0]}`);
263
+ }
264
+ return { ...result, data: [] };
265
+ }
266
+ const filteredData = result.data.filter((item) => item && item.symbol);
267
+ return { ...result, data: filteredData };
268
+ }
269
+ /**
270
+ * Get stock real time price full
271
+ * https://site.financialmodelingprep.com/developer/docs#real-time-full-price-quote
272
+ * @param symbols - The stock symbols to get the real time price for
273
+ * @returns The real time price for the stocks
274
+ */
275
+ async getRealTimePriceForMultipleStocks({
276
+ symbols
277
+ }) {
278
+ const url = `stock/full/real-time-price/${symbols.join(",")}`;
279
+ const result = await this.client.get(url, "v3");
280
+ if (result.success && result.data && !Array.isArray(result.data)) {
281
+ const data = result.data;
282
+ if (typeof data === "object" && data !== null && "companiesPriceList" in data && Array.isArray(data.companiesPriceList)) {
283
+ const filteredData2 = data.companiesPriceList.filter((item) => item && item.symbol);
284
+ if (filteredData2.length > 0) {
285
+ return { ...result, data: filteredData2 };
286
+ }
287
+ }
288
+ if (typeof data === "object" && data !== null && "stockList" in data && Array.isArray(data.stockList)) {
289
+ const filteredData2 = data.stockList.filter((item) => item && item.symbol);
290
+ if (filteredData2.length > 0) {
291
+ return { ...result, data: filteredData2 };
292
+ }
293
+ }
294
+ if (data.symbol) {
295
+ return { ...result, data: [data] };
296
+ }
297
+ if (symbols.length === 1) {
298
+ console.warn(`No full real-time price data found for symbol: ${symbols[0]}`);
299
+ }
300
+ return { ...result, data: [] };
301
+ }
302
+ const filteredData = result.data.filter(
303
+ (item) => item && item.symbol
304
+ );
305
+ return { ...result, data: filteredData };
306
+ }
211
307
  };
212
308
 
213
309
  // src/endpoints/financial.ts
@@ -442,21 +538,6 @@ var ForexEndpoints = class {
442
538
  if (to) params.to = to;
443
539
  return this.client.get(`/historical-price-full/${symbol}`, "v3", params);
444
540
  }
445
- /**
446
- * Get forex rates for a specific base currency
447
- * @param baseCurrency - The base currency to get forex rates for
448
- * @returns Forex rates data
449
- */
450
- async getForexRates(baseCurrency = "USD") {
451
- return this.client.get(`/forex/${baseCurrency}`, "v3");
452
- }
453
- /**
454
- * Get all forex rates
455
- * @returns All forex rates data
456
- */
457
- async getAllForexRates() {
458
- return this.client.get("/forex", "v3");
459
- }
460
541
  };
461
542
 
462
543
  // src/endpoints/crypto.ts
@@ -595,50 +676,13 @@ var MutualFundEndpoints = class {
595
676
  return this.client.get("/quote", "v3", params);
596
677
  }
597
678
  /**
598
- * Get mutual fund profile
599
- */
600
- async getProfile(params) {
601
- return this.client.get("/profile", "v3", params);
602
- }
603
- /**
604
- * Get mutual fund holdings
605
- */
606
- async getHoldings(params) {
607
- return this.client.get("/holdings", "v3", params);
608
- }
609
- };
610
-
611
- // src/endpoints/bond.ts
612
- var BondEndpoints = class {
613
- constructor(client) {
614
- this.client = client;
615
- }
616
- /**
617
- * Get bond quote
618
- * @deprecated Use `fmp.quote.getQuote()` instead. This method will be removed in a future release.
619
- * @param params - Parameters for the bond quote request
620
- * @returns Bond quote data
621
- */
622
- async getQuote(params) {
623
- return this.client.get("/quote", "v3", params);
624
- }
625
- /**
626
- * Get historical bond prices
627
- * @deprecated Use `fmp.quote.getHistoricalPrice()` instead. This method will be removed in a future release.
628
- * @param symbol - The bond symbol to get the historical prices for
629
- * @param from - The start date to get the historical prices for
630
- * @param to - The end date to get the historical prices for
631
- * @returns Historical bond price data
679
+ * Get mutual fund holders
680
+ * https://site.financialmodelingprep.com/developer/docs#mutual-fund-holder-mutual-funds-holdings
681
+ * @param symbol - The symbol of the mutual fund to get the holders for
682
+ * @returns Mutual fund holders data
632
683
  */
633
- async getHistoricalPrice({
634
- symbol,
635
- from,
636
- to
637
- }) {
638
- const params = {};
639
- if (from) params.from = from;
640
- if (to) params.to = to;
641
- return this.client.get(`/historical-price-full/${symbol}`, "v3", params);
684
+ async getHolders({ symbol }) {
685
+ return this.client.get(`/mutual-fund-holder/${symbol}`, "v3");
642
686
  }
643
687
  };
644
688
 
@@ -649,33 +693,32 @@ var EconomicEndpoints = class {
649
693
  }
650
694
  /**
651
695
  * Get treasury rates
696
+ * https://site.financialmodelingprep.com/developer/docs#treasury-rates-economics-data
697
+ * @param from - The start date to get the treasury rates for
698
+ * @param to - The end date to get the treasury rates for
699
+ * @returns Treasury rates data
652
700
  */
653
- async getTreasuryRates(params = {}) {
654
- return this.client.get("/treasury-rates", "v3", params);
655
- }
656
- /**
657
- * Get federal funds rate
658
- */
659
- async getFederalFundsRate(params = {}) {
660
- return this.client.get("/federal-funds-rate", "v3", params);
661
- }
662
- /**
663
- * Get CPI data
664
- */
665
- async getCPI(params = {}) {
666
- return this.client.get("/economic/cpi", "v3", params);
667
- }
668
- /**
669
- * Get GDP data
670
- */
671
- async getGDP(params = {}) {
672
- return this.client.get("/economic/gdp", "v3", params);
701
+ async getTreasuryRates(params) {
702
+ const { from, to } = params;
703
+ const queryParams = {};
704
+ if (from) queryParams.from = from;
705
+ if (to) queryParams.to = to;
706
+ return this.client.get("/treasury", "v4", queryParams);
673
707
  }
674
708
  /**
675
- * Get unemployment data
709
+ * Get economic indicators
710
+ * https://site.financialmodelingprep.com/developer/docs#economic-indicators-economics-data
711
+ * @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
712
+ * @param from - The start date to get the economic indicators for
713
+ * @param to - The end date to get the economic indicators for
714
+ * @returns Provides real-time and historical economic data for a variety of economic indicators, such as GDP, unemployment, and inflation.
676
715
  */
677
- async getUnemployment(params = {}) {
678
- return this.client.get("/economic/unemployment", "v3", params);
716
+ async getEconomicIndicators(params) {
717
+ const { name, from, to } = params;
718
+ const queryParams = { name };
719
+ if (from) queryParams.from = from;
720
+ if (to) queryParams.to = to;
721
+ return this.client.get(`/economic`, "v4", queryParams);
679
722
  }
680
723
  };
681
724
 
@@ -801,6 +844,19 @@ var CalendarEndpoints = class {
801
844
  if (to) params.to = to;
802
845
  return this.client.get("/earning_calendar", "v3", params);
803
846
  }
847
+ /**
848
+ * Get earnings confirmed
849
+ * https://site.financialmodelingprep.com/developer/docs#earnings-confirmed-earnings
850
+ * @param from - The start date to get the earnings confirmed for
851
+ * @param to - The end date to get the earnings confirmed for
852
+ * @returns The earnings confirmed
853
+ */
854
+ async getEarningsConfirmed({ from, to } = {}) {
855
+ const params = {};
856
+ if (from) params.from = from;
857
+ if (to) params.to = to;
858
+ return this.client.get("/earning-calendar-confirmed", "v4", params);
859
+ }
804
860
  /**
805
861
  * Get dividends calendar
806
862
  * https://site.financialmodelingprep.com/developer/docs#dividends-calendar-dividends
@@ -866,9 +922,7 @@ var CompanyEndpoints = class {
866
922
  * @param symbol - The stock symbol to get the profile for
867
923
  * @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.
868
924
  */
869
- async getCompanyProfile({
870
- symbol
871
- }) {
925
+ async getCompanyProfile({ symbol }) {
872
926
  return this.client.getSingle(`/profile/${symbol}`, "v3");
873
927
  }
874
928
  /**
@@ -889,9 +943,7 @@ var CompanyEndpoints = class {
889
943
  * @param symbol - The stock symbol to get the notes for
890
944
  * @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.
891
945
  */
892
- async getCompanyNotes({
893
- symbol
894
- }) {
946
+ async getCompanyNotes({ symbol }) {
895
947
  const params = { symbol };
896
948
  return this.client.get(`/company-notes`, "v4", params);
897
949
  }
@@ -945,6 +997,18 @@ var CompanyEndpoints = class {
945
997
  const params = { year, quarter };
946
998
  return this.client.getSingle(`/earning_call_transcript/${symbol}`, "v3", params);
947
999
  }
1000
+ /**
1001
+ * Get company transcript dates
1002
+ * https://site.financialmodelingprep.com/developer/docs#transcript-dates-earnings-transcripts
1003
+ * @param symbol - The stock symbol to get the transcript data for
1004
+ * @returns The FMP Company Transcript Data endpoint provides the transcript data for a company's earnings call.
1005
+ */
1006
+ async getCompanyTranscriptData({
1007
+ symbol
1008
+ }) {
1009
+ const params = { symbol };
1010
+ return this.client.getSingle(`/earning_call_transcript`, "v4", params);
1011
+ }
948
1012
  };
949
1013
 
950
1014
  // src/endpoints/quote.ts
@@ -996,6 +1060,69 @@ var QuoteEndpoints = class {
996
1060
  }
997
1061
  };
998
1062
 
1063
+ // src/endpoints/senate-house.ts
1064
+ var SenateHouseEndpoints = class {
1065
+ constructor(client) {
1066
+ this.client = client;
1067
+ }
1068
+ /**
1069
+ * Get senate trading data only
1070
+ * https://site.financialmodelingprep.com/developer/docs#senate-trading
1071
+ * @param symbol - The stock symbol to get the senate trading data for
1072
+ * @returns Senate trading data only
1073
+ */
1074
+ async getSenateTrading(params) {
1075
+ const { symbol } = params;
1076
+ return this.client.get(`/senate-trading`, "v4", { symbol });
1077
+ }
1078
+ /** Get senate trading RSS feed
1079
+ * https://site.financialmodelingprep.com/developer/docs#senate-trading-rss-feed-senate
1080
+ * @param page - The page number to get
1081
+ * @returns Senate trading RSS feed
1082
+ */
1083
+ async getSenateTradingRSSFeed(params) {
1084
+ const { page } = params;
1085
+ return this.client.get("/senate-trading-rss-feed", "v4", { page });
1086
+ }
1087
+ /** Get Senate trades by name
1088
+ * https://site.financialmodelingprep.com/developer/docs/stable#senate-trading-by-name
1089
+ * @param name - The name of the senator to get the trades for
1090
+ * @returns Senate trades by name
1091
+ */
1092
+ async getSenateTradingByName(params) {
1093
+ const { name } = params;
1094
+ return this.client.get("/senate-trades-by-name", "stable", { name });
1095
+ }
1096
+ /**
1097
+ * Get house trading data only
1098
+ * https://site.financialmodelingprep.com/developer/docs#house-disclosure
1099
+ * @param symbol - The stock symbol to get the house trading data for
1100
+ * @returns House trading data only
1101
+ */
1102
+ async getHouseTrading(params) {
1103
+ const { symbol } = params;
1104
+ return this.client.get("/senate-disclosure", "v4", { symbol });
1105
+ }
1106
+ /** Get house trading RSS feed
1107
+ * https://site.financialmodelingprep.com/developer/docs#house-disclosure-rss-feed-senate
1108
+ * @param page - The page number to get
1109
+ * @returns House trading RSS feed
1110
+ */
1111
+ async getHouseTradingRSSFeed(params) {
1112
+ const { page } = params;
1113
+ return this.client.get("/senate-disclosure-rss-feed", "v4", { page });
1114
+ }
1115
+ /** Get house trading by name
1116
+ * https://site.financialmodelingprep.com/developer/docs/stable#house-trading-by-name
1117
+ * @param name - The name of the representative to get the trades for
1118
+ * @returns House trading by name
1119
+ */
1120
+ async getHouseTradingByName(params) {
1121
+ const { name } = params;
1122
+ return this.client.get("/house-trades-by-name", "stable", { name });
1123
+ }
1124
+ };
1125
+
999
1126
  // src/fmp.ts
1000
1127
  var FMP = class {
1001
1128
  constructor(config) {
@@ -1010,9 +1137,9 @@ var FMP = class {
1010
1137
  this.calendar = new CalendarEndpoints(client);
1011
1138
  this.company = new CompanyEndpoints(client);
1012
1139
  this.quote = new QuoteEndpoints(client);
1140
+ this.senateHouse = new SenateHouseEndpoints(client);
1013
1141
  this.forex = new ForexEndpoints(client);
1014
1142
  this.economic = new EconomicEndpoints(client);
1015
- this.bond = new BondEndpoints(client);
1016
1143
  this.mutualFund = new MutualFundEndpoints(client);
1017
1144
  }
1018
1145
  /**
@@ -1160,7 +1287,6 @@ var HTTP_STATUS = {
1160
1287
  INTERNAL_SERVER_ERROR: 500
1161
1288
  };
1162
1289
 
1163
- exports.BondEndpoints = BondEndpoints;
1164
1290
  exports.COUNTRIES = COUNTRIES;
1165
1291
  exports.CalendarEndpoints = CalendarEndpoints;
1166
1292
  exports.CompanyEndpoints = CompanyEndpoints;
@@ -1185,6 +1311,7 @@ exports.PERIODS = PERIODS;
1185
1311
  exports.Period = Period;
1186
1312
  exports.QuoteEndpoints = QuoteEndpoints;
1187
1313
  exports.SECTORS = SECTORS;
1314
+ exports.SenateHouseEndpoints = SenateHouseEndpoints;
1188
1315
  exports.StockEndpoints = StockEndpoints;
1189
1316
  exports.formatCurrency = formatCurrency;
1190
1317
  exports.formatDate = formatDate;