sec-edgar-api 0.0.3 → 0.0.6
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/README.md +15 -43
- package/build/downloader.d.ts +6 -0
- package/build/downloader.js +9 -0
- package/build/index.d.ts +2 -7
- package/build/index.js +12 -8
- package/build/services/Client/Client.d.ts +43 -0
- package/build/services/Client/Client.js +104 -0
- package/build/services/Client/index.d.ts +3 -0
- package/build/services/Client/index.js +15 -0
- package/build/services/DocumentParser/DocumentParser.d.ts +15 -0
- package/build/services/DocumentParser/DocumentParser.js +19 -0
- package/build/services/DocumentParser/XMLParser.d.ts +25 -0
- package/build/services/DocumentParser/XMLParser.js +178 -0
- package/build/services/DocumentParser/index.d.ts +2 -0
- package/build/services/DocumentParser/index.js +4 -0
- package/build/services/DocumentParser/parsers/index.d.ts +7 -0
- package/build/services/DocumentParser/parsers/index.js +9 -0
- package/build/services/DocumentParser/parsers/parse-form-13g.d.ts +8 -0
- package/build/services/DocumentParser/parsers/parse-form-13g.js +88 -0
- package/build/services/DocumentParser/parsers/parse-form-4.d.ts +8 -0
- package/build/services/DocumentParser/parsers/parse-form-4.js +220 -0
- package/build/services/FactsDownloader/Downloader.d.ts +26 -0
- package/build/services/FactsDownloader/Downloader.js +102 -0
- package/build/services/FactsDownloader/FactsDownloader.d.ts +37 -0
- package/build/services/FactsDownloader/FactsDownloader.js +131 -0
- package/build/services/FactsDownloader/Unzipper.d.ts +40 -0
- package/build/services/FactsDownloader/Unzipper.js +40 -0
- package/build/services/FactsDownloader/index.d.ts +2 -0
- package/build/services/FactsDownloader/index.js +4 -0
- package/build/services/ReportParser/ReportParser.d.ts +1 -1
- package/build/services/ReportParser/ReportTranslatedProxy.d.ts +1 -1
- package/build/services/ReportParser/ReportWrapper.js +1 -2
- package/build/services/ReportParser/resolvers/helpers.d.ts +1 -1
- package/build/services/SecEdgarApi/RequestWrapper.d.ts +30 -0
- package/build/services/SecEdgarApi/RequestWrapper.js +133 -0
- package/build/services/SecEdgarApi/SecConnector.d.ts +1 -1
- package/build/services/SecEdgarApi/SecConnector.js +1 -1
- package/build/services/SecEdgarApi/SecEdgarApi.d.ts +140 -30
- package/build/services/SecEdgarApi/SecEdgarApi.js +284 -42
- package/build/services/SecEdgarApi/Throttler.d.ts +1 -2
- package/build/services/SecEdgarApi/Throttler.js +13 -13
- package/build/services/SecEdgarApi/index.js +1 -5
- package/build/types/common.type.d.ts +12 -0
- package/build/types/common.type.js +2 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.js +3 -5
- package/build/types/parsed-filings.type.d.ts +58 -0
- package/build/types/parsed-filings.type.js +2 -0
- package/build/types/report-raw.type.d.ts +3 -3
- package/build/types/submission.type.d.ts +19 -1
- package/package.json +1 -5
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (
|
|
17
|
+
while (_) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -36,75 +36,187 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var cik_by_symbol_1 = require("../../util/cik-by-symbol");
|
|
40
|
+
var Client_1 = require("../Client");
|
|
41
|
+
var DocumentParser_1 = require("../DocumentParser");
|
|
39
42
|
var ReportParser_1 = require("../ReportParser");
|
|
40
|
-
var
|
|
41
|
-
var
|
|
43
|
+
var RequestWrapper_1 = require("./RequestWrapper");
|
|
44
|
+
var Throttler_1 = require("./Throttler");
|
|
42
45
|
/**
|
|
43
|
-
* Gets
|
|
44
|
-
*
|
|
45
|
-
* Requests are throttled with 120ms delay between requests to avoid rate limiting
|
|
46
|
+
* Gets reports from companies filed with the SEC
|
|
46
47
|
*
|
|
47
48
|
* @see https://www.sec.gov/edgar/sec-api-documentation
|
|
48
49
|
*/
|
|
49
50
|
var SecEdgarApi = /** @class */ (function () {
|
|
50
51
|
function SecEdgarApi(args) {
|
|
51
52
|
if (args === void 0) { args = {
|
|
52
|
-
|
|
53
|
+
client: new Client_1.default(),
|
|
54
|
+
throttler: new Throttler_1.default(),
|
|
55
|
+
cikBySymbol: cik_by_symbol_1.default,
|
|
53
56
|
reportParser: new ReportParser_1.default(),
|
|
54
|
-
|
|
57
|
+
documentParser: new DocumentParser_1.default(),
|
|
55
58
|
}; }
|
|
56
|
-
var
|
|
57
|
-
this.
|
|
59
|
+
var client = args.client, throttler = args.throttler, cikBySymbol = args.cikBySymbol, reportParser = args.reportParser, documentParser = args.documentParser;
|
|
60
|
+
this.client = client;
|
|
61
|
+
this.throttler = throttler;
|
|
62
|
+
this.cikBySymbol = cikBySymbol;
|
|
58
63
|
this.reportParser = reportParser;
|
|
59
|
-
this.
|
|
64
|
+
this.documentParser = documentParser;
|
|
65
|
+
this.baseUrlEdgar = 'https://data.sec.gov';
|
|
66
|
+
this.baseUrlSec = 'https://www.sec.gov';
|
|
60
67
|
}
|
|
68
|
+
SecEdgarApi.prototype.request = function (url, isText) {
|
|
69
|
+
if (isText === void 0) { isText = false; }
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var _this = this;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
74
|
+
var _this = this;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
this.throttler.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
77
|
+
var response, responseData, e_1;
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
_c.trys.push([0, 2, , 3]);
|
|
83
|
+
return [4 /*yield*/, this.client.request({
|
|
84
|
+
url: url,
|
|
85
|
+
onError: function (err) { return reject(err); },
|
|
86
|
+
})];
|
|
87
|
+
case 1:
|
|
88
|
+
response = _c.sent();
|
|
89
|
+
responseData = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.toString('utf-8')) !== null && _b !== void 0 ? _b : null;
|
|
90
|
+
if (response.statusCode >= 400 || typeof responseData !== 'string') {
|
|
91
|
+
reject("Request failed with status ".concat(response.statusCode, " ").concat(response.message));
|
|
92
|
+
}
|
|
93
|
+
resolve((isText ? responseData : JSON.parse(responseData)));
|
|
94
|
+
return [3 /*break*/, 3];
|
|
95
|
+
case 2:
|
|
96
|
+
e_1 = _c.sent();
|
|
97
|
+
reject(e_1);
|
|
98
|
+
return [3 /*break*/, 3];
|
|
99
|
+
case 3: return [2 /*return*/];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}); });
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
});
|
|
105
|
+
}); })];
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
SecEdgarApi.prototype.mapFilingListDetails = function (cik, filingListDetails) {
|
|
110
|
+
var _a;
|
|
111
|
+
var filings = [];
|
|
112
|
+
for (var key in filingListDetails) {
|
|
113
|
+
var k = key;
|
|
114
|
+
var dataArr = filingListDetails[k];
|
|
115
|
+
for (var i = 0; i < dataArr.length; i++) {
|
|
116
|
+
filings[i] = (_a = filings[i]) !== null && _a !== void 0 ? _a : {};
|
|
117
|
+
var filing = filings[i];
|
|
118
|
+
filing[k] = dataArr[i];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (var _i = 0, filings_1 = filings; _i < filings_1.length; _i++) {
|
|
122
|
+
var filing = filings_1[_i];
|
|
123
|
+
var accessionStr = filing.accessionNumber.replace(/-/g, '');
|
|
124
|
+
var primaryDocument = filing.primaryDocument;
|
|
125
|
+
filing.url = "https://www.sec.gov/Archives/edgar/data/".concat(Number(cik), "/").concat(accessionStr, "/").concat(primaryDocument);
|
|
126
|
+
}
|
|
127
|
+
return filings;
|
|
128
|
+
};
|
|
129
|
+
SecEdgarApi.prototype.getCreateRequestUrls = function (params, forms) {
|
|
130
|
+
var symbol = params.symbol, filings = params.filings, _a = params.cutoffDate, cutoffDate = _a === void 0 ? new Date('1970-01-01') : _a;
|
|
131
|
+
var cik = this.getCikString(symbol);
|
|
132
|
+
var filingsArr = Array.isArray(filings) ? filings : this.mapFilingListDetails(cik, filings);
|
|
133
|
+
var filingsFiltered = filingsArr.filter(function (_a) {
|
|
134
|
+
var form = _a.form, filingDate = _a.filingDate;
|
|
135
|
+
return forms.includes(form) && new Date(filingDate).getTime() > cutoffDate.getTime();
|
|
136
|
+
});
|
|
137
|
+
var urls = filingsFiltered.filter(function (_a) {
|
|
138
|
+
var form = _a.form;
|
|
139
|
+
return forms.includes(form);
|
|
140
|
+
}).map(function (_a) {
|
|
141
|
+
var url = _a.url;
|
|
142
|
+
return url;
|
|
143
|
+
});
|
|
144
|
+
return urls;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* If symbol is not in cikBySymbol, assume it is a cik. does not make a request
|
|
148
|
+
*/
|
|
149
|
+
SecEdgarApi.prototype.getCikString = function (symbol) {
|
|
150
|
+
var cik = this.cikBySymbol[symbol];
|
|
151
|
+
if (cik)
|
|
152
|
+
return cik.toString().padStart(10, '0');
|
|
153
|
+
if (!isNaN(Number(symbol)))
|
|
154
|
+
return Number(symbol).toString().padStart(10, '0');
|
|
155
|
+
throw new Error("".concat(symbol, " is not a known symbol or valid cik"));
|
|
156
|
+
};
|
|
61
157
|
/**
|
|
62
|
-
* endpoint: /submissions/CIK${cik}.json
|
|
63
|
-
*
|
|
64
158
|
* This JSON data structure contains metadata such as current name, former name,
|
|
65
159
|
* and stock exchanges and ticker symbols of publicly-traded companies. The object’s
|
|
66
160
|
* property path contains at least one year’s of filing or to 1,000 (whichever is more)
|
|
67
161
|
* of the most recent filings in a compact columnar data array. If the entity has
|
|
68
162
|
* additional filings, files will contain an array of additional JSON files and the
|
|
69
163
|
* date range for the filings each one contains.
|
|
164
|
+
*
|
|
165
|
+
* endpoint: `/submissions/CIK${cik}.json`
|
|
70
166
|
*/
|
|
71
167
|
SecEdgarApi.prototype.getSubmissions = function (params) {
|
|
72
168
|
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var symbol, includeTranslated, cik, submissions;
|
|
73
170
|
return __generator(this, function (_a) {
|
|
74
|
-
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
symbol = params.symbol, includeTranslated = params.includeTranslated;
|
|
174
|
+
cik = this.getCikString(symbol);
|
|
175
|
+
return [4 /*yield*/, this.request("".concat(this.baseUrlEdgar, "/submissions/CIK").concat(cik, ".json"))];
|
|
176
|
+
case 1:
|
|
177
|
+
submissions = _a.sent();
|
|
178
|
+
if (!includeTranslated)
|
|
179
|
+
return [2 /*return*/, submissions];
|
|
180
|
+
submissions.filings.recentTranslated = this.mapFilingListDetails(cik, submissions.filings.recent);
|
|
181
|
+
return [2 /*return*/, submissions];
|
|
182
|
+
}
|
|
75
183
|
});
|
|
76
184
|
});
|
|
77
185
|
};
|
|
78
186
|
/**
|
|
79
|
-
*
|
|
187
|
+
* The company-concept API returns all the XBRL disclosures from a single company (CIK)
|
|
188
|
+
* and concept (a taxonomy and tag) into a single JSON file, with a separate array
|
|
189
|
+
* of facts for each units on measure that the company has chosen to disclose
|
|
190
|
+
* (e.g. net profits reported in U.S. dollars and in Canadian dollars).
|
|
80
191
|
*
|
|
81
|
-
*
|
|
192
|
+
* endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
|
|
82
193
|
*/
|
|
83
|
-
SecEdgarApi.prototype.
|
|
194
|
+
SecEdgarApi.prototype.getFact = function (params) {
|
|
84
195
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
|
|
86
|
-
|
|
196
|
+
var symbol, fact, _a, taxonomy, cik;
|
|
197
|
+
return __generator(this, function (_b) {
|
|
198
|
+
symbol = params.symbol, fact = params.fact, _a = params.taxonomy, taxonomy = _a === void 0 ? 'us-gaap' : _a;
|
|
199
|
+
cik = this.getCikString(symbol);
|
|
200
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyconcept/CIK").concat(cik, "/").concat(taxonomy, "/").concat(fact, ".json"))];
|
|
87
201
|
});
|
|
88
202
|
});
|
|
89
203
|
};
|
|
90
204
|
/**
|
|
91
|
-
*
|
|
205
|
+
* Returns all the company concepts data for a company into a single API call:
|
|
92
206
|
*
|
|
93
|
-
*
|
|
94
|
-
* and concept (a taxonomy and tag) into a single JSON file, with a separate array
|
|
95
|
-
* of facts for each units on measure that the company has chosen to disclose
|
|
96
|
-
* (e.g. net profits reported in U.S. dollars and in Canadian dollars).
|
|
207
|
+
* endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json`
|
|
97
208
|
*/
|
|
98
|
-
SecEdgarApi.prototype.
|
|
209
|
+
SecEdgarApi.prototype.getFacts = function (params) {
|
|
99
210
|
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
var symbol, cik;
|
|
100
212
|
return __generator(this, function (_a) {
|
|
101
|
-
|
|
213
|
+
symbol = params.symbol;
|
|
214
|
+
cik = this.getCikString(symbol);
|
|
215
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyfacts/CIK").concat(cik, ".json"))];
|
|
102
216
|
});
|
|
103
217
|
});
|
|
104
218
|
};
|
|
105
219
|
/**
|
|
106
|
-
* endpoint /api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json
|
|
107
|
-
*
|
|
108
220
|
* The xbrl/frames API aggregates one fact for each reporting entity that is last filed
|
|
109
221
|
* that most closely fits the calendrical period requested. This API supports for annual,
|
|
110
222
|
* quarterly and instantaneous data:
|
|
@@ -122,11 +234,15 @@ var SecEdgarApi = /** @class */ (function () {
|
|
|
122
234
|
* data is assembled by the dates that best align with a calendar quarter or year. Data
|
|
123
235
|
* users should be mindful different reporting start and end dates for facts contained
|
|
124
236
|
* in a frame.
|
|
237
|
+
*
|
|
238
|
+
* endpoint `/api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json`
|
|
125
239
|
*/
|
|
126
240
|
SecEdgarApi.prototype.getFactFrame = function (params) {
|
|
127
241
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
|
|
129
|
-
|
|
242
|
+
var fact, frame, _a, taxonomy, _b, unit;
|
|
243
|
+
return __generator(this, function (_c) {
|
|
244
|
+
fact = params.fact, frame = params.frame, _a = params.taxonomy, taxonomy = _a === void 0 ? 'us-gaap' : _a, _b = params.unit, unit = _b === void 0 ? 'pure' : _b;
|
|
245
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/frames/").concat(taxonomy, "/").concat(fact, "/").concat(unit, "/").concat(frame, ".json"))];
|
|
130
246
|
});
|
|
131
247
|
});
|
|
132
248
|
};
|
|
@@ -142,13 +258,16 @@ var SecEdgarApi = /** @class */ (function () {
|
|
|
142
258
|
*/
|
|
143
259
|
SecEdgarApi.prototype.getReports = function (params) {
|
|
144
260
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var facts;
|
|
146
|
-
return __generator(this, function (
|
|
147
|
-
switch (
|
|
148
|
-
case 0:
|
|
261
|
+
var symbol, _a, withWrapper, facts, reports;
|
|
262
|
+
return __generator(this, function (_b) {
|
|
263
|
+
switch (_b.label) {
|
|
264
|
+
case 0:
|
|
265
|
+
symbol = params.symbol, _a = params.withWrapper, withWrapper = _a === void 0 ? false : _a;
|
|
266
|
+
return [4 /*yield*/, this.getFacts({ symbol: symbol })];
|
|
149
267
|
case 1:
|
|
150
|
-
facts =
|
|
151
|
-
|
|
268
|
+
facts = _b.sent();
|
|
269
|
+
reports = this.reportParser.parseReports(facts);
|
|
270
|
+
return [2 /*return*/, withWrapper ? reports : reports.map(function (report) { return report.getReport(); })];
|
|
152
271
|
}
|
|
153
272
|
});
|
|
154
273
|
});
|
|
@@ -171,19 +290,142 @@ var SecEdgarApi = /** @class */ (function () {
|
|
|
171
290
|
});
|
|
172
291
|
};
|
|
173
292
|
/**
|
|
174
|
-
*
|
|
175
|
-
* reports available from sec.gov. After downloading, you can use factFileReader and reportParser
|
|
176
|
-
* to get and read reports.
|
|
293
|
+
* Gets a list of all tickers and CIKs from `https://www.sec.gov/files/company_tickers.json`
|
|
177
294
|
*
|
|
178
|
-
* Note
|
|
295
|
+
* Note that they key cik_str is actually a number. To get cik string, you can do `${cik_str}`.padStart(10, '0')
|
|
179
296
|
*/
|
|
180
|
-
SecEdgarApi.prototype.
|
|
297
|
+
SecEdgarApi.prototype.getCompanyTickerList = function () {
|
|
181
298
|
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
+
var response;
|
|
182
300
|
return __generator(this, function (_a) {
|
|
183
|
-
|
|
301
|
+
switch (_a.label) {
|
|
302
|
+
case 0: return [4 /*yield*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers.json"))];
|
|
303
|
+
case 1:
|
|
304
|
+
response = _a.sent();
|
|
305
|
+
return [2 /*return*/, Object.values(response)];
|
|
306
|
+
}
|
|
184
307
|
});
|
|
185
308
|
});
|
|
186
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* Gets a list of all tickers and CIKs with exchange and company name from `https://www.sec.gov/files/company_tickers_exchange.json`
|
|
312
|
+
*
|
|
313
|
+
* response: { fields: ['cik', 'name', 'ticker', 'exchange'], data: [ [320193,'Apple Inc.','AAPL','Nasdaq'], ... ] }
|
|
314
|
+
*/
|
|
315
|
+
SecEdgarApi.prototype.getCompanyTickerExchangeList = function () {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
317
|
+
return __generator(this, function (_a) {
|
|
318
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_exchange.json"))];
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Gets a list of all mutual funds from `https://www.sec.gov/files/company_tickers_mf.json`
|
|
324
|
+
*
|
|
325
|
+
* response: { fields: ['cik','seriesId','classId','symbol'], data: [ [2110,'S000009184','C000024954','LACAX'], ... ] }
|
|
326
|
+
*/
|
|
327
|
+
SecEdgarApi.prototype.getMutualFundList = function () {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
+
return __generator(this, function (_a) {
|
|
330
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_mf.json"))];
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Gets a raw xml document string. the parameters are found in the submission list response. (response.filings.recent or response.filings.recentTranslated)
|
|
336
|
+
*
|
|
337
|
+
* Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
|
|
338
|
+
*
|
|
339
|
+
* endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
|
|
340
|
+
*
|
|
341
|
+
* @see https://www.sec.gov/forms for a list of form types
|
|
342
|
+
*/
|
|
343
|
+
SecEdgarApi.prototype.getDocumentXML = function (params) {
|
|
344
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
345
|
+
var accessionNumber, primaryDocument, symbol, cik;
|
|
346
|
+
return __generator(this, function (_a) {
|
|
347
|
+
accessionNumber = params.accessionNumber, primaryDocument = params.primaryDocument, symbol = params.symbol;
|
|
348
|
+
cik = this.cikBySymbol[symbol];
|
|
349
|
+
return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/Archives/edgar/data/").concat(cik, "/").concat(accessionNumber.replace(/-/g, ''), "/").concat(primaryDocument), true)];
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Gets a raw xml document string. the url is found in the submission list response. (response.filings.recentTranslated.url)
|
|
355
|
+
*
|
|
356
|
+
* Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
|
|
357
|
+
*
|
|
358
|
+
* endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
|
|
359
|
+
*
|
|
360
|
+
* @see https://www.sec.gov/forms for a list of form types
|
|
361
|
+
*/
|
|
362
|
+
SecEdgarApi.prototype.getDocumentXMLByUrl = function (params) {
|
|
363
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
364
|
+
return __generator(this, function (_a) {
|
|
365
|
+
return [2 /*return*/, this.request(params.url, true)];
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc.
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
|
|
374
|
+
* const requestWrapper = secEdgarApi.createRequestInsiderTransactions({ symbol: 'AAPL', filings: submissions.filings.recent })
|
|
375
|
+
*
|
|
376
|
+
* const transactions1 = await requestWrapper.requestNext() // array of transactions from most recent doc
|
|
377
|
+
* const transactions2 = await requestWrapper.requestNext() // array of transactions from second most recent doc
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
SecEdgarApi.prototype.createRequestInsiderTransactions = function (params) {
|
|
381
|
+
var _this = this;
|
|
382
|
+
var urls = this.getCreateRequestUrls(params, ['4', '4/A', '5', '5/A']);
|
|
383
|
+
var options = { maxRequests: params.maxRequests };
|
|
384
|
+
var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
|
|
385
|
+
var _a, _b;
|
|
386
|
+
var _c;
|
|
387
|
+
return __generator(this, function (_d) {
|
|
388
|
+
switch (_d.label) {
|
|
389
|
+
case 0:
|
|
390
|
+
_b = (_a = this.documentParser).parseInsiderTransactions;
|
|
391
|
+
_c = {};
|
|
392
|
+
return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
|
|
393
|
+
case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}); };
|
|
397
|
+
return new RequestWrapper_1.default({ urls: urls, options: options, sendRequest: sendRequest });
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* Used for getting institutional holders. extracts holders urls from submission list response, and parses the xml doc.
|
|
401
|
+
*
|
|
402
|
+
* ```ts
|
|
403
|
+
* const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' })
|
|
404
|
+
* const requestWrapper = secEdgarApi.createRequestHolders({ symbol: 'AAPL', filings: submissions.filings.recent })
|
|
405
|
+
*
|
|
406
|
+
* const holders1 = await requestWrapper.requestNext() // array of holders from most recent doc
|
|
407
|
+
* const holders2 = await requestWrapper.requestNext() // array of holders from second most recent doc
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
SecEdgarApi.prototype.createRequestHolders = function (params) {
|
|
411
|
+
var _this = this;
|
|
412
|
+
var urls = this.getCreateRequestUrls(params, ['SC 13G', 'SC 13G/A']);
|
|
413
|
+
var options = { maxRequests: params.maxRequests };
|
|
414
|
+
var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () {
|
|
415
|
+
var _a, _b;
|
|
416
|
+
var _c;
|
|
417
|
+
return __generator(this, function (_d) {
|
|
418
|
+
switch (_d.label) {
|
|
419
|
+
case 0:
|
|
420
|
+
_b = (_a = this.documentParser).parseHolders;
|
|
421
|
+
_c = {};
|
|
422
|
+
return [4 /*yield*/, this.getDocumentXMLByUrl(params)];
|
|
423
|
+
case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])];
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}); };
|
|
427
|
+
return new RequestWrapper_1.default({ urls: urls, options: options, sendRequest: sendRequest });
|
|
428
|
+
};
|
|
187
429
|
return SecEdgarApi;
|
|
188
430
|
}());
|
|
189
431
|
exports.default = SecEdgarApi;
|
|
@@ -15,10 +15,10 @@ export interface IThrottler {
|
|
|
15
15
|
add: (fn: () => Promise<any>) => void;
|
|
16
16
|
}
|
|
17
17
|
export default class Throttler implements IThrottler {
|
|
18
|
+
private readonly decrementTimeouts;
|
|
18
19
|
private readonly queue;
|
|
19
20
|
private readonly results;
|
|
20
21
|
private readonly errors;
|
|
21
|
-
private countRunning;
|
|
22
22
|
private maxConcurrent;
|
|
23
23
|
private delayMs;
|
|
24
24
|
onProgress?: (data: OnProgressData) => void;
|
|
@@ -26,7 +26,6 @@ export default class Throttler implements IThrottler {
|
|
|
26
26
|
onError?: (err: any) => void;
|
|
27
27
|
onEnd?: (results: any[], errors: any[]) => void;
|
|
28
28
|
constructor(args?: ThrottlerArgs);
|
|
29
|
-
setMaxConcurrent(maxConcurrent: number): void;
|
|
30
29
|
setDelayMs(delayMs: number): void;
|
|
31
30
|
add(fn: () => Promise<any>): void;
|
|
32
31
|
private run;
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (
|
|
17
|
+
while (_) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -39,10 +39,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var Throttler = /** @class */ (function () {
|
|
40
40
|
function Throttler(args) {
|
|
41
41
|
if (args === void 0) { args = {}; }
|
|
42
|
-
var _a = args.maxConcurrent, maxConcurrent = _a === void 0 ?
|
|
42
|
+
var _a = args.maxConcurrent, maxConcurrent = _a === void 0 ? 10 : _a, _b = args.delayMs, delayMs = _b === void 0 ? 1100 : _b, onProgress = args.onProgress, onResult = args.onResult, onError = args.onError, onEnd = args.onEnd;
|
|
43
43
|
this.maxConcurrent = maxConcurrent;
|
|
44
44
|
this.delayMs = delayMs;
|
|
45
|
-
this.
|
|
45
|
+
this.decrementTimeouts = new Set();
|
|
46
46
|
this.queue = [];
|
|
47
47
|
this.results = [];
|
|
48
48
|
this.errors = [];
|
|
@@ -51,9 +51,6 @@ var Throttler = /** @class */ (function () {
|
|
|
51
51
|
this.onError = onError;
|
|
52
52
|
this.onEnd = onEnd;
|
|
53
53
|
}
|
|
54
|
-
Throttler.prototype.setMaxConcurrent = function (maxConcurrent) {
|
|
55
|
-
this.maxConcurrent = maxConcurrent;
|
|
56
|
-
};
|
|
57
54
|
Throttler.prototype.setDelayMs = function (delayMs) {
|
|
58
55
|
this.delayMs = delayMs;
|
|
59
56
|
};
|
|
@@ -64,22 +61,27 @@ var Throttler = /** @class */ (function () {
|
|
|
64
61
|
Throttler.prototype.run = function () {
|
|
65
62
|
var _a, _b, _c, _d;
|
|
66
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var fn, result, err_1;
|
|
64
|
+
var countRunning, fn, decrementTimeout, result, err_1;
|
|
68
65
|
var _this = this;
|
|
69
66
|
return __generator(this, function (_e) {
|
|
70
67
|
switch (_e.label) {
|
|
71
68
|
case 0:
|
|
72
|
-
|
|
69
|
+
countRunning = this.decrementTimeouts.size;
|
|
70
|
+
if (countRunning >= this.maxConcurrent) {
|
|
73
71
|
return [2 /*return*/];
|
|
74
72
|
}
|
|
75
73
|
if (this.queue.length === 0) {
|
|
76
|
-
if (
|
|
74
|
+
if (countRunning === 0) {
|
|
77
75
|
(_a = this.onEnd) === null || _a === void 0 ? void 0 : _a.call(this, this.results, this.errors);
|
|
78
76
|
}
|
|
79
77
|
return [2 /*return*/];
|
|
80
78
|
}
|
|
81
|
-
this.countRunning++;
|
|
82
79
|
fn = this.queue.shift();
|
|
80
|
+
decrementTimeout = setTimeout(function () {
|
|
81
|
+
_this.decrementTimeouts.delete(decrementTimeout);
|
|
82
|
+
_this.run();
|
|
83
|
+
}, this.delayMs);
|
|
84
|
+
this.decrementTimeouts.add(decrementTimeout);
|
|
83
85
|
_e.label = 1;
|
|
84
86
|
case 1:
|
|
85
87
|
_e.trys.push([1, 3, , 4]);
|
|
@@ -95,12 +97,10 @@ var Throttler = /** @class */ (function () {
|
|
|
95
97
|
(_c = this.onError) === null || _c === void 0 ? void 0 : _c.call(this, err_1);
|
|
96
98
|
return [3 /*break*/, 4];
|
|
97
99
|
case 4:
|
|
98
|
-
this.countRunning--;
|
|
99
100
|
(_d = this.onProgress) === null || _d === void 0 ? void 0 : _d.call(this, {
|
|
100
101
|
queueLength: this.queue.length,
|
|
101
|
-
countRunning: this.
|
|
102
|
+
countRunning: this.decrementTimeouts.size,
|
|
102
103
|
});
|
|
103
|
-
setTimeout(function () { return _this.run(); }, this.delayMs);
|
|
104
104
|
return [2 /*return*/];
|
|
105
105
|
}
|
|
106
106
|
});
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface XMLParams {
|
|
2
|
+
xml: string;
|
|
3
|
+
}
|
|
4
|
+
export interface CompanyTickerItem {
|
|
5
|
+
cik_str: number;
|
|
6
|
+
ticker: string;
|
|
7
|
+
title: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FieldDataResponse<Field extends string = string> {
|
|
10
|
+
fields: Field[];
|
|
11
|
+
data: (string | number)[][];
|
|
12
|
+
}
|
package/build/types/index.d.ts
CHANGED
package/build/types/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -18,3 +14,5 @@ __exportStar(require("./company-facts.type"), exports);
|
|
|
18
14
|
__exportStar(require("./report-raw.type"), exports);
|
|
19
15
|
__exportStar(require("./report-translated.type"), exports);
|
|
20
16
|
__exportStar(require("./submission.type"), exports);
|
|
17
|
+
__exportStar(require("./parsed-filings.type"), exports);
|
|
18
|
+
__exportStar(require("./common.type"), exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
interface TransactionDescriptionByCode {
|
|
2
|
+
S: 'Sale';
|
|
3
|
+
V: 'Voluntary Reporting';
|
|
4
|
+
A: 'Grant';
|
|
5
|
+
D: 'Sale to Issuer';
|
|
6
|
+
F: 'Payment of Exercise Price';
|
|
7
|
+
I: 'Discretionary Transaction';
|
|
8
|
+
M: 'Conversion of Derivative Exempt';
|
|
9
|
+
C: 'Conversion of Derivative';
|
|
10
|
+
E: 'Expiration of Short Derivative Position';
|
|
11
|
+
H: 'Expiration of Long Derivative Position';
|
|
12
|
+
O: 'Exercise of out-of-the-money Derivative';
|
|
13
|
+
X: 'Exercise of in-the-money Derivative';
|
|
14
|
+
G: 'Gift';
|
|
15
|
+
L: 'Small Acquisition';
|
|
16
|
+
W: 'Acquisition or Disposition By Will or Laws';
|
|
17
|
+
Z: 'Voting Trust Deposit or Withdrawal';
|
|
18
|
+
J: 'Other Acquisition or Disposition';
|
|
19
|
+
K: 'Equity Swap';
|
|
20
|
+
U: 'Disposition Change in Control';
|
|
21
|
+
}
|
|
22
|
+
export declare type TransactionType = 'Acquire' | 'Dispose';
|
|
23
|
+
export declare type TransactionCode = keyof TransactionDescriptionByCode;
|
|
24
|
+
export declare type TransactionDescription = TransactionDescriptionByCode[TransactionCode];
|
|
25
|
+
export interface InsiderTransaction {
|
|
26
|
+
filerName: string;
|
|
27
|
+
filerPosition: string;
|
|
28
|
+
filerPositionTypes: string[];
|
|
29
|
+
securityType: string;
|
|
30
|
+
securityTypeUnderlying: string | null;
|
|
31
|
+
category: 'Derivative' | 'Non-Derivative';
|
|
32
|
+
date: string;
|
|
33
|
+
dateExecuted: string | null;
|
|
34
|
+
dateExpiration: string | null;
|
|
35
|
+
dateExercisable: string | null;
|
|
36
|
+
transactionDescription: string | null;
|
|
37
|
+
transactionCode: TransactionCode | null;
|
|
38
|
+
transactionType: TransactionType | null;
|
|
39
|
+
sharesEnding: number | null;
|
|
40
|
+
shares: number | null;
|
|
41
|
+
sharesUnderlying: number | null;
|
|
42
|
+
price: number | null;
|
|
43
|
+
priceExcercised: number | null;
|
|
44
|
+
ownership: string;
|
|
45
|
+
explainationByKey: Partial<Record<keyof InsiderTransaction, string>>;
|
|
46
|
+
}
|
|
47
|
+
export interface Holder {
|
|
48
|
+
name: string;
|
|
49
|
+
origin: string;
|
|
50
|
+
shares: number;
|
|
51
|
+
percentOfClass: string;
|
|
52
|
+
votingPowerSole: string | null;
|
|
53
|
+
votingPowerShared: string | null;
|
|
54
|
+
dispositivePowerSole: string | null;
|
|
55
|
+
dispositivePowerShared: string | null;
|
|
56
|
+
typeOfReportingPerson: string | null;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Contains all keys matched from the report, along with the added keys dateEnd, dateFiled, fiscalPeriod, fiscalYear.
|
|
3
3
|
*/
|
|
4
|
-
export type ReportRaw = {
|
|
4
|
+
export declare type ReportRaw = {
|
|
5
5
|
[key: string]: string | number | boolean;
|
|
6
6
|
dateReport: string;
|
|
7
7
|
dateFiled: string;
|
|
@@ -19,5 +19,5 @@ export type ReportRaw = {
|
|
|
19
19
|
*
|
|
20
20
|
* for dei, see https://www.sec.gov/structureddata/announcement/osd-announcement-2212-new-2022q4-taxonomies
|
|
21
21
|
*/
|
|
22
|
-
export type ReportType = 'QUARTERLY' | 'ANNUAL' | '8K' | 'DOCUMENT_ENTITY_INFO';
|
|
23
|
-
export type FiscalPeriod = 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY';
|
|
22
|
+
export declare type ReportType = 'QUARTERLY' | 'ANNUAL' | '8K' | 'DOCUMENT_ENTITY_INFO';
|
|
23
|
+
export declare type FiscalPeriod = 'Q1' | 'Q2' | 'Q3' | 'Q4' | 'FY';
|