Glanceway Glanceway
所有資料來源

股价监控

財經

在菜单栏实时监控 A 股股价。 显示当前价格、涨跌额和涨跌幅。

@codytseng #stock #finance #china #a-share

安裝與設定方式

  1. 先在 Mac 上安裝並開啟 Glanceway,再使用上方的安裝連結。
  2. 點選「安裝到 Glanceway」。若瀏覽器無法開啟應用程式,下載 .gwsrc 檔案並在資訊源管理中匯入。
  3. 填寫以下必填欄位並儲存,設定更新間隔,等待首次成功取得內容。

設定檢查

  • STOCK_CODES — 必填. 股票代码(例如 600519, 000001, 300750) 每個值分別作為一個清單項目新增。

填寫六位滬深股票代碼並保留開頭的零。以 6 開頭的代碼映射至上海,其餘映射至深圳。目前資訊源未實作港股代碼映射。

設定範例

STOCK_CODES (list items):
  600519
  000001
  300750

沒有顯示內容時如何排查

  • 對照目前版本設定表檢查欄位、清單項目與憑證。下方範例不包含可用的真實憑證。
  • 檢查網路及上游服務狀態。認證失敗或速率限制可能使更新失敗,請依上游限制調整間隔。
  • 空清單也可能代表沒有符合條件的條目。內容與更新時間取決於資料提供方及資訊源實作。

設定項目

名稱 鍵 類型 必填 預設值 描述
股票代码 STOCK_CODES list 是 — 股票代码(例如 600519, 000001, 300750)

原始碼

id: codytseng/cn-stock-price
version: 1.1.0
name: 股价监控
description: |
  在菜单栏实时监控 A 股股价。
  显示当前价格、涨跌额和涨跌幅。
author: codytseng
author_url: https://github.com/codytseng
category: Finance
tags:
  - stock
  - finance
  - china
  - a-share

config:
  - key: STOCK_CODES
    name: 股票代码
    type: list
    required: true
    description: "股票代码(例如 600519, 000001, 300750)"
function toSecId(code) {
  const c = code.trim();
  // Shanghai: starts with 6
  if (c.startsWith("6")) return `1.${c}`;
  // Shenzhen: starts with 0 or 3
  return `0.${c}`;
}

function marketLabel(market) {
  return market === 1 ? "SH" : "SZ";
}

module.exports = async (api) => {
  const codes = api.config.get("STOCK_CODES") ?? [];

  async function fetchData() {
    if (codes.length === 0) {
      api.emit([]);
      return;
    }

    const secIds = codes.map(toSecId).join(",");
    const url = `https://push2.eastmoney.com/api/qt/ulist.np/get?secids=${secIds}&fields=f1,f2,f3,f4,f12,f13,f14`;

    const response = await api.fetch(url);

    if (!response.ok || !response.json?.data?.diff) {
      throw new Error(
        `Failed to fetch stock data (HTTP ${response.status})`,
      );
    }

    const items = response.json.data.diff.map((stock) => {
      const precision = stock.f1;
      const divisor = Math.pow(10, precision);
      const priceVal = stock.f2 / divisor;
      const changeVal = stock.f4 / divisor;
      const changePctVal = stock.f3 / divisor;

      const arrow = changePctVal > 0 ? "↑" : changePctVal < 0 ? "↓" : "";
      const sign = changePctVal > 0 ? "+" : "";
      const ml = marketLabel(stock.f13);

      const price = priceVal.toFixed(precision);
      const change = changeVal.toFixed(precision);
      const changePct = changePctVal.toFixed(2);

      return {
        id: `${ml}${stock.f12}`,
        title: `${stock.f14} (${ml}${stock.f12})`,
        subtitle: `${price} ${arrow} ${sign}${change} (${sign}${changePct}%)`,
        tickerText: `${stock.f14} ${price} ${sign}${changePct}%`,
        url: `https://quote.eastmoney.com/${ml.toLowerCase()}${stock.f12}.html`,
      };
    });

    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};
id: codytseng/cn-stock-price
version: 1.0.0
name: 股价监控
description: |
  在菜单栏实时监控 A 股股价。
  显示当前价格、涨跌额和涨跌幅。
author: codytseng
author_url: https://github.com/codytseng
category: Finance
tags:
  - stock
  - finance
  - china
  - a-share

config:
  - key: STOCK_CODES
    name: 股票代码
    type: list
    required: true
    description: "股票代码(例如 600519, 000001, 300750)"
function toSecId(code) {
  const c = code.trim();
  // Shanghai: starts with 6
  if (c.startsWith("6")) return `1.${c}`;
  // Shenzhen: starts with 0 or 3
  return `0.${c}`;
}

function marketLabel(market) {
  return market === 1 ? "SH" : "SZ";
}

module.exports = async (api) => {
  const codes = api.config.get("STOCK_CODES") ?? [];

  async function fetchData() {
    if (codes.length === 0) {
      api.emit([]);
      return;
    }

    const secIds = codes.map(toSecId).join(",");
    const url = `https://push2.eastmoney.com/api/qt/ulist.np/get?secids=${secIds}&fields=f1,f2,f3,f4,f12,f13,f14`;

    const response = await api.fetch(url);

    if (!response.ok || !response.json?.data?.diff) {
      throw new Error(
        `Failed to fetch stock data (HTTP ${response.status})`,
      );
    }

    const items = response.json.data.diff.map((stock) => {
      const precision = stock.f1;
      const divisor = Math.pow(10, precision);
      const priceVal = stock.f2 / divisor;
      const changeVal = stock.f4 / divisor;
      const changePctVal = stock.f3 / divisor;

      const arrow = changePctVal > 0 ? "↑" : changePctVal < 0 ? "↓" : "";
      const sign = changePctVal > 0 ? "+" : "";
      const ml = marketLabel(stock.f13);

      const price = priceVal.toFixed(precision);
      const change = changeVal.toFixed(precision);
      const changePct = changePctVal.toFixed(2);

      return {
        id: `${ml}${stock.f12}`,
        title: `${stock.f14} (${ml}${stock.f12})`,
        subtitle: `${price} ${arrow} ${sign}${change} (${sign}${changePct}%)`,
        url: `https://quote.eastmoney.com/${ml.toLowerCase()}${stock.f12}.html`,
      };
    });

    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

相關資料來源