binance-spot-websocket-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBinance Spot WebSocket Skill
Binance Spot WebSocket 技能
Use this skill to run Binance Spot public market streams through raw WebSocket mode.
uxc subscribeReuse the skill for generic runtime behavior, sink handling, and event-envelope parsing.
uxc使用该技能通过原生WebSocket模式运行币安现货公开市场流。
uxc subscribe复用技能来处理通用运行时行为、输出目标(sink)处理以及事件信封解析。
uxcPrerequisites
前提条件
- is installed and available in
uxc.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
核心工作流
- Start a subscription directly with :
uxc subscribe startuxc subscribe start wss://stream.binance.com:443/ws/btcusdt@trade --transport websocket --sink file:$HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
- Inspect the sink output:
tail -n 5 $HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
- Query runtime status:
uxc subscribe listuxc subscribe status <job_id>
- Stop the job when finished:
uxc subscribe stop <job_id>
- 使用直接启动订阅:
uxc subscribe startuxc subscribe start wss://stream.binance.com:443/ws/btcusdt@trade --transport websocket --sink file:$HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
- 查看输出目标的内容:
tail -n 5 $HOME/.uxc/subscriptions/binance-btcusdt-trade.ndjson
- 查询运行时状态:
uxc subscribe listuxc subscribe status <job_id>
- 完成后停止任务:
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 events with Binance
datapayloadstrade - after stop
closed
Observed event fields included:
e: "trade"s: "BTCUSDT"pqt
以下原生WebSocket实时流已通过成功验证:
uxc- 端点:
wss://stream.binance.com:443/ws/btcusdt@trade - 传输方式:
--transport websocket - 输出目标内容:
open- 重复的事件,携带币安
data负载trade - 停止后显示
closed
观察到的事件字段包括:
e: "trade"s: "BTCUSDT"pqt
Guardrails
防护机制
- Keep automation on the JSON output envelope; do not use .
--text - Parse stable event fields first: ,
event_kind,data.meta - Use as the default public stream host; it validated more reliably than
wss://stream.binance.com:443in recent runtime checks.:9443 - 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 wrappers.
stream - is the intended execution path for this skill;
uxc subscribe start ... --transport websocketis not the main interface because stream identity is encoded directly in the endpoint path.uxc link
- 针对JSON输出信封进行自动化处理;请勿使用参数。
--text - 优先解析稳定的事件字段:、
event_kind、data。meta - 使用作为默认公开流主机;在近期运行时检查中,它比
wss://stream.binance.com:443更可靠。:9443 - 流名称必须为小写。
- 该技能为只读模式。请勿将其描述为账户、订单或带签名的WebSocket支持。
- 当单个任务需要将多个市场数据输出到同一个输出目标时,组合流非常有用,但下游解析必须处理包装器。
stream - 是该技能的预期执行路径;
uxc subscribe start ... --transport websocket不是主要接口,因为流标识直接编码在端点路径中。uxc link
References
参考资料
- Usage patterns:
references/usage-patterns.md
- Binance Spot WebSocket Streams:
- 使用模式:
references/usage-patterns.md
- 币安现货WebSocket流: