Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_insider_transaction_reported #1683

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,3 +2103,9 @@ def get_history_metadata(self, proxy=None) -> dict:
self._history_metadata_formatted = True

return self._history_metadata

def get_insider_transactions(self, proxy=None):
if self._holders._insider_transactions is None:
self._holders._insider_transactions = self._holders._insider_transaction(self.ticker, proxy=proxy)

return self._holders._insider_transactions
18 changes: 18 additions & 0 deletions yfinance/scrapers/holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, data: TickerData, proxy=None):
self._major = None
self._institutional = None
self._mutualfund = None
self._insider_transactions = None

@property
def major(self) -> pd.DataFrame:
Expand All @@ -31,6 +32,12 @@ def mutualfund(self) -> pd.DataFrame:
if self._mutualfund is None:
self._scrape(self.proxy)
return self._mutualfund

@property
def insider_transactions(self) -> pd.DataFrame:
if self._insider_transactions is None:
self._insider_transaction(self.proxy)
return self._insider_transactions

def _scrape(self, proxy):
ticker_url = f"{self._SCRAPE_URL_}/{self._data.ticker}"
Expand Down Expand Up @@ -65,3 +72,14 @@ def _scrape(self, proxy):
if '% Out' in self._mutualfund:
self._mutualfund['% Out'] = self._mutualfund[
'% Out'].str.replace('%', '').astype(float) / 100

def _insider_transaction(self, proxy) -> pd.DataFrame:
ticker_url = f"{self._SCRAPE_URL_}/{self._data.ticker}"

try:
resp = self._data.cache_get(ticker_url + '/insider-transactions', proxy=proxy)
self._insider_transactions = pd.read_html(resp.text)[2]
except Exception:
self._insider_transactions = []

return self._insider_transactions
4 changes: 4 additions & 0 deletions yfinance/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,7 @@ def earnings_forecasts(self) -> _pd.DataFrame:
@property
def history_metadata(self) -> dict:
return self.get_history_metadata()

@property
def insider_transactions(self) -> _pd.DataFrame:
return self.get_insider_transactions()