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>
This commit is contained in:
1 parent
67350f091e
commit
3b13a4258d
54 files changed
+3067
-3
No files matched your search
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": "dc2d8be9-33b5-4a32-8f57-5b7d209d2c82",
|
||||
"class": "us_equity",
|
||||
"exchange": "OTC", // << This symbol is traded in OTC
|
||||
"symbol": "CGRNQ",
|
||||
"name": "CAPSTONE GREEN ENERGY CORP COM PAR $.001",
|
||||
"status": "active",
|
||||
"tradable": false,
|
||||
"marginable": false,
|
||||
"maintenance_margin_requirement": 100,
|
||||
"shortable": true,
|
||||
"easy_to_borrow": true,
|
||||
"fractionable": true,
|
||||
"attributes": []
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"borrow_status": "easy_to_borrow",
|
||||
"class": "us_equity",
|
||||
"easy_to_borrow": true,
|
||||
"exchange": "NASDAQ",
|
||||
"fractionable": true,
|
||||
"id": "b0b6dd9d-8b9b-48a9-ba46-b9d54906e415",
|
||||
"marginable": true,
|
||||
"name": "Apple Inc. Common Stock",
|
||||
"shortable": true,
|
||||
"status": "active",
|
||||
"symbol": "AAPL",
|
||||
"tradable": true
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"is_open": true,
|
||||
"next_close": "2025-06-24T16:00:00-04:00",
|
||||
"next_open": "2025-06-25T09:30:00-04:00",
|
||||
"timestamp": "2025-06-24T14:15:22-04:00"
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
{
|
||||
"capital_gains_distribution": [
|
||||
{
|
||||
"currency": "USD",
|
||||
"cusip": "36261K509",
|
||||
"ex_date": "2025-12-26",
|
||||
"id": "98c905a1-08c7-450c-8669-b8e7aee8b44d",
|
||||
"isin": "US36261K5090",
|
||||
"long_term_rate": 0.45855,
|
||||
"payable_date": "2026-01-09",
|
||||
"process_date": "2026-01-08",
|
||||
"record_date": "2025-12-29",
|
||||
"short_term_rate": 0.11019,
|
||||
"symbol": "GCAD"
|
||||
}
|
||||
],
|
||||
"cash_dividend": [
|
||||
{
|
||||
"cusip": "319829107",
|
||||
"ex_date": "2023-05-04",
|
||||
"foreign": false,
|
||||
"id": "11cfd108-292e-4cc6-bfbf-5999cdbc4029",
|
||||
"payable_date": "2023-05-19",
|
||||
"process_date": "2023-05-19",
|
||||
"rate": 0.125,
|
||||
"record_date": "2023-05-05",
|
||||
"special": false,
|
||||
"symbol": "FCF"
|
||||
}
|
||||
],
|
||||
"cash_merger": [
|
||||
{
|
||||
"acquiree_cusip": "Y2687W108",
|
||||
"acquiree_symbol": "GLOP",
|
||||
"effective_date": "2023-07-17",
|
||||
"id": "3772bbd7-4ad5-44d4-9cc0-f69156a2f8f5",
|
||||
"payable_date": "2023-07-17",
|
||||
"process_date": "2023-07-17",
|
||||
"rate": 5.37
|
||||
}
|
||||
],
|
||||
"forward_split": [
|
||||
{
|
||||
"cusip": "816851109",
|
||||
"due_bill_redemption_date": "2023-08-23",
|
||||
"ex_date": "2023-08-22",
|
||||
"id": "189bd849-ab9f-4b4d-aaaa-a6d415fd976d",
|
||||
"new_rate": 2,
|
||||
"old_rate": 1,
|
||||
"payable_date": "2023-08-21",
|
||||
"process_date": "2023-08-22",
|
||||
"record_date": "2023-08-14",
|
||||
"symbol": "SRE"
|
||||
}
|
||||
],
|
||||
"name_change": [
|
||||
{
|
||||
"id": "5a774c35-edec-4532-a812-a56d0bbb623a",
|
||||
"new_cusip": "Y9390M103",
|
||||
"new_symbol": "VFS",
|
||||
"old_cusip": "G11537100",
|
||||
"old_symbol": "BSAQ",
|
||||
"process_date": "2023-08-15"
|
||||
}
|
||||
],
|
||||
"redemption": [
|
||||
{
|
||||
"cusip": "687305102",
|
||||
"id": "395da031-0e57-4918-a6fb-64a7c713aca4",
|
||||
"payable_date": "2023-06-13",
|
||||
"process_date": "2023-06-13",
|
||||
"rate": 0.141134,
|
||||
"symbol": "ORPHY"
|
||||
}
|
||||
],
|
||||
"reverse_split": [
|
||||
{
|
||||
"ex_date": "2023-08-24",
|
||||
"id": "913de862-c02c-46dc-a89c-fc8779a50d30",
|
||||
"new_cusip": "60879E200",
|
||||
"new_rate": 1,
|
||||
"old_cusip": "60879E101",
|
||||
"old_rate": 50,
|
||||
"process_date": "2023-08-24",
|
||||
"record_date": "2023-08-24",
|
||||
"symbol": "MNTS"
|
||||
}
|
||||
],
|
||||
"rights_distribution": [
|
||||
{
|
||||
"ex_date": "2024-04-17",
|
||||
"expiration_date": "2024-05-14",
|
||||
"id": "69794cfd-0adc-4e11-9211-9210a9cf8932",
|
||||
"new_cusip": "454089111",
|
||||
"new_symbol": "IFN.RTWI",
|
||||
"payable_date": "2024-04-19",
|
||||
"process_date": "2024-04-19",
|
||||
"rate": 1,
|
||||
"record_date": "2024-04-18",
|
||||
"source_cusip": "454089103",
|
||||
"source_symbol": "IFN"
|
||||
}
|
||||
],
|
||||
"spin_off": [
|
||||
{
|
||||
"ex_date": "2023-08-15",
|
||||
"id": "82e602f6-35bc-4651-a5dd-f6d88ff37c55",
|
||||
"new_cusip": "85237B101",
|
||||
"new_rate": 1,
|
||||
"new_symbol": "SRM",
|
||||
"process_date": "2023-08-15",
|
||||
"record_date": "2023-08-15",
|
||||
"source_cusip": "48208F105",
|
||||
"source_rate": 19.35,
|
||||
"source_symbol": "JUPW"
|
||||
}
|
||||
],
|
||||
"stock_and_cash_merger": [
|
||||
{
|
||||
"acquiree_cusip": "561409103",
|
||||
"acquiree_rate": 1,
|
||||
"acquiree_symbol": "MLVF",
|
||||
"acquirer_cusip": "31931U102",
|
||||
"acquirer_rate": 0.7733,
|
||||
"acquirer_symbol": "FRBA",
|
||||
"cash_rate": 7.8,
|
||||
"effective_date": "2023-07-18",
|
||||
"id": "e5248356-2c06-42cf-aeb9-1595bd616cdb",
|
||||
"payable_date": "2023-07-18",
|
||||
"process_date": "2023-07-18"
|
||||
}
|
||||
],
|
||||
"stock_dividend": [
|
||||
{
|
||||
"cusip": "605015106",
|
||||
"ex_date": "2023-05-19",
|
||||
"id": "3ae94c30-2d37-473a-bf29-5f7b4ab6d3ca",
|
||||
"payable_date": "2023-05-05",
|
||||
"process_date": "2023-05-19",
|
||||
"rate": 0.05,
|
||||
"record_date": "2023-05-22",
|
||||
"symbol": "MSBC"
|
||||
}
|
||||
],
|
||||
"stock_merger": [
|
||||
{
|
||||
"acquiree_cusip": "53223X107",
|
||||
"acquiree_rate": 1,
|
||||
"acquiree_symbol": "LSI",
|
||||
"acquirer_cusip": "30225T102",
|
||||
"acquirer_rate": 0.895,
|
||||
"acquirer_symbol": "EXR",
|
||||
"effective_date": "2023-07-20",
|
||||
"id": "728f8cb2-a00e-4bc7-ad14-d15fe82bbcff",
|
||||
"payable_date": "2023-07-20",
|
||||
"process_date": "2023-07-20"
|
||||
}
|
||||
],
|
||||
"unit_split": [
|
||||
{
|
||||
"alternate_cusip": "G5391L110",
|
||||
"alternate_rate": 0.3333,
|
||||
"alternate_symbol": "LVROW",
|
||||
"effective_date": "2023-03-01",
|
||||
"id": "3e68e87e-ae95-4d68-91d1-715d52ef143a",
|
||||
"new_cusip": "G5391L102",
|
||||
"new_rate": 1,
|
||||
"new_symbol": "LVRO",
|
||||
"old_cusip": "G8990L119",
|
||||
"old_rate": 1,
|
||||
"old_symbol": "TPBAU",
|
||||
"process_date": "2023-03-01"
|
||||
}
|
||||
],
|
||||
"worthless_removal": [
|
||||
{
|
||||
"cusip": "078771300",
|
||||
"id": "106c2149-ee04-4d2e-a943-98dbb4d21a3c",
|
||||
"process_date": "2024-12-19",
|
||||
"symbol": "BLPH"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"code":42210000,"message":"subscription does not permit querying recent SIP data"}
|
||||
@@ -0,0 +1,78 @@
|
||||
# Alpaca REST errors and rate limiting: what the docs actually show
|
||||
|
||||
Read 2026-11-10. Verbatim where quoted; "NOT DOCUMENTED" where the docs show nothing.
|
||||
|
||||
## Market Data API (https://data.alpaca.markets)
|
||||
|
||||
Source: OpenAPI blocks on https://docs.alpaca.markets/us/reference/stockbars (and every other
|
||||
stock reference page, e.g. stocklatestquotes-1, stocksnapshots-1, corporateactions-1).
|
||||
|
||||
Documented status codes, descriptions only (the OpenAPI declares NO response body schema
|
||||
for any error):
|
||||
|
||||
- 400: "One of the request parameters is invalid. See the returned message for details."
|
||||
(carries the X-RateLimit-* headers)
|
||||
- 401: "Authentication headers are missing or invalid. Make sure you authenticate your
|
||||
request with a valid API key."
|
||||
- 403: "The requested resource is forbidden."
|
||||
- 429: "Too many requests. You hit the rate limit. Use the X-RateLimit-... response headers to
|
||||
make sure you're under the rate limit." (carries the X-RateLimit-* headers)
|
||||
- 500: "Internal server error. We recommend retrying these later. ..."
|
||||
- 422: not listed on the market data reference pages.
|
||||
|
||||
Rate-limit headers (declared on 200, 400 and 429):
|
||||
|
||||
| Header | Doc description | Doc example |
|
||||
|---|---|---|
|
||||
| `X-RateLimit-Limit` | "Request limit per minute." | 100 |
|
||||
| `X-RateLimit-Remaining` | "Request limit per minute remaining." | 90 |
|
||||
| `X-RateLimit-Reset` | "The UNIX epoch when the remaining quota changes." | 1674044551 |
|
||||
|
||||
Basic plan: "Historical API calls 200 / min" (https://docs.alpaca.markets/us/docs/about-market-data-api).
|
||||
|
||||
Market Data FAQ (https://docs.alpaca.markets/us/docs/market-data-faq), "Why am I getting HTTP 403":
|
||||
403 is returned if the request was not authenticated, the credentials were incorrect, or the user
|
||||
has insufficient permissions. (So in practice bad keys may yield 403, while the OpenAPI says 401;
|
||||
the docs do not reconcile the two.)
|
||||
|
||||
The ONLY error body shown anywhere for market data (FAQ, latest trade with feed=sip on the free
|
||||
plan; HTTP status NOT shown):
|
||||
|
||||
```
|
||||
$ curl -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \
|
||||
"https://data.alpaca.markets/v2/stocks/AAPL/trades/latest?feed=sip"
|
||||
{"code":42210000,"message":"subscription does not permit querying recent SIP data"}
|
||||
```
|
||||
|
||||
Saved as `error-sip-recent.faq.json`. Shape: `{"code": <int>, "message": <string>}`.
|
||||
|
||||
Adjustment parameter (stockbars): unknown values, empty values and repeated keys such as
|
||||
`?adjustment=split&adjustment=all` "are rejected with a `400`". Body NOT DOCUMENTED.
|
||||
|
||||
## Trading API (https://paper-api.alpaca.markets)
|
||||
|
||||
- /v2/assets, /v2/calendar, /v2/clock, /v3/calendar, /v3/clock reference pages
|
||||
(get-v2-assets-1, legacycalendar, legacyclock, calendar-2, clock-1): calendars list
|
||||
400 / 429 / 500, /v2/clock lists 429 / 500, all with the same X-RateLimit-* headers on 200;
|
||||
/v2/assets lists only 200. No error bodies.
|
||||
- /v2/assets/{symbol_or_asset_id}: 404 when not found (no body documented).
|
||||
- POST /v2/orders (postorder): 403 "Forbidden\n\nBuying power or shares is not sufficient.",
|
||||
422 "Unprocessable\n\nInput parameters are not recognized." No bodies.
|
||||
- Getting Started with Trading API (https://docs.alpaca.markets/us/docs/getting-started-with-trading-api):
|
||||
every response carries `X-Request-ID`; the example is an unauthenticated
|
||||
`GET /v2/account` -> `HTTP/1.1 403 Forbidden`, `Content-Type: application/json`,
|
||||
`Content-Length: 26`. The body itself is elided ("...") in the docs: NOT DOCUMENTED.
|
||||
- Trading API rate limit number: NOT DOCUMENTED on the current pages.
|
||||
|
||||
## 429 behaviour
|
||||
|
||||
Only the Broker API page documents behaviour explicitly
|
||||
(https://docs.alpaca.markets/us/docs/broker-api-rate-limits): headers on every response, not
|
||||
only 429; on 429 "stop, wait, and retry using exponential backoff", ideally not before
|
||||
`X-RateLimit-Reset`. For the Trading/Market Data APIs the docs only say "Use the X-RateLimit-...
|
||||
response headers". No Retry-After header is documented anywhere.
|
||||
|
||||
## Bodies for 401 / 403 / 422 / 429
|
||||
|
||||
NOT DOCUMENTED (no example body exists in the docs). The only observed shape is the FAQ's
|
||||
`{"code":42210000,"message":"..."}`. Treat other shapes as unknown and parse defensively.
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"quote": {
|
||||
"ap": 172.7,
|
||||
"as": 1,
|
||||
"ax": "Q",
|
||||
"bp": 172.6,
|
||||
"bs": 2,
|
||||
"bx": "Q",
|
||||
"c": [
|
||||
"R"
|
||||
],
|
||||
"t": "2022-08-17T10:09:34.055031265Z",
|
||||
"z": "C"
|
||||
},
|
||||
"symbol": "AAPL"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"quotes": {
|
||||
"AAPL": {
|
||||
"ap": 172.7,
|
||||
"as": 1,
|
||||
"ax": "Q",
|
||||
"bp": 172.62,
|
||||
"bs": 2,
|
||||
"bx": "Q",
|
||||
"c": [
|
||||
"R"
|
||||
],
|
||||
"t": "2022-08-17T10:07:40.286587431Z",
|
||||
"z": "C"
|
||||
},
|
||||
"TSLA": {
|
||||
"ap": 911.6,
|
||||
"as": 1,
|
||||
"ax": "Q",
|
||||
"bp": 911.3,
|
||||
"bs": 1,
|
||||
"bx": "K",
|
||||
"c": [
|
||||
"R"
|
||||
],
|
||||
"t": "2022-08-17T10:07:49.387064037Z",
|
||||
"z": "C"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"AAPL": {
|
||||
"dailyBar": {
|
||||
"c": 173.03,
|
||||
"h": 173.71,
|
||||
"l": 171.6618,
|
||||
"n": 515139,
|
||||
"o": 172.62,
|
||||
"t": "2022-08-16T04:00:00Z",
|
||||
"v": 56457696,
|
||||
"vw": 172.743391
|
||||
},
|
||||
"latestQuote": {
|
||||
"ap": 172.7,
|
||||
"as": 5,
|
||||
"ax": "Q",
|
||||
"bp": 172.6,
|
||||
"bs": 2,
|
||||
"bx": "Q",
|
||||
"c": [
|
||||
"R"
|
||||
],
|
||||
"t": "2022-08-17T10:18:27.052763263Z",
|
||||
"z": "C"
|
||||
},
|
||||
"latestTrade": {
|
||||
"c": [
|
||||
"@",
|
||||
"T"
|
||||
],
|
||||
"i": 1011,
|
||||
"p": 172.61,
|
||||
"s": 160,
|
||||
"t": "2022-08-17T10:18:24.114694956Z",
|
||||
"x": "Q",
|
||||
"z": "C"
|
||||
},
|
||||
"minuteBar": {
|
||||
"c": 172.69,
|
||||
"h": 172.69,
|
||||
"l": 172.69,
|
||||
"n": 3,
|
||||
"o": 172.69,
|
||||
"t": "2022-08-17T10:16:00Z",
|
||||
"v": 106,
|
||||
"vw": 172.688113
|
||||
},
|
||||
"prevDailyBar": {
|
||||
"c": 173.19,
|
||||
"h": 173.39,
|
||||
"l": 171.345,
|
||||
"n": 501626,
|
||||
"o": 171.5,
|
||||
"t": "2022-08-15T04:00:00Z",
|
||||
"v": 54091719,
|
||||
"vw": 172.625371
|
||||
}
|
||||
},
|
||||
"TSLA": {
|
||||
"dailyBar": {
|
||||
"c": 919.69,
|
||||
"h": 944,
|
||||
"l": 908.65,
|
||||
"n": 805572,
|
||||
"o": 935,
|
||||
"t": "2022-08-16T04:00:00Z",
|
||||
"v": 29378774,
|
||||
"vw": 925.215087
|
||||
},
|
||||
"latestQuote": {
|
||||
"ap": 911.75,
|
||||
"as": 4,
|
||||
"ax": "P",
|
||||
"bp": 911.31,
|
||||
"bs": 1,
|
||||
"bx": "Q",
|
||||
"c": [
|
||||
"R"
|
||||
],
|
||||
"t": "2022-08-17T10:18:23.84717767Z",
|
||||
"z": "C"
|
||||
},
|
||||
"latestTrade": {
|
||||
"c": [
|
||||
"@",
|
||||
"T"
|
||||
],
|
||||
"i": 2047,
|
||||
"p": 911.99,
|
||||
"s": 100,
|
||||
"t": "2022-08-17T10:13:12.952851456Z",
|
||||
"x": "P",
|
||||
"z": "C"
|
||||
},
|
||||
"minuteBar": {
|
||||
"c": 911.99,
|
||||
"h": 911.99,
|
||||
"l": 911.99,
|
||||
"n": 64,
|
||||
"o": 911.99,
|
||||
"t": "2022-08-17T10:13:00Z",
|
||||
"v": 740,
|
||||
"vw": 911.780405
|
||||
},
|
||||
"prevDailyBar": {
|
||||
"c": 927.96,
|
||||
"h": 939.4,
|
||||
"l": 903.69,
|
||||
"n": 825109,
|
||||
"o": 905.32,
|
||||
"t": "2022-08-15T04:00:00Z",
|
||||
"v": 29786389,
|
||||
"vw": 923.982755
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"bars": [
|
||||
{
|
||||
"t": "2023-09-29T04:00:00Z",
|
||||
"o": 172.015,
|
||||
"h": 173.06,
|
||||
"l": 170.36,
|
||||
"c": 171.29,
|
||||
"v": 923134,
|
||||
"n": 12630,
|
||||
"vw": 171.716432
|
||||
}
|
||||
],
|
||||
"symbol": "AAPL",
|
||||
"next_page_token": null
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"bars": [
|
||||
{
|
||||
"t": "2023-09-29T04:00:00Z",
|
||||
"o": 172.02,
|
||||
"h": 173.07,
|
||||
"l": 170.341,
|
||||
"c": 171.21,
|
||||
"v": 51861083,
|
||||
"n": 535134,
|
||||
"vw": 171.599691
|
||||
}
|
||||
],
|
||||
"symbol": "AAPL",
|
||||
"next_page_token": "QUFQTHxEfDIwMjMtMDktMjlUMDQ6MDA6MDAuMDAwMDAwMDAwWg=="
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"bars": [
|
||||
{
|
||||
"c": 178.21,
|
||||
"h": 178.26,
|
||||
"l": 178.21,
|
||||
"n": 65,
|
||||
"o": 178.26,
|
||||
"t": "2022-01-03T09:00:00Z",
|
||||
"v": 1118,
|
||||
"vw": 178.235733
|
||||
}
|
||||
],
|
||||
"next_page_token": "QUFQTHxNfDIwMjItMDEtMDNUMDk6MDA6MDAuMDAwMDAwMDAwWg==",
|
||||
"symbol": "AAPL"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"bars": {
|
||||
"AAPL": [
|
||||
{
|
||||
"c": 178.21,
|
||||
"h": 178.26,
|
||||
"l": 178.21,
|
||||
"n": 65,
|
||||
"o": 178.26,
|
||||
"t": "2022-01-03T09:00:00Z",
|
||||
"v": 1118,
|
||||
"vw": 178.235733
|
||||
}
|
||||
]
|
||||
},
|
||||
"next_page_token": "QUFQTHxNfDIwMjItMDEtMDNUMDk6MDA6MDAuMDAwMDAwMDAwWg=="
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
# 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:
|
||||
|
||||
```json
|
||||
[{"T":"success","msg":"connected"}]
|
||||
```
|
||||
|
||||
## Authenticate (G)
|
||||
|
||||
Option A, HTTP headers on the opening handshake (Trading API keys):
|
||||
|
||||
```shell
|
||||
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."
|
||||
|
||||
```json
|
||||
{"action":"auth","key":"{KEY_ID}","secret":"{SECRET_KEY}"}
|
||||
```
|
||||
|
||||
Success reply:
|
||||
|
||||
```json
|
||||
[{"T":"success","msg":"authenticated"}]
|
||||
```
|
||||
|
||||
## Subscribe / unsubscribe (G)
|
||||
|
||||
General form:
|
||||
|
||||
```json
|
||||
{
|
||||
"action": "subscribe",
|
||||
"<channel1>": ["<SYMBOL1>"],
|
||||
"<channel2>": ["<SYMBOL2>","<SYMBOL3>"],
|
||||
"<channel3>": ["*"]
|
||||
}
|
||||
```
|
||||
|
||||
Subscriptions are additive; `unsubscribe` subtracts:
|
||||
|
||||
```json
|
||||
{"action":"subscribe","trades":["FAKEPACA"]}
|
||||
```
|
||||
|
||||
```json
|
||||
{"action":"unsubscribe","quotes":["FAKEPACA"]}
|
||||
```
|
||||
|
||||
The reply always lists the WHOLE current subscription set:
|
||||
|
||||
```json
|
||||
[{"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)
|
||||
|
||||
```json
|
||||
[{"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/json` or `Content-Type: application/msgpack` switches 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`):
|
||||
|
||||
```json
|
||||
{
|
||||
"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`):
|
||||
|
||||
```json
|
||||
{
|
||||
"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.
|
||||
|
||||
```json
|
||||
{
|
||||
"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 with `t` = 16:49:00).
|
||||
|
||||
Trade correction (`c`):
|
||||
|
||||
```json
|
||||
{
|
||||
"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`):
|
||||
|
||||
```json
|
||||
{
|
||||
"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`):
|
||||
|
||||
```json
|
||||
{
|
||||
"T": "l",
|
||||
"S": "IONM",
|
||||
"u": 3.24,
|
||||
"d": 2.65,
|
||||
"i": "B",
|
||||
"t": "2023-04-06T13:34:45.565004401Z",
|
||||
"z": "C"
|
||||
}
|
||||
```
|
||||
|
||||
Trading status (`s`):
|
||||
|
||||
```json
|
||||
{
|
||||
"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"]}`:
|
||||
|
||||
```json
|
||||
{
|
||||
"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:
|
||||
|
||||
```json
|
||||
[{"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.
|
||||
Reference in new issue
Block a user