Skip to content

FMP

Reference information for the Financial Modeling Prep (FMP) data fetching module. You can find more information about FMP at FMP developer docs.

You can import the module via

from quantflow.data.fmp import FMP

quantflow.data.fmp.FMP dataclass

FMP(url='https://financialmodelingprep.com/stable', key=(lambda: get('FMP_API_KEY', ''))())

Bases: AioHttpClient

Financial Modeling Prep API client

url class-attribute instance-attribute

url = 'https://financialmodelingprep.com/stable'

key class-attribute instance-attribute

key = field(default_factory=lambda: get('FMP_API_KEY', ''))

freq

Bases: StrEnum

FMP historical frequencies

one_min class-attribute instance-attribute

one_min = '1min'

five_min class-attribute instance-attribute

five_min = '5min'

fifteen_min class-attribute instance-attribute

fifteen_min = '15min'

thirty_min class-attribute instance-attribute

thirty_min = '30min'

one_hour class-attribute instance-attribute

one_hour = '1hour'

four_hour class-attribute instance-attribute

four_hour = '4hour'

daily class-attribute instance-attribute

daily = ''

market_risk_premium async

market_risk_premium()

Market risk premium

Source code in quantflow/data/fmp.py
async def market_risk_premium(self) -> list[dict]:
    """Market risk premium"""
    return await self.get_path("market-risk-premium")

stocks async

stocks(**kw)
Source code in quantflow/data/fmp.py
async def stocks(self, **kw: Any) -> list[dict]:
    return await self.get_path("stock-list", **kw)

etfs async

etfs(**kw)
Source code in quantflow/data/fmp.py
async def etfs(self, **kw: Any) -> list[dict]:
    return await self.get_path("etf-list", **kw)

indices async

indices(**kw)

Retrieve a comprehensive list of stock market indexes across global exchanges

Source code in quantflow/data/fmp.py
async def indices(self, **kw: Any) -> list[dict]:
    """Retrieve a comprehensive list of stock market indexes
    across global exchanges"""
    return await self.get_path("index-list", **kw)

profile async

profile(*tickers, **kw)

Company profile - minute

PARAMETER DESCRIPTION
*tickers

One or more ticker symbols

TYPE: str DEFAULT: ()

Source code in quantflow/data/fmp.py
async def profile(
    self,
    *tickers: Annotated[str, Doc("One or more ticker symbols")],
    **kw: Any,
) -> list[dict]:
    """Company profile - minute"""
    return await self.get_path(f"profile/{self.join(*tickers)}", **kw)

quote async

quote(*tickers, **kw)

Company quote - real time

PARAMETER DESCRIPTION
*tickers

One or more ticker symbols

TYPE: str DEFAULT: ()

Source code in quantflow/data/fmp.py
async def quote(
    self,
    *tickers: Annotated[str, Doc("One or more ticker symbols")],
    **kw: Any,
) -> list[dict]:
    """Company quote - real time"""
    return await self.get_path(f"quote/{self.join(*tickers)}", **kw)

dividends async

dividends(from_date=None, to_date=None, **kw)

Dividend calendar

PARAMETER DESCRIPTION
from_date

Start date for dividend calendar

TYPE: str | date | None DEFAULT: None

to_date

End date for dividend calendar

TYPE: str | date | None DEFAULT: None

Source code in quantflow/data/fmp.py
async def dividends(
    self,
    from_date: Annotated[
        str | date | None, Doc("Start date for dividend calendar")
    ] = None,
    to_date: Annotated[
        str | date | None, Doc("End date for dividend calendar")
    ] = None,
    **kw: Any,
) -> list[dict]:
    """Dividend calendar"""
    params = compact_dict(
        {"from": to_date_iso(from_date), "to": to_date_iso(to_date)},
    )
    return await self.get_path("dividends-calendar", params=params, **kw)

executives async

executives(ticker, **kw)

Company quote - real time

PARAMETER DESCRIPTION
ticker

Ticker symbol

TYPE: str

Source code in quantflow/data/fmp.py
async def executives(
    self,
    ticker: Annotated[str, Doc("Ticker symbol")],
    **kw: Any,
) -> list[dict]:
    """Company quote - real time"""
    return await self.get_path(f"key-executives/{ticker}", **kw)

insider_trading async

insider_trading(ticker, **kw)

Company Insider Trading

PARAMETER DESCRIPTION
ticker

Ticker symbol

TYPE: str

Source code in quantflow/data/fmp.py
async def insider_trading(
    self,
    ticker: Annotated[str, Doc("Ticker symbol")],
    **kw: Any,
) -> list[dict]:
    """Company Insider Trading"""
    return await self.get_path(
        "insider-trading", **self.params(dict(symbol=ticker), **kw)
    )

rating async

rating(ticker, **kw)

Company rating - real time

PARAMETER DESCRIPTION
ticker

Ticker symbol

TYPE: str

Source code in quantflow/data/fmp.py
async def rating(
    self,
    ticker: Annotated[str, Doc("Ticker symbol")],
    **kw: Any,
) -> list[dict]:
    """Company rating - real time"""
    return await self.get_path(f"rating/{ticker}", **kw)

etf_holders async

etf_holders(ticker, **kw)
PARAMETER DESCRIPTION
ticker

Ticker symbol

TYPE: str

Source code in quantflow/data/fmp.py
async def etf_holders(
    self,
    ticker: Annotated[str, Doc("Ticker symbol")],
    **kw: Any,
) -> list[dict]:
    return await self.get_path(f"etf-holder/{ticker}", **kw)

ratios async

ratios(ticker, period=None, limit=None, **kw)

Company financial ratios - if period not provided it is for the trailing 12 months

PARAMETER DESCRIPTION
ticker

Ticker symbol

TYPE: str

period

Reporting period (e.g., 'annual', 'quarter')

TYPE: str | None DEFAULT: None

limit

Maximum number of results

TYPE: int | None DEFAULT: None

Source code in quantflow/data/fmp.py
async def ratios(
    self,
    ticker: Annotated[str, Doc("Ticker symbol")],
    period: Annotated[
        str | None, Doc("Reporting period (e.g., 'annual', 'quarter')")
    ] = None,
    limit: Annotated[int | None, Doc("Maximum number of results")] = None,
    **kw: Any,
) -> list[dict]:
    """Company financial ratios - if period not provided it is for
    the trailing 12 months"""
    path = "ratios" if period else "ratios-ttm"
    return await self.get_path(
        f"{path}/{ticker}",
        **self.params(compact_dict(period=period, limit=limit), **kw),
    )

peers async

peers(*tickers, **kw)

Stock peers based on sector, exchange and market cap

PARAMETER DESCRIPTION
*tickers

One or more ticker symbols

TYPE: str DEFAULT: ()

Source code in quantflow/data/fmp.py
async def peers(
    self,
    *tickers: Annotated[str, Doc("One or more ticker symbols")],
    **kw: Any,
) -> list[dict]:
    """Stock peers based on sector, exchange and market cap"""
    kwargs = self.params(**kw)
    kwargs["params"]["symbol"] = self.join(*tickers)
    return await self.get_path("stock_peers", **kwargs)

news async

news(*tickers, **kw)

Company quote - real time

PARAMETER DESCRIPTION
*tickers

One or more ticker symbols

TYPE: str DEFAULT: ()

Source code in quantflow/data/fmp.py
async def news(
    self,
    *tickers: Annotated[str, Doc("One or more ticker symbols")],
    **kw: Any,
) -> list[dict]:
    """Company quote - real time"""
    kwargs = self.params(**kw)
    if tickers:
        kwargs["params"]["tickers"] = self.join(*tickers)
    return await self.get_path("stock_news", **kwargs)

search async

search(query, *, exchange=None, limit=None, symbol=False, **kw)
PARAMETER DESCRIPTION
query

Search query string

TYPE: str

exchange

Filter by exchange

TYPE: str | None DEFAULT: None

limit

Maximum number of results

TYPE: int | None DEFAULT: None

symbol

Search by symbol instead of name

TYPE: bool DEFAULT: False

Source code in quantflow/data/fmp.py
async def search(
    self,
    query: Annotated[str, Doc("Search query string")],
    *,
    exchange: Annotated[str | None, Doc("Filter by exchange")] = None,
    limit: Annotated[int | None, Doc("Maximum number of results")] = None,
    symbol: Annotated[bool, Doc("Search by symbol instead of name")] = False,
    **kw: Any,
) -> list[dict]:
    path = "search-symbol" if symbol else "search-name"
    return await self.get_path(
        path,
        **self.params(
            compact_dict(query=query, exchange=exchange, limit=limit), **kw
        ),
    )

prices async

prices(symbol, *, frequency=None, from_date=None, to_date=None, convert_to_date=False)

Historical prices, daily if frequency is not provided

PARAMETER DESCRIPTION
symbol

Ticker symbol

TYPE: str

frequency

Price frequency (e.g., '1min', '5min', 'daily')

TYPE: str | None DEFAULT: None

from_date

From date for historical prices

TYPE: str | date | None DEFAULT: None

to_date

To date for historical prices

TYPE: str | date | None DEFAULT: None

convert_to_date

Convert date column to datetime type

TYPE: bool DEFAULT: False

Source code in quantflow/data/fmp.py
async def prices(
    self,
    symbol: Annotated[str, Doc("Ticker symbol")],
    *,
    frequency: Annotated[
        str | None, Doc("Price frequency (e.g., '1min', '5min', 'daily')")
    ] = None,
    from_date: Annotated[
        str | date | None, Doc("From date for historical prices")
    ] = None,
    to_date: Annotated[
        str | date | None, Doc("To date for historical prices")
    ] = None,
    convert_to_date: Annotated[
        bool, Doc("Convert date column to datetime type")
    ] = False,
) -> pd.DataFrame:
    """Historical prices, daily if frequency is not provided"""
    path = (
        "historical-price-eod/full"
        if not frequency
        else f"historical-chart/{frequency}"
    )
    data = await self.get_path(
        path,
        params=compact_dict(
            {"from": to_date_iso(from_date), "to": to_date_iso(to_date)},
            frequency=frequency,
            symbol=symbol,
        ),
    )
    if isinstance(data, dict):
        data = data.get("historical", [])
    df = pd.DataFrame(data)
    if convert_to_date and "date" in df.columns:
        df["date"] = pd.to_datetime(df["date"])
    return df

sector_performance async

sector_performance(*, from_date=None, to_date=None, summary=False, params=None, **kw)
PARAMETER DESCRIPTION
from_date

Start date for historical sector performance

TYPE: date | None DEFAULT: None

to_date

End date for historical sector performance

TYPE: date | None DEFAULT: None

summary

Return summary instead of daily performance

TYPE: bool DEFAULT: False

params

Additional query parameters

TYPE: dict | None DEFAULT: None

Source code in quantflow/data/fmp.py
async def sector_performance(
    self,
    *,
    from_date: Annotated[
        date | None, Doc("Start date for historical sector performance")
    ] = None,
    to_date: Annotated[
        date | None, Doc("End date for historical sector performance")
    ] = None,
    summary: Annotated[
        bool, Doc("Return summary instead of daily performance")
    ] = False,
    params: Annotated[dict | None, Doc("Additional query parameters")] = None,
    **kw: Any,
) -> dict | list[dict]:
    if not from_date:
        data = await self.get_path("sectors-performance", params=params, **kw)
        return {d["sector"]: Decimal(d["changesPercentage"][:-1]) for d in data}
    else:
        params = params.copy() if params is not None else {}
        params.update(compact_dict({"from": from_date, "to": to_date}))
        data = await self.get_path(
            "historical-sectors-performance", params=params, **kw
        )
        ts = [dict(nice_sector_performance(d)) for d in data]
        return summary_sector_performance(ts) if summary else ts

sector_pe async

sector_pe(**kw)
Source code in quantflow/data/fmp.py
async def sector_pe(self, **kw: Any) -> list[dict]:
    return cast(list[dict], await self.get_path("sector_price_earning_ratio", **kw))

forex_list async

forex_list()
Source code in quantflow/data/fmp.py
async def forex_list(self) -> list[dict]:
    return await self.get_path("symbol/available-forex-currency-pairs")

historical_frequencies

historical_frequencies()
Source code in quantflow/data/fmp.py
def historical_frequencies(self) -> dict:
    return {
        "1min": 1,
        "5min": 5,
        "15min": 15,
        "30min": 30,
        "1hour": 60,
        "4hour": 240,
        "": 1440,
    }

historical_frequencies_annulaized

historical_frequencies_annulaized()
Source code in quantflow/data/fmp.py
def historical_frequencies_annulaized(self) -> dict:
    one_year = 525600
    return {k: v / one_year for k, v in self.historical_frequencies().items()}

crypto_list async

crypto_list()
Source code in quantflow/data/fmp.py
async def crypto_list(self) -> list[dict]:
    return await self.get_path("symbol/available-cryptocurrencies")

get_path async

get_path(path, **kw)
PARAMETER DESCRIPTION
path

API endpoint path

TYPE: str

Source code in quantflow/data/fmp.py
async def get_path(
    self,
    path: Annotated[str, Doc("API endpoint path")],
    **kw: Any,
) -> list[dict]:
    result = await self.get(f"{self.url}/{path}", **self.params(**kw))
    return cast(list[dict], result)

join

join(*tickers)
PARAMETER DESCRIPTION
*tickers

One or more ticker symbols

TYPE: str DEFAULT: ()

Source code in quantflow/data/fmp.py
def join(
    self,
    *tickers: Annotated[str, Doc("One or more ticker symbols")],
) -> str:
    value = ",".join(tickers)
    if not value:
        raise TypeError("at least one ticker must be provided")
    return value

params

params(params=None, **kw)
PARAMETER DESCRIPTION
params

Query parameters dictionary

TYPE: dict | None DEFAULT: None

Source code in quantflow/data/fmp.py
def params(
    self,
    params: Annotated[dict | None, Doc("Query parameters dictionary")] = None,
    **kw: Any,
) -> dict:
    params = params.copy() if params is not None else {}
    params["apikey"] = self.key
    return {"params": params, **kw}