fetch_funding_rate_history

Documentation for eth_defi.derive.api.fetch_funding_rate_history function.

fetch_funding_rate_history(session, instrument_name, start_time=None, end_time=None, base_url='https://api.lyra.finance', timeout=30.0)

Fetch funding rate history for a Derive perpetual instrument.

Calls the public get_funding_rate_history endpoint. No authentication required.

Data is returned at hourly resolution — the native funding rate interval on Derive. The full history is available back to instrument inception (ETH-PERP since 2024-01-05).

For best results, keep the query window to one day at a time and use DeriveFundingRateDatabase for bulk historical fetches.

Note

The Derive API requires the parameter names start_timestamp and end_timestamp (not start_time / end_time). Using the wrong names silently falls back to the most recent 30 days.

Example:

from eth_defi.derive.api import fetch_funding_rate_history
from eth_defi.derive.session import create_derive_session

session = create_derive_session()
rates = fetch_funding_rate_history(session, "ETH-PERP")
for r in rates:
    print(f"{r.timestamp}: {r.funding_rate}")
Parameters
  • session (requests.sessions.Session) – HTTP session from create_derive_session().

  • instrument_name (str) – Perpetual instrument name (e.g. "ETH-PERP").

  • start_time (datetime.datetime | None) – Start of the query window (naive UTC). Defaults to 30 days ago.

  • end_time (datetime.datetime | None) – End of the query window (naive UTC). Defaults to now.

  • base_url (str) – Derive API base URL.

  • timeout (float) – HTTP request timeout in seconds.

Returns

List of funding rate entries sorted by timestamp ascending.

Raises

ValueError – If the API returns an error response.

Return type

list[eth_defi.derive.api.FundingRateEntry]