Record Class AlpacaCredentials

java.lang.Object
java.lang.Record
markets.alpaca.client.AlpacaCredentials

public record AlpacaCredentials(String apiKeyId, String apiSecretKey) extends Record
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-ID and APCA-API-SECRET-KEY headers.
  • Data API — same header scheme as Trading API.
Use AlpacaClientFactory to obtain pre-configured API client instances.
  • Field Details

  • Constructor Details

    • AlpacaCredentials

      public AlpacaCredentials(String apiKeyId, String apiSecretKey)
      Creates an instance of a AlpacaCredentials record class.
      Parameters:
      apiKeyId - the value for the apiKeyId record component
      apiSecretKey - the value for the apiSecretKey record component
  • Method Details

    • fromTradingApiEnvironmentVariables

      public static AlpacaCredentials 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

      public static AlpacaCredentials 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 ID
      apiSecretKeyEnvironmentVariable - environment variable that contains the API secret key
      Throws:
      IllegalArgumentException - if an environment variable name is blank
      IllegalStateException - if either environment variable is missing or blank
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • apiKeyId

      public String apiKeyId()
      Returns the value of the apiKeyId record component.
      Returns:
      the value of the apiKeyId record component
    • apiSecretKey

      public String apiSecretKey()
      Returns the value of the apiSecretKey record component.
      Returns:
      the value of the apiSecretKey record component