Authenticate with the Alpaca API
masterThe Alpaca API requires an API key ID and a secret key. You can provide these to the SDK in two ways:
1. Environment Variables
Set the following environment variables in your shell:
APCA_API_KEY_IDAPCA_API_SECRET_KEYAPCA_API_BASE_URL(optional, used to specify the base URL, e.g., for paper trading)
export APCA_API_KEY_ID=xxxxx
export APCA_API_SECRET_KEY=yyyyy
export APCA_API_BASE_URL=https://paper-api.alpaca.markets2. Code Configuration
Pass the credentials directly into the alpaca.ClientOpts struct when initializing a new client.
client := alpaca.NewClient(alpaca.ClientOpts{
APIKey: "YOUR_API_KEY",
APISecret: "YOUR_API_SECRET",
BaseURL: "https://paper-api.alpaca.markets",
})