## 历史资金费率 ---- 接口:GET /api/v5/public/funding-rate-history 描述:获取永续合约的历史资金费率数据,用于分析费率趋势和套利机会。 限频:10次/2s **输入参数** | 名称 | 类型 | 必选 | 描述 | | ---- | ---- | ---- | ---- | | instId | str | Y | 永续合约ID,如 `BTC-USDT-SWAP` | | after | str | N | 请求此时间戳之前的数据(毫秒) | | before | str | N | 请求此时间戳之后的数据(毫秒) | | limit | str | N | 返回条数,默认 100 | **输出参数** | 名称 | 类型 | 描述 | | ---- | ---- | ---- | | instId | str | 合约ID | | instType | str | 产品类型 | | fundingRate | str | 资金费率 | | realizedRate | str | 实际收取费率 | | fundingTime | str | 结算时间(毫秒) | **接口示例** ```python import requests import pandas as pd BASE_URL = "https://www.okx.com/api/v5" # 获取 BTC 永续历史资金费率 resp = requests.get(f"{BASE_URL}/public/funding-rate-history", params={ "instId": "BTC-USDT-SWAP", "limit": "100" }) rates = resp.json()["data"] df = pd.DataFrame(rates) df["fundingRate"] = df["fundingRate"].astype(float) df["fundingTime"] = pd.to_datetime(df["fundingTime"].astype(int), unit="ms") print(f"平均费率: {df['fundingRate'].mean():.6f}") print(f"最大费率: {df['fundingRate'].max():.6f}") print(f"最小费率: {df['fundingRate'].min():.6f}") print(df[["fundingTime", "fundingRate"]].head(10)) ```