Skip to content

Storing the Alpaca API key

Axel Gard edited this page Jul 23, 2024 · 2 revisions

Diffrent ways of storing the API key.

Cira has some different ways of how to store the API key. The code for how this is done can is in the cira/alpaca.py

JSON file

One of the easy ways to store your key is to so keep it in a file. Cira supports JSON by default. The JSON file needs to have the following format to work with cira.

{
  "APCA-API-KEY-ID":"your_pub_key",
  "APCA-API-SECRET-KEY":"your_private_key"
}

Then all you need to do is to set the KEY_FILE variable.

cira.alpaca.KEY_FILE = "../mypath/key.json"

Envoerment variable

You can use environment variables to set the API key.

for Linux and MacOS

export APCA_ID = "your_pub_key"
export APCA_KEY = "your_private_key"

The API function will check for it the environment variable.

Set directly

You can set the variable directly.

cira.auth.APCA_API_KEY_ID = "my key" 
cira.auth.APCA_API_SECRET_KEY = "my secret key"
Clone this wiki locally