okx-account

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OKX Account (Read-Only)

OKX 账户(只读)

Read-only OKX account tracker built on the official
python-okx
library. Use it for account tracking, daily/weekly reports, risk alerts, and cashflow attribution.
基于官方
python-okx
库构建的只读OKX账户追踪工具。 可用于账户追踪、日/周度报告、风险预警以及现金流归因分析。

How to Get an OKX API Key (Read-Only)

如何获取只读OKX API密钥

  1. Sign in at okx.com, top-right avatar → API
  2. Create V5 API Key → complete 2FA verification
  3. Fill the form:
    • API name: anything
    • Passphrase: ⚠️ a brand-new password used to sign API requests, NOT your login password. Lose it and you can only delete the key and create a new one.
    • Permissions: tick Read only, leave Trade / Withdraw off
    • IP whitelist: leave empty
  4. Submit → immediately copy and save all three values:
    API Key
    /
    Secret Key
    /
    Passphrase
    (Secret is shown only once)
  5. Set them into this skill's environment variables
  1. 登录okx.com,点击右上角头像 → API
  2. 创建V5 API密钥 → 完成二次验证(2FA)
  3. 填写表单:
    • API名称: 可自定义
    • Passphrase(密钥密码): ⚠️ 用于签署API请求的全新密码,并非您的登录密码。若丢失该密码,您只能删除当前密钥并重新创建。
    • 权限: 仅勾选只读,取消交易/提现权限
    • IP白名单: 留空
  4. 提交后 → 立即复制并保存以下三项信息:
    API Key
    /
    Secret Key
    /
    Passphrase
    (Secret Key仅显示一次)
  5. 将这些信息配置到本工具的环境变量中
参考文档:OKX官方教程

Prerequisites

前置条件

1) API key

1) API密钥

In OKX API Management create a key with Read only. OKX requires three credentials:
api_key
/
secret
/
passphrase
(the password you set when creating the key — not the login password).
在OKX API管理页面创建一个只读权限的密钥。OKX需要三项凭证:
api_key
/
secret
/
passphrase
(创建密钥时设置的密码,而非登录密码)。

2) Environment variables

2) 环境变量

OKX_RO_API_KEY=...
OKX_RO_SECRET=...
OKX_RO_PASSPHRASE=...
OKX_RO_API_KEY=...
OKX_RO_SECRET=...
OKX_RO_PASSPHRASE=...

3) Geo restriction (required)

3) 地域限制(必填)

OKX geo-blocks server IPs. Scripts default to the SC internal HK proxy:
python
HK_PROXY = "http://hk:x@sc-vpn.internal:8080"
Do not set a global
HTTP_PROXY
.
OKX对服务器IP有地域限制。脚本默认使用SC内部香港代理:
python
HK_PROXY = "http://hk:x@sc-vpn.internal:8080"
请勿设置全局
HTTP_PROXY

Scripts

脚本使用

bash
python3 skills/okx-account/scripts/okx_account.py <action> [options]
python3 skills/okx-account/scripts/account_scenarios.py <scenario> [options]
bash
python3 skills/okx-account/scripts/okx_account.py <action> [options]
python3 skills/okx-account/scripts/account_scenarios.py <scenario> [options]

Actions

操作指令

  • summary
    : one-shot summary
  • account_balance
    /
    account_config
    /
    positions
    /
    position_risk
    /
    fee_rates
    /
    bills
  • open_orders
    /
    order_history
    /
    fills_history
  • funding_balance
    /
    deposits
    /
    withdrawals
    /
    currencies
    /
    funding_rate
  • summary
    : 一键生成账户汇总信息
  • account_balance
    /
    account_config
    /
    positions
    /
    position_risk
    /
    fee_rates
    /
    bills
    (账户余额/账户配置/仓位/仓位风险/手续费率/账单)
  • open_orders
    /
    order_history
    /
    fills_history
    (未成交订单/订单历史/成交历史)
  • funding_balance
    /
    deposits
    /
    withdrawals
    /
    currencies
    /
    funding_rate
    (资金余额/充值记录/提现记录/支持币种/资金费率)

Scenarios

场景功能

  • portfolio_snapshot
    : full account snapshot
  • perp_risk
    : perpetual risk monitoring (margin ratio + unrealized loss thresholds)
  • cashflow
    : deposits + withdrawals + 7d bills aggregation
  • trading_activity
    : recent fills activity by instType
  • portfolio_snapshot
    : 完整账户快照
  • perp_risk
    : 永续合约风险监控(保证金比例+未实现亏损阈值)
  • cashflow
    : 充值+提现+7天账单汇总
  • trading_activity
    : 按产品类型统计近期成交活动

Common usage

常用示例

bash
python3 skills/okx-account/scripts/okx_account.py summary
python3 skills/okx-account/scripts/account_scenarios.py portfolio_snapshot
python3 skills/okx-account/scripts/account_scenarios.py perp_risk --loss-threshold 5000
python3 skills/okx-account/scripts/account_scenarios.py cashflow --limit 100
python3 skills/okx-account/scripts/account_scenarios.py trading_activity --inst-types SPOT,SWAP
bash
python3 skills/okx-account/scripts/okx_account.py summary
python3 skills/okx-account/scripts/account_scenarios.py portfolio_snapshot
python3 skills/okx-account/scripts/account_scenarios.py perp_risk --loss-threshold 5000
python3 skills/okx-account/scripts/account_scenarios.py cashflow --limit 100
python3 skills/okx-account/scripts/account_scenarios.py trading_activity --inst-types SPOT,SWAP

Notes

注意事项

  • The
    passphrase
    is easy to forget — it is the password you set when creating the key, not your login password.
  • If you bound an IP whitelist when creating the key, either disable it or add the proxy egress IP.
  • Use time-windowed pagination for high-volume fills.
  • passphrase
    容易遗忘,它是创建密钥时设置的密码,而非登录密码。
  • 如果创建密钥时绑定了IP白名单,请关闭该设置或添加代理出口IP。
  • 对于大量成交记录,请使用时间窗口分页查询。