diff --git a/fmpsdk/__init__.py b/fmpsdk/__init__.py index 3f73967..de5cc4e 100644 --- a/fmpsdk/__init__.py +++ b/fmpsdk/__init__.py @@ -78,8 +78,13 @@ from .general import historical_chart, historical_price_full, quote from .insider_trading import ( insider_trading, + insider_trading_latest, + insider_trading_by_reporting_name, + insider_trading_transaction_types, + insider_trading_statistics, + acquisition_of_beneficial_ownership, + insider_trading_rss_feed, - insider_trade_statistics, mapper_cik_company, mapper_cik_name, ) diff --git a/fmpsdk/calendar.py b/fmpsdk/calendar.py index 1180d90..8b4409b 100644 --- a/fmpsdk/calendar.py +++ b/fmpsdk/calendar.py @@ -2,22 +2,22 @@ import logging from .settings import DEFAULT_LIMIT -from .url_methods import __return_json_v3, __return_json_v4 +from .url_methods import __return_json_v3, __return_json_v4, __return_json_stable def earning_calendar( apikey: str, from_date: str = None, to_date: str = None ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /earning_calendar/ API. + Query FMP /earnings-calendar/ API. Note: Between the "from" and "to" parameters the maximum time interval can be 3 months. :param apikey: Your API key. - :param from_date: 'YYYY:MM:DD' - :param to_date: 'YYYY:MM:DD' + :param from_date: 'YYYY-MM-DD' + :param to_date: 'YYYY-MM-DD' :return: A list of dictionaries. """ - path = f"earning_calendar" + path = f"earnings-calendar" query_vars = { "apikey": apikey, } @@ -25,7 +25,7 @@ def earning_calendar( query_vars["from"] = from_date if to_date: query_vars["to"] = to_date - return __return_json_v3(path=path, query_vars=query_vars) + return __return_json_stable(path=path, query_vars=query_vars) def historical_earning_calendar( @@ -53,15 +53,15 @@ def ipo_calendar( apikey: str, from_date: str = None, to_date: str = None ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /ipo_calendar/ API. + Query FMP /ipos-calendar/ API. Note: Between the "from" and "to" parameters the maximum time interval can be 3 months. :param apikey: Your API key. - :param from_date: 'YYYY:MM:DD' - :param to_date: 'YYYY:MM:DD' + :param from_date: 'YYYY-MM-DD' + :param to_date: 'YYYY-MM-DD' :return: A list of dictionaries. """ - path = f"ipo_calendar" + path = f"ipos-calendar" query_vars = { "apikey": apikey, } @@ -69,22 +69,22 @@ def ipo_calendar( query_vars["from"] = from_date if to_date: query_vars["to"] = to_date - return __return_json_v3(path=path, query_vars=query_vars) + return __return_json_stable(path=path, query_vars=query_vars) def stock_split_calendar( apikey: str, from_date: str = None, to_date: str = None ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /stock_split_calendar/ API. + Query FMP /splits-calendar/ API. Note: Between the "from" and "to" parameters the maximum time interval can be 3 months. :param apikey: Your API key. - :param from_date: 'YYYY:MM:DD' - :param to_date: 'YYYY:MM:DD' + :param from_date: 'YYYY-MM-DD' + :param to_date: 'YYYY-MM-DD' :return: A list of dictionaries. """ - path = f"stock_split_calendar" + path = f"splits-calendar" query_vars = { "apikey": apikey, } @@ -92,22 +92,22 @@ def stock_split_calendar( query_vars["from"] = from_date if to_date: query_vars["to"] = to_date - return __return_json_v3(path=path, query_vars=query_vars) + return __return_json_stable(path=path, query_vars=query_vars) def dividend_calendar( apikey: str, from_date: str = None, to_date: str = None ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /stock_dividend_calendar/ API. + Query FMP /dividends-calendar/ API. Note: Between the "from" and "to" parameters the maximum time interval can be 3 months. :param apikey: Your API key. - :param from_date: 'YYYY:MM:DD' - :param to_date: 'YYYY:MM:DD' + :param from_date: 'YYYY-MM-DD' + :param to_date: 'YYYY-MM-DD' :return: A list of dictionaries. """ - path = f"stock_dividend_calendar" + path = f"dividends-calendar" query_vars = { "apikey": apikey, } @@ -115,22 +115,23 @@ def dividend_calendar( query_vars["from"] = from_date if to_date: query_vars["to"] = to_date - return __return_json_v3(path=path, query_vars=query_vars) + + return __return_json_stable(path=path, query_vars=query_vars) def economic_calendar( apikey: str, from_date: str = None, to_date: str = None ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /economic_calendar/ API. + Query FMP /economic-calendar/ API. Note: Between the "from" and "to" parameters the maximum time interval can be 3 months. :param apikey: Your API key. - :param from_date: 'YYYY:MM:DD' - :param to_date: 'YYYY:MM:DD' + :param from_date: 'YYYY-MM-DD' + :param to_date: 'YYYY-MM-DD' :return: A list of dictionaries. """ - path = f"economic_calendar" + path = f"economic-calendar" query_vars = { "apikey": apikey, } @@ -138,7 +139,7 @@ def economic_calendar( query_vars["from"] = from_date if to_date: query_vars["to"] = to_date - return __return_json_v3(path=path, query_vars=query_vars) + return __return_json_stable(path=path, query_vars=query_vars) def earning_calendar_confirmed( diff --git a/fmpsdk/insider_trading.py b/fmpsdk/insider_trading.py index 1bf31e4..cc5be6d 100644 --- a/fmpsdk/insider_trading.py +++ b/fmpsdk/insider_trading.py @@ -2,70 +2,129 @@ import typing from .settings import DEFAULT_LIMIT -from .url_methods import __return_json_v3, __return_json_v4 +from .url_methods import __return_json_v3, __return_json_v4, __return_json_stable def insider_trading( apikey: str, symbol: str = None, - reporting_name: str = None, + reportingCik: str = None, + companyCik: str = None, + transactionType: str = None, + page: int = 0, limit: int = DEFAULT_LIMIT, ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /insider-trading/ API. + Query FMP /insider-trading/search API. :param apikey: Your API key. - :param symbol: Company ticker. - :param reporting_name: Name of reporting person. + :param symbol: Company ticker symbol. + :param reportingCik: CIK of the reporting person. + :param companyCik: CIK of the company. + :param transactionType: Type of transaction (e.g., 'P-Purchase', 'S-Sale'). + :param page: Page number for pagination. :param limit: Number of rows to return. - :return: A list of dictionaries. + :return: A list of dictionaries containing insider trading data. """ - path = f"insider-trading" - query_vars = {"apikey": apikey, "limit": limit} + path = f"insider-trading/search" + query_vars = {"apikey": apikey, "page": page, "limit": limit} if symbol: query_vars["symbol"] = symbol - if reporting_name: - query_vars["reportingName"] = reporting_name - return __return_json_v3(path=path, query_vars=query_vars) + if reportingCik: + query_vars["reportingCik"] = reportingCik + if companyCik: + query_vars["companyCik"] = companyCik + if transactionType: + query_vars["transactionType"] = transactionType + return __return_json_stable(path=path, query_vars=query_vars) + + +def insider_trading_latest( + apikey: str, + page: int = 0, + limit: int = DEFAULT_LIMIT, +) -> typing.Optional[typing.List[typing.Dict]]: + """ + Query FMP /insider-trading/latest API. + + :param apikey: Your API key. + :param page: Page number for pagination. + :param limit: Number of rows to return. + :return: A list of dictionaries containing latest insider trading data. + """ + path = f"insider-trading/latest" + query_vars = {"apikey": apikey, "page": page, "limit": limit} + return __return_json_stable(path=path, query_vars=query_vars) -def insider_trade_statistics( +def insider_trading_by_reporting_name( apikey: str, - symbol: str, + name: str = None, ) -> typing.Optional[typing.List[typing.Dict]]: """ - Query FMP /insider-roaster-statistic API. + Query FMP /insider-trading/reporting-name API. - Get insider trading statistics for a specific company. + :param apikey: Your API key. + :param name: name of the reporting person. + :return: A list of dictionaries containing reporting ciks. + """ + path = f"insider-trading/reporting-name" + query_vars = {"apikey": apikey} + if name: + query_vars["name"] = name + return __return_json_stable(path=path, query_vars=query_vars) - https://site.financialmodelingprep.com/developer/docs#insider-trade-statistics - Endpoint: - https://financialmodelingprep.com/api/v4/insider-roaster-statistic?symbol=AAPL +def insider_trading_transaction_types( + apikey: str, +) -> typing.Optional[typing.List[typing.Dict]]: + """ + Query FMP /insider-trading-transaction-type API. + + :param apikey: Your API key. + :return: A list of dictionaries containing all transaction types. + """ + path = f"insider-trading-transaction-type" + query_vars = {"apikey": apikey} + return __return_json_stable(path=path, query_vars=query_vars) + + +def insider_trading_statistics( + apikey: str, + symbol: str = None, +) -> typing.Optional[typing.List[typing.Dict]]: + """ + Query FMP /insider-trading/statistics API. :param apikey: Your API key. :param symbol: Company ticker symbol. - :return: A list of dictionaries containing insider trading statistics with fields: - - symbol: The stock symbol - - name: Name of the insider - - position: Position in the company - - totalBuy: Total number of buy transactions - - totalBuyAmount: Total amount spent on buys - - totalSell: Total number of sell transactions - - totalSellAmount: Total amount from sells - - totalTransactions: Total number of transactions - - lastDate: Date of last transaction - - lastPrice: Price of last transaction - - lastAmount: Amount of last transaction - - lastType: Type of last transaction (buy/sell) - """ - if not symbol: - logging.warning("Symbol is required for insider trade statistics request.") - return None - - path = "insider-roaster-statistic" - query_vars = {"apikey": apikey, "symbol": symbol} - return __return_json_v4(path=path, query_vars=query_vars) + :return: A list of dictionaries containing insider trading statistics. + """ + path = f"insider-trading/statistics" + query_vars = {"apikey": apikey} + if symbol: + query_vars["symbol"] = symbol + return __return_json_stable(path=path, query_vars=query_vars) + + +def acquisition_of_beneficial_ownership( + apikey: str, + symbol: str = None, + limit: int = DEFAULT_LIMIT, +) -> typing.Optional[typing.List[typing.Dict]]: + """ + Query FMP /acquisition-of-beneficial-ownership API. + + :param apikey: Your API key. + :param symbol: Company ticker symbol. + :param limit: Number of rows to return. + :return: A list of dictionaries containing changes in stock ownership during acquisitions. + """ + path = f"acquisition-of-beneficial-ownership" + query_vars = {"apikey": apikey, "limit": limit} + if symbol: + query_vars["symbol"] = symbol + return __return_json_stable(path=path, query_vars=query_vars) def mapper_cik_name(