Package markets.alpaca.client
Record Class AlpacaCredentials
java.lang.Object
java.lang.Record
markets.alpaca.client.AlpacaCredentials
Alpaca API credentials (key ID + secret key).
- Broker API — sent as HTTP Basic Auth (key ID = username, secret key = password).
- Trading API — sent as
APCA-API-KEY-IDandAPCA-API-SECRET-KEYheaders. - Data API — same header scheme as Trading API.
AlpacaClientFactory to obtain pre-configured API client instances.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEnvironment variable used byfromBrokerApiEnvironmentVariables()for Broker API key IDs.static final StringEnvironment variable used byfromBrokerApiEnvironmentVariables()for Broker API secret keys.static final StringEnvironment variable used byfromTradingApiEnvironmentVariables()for trading/data API key IDs.static final StringEnvironment variable used byfromTradingApiEnvironmentVariables()for trading/data API secret keys. -
Constructor Summary
ConstructorsConstructorDescriptionAlpacaCredentials(String apiKeyId, String apiSecretKey) Creates an instance of aAlpacaCredentialsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionapiKeyId()Returns the value of theapiKeyIdrecord component.Returns the value of theapiSecretKeyrecord component.final booleanIndicates whether some other object is "equal to" this one.static AlpacaCredentialsReads Broker API credentials from "APCA_BROKER_KEY_ID" and "APCA_BROKER_SECRET_KEY".static AlpacaCredentialsfromEnvironmentVariables(String apiKeyIdEnvironmentVariable, String apiSecretKeyEnvironmentVariable) Reads credentials from caller-specified environment variables.static AlpacaCredentialsReads trading/data API credentials from "APCA_TRADING_KEY_ID" and "APCA_TRADING_SECRET_KEY".final inthashCode()Returns a hash code value for this object.toString()Returns a string representation of this record class.
-
Field Details
-
TRADING_API_KEY_ID_ENV
Environment variable used byfromTradingApiEnvironmentVariables()for trading/data API key IDs.- See Also:
-
TRADING_API_SECRET_KEY_ENV
Environment variable used byfromTradingApiEnvironmentVariables()for trading/data API secret keys.- See Also:
-
BROKER_API_KEY_ID_ENV
Environment variable used byfromBrokerApiEnvironmentVariables()for Broker API key IDs.- See Also:
-
BROKER_API_SECRET_KEY_ENV
Environment variable used byfromBrokerApiEnvironmentVariables()for Broker API secret keys.- See Also:
-
-
Constructor Details
-
AlpacaCredentials
Creates an instance of aAlpacaCredentialsrecord class.- Parameters:
apiKeyId- the value for theapiKeyIdrecord componentapiSecretKey- the value for theapiSecretKeyrecord component
-
-
Method Details
-
fromTradingApiEnvironmentVariables
Reads trading/data API credentials from "APCA_TRADING_KEY_ID" and "APCA_TRADING_SECRET_KEY".Use
fromBrokerApiEnvironmentVariables()for Broker API credentials.- Throws:
IllegalStateException- if either environment variable is missing or blank
-
fromBrokerApiEnvironmentVariables
Reads Broker API credentials from "APCA_BROKER_KEY_ID" and "APCA_BROKER_SECRET_KEY".- Throws:
IllegalStateException- if either environment variable is missing or blank
-
fromEnvironmentVariables
public static AlpacaCredentials fromEnvironmentVariables(String apiKeyIdEnvironmentVariable, String apiSecretKeyEnvironmentVariable) Reads credentials from caller-specified environment variables.- Parameters:
apiKeyIdEnvironmentVariable- environment variable that contains the API key IDapiSecretKeyEnvironmentVariable- environment variable that contains the API secret key- Throws:
IllegalArgumentException- if an environment variable name is blankIllegalStateException- if either environment variable is missing or blank
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
apiKeyId
Returns the value of theapiKeyIdrecord component.- Returns:
- the value of the
apiKeyIdrecord component
-
apiSecretKey
Returns the value of theapiSecretKeyrecord component.- Returns:
- the value of the
apiSecretKeyrecord component
-