|
| 1 | +import pandas as pd |
| 2 | +from fmp_py.fmp_base import FmpBase |
| 3 | +import os |
| 4 | +from dotenv import load_dotenv |
| 5 | + |
| 6 | +load_dotenv() |
| 7 | + |
| 8 | + |
| 9 | +""" |
| 10 | +The FmpMergersAndAquisitions class provides methods for retrieving mergers and acquisitions data from the Financial Modeling Prep API. |
| 11 | +Refer to the official documentation (https://site.financialmodelingprep.com/developer/docs#mergers-&-acquisitions) for more information. |
| 12 | +
|
| 13 | +def ma_rss_feed(self, page: int = 0) -> pd.DataFrame: |
| 14 | + Reference: https://site.financialmodelingprep.com/developer/docs#m&a-rss-feed-mergers-&-acquisitions |
| 15 | +
|
| 16 | +def search_ma(self, query: str) -> pd.DataFrame: |
| 17 | + Reference: https://site.financialmodelingprep.com/developer/docs#search-m&a-mergers-&-acquisitions |
| 18 | +""" |
| 19 | + |
| 20 | + |
| 21 | +class FmpMergersAndAquisitions(FmpBase): |
| 22 | + def __init__(self, api_key: str = os.getenv("FMP_API_KEY")) -> None: |
| 23 | + super().__init__(api_key) |
| 24 | + |
| 25 | + ##################################### |
| 26 | + # Mergers and Acquisitions Search |
| 27 | + ##################################### |
| 28 | + def search_ma(self, name: str) -> pd.DataFrame: |
| 29 | + """ |
| 30 | + Retrieves mergers and acquisitions data based on a search name. |
| 31 | +
|
| 32 | + Args: |
| 33 | + name (str): The search name of company. |
| 34 | +
|
| 35 | + Returns: |
| 36 | + pd.DataFrame: A DataFrame containing the mergers and acquisitions data. |
| 37 | + """ |
| 38 | + url = "v4/mergers-acquisitions/search" |
| 39 | + params = {"name": name} |
| 40 | + response = self.get_request(url, params) |
| 41 | + |
| 42 | + if not response: |
| 43 | + raise ValueError("No data found for the specified parameters.") |
| 44 | + |
| 45 | + data_df = ( |
| 46 | + pd.DataFrame(response) |
| 47 | + .fillna("") |
| 48 | + .rename( |
| 49 | + columns={ |
| 50 | + "companyName": "company_name", |
| 51 | + "symbol": "symbol", |
| 52 | + "targetedCompanyName": "targeted_company_name", |
| 53 | + "targetedCik": "targeted_cik", |
| 54 | + "targetedSymbol": "targeted_symbol", |
| 55 | + "transactionDate": "transaction_date", |
| 56 | + "acceptanceTime": "acceptance_time", |
| 57 | + "url": "url", |
| 58 | + } |
| 59 | + ) |
| 60 | + .astype( |
| 61 | + { |
| 62 | + "company_name": "str", |
| 63 | + "symbol": "str", |
| 64 | + "targeted_company_name": "str", |
| 65 | + "targeted_cik": "str", |
| 66 | + "targeted_symbol": "str", |
| 67 | + "transaction_date": "datetime64[ns]", |
| 68 | + "acceptance_time": "datetime64[ns]", |
| 69 | + "url": "str", |
| 70 | + } |
| 71 | + ) |
| 72 | + ) |
| 73 | + return data_df |
| 74 | + |
| 75 | + ##################################### |
| 76 | + # Mergers and Acquisitions RSS Feed |
| 77 | + ##################################### |
| 78 | + def ma_rss_feed(self, page: int = 0) -> pd.DataFrame: |
| 79 | + """ |
| 80 | + Retrieves mergers and acquisitions data from the RSS feed. |
| 81 | +
|
| 82 | + Args: |
| 83 | + page (int): The page number for the RSS feed. |
| 84 | +
|
| 85 | + Returns: |
| 86 | + pd.DataFrame: A DataFrame containing the mergers and acquisitions data. |
| 87 | + """ |
| 88 | + url = "v4/mergers-acquisitions-rss-feed" |
| 89 | + params = {"page": page} |
| 90 | + response = self.get_request(url, params) |
| 91 | + |
| 92 | + if not response: |
| 93 | + raise ValueError("No data found for the specified parameters.") |
| 94 | + |
| 95 | + data_df = ( |
| 96 | + pd.DataFrame(response) |
| 97 | + .fillna("") |
| 98 | + .rename( |
| 99 | + columns={ |
| 100 | + "companyName": "company_name", |
| 101 | + "symbol": "symbol", |
| 102 | + "targetedCompanyName": "targeted_company_name", |
| 103 | + "targetedCik": "targeted_cik", |
| 104 | + "targetedSymbol": "targeted_symbol", |
| 105 | + "transactionDate": "transaction_date", |
| 106 | + "acceptanceTime": "acceptance_time", |
| 107 | + "url": "url", |
| 108 | + } |
| 109 | + ) |
| 110 | + .astype( |
| 111 | + { |
| 112 | + "company_name": "str", |
| 113 | + "symbol": "str", |
| 114 | + "targeted_company_name": "str", |
| 115 | + "targeted_cik": "str", |
| 116 | + "targeted_symbol": "str", |
| 117 | + "transaction_date": "datetime64[ns]", |
| 118 | + "acceptance_time": "datetime64[ns]", |
| 119 | + "url": "str", |
| 120 | + } |
| 121 | + ) |
| 122 | + ) |
| 123 | + return data_df |
0 commit comments