Class AlpacaClientFactory
For most applications, prefer client(AlpacaCredentials) or AlpacaClient.builder(AlpacaCredentials). AlpacaClient is an immutable facade that owns
configured generated REST clients internally and exposes narrower workflow helpers. Use the
builder when Trading, Market Data, and Broker credentials differ.
The *Client(...) methods return the generated ApiClient for the corresponding
REST API, wired with the correct authentication scheme and a shared OkHttp client. Each REST API
has its own ApiClient class with a different default base URL and server configuration.
Overloads that accept OkHttpClient let applications use distinct transport settings for
Broker, Market Data, Trading, WebSocket, or SSE workloads.
Thread safety: the shared OkHttpClient is safe to use concurrently, but the
generated REST ApiClient instances are mutable. Configure base paths, default headers,
JSON settings, and custom HTTP clients before sharing an ApiClient across threads. Prefer
one fully configured ApiClient per API/environment/credential set, then share that
instance read-only.
Resiliency: configure HTTP timeouts, logging, retry/backoff interceptors, proxies, and
connection-pool settings on the supplied OkHttpClient. Keep application-level retries
conservative around non-idempotent operations such as order placement, account creation, and
transfers.
Example — Trading REST API
var creds = AlpacaCredentials.fromTradingApiEnvironmentVariables();
var client = AlpacaClientFactory.client(creds);
// default environment: TradingApiEnvironment.PAPER
var liveClient = AlpacaClientFactory.client(creds, TradingApiEnvironment.PRODUCTION);
var openOrders = client.orders().list(ListOrdersRequest.builder()
.status(ListOrdersRequest.Status.OPEN)
.symbols("AAPL")
.limit(50)
.build());
// Escape hatch: create a fresh mutable generated client.
var trading = client.newTradingClient();
var ordersApi = new markets.alpaca.client.openapi.trading.api.OrdersApi(trading);
Example — Broker REST API
var creds = AlpacaCredentials.fromBrokerApiEnvironmentVariables();
var broker = AlpacaClientFactory.brokerClient(creds);
// default environment: BrokerApiEnvironment.SANDBOX
var prodBroker = AlpacaClientFactory.brokerClient(creds, BrokerApiEnvironment.PRODUCTION);
var accountsApi = new markets.alpaca.client.openapi.broker.api.AccountsApi(broker);
Example — Stock WebSocket stream
var stream = AlpacaClientFactory.stockStream(
creds, StockSource.IEX, AlpacaStreamEnvironment.PRODUCTION,
new StockStreamListener() {
public void onTrade(StockTrade t) { System.out.println(t); }
});
stream.connect(StockSubscription.builder().trades("AAPL").build());
// later:
stream.close();
NOTE: This file references classes generated by ./gradlew generateApis. Run
that task at least once before opening the project in your IDE.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ApiClientbrokerClient(AlpacaCredentials credentials) Creates a BrokerApiClientfor the sandbox environment with HTTP Basic authentication and default timeouts.static ApiClientbrokerClient(AlpacaCredentials credentials, String baseUrl) Creates a BrokerApiClientfor a custom base URL with default timeouts.static ApiClientbrokerClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a BrokerApiClientfor a custom base URL and HTTP client.static ApiClientbrokerClient(AlpacaCredentials credentials, BrokerApiEnvironment environment) Creates a BrokerApiClientfor the requested environment with HTTP Basic authentication and default timeouts.static ApiClientbrokerClient(AlpacaCredentials credentials, BrokerApiEnvironment environment, okhttp3.OkHttpClient httpClient) Creates a BrokerApiClientfor the requested environment and HTTP client.static ApiClientbrokerClient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates a sandbox BrokerApiClientwith HTTP Basic authentication and a customOkHttpClient(e.g.static BrokerEventsSseClientbrokerEventsSseClient(AlpacaCredentials credentials) Creates a Broker Events SSE client with HTTP Basic authentication and default timeouts.static BrokerEventsSseClientbrokerEventsSseClient(AlpacaCredentials credentials, Executor callbackExecutor) Creates a Broker Events SSE client with HTTP Basic authentication and a custom listener executor.static BrokerEventsSseClientbrokerEventsSseClient(ApiClient brokerClient) Creates a Broker Events SSE client from an existing generated BrokerApiClient.static BrokerEventsSseClientbrokerEventsSseClient(ApiClient brokerClient, Executor callbackExecutor) Creates a Broker Events SSE client from an existing Broker client and callback executor.static AlpacaClientclient(AlpacaCredentials credentials) Creates an immutable client facade using default REST settings.static AlpacaClientclient(AlpacaCredentials credentials, TradingApiEnvironment tradingEnvironment) Creates an immutable client facade in the requested Trading environment.static AlpacaClientclient(AlpacaCredentials credentials, TradingApiEnvironment tradingEnvironment, okhttp3.OkHttpClient httpClient) Creates an immutable client facade using the requested Trading environment and one shared HTTP client.static AlpacaClientclient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates an immutable client facade using one shared HTTP client.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, String baseUrl, CryptoStreamListener listener) Creates a crypto pricing WebSocket stream client for a custom stream base URL.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, String baseUrl, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a crypto pricing WebSocket stream client for a custom stream base URL and HTTP client.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener) Creates a crypto pricing WebSocket stream client.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a custom listener executor.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a crypto pricing WebSocket stream client with a custom reconnect policy.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a crypto pricing WebSocket stream client with a customOkHttpClient.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a customOkHttpClientand listener executor.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a crypto pricing WebSocket stream client with a customOkHttpClientand reconnect policy.static AlpacaCryptoStreamcryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor.static ApiClientdataClient(AlpacaCredentials credentials) Creates a DataApiClientwith API-key header authentication and default timeouts.static ApiClientdataClient(AlpacaCredentials credentials, String baseUrl) Creates a DataApiClientfor a custom base URL with default timeouts.static ApiClientdataClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a DataApiClientfor a custom base URL and HTTP client.static ApiClientdataClient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates a DataApiClientwith a customOkHttpClient.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, String baseUrl, NewsStreamListener listener) Creates a real-time news WebSocket stream client for a custom stream base URL.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, String baseUrl, NewsStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time news WebSocket stream client for a custom stream base URL and HTTP client.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener) Creates a real-time news WebSocket stream client.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a custom listener executor.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time news WebSocket stream client with a custom reconnect policy.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time news WebSocket stream client with a customOkHttpClient.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a customOkHttpClientand listener executor.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time news WebSocket stream client with a customOkHttpClientand reconnect policy.static AlpacaNewsStreamnewsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor.static AlpacaOrdersCreates a handwritten convenience facade for common Trading order workflows.static AlpacaStocksCreates a handwritten convenience facade for common Market Data stock workflows.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, String baseUrl, StockStreamListener listener) Creates a stock pricing WebSocket stream client for a custom stream base URL.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, String baseUrl, StockStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a stock pricing WebSocket stream client for a custom stream base URL and HTTP client.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener) Creates a stock pricing WebSocket stream client.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a custom listener executor.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a stock pricing WebSocket stream client with a custom reconnect policy.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a stock pricing WebSocket stream client with a customOkHttpClient.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a customOkHttpClientand listener executor.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a stock pricing WebSocket stream client with a customOkHttpClientand reconnect policy.static AlpacaStockStreamstockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor.static ApiClienttradingClient(AlpacaCredentials credentials) Creates a TradingApiClientfor the paper environment with API-key header authentication and default timeouts.static ApiClienttradingClient(AlpacaCredentials credentials, String baseUrl) Creates a TradingApiClientfor a custom base URL with default timeouts.static ApiClienttradingClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a TradingApiClientfor a custom base URL and HTTP client.static ApiClienttradingClient(AlpacaCredentials credentials, TradingApiEnvironment environment) Creates a TradingApiClientfor the requested environment with API-key header authentication and default timeouts.static ApiClienttradingClient(AlpacaCredentials credentials, TradingApiEnvironment environment, okhttp3.OkHttpClient httpClient) Creates a TradingApiClientfor the requested environment and HTTP client.static ApiClienttradingClient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates a paper TradingApiClientwith a customOkHttpClient.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, String baseUrl, TradingStreamListener listener) Creates a real-time trading WebSocket stream client for a custom stream base URL.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, String baseUrl, TradingStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time trading WebSocket stream client for a custom stream base URL and HTTP client.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener) Creates a real-time trading WebSocket stream client.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a custom listener executor.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time trading WebSocket stream client with a custom reconnect policy.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time trading WebSocket stream client with a customOkHttpClient.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a customOkHttpClientand listener executor.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time trading WebSocket stream client with a customOkHttpClientand reconnect policy.static AlpacaTradingStreamtradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor.
-
Method Details
-
client
Creates an immutable client facade using default REST settings. -
client
public static AlpacaClient client(AlpacaCredentials credentials, TradingApiEnvironment tradingEnvironment) Creates an immutable client facade in the requested Trading environment. -
client
Creates an immutable client facade using one shared HTTP client. -
client
public static AlpacaClient client(AlpacaCredentials credentials, TradingApiEnvironment tradingEnvironment, okhttp3.OkHttpClient httpClient) Creates an immutable client facade using the requested Trading environment and one shared HTTP client. -
brokerClient
Creates a BrokerApiClientfor the sandbox environment with HTTP Basic authentication and default timeouts. -
brokerClient
public static ApiClient brokerClient(AlpacaCredentials credentials, BrokerApiEnvironment environment) Creates a BrokerApiClientfor the requested environment with HTTP Basic authentication and default timeouts. -
brokerClient
public static ApiClient brokerClient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates a sandbox BrokerApiClientwith HTTP Basic authentication and a customOkHttpClient(e.g. one with logging — seeAlpacaHttpConfig.loggingClient(okhttp3.logging.HttpLoggingInterceptor.Level)). -
brokerClient
public static ApiClient brokerClient(AlpacaCredentials credentials, BrokerApiEnvironment environment, okhttp3.OkHttpClient httpClient) Creates a BrokerApiClientfor the requested environment and HTTP client. -
brokerClient
Creates a BrokerApiClientfor a custom base URL with default timeouts. -
brokerClient
public static ApiClient brokerClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a BrokerApiClientfor a custom base URL and HTTP client. -
brokerEventsSseClient
Creates a Broker Events SSE client with HTTP Basic authentication and default timeouts. -
brokerEventsSseClient
public static BrokerEventsSseClient brokerEventsSseClient(AlpacaCredentials credentials, Executor callbackExecutor) Creates a Broker Events SSE client with HTTP Basic authentication and a custom listener executor. -
brokerEventsSseClient
Creates a Broker Events SSE client from an existing generated BrokerApiClient. -
brokerEventsSseClient
public static BrokerEventsSseClient brokerEventsSseClient(ApiClient brokerClient, Executor callbackExecutor) Creates a Broker Events SSE client from an existing Broker client and callback executor. -
tradingClient
Creates a TradingApiClientfor the paper environment with API-key header authentication and default timeouts. -
tradingClient
public static ApiClient tradingClient(AlpacaCredentials credentials, TradingApiEnvironment environment) Creates a TradingApiClientfor the requested environment with API-key header authentication and default timeouts. -
tradingClient
public static ApiClient tradingClient(AlpacaCredentials credentials, okhttp3.OkHttpClient httpClient) Creates a paper TradingApiClientwith a customOkHttpClient. -
tradingClient
public static ApiClient tradingClient(AlpacaCredentials credentials, TradingApiEnvironment environment, okhttp3.OkHttpClient httpClient) Creates a TradingApiClientfor the requested environment and HTTP client. -
tradingClient
Creates a TradingApiClientfor a custom base URL with default timeouts. -
tradingClient
public static ApiClient tradingClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a TradingApiClientfor a custom base URL and HTTP client. -
orders
Creates a handwritten convenience facade for common Trading order workflows. -
dataClient
Creates a DataApiClientwith API-key header authentication and default timeouts. -
dataClient
Creates a DataApiClientwith a customOkHttpClient. -
dataClient
Creates a DataApiClientfor a custom base URL with default timeouts. -
dataClient
public static ApiClient dataClient(AlpacaCredentials credentials, String baseUrl, okhttp3.OkHttpClient httpClient) Creates a DataApiClientfor a custom base URL and HTTP client. -
stocks
Creates a handwritten convenience facade for common Market Data stock workflows. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener) Creates a stock pricing WebSocket stream client.Call
connect(subscription)to open the connection and subscribe after authentication completes.- Parameters:
credentials- API credentialssource-StockSource.IEXorStockSource.SIPenvironment-AlpacaStreamEnvironment.PRODUCTIONorSANDBOXlistener- event callbacks
-
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a stock pricing WebSocket stream client with a custom reconnect policy. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a custom listener executor. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a stock pricing WebSocket stream client with a customOkHttpClient. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a customOkHttpClientand listener executor. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a stock pricing WebSocket stream client with a customOkHttpClientand reconnect policy. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, AlpacaStreamEnvironment environment, StockStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a stock pricing WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, String baseUrl, StockStreamListener listener) Creates a stock pricing WebSocket stream client for a custom stream base URL. -
stockStream
public static AlpacaStockStream stockStream(AlpacaCredentials credentials, StockSource source, String baseUrl, StockStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a stock pricing WebSocket stream client for a custom stream base URL and HTTP client. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener) Creates a crypto pricing WebSocket stream client.Only available on
AlpacaStreamEnvironment.PRODUCTION.- Parameters:
credentials- API credentialsenvironment- must beAlpacaStreamEnvironment.PRODUCTIONlistener- event callbacks
-
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a crypto pricing WebSocket stream client with a custom reconnect policy. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a custom listener executor. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a crypto pricing WebSocket stream client with a customOkHttpClient. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a customOkHttpClientand listener executor. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a crypto pricing WebSocket stream client with a customOkHttpClientand reconnect policy. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a crypto pricing WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, String baseUrl, CryptoStreamListener listener) Creates a crypto pricing WebSocket stream client for a custom stream base URL. -
cryptoStream
public static AlpacaCryptoStream cryptoStream(AlpacaCredentials credentials, String baseUrl, CryptoStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a crypto pricing WebSocket stream client for a custom stream base URL and HTTP client. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener) Creates a real-time news WebSocket stream client.Only available on
AlpacaStreamEnvironment.PRODUCTION.- Parameters:
credentials- API credentialsenvironment- must beAlpacaStreamEnvironment.PRODUCTIONlistener- event callbacks
-
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time news WebSocket stream client with a custom reconnect policy. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a custom listener executor. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time news WebSocket stream client with a customOkHttpClient. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a customOkHttpClientand listener executor. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time news WebSocket stream client with a customOkHttpClientand reconnect policy. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, AlpacaStreamEnvironment environment, NewsStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a real-time news WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, String baseUrl, NewsStreamListener listener) Creates a real-time news WebSocket stream client for a custom stream base URL. -
newsStream
public static AlpacaNewsStream newsStream(AlpacaCredentials credentials, String baseUrl, NewsStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time news WebSocket stream client for a custom stream base URL and HTTP client. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener) Creates a real-time trading WebSocket stream client.Provides order lifecycle events (
trade_updates) for the authenticated account.- Parameters:
credentials- API credentialsenvironment-TradingEnvironment.PRODUCTIONorTradingEnvironment.PAPERlistener- event callbacks
-
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time trading WebSocket stream client with a custom reconnect policy. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a custom listener executor. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time trading WebSocket stream client with a customOkHttpClient. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a customOkHttpClientand listener executor. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy) Creates a real-time trading WebSocket stream client with a customOkHttpClientand reconnect policy. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, TradingEnvironment environment, TradingStreamListener listener, okhttp3.OkHttpClient httpClient, AlpacaStreamReconnectPolicy reconnectPolicy, Executor callbackExecutor) Creates a real-time trading WebSocket stream client with a customOkHttpClient, reconnect policy, and listener executor. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, String baseUrl, TradingStreamListener listener) Creates a real-time trading WebSocket stream client for a custom stream base URL. -
tradingStream
public static AlpacaTradingStream tradingStream(AlpacaCredentials credentials, String baseUrl, TradingStreamListener listener, okhttp3.OkHttpClient httpClient) Creates a real-time trading WebSocket stream client for a custom stream base URL and HTTP client.
-