Skip to content

Commit 5745792

Browse files
added Insider Trading Data API
1 parent 30ce5a9 commit 5745792

6 files changed

Lines changed: 146 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
venv
12
env
23
dist
34
build
45
.idea
56
.pypirc
67
sec_api.egg-info
7-
sec_api.egg-info
88
deploy.sh
99
sec_api/__pycache__

README.md

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
**sec-api** is a Python package for querying the entire SEC filings corpus in real-time without the need to download filings.
44
It includes:
55

6-
- Query and Full-Text Search API
7-
- Real-Time Stream API
8-
- XBRL-to-JSON Converter API + Financial Statements
9-
- 10-K/10-Q/8-K Section Extraction API
10-
- Filing Render & Download API
11-
- Executive Compensation Data API
6+
- [Query and Full-Text Search API](#sec-edgar-filings-query-api)
7+
- [Real-Time Stream API](#sec-edgar-filings-real-time-stream-api)
8+
- [XBRL-to-JSON Converter API + Financial Statements](#xbrl-to-json-converter-api)
9+
- [10-K/10-Q/8-K Section Extraction API](#10-k-10-q-8-k-section-extractor-api)
10+
- [Filing Download & PDF Render API](#filing-render-download-api)
11+
- [Executive Compensation Data API](#executive-compensation-data-api)
12+
- [Insider Trading Data API](#insider-trading-data-api)
13+
- [13F Institutional Investor Database](#13f-institutional-investor-database)
14+
- [CUSIP/CIK/Ticker Mapping API](#cusip-cik-ticker-mapping-api)
1215

1316

1417
# Data Coverage
@@ -86,6 +89,7 @@ query = {
8689
filings = queryApi.get_filings(query)
8790
```
8891

92+
## 13F Institutional Investor Database
8993
Fetch most recent 13F filings that hold Tesla
9094

9195
```python
@@ -627,6 +631,77 @@ result_query = execCompApi.get_data(query)
627631

628632
> See the documentation for more details: https://sec-api.io/docs/executive-compensation-api
629633
634+
# Insider Trading Data API
635+
636+
The Insider Trading Data API allows you to search and list all insider buy and sell transactions of all publicly listed
637+
companies on US stock exchanges. Insider activities of company directors, officers, 10% owners and other executives are
638+
fully searchable. The insider trading database includes information about the CIK and name of the insider,
639+
her/his relationship to the company, the number of shares and securities purchased or sold, the purchase or selling price,
640+
the date of the transaction, the amount of securities held before and after the transaction occured, any footnotes such
641+
as the effect of Rule 10b-18 or 10b5-1 stock purchase plans and more. The full list of all data points is available below.
642+
643+
```python
644+
from sec_api import InsiderTradingApi
645+
646+
insiderTradingApi = InsiderTradingApi("YOUR_API_KEY")
647+
648+
insider_trades = insiderTradingApi.get_data({
649+
"query": {"query_string": {"query": "issuer.tradingSymbol:TSLA"}}
650+
})
651+
652+
print(insider_trades["transactions"])
653+
```
654+
655+
### Response Example
656+
```json
657+
[
658+
{
659+
"accessionNo": "0000899243-22-028189",
660+
"filedAt": "2022-08-09T21:23:00-04:00",
661+
"documentType": "4",
662+
"periodOfReport": "2022-08-09",
663+
"issuer": {"cik": "1318605", "name": "Tesla, Inc.", "tradingSymbol": "TSLA"},
664+
"reportingOwner": {
665+
"cik": "1494730",
666+
"name": "Musk Elon",
667+
"address": {
668+
"street1": "C/O TESLA, INC.",
669+
"street2": "1 TESLA ROAD",
670+
"city": "AUSTIN",
671+
"state": "TX",
672+
"zipCode": "78725"
673+
},
674+
"relationship": {
675+
"isDirector": true,
676+
"isOfficer": true,
677+
"officerTitle": "CEO",
678+
"isTenPercentOwner": true,
679+
"isOther": false
680+
}
681+
},
682+
"nonDerivativeTable": {
683+
"transactions": [
684+
{
685+
"securityTitle": "Common Stock",
686+
"transactionDate": "2022-08-09",
687+
"coding": {
688+
"formType": "4",
689+
"code": "S",
690+
"equitySwapInvolved": false
691+
},
692+
"amounts": {
693+
"shares": 435,
694+
"pricePerShare": 872.469,
695+
"pricePerShareFootnoteId": ["F1"],
696+
"acquiredDisposedCode": "D"
697+
}
698+
}
699+
]
700+
// and many more
701+
}
702+
}
703+
]
704+
```
630705

631706
# Query API Response Format
632707

examples.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from sec_api.index import RenderApi, XbrlApi, ExtractorApi, MappingApi, ExecCompApi
1+
from sec_api.index import (
2+
RenderApi,
3+
XbrlApi,
4+
ExtractorApi,
5+
MappingApi,
6+
ExecCompApi,
7+
InsiderTradingApi,
8+
)
29

310
#
411
# Render API
@@ -95,3 +102,22 @@
95102
print(result_cik)
96103
print(result_query)
97104
# """
105+
106+
107+
#
108+
# Insider Trading Data API Example
109+
#
110+
"""
111+
insiderTradingApi = InsiderTradingApi("YOUR_API_KEY")
112+
113+
insider_trades = insiderTradingApi.get_data(
114+
{
115+
"query": {"query_string": {"query": "issuer.tradingSymbol:TSLA"}},
116+
"from": "0",
117+
"size": "50",
118+
"sort": [{"filedAt": {"order": "desc"}}],
119+
}
120+
)
121+
122+
print(insider_trades["transactions"])
123+
# """

sec_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
from sec_api.index import ExtractorApi
77
from sec_api.index import MappingApi
88
from sec_api.index import ExecCompApi
9+
from sec_api.index import InsiderTradingApi

sec_api/index.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
extractor_api_endpoint = "https://api.sec-api.io/extractor"
1111
mapping_api_endpoint = "https://api.sec-api.io/mapping"
1212
exec_comp_api_endpoint = "https://api.sec-api.io/compensation"
13+
insider_api_endpoint = "https://api.sec-api.io/insider-trading"
1314

1415

1516
def handle_api_error(response):
@@ -77,7 +78,7 @@ def __init__(self, api_key):
7778
self.api_key = api_key
7879
self.api_endpoint = render_api_endpoint
7980

80-
def get_filing(self, url):
81+
def get_filing(self, url, as_pdf=False):
8182
response = {}
8283
filename = re.sub(r"https://www.sec.gov/Archives/edgar/data", "", url)
8384
_url = self.api_endpoint + filename + "?token=" + self.api_key
@@ -271,3 +272,29 @@ def get_data(self, parameter=""):
271272
handle_api_error(response)
272273
else:
273274
handle_api_error(response)
275+
276+
277+
class InsiderTradingApi:
278+
"""
279+
Base class for Insider Trading Data API
280+
"""
281+
282+
def __init__(self, api_key):
283+
self.api_key = api_key
284+
self.api_endpoint = insider_api_endpoint + "?token=" + api_key
285+
286+
def get_data(self, query):
287+
response = {}
288+
289+
# use backoff strategy to handle "too many requests" error.
290+
for x in range(3):
291+
response = requests.post(self.api_endpoint, json=query)
292+
if response.status_code == 200:
293+
return response.json()
294+
elif response.status_code == 429:
295+
# wait 500 * (x + 1) milliseconds and try again
296+
time.sleep(0.5 * (x + 1))
297+
else:
298+
handle_api_error(response)
299+
else:
300+
handle_api_error(response)

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="sec-api",
8-
version="1.0.12",
8+
version="1.0.13",
99
author="SEC API",
1010
author_email="support@sec-api.io",
1111
description="SEC EDGAR Filings API",
@@ -32,15 +32,22 @@
3232
keywords=[
3333
"SEC EDGAR API",
3434
"SEC Filings API",
35+
"SEC Full-Text Search API",
3536
"EDGAR API",
3637
"Finance",
3738
"CIK",
3839
"CUSIP",
40+
"CUSIP to Ticker",
41+
"CUSIP to CIK",
3942
"10-Q",
4043
"10-K",
4144
"8-K",
4245
"S-1",
4346
"424B4",
47+
"XBRL Converter",
48+
"Financial Statements API",
49+
"Insider Trading Data",
50+
"Executive Compensation Data",
4451
],
4552
project_urls={
4653
"Bug Reports": "https://github.com/janlukasschroeder/sec-api-python/issues",

0 commit comments

Comments
 (0)