360 Secure SkillHub
360 安全技能中心

OKX Exchange WebSocket Skill

该 Skill 指导在 uxc 的原始 WebSocket 模式下订阅 OKX 公共行情频道(tickers、trades、books5、candle 等),通过 --init-frame 发送订阅帧,将事件写入 NDJSON sink 文件,并给出发起、查看、状态查询与停止的工作流;不涉及私有鉴权、交易账户频道和 REST 接口。

jolestar
jolestar
热度 63.89
最近更新 2026-05-11 17:32:13
分类:数据依赖:代码执行 / 读写文件 / 第三方 API应用场景:数据处理 / 财务 / API 集成

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add okx-exchange-websocket-skill
Metadata
name
okx-exchange-websocket-skill
description
Subscribe to OKX public exchange WebSocket channels through UXC raw WebSocket mode for ticker, trade, book, and candle events with explicit subscribe frames.

OKX Exchange WebSocket Skill

Use this skill to run OKX public exchange WebSocket channels through uxc subscribe raw WebSocket mode.

Reuse the uxc skill for generic runtime behavior, sink handling, and event-envelope parsing.

Prerequisites

  • uxc is installed and available in PATH.
  • Network access to the OKX public WebSocket endpoint.
  • A writable sink path for NDJSON output.

Scope

This skill covers OKX public exchange channels such as:

  • tickers
  • trades
  • books and books5
  • candle channels

This skill does not cover:

  • OKX OnchainOS MCP
  • private WebSocket login flows
  • trading, account, or order-management channels
  • REST API workflows

Endpoint Model

Use the OKX public WebSocket endpoint:

  • wss://ws.okx.com:8443/ws/v5/public

OKX public channels require a subscribe frame after connect, for example:

{"op":"subscribe","args":[{"channel":"tickers","instId":"BTC-USDT"}]}

Core Workflow

  1. Start a raw WebSocket subscription:
    • uxc subscribe start wss://ws.okx.com:8443/ws/v5/public --transport websocket --init-frame '{"op":"subscribe","args":[{"channel":"tickers","instId":"BTC-USDT"}]}' --sink file:$HOME/.uxc/subscriptions/okx-btcusdt-ticker.ndjson
  2. Inspect sink output:
    • tail -n 5 $HOME/.uxc/subscriptions/okx-btcusdt-ticker.ndjson
  3. Query runtime status:
    • uxc subscribe list
    • uxc subscribe status <job_id>
  4. Stop the job when finished:
    • uxc subscribe stop <job_id>

Common Subscribe Frames

  • tickers:
    • {"op":"subscribe","args":[{"channel":"tickers","instId":"BTC-USDT"}]}
  • trades:
    • {"op":"subscribe","args":[{"channel":"trades","instId":"BTC-USDT"}]}
  • books5:
    • {"op":"subscribe","args":[{"channel":"books5","instId":"BTC-USDT"}]}
  • candles:
    • {"op":"subscribe","args":[{"channel":"candle1m","instId":"BTC-USDT"}]}

Runtime Validation

The following live raw WebSocket flow has been validated successfully through uxc:

  • endpoint: wss://ws.okx.com:8443/ws/v5/public
  • transport: --transport websocket
  • init frame:
    • {"op":"subscribe","args":[{"channel":"tickers","instId":"BTC-USDT"}]}

Observed sink behavior:

  • initial open
  • JSON data event for subscription acknowledgement
  • repeated data events carrying ticker payloads under:
    • arg.channel
    • arg.instId
    • data[0].last
    • data[0].bidPx
    • data[0].askPx
    • data[0].ts

Guardrails

  • Keep automation on the JSON output envelope; do not use --text.
  • Parse stable event fields first: event_kind, data, meta.
  • Always pass --transport websocket for this skill.
  • Public OKX channels do not require login. Do not mix this skill with private WebSocket auth flows.
  • --init-frame is required because OKX public channels are multiplexed behind one endpoint.
  • instId values use OKX instrument naming such as BTC-USDT.
  • uxc subscribe start ... --transport websocket is the intended execution path for this skill; uxc link is not the main interface because channel selection lives in the subscribe frame.

References