QVeris
Guides 指南 / Live stock data for Claude Claude 实时股票数据
Claude market-data implementation lab Claude 行情接入实验室

How to Add Real-Time Stock Market Data to Claude 如何为 Claude 接入实时股票市场数据

Give Claude a narrow quote capability—not an unfiltered firehose. Connect a licensed feed through MCP or API tool use and expose source, session, delay, and timestamp in every answer. 不要把未经处理的行情流直接塞给 Claude,而应提供边界清晰的报价能力。通过 MCP 或 API tool use 接入合规数据源,并让每次回答都展示来源、交易时段、延迟和时间戳。

Core pattern: 核心模式: Claude requests a quote; application code validates the instrument, queries the entitled feed, normalizes the response, and returns evidence. Claude explains it but never invents the price. Claude 发起报价请求;应用代码校验标的、查询已授权 Feed、统一响应并返回依据。Claude 解释依据,但不生成价格。
Choose a path 选择路径 Test a quote workflow 测试报价工作流
Claude request routed through a secure market-data tool to a timestamped quote
Reasoning stays separate from retrieval, validation, and provenance. 推理与获取、校验和来源追踪相互分离。
Five-part lab 五段式实验

Build one trustworthy quote before scaling 先跑通一条可信报价,再考虑扩展

Decision 01

Choose the Claude surface first 先确定 Claude 的使用场景

MESSAGES API

Application-owned tool use 应用控制的 tool use

For a web app or analyst copilot, your backend sends the tool definition, executes Claude’s selected function, and returns a matching tool result. 适合 Web 应用或分析师 Copilot。后端发送工具定义,执行 Claude 选中的函数,再返回对应结果。

Anthropic tool use
MCP

Claude discovers a server Claude 发现 Server

For Claude Code or Desktop, the server exposes read-only tools and keeps provider credentials outside the conversation. 适合 Claude Code 或 Desktop。Server 暴露只读工具,并把数据源凭证留在对话之外。

Anthropic MCP
Browsing is not a quote feed. 浏览网页不是行情 Feed。 Pages may be cached, delayed, or licensed only for display. 网页可能缓存、延迟,或仅获准展示。
Contract 02

Make “real time” a field, not a claim 把“实时”变成字段,而不是宣传语

instrument Symbol, exchange, asset type 代码、交易所、资产类型
price Value and currency 数值与币种
as_of Provider timestamp 数据源时间戳
feed Provider and entitlement Provider 与授权 Feed
freshness Real-time, delayed, close 实时、延迟、收盘
session Pre, regular, after, closed 盘前、常规、盘后、休市
{ "instrument": { "symbol": "AAPL", "exchange": "NASDAQ" }, "price": 0, "currency": "USD", "as_of": "provider timestamp", "provider": "configured source", "feed": "entitled feed", "freshness": "real_time | delayed", "session": "regular | closed" }

The zero is a schema placeholder—not a quote. 零值只是 Schema 占位符,不代表报价。

Execution 03

Run Claude’s tool loop deliberately 明确控制 Claude 的工具调用循环

Describe one read-only operation 描述一个只读操作

Define get_stock_quote with symbol and optional exchange. State that it cannot trade. 定义 get_stock_quote,要求代码、可选交易所,并说明不能交易。

Validate outside the model 在模型之外校验

Resolve ambiguous tickers, cap batches, and never let Claude build a URL containing credentials. 处理代码歧义、限制批量大小,不让 Claude 拼接含密钥的 URL。

Execute and normalize 执行并归一化

Call a snapshot or read the newest validated stream event, then convert it to the contract. 调用快照或读取最新有效流事件,再转换为统一契约。

Return evidence and errors 返回依据与错误

Preserve ambiguity, halt, stale cache, entitlement, rate-limit, and timeout states. 保留歧义、停牌、缓存过期、授权、限流和超时状态。

Constrain the answer 约束回答

Require price, currency, exchange, session, source, and time. If stale, say unavailable. 要求价格、币种、交易所、时段、来源和时间;过期时说明不可用。

Connect with the QVeris MCP guide, inspect the tool directory, and test in the Playground. 通过 QVeris MCP 指南连接,在工具目录检查能力,并到 Playground 测试。
Streaming 04

Keep the firehose outside Claude 不要把全量 Tick 流发给 Claude

INGEST

Subscribe narrowly 缩小订阅范围

Request only needed symbols and event types; monitor reconnects and sequence. 只订阅所需标的和事件类型,监控重连与序号。

REDUCE

Validate and aggregate 校验并聚合

Deduplicate, detect out-of-order data, and retain provenance. 去重、识别乱序,并保留来源。

REASON

Send bounded context 发送有限上下文

Send a snapshot or threshold event—not thousands of ticks. 发送快照或阈值事件,而不是数千条 Tick。

Alpaca documents separate SIP, IEX, and delayed SIP feeds. Expose the feed instead of calling everything “live.” Read its stream documentation and FAQ. Alpaca 文档列出 SIP、IEX 和 delayed SIP 等 Feed。应展示 Feed,而不能统称“实时”。参见其流文档FAQ

Acceptance 05

Prove freshness—and honest failure 验证新鲜度与诚实失败

Test 测试 Condition 条件 Required behavior 预期行为
Fresh quote 新鲜报价 Known symbol, valid entitlement 标的明确、授权有效 Show value, currency, exchange, source, session, time 展示数值、币种、交易所、来源、时段和时间
Ambiguous 歧义 Multiple instruments 多个标的 Ask; do not guess 追问,不猜测
Closed 休市 Earlier session 更早时段 Label last trade or close 标注最后成交或收盘
Stale 过期 Age exceeds threshold 超过阈值 Return stale or unavailable 返回过期或不可用
Failure 故障 Timeout, limit, auth 超时、限流、认证 Never fall back to model memory 不退回模型记忆
Source design 06数据源设计 06

Choose the market-data mode from the question根据问题选择行情模式

“Real-time stock market data for Claude” does not mean every workflow needs a continuous stream. Match retrieval to the decision Claude must support.“Claude 实时股票市场数据”并不意味着每个工作流都需要持续数据流。应根据 Claude 要支持的决策选择获取方式。

Intent意图 Best input推荐输入 Disclose披露内容
Current price当前价格 Latest quote or trade snapshot最新 Quote 或 Trade 快照 Value type, feed, time, session数值类型、Feed、时间、时段
Spread alert价差提醒 WebSocket plus rule engineWebSocket 与规则引擎 Trigger, window, event time触发条件、窗口、事件时间
Intraday summary日内总结 Validated intraday bars已校验的日内 Bars Interval, timezone, partial status周期、时区、未完成状态
Historical comparison历史对比 Historical bars with adjustment policy带复权策略的历史 Bars Range, adjustment, missing sessions范围、复权、缺失交易日
TRADE

Last execution最后成交

A completed trade is not necessarily the price available for a new order.已完成成交不一定等于新订单当前可成交价格。

QUOTE

Bid and ask买价与卖价

Claude should name the cited side instead of flattening both into one “stock price.”Claude 应明确引用哪一侧,而不是统称为“股价”。

BAR

Aggregated interval聚合周期

Mark an in-progress OHLCV bar before comparing it with completed periods.将未完成 OHLCV Bar 与完整周期比较前必须明确标注。

Tool definition 07工具定义 07

Give Claude a schema that prevents guessing用 Schema 阻止 Claude 猜测参数

State when the tool is required, what it cannot do, and which ambiguity must be resolved. Application code validates arguments and accesses the provider.明确何时必须调用、不能做什么,以及必须解决哪些歧义。参数校验和 Provider 访问由应用代码负责。

symbolRequired; never infer exchange必填;不得推断交易所
exchangeRequired when ambiguous标的有歧义时必填
modelatest_quote · latest_trade · snapshot
max_age_msApplication freshness threshold应用新鲜度阈值
extended_hoursExplicit session scope明确盘前盘后范围
{ "name": "get_stock_quote", "description": "Read-only current quote. Never places orders. Ask for exchange when ambiguous.", "input_schema": { "type": "object", "properties": { "symbol": { "type": "string" }, "exchange": { "type": "string" }, "mode": { "enum": ["latest_quote", "latest_trade", "snapshot"] } }, "required": ["symbol", "mode"] } }
Explicit result states:明确结果状态: ok, ambiguous_instrument, stale, market_halt, not_entitled, rate_limited, provider_unavailable.
Production controls 08生产控制 08

Control latency, cost, permissions, and licensing控制延迟、成本、权限与许可

Read-only boundary只读边界

Separate data credentials from brokerage credentials. Trading needs another tool, credential, approval path, and audit trail.行情与交易凭证分离。交易需要独立工具、凭证、批准流程和审计。

Freshness budget新鲜度预算

Define acceptable quote age per workflow and reject data beyond it.按工作流定义可接受报价年龄,并拒绝超出阈值的数据。

Cache with provenance带来源缓存

Store provider time, receive time, feed, entitlement, and visible cache age.保存 Provider 时间、接收时间、Feed、授权和可见缓存年龄。

Redistribution rights再分发权

Review terms for end-user display, derived output, storage, and multi-user access.核对终端展示、衍生输出、存储和多用户访问条款。

Observability可观测性

Log sanitized arguments, feed, event time, cache age, latency, and outcome. Redact secrets.记录脱敏参数、Feed、事件时间、缓存年龄、延迟和结果,并隐藏密钥。

Injection resistance抵御提示注入

Treat news as data, not instructions. Accept typed parameters—not retrieved URLs or headers.新闻是数据而非指令。只接受类型明确的参数,不接受检索到的 URL 或请求头。

Troubleshooting 09故障排查 09

Diagnose the data path before changing the prompt先诊断数据链路,再修改提示词

Symptom现象 Likely cause可能原因 Action处理
No tool call未调用工具 Description misses live intent描述未覆盖实时意图 Require the tool for current, latest, bid, ask, and session queries要求当前、最新、买卖价和时段问题调用工具
Different price价格不同 Different feed, field, session, or timeFeed、字段、时段或时间不同 Compare identical instrument, feed, value type, and timestamp统一标的、Feed、数值类型和时间戳
No symbol data代码无数据 OTC entitlement, inactivity, halt, symbol changeOTC 授权、失效、停牌、代码变更 Resolve metadata; never substitute a similar ticker查询元数据,不替换为相似代码
HTTP 403 Credentials, host, or entitlement凭证、Host 或授权 Check auth and label any feed downgrade检查认证并标注 Feed 降级
Old latest event最新事件过旧 Closed, halt, stale connection, delayed feed休市、停牌、连接失效、延迟 Feed Check calendar, connection, feed class, provider time检查日历、连接、Feed 类型和 Provider 时间
Launch playbook 10上线手册 10

Validate the workflow in four passes用四轮验证完成上线准备

Contract tests契约测试

Test valid, ambiguous, inactive, and unsupported symbols; assert evidence fields and timezone parsing.测试有效、歧义、失效和不支持的代码;断言依据字段与时区解析。

Session tests时段测试

Run before open, during regular hours, after close, on holidays, and in extended hours.在盘前、常规时段、收盘后、休市日和盘前盘后测试。

Failure injection故障注入

Simulate timeout, 403, 429, broken stream, stale cache, malformed payload, and out-of-order events.模拟超时、403、429、流中断、缓存过期、响应畸形和事件乱序。

Answer review回答审阅

Verify multiple phrasings return instrument, value type, currency, exchange, session, provider/feed, and time.验证多种表达都返回标的、数值类型、币种、交易所、时段、Provider/Feed 和时间。

Production gate:生产门槛: Distinguish unavailable from numeric zero, and delayed or partial coverage from consolidated real time.区分不可用与数值零,也区分延迟或局部覆盖与聚合实时数据。
Reference 11参考 11

Terms Claude should use preciselyClaude 应准确使用的术语

As-of time

Market observation time, not answer-generation time.市场观测时间,不是回答生成时间。

Feed

Delivery source and coverage class.传输来源和覆盖类型。

Freshness

Measured age and declared delay class.实际年龄与声明延迟类型。

Session

Pre-market, regular, after-hours, or closed.盘前、常规、盘后或休市。

Quote

Bid and ask; different from a completed trade.买价与卖价,不同于已完成成交。

Snapshot

Bounded latest fields at a defined retrieval time.明确获取时间下的最新字段有限视图。

FAQ

Real-time stock data for Claude Claude 实时股票数据常见问题

Does Claude include real-time prices? Claude 自带实时价格吗?

Do not treat Claude as a licensed feed. Connect an external source and return timestamp, feed, and session. 不要把 Claude 当作获得许可的 Feed。应连接外部源并返回时间戳、Feed 和时段。

MCP or Messages API? MCP 还是 Messages API?

Use Messages API in your app; use MCP when a Claude client should discover the capability. 在自有应用中用 Messages API;需要客户端发现能力时用 MCP。

Send every tick? 发送每条 Tick?

No. Aggregate outside the model and send a bounded snapshot. 不需要。在模型外聚合并发送有限快照。