How to get insider trading data from the SEC database using Python

Company insiders are forced to report their buy/sell operations to the SEC through form-4, and this can give us clues about the business direction. While insider selling is not always a bad sign, insider buying generally is good as shows insider confidence in the company’s future.

That said, is a waste of time to have to check the SEC website and the EDGAR database constantly (and manually) in order to get this information, for all the businesses we are following. That’s why we’ll use Python! So we can get the form-4 submission updates automatically.

This is the initial MVP code:

from bs4 import BeautifulSoup
from urllib2 import urlopen


def _edgar_form_4(ticker):

	url = urlopen('' + ticker + '&type=4&dateb=&owner=only&count=40')
	soup = BeautifulSoup(url, 'html.parser')
	filling_date_block = soup.find_all('tr')
	data = list()
	rows = filling_date_block[3].find_all('td')
	for row in rows:
	print ticker + ': Latest change was on ' + str(data[3])
for eachStock in EDGAR_STOCKS_TO_CHECK:

And this will be the end result in our terminal:

Leave a Reply