Class Config
- java.lang.Object
-
- com.longbridge.Config
-
- All Implemented Interfaces:
AutoCloseable
public class Config extends Object implements AutoCloseable
Configuration options for Longbridge SDK
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ConfigdisablePrintQuotePackages()Disable printing quote packages when connected to the server.ConfigenableOvernight()Enable overnight quote.static ConfigfromApikey(String appKey, String appSecret, String accessToken)Create a newConfigfrom API key credentials.static ConfigfromApikeyEnv()Create a newConfigfrom the given environment variablesstatic ConfigfromOAuth(OAuth oauth)Create a newConfigfor OAuth 2.0 authentication.ConfighttpUrl(String httpUrl)Set the HTTP endpoint URL.Configlanguage(Language language)Set the language identifier.ConfiglogPath(String path)Set the path of the log files.ConfigpushCandlestickMode(PushCandlestickMode mode)Set the push candlestick mode.ConfigquoteWebsocketUrl(String quoteWsUrl)Set the quote websocket endpoint URL.ConfigtradeWebsocketUrl(String tradeWsUrl)Set the trade websocket endpoint URL.
-
-
-
Method Detail
-
fromApikey
public static Config fromApikey(String appKey, String appSecret, String accessToken) throws OpenApiException
Create a newConfigfrom API key credentials.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. Use the chainable setter methods (e.g.httpUrl(java.lang.String)) to override any of these values.- Parameters:
appKey- App keyappSecret- App secretaccessToken- Access token- Returns:
- Config object
- Throws:
OpenApiException- If an error occurs
-
fromApikeyEnv
public static Config fromApikeyEnv() throws OpenApiException
Create a newConfigfrom the given environment variablesIt first gets the environment variables from the .env file in the current directory.
Variables
LONGBRIDGE_LANGUAGE- Language identifier,zh-CN,zh-HKoren(Default:en)LONGBRIDGE_APP_KEY- App keyLONGBRIDGE_APP_SECRET- App secretLONGBRIDGE_ACCESS_TOKEN- Access tokenLONGBRIDGE_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,trueorfalse(Default:false)LONGBRIDGE_PUSH_CANDLESTICK_MODE-realtimeorconfirmed(Default:realtime)LONGBRIDGE_PRINT_QUOTE_PACKAGES- Print quote packages when connected,trueorfalse(Default:true)LONGBRIDGE_LOG_PATH- Set the path of the log files (Default: no logs)
- Returns:
- Config object
- Throws:
OpenApiException- If an error occurs
-
fromOAuth
public static Config fromOAuth(OAuth oauth) throws OpenApiException
Create a newConfigfor OAuth 2.0 authentication.OAuth 2.0 is the recommended authentication method. Obtain an
OAuthinstance viaOAuthBuilder.build(java.util.function.Consumer<java.lang.String>).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. Use the chainable setter methods (e.g.httpUrl(java.lang.String)) to override any of these values.- Parameters:
oauth- OAuth handle returned byOAuthBuilder.build(java.util.function.Consumer<java.lang.String>)- Returns:
- Config object
- Throws:
OpenApiException- If an error occurs
-
httpUrl
public Config httpUrl(String httpUrl)
Set the HTTP endpoint URL.NOTE: Usually you don't need to change it.
- Parameters:
httpUrl- OpenAPI endpoint (Default:https://openapi.longbridge.com)- Returns:
- this object
-
quoteWebsocketUrl
public Config quoteWebsocketUrl(String quoteWsUrl)
Set the quote websocket endpoint URL.NOTE: Usually you don't need to change it.
- Parameters:
quoteWsUrl- OpenAPI quote websocket endpoint- Returns:
- this object
-
tradeWebsocketUrl
public Config tradeWebsocketUrl(String tradeWsUrl)
Set the trade websocket endpoint URL.NOTE: Usually you don't need to change it.
- Parameters:
tradeWsUrl- OpenAPI trade websocket endpoint- Returns:
- this object
-
language
public Config language(Language language)
Set the language identifier.- Parameters:
language- Language identifier (Default:Language.EN)- Returns:
- this object
-
enableOvernight
public Config enableOvernight()
Enable overnight quote.- Returns:
- this object
-
pushCandlestickMode
public Config pushCandlestickMode(PushCandlestickMode mode)
Set the push candlestick mode.- Parameters:
mode- Mode (Default:PushCandlestickMode.Realtime)- Returns:
- this object
-
disablePrintQuotePackages
public Config disablePrintQuotePackages()
Disable printing quote packages when connected to the server.- Returns:
- this object
-
logPath
public Config logPath(String path)
Set the path of the log files.- Parameters:
path- The path of the log files (Default: no logs)- Returns:
- this object
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
-