网淘吧来吧,欢迎您!

Stock Prices

2026-03-30 新闻来源:网淘吧 围观:11
电脑广告
手机广告

股票价格API技能

本技能帮助您使用股票价格API获取实时市场数据和股票报价。

API端点

基础URLhttps://stock-prices.on99.app

Stock Prices

主要端点/quotes?symbols={SYMBOLS}

快速开始

获取一个或多个股票代码的报价(响应格式为TOON):

curl "https://stock-prices.on99.app/quotes?symbols=NVDA"
curl "https://stock-prices.on99.app/quotes?symbols=AAPL,GOOGL,MSFT"

安装TOON解码器用于解析:pnpm add @toon-format/toon

响应格式

API返回TOON(面向令牌的对象表示法)格式——一种紧凑、人类可读的编码,比JSON少使用约40%的令牌。这使其非常适合LLM提示和流式传输。

TOON响应示例

quotes[1]{symbol,currentPrice,change,percentChange,highPrice,lowPrice,openPrice,previousClosePrice,preMarketPrice,preMarketChange,preMarketTime,preMarketChangePercent,...}:
  NVDA,188.54,-1.5,-0.789308,192.48,188.12,191.405,190.04,191.8799,3.3399048,2026-02-11T13:49:16.000Z,1.771457,...

解码TOON响应

使用@toon-format/toon将响应解析回JavaScript/JSON:

import { decode } from "@toon-format/toon";

const response = await fetch("https://stock-prices.on99.app/quotes?symbols=NVDA");
const toonText = await response.text();
const data = decode(toonText);

// data.quotes is an array of quote objects
const quote = data.quotes[0];
console.log(`${quote.symbol}: $${quote.currentPrice}`);

解码后的结构与JSON匹配——相同的对象、数组和基本类型。

可用数据字段

字段类型描述
symbol字符串股票代码
currentPrice数字当前交易价格
change数字与前一日收盘价相比的价格变动
percentChange数字与前一日收盘价相比的百分比变动
highPrice数字当日最高价
lowPrice数字当日最低价
openPrice数字开盘价
前收盘价数字前一日收盘价
盘前交易价数字盘前交易价格
盘前价格变动数字盘前价格变动
盘前时间字符串(ISO 8601格式)盘前数据时间戳
盘前变动百分比数字盘前百分比变动

使用指南

多只股票

通过逗号分隔股票代码查询多只股票(最多50只):

curl "https://stock-prices.on99.app/quotes?symbols=AAPL,GOOGL,MSFT,TSLA,AMZN"

错误处理

请始终检查响应是否有效。在访问数据前先解码TOON:

import { decode } from "@toon-format/toon";

const response = await fetch("https://stock-prices.on99.app/quotes?symbols=NVDA");
const data = decode(await response.text());

if (data.quotes && data.quotes.length > 0) {
    const quote = data.quotes[0];
    console.log(`${quote.symbol}: $${quote.currentPrice}`);
}

价格分析

计算常用指标

// Determine if stock is up or down
const isUp = quote.change > 0;
const direction = isUp ? "📈" : "📉";

// Calculate day's range percentage
const rangePct = ((quote.highPrice - quote.lowPrice) / quote.lowPrice) * 100;

// Compare current to open
const vsOpen = quote.currentPrice - quote.openPrice;

常见用例

1. 价格监控

import { decode } from "@toon-format/toon";

async function checkPrice(symbol: string) {
    const res = await fetch(`https://stock-prices.on99.app/quotes?symbols=${symbol}`);
    const data = decode(await res.text());
    const quote = data.quotes[0];

    return {
        price: quote.currentPrice,
        change: quote.change,
        changePercent: quote.percentChange,
    };
}

2. 投资组合跟踪

import { decode } from "@toon-format/toon";

async function getPortfolio(symbols: string[]) {
    const symbolString = symbols.join(",");
    const res = await fetch(`https://stock-prices.on99.app/quotes?symbols=${symbolString}`);
    const data = decode(await res.text());

    return data.quotes.map(q => ({
        symbol: q.symbol,
        value: q.currentPrice,
        dailyChange: q.percentChange,
    }));
}

3. 市场概览

import { decode } from "@toon-format/toon";

async function marketSummary(symbols: string[]) {
    const res = await fetch(`https://stock-prices.on99.app/quotes?symbols=${symbols.join(",")}`);
    const data = decode(await res.text());

    const gainers = data.quotes.filter(q => q.change > 0);
    const losers = data.quotes.filter(q => q.change < 0);

    return {
        totalStocks: data.quotes.length,
        gainers: gainers.length,
        losers: losers.length,
        avgChange: data.quotes.reduce((sum, q) => sum + q.percentChange, 0) / data.quotes.length,
    };
}

热门股票代码

科技巨头(FAANG+)

  • AAPL- 苹果公司
  • GOOGL- Alphabet(谷歌)
  • META- Meta(Facebook)
  • AMZN- 亚马逊
  • NFLX- 网飞
  • MSFT- 微软

高关注度股票

  • NVDA- 英伟达
  • TSLA- 特斯拉
  • AMD- 超威半导体
  • 英特尔甲骨文
  • 指数标普500指数

道琼斯指数

  • 纳斯达克指数备注
  • 响应格式API返回TOON格式,而非JSON。请使用
  • decode()来自

@toon-format/toon

  • 进行解析。所有价格均为美元计价交易时段内数据实时更新提供盘前与盘后交易数据时间戳采用ISO 8601格式(协调世界时)单次请求最多支持50个交易代码
  • All prices are in USD
  • Data updates in real-time during market hours
  • Pre-market and after-hours data is available
  • Timestamps are in ISO 8601 format (UTC)
  • Maximum 50 symbols per request

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部
上一篇:Emergency Rescue Kit 下一篇:Nutrient Openclaw

相关文章

您是本站第320403名访客 今日有98篇新文章/评论