client-js

massive-comMIT活跃维护

Massive.com 官方 JavaScript 客户端库,封装 REST 与 WebSocket 接口,省去手写请求和连接管理,直接调用行情数据。

The official JS client library for the Massive.com REST and WebSocket API.

v10.8.0发布于 2026-09-17 17:03 UTC272star75fork同步于 2026-11-10 12:03 UTC

怎么上手

由 README 提炼,执行前请确认
npm install --save '@massive.com/client-js'
硬件要求按 README 说明

README 未说明,纯 JS 客户端,无 GPU 或显存要求

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Massive.com 官方 JS 客户端,封装 REST 与 WebSocket 行情接口

Massive.com 官方 JavaScript 客户端库,封装 REST 与 WebSocket 接口,省去手写请求和连接管理,直接调用行情数据。

核心能力

  • 用 restClient 一行初始化并调用行情接口
  • 支持 getStocksAggregates 等聚合、快照、最新成交查询
  • 开启 pagination 自动递归拉取 next_url 分页
  • websocketClient 订阅股票实时与延迟行情
  • src/rest 由 OpenAPI 规范自动生成,接口随规范更新

容易踩的坑

需要自备 Massive API key,并设置 MASSIVE_API_KEY 环境变量;WebSocket 示例使用 wss://delayed.massive.com,实时行情需换对应地址;从源码构建需 Node.js 18+ 和 JDK 17+,否则用 Docker 方案

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v10.8.0
  1. v10.8.0最新正式版2026-09-17 · 2026-09-17 17:03 UTC

    What's Changed

    Breaking Changes

    • conditions, sequence_number and sip_timestamp on GetOptionsV3TradesTicker200ResponseResultsInner are now optional. Code assigning them straight to a non-optional type will need a guard.

    Bug Fixes

    • Fixed the TypeScript build under axios 1.19 and later. axios began defaulting a generic to a non-exported unique symbol, which broke declaration emit with TS2527 and left the package unable to produce type definitions.
    • Dependency updates: axios, ws, form-data, follow-redirects, js-yaml, brace-expansion, serialize-javascript, undici, shell-quote and the openapi-generator CLI.

    New Contributors

    Full Changelog: https://github.com/massive-com/client-js/compare/v10.7.0...v10.8.0

  2. v10.7.02026-04-27 · 2026-04-27 14:25 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/massive-com/client-js/compare/v10.6.0...v10.7.0

  3. v10.6.02026-04-07 · 2026-04-07 11:04 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/massive-com/client-js/compare/v10.5.0...v10.6.0

  4. v10.5.02026-03-03 · 2026-03-03 14:10 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/massive-com/client-js/compare/v10.4.0...v10.5.0

  5. v10.4.02026-02-24 · 2026-02-24 23:57 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/massive-com/client-js/compare/v10.3.0...v10.4.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Massive JS Client

    code style: prettier

    Welcome to the official JS client library for the Massive REST and WebSocket API. To get started, please see the Getting Started section in our documentation, view the examples directory for code snippets, or the blog post with video tutorials to learn more. To generate the package documentation please run npm run generate-doc.

    For upgrade instructions please see the Release Notes.

    Note: Polygon.io has rebranded as Massive.com on Oct 30, 2025. Existing API keys, accounts, and integrations continue to work exactly as before. The only change in this SDK is that it now defaults to the new API base at api.massive.com, while api.polygon.io remains supported for an extended period.

    For details, see our rebrand announcement blog post or open an issue / contact [email protected] if you have questions.

    Getting the client

    To get started, you'll need to install the client library:

    npm install --save '@massive.com/client-js'
    

    Next, create a new client with your API key.

    import { restClient } from '@massive.com/client-js';
    const rest = restClient(process.env.MASSIVE_API_KEY);
    

    AI tools

    Coding with Claude, Cursor, ChatGPT, or another AI assistant? Give it direct access to Massive data and docs:

    • MCP server: connect your MCP client to the hosted server at https://mcp.massive.com/. See the AI Tools quickstart for setup in each client.
    • llms.txt: point your agent at https://massive.com/docs/llms.txt for an LLM-friendly index of the Massive docs.
    • Skills plugin: install the Massive plugin from massive-com/ai to teach your assistant how to use the API correctly: hosts, auth, entitlements, and accurate historical data. In Claude Code, run /plugin marketplace add massive-com/ai, then /plugin install massive@massive-plugins.

    Using the client

    After creating the client, making calls to the Massive API is easy. For example, here's a complete example on how to get aggregates (bars):

    import { restClient } from '@massive.com/client-js';
    
    const apiKey = "XXXX";
    const rest = restClient(apiKey, 'https://api.massive.com');
    
    async function example_getStocksAggregates() {
      try {
        const response = await rest.getStocksAggregates(
          {
            stocksTicker: "AAPL",
            multiplier: "1",
            timespan: "day",
            from: "2025-11-01",
            to: "2025-11-30",
            adjusted: "true",
            sort: "asc",
            limit: "120"
          }
        );
        console.log('Response:', response);
      } catch (e) {
        console.error('An error happened:', e);
      }
    }
    
    example_getStocksAggregates();
    

    Or, maybe you want to get the last trades or quotes for a ticker:

    import { restClient } from '@massive.com/client-js';
    
    const apiKey = "XXXX";
    const rest = restClient(apiKey, 'https://api.massive.com');
    
    async function example_getLastStocksTrade() {
      try {
        const response = await rest.getLastStocksTrade("AAPL");
        console.log('Response:', response);
      } catch (e) {
        console.error('An error happened:', e);
      }
    }
    
    example_getLastStocksTrade();
    
    import { restClient } from '@massive.com/client-js';
    
    const apiKey = "XXXXX";
    const rest = restClient(apiKey, 'https://api.massive.com');
    
    async function example_getLastStocksQuote() {
      try {
        const response = await rest.getLastStocksQuote("AAPL");
        console.log('Response:', response);
      } catch (e) {
        console.error('An error happened:', e);
      }
    }
    
    example_getLastStocksQuote();
    

    Finally, maybe you want a snapshot of a ticker:

    import { restClient } from '@massive.com/client-js';
    
    const apiKey = "XXXXX";
    const rest = restClient(apiKey, 'https://api.massive.com');
    
    async function example_getStocksSnapshotTicker() {
      try {
        const response = await rest.getStocksSnapshotTicker("AAPL");
        console.log('Response:', response);
      } catch (e) {
        console.error('An error happened:', e);
      }
    }
    
    example_getStocksSnapshotTicker();
    

    See full examples for more details on how to use this client effectively.

    Pagination

    The client can handle pagination for you through the globalFetchOptions by turning on the pagination: true option. The feature will automatically fetch all next_url pages of data when the API response indicates more data is available.

    import { restClient } from '@massive.com/client-js';
    
    const globalFetchOptions = {
    	pagination: true,
    };
    const rest = restClient(process.env.MASSIVE_API_KEY, "https://api.massive.com", globalFetchOptions);
    
    rest.getStocksAggregates({
      stocksTicker: "AAPL",
      multiplier: "1",
      timespan: "day",
      from: "2025-11-01",
      to: "2025-11-30"
    }).then((response) => {
    	const data = response.data; // convert axios-wrapped response
    	const resultCount = data.resultsCount;
    	console.log("Result count:", resultCount);
    }).catch(e => {
    	console.error('An error happened:', e);
    });
    

    If there is a next_url field in the API response, the client will recursively fetch the next page for you, and then pass along the accumulated data.

    WebSocket Client

    Import the Websocket client and models packages to get started. You can get preauthenticated websocket clients for the 3 topics.

    import { websocketClient } from "@massive.com/client-js";
    const stocksWS = websocketClient(process.env.MASSIVE_API_KEY, 'wss://delayed.massive.com').stocks();
    
    stocksWS.onmessage = ({response}) => {
      const [message] = JSON.parse(response);
    
      stocksWS.send('{"action":"subscribe", "params":"AM.MSFT,A.MSFT"}');
    
      switch (message.ev) {
        case "AM":
          // your trade message handler
          break;
        case "A":
          // your trade message handler
          break;
      }
    };
    
    stocksWS.send({ action: "subscribe", params: "T.MSFT" });
    

    See full examples for more details on how to use this client effectively.

    Developing the client

    Most users only need the published npm package above. This section is for contributors who want to build the client from source or regenerate it from the OpenAPI spec.

    How the code is organized

    • Generated — src/rest/ is generated from the OpenAPI spec by openapi-generator (typescript-axios). Do not edit it by hand; it is overwritten on every regeneration.
    • Hand-written — src/main.ts (the restClient / MassiveClient glue and auto-pagination) and the entire WebSocket client under src/websockets/. These are never touched by regeneration.
    • Committed spec — src/openapi.json is the filtered spec the client is generated from, committed so spec changes are visible in diffs.

    Prerequisites

    • Node.js 18+ (CI uses 22)
    • A JDK 17+ on your PATH — the typescript-axios generator is a Java tool. No local JDK? Use the Docker recipe below.

    Clone, build, and verify

    git clone [email protected]:massive-com/client-js.git
    cd client-js
    npm ci
    
    # Pulls the latest spec, regenerates src/rest, and bundles to dist/
    npm run build
    

    If you don't have a JDK locally, build inside a container that has both Node and Java (the generator needs Java):

    docker run --rm -it -v "$(pwd)":/app -w /app node:22-bookworm sh -c \
      "apt-get update && apt-get install -y openjdk-17-jre-headless && npm ci && npm run build"
    

    Verify the build produced a working client with a runnable REST example. Save this as verify.mjs in the repo root and run MASSIVE_API_KEY=your_key node verify.mjs:

    import { restClient } from './dist/main.js';
    
    const rest = restClient(process.env.MASSIVE_API_KEY, 'https://api.massive.com');
    
    const response = await rest.getStocksAggregates({
      stocksTicker: 'AAPL',
      multiplier: '1',
      timespan: 'day',
      from: '2023-01-09',
      to: '2023-02-10',
      adjusted: 'true',
      sort: 'asc',
      limit: '120',
    });
    console.log('Aggregates results:', response.results?.length);
    

    And a runnable WebSocket example (MASSIVE_API_KEY=your_key node ws-verify.mjs):

    import { websocketClient } from './dist/main.js';
    
    const stocksWS = websocketClient(process.env.MASSIVE_API_KEY, 'wss://delayed.massive.com').stocks();
    
    stocksWS.onopen = () => stocksWS.send('{"action":"subscribe","params":"AM.MSFT"}');
    stocksWS.onmessage = ({ data }) => {
      const messages = JSON.parse(data);
      for (const message of messages) console.log('WS message:', message);
    };
    stocksWS.onerror = (e) => console.error('WS error:', e);
    

    Regenerating from the spec

    Regeneration is a single command that pulls the latest spec, runs the generator, and leaves src/rest/ deterministic (hand-written code untouched):

    npm run generate      # runs scripts/generate.sh: pull spec -> generate -> gate
    

    The generator version is pinned in openapitools.json (currently 7.21.0) so diffs reflect spec changes, not generator upgrades. Spec filtering and the operation-id → method-name mapping live in scripts/pull_spec.js and scripts/operation-mappings.js.

    Automated daily sync

    .github/workflows/sync-openapi.yml runs every day (and on manual dispatch). It:

    1. Pulls the latest spec from https://api.massive.com/openapi and regenerates the client with scripts/generate.sh.
    2. Opens a brand-new PR (bot/openapi-sync-<date>-<run-id> → master, [bot]-prefixed title) only when the regenerated output differs from what's committed — no diff, no PR. The commit is GPG-signed as the bot identity and a Slack notification is posted.

    Required repo secrets: GPG_PRIVATE_KEY, SLACK_CLIENT_LIBRARY_WEBHOOK (GITHUB_TOKEN is provided automatically). Every run opens a new PR and never reuses an existing one, so the reviewer always differs from the author.

    Contributing

    If you found a bug or have an idea for a new feature, please first discuss it with us by submitting a new issue. We will respond to issues within at most 3 weeks. We're also open to volunteers if you want to submit a PR for any open issues but please discuss it with us beforehand. PRs that aren't linked to an existing issue or discussed with us ahead of time will generally be declined. If you have more general feedback or want to discuss using this client with other users, feel free to reach out on our Slack channel.

    If you use an AI coding agent to work on this repo, it should read AGENTS.md, which covers the project layout, build and test commands, and which files are generated.