UNPKG

sec-edgar-api

Version:

Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.

752 lines (751 loc) 40.4 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { 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; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var cik_by_symbol_1 = require("../../util/cik-by-symbol"); var Client_1 = require("../Client"); var DocumentParser_1 = require("../DocumentParser"); var ReportParser_1 = require("../ReportParser"); var FilingMapper_1 = require("./FilingMapper"); var RequestWrapper_1 = require("./RequestWrapper"); var Throttler_1 = require("./Throttler"); /** * Gets reports from companies filed with the SEC * * @see https://www.sec.gov/edgar/sec-api-documentation */ var SecEdgarApi = /** @class */ (function () { function SecEdgarApi(args) { if (args === void 0) { args = { client: new Client_1.default(), throttler: new Throttler_1.default(), cikBySymbol: cik_by_symbol_1.default, reportParser: new ReportParser_1.default(), documentParser: new DocumentParser_1.default(), filingMapper: new FilingMapper_1.default(), }; } var client = args.client, throttler = args.throttler, cikBySymbol = args.cikBySymbol, reportParser = args.reportParser, documentParser = args.documentParser, _a = args.filingMapper, filingMapper = _a === void 0 ? new FilingMapper_1.default() : _a; this.client = client; this.throttler = throttler; this.cikBySymbol = cikBySymbol; this.reportParser = reportParser; this.documentParser = documentParser; this.filingMapper = filingMapper; this.baseUrlEdgar = 'https://data.sec.gov'; this.baseUrlSec = 'https://www.sec.gov'; } SecEdgarApi.prototype.request = function (url, isText) { if (isText === void 0) { isText = false; } return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { _this.throttler.add(function () { return __awaiter(_this, void 0, void 0, function () { var response, responseData, e_1; var _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); return [4 /*yield*/, this.client.request({ url: url, onError: function (err) { return reject(err); }, })]; case 1: response = _c.sent(); responseData = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.toString('utf-8')) !== null && _b !== void 0 ? _b : null; if (response.statusCode >= 400 || typeof responseData !== 'string') { reject("Request failed with status ".concat(response.statusCode, " ").concat(response.message)); } resolve((isText ? responseData : JSON.parse(responseData))); return [3 /*break*/, 3]; case 2: e_1 = _c.sent(); reject(e_1); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }); })]; }); }); }; SecEdgarApi.prototype.mapFilingListDetails = function (cik, filingListDetails) { return this.filingMapper.mapFilingListDetails(cik, filingListDetails); }; SecEdgarApi.prototype.getCreateRequestSubmissions = function (params, forms) { var symbol = params.symbol, filings = params.filings, _a = params.cutoffDate, cutoffDate = _a === void 0 ? new Date('1970-01-01') : _a; var cik = this.getCikString(symbol); var filingsArr = Array.isArray(filings) ? filings : this.mapFilingListDetails(cik, filings); return filingsArr.filter(function (_a) { var form = _a.form, filingDate = _a.filingDate; return forms.includes(form) && new Date(filingDate).getTime() > cutoffDate.getTime(); }); }; /** * If symbol is not in cikBySymbol, assume it is a cik. does not make a request */ SecEdgarApi.prototype.getCikString = function (symbol) { var cik = this.cikBySymbol[symbol]; if (cik) return cik.toString().padStart(10, '0'); if (!isNaN(Number(symbol))) return Number(symbol).toString().padStart(10, '0'); throw new Error("".concat(symbol, " is not a known symbol or valid cik")); }; /** * This JSON data structure contains metadata such as current name, former name, * and stock exchanges and ticker symbols of publicly-traded companies. The object’s * property path contains at least one year’s of filing or to 1,000 (whichever is more) * of the most recent filings in a compact columnar data array. If the entity has * additional filings, files will contain an array of additional JSON files and the * date range for the filings each one contains. * * endpoint: `/submissions/CIK${cik}.json` */ SecEdgarApi.prototype.getSubmissions = function (params) { return __awaiter(this, void 0, void 0, function () { var symbol, includeOldFilings, cik, submissionList, additionalFilings, filings; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: symbol = params.symbol, includeOldFilings = params.includeOldFilings; cik = this.getCikString(symbol); return [4 /*yield*/, this.request("".concat(this.baseUrlEdgar, "/submissions/CIK").concat(cik, ".json"))]; case 1: submissionList = _a.sent(); if (!includeOldFilings) return [3 /*break*/, 3]; return [4 /*yield*/, Promise.all(submissionList.filings.files.map(function (file) { return _this.request("".concat(_this.baseUrlEdgar, "/submissions/").concat(file.name)); }))]; case 2: additionalFilings = _a.sent(); additionalFilings.forEach(function (data) { var _loop_1 = function (key) { var k = key; var valuesCurrent = submissionList.filings.recent[k]; var values = data[k]; values.forEach(function (v) { return valuesCurrent.push(v); }); }; for (var key in data) { _loop_1(key); } }); _a.label = 3; case 3: submissionList.cik = Number(submissionList.cik); filings = this.mapFilingListDetails(cik, submissionList.filings.recent); return [2 /*return*/, { submissionList: submissionList, filings: filings }]; } }); }); }; /** * The company-concept API returns all the XBRL disclosures from a single company (CIK) * and concept (a taxonomy and tag) into a single JSON file, with a separate array * of facts for each units on measure that the company has chosen to disclose * (e.g. net profits reported in U.S. dollars and in Canadian dollars). * * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json` */ SecEdgarApi.prototype.getFact = function (params) { return __awaiter(this, void 0, void 0, function () { var symbol, fact, _a, taxonomy, cik; return __generator(this, function (_b) { symbol = params.symbol, fact = params.fact, _a = params.taxonomy, taxonomy = _a === void 0 ? 'us-gaap' : _a; cik = this.getCikString(symbol); return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyconcept/CIK").concat(cik, "/").concat(taxonomy, "/").concat(fact, ".json"))]; }); }); }; /** * Returns all the company concepts data for a company into a single API call: * * endpoint `/api/xbrl/companyconcept/CIK${cik}/${taxonomy}/${fact}.json` */ SecEdgarApi.prototype.getFacts = function (params) { return __awaiter(this, void 0, void 0, function () { var symbol, cik; return __generator(this, function (_a) { symbol = params.symbol; cik = this.getCikString(symbol); return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/companyfacts/CIK").concat(cik, ".json"))]; }); }); }; /** * The xbrl/frames API aggregates one fact for each reporting entity that is last filed * that most closely fits the calendrical period requested. This API supports for annual, * quarterly and instantaneous data: * * data.sec.gov/api/xbrl/frames/us-gaap/AccountsPayableCurrent/USD/CY2019Q1I.json * * Where the units of measure specified in the XBRL contains a numerator and a denominator, * these are separated by “-per-” such as “USD-per-shares”. Note that the default unit * in XBRL is “pure”. * * The period format is CY#### for annual data (duration 365 days +/- 30 days), CY####Q# * for quarterly data (duration 91 days +/- 30 days), and CY####Q#I for instantaneous data. * Because company financial calendars can start and end on any month or day and even * change in length from quarter to quarter to according to the day of the week, the frame * data is assembled by the dates that best align with a calendar quarter or year. Data * users should be mindful different reporting start and end dates for facts contained * in a frame. * * endpoint `/api/xbrl/frames/${taxonomy}/${fact}/${unit}/${frame}.json` */ SecEdgarApi.prototype.getFactFrame = function (params) { return __awaiter(this, void 0, void 0, function () { var fact, frame, _a, taxonomy, _b, unit; return __generator(this, function (_c) { 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; return [2 /*return*/, this.request("".concat(this.baseUrlEdgar, "/api/xbrl/frames/").concat(taxonomy, "/").concat(fact, "/").concat(unit, "/").concat(frame, ".json"))]; }); }); }; /** * Note: Properties that are not provied from report are calculated an may not be accurate, * verify results finance.yahoo.com (ex: https://finance.yahoo.com/quote/AAPL/financials) * * Please contribute to improve resolving report properties: https://github.com/andyevers/sec-edgar-api * * Parses reports from company facts. Calculates missing properties and uses a single interface * for all reports. This includes only 10-K and 10-Q annual and quarterly reports. To include * all reports, use getReportsRaw. * * @deprecated Formerly getReports. This will be removed in a future version. */ SecEdgarApi.prototype.getReportsLegacy = function (params) { return __awaiter(this, void 0, void 0, function () { var _a, withWrapper, _b, usePropertyResolver, reportsRaw, reportsWithWrapper, reports; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = params.withWrapper, withWrapper = _a === void 0 ? false : _a, _b = params.usePropertyResolver, usePropertyResolver = _b === void 0 ? true : _b; return [4 /*yield*/, this.getReportsRaw(__assign(__assign({}, params), { includeNamePrefix: false }))]; case 1: reportsRaw = _c.sent(); reportsWithWrapper = this.reportParser.parseReportsFromRawLegacy({ reportsRaw: reportsRaw, usePropertyResolver: usePropertyResolver }); reports = withWrapper ? reportsWithWrapper : reportsWithWrapper.map(function (report) { return report.getReport(); }); return [2 /*return*/, reports]; } }); }); }; /** * Note: Properties that are not provied from report are calculated an may not be accurate, * verify results finance.yahoo.com (ex: https://finance.yahoo.com/quote/AAPL/financials) * * Please contribute to improve resolving report properties: https://github.com/andyevers/sec-edgar-api * * Parses reports from company facts. Calculates missing properties and uses a single interface * for all reports. This includes only 10-K and 10-Q annual and quarterly reports. To include * all reports, use getReportsRaw. */ SecEdgarApi.prototype.getReports = function (params) { return __awaiter(this, void 0, void 0, function () { var calculationMap, reports; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: calculationMap = params.calculationMap; return [4 /*yield*/, this.getReportsRaw(__assign(__assign({}, params), { includeNamePrefix: true }))]; case 1: reports = _a.sent(); return [2 /*return*/, reports.map(function (report) { return _this.reportParser.translateReport({ report: report, calculationMap: calculationMap }); })]; } }); }); }; /** * Parses reports from company facts. */ SecEdgarApi.prototype.getReportsRaw = function (params) { return __awaiter(this, void 0, void 0, function () { var symbol, _a, includeNamePrefix, _b, adjustForSplits, _c, resolvePeriodValues, splits, filings, companyFacts, reports; return __generator(this, function (_d) { switch (_d.label) { case 0: symbol = params.symbol, _a = params.includeNamePrefix, includeNamePrefix = _a === void 0 ? false : _a, _b = params.adjustForSplits, adjustForSplits = _b === void 0 ? true : _b, _c = params.resolvePeriodValues, resolvePeriodValues = _c === void 0 ? true : _c, splits = params.splits, filings = params.filings; return [4 /*yield*/, this.getFacts({ symbol: symbol })]; case 1: companyFacts = _d.sent(); reports = this.reportParser.parseReportsRaw(companyFacts, { adjustForSplits: adjustForSplits, resolvePeriodValues: resolvePeriodValues, includeNamePrefix: includeNamePrefix, splits: splits, filings: filings, }); return [2 /*return*/, reports]; } }); }); }; /** * Gets a list of all tickers and CIKs from `https://www.sec.gov/files/company_tickers.json` * * Note that they key cik_str is actually a number. To get cik string, you can do `${cik_str}`.padStart(10, '0') */ SecEdgarApi.prototype.getCompanyTickerList = function () { return __awaiter(this, void 0, void 0, function () { var response; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers.json"))]; case 1: response = _a.sent(); return [2 /*return*/, Object.values(response)]; } }); }); }; /** * Gets a list of all tickers and CIKs with exchange and company name from `https://www.sec.gov/files/company_tickers_exchange.json` * * response: { fields: ['cik', 'name', 'ticker', 'exchange'], data: [ [320193,'Apple Inc.','AAPL','Nasdaq'], ... ] } */ SecEdgarApi.prototype.getCompanyTickerExchangeList = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_exchange.json"))]; }); }); }; /** * Gets a list of all mutual funds from `https://www.sec.gov/files/company_tickers_mf.json` * * response: { fields: ['cik','seriesId','classId','symbol'], data: [ [2110,'S000009184','C000024954','LACAX'], ... ] } */ SecEdgarApi.prototype.getMutualFundList = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.request("".concat(this.baseUrlSec, "/files/company_tickers_mf.json"))]; }); }); }; /** * If url is provided, all other props are ignored. Otherwise, both accessionNumber * and symbol (symbol or cik) are required. provide fileName if different from `${accessionNumber}.txt` * * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders) * * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}` * * @see https://www.sec.gov/forms for a list of form types */ SecEdgarApi.prototype.getDocument = function (params) { return __awaiter(this, void 0, void 0, function () { var _a, accessionNumber, fileName, _b, symbol, urlProp, url; return __generator(this, function (_c) { _a = params.accessionNumber, accessionNumber = _a === void 0 ? '' : _a, fileName = params.fileName, _b = params.symbol, symbol = _b === void 0 ? '' : _b, urlProp = params.url; if (!urlProp && (!accessionNumber || !symbol)) { throw new Error('Must provide either url or (a)ccessionNumber and symbol)'); } url = urlProp !== null && urlProp !== void 0 ? urlProp : this.buildDocumentUrl({ symbol: symbol, accessionNumber: accessionNumber, fileName: fileName }); return [2 /*return*/, this.request(url, true)]; }); }); }; /** * Fetches SEC document and parses XBRL data. If url is provided, symbol and accessionNumber are ignored. * * Use "include" params to specify what to parse. If not provided, all data is parsed. */ SecEdgarApi.prototype.getDocumentXbrl = function (params) { return __awaiter(this, void 0, void 0, function () { var url, accessionNumber, symbol, options, xml; return __generator(this, function (_a) { switch (_a.label) { case 0: url = params.url, accessionNumber = params.accessionNumber, symbol = params.symbol, options = __rest(params, ["url", "accessionNumber", "symbol"]); return [4 /*yield*/, this.getDocument({ url: url, accessionNumber: accessionNumber, symbol: symbol })]; case 1: xml = _a.sent(); return [2 /*return*/, this.documentParser.parseXbrl(__assign({ xml: xml }, options))]; } }); }); }; /** * Builds a url for a document. If fileName is not provided, it defaults to `${accessionNumber}.txt` * * format: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumberNoHyphen)}/${fileNameAccessionFile}` */ SecEdgarApi.prototype.buildDocumentUrl = function (params) { var symbol = params.symbol, accessionNumber = params.accessionNumber, fileNameProp = params.fileName; var cik = Number(this.getCikString(symbol)); var fileName = fileNameProp !== null && fileNameProp !== void 0 ? fileNameProp : "".concat(accessionNumber, ".txt"); return "".concat(this.baseUrlSec, "/Archives/edgar/data/").concat(cik, "/").concat(accessionNumber.replace(/-/g, ''), "/").concat(fileName); }; /** * Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc. * * ```ts * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' }) * const requestWrapper = secEdgarApi.createRequestInsiderTransactions({ symbol: 'AAPL', filings: submissions.filings.recent }) * * const transactions1 = (await requestWrapper.requestNext()).result.transactions // array of transactions from most recent doc * const transactions2 = (await requestWrapper.requestNext()).result.transactions // array of transactions from second most recent doc * ``` */ SecEdgarApi.prototype.createRequestInsiderTransactions = function (params) { var _this = this; var submissions = this.getCreateRequestSubmissions(params, ['4', '4/A', '5', '5/A']); var options = { maxRequests: params.maxRequests }; var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; var _c; return __generator(this, function (_d) { switch (_d.label) { case 0: _b = (_a = this.documentParser).parseForm4; _c = {}; return [4 /*yield*/, this.getDocument(params)]; case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])]; } }); }); }; return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest, usePrimaryDocument: true, }); }; /** * Used for getting institutional holders. extracts holders urls from submission list response, and parses the xml doc. * * ```ts * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' }) * const requestWrapper = secEdgarApi.createRequestInstitutionalHolders({ symbol: 'AAPL', filings: submissions.filings.recent }) * * const holders1 = (await requestWrapper.requestNext()).result.holders // array of holders from most recent doc * const holders2 = (await requestWrapper.requestNext()).result.holders // array of holders from second most recent doc * ``` */ SecEdgarApi.prototype.createRequestInstitutionalHolders = function (params) { var _this = this; var submissions = this.getCreateRequestSubmissions(params, ['SC 13G', 'SC 13G/A']); var options = { maxRequests: params.maxRequests }; var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; var _c; return __generator(this, function (_d) { switch (_d.label) { case 0: _b = (_a = this.documentParser).parseForm13g; _c = {}; return [4 /*yield*/, this.getDocument(params)]; case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])]; } }); }); }; return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest, usePrimaryDocument: true, }); }; /** * Used for getting earnings report tables from submission files. * * ```ts * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' }) * const requestWrapper = secEdgarApi.createRequesEarningsReports({ symbol: 'AAPL', filings: submissions.filings.recent }) * * const tables1 = (await requestWrapper.requestNext()).result.tables // array of tables from most recent doc * const tables2 = (await requestWrapper.requestNext()).result.tables // array of tables from second most recent doc * ``` */ SecEdgarApi.prototype.createRequestEarningsReports = function (params) { var _this = this; var submissions = this.getCreateRequestSubmissions(params, [ '10-Q', '10-Q/A', '10-K', '10-K/A', '20-F', '20-F/A', '40-F', '40-F/A', ]); var options = { maxRequests: params.maxRequests }; var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; var _c; return __generator(this, function (_d) { switch (_d.label) { case 0: _b = (_a = this.documentParser).parseForm10k; _c = {}; return [4 /*yield*/, this.getDocument(params)]; case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])]; } }); }); }; return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest, usePrimaryDocument: true, }); }; /** * Proxy statement includes list of holders, executiveCompensation, and other tables. returns FormDef14aData * * ```ts * const submissions = await secEdgarApi.getSubmissions({ symbol: 'AAPL' }) * const requestWrapper = secEdgarApi.createRequesProxyStatement({ symbol: 'AAPL', filings: submissions.filings.recent }) * * const { holders, executiveCompensation } = (await requestWrapper.requestNext()).result * ``` */ SecEdgarApi.prototype.createRequestProxyStatement = function (params) { var _this = this; var submissions = this.getCreateRequestSubmissions(params, ['DEF 14A']); var options = { maxRequests: params.maxRequests }; var sendRequest = function (params) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; var _c; return __generator(this, function (_d) { switch (_d.label) { case 0: _b = (_a = this.documentParser).parseFormDef14a; _c = {}; return [4 /*yield*/, this.getDocument(params)]; case 1: return [2 /*return*/, _b.apply(_a, [(_c.xml = _d.sent(), _c)])]; } }); }); }; return new RequestWrapper_1.default({ submissions: submissions, options: options, sendRequest: sendRequest, usePrimaryDocument: true, }); }; /** * Gets list of filings for a day up to 5 days ago. * * NOTE: This has not been updated since 2014 and has had issues with not returning data. * * @see https://www.sec.gov/edgar/searchedgar/currentevents */ SecEdgarApi.prototype.getCurrentFilingsDaily = function (params) { var _a; return __awaiter(this, void 0, void 0, function () { var _b, _c, formType, _d, lookbackDays, _e, startsWith, indexByFormType, indexFormType, url, xml; return __generator(this, function (_f) { switch (_f.label) { case 0: _b = params !== null && params !== void 0 ? params : {}, _c = _b.formType, formType = _c === void 0 ? 'ALL' : _c, _d = _b.lookbackDays, lookbackDays = _d === void 0 ? 0 : _d, _e = _b.startsWith, startsWith = _e === void 0 ? '' : _e; if (lookbackDays > 5) { throw new Error("lookbackDays must be <= 5. Received ".concat(lookbackDays)); } indexByFormType = { '10-K': 0, '10-Q': 1, '14': 2, '485': 3, '8-K': 4, 'S-8': 5, ALL: 6, }; indexFormType = (_a = indexByFormType[formType]) !== null && _a !== void 0 ? _a : 0; url = "".concat(this.baseUrlSec, "/cgi-bin/current?q1=").concat(lookbackDays, "&q2=").concat(indexFormType, "&q3=").concat(startsWith); return [4 /*yield*/, this.request(url, true)]; case 1: xml = (_f.sent()); return [2 /*return*/, this.documentParser.parseCurrentFilingsDaily({ xml: xml })]; } }); }); }; /** * Lists all types of current filings including non XBRL. If fetching earnings reports, * use getCurrentFilingsXbrl instead. * * @see https://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent */ SecEdgarApi.prototype.getCurrentFilings = function (params) { var _a; return __awaiter(this, void 0, void 0, function () { var _b, _c, page, _d, itemsPerPage, formType, searchType, symbol, type, owner, offset, cik, url, xml; return __generator(this, function (_e) { switch (_e.label) { case 0: _b = params !== null && params !== void 0 ? params : {}, _c = _b.page, page = _c === void 0 ? 1 : _c, _d = _b.itemsPerPage, itemsPerPage = _d === void 0 ? 100 : _d, formType = _b.formType, searchType = _b.searchType, symbol = _b.symbol; type = (_a = formType === null || formType === void 0 ? void 0 : formType.trim().replace(/\s/g, '+')) !== null && _a !== void 0 ? _a : null; owner = searchType !== null && searchType !== void 0 ? searchType : ((formType === null || formType === void 0 ? void 0 : formType.includes(' ')) ? 'include' : 'only'); offset = (page - 1) * Math.max(1, itemsPerPage || 100); cik = symbol ? Number(this.getCikString(symbol)) : null; url = "".concat(this.baseUrlSec, "/cgi-bin/browse-edgar?action=getcurrent&start=").concat(offset, "&count=").concat(itemsPerPage, "&output=atom"); if (cik) url += "&CIK=".concat(symbol); if (type) url += "&type=".concat(formType); if (owner) url += "&owner=".concat(searchType); return [4 /*yield*/, this.request(url, true)]; case 1: xml = (_e.sent()); return [2 /*return*/, this.documentParser.parseCurrentFilings({ xml: xml })]; } }); }); }; /** * Fetches XBRL filings using the RSS feeds provided by the SEC. * * @see https://www.sec.gov/structureddata/rss-feeds-submitted-filings */ SecEdgarApi.prototype.getCurrentFilingsXbrl = function (params) { return __awaiter(this, void 0, void 0, function () { var _a, taxonomy, urlByTaxonomy, url, xml; return __generator(this, function (_b) { switch (_b.label) { case 0: _a = (params !== null && params !== void 0 ? params : {}).taxonomy, taxonomy = _a === void 0 ? 'allXbrl' : _a; urlByTaxonomy = { usGaap: 'https://www.sec.gov/Archives/edgar/usgaap.rss.xml', mutualFund: 'https://www.sec.gov/Archives/edgar/xbrl-rr.rss.xml', inlineXbrl: 'https://www.sec.gov/Archives/edgar/xbrl-inline.rss.xml', allXbrl: 'https://www.sec.gov/Archives/edgar/xbrlrss.all.xml', }; url = urlByTaxonomy[taxonomy] || urlByTaxonomy.allXbrl; return [4 /*yield*/, this.request(url, true)]; case 1: xml = _b.sent(); return [2 /*return*/, this.documentParser.parseCurrentFilingsXbrl({ xml: xml })]; } }); }); }; /** * Gets insider transactions for a provided symbol or CIK. * * To get transactions by a specific owner, set isOwnerCik to true and provide * the owner CIK for the symbol parameter. * * example at https://www.sec.gov/cgi-bin/own-disp?action=getissuer&CIK=0000320193 */ SecEdgarApi.prototype.getInsiderTransactions = function (params) { return __awaiter(this, void 0, void 0, function () { var page, symbol, itemsPerPage, _a, isOwnerCik, action, offset, cik, url, xml; return __generator(this, function (_b) { switch (_b.label) { case 0: page = params.page, symbol = params.symbol, itemsPerPage = params.itemsPerPage, _a = params.isOwnerCik, isOwnerCik = _a === void 0 ? false : _a; action = isOwnerCik ? 'getowner' : 'getissuer'; offset = (page - 1) * Math.max(1, itemsPerPage || 100); cik = this.getCikString(symbol); url = "".concat(this.baseUrlSec, "/cgi-bin/own-disp?action=").concat(action, "&CIK=").concat(cik, "&owner=include&start=").concat(offset, "&count=").concat(itemsPerPage); return [4 /*yield*/, this.request(url, true)]; case 1: xml = (_b.sent()); return [2 /*return*/, this.documentParser.parseInsiderTransactions({ xml: xml })]; } }); }); }; /** * Search for companies from by name, sic code, or state. * * example at https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=0&count=100&hidefilings=0&company=Apple&match=contains * * TODO: Switch this to use output=atom in the url */ SecEdgarApi.prototype.searchCompanies = function (params) { return __awaiter(this, void 0, void 0, function () { var sic, page, itemsPerPageProp, state, company, companyMatch, match, itemsPerPage, offset, url, xml; return __generator(this, function (_a) { switch (_a.label) { case 0: sic = params.sic, page = params.page, itemsPerPageProp = params.itemsPerPage, state = params.state, company = params.company, companyMatch = params.companyMatch; match = companyMatch === 'startsWith' ? '' : 'contains'; itemsPerPage = Math.max(1, Math.min(100, itemsPerPageProp || 100)); offset = (page - 1) * itemsPerPage; url = "".concat(this.baseUrlSec, "/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=").concat(offset, "&count=").concat(itemsPerPage, "&hidefilings=0"); if (sic) url += "&SIC=".concat(sic); if (state) url += "&State=".concat(state); if (company) url += "&company=".concat(company, "&match=").concat(match); if (!sic && !state && !company) { throw new Error('You must provide sic, company, or state filters'); } return [4 /*yield*/, this.request(url, true)]; case 1: xml = (_a.sent()); return [2 /*return*/, this.documentParser.parseCompanies({ xml: xml })]; } }); }); }; return SecEdgarApi; }()); exports.default = SecEdgarApi;