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.d.mts +126 -15
- package/dist/index.d.ts +126 -15
- package/dist/index.js +146 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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/
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -742,6 +838,19 @@ var CalendarEndpoints = class {
|
|
|
742
838
|
if (to) params.to = to;
|
|
743
839
|
return this.client.get("/earning_calendar", "v3", params);
|
|
744
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
|
+
}
|
|
745
854
|
/**
|
|
746
855
|
* Get dividends calendar
|
|
747
856
|
* https://site.financialmodelingprep.com/developer/docs#dividends-calendar-dividends
|
|
@@ -807,9 +916,7 @@ var CompanyEndpoints = class {
|
|
|
807
916
|
* @param symbol - The stock symbol to get the profile for
|
|
808
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.
|
|
809
918
|
*/
|
|
810
|
-
async getCompanyProfile({
|
|
811
|
-
symbol
|
|
812
|
-
}) {
|
|
919
|
+
async getCompanyProfile({ symbol }) {
|
|
813
920
|
return this.client.getSingle(`/profile/${symbol}`, "v3");
|
|
814
921
|
}
|
|
815
922
|
/**
|
|
@@ -830,9 +937,7 @@ var CompanyEndpoints = class {
|
|
|
830
937
|
* @param symbol - The stock symbol to get the notes for
|
|
831
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.
|
|
832
939
|
*/
|
|
833
|
-
async getCompanyNotes({
|
|
834
|
-
symbol
|
|
835
|
-
}) {
|
|
940
|
+
async getCompanyNotes({ symbol }) {
|
|
836
941
|
const params = { symbol };
|
|
837
942
|
return this.client.get(`/company-notes`, "v4", params);
|
|
838
943
|
}
|
|
@@ -886,6 +991,18 @@ var CompanyEndpoints = class {
|
|
|
886
991
|
const params = { year, quarter };
|
|
887
992
|
return this.client.getSingle(`/earning_call_transcript/${symbol}`, "v3", params);
|
|
888
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
|
+
}
|
|
889
1006
|
};
|
|
890
1007
|
|
|
891
1008
|
// src/endpoints/quote.ts
|
|
@@ -961,6 +1078,15 @@ var SenateHouseEndpoints = class {
|
|
|
961
1078
|
const { page } = params;
|
|
962
1079
|
return this.client.get("/senate-trading-rss-feed", "v4", { page });
|
|
963
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
|
+
}
|
|
964
1090
|
/**
|
|
965
1091
|
* Get house trading data only
|
|
966
1092
|
* https://site.financialmodelingprep.com/developer/docs#house-disclosure
|
|
@@ -980,6 +1106,15 @@ var SenateHouseEndpoints = class {
|
|
|
980
1106
|
const { page } = params;
|
|
981
1107
|
return this.client.get("/senate-disclosure-rss-feed", "v4", { page });
|
|
982
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
|
+
}
|
|
983
1118
|
};
|
|
984
1119
|
|
|
985
1120
|
// src/fmp.ts
|