Class AlpacaHttpConfig
defaultClient() returns a shared singleton — OkHttp instances hold a thread pool and
a connection pool and should be shared across the application when the same transport policy is
appropriate. Pass the result directly to AlpacaClientFactory, or use defaultBuilder() to create a customised instance for a specific API, credential set, timeout
profile, proxy, retry interceptor, logging policy, or connection pool.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic okhttp3.OkHttpClient.BuilderReturns a pre-configured builder so callers can add their own interceptors, certificates, retry/backoff policies, or other customisations before callingbuild().static okhttp3.OkHttpClientReturns the shared singletonOkHttpClientwith Alpaca defaults (no logging).static okhttp3.OkHttpClientloggingClient(okhttp3.logging.HttpLoggingInterceptor.Level level) Returns an OkHttpClient with HTTP-level request/response logging at the given level, writing to the platform logger (java.util.logging).static okhttp3.OkHttpClientloggingClient(okhttp3.logging.HttpLoggingInterceptor.Level level, okhttp3.logging.HttpLoggingInterceptor.Logger logger) Returns an OkHttpClient with HTTP-level request/response logging at the given level, writing to a caller-suppliedHttpLoggingInterceptor.Logger.static okhttp3.OkHttpClientReturns an OkHttp client with default timeouts and the default Alpaca retry policy.static okhttp3.OkHttpClientretryingClient(AlpacaRetryPolicy policy) Returns an OkHttp client with default timeouts and the supplied Alpaca retry policy.static okhttp3.OkHttpClientwithAgentInformation(okhttp3.OkHttpClient httpClient) Returns an HTTP client that identifies this SDK and its version in theUser-Agentheader usingAPCA-JAVA/<sdk-version> Java/<runtime-version>.
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT
-
DEFAULT_READ_TIMEOUT
-
DEFAULT_WRITE_TIMEOUT
-
-
Method Details
-
defaultClient
public static okhttp3.OkHttpClient defaultClient()Returns the shared singletonOkHttpClientwith Alpaca defaults (no logging). UsedefaultBuilder()if you need a distinct instance with different timeouts, interceptors, retry/backoff behavior, logging, proxy settings, or connection-pool sizing. UseretryingClient(AlpacaRetryPolicy)for opt-in application-level retries of idempotent requests. -
defaultBuilder
public static okhttp3.OkHttpClient.Builder defaultBuilder()Returns a pre-configured builder so callers can add their own interceptors, certificates, retry/backoff policies, or other customisations before callingbuild().OkHttp's transport retry support is enabled by default, but application-level retries for responses such as HTTP 429 or 5xx are opt-in. Add
AlpacaRetryInterceptorwhen you want conservative retries for idempotent requests. -
withAgentInformation
public static okhttp3.OkHttpClient withAgentInformation(okhttp3.OkHttpClient httpClient) Returns an HTTP client that identifies this SDK and its version in theUser-Agentheader usingAPCA-JAVA/<sdk-version> Java/<runtime-version>.If the supplied client already has the Alpaca agent interceptor, the same instance is returned. Otherwise, a derived client is returned without modifying the supplied instance. The SDK's canonical agent value replaces any existing
User-Agentheader. -
retryingClient
public static okhttp3.OkHttpClient retryingClient()Returns an OkHttp client with default timeouts and the default Alpaca retry policy. -
retryingClient
Returns an OkHttp client with default timeouts and the supplied Alpaca retry policy. -
loggingClient
public static okhttp3.OkHttpClient loggingClient(okhttp3.logging.HttpLoggingInterceptor.Level level) Returns an OkHttpClient with HTTP-level request/response logging at the given level, writing to the platform logger (java.util.logging).HttpLoggingInterceptor.Level.BASIClogs request line, response code, and size — safe for all environments. Higher levels log headers and bodies:HttpLoggingInterceptor.Level.HEADERS— logs all headers. TheAPCA-API-KEY-ID,APCA-API-SECRET-KEY, andAuthorizationheaders are redacted automatically by this method, but any other sensitive headers you add will not be.HttpLoggingInterceptor.Level.BODY— logs headers and bodies; same redaction applies. Avoid in production: response bodies may contain PII.
- Parameters:
level- the desired logging verbosity- See Also:
-
loggingClient
public static okhttp3.OkHttpClient loggingClient(okhttp3.logging.HttpLoggingInterceptor.Level level, okhttp3.logging.HttpLoggingInterceptor.Logger logger) Returns an OkHttpClient with HTTP-level request/response logging at the given level, writing to a caller-suppliedHttpLoggingInterceptor.Logger.Use this overload to route OkHttp log lines into your own logging framework (SLF4J, Logback, Log4j, Android Logcat, etc.):
// SLF4J example Logger slf4j = LoggerFactory.getLogger(AlpacaHttpConfig.class); var client = AlpacaHttpConfig.loggingClient(Level.BASIC, slf4j::debug);The same header-redaction rules as
loggingClient(HttpLoggingInterceptor.Level)apply.- Parameters:
level- the desired logging verbositylogger- destination for log lines produced by the interceptor
-