binance-spot-websocket-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Binance Spot WebSocket Skill

Binance Spot WebSocket 技能

Use this skill to run Binance Spot public market streams through
uxc subscribe
raw WebSocket mode.
Reuse the
uxc
skill for generic runtime behavior, sink handling, and event-envelope parsing.
使用该技能通过
uxc subscribe
原生WebSocket模式运行币安现货公开市场流。
复用
uxc
技能来处理通用运行时行为、输出目标(sink)处理以及事件信封解析。

Prerequisites

前提条件

  • uxc
    is installed and available in
    PATH
    .
  • Network access to Binance Spot public WebSocket streams.
  • A writable sink path for NDJSON output.
  • 已安装
    uxc
    且其可在
    PATH
    中访问。
  • 能够访问币安现货公开WebSocket流的网络环境。
  • 一个可写入的输出路径(sink)用于存储NDJSON格式的输出。

Scope

适用范围

This skill covers Binance Spot public market streams such as:
  • trade events
  • aggregate trade events
  • book ticker updates
  • ticker updates
  • depth updates
This skill does not cover:
  • Binance Spot REST/OpenAPI workflows
  • private user data streams
  • signed WebSocket API methods
  • margin, wallet, futures, or other non-Spot product families
该技能涵盖币安现货公开市场流,例如:
  • 交易事件
  • 聚合交易事件
  • 买卖盘报价更新
  • 行情报价更新
  • 深度行情更新
该技能涵盖:
  • 币安现货REST/OpenAPI工作流
  • 用户私有数据流
  • 带签名的WebSocket API方法
  • 杠杆、钱包、期货或其他非现货产品系列

Endpoint Model

端点模型

Binance Spot public market streams use raw WebSocket endpoints.
  • preferred base:
    wss://stream.binance.com:443
  • raw stream form:
    wss://stream.binance.com:443/ws/<streamName>
  • combined stream form:
    wss://stream.binance.com:443/stream?streams=<stream1>/<stream2>
Important:
  • stream names are lowercase
  • connections are valid for up to 24 hours
  • raw stream payloads arrive directly as JSON objects
  • combined stream payloads arrive as
    {"stream":"...","data":{...}}
币安现货公开市场流使用原生WebSocket端点。
  • 首选基础地址:
    wss://stream.binance.com:443
  • 原生流格式:
    wss://stream.binance.com:443/ws/<streamName>
  • 组合流格式:
    wss://stream.binance.com:443/stream?streams=<stream1>/<stream2>
重要提示:
  • 流名称必须为小写
  • 连接有效期最长为24小时
  • 原生流的负载直接以JSON对象形式传输
  • 组合流的负载以
    {"stream":"...","data":{...}}
    格式传输

Core Workflow

核心工作流

  1. Start a subscription directly with
    uxc subscribe start
    :
    • uxc subscribe start wss://stream.binance.com:443/ws/btcusdt@trade --transport websocket --sink file:$HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
  2. Inspect the sink output:
    • tail -n 5 $HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
  3. Query runtime status:
    • uxc subscribe list
    • uxc subscribe status <job_id>
  4. Stop the job when finished:
    • uxc subscribe stop <job_id>
  1. 使用
    uxc subscribe start
    直接启动订阅:
    • uxc subscribe start wss://stream.binance.com:443/ws/btcusdt@trade --transport websocket --sink file:$HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
  2. 查看输出目标的内容:
    • tail -n 5 $HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
  3. 查询运行时状态:
    • uxc subscribe list
    • uxc subscribe status <job_id>
  4. 完成后停止任务:
    • uxc subscribe stop <job_id>

Common Stream Targets

常见流目标

  • raw trade stream:
    • btcusdt@trade
  • aggregate trade stream:
    • btcusdt@aggTrade
  • book ticker stream:
    • btcusdt@bookTicker
  • mini ticker stream:
    • btcusdt@miniTicker
  • rolling ticker stream:
    • btcusdt@ticker
  • depth stream:
    • btcusdt@depth
  • 原生交易流:
    • btcusdt@trade
  • 聚合交易流:
    • btcusdt@aggTrade
  • 买卖盘报价流:
    • btcusdt@bookTicker
  • 迷你行情报价流:
    • btcusdt@miniTicker
  • 滚动行情报价流:
    • btcusdt@ticker
  • 深度行情流:
    • btcusdt@depth

Runtime Validation

运行时验证

The following live raw WebSocket flow was validated successfully through
uxc
:
  • endpoint:
    wss://stream.binance.com:443/ws/btcusdt@trade
  • transport:
    --transport websocket
  • sink output:
    • open
    • repeated
      data
      events with Binance
      trade
      payloads
    • closed
      after stop
Observed event fields included:
  • e: "trade"
  • s: "BTCUSDT"
  • p
  • q
  • t
以下原生WebSocket实时流已通过
uxc
成功验证:
  • 端点:
    wss://stream.binance.com:443/ws/btcusdt@trade
  • 传输方式:
    --transport websocket
  • 输出目标内容:
    • open
    • 重复的
      data
      事件,携带币安
      trade
      负载
    • 停止后显示
      closed
观察到的事件字段包括:
  • e: "trade"
  • s: "BTCUSDT"
  • p
  • q
  • t

Guardrails

防护机制

  • Keep automation on the JSON output envelope; do not use
    --text
    .
  • Parse stable event fields first:
    event_kind
    ,
    data
    ,
    meta
    .
  • Use
    wss://stream.binance.com:443
    as the default public stream host; it validated more reliably than
    :9443
    in recent runtime checks.
  • Stream names must be lowercase.
  • This skill is read-only. Do not describe it as account, order, or signed WebSocket support.
  • Combined streams are useful when one job should emit multiple markets into one sink, but downstream parsing must handle
    stream
    wrappers.
  • uxc subscribe start ... --transport websocket
    is the intended execution path for this skill;
    uxc link
    is not the main interface because stream identity is encoded directly in the endpoint path.
  • 针对JSON输出信封进行自动化处理;请勿使用
    --text
    参数。
  • 优先解析稳定的事件字段:
    event_kind
    data
    meta
  • 使用
    wss://stream.binance.com:443
    作为默认公开流主机;在近期运行时检查中,它比
    :9443
    更可靠。
  • 流名称必须为小写。
  • 该技能为只读模式。请勿将其描述为账户、订单或带签名的WebSocket支持。
  • 当单个任务需要将多个市场数据输出到同一个输出目标时,组合流非常有用,但下游解析必须处理
    stream
    包装器。
  • uxc subscribe start ... --transport websocket
    是该技能的预期执行路径;
    uxc link
    不是主要接口,因为流标识直接编码在端点路径中。

References

参考资料