Glanceway Glanceway
所有信息源

Stock Price Monitor

财经

Monitor global stock prices in your menu bar. Displays real-time price, change amount, and change percentage. Powered by Finnhub (free API key required).

@codytseng #stock #finance #market

安装与配置方法

  1. 先在 Mac 上安装并打开 Glanceway,再使用上方的安装链接。
  2. 点击“安装到 Glanceway”。如果浏览器无法唤起应用,下载 .gwsrc 文件并在信息源管理中导入。
  3. 填写下列必填字段并保存,设置刷新间隔,等待首次成功获取。

配置检查

  • FINNHUB_TOKEN — 必填. Free API token from https://finnhub.io 填写自己的访问凭据,不要在截图或公开文件中分享。
  • SYMBOLS — 必填. Stock symbols (e.g. AAPL, TSLA, MSFT) 每个值分别作为一条列表项添加。

信息源逐个向 Finnhub 请求股票代码,并跳过失败或价格为零的响应。覆盖范围与延迟取决于服务权限。股票代码逐项添加;此信息源不执行交易。

配置示例

FINNHUB_TOKEN: <your Finnhub token>
SYMBOLS (list items):
  AAPL
  MSFT

没有显示内容时如何排查

  • 对照当前版本配置表核对字段、列表项和凭据。下方示例不包含可用的真实凭据。
  • 检查网络与上游服务状态。认证失败或速率限制可能导致刷新失败,应根据上游限制调整间隔。
  • 空列表也可能表示没有符合条件的条目。内容和更新时间取决于数据提供方及信息源实现。

配置项

名称 键 类型 必填 默认值 描述
Finnhub API Token FINNHUB_TOKEN secret 是 — Free API token from https://finnhub.io
Stock Symbols SYMBOLS list 是 — Stock symbols (e.g. AAPL, TSLA, MSFT)

源代码

id: codytseng/stock-price
version: 1.1.0
name: Stock Price Monitor
description: |
  Monitor global stock prices in your menu bar.
  Displays real-time price, change amount, and change percentage.
  Powered by Finnhub (free API key required).
author: codytseng
author_url: https://github.com/codytseng
category: Finance
tags:
  - stock
  - finance
  - market

config:
  - key: FINNHUB_TOKEN
    name: Finnhub API Token
    type: secret
    required: true
    description: "Free API token from https://finnhub.io"
  - key: SYMBOLS
    name: Stock Symbols
    type: list
    required: true
    description: "Stock symbols (e.g. AAPL, TSLA, MSFT)"

module.exports = async (api) => {
  const token = api.config.get("FINNHUB_TOKEN");
  const symbolsRaw = api.config.get("SYMBOLS") ?? [];

  async function fetchData() {
    const symbols = symbolsRaw.map((s) => s.toUpperCase());

    if (symbols.length === 0) {
      api.emit([]);
      return;
    }

    const items = [];

    for (const symbol of symbols) {
      const quoteRes = await api.fetch(
        `https://finnhub.io/api/v1/quote?symbol=${symbol}&token=${token}`,
      );

      if (!quoteRes.ok || !quoteRes.json || quoteRes.json.c === 0) {
        api.log("warn", `Failed to fetch quote for ${symbol}`);
        continue;
      }

      const q = quoteRes.json;

      // fetch and cache company name
      let name = api.storage.get(`name:${symbol}`);
      if (!name) {
        const profileRes = await api.fetch(
          `https://finnhub.io/api/v1/stock/profile2?symbol=${symbol}&token=${token}`,
        );
        if (profileRes.ok && profileRes.json?.name) {
          name = profileRes.json.name;
          api.storage.set(`name:${symbol}`, name);
        }
      }

      const price = q.c.toFixed(2);
      const change = q.d.toFixed(2);
      const changePct = q.dp.toFixed(2);
      const arrow = q.d > 0 ? "↑" : q.d < 0 ? "↓" : "";
      const sign = q.d > 0 ? "+" : "";

      items.push({
        id: symbol,
        title: name ? `${name} (${symbol})` : symbol,
        subtitle: `${price} ${arrow} ${sign}${change} (${sign}${changePct}%)`,
        tickerText: `${symbol} ${price} ${sign}${changePct}%`,
        url: `https://finnhub.io/stock/${symbol}`,
      });
    }

    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};
id: codytseng/stock-price
version: 1.0.0
name: Stock Price Monitor
description: |
  Monitor global stock prices in your menu bar.
  Displays real-time price, change amount, and change percentage.
  Powered by Finnhub (free API key required).
author: codytseng
author_url: https://github.com/codytseng
category: Finance
tags:
  - stock
  - finance
  - market

config:
  - key: FINNHUB_TOKEN
    name: Finnhub API Token
    type: secret
    required: true
    description: "Free API token from https://finnhub.io"
  - key: SYMBOLS
    name: Stock Symbols
    type: list
    required: true
    description: "Stock symbols (e.g. AAPL, TSLA, MSFT)"

module.exports = async (api) => {
  const token = api.config.get("FINNHUB_TOKEN");
  const symbolsRaw = api.config.get("SYMBOLS") ?? [];

  async function fetchData() {
    const symbols = symbolsRaw.map((s) => s.toUpperCase());

    if (symbols.length === 0) {
      api.emit([]);
      return;
    }

    const items = [];

    for (const symbol of symbols) {
      const quoteRes = await api.fetch(
        `https://finnhub.io/api/v1/quote?symbol=${symbol}&token=${token}`,
      );

      if (!quoteRes.ok || !quoteRes.json || quoteRes.json.c === 0) {
        api.log("warn", `Failed to fetch quote for ${symbol}`);
        continue;
      }

      const q = quoteRes.json;

      // fetch and cache company name
      let name = api.storage.get(`name:${symbol}`);
      if (!name) {
        const profileRes = await api.fetch(
          `https://finnhub.io/api/v1/stock/profile2?symbol=${symbol}&token=${token}`,
        );
        if (profileRes.ok && profileRes.json?.name) {
          name = profileRes.json.name;
          api.storage.set(`name:${symbol}`, name);
        }
      }

      const price = q.c.toFixed(2);
      const change = q.d.toFixed(2);
      const changePct = q.dp.toFixed(2);
      const arrow = q.d > 0 ? "↑" : q.d < 0 ? "↓" : "";
      const sign = q.d > 0 ? "+" : "";

      items.push({
        id: symbol,
        title: name ? `${name} (${symbol})` : symbol,
        subtitle: `${price} ${arrow} ${sign}${change} (${sign}${changePct}%)`,
        url: `https://finnhub.io/stock/${symbol}`,
      });
    }

    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

相关信息源