Glanceway Glanceway
Todas las fuentes

股价监控

Finanzas

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

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

Install and configure this source

  1. Install Glanceway and open it on your Mac before using the install link above.
  2. Choose Install in Glanceway. If the browser cannot open the app, download the .gwsrc file and import it through source management.
  3. Complete the required fields below, save, and choose a refresh interval. Check the source after its first successful fetch.

Configuration checklist

  • STOCK_CODES — Required. 股票代码(例如 600519, 000001, 300750) Add each value as a separate list item.

Use six-digit Shanghai or Shenzhen stock codes and retain leading zeroes. Codes starting with 6 map to Shanghai; others map to Shenzhen. The current source does not implement Hong Kong symbol mapping.

Example settings

STOCK_CODES (list items):
  600519
  000001
  300750

If items are missing

  • Verify the field names, list entries, and credentials against the current version’s configuration table. Sample values below are examples, not active credentials.
  • Check network access and upstream service availability. Authentication failures and rate limits can prevent a refresh; use a slower interval when the provider limits requests.
  • An empty result can also mean there are no matching items. Fetched content and update timing depend on the provider and source implementation.

Configuración

Nombre Clave Tipo Requerido Predeterminado Descripción
股票代码 STOCK_CODES list Sí — 股票代码(例如 600519, 000001, 300750)

Código fuente

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

Fuentes relacionadas