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.CompletableFuture<String>refreshAccessTokenβ(OffsetDateTime expiredAt)Gets a newaccess_token.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
-
refreshAccessToken
public CompletableFuture<String> refreshAccessTokenβ(OffsetDateTime expiredAt)
Gets a newaccess_token.This method is only available when using Legacy API Key authentication (i.e.
fromApikey(java.lang.String, java.lang.String, java.lang.String)). It is not supported for OAuth 2.0 mode.- Parameters:
expiredAt- The expiration time of the new access token. Passnullto use the default (90 days from now).- Returns:
- A
CompletableFuturethat resolves to the new access token string. - See Also:
- Refresh Token API
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
-