Stock Data API Guide股票数据 API 指南

Choose a Free Stock Quote API
That Fits Your App
选择适合应用的
免费股票报价 API

Compare freshness, coverage, limits, fields, and licensing before your prototype becomes production infrastructure.

在原型进入生产前,比较数据新鲜度、市场覆盖、
速率限制、报价字段与使用许可。

Hand-drawn workflow for choosing a free stock quote API by freshness, coverage, rate limits, and licensing

TL;DR核心摘要

Best starting point

Use a free tier for prototypes, internal dashboards, coursework, and low-frequency portfolio checks.

“Real-time” varies

Confirm the exchange feed, delay, trading session, and timestamp instead of trusting a marketing label.

Limits matter

Requests per minute, daily quotas, symbol credits, WebSocket access, and caching rules can change the real cost.

Production rule

Validate licensing, redistribution, uptime, and fallback behavior before displaying quotes to end users.

适合起步

免费套餐适合原型、内部看板、课程项目和低频投资组合查询。

“实时”并不统一

不要只看宣传词,要核对交易所数据源、延迟、交易时段和时间戳。

限制决定成本

每分钟请求数、每日配额、按标的计费、WebSocket 权限和缓存规则都会影响真实成本。

生产环境原则

面向终端用户展示报价前,先验证许可、再分发权、稳定性和回退策略。

What a useful stock quote response includes有用的股票报价响应应包含什么

A quote endpoint usually accepts a ticker symbol and returns a JSON object. The minimum useful response identifies the instrument, price, currency, market session, source timestamp, and whether the value is delayed.

报价端点通常接收股票代码并返回 JSON 对象。最少应包含标的、价格、币种、交易时段、数据源时间戳,以及报价是否延迟。

Identity and venue

Return symbol, company or instrument name, exchange, asset type, and currency so similarly named instruments are not mixed.

Price and change

Include last price, absolute change, percentage change, previous close, open, high, low, and volume where available.

Timestamp and freshness

Store the provider timestamp and timezone. Mark delayed, end-of-day, pre-market, and after-hours values explicitly.

Errors and entitlement

Handle unknown symbols, closed markets, throttling, expired keys, and fields unavailable under the free plan.

标的与交易场所

返回股票代码、名称、交易所、资产类型和币种,避免混淆相似标的。

价格与涨跌

尽可能包含最新价、涨跌额、涨跌幅、昨收、开盘、最高、最低和成交量。

时间戳与新鲜度

保存服务商时间戳和时区,并明确标注延迟、日终、盘前与盘后数据。

错误与权限

处理无效代码、休市、限流、密钥过期,以及免费套餐中不可用的字段。

Quote, trade, last price, and bar are not synonyms报价、成交、最新价和 K 线不是同义词

A quote normally describes displayed buying and selling interest: bid price, bid size, ask price, and ask size. A trade records an executed transaction. “Last price” is often the latest eligible trade selected by the provider, while an OHLCV bar aggregates eligible events over an interval. A snapshot may package fields from several of these records, and those fields may not share one timestamp. Ask the provider exactly which event populates each field before using a response for an alert, spread calculation, chart, or execution decision.

报价通常表示公开显示的买卖意愿,包括买价、买量、卖价和卖量;成交记录实际执行的交易。“最新价”通常是供应商按规则选择的最近一笔有效成交,而 OHLCV K 线是对某个周期内符合条件的事件进行聚合。快照可能把多类记录的字段组合在一起,而且这些字段不一定对应同一时间。把响应用于提醒、价差计算、图表或交易决策前,必须确认每个字段究竟由什么事件产生。

Field字段What it should mean应表达的含义Required metadata必要元数据Validation test验证方法
bid / askDisplayed buying and selling prices, ideally with sizes.公开显示的买卖价格,最好同时包含数量。Venue or consolidated indicator, size, event time, and condition.交易场所或综合标识、数量、事件时间和条件。Confirm bid does not exceed ask except during defined crossed-market conditions.除明确的交叉市场情形外,检查买价不应高于卖价。
lastMost recent trade that satisfies the provider’s eligibility rules.符合供应商有效性规则的最近一笔成交。Trade venue, condition, size, correction status, and event time.成交场所、条件、数量、更正状态和事件时间。Compare with a known liquid symbol during regular and extended sessions.在常规与延长交易时段用高流动性标的交叉检查。
previous closePrior session’s official or provider-defined close.上一交易时段的官方或供应商定义收盘价。Session, calendar, adjustment status, and corporate-action treatment.交易时段、日历、复权状态和公司行动处理。Test a date after a split or dividend and inspect the change calculation.检查拆股或分红后的日期以及涨跌计算。
timestampTime of the market event—not merely the API response time.市场事件发生时间,而不只是 API 返回时间。Timezone, event/receipt distinction, precision, and delay label.时区、事件时间与接收时间的区别、精度和延迟标记。Measure event age at receipt and reject impossible future timestamps.计算数据到达时已经延迟了多久,并拒绝不合理的未来时间戳。

Real-time, delayed, and extended-hours quotes实时、延迟与盘前盘后报价

“Real-time” is not a complete specification. A feed may cover one venue rather than the consolidated market, exclude certain trade conditions, update only selected symbols, or deliver a current last trade without a current bid and ask. A delayed feed can be useful for education and low-frequency research, but its user interface must not imply that the value is live. Store the provider’s delay classification and calculate the age of every event from its source timestamp.

“实时”并不是完整规格。数据流可能只覆盖单一交易场所,而不是全市场综合行情;也可能排除部分成交条件、只更新特定标的,或提供最新成交价却没有同步的买卖报价。延迟数据适合教学和低频研究,但界面不能让用户误以为它是实时行情。应保存供应商的延迟分类,并依据来源时间戳计算每条数据的实际时效。

Regular session

Define the exchange calendar and timezone, not only a fixed clock range. Holidays, early closes, halts, and daylight-saving transitions alter expected behavior.

Pre-market and after-hours

Extended sessions often have lower liquidity, wider spreads, and different eligible venues. Label the session and avoid combining it with the regular-session close.

Closed, halted, or stale

A valid endpoint can return an old last trade when the market is closed or a symbol is halted. Show market state and source time instead of treating unchanged data as an outage.

Entitlement and display

Exchange licenses may distinguish personal use, internal calculations, public display, redistribution, and non-display automated use. API access alone does not grant every right.

常规交易时段

应定义交易所日历和时区,而不只是固定钟点。节假日、提前收盘、停牌和夏令时切换都会改变预期行为。

盘前与盘后

延长交易时段通常流动性较低、价差较大,可用场所也可能不同。必须标记时段,不要把它与常规时段收盘价混为一谈。

休市、停牌或陈旧

休市或停牌时,正常端点也可能返回较旧的最后成交。应显示市场状态和来源时间,而不是把价格不变直接认定为故障。

数据权限与展示

交易所许可可能区分个人使用、内部计算、公开展示、再分发和非展示自动化用途。能够调用 API 并不自动获得全部权利。

Compare free stock quote API options比较免费股票报价 API 方案

Option方案Typical strength常见优势Best for适合场景Verify first优先核对
Alpha VantageBroad stocks, fundamentals, FX, crypto, and indicators.股票、基本面、外汇、加密资产和技术指标覆盖广。Learning and low-frequency prototypes.学习和低频原型。Daily quota and real-time entitlement.每日配额与实时权限。
Financial Modeling PrepNormalized quote, history, company, statement, and corporate-action endpoints.标准化行情、历史、公司、财报和公司行动端点。Apps combining prices with company context.需要同时使用价格与公司上下文的应用。Current plan coverage, quote delay, exchange scope, and commercial rights.当前套餐覆盖、报价延迟、交易所范围与商用权利。
Massive / Polygon.ioDetailed U.S. trades, quotes, aggregates, snapshots, and reference records.详细的美国成交、报价、聚合行情、快照和参考记录。Market-data applications needing event-level context.需要事件级上下文的市场数据应用。Plan entitlement, SIP versus venue coverage, recency, and display rights.套餐权限、SIP 与场所覆盖、时效和展示权。
Broker market data券商市场数据Quotes integrated with paper or live trading workflows.报价与模拟或实盘交易流程集成。Trading apps already tied to a broker.已接入券商的交易应用。Account, feed, region, and redistribution rules.账户、数据源、地区与再分发规则。

Alpha Vantage currently says the majority of its free datasets allow up to 25 requests per day and that real-time and 15-minute delayed U.S. market data are premium-only. FMP requires an API key for all documented requests. Massive documents U.S. stock data sourced through exchanges, securities information processors, FINRA facilities, and OTC markets, while actual access depends on plan and entitlement. These facts can change, so record the date you verified a plan instead of copying an old comparison table into production requirements.

Alpha Vantage 目前说明,大多数免费数据集每天最多调用 25 次,而美国市场实时和 15 分钟延迟数据属于付费能力。FMP 文档中的请求均要求 API Key。Massive 的文档说明,其美国股票数据来自交易所、证券信息处理机构、FINRA 设施和 OTC 市场,实际可访问的数据取决于套餐和授权。这些信息可能变化,因此应记录核验套餐的日期,不能把旧对比表直接当成生产规格。

Build checklist: from first request to production从首次请求到生产的接入检查

1. Test one liquid symbol

Request AAPL or another liquid listing during and outside market hours. Compare the response timestamp with the provider documentation.

2. Normalize your schema

Map provider-specific fields into your own quote model so you can change providers without rewriting the UI.

3. Cache intentionally

Choose a TTL that matches the promised freshness. Never present cached data as live, and follow redistribution restrictions.

4. Design for limits

Batch symbols where supported, back off after 429 responses, log quota usage, and define a stale-data state before launch.

1. 用高流动性标的测试

在盘中和盘外请求 AAPL 等高流动性标的,并把响应时间戳与服务商文档对照。

2. 统一内部数据模型

把服务商特有字段映射到自己的报价模型,未来更换服务商时无需重写 UI。

3. 有意设计缓存

根据产品承诺的数据时效设置 TTL,不要把缓存数据标成实时,并遵守再分发限制。

4. 围绕限额设计

如果供应商支持,应批量查询多个标的;遇到 429 后退避重试,记录配额用量,并在上线前定义陈旧数据的处理方式。

Make a real FMP quote request发起一个真实的 FMP 报价请求

FMP documents the stable quote endpoint below and requires an API key. The validation is intentionally strict: an HTTP 200 response is not enough if the body is empty, changes shape, or lacks the expected symbol and price. Keep the API key in an environment variable rather than source code.

FMP 文档提供了下面的稳定版报价端点,并要求 API Key。示例会进行严格验证:即使 HTTP 返回 200,如果响应为空、结构变化或缺少预期的股票代码与价格,也不能视为成功。API Key 应保存在环境变量中,而不是写进源代码。

import os
import requests

response = requests.get(
    "https://financialmodelingprep.com/stable/quote",
    params={
        "symbol": "AAPL",
        "apikey": os.environ["FMP_API_KEY"],
    },
    timeout=20,
)
response.raise_for_status()
payload = response.json()

if not isinstance(payload, list) or not payload:
    raise RuntimeError(f"Unexpected quote response: {payload!r}")

quote = payload[0]
if quote.get("symbol") != "AAPL" or quote.get("price") is None:
    raise RuntimeError(f"Missing required fields: {quote!r}")

normalized = {
    "symbol": quote["symbol"],
    "last_price": float(quote["price"]),
    "provider": "Financial Modeling Prep",
    "retrieved_at": response.headers.get("Date"),
}

The provider response may expose additional timestamps or fields depending on the endpoint and plan; preserve the raw payload and map only documented fields. Do not substitute the HTTP Date header for market event time—it is only a fallback retrieval marker in this small example. Production code should use the provider’s source timestamp where available, record timezone and delay, and compare the result with a second source during onboarding.

供应商响应可能根据端点和套餐包含额外时间戳或字段;应保留原始响应,只映射文档明确说明的字段。这个小示例中的 HTTP Date 只能作为获取时间标记,不能替代市场事件时间。生产代码应优先使用供应商提供的来源时间戳,记录时区与延迟,并在接入阶段与第二来源交叉验证。

Design a resilient stock quote service设计可靠的股票报价服务

A production quote service should separate provider access from the application-facing model. The adapter authenticates, calls the endpoint, retains the raw response, and maps fields. The validation layer checks identity, numeric ranges, timestamps, session state, and staleness. A cache protects quotas and absorbs short provider interruptions. The delivery layer returns the normalized quote together with source, delay, market state, and last successful update so the UI can communicate uncertainty instead of showing a plausible but stale number.

生产报价服务应把供应商接入与面向应用的数据模型分离。适配器负责认证、调用端点、保留原始响应和映射字段;验证层检查标的身份、数值范围、时间戳、交易状态与陈旧程度;缓存保护配额并吸收短时供应商中断;交付层返回标准化报价,同时带上来源、延迟、市场状态和最后成功更新时间,让界面能够表达不确定性,而不是展示一个看似合理但已经过期的数字。

Rate limits and retries

Track quota at the same scope the provider enforces. Retry only temporary failures, respect 429 guidance, add jitter, and never multiply traffic with uncontrolled client retries.

Cache with truthful freshness

Set TTL by product promise and market state. Return “stale” or “last updated” metadata with cached values; do not label a cached quote real-time.

Fallback without mixing definitions

A secondary provider may define last, close, session, and adjusted values differently. Normalize explicitly and surface source changes rather than silently swapping numbers.

Monitor schemas and data age

Alert on missing required fields, type changes, empty responses, future timestamps, abnormal event age, repeated values during an open session, and coverage loss.

限额与重试

按照供应商实际采用的计费与限额口径跟踪配额。只重试临时故障,遵守 429 提示并加入随机退避,避免客户端不受控制的重试放大流量。

如实表达缓存新鲜度

根据产品承诺和市场状态设置 TTL。缓存值应带“已陈旧”或“最后更新”信息,不能把缓存报价标成实时。

回退时不要混淆定义

备用供应商对最新价、收盘价、交易时段和复权值的定义可能不同。应明确标准化并显示来源变化,而不是悄悄替换数字。

监控字段结构与数据时效

对必要字段缺失、类型变化、空响应、未来时间戳、数据延迟异常、开市期间长时间不变以及覆盖范围下降设置告警。

REST polling or WebSocket streaming?选择 REST 轮询还是 WebSocket 推送?

REST is usually simpler for occasional symbol lookups, scheduled portfolio checks, server-rendered pages, and low-frequency agents. WebSockets fit continuously updating watchlists or event-driven systems, but require connection recovery, subscription state, sequence handling, heartbeats, backpressure, and entitlement monitoring. Polling a REST quote every second does not automatically reproduce a licensed real-time stream; it can exhaust quotas while still missing intermediate events.

REST 更适合偶尔查询标的、定时检查投资组合、服务端渲染页面和低频 Agent。WebSocket 适合持续刷新的自选列表或事件驱动系统,但需要处理连接恢复、订阅状态、序列号、心跳、消息积压和权限监控。每秒轮询一次 REST 报价并不等于获得了合规的实时数据流,它可能既耗尽配额,又遗漏中间事件。

When to use QVeris for stock quote APIs何时使用 QVeris 查找股票报价 API

Use QVeris when an AI agent or developer workflow must discover, inspect, and call financial-data capabilities without hardcoding one provider too early.

当 AI Agent 或开发工作流需要发现、检查和调用金融数据能力,又不希望过早写死单一服务商时,可以使用 QVeris。

  • Search for quote, historical-price, fundamentals, and market-status capabilities in one place.
  • Inspect capability inputs and outputs before wiring them into an agent.
  • Keep provider choice flexible while maintaining auditable tool calls.
  • 在一个入口搜索报价、历史价格、基本面和市场状态能力。
  • 接入 Agent 前检查能力的输入与输出。
  • 保持服务商选择灵活,同时保留可审计的工具调用。

A useful QVeris request should state more than “get a stock price.” Include the security identifier and exchange when known, required fields, acceptable delay, regular or extended session, currency, intended use, and maximum staleness. Inspect the discovered capability before calling it: verify whether the output is a quote, trade, aggregate, or snapshot; which provider supplies it; what authentication it needs; and whether timestamps and provenance are returned. This prevents an agent from selecting a convenient endpoint whose data definition does not match the decision.

有效的 QVeris 请求不能只写“获取股票价格”。应尽量提供证券标识与交易所、必要字段、可接受延迟、常规或延长交易时段、币种、使用目的和最大陈旧时间。调用前先检查发现的能力:确认输出属于报价、成交、聚合 K 线还是快照,数据由哪家供应商提供,需要什么认证,以及是否返回时间戳与来源。这样可以避免 Agent 选择调用方便、但数据定义与决策不匹配的端点。

After the call, keep the tool name, provider, input parameters, raw response, retrieval time, normalized output, and validation result together. If a second call returns a materially different price, compare event time, venue, session, delay, and field definition before declaring one source wrong. QVeris supports capability discovery and auditable routing; it does not provide exchange entitlements, override provider licenses, or guarantee that a quote is suitable for execution, compliance, or customer display.

调用完成后,应把工具名称、供应商、输入参数、原始响应、获取时间、标准化结果和验证结论一起保存。如果第二个来源返回明显不同的价格,应先比较事件时间、交易场所、交易时段、延迟和字段定义,再判断某个来源是否错误。QVeris 可以帮助查找能力,并保留可审计的调用记录,但不会提供交易所数据权限,也不能取代供应商许可;它也不保证某个报价适合交易执行、合规或面向客户展示。

FAQ常见问题

Is there a completely free real-time stock quote API?

Free access usually has limits on symbols, exchanges, request volume, licensing, or real-time entitlements. Check the current plan before building.

Can I use free quotes in a commercial app?

Not automatically. Provider terms and exchange rules may restrict display, caching, redistribution, or commercial use.

REST or WebSocket?

REST fits occasional lookups. WebSockets fit continuously updating screens, but free tiers often restrict streams or symbol counts.

How do I detect delayed data?

Compare the source timestamp with the market clock, read the feed entitlement, and show a visible delayed or stale label in the UI.

Why do two stock quote APIs show different prices?

They may use different venues, eligible trade conditions, sessions, delays, timestamps, or definitions of “last.” Compare those fields before treating either value as incorrect.

Should I cache stock quotes?

Yes, when the provider license permits it and the product can tolerate the resulting age. Set TTL by market state, retain the source timestamp, and clearly label stale values.

有完全免费的实时股票报价 API 吗?

免费访问通常会限制标的、交易所、请求量、许可或实时权限,接入前应核对最新方案。

免费报价能用于商业应用吗?

不一定。服务商条款和交易所规则可能限制展示、缓存、再分发或商业使用。

REST 还是 WebSocket?

REST 适合偶尔查询;WebSocket 适合持续刷新,但免费套餐通常会限制连接数或标的数量。

如何识别延迟数据?

比较数据源时间戳与市场时间,核对数据权限,并在 UI 中明确标注延迟或陈旧状态。

为什么两个报价 API 显示的价格不同?

它们可能使用不同交易场所、有效成交条件、交易时段、延迟、时间戳或“最新价”定义。判断错误前应先比较这些字段。

股票报价应该缓存吗?

如果供应商许可允许,并且产品能够接受相应的数据延迟,就可以缓存。TTL 应根据市场状态设置,同时保留来源时间戳,并明确标注已经陈旧的报价。

External references外部参考链接