Migration 0002 adds the market data tables on both engines: daily and one-minute bars, corporate actions, FX rates, the exchange calendar, calendar events, mood indicators, spread samples, data issues, source state and universe members, plus the trading rules on instruments. The data layer is format-independent so the venue clients can build on it: the instrument catalogue (rules from the venue, delisted kept), bar upserts with ON CONFLICT, the SPEC 6.4 checks with an issue register that blocks entries until a second reading, freshness by age of the last datum (trap 10), research history in .csv.gz with exact decimals, and adjusted series anchored at the decision day with level and quantity conversion across splits and dividends. Recorded API responses from OKX, the Alpaca docs and the free sources are kept byte for byte as test fixtures; the secret scan now ignores pagination cursors such as Alpaca's next_page_token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9.7 KiB
Alpaca market data stream v2: documented examples
Copied verbatim from the official docs (read 2026-11-10). Nothing here is invented; where the docs show no example, it says so.
Sources:
- G = https://docs.alpaca.markets/us/docs/streaming-market-data (page updatedAt 2026-08-27)
- S = https://docs.alpaca.markets/us/docs/real-time-stock-pricing-data (page updatedAt 2026-05-18)
- P = https://docs.alpaca.markets/us/docs/about-market-data-api (plan table)
URLs (S)
wss://stream.data.alpaca.markets/{version}/{feed}
v2/sip,v2/iex,v2/delayed_sip,v1beta1/boats,v1beta1/overnight- Sandbox (broker partners):
wss://stream.data.sandbox.alpaca.markets/{version}/{feed} - Test stream, always on, symbol
FAKEPACA(G):wss://stream.data.alpaca.markets/v2/test - "Any attempt to access a data feed not available for your subscription will result in an error during authentication." (G, S)
Connect (G)
Welcome message:
[{"T":"success","msg":"connected"}]
Authenticate (G)
Option A, HTTP headers on the opening handshake (Trading API keys):
websocat wss://stream.data.alpaca.markets/v2/test \
-H="APCA-API-KEY-ID: {KEY_ID}" \
-H="APCA-API-SECRET-KEY: {SECRET_KEY}"
Option B, message after connecting. "You must authenticate within 10 seconds."
{"action":"auth","key":"{KEY_ID}","secret":"{SECRET_KEY}"}
Success reply:
[{"T":"success","msg":"authenticated"}]
Subscribe / unsubscribe (G)
General form:
{
"action": "subscribe",
"<channel1>": ["<SYMBOL1>"],
"<channel2>": ["<SYMBOL2>","<SYMBOL3>"],
"<channel3>": ["*"]
}
Subscriptions are additive; unsubscribe subtracts:
{"action":"subscribe","trades":["FAKEPACA"]}
{"action":"unsubscribe","quotes":["FAKEPACA"]}
The reply always lists the WHOLE current subscription set:
[{"T":"subscription","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":["*"],"updatedBars":[],"dailyBars":["VOO"],"statuses":["*"],"lulds":[],"corrections":["AAPL"],"cancelErrors":["AAPL"]}]
Sample exchange (G):
> {"action": "subscribe", "trades": ["AAPL"], "quotes": ["AMD", "CLDR"], "bars": ["*"]}
< [{"T":"subscription","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":["*"],"updatedBars":[],"dailyBars":[],"statuses":[],"lulds":[],"corrections":["AAPL"],"cancelErrors":["AAPL"]}]
...
> {"action": "unsubscribe", "bars": ["*"]}
< [{"T":"subscription","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":[],"updatedBars":[],"dailyBars":[],"statuses":[],"lulds":[],"corrections":["AAPL"],"cancelErrors":["AAPL"]}]
Stock channels (S): trades, quotes, bars, dailyBars, updatedBars, statuses,
lulds, imbalances. corrections and cancelErrors are subscribed automatically with
trades. (The imbalances key does not appear in any documented subscription reply.)
Message envelope (G)
[{"T": "{message_type}", {contents}},...]
- Control messages (
T=error,success,subscription) always arrive in arrays of size one. - Data messages may arrive in arrays longer than one.
Content-Type: application/jsonorContent-Type: application/msgpackswitches text/binary frames.- Compression per RFC 7692 (permessage-deflate).
Data messages (S)
| T | channel | fields |
|---|---|---|
t |
trades | T, S, i, x, p, s, c, t, z |
q |
quotes | T, S, ax, ap, as, bx, bp, bs, c, t, z (as/bs described as "in round lots" on this page) |
b |
bars (minute) | T, S, o, h, l, c, v, vw, n, t |
d |
dailyBars | same as b |
u |
updatedBars | same as b |
c |
corrections | T, S, x, oi, op, os, oc, ci, cp, cs, cc, t, z |
x |
cancelErrors | T, S, i, x, p, s, a ("C" cancel, "E" error), t, z |
l |
lulds | T, S, u, d, i, t, z |
s |
statuses | T, S, sc, sm, rc, rm, t, z |
i |
imbalances | T, S, p, z, t |
Trade (t):
{
"T": "t",
"i": 96921,
"S": "AAPL",
"x": "D",
"p": 126.55,
"s": 1,
"t": "2021-02-22T15:51:44.208Z",
"c": ["@", "I"],
"z": "C"
}
Quote (q):
{
"T": "q",
"S": "AMD",
"bx": "U",
"bp": 87.66,
"bs": 1,
"ax": "Q",
"ap": 87.68,
"as": 4,
"t": "2021-02-22T15:51:45.335689322Z",
"c": ["R"],
"z": "C"
}
Bar (b). The docs show ONLY a b example; there is NO documented example of a d
(dailyBars) or u (updatedBars) message, only the shared schema.
{
"T": "b",
"S": "SPY",
"o": 388.985,
"h": 389.13,
"l": 388.975,
"c": 389.12,
"v": 49378,
"n": 461,
"vw": 389.062639,
"t": "2021-02-22T19:15:00Z"
}
Bar semantics (S):
bars: emitted right after each minute mark, containing the trades of the previous minute; pre-market and after-hours trades are included.dailyBars: emitted right after each minute mark after the market opens; contain all trades until the emission time.updatedBars: emitted after each half-minute mark if a late trade arrived after the previous minute mark (e.g. trade 16:49:59.998 arriving after 16:50:00 -> just after 16:50:30 an updated bar witht= 16:49:00).
Trade correction (c):
{
"T": "c",
"S": "EEM",
"x": "M",
"oi": 52983525033527,
"op": 39.1582,
"os": 440000,
"oc": [
" ",
"7"
],
"ci": 52983525034326,
"cp": 39.1809,
"cs": 440000,
"cc": [
" ",
"7"
],
"z": "B",
"t": "2023-04-06T14:25:06.542305024Z"
}
Trade cancel/error (x):
{
"T": "x",
"S": "GOOGL",
"i": 465,
"x": "D",
"p": 105.31,
"s": 300,
"a": "C",
"z": "C",
"t": "2023-04-06T13:15:42.83540958Z"
}
LULD (l):
{
"T": "l",
"S": "IONM",
"u": 3.24,
"d": 2.65,
"i": "B",
"t": "2023-04-06T13:34:45.565004401Z",
"z": "C"
}
Trading status (s):
{
"T": "s",
"S": "AAPL",
"sc": "H",
"sm": "Trading Halt",
"rc": "T12",
"rm": "Trading Halted; For information requested by NASDAQ",
"t": "2021-02-22T19:15:00Z",
"z": "C"
}
Order imbalance (i), subscribe with {"action":"subscribe","imbalances":["INAQU"]}:
{
"T": "i",
"S": "INAQU",
"p": 9.12,
"z": "C",
"t": "2024-12-13T19:58:09.242138635Z"
}
Full sessions as documented
Test stream (G):
$ wscat -c wss://stream.data.alpaca.markets/v2/test
Connected (press CTRL+C to quit)
< [{"T":"success","msg":"connected"}]
> {"action":"auth","key":"<YOUR API KEY>","secret":"<YOUR API SECRET>"}
< [{"T":"success","msg":"authenticated"}]
> {"action":"subscribe","bars":["FAKEPACA"],"quotes":["FAKEPACA"]}
< [{"T":"subscription","trades":[],"quotes":["FAKEPACA"],"bars":["FAKEPACA"]}]
< [{"T":"q","S":"FAKEPACA","bx":"O","bp":133.85,"bs":4,"ax":"R","ap":135.77,"as":5,"c":["R"],"z":"A","t":"2024-07-24T07:56:53.639713735Z"}]
< [{"T":"q","S":"FAKEPACA","bx":"O","bp":133.85,"bs":4,"ax":"R","ap":135.77,"as":5,"c":["R"],"z":"A","t":"2024-07-24T07:56:58.641207127Z"}]
< [{"T":"b","S":"FAKEPACA","o":132.65,"h":136,"l":132.12,"c":134.65,"v":205,"t":"2024-07-24T07:56:00Z","n":16,"vw":133.7}]
Note: in this test-stream transcript the subscription reply has only trades, quotes, bars
keys, unlike the full reply above. A parser must tolerate missing channel keys.
SIP stream (S):
$ wscat -c wss://stream.data.alpaca.markets/v2/sip
connected (press CTRL+C to quit)
< [{"T":"success","msg":"connected"}]
> {"action": "auth", "key": "*****", "secret": "*****"}
< [{"T":"success","msg":"authenticated"}]
> {"action": "subscribe", "trades": ["AAPL"], "quotes": ["AMD", "CLDR"], "bars": ["*"],"dailyBars":["VOO"],"statuses":["*"]}
< [{"T":"subscription","trades":["AAPL"],"quotes":["AMD","CLDR"],"bars":["*"],"updatedBars":[],"dailyBars":["VOO"],"statuses":["*"],"lulds":[],"corrections":["AAPL"],"cancelErrors":["AAPL"]}]
< [{"T":"q","S":"AMD","bx":"K","bp":91.95,"bs":2,"ax":"Q","ap":91.98,"as":1,"c":["R"],"z":"C","t":"2023-04-06T11:54:21.670905508Z"}]
< [{"T":"t","S":"AAPL","i":628,"x":"K","p":162.92,"s":3,"c":["@","F","T","I"],"z":"C","t":"2023-04-06T11:54:26.838232225Z"},{"T":"t","S":"AAPL","i":75,"x":"Z","p":162.92,"s":3,"c":["@","F","T","I"],"z":"C","t":"2023-04-06T11:54:26.838562809Z"},{"T":"t","S":"AAPL","i":1465,"x":"P","p":162.91,"s":71,"c":["@","F","T","I"],"z":"C","t":"2023-04-06T11:54:26.83915973Z"}]
< [{"T":"q","S":"AMD","bx":"P","bp":91.9,"bs":1,"ax":"Q","ap":91.98,"as":1,"c":["R"],"z":"C","t":"2023-04-06T11:54:27.924933876Z"}]
Errors (G)
The only error message shown verbatim as JSON in the docs:
[{"T":"error","code":406,"msg":"connection limit exceeded"}]
The other codes are documented only as a table (code + msg + description), not as JSON:
| Code | msg | Meaning (summarised) |
|---|---|---|
| 400 | invalid syntax | message not per spec; also sent for an invalid symbol format in a subscription |
| 401 | not authenticated | subscribe/unsubscribe before auth |
| 402 | auth failed | invalid credentials |
| 403 | already authenticated | auth sent twice in the session |
| 404 | auth timeout | did not authenticate in time after connecting |
| 405 | symbol limit exceeded | over the plan's symbol limit; previous subscriptions are kept unchanged |
| 406 | connection limit exceeded | already at the number of sessions allowed |
| 407 | slow client | client too slow; not guaranteed to arrive before disconnection |
| 409 | insufficient subscription | data source not in the plan |
| 410 | invalid subscribe action for this feed | channel not available on that stream |
| 500 | internal error | unexpected server error |
Limits
- Basic plan: 30 symbols on the websocket (P, table "Websocket subscriptions").
- Connections: "The number of connections to a single endpoint from a user is limited based on the user's subscription, but in many subscriptions (or without one) this limit is 1." (G) A second connection gets the 406 above. The docs do not state the Basic limit as an exact number.