Longport OpenAPI SDK
    Preparing search index...

    Class Config

    Configuration for Longport SDK

    Index

    Constructors

    Methods

    • Create a new Config using API Key authentication

      Optional environment variables are read automatically (LONGPORT_HTTP_URL, LONGPORT_LANGUAGE, LONGPORT_QUOTE_WS_URL, LONGPORT_TRADE_WS_URL, LONGPORT_ENABLE_OVERNIGHT, LONGPORT_PUSH_CANDLESTICK_MODE, LONGPORT_PRINT_QUOTE_PACKAGES, LONGPORT_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('longport');

      const config = Config.fromApikey(
      process.env.LONGPORT_APP_KEY,
      process.env.LONGPORT_APP_SECRET,
      process.env.LONGPORT_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

      • LONGPORT_LANGUAGE - Language identifier, zh-CN, zh-HK or en (Default: en)
      • LONGPORT_APP_KEY - App key
      • LONGPORT_APP_SECRET - App secret
      • LONGPORT_ACCESS_TOKEN - Access token
      • LONGPORT_HTTP_URL - HTTP endpoint url
      • LONGPORT_QUOTE_WS_URL - Quote websocket endpoint url
      • LONGPORT_TRADE_WS_URL - Trade websocket endpoint url
      • LONGPORT_ENABLE_OVERNIGHT - Enable overnight quote, true or false (Default: false)
      • LONGPORT_PUSH_CANDLESTICK_MODE - realtime or confirmed (Default: realtime)
      • LONGPORT_PRINT_QUOTE_PACKAGES - Print quote packages when connected, true or false (Default: true)
      • LONGPORT_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 (LONGPORT_HTTP_URL, LONGPORT_LANGUAGE, LONGPORT_QUOTE_WS_URL, LONGPORT_TRADE_WS_URL, LONGPORT_ENABLE_OVERNIGHT, LONGPORT_PUSH_CANDLESTICK_MODE, LONGPORT_PRINT_QUOTE_PACKAGES, LONGPORT_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('longport');

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

      This method is only available when using Legacy API Key authentication (i.e. Config.fromApikey). It is not supported for OAuth 2.0 mode.

      Parameters

      • OptionalexpiredAt: Date | null

        The expiration time of the access token, defaults to 90 days from now.

      Returns Promise<string>