获取加密货币杠杆多空比
okx_loan_ratiosRetrieve OKX cryptocurrency loan ratios: the cumulative amount of borrowed quote currency divided by borrowed base currency for a given symbol and time period.
Instructions
获取OKX加密货币借入计价货币与借入交易货币的累计数额比值
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | No | 币种,格式: BTC 或 ETH | BTC |
| period | No | 时间粒度,仅支持: [5m/1H/1D] 注意大小写,仅分钟为小写m | 1h |
Implementation Reference
- mcp_aktools/__init__.py:410-433 (handler)The function that executes the okx_loan_ratios tool logic. It calls the OKX API endpoint /api/v5/rubik/stat/margin/loan-ratio with symbol and period params, processes the JSON response into a pandas DataFrame, transforms the columns ('时间' for time and '多空比' for ratio), converts types, and returns CSV data.
@mcp.tool( title="获取加密货币杠杆多空比", description="获取OKX加密货币借入计价货币与借入交易货币的累计数额比值", ) def okx_loan_ratios( symbol: str = Field("BTC", description="币种,格式: BTC 或 ETH"), period: str = Field("1h", description="时间粒度,仅支持: [5m/1H/1D] 注意大小写,仅分钟为小写m"), ): res = requests.get( f"{OKX_BASE_URL}/api/v5/rubik/stat/margin/loan-ratio", params={ "ccy": symbol, "period": period, }, timeout=20, ) data = res.json() or {} dfs = pd.DataFrame(data.get("data", [])) if dfs.empty: return pd.DataFrame() dfs.columns = ["时间", "多空比"] dfs["时间"] = pd.to_datetime(dfs["时间"], errors="coerce", unit="ms") dfs["多空比"] = pd.to_numeric(dfs["多空比"], errors="coerce") return dfs.to_csv(index=False, float_format="%.2f").strip() - mcp_aktools/__init__.py:410-412 (registration)The tool is registered via the @mcp.tool() decorator on the okx_loan_ratios function, with title '获取加密货币杠杆多空比' and a description in Chinese.
@mcp.tool( title="获取加密货币杠杆多空比", description="获取OKX加密货币借入计价货币与借入交易货币的累计数额比值", - mcp_aktools/__init__.py:414-416 (schema)The input schema definitions: 'symbol' (str, default 'BTC') and 'period' (str, default '1h', supported values: 5m/1H/1D) defined via Pydantic Field annotations.
def okx_loan_ratios( symbol: str = Field("BTC", description="币种,格式: BTC 或 ETH"), period: str = Field("1h", description="时间粒度,仅支持: [5m/1H/1D] 注意大小写,仅分钟为小写m"), - mcp_aktools/__init__.py:23-23 (helper)The OKX_BASE_URL constant used by the handler, defaulting to 'https://www.okx.com' with override via environment variable.
OKX_BASE_URL = os.getenv("OKX_BASE_URL") or "https://www.okx.com"