npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

longbridge

v4.1.0

Published

A Node.js library for Longbridge Open API

Readme

Longbridge OpenAPI SDK for Node.js

longbridge provides an easy-to-use interface for invoking Longbridge OpenAPI.

Context Types

| Context | Description | |---------|-------------| | QuoteContext | Real-time quotes, candlesticks, options, warrants, watchlists, push subscriptions | | TradeContext | Orders, positions, account balance, executions, cash flow | | AssetContext | Account statement download | | ContentContext | News, community topics | | FundamentalContext | Financial reports, analyst ratings, dividends, valuation, company overview, shareholders | | MarketContext | Market status, broker holdings, A/H premium, trade statistics, anomaly alerts, index constituents | | CalendarContext | Financial calendar (earnings, dividends, splits, IPOs, macro data, market closures) | | PortfolioContext | Exchange rates, portfolio P&L analysis | | AlertContext | Price alert management (add/enable/disable/delete) | | DCAContext | Dollar-cost averaging plan management | | SharelistContext | Community sharelist management |

Documentation

  • SDK docs: https://longbridge.github.io/openapi/nodejs/index.html
  • Longbridge OpenAPI: https://open.longbridge.com/en/

Examples

Runnable examples live in examples/nodejs/:

  • examples/nodejs/account_asset.js
  • examples/nodejs/http_client.js
  • examples/nodejs/subscribe_candlesticks.js
  • examples/nodejs/subscribe_quote.js
  • examples/nodejs/submit_order.js
  • examples/nodejs/today_orders.js

Quickstart

Install Longbridge OpenAPI SDK

npm install longbridge

Authentication

Longbridge OpenAPI supports two authentication methods:

1. OAuth 2.0 (Recommended)

OAuth 2.0 is the modern authentication method that uses Bearer tokens without requiring HMAC signatures.

Step 1: Register OAuth Client

First, register an OAuth client to get your client_id:

bash / macOS / Linux

curl -X POST https://openapi.longbridge.com/oauth2/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "My Application",
    "redirect_uris": ["http://localhost:60355/callback"],
    "grant_types": ["authorization_code", "refresh_token"]
  }'

PowerShell (Windows)

Invoke-RestMethod -Method Post -Uri https://openapi.longbridge.com/oauth2/register `
  -ContentType "application/json" `
  -Body '{
    "client_name": "My Application",
    "redirect_uris": ["http://localhost:60355/callback"],
    "grant_types": ["authorization_code", "refresh_token"]
  }'

Response:

{
  "client_id": "your-client-id-here",
  "client_secret": null,
  "client_name": "My Application",
  "redirect_uris": ["http://localhost:60355/callback"]
}

Save the client_id for use in your application.

Step 2: Build an OAuth client and create Config

OAuth.build() loads a cached token from ~/.longbridge/openapi/tokens/<client_id> (%USERPROFILE%\.longbridge\openapi\tokens\<client_id> on Windows) if one exists and is still valid, or starts the browser authorization flow automatically. The token is persisted to the same path after a successful authorization or refresh.

const { OAuth, Config } = require('longbridge');

async function main() {
  const oauth = await OAuth.build(
    "your-client-id",
    (_, url) => console.log("Open this URL to authorize: " + url)
  );
  const config = Config.fromOAuth(oauth);
  // Use config to create contexts...
}

main();

2. Legacy API Key (Environment Variables)

Setting environment variables (macOS/Linux)

export LONGBRIDGE_APP_KEY="App Key get from user center"
export LONGBRIDGE_APP_SECRET="App Secret get from user center"
export LONGBRIDGE_ACCESS_TOKEN="Access Token get from user center"

Setting environment variables (Windows)

setx LONGBRIDGE_APP_KEY "App Key get from user center"
setx LONGBRIDGE_APP_SECRET "App Secret get from user center"
setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"

Other environment variables

| Name | Description | |----------------------------------|---------------------------------------------------------------------------------| | LONGBRIDGE_LANGUAGE | Language identifier, zh-CN, zh-HK or en (Default: en) | | LONGBRIDGE_HTTP_URL | HTTP endpoint url (Default: https://openapi.longbridge.com) | | LONGBRIDGE_QUOTE_WS_URL | Quote websocket endpoint url (Default: wss://openapi-quote.longbridge.com/v2) | | LONGBRIDGE_TRADE_WS_URL | Trade websocket endpoint url (Default: wss://openapi-trade.longbridge.com/v2) | | LONGBRIDGE_ENABLE_OVERNIGHT | Enable overnight quote, true or false (Default: false) | | LONGBRIDGE_PUSH_CANDLESTICK_MODE | realtime or confirmed (Default: realtime) | | LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, true or false (Default: true) | | LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: no logs) |

Then create a config from the environment:

const { Config } = require('longbridge');
const config = Config.fromApikeyEnv();

Quote API (Get basic information of securities)

const { OAuth, Config, QuoteContext } = require('longbridge');

async function main() {
  const oauth = await OAuth.build(
    "your-client-id",
    (_, url) => console.log("Open this URL to authorize: " + url)
  );
  const config = Config.fromOAuth(oauth);
  const ctx = QuoteContext.new(config);
  const resp = await ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]);
  for (let obj of resp) {
    console.log(obj.toString());
  }
}

main();

Quote API (Subscribe quotes)

const { OAuth, Config, QuoteContext, SubType } = require('longbridge');

async function main() {
  const oauth = await OAuth.build(
    "your-client-id",
    (_, url) => console.log("Open this URL to authorize: " + url)
  );
  const config = Config.fromOAuth(oauth);
  const ctx = QuoteContext.new(config);
  ctx.setOnQuote((_, event) => console.log(event.toString()));
  await ctx.subscribe(
    ["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"],
    [SubType.Quote],
  );
}

main();

Trade API (Submit order)

const {
  OAuth,
  Config,
  TradeContext,
  Decimal,
  OrderSide,
  TimeInForceType,
  OrderType,
} = require('longbridge');

async function main() {
  const oauth = await OAuth.build(
    "your-client-id",
    (_, url) => console.log("Open this URL to authorize: " + url)
  );
  const config = Config.fromOAuth(oauth);
  const ctx = TradeContext.new(config);
  const resp = await ctx.submitOrder({
    symbol: "700.HK",
    orderType: OrderType.LO,
    side: OrderSide.Buy,
    timeInForce: TimeInForceType.Day,
    submittedPrice: new Decimal("50"),
    submittedQuantity: new Decimal(200),
  });
  console.log(resp.toString());
}

main();

Troubleshooting

  • Windows setx requires a new terminal; use set for the current cmd.exe session.
  • If the script exits, you won't receive push events; keep Node running.
  • For debugging, set LONGBRIDGE_LOG_PATH to enable SDK logs.

License

Licensed under either of

  • Apache License, Version 2.0,(LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.