fmp-node-api 0.0.6 → 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
@@ -748,6 +844,19 @@ var CalendarEndpoints = class {
748
844
  if (to) params.to = to;
749
845
  return this.client.get("/earning_calendar", "v3", params);
750
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
+ }
751
860
  /**
752
861
  * Get dividends calendar
753
862
  * https://site.financialmodelingprep.com/developer/docs#dividends-calendar-dividends
@@ -813,9 +922,7 @@ var CompanyEndpoints = class {
813
922
  * @param symbol - The stock symbol to get the profile for
814
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.
815
924
  */
816
- async getCompanyProfile({
817
- symbol
818
- }) {
925
+ async getCompanyProfile({ symbol }) {
819
926
  return this.client.getSingle(`/profile/${symbol}`, "v3");
820
927
  }
821
928
  /**
@@ -836,9 +943,7 @@ var CompanyEndpoints = class {
836
943
  * @param symbol - The stock symbol to get the notes for
837
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.
838
945
  */
839
- async getCompanyNotes({
840
- symbol
841
- }) {
946
+ async getCompanyNotes({ symbol }) {
842
947
  const params = { symbol };
843
948
  return this.client.get(`/company-notes`, "v4", params);
844
949
  }
@@ -892,6 +997,18 @@ var CompanyEndpoints = class {
892
997
  const params = { year, quarter };
893
998
  return this.client.getSingle(`/earning_call_transcript/${symbol}`, "v3", params);
894
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
+ }
895
1012
  };
896
1013
 
897
1014
  // src/endpoints/quote.ts
@@ -967,6 +1084,15 @@ var SenateHouseEndpoints = class {
967
1084
  const { page } = params;
968
1085
  return this.client.get("/senate-trading-rss-feed", "v4", { page });
969
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
+ }
970
1096
  /**
971
1097
  * Get house trading data only
972
1098
  * https://site.financialmodelingprep.com/developer/docs#house-disclosure
@@ -986,6 +1112,15 @@ var SenateHouseEndpoints = class {
986
1112
  const { page } = params;
987
1113
  return this.client.get("/senate-disclosure-rss-feed", "v4", { page });
988
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
+ }
989
1124
  };
990
1125
 
991
1126
  // src/fmp.ts