Alpaca Trading API
api.alpaca.markets · Finance
Commission-free US stock, ETF, options, and crypto trading API — built for developers. Real-time market data, paper trading sandbox, WebSocket streaming. Free paper trading forever.
Authentication
API Key
Free account at alpaca.markets. Get API key and secret from dashboard. Pass as APCA-API-KEY-ID and APCA-API-SECRET-KEY headers. Paper trading: use paper-api.alpaca.markets.
Sample Requests
GET
Get account info
Get your paper trading account details.
https://api.alpaca.markets/v2/account
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| APCA-API-KEY-ID | YOUR_KEY_ID |
| APCA-API-SECRET-KEY | YOUR_SECRET |
curl -X GET "https://api.alpaca.markets/v2/account" \ -H "APCA-API-KEY-ID: YOUR_KEY_ID" \ -H "APCA-API-SECRET-KEY: YOUR_SECRET"
import requests
headers = {
"APCA-API-KEY-ID": "YOUR_KEY_ID",
"APCA-API-SECRET-KEY": "YOUR_SECRET"
}
response = requests.get(
"https://api.alpaca.markets/v2/account",
headers=headers,
)
print(response.json())const url = 'https://api.alpaca.markets/v2/account';
const response = await fetch(url, {
headers: {
'APCA-API-KEY-ID': 'YOUR_KEY_ID',
'APCA-API-SECRET-KEY': 'YOUR_SECRET'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
targetURL := "https://api.alpaca.markets/v2/account"
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("APCA-API-KEY-ID", "YOUR_KEY_ID")
req.Header.Set("APCA-API-SECRET-KEY", "YOUR_SECRET")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.alpaca.markets/v2/account")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["APCA-API-KEY-ID"] = "YOUR_KEY_ID"
req["APCA-API-SECRET-KEY"] = "YOUR_SECRET"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.alpaca.markets/v2/account";
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"APCA-API-KEY-ID: YOUR_KEY_ID",
"APCA-API-SECRET-KEY: YOUR_SECRET"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Get latest stock quote
Get the latest bid/ask quote for Apple stock.
https://api.alpaca.markets/v2https:/data.alpaca.markets/v2/stocks/AAPL/quotes/latest
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| APCA-API-KEY-ID | YOUR_KEY_ID |
| APCA-API-SECRET-KEY | YOUR_SECRET |
curl -X GET "https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest" \ -H "APCA-API-KEY-ID: YOUR_KEY_ID" \ -H "APCA-API-SECRET-KEY: YOUR_SECRET"
import requests
headers = {
"APCA-API-KEY-ID": "YOUR_KEY_ID",
"APCA-API-SECRET-KEY": "YOUR_SECRET"
}
response = requests.get(
"https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest",
headers=headers,
)
print(response.json())const url = 'https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest';
const response = await fetch(url, {
headers: {
'APCA-API-KEY-ID': 'YOUR_KEY_ID',
'APCA-API-SECRET-KEY': 'YOUR_SECRET'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
targetURL := "https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest"
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("APCA-API-KEY-ID", "YOUR_KEY_ID")
req.Header.Set("APCA-API-SECRET-KEY", "YOUR_SECRET")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["APCA-API-KEY-ID"] = "YOUR_KEY_ID"
req["APCA-API-SECRET-KEY"] = "YOUR_SECRET"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.alpaca.markets/v2https://data.alpaca.markets/v2/stocks/AAPL/quotes/latest";
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"APCA-API-KEY-ID: YOUR_KEY_ID",
"APCA-API-SECRET-KEY: YOUR_SECRET"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Sign up free at alpaca.markets
- Get API key ID and secret key from dashboard
- Paper trading: use paper-api.alpaca.markets (no real money)
- Set headers: APCA-API-KEY-ID and APCA-API-SECRET-KEY
- Market data: data.alpaca.markets (separate endpoint)