fetch_open_interest

Documentation for eth_defi.derive.api.fetch_open_interest function.

fetch_open_interest(session, instrument_name, base_url='https://api.lyra.finance', timeout=30.0)

Fetch the current open interest for a Derive perpetual instrument.

Calls the public /public/statistics endpoint. No authentication required.

Warning

This endpoint always returns the current live OI regardless of any timestamp parameter. It does not support historical queries. For historical open interest data, use fetch_open_interest_onchain() which reads on-chain state from the Derive Chain archive node at any historical block.

Example:

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

session = create_derive_session()
entry = fetch_open_interest(session, "ETH-PERP")
if entry:
    print(f"{entry.timestamp}: {entry.open_interest}")
Parameters
  • session (requests.sessions.Session) – HTTP session from create_derive_session().

  • instrument_name (str) – Perpetual instrument name (e.g. "ETH-PERP") or aggregate type ("PERP", "ALL", "OPTION", "SPOT").

  • base_url (str) – Derive API base URL.

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

Returns

OpenInterestEntry timestamped at the current moment, or None if open interest is zero (instrument not yet listed).

Raises

ValueError – If the API returns an error response.

Return type

eth_defi.derive.api.OpenInterestEntry | None