Longbridge OpenAPI SDK
    Preparing search index...

    Class Config

    Configuration for Longbridge SDK

    Index

    Constructors

    Methods

    • Create a new Config using API Key authentication

      Optional environment variables are read automatically (LONGBRIDGE_HTTP_URL, LONGBRIDGE_LANGUAGE, LONGBRIDGE_QUOTE_WS_URL, LONGBRIDGE_TRADE_WS_URL, LONGBRIDGE_ENABLE_OVERNIGHT, LONGBRIDGE_PUSH_CANDLESTICK_MODE, LONGBRIDGE_PRINT_QUOTE_PACKAGES, LONGBRIDGE_LOG_PATH). Fields set in extra override the corresponding environment variables.

      Parameters

      • appKey: string

        Application key

      • appSecret: string

        Application secret

      • accessToken: string

        Access token

      • Optionalextra: ExtraConfigParams | null

        Optional extra parameters (override env variables)

      Returns Config

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

      const config = Config.fromApikey(
      process.env.LONGBRIDGE_APP_KEY,
      process.env.LONGBRIDGE_APP_SECRET,
      process.env.LONGBRIDGE_ACCESS_TOKEN,
      );
    • Create a new Config from the environment (API Key authentication)

      It first gets the environment variables from the .env file in the current directory.

      Variables

      • LONGBRIDGE_LANGUAGE - Language identifier, zh-CN, zh-HK or en (Default: en)
      • LONGBRIDGE_APP_KEY - App key
      • LONGBRIDGE_APP_SECRET - App secret
      • LONGBRIDGE_ACCESS_TOKEN - Access token
      • LONGBRIDGE_HTTP_URL - HTTP endpoint url
      • LONGBRIDGE_QUOTE_WS_URL - Quote websocket endpoint url
      • LONGBRIDGE_TRADE_WS_URL - Trade websocket endpoint url
      • 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 - Log file directory (Default: no logs)

      Returns Config

    • Create a new Config for OAuth 2.0 authentication

      OAuth 2.0 is the recommended authentication method that uses Bearer tokens and does not require app_secret or HMAC signatures.

      Optional environment variables are read automatically (LONGBRIDGE_HTTP_URL, LONGBRIDGE_LANGUAGE, LONGBRIDGE_QUOTE_WS_URL, LONGBRIDGE_TRADE_WS_URL, LONGBRIDGE_ENABLE_OVERNIGHT, LONGBRIDGE_PUSH_CANDLESTICK_MODE, LONGBRIDGE_PRINT_QUOTE_PACKAGES, LONGBRIDGE_LOG_PATH). Fields set in extra override the corresponding environment variables.

      Parameters

      • oauth: OAuth

        OAuth handle obtained from OAuth.build(...)

      • Optionalextra: ExtraConfigParams | null

        Optional extra parameters (override env variables)

      Returns Config

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

      const oauth = await OAuth.build('your-client-id', (_, url) => {
      console.log('Open:', url);
      });
      const config = Config.fromOAuth(oauth);