实时多链加密货币行情数据流
简介
基于 Bitquery 官方 API 的多链实时加密货币数据流技能,提供 1 秒级 OHLC 行情、USD 计价及成交量数据,支持 8 大主流公链全代币监控。
原始描述
Real-time streaming crypto token feed for charting with 1-second OHLC ticks and USD pricing across Arbitrum, Base, Matic, Ethereum, Solana, Binance Smart Cha...
通过你的 Agent 添加
安装目录:crypto-charting-with-usd-pricing-1s/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
crypto-chart-usd 是一个专为实时加密货币数据可视化设计的 WebSocket 数据流技能。用户通过配置 BITQUERY_API_KEY 环境变量即可建立与 Bitquery Trading.Tokens API 的实时连接,获取 1 秒级 OHLC(开盘-最高-最低-收盘)行情数据、三维度成交量(Base/Quote/USD)以及多种 USD 价格指标(均值、简单/指数/加权移动平均线)。
该技能采用订阅制架构,无需轮询,数据主动推送至客户端。默认订阅间隔为 1 秒(Duration: 1),同时支持通过修改 GraphQL 查询参数切换至 5 分钟、1 小时或 1 天等其他时间维度。数据覆盖 Arbitrum、Base、Polygon、Ethereum、Solana、BNB Chain、Tron、Optimism 八大公链的全部代币,用户可通过 Token.Network 字段进行链级筛选或分组。
典型使用场景包括:构建实时加密货币行情仪表盘、开发量化交易策略的数据基础设施、进行多链资产组合监控,以及为交易分析平台提供底层数据流支持。
显著优点
高实时性与覆盖广度:1 秒级 tick 数据在多链加密货币数据服务中属于较高频率,且单一流同时覆盖 8 条主流公链的全部代币,无需为不同链部署独立数据源。
USD 标准化计价:内置 USD 价格换算与多种平滑算法(EMA/SMA/WSMA),降低跨链资产比价复杂度,便于构建统一的风险敞口视图。
技术栈简洁:仅需 Python 3.8+ 和 gql[websockets] 单一依赖,无复杂运行时要求,本地开发与云端部署门槛低。
数据源权威性:Bitquery 作为区块链数据领域的专业服务商,其 Trading.Tokens API 在加密资产数据分析领域具有较高认可度。
潜在缺点与局限性
认证方式存在结构性风险:Bitquery API 强制要求将 API Token 嵌入 WebSocket URL(?token=...),不支持 Header 或 Bearer Token 认证。这意味着令牌将以明文形式存在于内存、网络流量及潜在的日志记录中,存在不可消除的泄露面。
无单代币/单链过滤的订阅粒度:默认订阅返回全量多链多代币数据流,若仅需特定资产或特定链数据,仍需在客户端完成过滤,可能带来不必要的带宽与处理开销。
依赖外部商业服务:数据完全依赖 Bitquery 服务可用性与定价策略,存在供应商锁定风险;高频流可能触发 API 用量配额或产生较高费用。
技术债务风险:脚本硬编码了 GraphQL 查询结构与字段映射,若 Bitquery Schema 发生变更,需手动更新本地代码。
适合的目标群体
- 量化交易开发者与算法工程师:需要实时高频行情数据构建策略回测或实盘系统
- DeFi 产品团队:开发跨链资产管理面板、收益率追踪工具或风险监控系统
- 数据分析与可视化从业者:构建加密货币实时行情仪表盘或研究报告数据层
- 区块链媒体与研究机构:需要多链统一数据口径进行市场分析与内容生产
不适合:无 API 密钥获取渠道的个人用户、对数据隐私有极高要求且无法容忍令牌暴露风险的场景,以及仅需低频历史数据(日/周线)的传统投资分析场景。
使用风险
令牌泄露与账户安全:由于令牌必须嵌入 URL,任何捕获完整 URL 的机制(Shell 历史、IDE 调试输出、代理日志、容器日志、网络监控工具)均可能导致令牌泄露。一旦泄露,攻击者可完全 impersonate 账户并消耗 API 配额。
运行时环境安全:建议在隔离环境(容器、虚拟环境或专用机器)中运行,严格禁用或监控日志系统对 URL 的捕获行为,并制定密钥轮换预案。
性能与稳定性风险:WebSocket 长连接可能因网络波动中断,需实现重连机制;高频数据流对本地内存与网络带宽有持续占用;多代币同时推送时数据量可能突发增长。
合规与数据使用边界:获取的实时金融数据需遵守 Bitquery 服务条款,禁止未经授权的再分发或构建竞争性数据服务。
技能正文
name: crypto-chart-usd
description: >
Real-time streaming crypto token feed for charting with 1-second OHLC ticks and USD pricing
across Arbitrum, Base, Matic, Ethereum, Solana, Binance Smart Chain, Tron, and Optimism — all
tokens on these chains. Subscribe to a live multi-token, multi-chain stream over WebSocket:
OHLC, volume (Base/Quote/USD), and USD pricing (OHLC, moving averages) from the Bitquery
Trading.Tokens API.
requires:
env:
- name: BITQUERY_API_KEY
required: true
description: Your Bitquery API token (required for WebSocket connection)
Crypto charting with USD pricing (1s)
This skill gives you a real-time streaming multi-token, multi-chain crypto feed over WebSocket for charting: 1-second OHLC ticks, volume (Base, Quote, USD), and USD pricing (OHLC, moving averages) for all tokens on the supported chains. Data is streamed in real time from the Bitquery Trading.Tokens API — no polling. Default interval is 1 second (duration 1).
Supported networks: Arbitrum, Base, Matic (Polygon), Ethereum, Solana, Binance Smart Chain, Tron, Optimism. The subscription returns tokens across all of these; use the Token.Network field to filter or group by chain.
When to use this skill
- Chart multiple tokens across chains with 1-second OHLC and USD volume
- Get USD pricing where available (
Price.IsQuotedInUsd); OHLC and averages in USD - Live multi-token, multi-chain feed for dashboards and charting (no single-token or single-network filter)
What to consider before installing
This skill implements a Bitquery WebSocket Trading.Tokens stream and uses one external dependency and one credential. Before installing:
-
Required credential: This skill requires
BITQUERY_API_KEY(your Bitquery API token). The registry metadata must declare this credential so installers are prompted to provide it. Verify the registry entry listsBITQUERY_API_KEYas a required environment variable. -
⚠️ Critical security risk — Token in WebSocket URL: Bitquery's API does not support header-based auth or any method other than embedding the token in the WebSocket URL as
?token=.... This is an inherent design limitation of the API, not a bug in this skill. However, it creates a significant leakage risk:- The token will always be present in the connection URL in memory and in any logs or captured network traffic
- If the URL is printed, logged, captured in shell history, IDE history, proxy logs, firewall logs, or monitoring systems, the token is exposed
- Once exposed, anyone with the token can impersonate your account and consume your quota
- Mitigation: Store the key only in a secure environment variable; never print or log the full URL; rotate the key immediately if you suspect exposure; run in a sandboxed environment (virtualenv/container) to limit logging surface
-
Sandbox first: Before using this skill in production or in shared environments, test it in an isolated environment (virtualenv, container, or dedicated machine) to confirm the logging behavior and ensure the URL is not captured by system monitoring or logging tools you have enabled.
-
Source and publisher: Verify the publisher's identity and source control access. Review the code in
scripts/stream_crypto_chart.pyto confirm the script does not log the full URL before use.
Prerequisites
- Environment:
BITQUERY_API_KEY — your Bitquery API token (required).
BITQUERY_API_KEY — your Bitquery API token (required).⚠️ URL-only authentication (Bitquery API limitation): Bitquery's streaming endpoint accepts the token only in the WebSocket URL as a query parameter (?token=...). It does not support header-based auth or Bearer tokens. This design choice means:
-
The token is embedded in the connection URL and will be present in memory, network traces, and any logs that capture the full URL
-
Never print, log, or emit the full WebSocket URL in any context
-
Always construct the URL from the environment variable and pass it only to the WebSocket transport
-
If the URL appears in shell history, logs, IDE debugger, or network monitoring, the token is compromised
-
Rotate your API key immediately if you suspect it was logged or captured
-
Run this script only in controlled environments where logging and monitoring are configured securely
-
Runtime: Python 3.8+ and
pip. Install the dependency:pip install 'gql[websockets]'.
Security Checklist
Before running this skill, confirm:
- You have set
BITQUERY_API_KEYin your environment:export BITQUERY_API_KEY=your_token_here - You are running in a sandboxed or isolated environment (virtualenv, Docker, or dedicated machine)
- Logging and shell history are disabled or monitored to prevent URL capture: check
HISTFILE,.bash_history, system logs, IDE debug output - You understand that the WebSocket URL will contain your API token in plaintext in memory
- You have a plan to rotate your key if it is ever exposed
- You will not print, log, or commit the full URL to any file or logging system
If any of these cannot be confirmed, do not proceed with this skill until those conditions are met.
Step 1 — Check API Key
import os
api_key = os.getenv("BITQUERY_API_KEY")
if not api_key:
print("ERROR: BITQUERY_API_KEY environment variable is not set.")
print("Run: export BITQUERY_API_KEY=your_token")
exit(1)
import os
api_key = os.getenv("BITQUERY_API_KEY")
if not api_key:
print("ERROR: BITQUERY_API_KEY environment variable is not set.")
print("Run: export BITQUERY_API_KEY=your_token")
exit(1)
If the key is missing, tell the user and stop. Do not proceed without it.
Step 2 — Run the stream
Install the WebSocket dependency once:
pip install 'gql[websockets]'
Use the streaming script (subscribes to the multi-token 1-second chart feed in real time):
python ~/.openclaw/skills/crypto-chart-usd/scripts/stream_crypto_chart.py
Optional: stop after N seconds:
python ~/.openclaw/skills/crypto-chart-usd/scripts/stream_crypto_chart.py --timeout 60
Or subscribe inline with Python (real-time stream, 1s ticks):
import asyncio, os
from gql import Client, gql
from gql.transport.websockets import WebsocketsTransport
async def main():
token = os.environ["BITQUERY_API_KEY"]
url = f"wss://streaming.bitquery.io/graphql?token={token}"
transport = WebsocketsTransport(
url=url,
headers={"Sec-WebSocket-Protocol": "graphql-ws"},
)
async with Client(transport=transport) as session:
sub = gql("""
subscription {
Trading {
Tokens(where: { Interval: { Time: { Duration: { eq: 1 } } } }) {
Token { Address Id IsNative Name Network Symbol TokenId }
Block { Date Time Timestamp }
Interval { Time { Start Duration End } }
Volume { Base Quote Usd }
Price {
IsQuotedInUsd
Ohlc { Close High Low Open }
Average { ExponentialMoving Mean SimpleMoving WeightedSimpleMoving }
}
}
}
}
""")
async for result in session.subscribe(sub):
tokens = (result.get("Trading") or {}).get("Tokens") or []
for t in tokens:
ohlc = (t.get("Price") or {}).get("Ohlc") or {}
vol = t.get("Volume") or {}
print(
f"{t.get('Token', {}).get('Symbol', '?')} | "
f"Close: ${float(ohlc.get('Close') or 0):,.4f} | "
f"Vol USD: ${float(vol.get('Usd') or 0):,.2f}"
)
asyncio.run(main())
Step 3 — What you get on the stream
Each tick can contain multiple tokens from any of the supported chains (Arbitrum, Base, Matic, Ethereum, Solana, Binance Smart Chain, Tron, Optimism). For each token you get 1-second OHLC and interval data:
- Token: Address, Id, IsNative, Name, Network, Symbol, TokenId
- Block: Date, Time, Timestamp
- Interval: Time.Start, Duration (1), End
- Volume: Base, Quote, Usd
- Price: IsQuotedInUsd, Ohlc (Open, High, Low, Close), Average (Mean, SimpleMoving, ExponentialMoving, WeightedSimpleMoving)
Not all tokens are quoted in USD; check Price.IsQuotedInUsd and use USD fields when true. The stream runs until you stop it (Ctrl+C) or use --timeout.
Step 4 — Format output clearly
When presenting streamed ticks to the user, use a clear format like:
ETH (Ethereum) — ethereum @ 2025-03-16T12:00:01Z (1s candle)
OHLC: Open: $3,450.00 High: $3,460.00 Low: $3,445.00 Close: $3,455.00
Mean: $3,452.00 SMA: $3,451.00 EMA: $3,453.00
Volume (USD): $1,234,567.00
Interval (subscription)
The default subscription uses duration 1 (1-second tick/candle data). The same Trading.Tokens subscription supports other durations in the where clause (e.g. 5, 60, 1440 for 5m, 1h, 1d candles) if the API supports them for subscriptions.
Error handling
- Missing BITQUERY_API_KEY: Tell user to export the variable and stop
- WebSocket connection failed / 401: Token invalid or expired (auth is via URL
?token= only — do not pass the token in headers)
- Subscription errors in payload: Log the error message and stop cleanly (send complete, close transport)
- No ticks received: Check token and network; Bitquery may need a moment to send the first tick; multi-token stream can be bursty
Supported networks
?token= only — do not pass the token in headers)The feed includes tokens from: Arbitrum, Base, Matic (Polygon), Ethereum, Solana, Binance Smart Chain, Tron, Optimism. Filter by network in the subscription where clause (e.g. Token: { Network: { is: "ethereum" } }) or use Token.Network in your code to group or filter results. See references/graphql-fields.md for filter options.
Reference
Full field reference is in references/graphql-fields.md. Use it to add filters (e.g. by Currency, Network) or request extra fields in the subscription.
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。