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,
  };
};

相關資料來源