"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
持仓量(Open Interest)
接口:GET /api/v5/public/open-interest 描述:获取合约持仓量数据,反映市场中未平仓合约的总量。持仓量变化是判断市场趋势的重要指标。 限频:20次/2s
输入参数
| 名称 | 类型 | 必选 | 描述 |
|---|---|---|---|
| instType | str | Y | 产品类型:SWAP、FUTURES、OPTION |
| instId | str | N | 产品ID(可选过滤) |
输出参数
| 名称 | 类型 | 描述 |
|---|---|---|
| instType | str | 产品类型 |
| instId | str | 产品ID |
| oi | str | 持仓量(合约张数) |
| oiCcy | str | 持仓量(币) |
| ts | str | 时间戳(毫秒) |
接口示例
import requests
import pandas as pd
BASE_URL = "https://www.okx.com/api/v5"
# 获取所有永续合约持仓量
resp = requests.get(f"{BASE_URL}/public/open-interest", params={"instType": "SWAP"})
oi_data = resp.json()["data"]
df = pd.DataFrame(oi_data)
df["oiCcy"] = df["oiCcy"].astype(float)
df = df.sort_values("oiCcy", ascending=False)
print(df[["instId", "oi", "oiCcy"]].head(10))