diff --git a/fmpsdk-example.py b/fmpsdk-example.py index 90a4284..af4b2a8 100644 --- a/fmpsdk-example.py +++ b/fmpsdk-example.py @@ -255,3 +255,11 @@ # print(f"Available Forex Currency Pairs: {fmpsdk.available_cryptocurrencies(apikey=apikey)=}") # print(f"Historical Forex Prices: {fmpsdk.historical_chart(apikey=apikey, symbol=symbol, time_delta=time_delta_5min, from_date=from_date, to_date=to_date))=}") # print(f"Historical Daily Forex Prices: {fmpsdk.historical_price_full(apikey=apikey, symbol=symbol)=}") + +### Bulk Requests +#bulkEods = fmpsdk.bulk_historical_eod(apikey=apikey, date="2021-05-18") +#bulkEodsDf = pd.DataFrame(bulkEods) +#print(bulkEodsDf) +#bulkProfiles = fmpsdk.bulk_profiles(apikey=apikey) +#bulkProfilesDf = pd.DataFrame(bulkProfiles) +#print(bulkProfilesDf) \ No newline at end of file diff --git a/fmpsdk/__init__.py b/fmpsdk/__init__.py index 1058e57..7f5c73f 100644 --- a/fmpsdk/__init__.py +++ b/fmpsdk/__init__.py @@ -53,6 +53,9 @@ stock_news, stock_screener, symbols_list, + + # mod + historical_employee_count, ) from .cryptocurrencies import available_cryptocurrencies, cryptocurrencies_list from .etf import available_efts, available_etfs, etf_price_realtime @@ -107,6 +110,12 @@ from .technical_indicators import technical_indicators from .tsx import available_tsx, tsx_list + +from .bulk import ( + bulk_historical_eod, + bulk_profiles, +) + attribution: str = "Data provided by Financial Modeling Prep" logging.info(attribution) @@ -144,6 +153,7 @@ "market_capitalization", "historical_market_capitalization", "symbols_list", + "historical_employee_count", "etf_list", "available_traded_list", "stock_screener", @@ -215,4 +225,8 @@ "senate_disclosure_rss", "senate_disclosure_symbol", "shares_float", + + #bulk apis + "bulk_historical_eod", + "bulk_profiles", ] diff --git a/fmpsdk/bulk.py b/fmpsdk/bulk.py new file mode 100644 index 0000000..4e1f749 --- /dev/null +++ b/fmpsdk/bulk.py @@ -0,0 +1,42 @@ +import logging +import typing +import requests + +from .general import __quotes +from .settings import ( + DEFAULT_LIMIT, + BASE_URL_v3, + BASE_URL_v4 +) +from .url_methods import __return_json_v3, __return_json_v4 + + +def bulk_historical_eod(apikey: str, date: str) -> typing.Optional[typing.List[typing.Dict]]: + """ + Batch request that contains all end of day prices for specific date + + https://site.financialmodelingprep.com/developer/docs#batch-eod-prices + + Endpoint: + https://financialmodelingprep.com/api/v4/batch-historical-eod?date=2021-05-18 + + :param apikey: Your API key. + :return: A list of dictionaries. + """ + path = f"batch-historical-eod" + query_vars = {"apikey": apikey, "date": date} + return __return_json_v4(path=path, query_vars=query_vars) + +def bulk_profiles(apikey: str) -> typing.Optional[typing.List[typing.Dict]]: + """ + It contains all profiles from our API in one CSV file + + Endpoint: + https://financialmodelingprep.com/api/v4/profile/all + + :param apikey: Your API key. + :return: A list of dictionaries. + """ + path = f"profile/all" + query_vars = {"apikey": apikey} + return __return_json_v4(path=path, query_vars=query_vars) \ No newline at end of file diff --git a/fmpsdk/company_valuation.py b/fmpsdk/company_valuation.py index f76c1a7..48af4eb 100644 --- a/fmpsdk/company_valuation.py +++ b/fmpsdk/company_valuation.py @@ -957,3 +957,14 @@ def analyst_estimates( "limit": limit, } return __return_json_v3(path=path, query_vars=query_vars) + + +def historical_employee_count( + apikey: str, symbol: str +) -> typing.Optional[typing.List[typing.Dict]]: + """ + historical_employee_count + """ + path = f"historical/employee_count" + query_vars = {"apikey": apikey, "symbol": symbol} + return __return_json_v4(path=path, query_vars=query_vars) \ No newline at end of file diff --git a/fmpsdk/url_methods.py b/fmpsdk/url_methods.py index 8e7d9c3..0ace89d 100644 --- a/fmpsdk/url_methods.py +++ b/fmpsdk/url_methods.py @@ -1,5 +1,7 @@ import logging import typing +import csv +import io import requests @@ -85,7 +87,16 @@ def __return_json_v4( url, params=query_vars, timeout=(CONNECT_TIMEOUT, READ_TIMEOUT) ) if len(response.content) > 0: - return_var = response.json() + try: + return response.json() + except Exception as e: + # check if response.content is csv, convert csv to json format + content = response.content.decode("utf-8") + try: + reader = csv.DictReader(io.StringIO(content)) + return [row for row in reader] + except csv.Error: + raise e if len(response.content) == 0 or ( isinstance(return_var, dict) and len(return_var.keys()) == 0