Skip to content

Commit

Permalink
add historical_employee_count to company_valuation.py (#53)
Browse files Browse the repository at this point in the history
* historical_employee_count

* add bulk requests api
  • Loading branch information
yacper authored Oct 30, 2024
1 parent e7949e8 commit 316c1f3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
8 changes: 8 additions & 0 deletions fmpsdk-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions fmpsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -144,6 +153,7 @@
"market_capitalization",
"historical_market_capitalization",
"symbols_list",
"historical_employee_count",
"etf_list",
"available_traded_list",
"stock_screener",
Expand Down Expand Up @@ -215,4 +225,8 @@
"senate_disclosure_rss",
"senate_disclosure_symbol",
"shares_float",

#bulk apis
"bulk_historical_eod",
"bulk_profiles",
]
42 changes: 42 additions & 0 deletions fmpsdk/bulk.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions fmpsdk/company_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 12 additions & 1 deletion fmpsdk/url_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import typing
import csv
import io

import requests

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 316c1f3

Please sign in to comment.