Skip to content

models

drift_data.models #

ContractConverted #

Bases: BaseModel

Converted contract data from Drift Protocol.

This model represents the converted data for a contract, which is more user-friendly. It is derived from the raw contract data (drift_data.ContractRaw) and provides types that are easier to work with.

from_raw classmethod #

from_raw(raw: ContractRaw) -> ContractConverted

Convert a raw contract to a converted contract.

Source code in drift_data/models.py
@classmethod
def from_raw(cls, raw: ContractRaw) -> "ContractConverted":
    """Convert a raw contract to a converted contract."""
    return cls.model_validate(raw.model_dump())

ContractRaw #

Bases: BaseModel

Raw contract data from Drift Protocol.

This model represents the raw data for a contract as returned by the Drift Data API. This is undocumented, but is referenced in the teacher documentation.

to_converted #

to_converted() -> ContractConverted

Convert a raw contract to a converted contract.

Source code in drift_data/models.py
def to_converted(self) -> "ContractConverted":
    """Convert a raw contract to a converted contract."""
    return ContractConverted.model_validate(self.model_dump())

FundingRateRecord #

Bases: BaseModel

Record of a perp market funding rate on Drift Protocol.

While this model is designed for a new undocumented API endpoint, it is nearly identical to GET /fundingRates and can be used as a point of reference.