Alpaca auth
Authenticates a WebSocket connection with the key id and secret, on the account stream and on the market data stream alike. Sent first, before listen or subscribe.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
This is a message of the Alpaca WebSocket streams, not an HTTP endpoint. It has no method and no path: it is sent as JSON, or as MessagePack where the client asks for it, over an open WebSocket connection.
Paper and live keys are different keys and each works only on its own host, so connect the paper stream with the paper key.
The message
- Name
- auth
- Direction
- Request, sent by the client
- Carried by
- WebSocket. The same message opens both of Alpaca's streams; the answer differs by stream, as the answer section says.
- Paper account stream
- wss://paper-api.alpaca.markets/stream
- Live account stream
- wss://api.alpaca.markets/stream
- Stocks, IEX feed (free plan)
- wss://stream.data.alpaca.markets/v2/iex
- Stocks, SIP feed (Algo Trader Plus)
- wss://stream.data.alpaca.markets/v2/sip
- Stocks, 15 minute delayed SIP
- wss://stream.data.alpaca.markets/v2/delayed_sip
- Test stream outside market hours, symbol FAKEPACA
- wss://stream.data.alpaca.markets/v2/test
- Crypto, Alpaca US
- wss://stream.data.alpaca.markets/v1beta3/crypto/us
Fields
The vendor's page does not say which of these fields are required or always present.
| Name | Type | Description |
|---|---|---|
| action | string | Names the message: auth. |
| key | string | Your API key id. Read it from your own environment; never paste it into a web page. |
| secret | string | The secret key that goes with the key id. Read it from your own environment. |
What arrives
On the account stream, a message with stream authorization and data.status authorized or unauthorized. On the market data stream, [{"T":"success","msg":"authenticated"}], or an error message with code 402 (auth failed), 403 (already authenticated) or 404 (auth timeout).
The vendor's page does not say which of these fields are required or always present.
| Name | Type | Description |
|---|---|---|
| stream | string | Account stream: authorization. |
| data.status | string | Account stream: authorized, or unauthorized where the credentials were refused. |
| data.action | string | Account stream: authenticate, or listen where a listen message arrived before the connection was authorised. |
| T | string | Market data stream: success, or error. |
| msg | string | Market data stream: authenticated on success; connected is the message sent on connecting, before auth. |
Sample
Written by this site from the fields recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. No credential is typed into it: where a field holds one, the placeholder says where it comes from. Nothing is entered on this site.
{
"action": "auth",
"key": "<your API key id, from your own environment>",
"secret": "<your secret key, from your own environment>"
}Return codes documented for this message
The market data stream page's error table gives 401 not authenticated, 402 auth failed, 403 already authenticated and 404 auth timeout as the errors of authenticating, and this site holds every code in that table as a record. docs.alpaca.marketschecked
- WS_400 (400)The market data stream's error 400, invalid syntax: the message sent could not be parsed.
- WS_401 (401)The market data stream's error 401, not authenticated: a message other than auth arrived before the connection was authenticated.
- WS_402 (402)The market data stream's error 402, auth failed: the key id and secret were not accepted, or the feed is not in your subscription.
- WS_403 (403)The market data stream's error 403, already authenticated: a second auth message on a connection that was already authenticated.
- WS_404 (404)The market data stream's error 404, auth timeout: no auth message arrived within the 10 seconds the page allows after connecting.
- WS_405 (405)The market data stream's error 405, symbol limit exceeded: the subscribe message would take the connection past the number of symbols the plan allows.
- WS_406 (406)The market data stream's error 406, connection limit exceeded: a second connection where the plan allows one.
- WS_407 (407)The market data stream's error 407, slow client: the client is not reading messages as fast as the server sends them.
- WS_409 (409)The market data stream's error 409, insufficient subscription: the feed or channel asked for is not in the plan.
- WS_410 (410)The market data stream's error 410: the subscribe action named a channel the connected feed does not serve.
- WS_500 (500)The market data stream's error 500, internal error, on Alpaca's side.
Limits that apply at Alpaca
| Limit | Value | Scope | Source |
|---|---|---|---|
| client_order_id length | 128 | POST /v2/orders and PATCH /v2/orders/{order_id} | docs.alpaca.marketschecked |
| Crypto order size | 200,000 | Crypto spot orders, buy or sell | docs.alpaca.marketschecked |
| Market data historical API, Basic plan | 200 | Market Data API historical calls, Basic (free) plan | docs.alpaca.marketschecked |
| Market data points per page | 10,000 | Market Data API historical bars, trades and quotes, counted across all symbols | docs.alpaca.marketschecked |
| Market data historical API, Algo Trader Plus | 10,000 | Market Data API historical calls, Algo Trader Plus plan (99 US dollars a month) | docs.alpaca.marketschecked |
| GTC order age | 90 | Orders with time in force gtc | docs.alpaca.marketschecked |
| Trading API request rate | HTTP 429 above the limit, with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers on replies; no figure on the pages opened | Trading API, per account | docs.alpaca.marketschecked |
| Market data WebSocket authentication timeout | 10 | Market data WebSocket, from connecting to the auth message | docs.alpaca.marketschecked |
| Market data WebSocket connections | Depends on the subscription; 1 for many subscriptions and with none. A second connection is answered with error 406 connection limit exceeded | Market data WebSocket, per account | docs.alpaca.marketschecked |
| Market data WebSocket symbols, Basic plan | 30 | Market data WebSocket, US equities, Basic (free) plan; Algo Trader Plus is unlimited | docs.alpaca.marketschecked |