Add market data schema, catalogue, bar storage and quality checks (refs #18 #20 #21 #23)

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:
Alby96andClaude Opus 5.5 committed 2026-11-10 14:58:44 +01:00
1 parent 67350f091e
commit 3b13a4258d
54 files changed
+3067 -3

No files matched your search

+3
View File
@@ -9,6 +9,9 @@
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>
<ItemGroup>
<None Include="Fixtures\**\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Anubis\Anubis.csproj" />
<ProjectReference Include="..\..\src\Anubis.Server\Anubis.Server.csproj" />
@@ -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.
@@ -0,0 +1 @@
c92970f74893163b848f117a37fa5e7110ee1d800c0d9ada949940fccccfdd2f BTCUSDT-1d-2017-08.zip
@@ -0,0 +1 @@
3a3eb1b723d944deb4dbef5ae361bbe39340a17fe987fe22e397ef03dca268d2 BTCUSDT-1d-2025-01.zip
@@ -0,0 +1,5 @@
1502928000000,4261.48000000,4485.39000000,4200.74000000,4285.08000000,795.15037700,1503014399999,3454770.05073206,3427,616.24854100,2678216.40060401,8733.91139481
1503014400000,4285.08000000,4371.52000000,3938.77000000,4108.37000000,1199.88826400,1503100799999,5086958.30617151,5233,972.86871000,4129123.31651808,9384.14140858
1503100800000,4108.37000000,4184.69000000,3850.00000000,4139.98000000,381.30976300,1503187199999,1549483.73542151,2153,274.33604200,1118001.87008735,9184.08552906
1503187200000,4120.98000000,4211.08000000,4032.62000000,4086.29000000,467.08302200,1503273599999,1930364.39032646,2321,376.79594700,1557401.33373730,10125.41408414
1503273600000,4069.13000000,4119.62000000,3911.79000000,4016.00000000,691.74306000,1503359999999,2797231.71402728,3972,557.35610700,2255662.55315837,11706.76997007
1 1502928000000 4261.48000000 4485.39000000 4200.74000000 4285.08000000 795.15037700 1503014399999 3454770.05073206 3427 616.24854100 2678216.40060401 8733.91139481
2 1503014400000 4285.08000000 4371.52000000 3938.77000000 4108.37000000 1199.88826400 1503100799999 5086958.30617151 5233 972.86871000 4129123.31651808 9384.14140858
3 1503100800000 4108.37000000 4184.69000000 3850.00000000 4139.98000000 381.30976300 1503187199999 1549483.73542151 2153 274.33604200 1118001.87008735 9184.08552906
4 1503187200000 4120.98000000 4211.08000000 4032.62000000 4086.29000000 467.08302200 1503273599999 1930364.39032646 2321 376.79594700 1557401.33373730 10125.41408414
5 1503273600000 4069.13000000 4119.62000000 3911.79000000 4016.00000000 691.74306000 1503359999999 2797231.71402728 3972 557.35610700 2255662.55315837 11706.76997007
@@ -0,0 +1,5 @@
1735689600000000,93576.00000000,95151.15000000,92888.00000000,94591.79000000,10373.32613000,1735775999999999,975444194.13799830,1516556,5347.73648000,502914035.64059070,0
1735776000000000,94591.78000000,97839.50000000,94392.00000000,96984.79000000,21970.48948000,1735862399999999,2118411852.68127950,3569079,10915.96986000,1052226710.33367170,0
1735862400000000,96984.79000000,98976.91000000,96100.01000000,98174.18000000,15253.82936000,1735948799999999,1486610768.59079170,2851164,7468.60797000,727787246.89655880,0
1735948800000000,98174.17000000,98778.43000000,97514.79000000,98220.50000000,8990.05651000,1736035199999999,881223751.63536030,1559982,4350.80221000,426524714.13055390,0
1736035200000000,98220.51000000,98836.85000000,97276.79000000,98363.61000000,8095.63723000,1736121599999999,793931715.95463240,1685799,3877.90985000,380355340.46860360,0
1 1735689600000000 93576.00000000 95151.15000000 92888.00000000 94591.79000000 10373.32613000 1735775999999999 975444194.13799830 1516556 5347.73648000 502914035.64059070 0
2 1735776000000000 94591.78000000 97839.50000000 94392.00000000 96984.79000000 21970.48948000 1735862399999999 2118411852.68127950 3569079 10915.96986000 1052226710.33367170 0
3 1735862400000000 96984.79000000 98976.91000000 96100.01000000 98174.18000000 15253.82936000 1735948799999999 1486610768.59079170 2851164 7468.60797000 727787246.89655880 0
4 1735948800000000 98174.17000000 98778.43000000 97514.79000000 98220.50000000 8990.05651000 1736035199999999 881223751.63536030 1559982 4350.80221000 426524714.13055390 0
5 1736035200000000 98220.51000000 98836.85000000 97276.79000000 98363.61000000 8095.63723000 1736121599999999 793931715.95463240 1685799 3877.90985000 380355340.46860360 0
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>data.binance.vision</Name><Prefix>data/spot/monthly/klines/BTCUSDT/1d/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><Delimiter>/</Delimiter><IsTruncated>false</IsTruncated>
<Contents><Key>data/spot/monthly/klines/BTCUSDT/1d/BTCUSDT-1d-2017-08.zip</Key><LastModified>2021-06-22T11:34:18.000Z</LastModified><ETag>&quot;de69dcc75a0d145a68ee7d2d7bb12e00&quot;</ETag><Size>1150</Size><StorageClass>STANDARD</StorageClass></Contents>
<Contents><Key>data/spot/monthly/klines/BTCUSDT/1d/BTCUSDT-1d-2017-08.zip.CHECKSUM</Key><LastModified>2021-06-22T11:34:18.000Z</LastModified><ETag>&quot;16214e8597f7b6dd811f97b4b8e9cb94&quot;</ETag><Size>88</Size><StorageClass>STANDARD</StorageClass></Contents>
<Contents><Key>data/spot/monthly/klines/BTCUSDT/1d/BTCUSDT-1d-2026-10.zip</Key><LastModified>2026-11-02T10:54:15.000Z</LastModified><ETag>&quot;9e3817dcfb6373a96ce8a37acc9ca433&quot;</ETag><ChecksumAlgorithm>CRC64NVME</ChecksumAlgorithm><ChecksumType>FULL_OBJECT</ChecksumType><Size>2224</Size><StorageClass>STANDARD</StorageClass></Contents>
<Contents><Key>data/spot/monthly/klines/BTCUSDT/1d/BTCUSDT-1d-2026-10.zip.CHECKSUM</Key><LastModified>2026-11-02T10:54:15.000Z</LastModified><ETag>&quot;29b93f9f76a4673ed03ad9584cc7e476&quot;</ETag><ChecksumAlgorithm>CRC64NVME</ChecksumAlgorithm><ChecksumType>FULL_OBJECT</ChecksumType><Size>88</Size><StorageClass>STANDARD</StorageClass></Contents>
</ListBucketResult>
@@ -0,0 +1,48 @@
# Central bank meeting calendars (retrieved 2026-11-10)
Decision day = the day the rate decision is announced (second day of two-day meetings).
## FOMC (Federal Reserve)
Source: https://www.federalreserve.gov/monetarypolicy/fomccalendars.htm (page "Last Update: October 28, 2026").
Statement at 14:00 America/New_York on the decision day (Fed practice, not stated on this page).
`*` = meeting with a Summary of Economic Projections (SEP).
Page note: "Each meeting date is tentative until confirmed at the meeting immediately preceding it."
| Meeting | Decision day | SEP |
|---|---|---|
| 2026-12-08/09 | 2026-12-09 | yes |
| 2027-01-26/27 | 2027-01-27 | no |
| 2027-03-16/17 | 2027-03-17 | yes |
| 2027-04-27/28 | 2027-04-28 | no |
| 2027-06-08/09 | 2027-06-09 | yes |
| 2027-07-27/28 | 2027-07-28 | no |
| 2027-09-14/15 | 2027-09-15 | yes |
| 2027-10-26/27 | 2027-10-27 | no |
| 2027-12-07/08 | 2027-12-08 | yes |
Next after that (page note): 2028-01-25/26, decision 2028-01-26.
Already past in 2026 (for reference): Jan 27-28, Mar 17-18*, Apr 28-29, Jun 16-17*, Jul 28-29, Sep 15-16*, Oct 27-28.
## ECB (Governing Council, monetary policy meetings)
Source: https://www.ecb.europa.eu/press/calendars/mgcgc/html/index.en.html
("Schedules for the meetings of the Governing Council and General Council of the ECB and related press conferences").
All listed as "monetary policy meeting in Frankfurt (Day 1)" + "(Day 2), followed by press conference".
Decision published on Day 2 at 14:15 CET, press conference 14:45 CET (ECB practice, not stated on this page).
Non-monetary policy meetings are not listed here.
| Meeting | Decision day |
|---|---|
| 2026-12-16/17 | 2026-12-17 |
| 2027-02-03/04 | 2027-02-04 |
| 2027-03-17/18 | 2027-03-18 |
| 2027-04-28/29 | 2027-04-29 |
| 2027-06-09/10 | 2027-06-10 |
| 2027-07-21/22 | 2027-07-22 |
| 2027-09-08/09 | 2027-09-09 |
| 2027-10-27/28 | 2027-10-28 |
| 2027-12-15/16 | 2027-12-16 |
The page also already lists 2028 decision days: 02-03, 03-23, 05-04, 06-08, 07-20, 09-07, 10-12, 12-07.
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time='2026-11-09'>
<Cube currency='USD' rate='1.1193'/>
<Cube currency='JPY' rate='176.79'/>
<Cube currency='GBP' rate='0.83430'/>
<Cube currency='CHF' rate='0.9164'/>
</Cube>
</Cube>
</gesmes:Envelope>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?><gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"><gesmes:subject>Reference rates</gesmes:subject><gesmes:Sender><gesmes:name>European Central Bank</gesmes:name></gesmes:Sender><Cube><Cube time="2026-11-09"><Cube currency="USD" rate="1.1193"/><Cube currency="JPY" rate="176.79"/><Cube currency="CZK" rate="24.365"/><Cube currency="DKK" rate="7.4753"/><Cube currency="GBP" rate="0.8343"/><Cube currency="HUF" rate="362.99"/><Cube currency="PLN" rate="4.3843"/><Cube currency="RON" rate="5.343"/><Cube currency="SEK" rate="10.996"/><Cube currency="CHF" rate="0.9164"/><Cube currency="ISK" rate="136.8"/><Cube currency="NOK" rate="10.5325"/><Cube currency="TRY" rate="56.1199"/><Cube currency="AUD" rate="1.6236"/><Cube currency="BRL" rate="6.1748"/><Cube currency="CAD" rate="1.5785"/><Cube currency="CNY" rate="7.4689"/><Cube currency="HKD" rate="8.7772"/><Cube currency="IDR" rate="20234.31"/><Cube currency="ILS" rate="3.549"/><Cube currency="INR" rate="105.1435"/><Cube currency="KRW" rate="1507.46"/><Cube currency="MXN" rate="20.8343"/><Cube currency="MYR" rate="4.5432"/><Cube currency="NZD" rate="1.9941"/><Cube currency="PHP" rate="70.712"/><Cube currency="SGD" rate="1.4328"/><Cube currency="THB" rate="37.485"/><Cube currency="ZAR" rate="18.4105"/></Cube>
<Cube time="2026-11-06"><Cube currency="USD" rate="1.1165"/><Cube currency="JPY" rate="176.77"/><Cube currency="CZK" rate="24.35"/><Cube currency="DKK" rate="7.4752"/><Cube currency="GBP" rate="0.83415"/><Cube currency="HUF" rate="363.9"/><Cube currency="PLN" rate="4.3925"/><Cube currency="RON" rate="5.3403"/><Cube currency="SEK" rate="11.026"/><Cube currency="CHF" rate="0.9143"/><Cube currency="ISK" rate="136.8"/><Cube currency="NOK" rate="10.526"/><Cube currency="TRY" rate="55.9957"/><Cube currency="AUD" rate="1.625"/><Cube currency="BRL" rate="6.1449"/><Cube currency="CAD" rate="1.5705"/><Cube currency="CNY" rate="7.4485"/><Cube currency="HKD" rate="8.7505"/><Cube currency="IDR" rate="20208.93"/><Cube currency="ILS" rate="3.5717"/><Cube currency="INR" rate="104.8645"/><Cube currency="KRW" rate="1517.02"/><Cube currency="MXN" rate="20.8828"/><Cube currency="MYR" rate="4.5319"/><Cube currency="NZD" rate="2.0141"/><Cube currency="PHP" rate="70.358"/><Cube currency="SGD" rate="1.4309"/><Cube currency="THB" rate="37.459"/><Cube currency="ZAR" rate="18.4649"/></Cube>
<Cube time="2026-11-05"><Cube currency="USD" rate="1.1224"/><Cube currency="JPY" rate="177.85"/><Cube currency="CZK" rate="24.289"/><Cube currency="DKK" rate="7.4747"/><Cube currency="GBP" rate="0.83393"/><Cube currency="HUF" rate="363.18"/><Cube currency="PLN" rate="4.389"/><Cube currency="RON" rate="5.3385"/><Cube currency="SEK" rate="10.9845"/><Cube currency="CHF" rate="0.918"/><Cube currency="ISK" rate="136.8"/><Cube currency="NOK" rate="10.4365"/><Cube currency="TRY" rate="56.1729"/><Cube currency="AUD" rate="1.6033"/><Cube currency="BRL" rate="6.1355"/><Cube currency="CAD" rate="1.5675"/><Cube currency="CNY" rate="7.4846"/><Cube currency="HKD" rate="8.8055"/><Cube currency="IDR" rate="20281.15"/><Cube currency="ILS" rate="3.5598"/><Cube currency="INR" rate="106.0395"/><Cube currency="KRW" rate="1509.28"/><Cube currency="MXN" rate="20.8655"/><Cube currency="MYR" rate="4.5412"/><Cube currency="NZD" rate="1.9966"/><Cube currency="PHP" rate="70.706"/><Cube currency="SGD" rate="1.4336"/><Cube currency="THB" rate="37.533"/><Cube currency="ZAR" rate="18.4268"/></Cube>
</Cube></gesmes:Envelope>
@@ -0,0 +1,3 @@
Date,USD,JPY,BGN,CYP,CZK,DKK,EEK,GBP,HUF,LTL,LVL,MTL,PLN,ROL,RON,SEK,SIT,SKK,CHF,ISK,NOK,HRK,RUB,TRL,TRY,AUD,BRL,CAD,CNY,HKD,IDR,ILS,INR,KRW,MXN,MYR,NZD,PHP,SGD,THB,ZAR,
2026-11-09,1.1193,176.79,N/A,N/A,24.365,7.4753,N/A,0.8343,362.99,N/A,N/A,N/A,4.3843,N/A,5.343,10.996,N/A,N/A,0.9164,136.8,10.5325,N/A,N/A,N/A,56.1199,1.6236,6.1748,1.5785,7.4689,8.7772,20234.31,3.549,105.1435,1507.46,20.8343,4.5432,1.9941,70.712,1.4328,37.485,18.4105,
2026-11-06,1.1165,176.77,N/A,N/A,24.35,7.4752,N/A,0.83415,363.9,N/A,N/A,N/A,4.3925,N/A,5.3403,11.026,N/A,N/A,0.9143,136.8,10.526,N/A,N/A,N/A,55.9957,1.625,6.1449,1.5705,7.4485,8.7505,20208.93,3.5717,104.8645,1517.02,20.8828,4.5319,2.0141,70.358,1.4309,37.459,18.4649,
1 Date USD JPY BGN CYP CZK DKK EEK GBP HUF LTL LVL MTL PLN ROL RON SEK SIT SKK CHF ISK NOK HRK RUB TRL TRY AUD BRL CAD CNY HKD IDR ILS INR KRW MXN MYR NZD PHP SGD THB ZAR
2 2026-11-09 1.1193 176.79 N/A N/A 24.365 7.4753 N/A 0.8343 362.99 N/A N/A N/A 4.3843 N/A 5.343 10.996 N/A N/A 0.9164 136.8 10.5325 N/A N/A N/A 56.1199 1.6236 6.1748 1.5785 7.4689 8.7772 20234.31 3.549 105.1435 1507.46 20.8343 4.5432 1.9941 70.712 1.4328 37.485 18.4105
3 2026-11-06 1.1165 176.77 N/A N/A 24.35 7.4752 N/A 0.83415 363.9 N/A N/A N/A 4.3925 N/A 5.3403 11.026 N/A N/A 0.9143 136.8 10.526 N/A N/A N/A 55.9957 1.625 6.1449 1.5705 7.4485 8.7505 20208.93 3.5717 104.8645 1517.02 20.8828 4.5319 2.0141 70.358 1.4309 37.459 18.4649
@@ -0,0 +1 @@
[{"title":"RBA Assist Gov Hunter Speaks","country":"AUD","date":"2026-11-08T17:30:00-05:00","impact":"Low","forecast":"","previous":""},{"title":"CPI y\/y","country":"CNY","date":"2026-11-08T20:30:00-05:00","impact":"Low","forecast":"0.8%","previous":"0.9%"},{"title":"CPI m\/m","country":"USD","date":"2026-11-10T08:30:00-05:00","impact":"High","forecast":"0.3%","previous":"0.6%"},{"title":"Unemployment Claims","country":"USD","date":"2026-11-12T08:30:00-05:00","impact":"Medium","forecast":"194K","previous":"189K"},{"title":"Bank Holiday","country":"USD","date":"2026-11-11T08:00:00-05:00","impact":"Holiday","forecast":"","previous":""}]
@@ -0,0 +1,26 @@
{
"earningsCalendar": [
{
"date": "2020-01-28",
"epsActual": 4.99,
"epsEstimate": 4.5474,
"hour": "amc",
"quarter": 1,
"revenueActual": 91819000000,
"revenueEstimate": 88496400810,
"symbol": "AAPL",
"year": 2020
},
{
"date": "2019-10-30",
"epsActual": 3.03,
"epsEstimate": 2.8393,
"hour": "amc",
"quarter": 4,
"revenueActual": 64040000000,
"revenueEstimate": 62985161760,
"symbol": "AAPL",
"year": 2019
}
]
}
+19
View File
@@ -0,0 +1,19 @@
{
"name": "Fear and Greed Index",
"data": [
{
"value": "32",
"value_classification": "Fear",
"timestamp": "1794268800",
"time_until_update": "36787"
},
{
"value": "29",
"value_classification": "Fear",
"timestamp": "1794182400"
}
],
"metadata": {
"error": null
}
}
@@ -0,0 +1,79 @@
{
"realtime_start": "1776-07-04",
"realtime_end": "9999-12-31",
"order_by": "release_date",
"sort_order": "asc",
"count": 17,
"offset": 0,
"limit": 10000,
"release_dates": [
{
"release_id": 82,
"date": "1997-02-10"
},
{
"release_id": 82,
"date": "1998-02-10"
},
{
"release_id": 82,
"date": "1999-02-04"
},
{
"release_id": 82,
"date": "2000-02-10"
},
{
"release_id": 82,
"date": "2001-01-16"
},
{
"release_id": 82,
"date": "2002-02-06"
},
{
"release_id": 82,
"date": "2003-02-07"
},
{
"release_id": 82,
"date": "2004-02-09"
},
{
"release_id": 82,
"date": "2005-02-17"
},
{
"release_id": 82,
"date": "2006-02-13"
},
{
"release_id": 82,
"date": "2007-02-16"
},
{
"release_id": 82,
"date": "2008-02-11"
},
{
"release_id": 82,
"date": "2009-03-03"
},
{
"release_id": 82,
"date": "2010-02-11"
},
{
"release_id": 82,
"date": "2011-02-23"
},
{
"release_id": 82,
"date": "2012-10-24"
},
{
"release_id": 82,
"date": "2013-04-10"
}
]
}
@@ -0,0 +1,14 @@
Nasdaq Traded|Symbol|Security Name|Listing Exchange|Market Category|ETF|Round Lot Size|Test Issue|Financial Status|CQS Symbol|NASDAQ Symbol|NextShares
Y|AAPL|Apple Inc. - Common Stock|Q|Q|N|40|N|N||AAPL|N
Y|KO|Coca-Cola Company (The) Common Stock|N| |N|100|N||KO|KO|N
Y|SPY|State Street SPDR S&P 500 ETF Trust|P| |Y|40|N||SPY|SPY|N
Y|CECO|CECO Environmental Corp. Common Stock|F| |N|100|N||CECO|CECO|N
Y|BULZ|MicroSectors FANG & Innovation 3x Leveraged ETN|P| |Y|100|N||BULZ|BULZ|N
Y|AMUB|ETRACS Alerian MLP Index ETN Series B due July 18, 2042|P| |N|100|N||AMUB|AMUB|N
Y|PDI|PIMCO Dynamic Income Fund Common Stock|N| |N|100|N||PDI|PDI|N
Y|ABR$D|Arbor Realty Trust 6.375% Series D Cumulative Redeemable Preferred Stock, Liquidation Preference $25.00 per Share|N| |N|100|N||ABRpD|ABR-D|N
Y|AACIW|Armada Acquisition Corp. III - Warrant|Q|G|N|100|N|N||AACIW|N
Y|AACG|ATA Creativity Global - American Depositary Shares, each representing two common shares|Q|S|N|100|N|D||AACG|N
N|BRK.A|Berkshire Hathaway Inc. Common Stock|N| |N|1|N||BRK.A|BRK.A|N
Y|ZXIET|IEX Test Company Test Symbol Three for IEX|V| |N|100|Y||ZXIET|ZXIET|N
File Creation Time: 1110202608:47|||||
+5
View File
@@ -0,0 +1,5 @@
DATE,OPEN,HIGH,LOW,CLOSE
01/02/1990,17.240000,17.240000,17.240000,17.240000
01/03/1990,18.190000,18.190000,18.190000,18.190000
11/06/2026,27.680000,27.760000,23.470000,25.640000
11/09/2026,25.080000,25.080000,19.640000,19.920000
1 DATE OPEN HIGH LOW CLOSE
2 01/02/1990 17.240000 17.240000 17.240000 17.240000
3 01/03/1990 18.190000 18.190000 18.190000 18.190000
4 11/06/2026 27.680000 27.760000 23.470000 25.640000
5 11/09/2026 25.080000 25.080000 19.640000 19.920000
@@ -0,0 +1 @@
{"code":"0","msg":"","data":[{"asks":[["65998.6","0.01847","0","1"],["66007.9","0.01950009","0","1"],["66017.2","0.02600013","0","1"],["66019.7","0.08124142","0","1"],["66040","0.00074","0","1"]],"bids": [["65986.1","0.02600013","0","1"],["65979.9","0.02600013","0","1"],["65967.5","0.02600013","0","1"],["65965.3","0.08130857","0","1"],["65940.4","0.00174173","0","1"]],"ts": "1794318312903","seqId": 8550771731}]}
@@ -0,0 +1 @@
{"code":"0","data":[["1794268800000","67082.7","67169.1","65700","65995.6","49.49453348","3281596.15859545","3281596.15859545","0"],["1794182400000","67102.9","67730.8","65957.5","67058.9","87.03419039","5799147.867285542","5799147.867285542","1"],["1794096000000","68031.7","68329.2","66005.3","67090.9","68.34820078","4593882.883114905","4593882.883114905","1"],["1794009600000","68000.7","68380.8","67773.8","68045.9","28.39339742","1933533.396611748","1933533.396611748","1"],["1793923200000","67722.2","68333.3","67091","68003.4","70.5073903","4783491.931149474","4783491.931149474","1"]],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[["1794318240000","66014","66014","65959.8","65959.8","0.00566935","374.097328501","374.097328501","0"],["1794318180000","65999.8","66069.8","65999.8","66050.5","0.0523422","3457.089286529","3457.089286529","1"],["1794318120000","65890.5","65986.5","65886.7","65968","0.01010823","666.959143595","666.959143595","1"],["1794318060000","65920","65928.9","65893.8","65898.8","0.01617887","1066.219812468","1066.219812468","1"],["1794318000000","65962.4","65997.7","65940.4","65945","0.01322151","872.109237591","872.109237591","1"]],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[{"formulaType":"withRate","fundingRate":"-0.0000009390698834","fundingTime":"1794326400000","impactValue":"20000.0000000000000000","instId":"BTC-USDT-SWAP","instType":"SWAP","interestRate":"0.0001000000000000","maxFundingRate":"0.00375","method":"current_period","minFundingRate":"-0.00375","nextFundingRate":"","nextFundingTime":"1794355200000","premium":"-0.0004047059587875","prevFundingTime":"1794297600000","settFundingRate":"0.0001000000000000","settState":"settled","ts":"1794318013510"}],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[["1700870400000","34593","34593","34511.2","34535.3","0.59821825","20677.171718216","20677.171718216","1"],["1700784000000","34275.4","34998.8","34275.4","34592.4","4.44982271","154238.594247212","154238.594247212","1"],["1700697600000","34397.3","34397.3","33953.5","34165.5","1.31890957","45071.044398169","45071.044398169","1"],["1700611200000","33316.2","34718.6","33309.5","34709.1","4.32517623","147240.001527279","147240.001527279","1"],["1700524800000","34255.8","34340.2","32774.3","32774.3","8.40657006","281736.604324771","281736.604324771","1"]],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[{"alias":"","auctionEndTime":"","baseCcy":"BTC","category":"1","contTdSwTime":"","ctMult":"","ctType":"","ctVal":"","ctValCcy":"","expTime":"","floatPxLmtPct":"0.005","freq":"","futureSettlement":false,"groupId":"18","initPxLmtPct":"","instCategory":"1","instFamily":"","instId":"BTC-EUR","instIdCode":138508,"instType":"SPOT","lever":"","listTime":"1700539860000","longPosRemainingQuota":"","lotSz":"0.00000001","maxIcebergSz":"9999999999.0000000000000000","maxLmtAmt":"20000000","maxLmtSz":"9999999999","maxMktAmt":"400000","maxMktSz":"1000000","maxPlatOICoinLmt":"","maxPlatOILmt":"","maxPxLmtPct":"0.01","maxStopSz":"1000000","maxTriggerSz":"9999999999.0000000000000000","maxTwapSz":"9999999999.0000000000000000","method":"","minSz":"0.0001","openType":"fix_price","optType":"","posLmtAmt":"","posLmtPct":"","preMktSwTime":"","quoteCcy":"EUR","rpiMinLevel":"2","rpiMinPxBand":"20","ruleType":"normal","seriesId":"","settleCcy":"","shortPosRemainingQuota":"","state":"live","stk":"","tickSz":"0.1","tradeQuoteCcyList":["EURC","EUR"],"uly":"","upcChg":[]},{"alias":"","auctionEndTime":"","baseCcy":"ETH","category":"1","contTdSwTime":"","ctMult":"","ctType":"","ctVal":"","ctValCcy":"","expTime":"","floatPxLmtPct":"0.005","freq":"","futureSettlement":false,"groupId":"18","initPxLmtPct":"","instCategory":"1","instFamily":"","instId":"ETH-EUR","instIdCode":138510,"instType":"SPOT","lever":"","listTime":"1700539860000","longPosRemainingQuota":"","lotSz":"0.000001","maxIcebergSz":"999999999999.0000000000000000","maxLmtAmt":"20000000","maxLmtSz":"999999999999","maxMktAmt":"100000","maxMktSz":"1000000","maxPlatOICoinLmt":"","maxPlatOILmt":"","maxPxLmtPct":"0.01","maxStopSz":"1000000","maxTriggerSz":"999999999999.0000000000000000","maxTwapSz":"999999999999.0000000000000000","method":"","minSz":"0.001","openType":"fix_price","optType":"","posLmtAmt":"","posLmtPct":"","preMktSwTime":"","quoteCcy":"EUR","rpiMinLevel":"2","rpiMinPxBand":"20","ruleType":"normal","seriesId":"","settleCcy":"","shortPosRemainingQuota":"","state":"live","stk":"","tickSz":"0.01","tradeQuoteCcyList":["EURC","EUR"],"uly":"","upcChg":[]},{"alias":"","auctionEndTime":"","baseCcy":"SOL","category":"1","contTdSwTime":"","ctMult":"","ctType":"","ctVal":"","ctValCcy":"","expTime":"","floatPxLmtPct":"0.005","freq":"","futureSettlement":false,"groupId":"18","initPxLmtPct":"","instCategory":"1","instFamily":"","instId":"SOL-EUR","instIdCode":138511,"instType":"SPOT","lever":"","listTime":"1700539860000","longPosRemainingQuota":"","lotSz":"0.000001","maxIcebergSz":"999999999999.0000000000000000","maxLmtAmt":"20000000","maxLmtSz":"999999999999","maxMktAmt":"45000","maxMktSz":"1000000","maxPlatOICoinLmt":"","maxPlatOILmt":"","maxPxLmtPct":"0.01","maxStopSz":"1000000","maxTriggerSz":"999999999999.0000000000000000","maxTwapSz":"999999999999.0000000000000000","method":"","minSz":"0.01","openType":"fix_price","optType":"","posLmtAmt":"","posLmtPct":"","preMktSwTime":"","quoteCcy":"EUR","rpiMinLevel":"2","rpiMinPxBand":"20","ruleType":"normal","seriesId":"","settleCcy":"","shortPosRemainingQuota":"","state":"live","stk":"","tickSz":"0.01","tradeQuoteCcyList":["EURC","EUR"],"uly":"","upcChg":[]},{"alias":"","auctionEndTime":"","baseCcy":"BTC","category":"1","contTdSwTime":"","ctMult":"","ctType":"","ctVal":"","ctValCcy":"","expTime":"","floatPxLmtPct":"0.005","freq":"","futureSettlement":false,"groupId":"12","initPxLmtPct":"0.1","instCategory":"1","instFamily":"","instId":"BTC-USDC","instIdCode":224008,"instType":"SPOT","lever":"","listTime":"1755763200000","longPosRemainingQuota":"","lotSz":"0.00000001","maxIcebergSz":"9999999999.0000000000000000","maxLmtAmt":"20000000","maxLmtSz":"9999999999","maxMktAmt":"1000000","maxMktSz":"1000000","maxPlatOICoinLmt":"","maxPlatOILmt":"","maxPxLmtPct":"0.01","maxStopSz":"1000000","maxTriggerSz":"9999999999.0000000000000000","maxTwapSz":"9999999999.0000000000000000","method":"","minSz":"0.00001","openType":"fix_price","optType":"","posLmtAmt":"","posLmtPct":"","preMktSwTime":"","quoteCcy":"USDC","rpiMinLevel":"2","rpiMinPxBand":"20","ruleType":"normal","seriesId":"","settleCcy":"","shortPosRemainingQuota":"","state":"live","stk":"","tickSz":"0.1","tradeQuoteCcyList":["USDG","USD","USDC","RLUSD"],"uly":"","upcChg":[]},{"alias":"","auctionEndTime":"","baseCcy":"BTC","category":"1","contTdSwTime":"","ctMult":"","ctType":"","ctVal":"","ctValCcy":"","expTime":"","floatPxLmtPct":"0.005","freq":"","futureSettlement":false,"groupId":"12","initPxLmtPct":"","instCategory":"1","instFamily":"","instId":"BTC-USDT","instIdCode":3,"instType":"SPOT","lever":"10","listTime":"1611907686000","longPosRemainingQuota":"","lotSz":"0.00000001","maxIcebergSz":"9999999999.0000000000000000","maxLmtAmt":"20000000","maxLmtSz":"9999999999","maxMktAmt":"1000000","maxMktSz":"1000000","maxPlatOICoinLmt":"","maxPlatOILmt":"","maxPxLmtPct":"0.01","maxStopSz":"1000000","maxTriggerSz":"9999999999.0000000000000000","maxTwapSz":"9999999999.0000000000000000"Line truncated
@@ -0,0 +1 @@
{"code":"0","data":[{"instId":"BTC-USDT-SWAP","instType":"SWAP","oi":"3600677.00000001675","oiCcy":"36006.7700000001675","oiUsd":"2659809297.86901237317475","ts":"1794318321995"}],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[{"ts":"1794318266358"}],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[{"instType":"SPOT","instId":"BTC-EUR","last":"65958.9","lastSz":"0.00044","askPx":"65998.6","askSz":"0.01847","bidPx":"65986.1","bidSz":"0.02600011","open24h":"66683.7","high24h":"67457","low24h":"65700","volCcy24h":"5575007.141398614","vol24h":"83.82602516","ts":"1794318312368","sodUtc0":"67082.7","sodUtc8":"67429.6"}],"msg":""}
@@ -0,0 +1 @@
{"code":"0","data":[{"instType":"SPOT","instId":"BTC-USDC","last":"73887","lastSz":"0.0012911","askPx":"73887.1","askSz":"0.0015","bidPx":"73886.9","bidSz":"0.07498377","open24h":"74580.7","high24h":"75498.5","low24h":"73456","volCcy24h":"52361791.317870886","vol24h":"701.87662721","ts":"1794318321771","sodUtc0":"75273.2","sodUtc8":"75455.2"},{"instType":"SPOT","instId":"BTC-EUR","last":"65958.9","lastSz":"0.00044","askPx":"66065.1","askSz":"0.02599891","bidPx":"66047.5","bidSz":"0.01949918","open24h":"66683.7","high24h":"67457","low24h":"65700","volCcy24h":"5575007.141398614","vol24h":"83.82602516","ts":"1794318321672","sodUtc0":"67082.7","sodUtc8":"67429.6"},{"instType":"SPOT","instId":"ETH-EUR","last":"1848.25","lastSz":"0.005067","askPx":"1849.56","askSz":"0.18408","bidPx":"1849.41","bidSz":"2.900507","open24h":"1889.85","high24h":"1920.5","low24h":"1817","volCcy24h":"2854479.7139542","vol24h":"1526.885348","ts":"1794318321675","sodUtc0":"1900.62","sodUtc8":"1916.45"}],"msg":""}
@@ -0,0 +1,197 @@
# OKX v5 WebSocket — examples
Source of [DOCS] blocks: https://my.okx.com/docs-v5/en/ (sections "WebSocket > Connect", "Subscribe",
"Notification", "Connection count limit", "WS / Tickers channel", "WS / Candlesticks channel",
"Error Code > WebSocket"), read on 2026-11-10.
Source of [LIVE] blocks: real frames captured on 2026-11-10 from wseea.okx.com / wseeapap.okx.com
(no login). Frames are copied byte-for-byte as received.
## URLs
| Use | URL | Channels |
|---|---|---|
| Production public | `wss://wseea.okx.com/ws/v5/public` | `tickers`, `books*`, `trades`, ... |
| Production business | `wss://wseea.okx.com/ws/v5/business` | `candle*` (all candle channels) |
| Demo public | `wss://wseeapap.okx.com/ws/v5/public` | as production |
| Demo business | `wss://wseeapap.okx.com/ws/v5/business` | as production |
## Keepalive [DOCS, "Connect"]
- The server closes the connection if no subscription is established or no data is pushed for more than 30 s
(close code 4004 "No data received in 30s").
- Client rule: reset an N-second timer (N < 30) on every received message; when it fires, send the
plain text frame `ping` (not JSON); expect the plain text frame `pong` within N s, otherwise reconnect.
- Connection limit: 3 connection requests per second per IP.
- Request limit: 480 `subscribe`/`unsubscribe`/`login` requests per connection per hour.
- Total length of the `args` of one request: max 64 KB.
[LIVE] public, after a tickers subscription:
```
> ping
< pong
```
Note: pushes already in flight can arrive before the `pong` (observed live).
## Subscribe request [DOCS]
```json
{
"id": "1512",
"op":"subscribe",
"args":[
{
"channel":"tickers",
"instId":"BTC-USDT"
}
]
}
```
`id` is optional, client-chosen, up to 32 alphanumeric characters, echoed in the response.
Unsubscribe: same shape with `"op":"unsubscribe"`.
## Subscription confirmation [DOCS]
```json
{
"id": "1512",
"event": "subscribe",
"arg": {
"channel": "tickers",
"instId": "BTC-USDT"
},
"connId": "accb8e21"
}
```
[LIVE] public, tickers BTC-EUR:
```json
{"id":"1","event":"subscribe","arg":{"channel":"tickers","instId":"BTC-EUR"},"connId":"53efe456"}
```
[LIVE] business, two args in one request -> one confirmation per arg, same `id`:
```
> {"id":"3","op":"subscribe","args":[{"channel":"candle1m","instId":"BTC-EUR"},{"channel":"candle1Dutc","instId":"BTC-EUR"}]}
< {"id":"3","event":"subscribe","arg":{"channel":"candle1m","instId":"BTC-EUR"},"connId":"3e5c5e42"}
< {"id":"3","event":"subscribe","arg":{"channel":"candle1Dutc","instId":"BTC-EUR"},"connId":"3e5c5e42"}
```
## Error response [DOCS]
```json
{
"id": "1512",
"event": "error",
"code": "60012",
"msg": "Invalid request: {\"op\": \"subscribe\", \"argss\":[{ \"channel\" : \"tickers\", \"instId\" : \"LTC-USD-200327\"}]}",
"connId": "a4d3ae55"
}
```
[LIVE] subscribing `candle1m` on the PUBLIC url (wrong url) -> code 60018 (not 64001):
```json
{"event":"error","msg":"Subscribe failed, wrong URL or channel:candle1m,instId:BTC-EUR doesn't exist. Please use the correct URL, channel and parameters referring to API document.","code":"60018","connId":"53efe456","id":"2"}
```
Main WS error codes [DOCS]: 60012 Invalid request; 60013 Invalid args; 60014 Requests too frequent;
60018 Wrong URL or {0} doesn't exist; 60019 Invalid op; 64001 channel migrated to '/business' URL;
64002 channel not supported by '/business' URL; 64008 connection will close for service upgrade;
64010 port 8443 will be retired. Close frames: 4004 No data received in 30s; 4008/4009 too many
subscribed channels; 1009 message exceeds the maximum frame length.
## Tickers push (channel `tickers`, public URL) [DOCS]
Fastest 1 update / 100 ms; only on trade or best bid/ask change.
```json
{
"arg": {
"channel": "tickers",
"instId": "BTC-USDT"
},
"data": [
{
"instType": "SPOT",
"instId": "BTC-USDT",
"last": "9999.99",
"lastSz": "0.1",
"askPx": "9999.99",
"askSz": "11",
"bidPx": "8888.88",
"bidSz": "5",
"open24h": "9000",
"high24h": "10000",
"low24h": "8888.88",
"volCcy24h": "2222",
"vol24h": "2222",
"sodUtc0": "2222",
"sodUtc8": "2222",
"ts": "1597026383085"
}
]
}
```
[LIVE] BTC-EUR:
```json
{"arg":{"channel":"tickers","instId":"BTC-EUR"},"data":[{"instType":"SPOT","instId":"BTC-EUR","last":"66148.9","lastSz":"0.00010133","askPx":"66134.7","askSz":"0.01847","bidPx":"66129.6","bidSz":"0.0193605","open24h":"66709.6","high24h":"67457","low24h":"65700","sodUtc0":"67082.7","sodUtc8":"67429.6","volCcy24h":"5581463.825401407","vol24h":"83.92407803","ts":"1794318514123"}]}
```
## Candle push (channels `candle1m`, `candle1Dutc`, ..., BUSINESS URL) [DOCS]
Fastest push every 1 s. `data` is an array of arrays
`[ts,o,h,l,c,vol,volCcy,volCcyQuote,confirm]`; `confirm` "0" = in progress, "1" = closed.
Channel names include candle1s, candle1m, candle3m, candle5m, candle15m, candle30m, candle1H, candle2H,
candle4H, candle6H, candle12H, candle1D, candle2D, candle3D, candle5D, candle1W, candle1M, candle3M and the
UTC variants candle6Hutc, candle12Hutc, candle1Dutc, candle2Dutc, candle3Dutc, candle5Dutc, candle1Wutc,
candle1Mutc, candle3Mutc. Note `candle1m` = 1 minute, `candle1M` = 1 month.
```json
{
"arg": {
"channel": "candle1D",
"instId": "BTC-USDT"
},
"data": [
[
"1597026383085",
"8533.02",
"8553.74",
"8527.17",
"8548.26",
"45247",
"529.5858061",
"5529.5858061",
"0"
]
]
}
```
[LIVE] BTC-EUR candle1m:
```json
{"arg":{"channel":"candle1m","instId":"BTC-EUR"},"data":[["1794318480000","66104.2","66148.9","66104.2","66132.7","0.01956494","1293.950829541","1293.950829541","0"]]}
```
## Notices [DOCS + LIVE]
[DOCS] service upgrade, sent 60 s before disconnect:
```json
{
"event": "notice",
"code": "64008",
"msg": "The connection will soon be closed for a service upgrade. Please reconnect.",
"connId": "a4d3ae55"
}
```
[LIVE] connecting to port 8443 (both `wss://wseea.okx.com:8443/ws/v5/public` and
`wss://wseeapap.okx.com:8443/ws/v5/public` still accepted the connection on 2026-11-10 and sent this
once after the handshake; the connection stays open):
```json
{"event":"notice","msg":"WebSocket port 8443 will be retired soon. Please migrate to port 443.","code":"64010","connId":"6a3d66ba"}
```
## Connection count limit [DOCS]
30 connections per channel per sub-account, but ONLY for private channels (orders, account, positions,
balance_and_position, liquidation-warning, account-greeks). Events `channel-conn-count` and
`channel-conn-count-error`. No per-connection limit on public channels is documented beyond the
480 requests/hour, 64 KB args and 3 connections/s per IP rules above.
+242
View File
@@ -0,0 +1,242 @@
using Anubis.Core;
using Anubis.Data;
namespace Anubis.Tests;
/// <summary>Quality checks, freshness, research files and adjusted series (issues #20, #21, #23).</summary>
[TestClass]
public sealed class MarketDataLogicTests
{
private static readonly DateOnly _day0 = new(2026, 1, 1);
/// <summary>A gentle random walk around 100: returns of about ±1%.</summary>
internal static List<DailyBar> Walk(int days, DateOnly? first = null, int seed = 7)
{
var random = new Random(seed);
var bars = new List<DailyBar>();
var close = 100.0;
for (var i = 0; i < days; i++)
{
var open = close;
close = open * (1 + ((random.NextDouble() - 0.5) * 0.02));
bars.Add(new DailyBar((first ?? _day0).AddDays(i), open, Math.Max(open, close) * 1.002, Math.Min(open, close) * 0.998, close, 1000 + i));
}
return bars;
}
[TestMethod]
[TestCategory(Category.Unit)]
public void CleanSeriesHasNoFindings()
{
var bars = Walk(200);
Assert.IsEmpty(QualityChecks.CheckDaily(bars, QualityChecks.EveryDay(bars[0].Day, bars[^1].Day)));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void ChecksFindEachKindOfProblem()
{
var bars = Walk(120);
bars[100] = bars[100] with { Close = bars[99].Close * 1.6, High = bars[99].Close * 1.6 }; // +60% in a day of ±1% days
bars[101] = bars[101] with { Open = bars[100].Close, High = bars[100].Close };
bars[50] = bars[50] with { Low = 0 };
bars[60] = bars[60] with { High = bars[60].Low - 1 };
bars.RemoveAt(30); // a missing day
bars.RemoveAt(30); // and the next one
bars.Add(bars[10]); // a duplicate
var findings = QualityChecks.CheckDaily(bars, QualityChecks.EveryDay(_day0, _day0.AddDays(119)));
var kinds = findings.GroupBy(f => f.Kind).ToDictionary(g => g.Key, g => g.ToList());
Assert.AreEqual(QualityChecks.Midnight(_day0.AddDays(10)), kinds[IssueKinds.Duplicate].Single().StartsAt);
Assert.Contains("identiche", kinds[IssueKinds.Duplicate].Single().Detail);
var gap = kinds[IssueKinds.Gap].Single();
Assert.AreEqual((QualityChecks.Midnight(_day0.AddDays(30)), QualityChecks.Midnight(_day0.AddDays(31))), (gap.StartsAt, gap.EndsAt));
Assert.AreEqual(QualityChecks.Midnight(_day0.AddDays(50)), kinds[IssueKinds.NonPositive].Single().StartsAt);
Assert.AreEqual(QualityChecks.Midnight(_day0.AddDays(60)), kinds[IssueKinds.HighBelowLow].Single().StartsAt);
Assert.IsTrue(kinds[IssueKinds.Jump].Any(f => f.StartsAt == QualityChecks.Midnight(_day0.AddDays(100))), "the 60% jump");
}
[TestMethod]
[TestCategory(Category.Unit)]
public void WeekendsBetweenMissingSessionsDoNotSplitAGap()
{
// Sessions Monday to Friday; Thursday 8, Friday 9 and Monday 12 January are missing: one gap of three sessions.
var sessions = QualityChecks.EveryDay(new DateOnly(2026, 1, 5), new DateOnly(2026, 1, 16))
.Where(d => d.DayOfWeek is not DayOfWeek.Saturday and not DayOfWeek.Sunday).ToList();
var missing = new[] { new DateOnly(2026, 1, 8), new DateOnly(2026, 1, 9), new DateOnly(2026, 1, 12) };
var bars = sessions.Where(d => !missing.Contains(d)).Select(d => new DailyBar(d, 10, 11, 9, 10, 1)).ToList();
var gap = QualityChecks.CheckDaily(bars, sessions).Single();
Assert.AreEqual(IssueKinds.Gap, gap.Kind);
Assert.AreEqual(QualityChecks.Midnight(missing[0]), gap.StartsAt);
Assert.AreEqual(QualityChecks.Midnight(missing[2]), gap.EndsAt);
Assert.Contains("3 giorni", gap.Detail);
}
[TestMethod]
[TestCategory(Category.Unit)]
public void SplitsDoNotLookLikeJumpsOnAdjustedPrices()
{
var bars = Walk(120);
var split = new CorporateAction("TEST", CorporateActionKinds.Split, bars[80].Day, "test", "s") { Ratio = 4m };
var raw = bars.Select((b, i) => i >= 80 ? b with { Open = b.Open / 4, High = b.High / 4, Low = b.Low / 4, Close = b.Close / 4 } : b).ToList();
Assert.IsTrue(QualityChecks.CheckDaily(raw).Any(f => f.Kind == IssueKinds.Jump), "on real prices the split is a jump");
Assert.IsEmpty(QualityChecks.CheckDaily(Adjustments.Anchored(raw, [split], raw[^1].Day)), "on adjusted prices it is not");
}
[TestMethod]
[TestCategory(Category.Unit)]
public void MinuteGapsAreFoundAgainstEveryMinute()
{
var from = new DateTimeOffset(2026, 11, 10, 9, 0, 0, TimeSpan.Zero);
var bars = Enumerable.Range(0, 30).Where(i => i is < 12 or >= 22).Select(i => new Bar(from.AddMinutes(i), 10, 10.1, 9.9, 10, 1)).ToList();
var gap = QualityChecks.CheckMinutes(bars, QualityChecks.EveryMinute(from, from.AddMinutes(30))).Single();
Assert.AreEqual((from.AddMinutes(12), from.AddMinutes(21)), (gap.StartsAt, gap.EndsAt));
Assert.Contains("10 minuti", gap.Detail);
}
[TestMethod]
[TestCategory(Category.Unit)]
public void FreshnessFollowsTheAgeOfTheLastDatum()
{
var clock = new ManualClock(new DateTimeOffset(2026, 11, 10, 9, 0, 0, TimeSpan.Zero));
var bus = new EventBus();
using var events = bus.Subscribe<FreshnessChanged>();
var monitor = new FreshnessMonitor(clock, bus);
var id = Guid.NewGuid();
monitor.Follow(id, "BTC-EUR");
Assert.IsFalse(monitor.IsFresh(id), "no datum yet");
monitor.Touch(id, clock.UtcNow.AddSeconds(-2));
Assert.IsTrue(monitor.IsFresh(id));
Assert.IsTrue(events.TryRead(out var fresh) && fresh!.Fresh);
// The connection stays up but nothing arrives: stale after 60 seconds (trap 10).
clock.Advance(TimeSpan.FromSeconds(58));
monitor.Check();
Assert.IsTrue(monitor.IsFresh(id));
clock.Advance(TimeSpan.FromSeconds(1));
monitor.Check();
Assert.IsFalse(monitor.IsFresh(id));
Assert.IsTrue(events.TryRead(out var stale) && !stale!.Fresh);
// A datum from the venue's future clock counts from now, not later.
monitor.Touch(id, clock.UtcNow.AddMinutes(5));
clock.Advance(TimeSpan.FromSeconds(61));
Assert.IsFalse(monitor.IsFresh(id));
Assert.IsFalse(monitor.IsFresh(Guid.NewGuid()), "an instrument not followed is never fresh");
}
[TestMethod]
[TestCategory(Category.Unit)]
public async Task ResearchFilesRoundTripWithoutLosingDecimals()
{
var folder = TempFolder.Create("research");
try
{
var store = new ResearchStore(folder);
var t0 = new DateTimeOffset(2017, 12, 31, 23, 58, 0, TimeSpan.Zero);
var bars = new[]
{
new ResearchBar(t0, 13850.01000000m, 13869.99m, 13800.00000001m, 13855m, 1.23456789m) { QuoteVolume = 17104.5m, Trades = 42 },
new ResearchBar(t0.AddMinutes(1), 0.00000001m, 79228162514264.337593543950m, 0.1m, 0.3m, 0m),
new ResearchBar(t0.AddMinutes(2), 13855m, 13860m, 13850m, 13851.5m, 2m) { QuoteVolume = 27704m },
};
await store.WriteAsync(Venues.Binance, "BTCUSDT", Timeframes.Minute, bars, CancellationToken.None).ConfigureAwait(false);
CollectionAssert.AreEqual(new[] { 2017, 2018 }, store.Years(Venues.Binance, "BTCUSDT", Timeframes.Minute).ToArray(), "one file per year");
var read = new List<ResearchBar>();
await foreach (var bar in store.ReadAsync(Venues.Binance, "BTCUSDT", Timeframes.Minute, t0, t0.AddDays(1)).ConfigureAwait(false))
{
read.Add(bar);
}
CollectionAssert.AreEqual(bars, read);
Assert.AreEqual("13850.01", read[0].Open.ToString(System.Globalization.CultureInfo.InvariantCulture), "trailing zeros dropped, digits kept");
// Writing again merges: the same minute is replaced, new ones are added.
await store.WriteAsync(Venues.Binance, "BTCUSDT", Timeframes.Minute, [bars[0] with { Close = 1m }, bars[0] with { OpensAt = t0.AddMinutes(-1) }], CancellationToken.None)
.ConfigureAwait(false);
read.Clear();
await foreach (var bar in store.ReadAsync(Venues.Binance, "BTCUSDT", Timeframes.Minute, t0.AddHours(-1), t0.AddDays(1)).ConfigureAwait(false))
{
read.Add(bar);
}
Assert.HasCount(4, read);
Assert.AreEqual(1m, read[1].Close);
CollectionAssert.Contains(store.Series().ToList(), (Venues.Binance, "BTCUSDT", Timeframes.Minute));
Assert.AreEqual("BTC_EUR", ResearchStore.Safe("BTC/EUR"));
Assert.AreEqual("__", ResearchStore.Safe(".."));
}
finally
{
TempFolder.Delete(folder);
}
}
[TestMethod]
[TestCategory(Category.Unit)]
public void SyntheticSplitKeepsTheAnchoredSeriesContinuousAndConvertsLevels()
{
// 2-for-1 split on day 50: real prices halve, the anchored adjusted series does not jump.
var adjustedTruth = Walk(80);
var exDay = adjustedTruth[50].Day;
var split = new CorporateAction("TEST", CorporateActionKinds.Split, exDay, "test", "split-1") { Ratio = 2m };
var raw = adjustedTruth.Select((b, i) => i < 50 ? b with { Open = b.Open * 2, High = b.High * 2, Low = b.Low * 2, Close = b.Close * 2, Volume = b.Volume / 2 } : b).ToList();
// On the day before the split, nobody knew it: the anchored series is the real one.
var before = Adjustments.Anchored(raw, [split], exDay.AddDays(-1));
Assert.HasCount(50, before);
Assert.IsTrue(before.All(b => b.Adjusted == b.Prices));
// From the ex-date on, older prices are halved and volumes doubled; the last price equals the real one.
var after = Adjustments.Anchored(raw, [split], raw[^1].Day);
Assert.AreEqual(raw[^1].Close, after[^1].Adjusted!.Value.Close);
for (var i = 0; i < after.Count; i++)
{
Assert.AreEqual(adjustedTruth[i].Close, after[i].Adjusted!.Value.Close, 1e-9);
Assert.AreEqual(adjustedTruth[i].Volume, after[i].Volume, 1e-9);
}
// Saved levels and quantities across the split: a stop at 180 becomes 90, 3 shares become 6.
Assert.AreEqual(90m, Adjustments.ConvertLevel(180m, split, null));
Assert.AreEqual(6m, Adjustments.ConvertQuantity(3m, split));
var reverse = split with { Ratio = 0.1m };
Assert.AreEqual(1800m, Adjustments.ConvertLevel(180m, reverse, null));
Assert.AreEqual(0.3m, Adjustments.ConvertQuantity(3m, reverse));
// Without the corporate actions endpoint the split is recognised from the real and adjusted series.
var withSource = raw.Select((b, i) => b with { Adjusted = adjustedTruth[i].Prices }).ToList();
var detected = Adjustments.Detect("TEST", withSource).Single();
Assert.AreEqual((CorporateActionKinds.Split, exDay, (decimal?)2m), (detected.Kind, detected.ExDate, detected.Ratio));
// The backtest view at day 30 is the final adjusted series rescaled to the real price of day 30.
var view = Adjustments.RescaledAt(withSource, raw[30].Day);
Assert.HasCount(31, view);
Assert.AreEqual(raw[30].Close, view[^1].Close, 1e-9);
Assert.AreEqual(raw[10].Close, view[10].Close, 1e-9);
}
[TestMethod]
[TestCategory(Category.Unit)]
public void CashDividendsAdjustOlderPricesButNotQuantities()
{
var raw = Walk(10);
var exDay = raw[5].Day;
var dividend = new CorporateAction("TEST", CorporateActionKinds.CashDividend, exDay, "test", "div-1") { CashAmount = 1m };
var closeBefore = raw[4].Close;
var anchored = Adjustments.Anchored(raw, [dividend], raw[^1].Day);
var factor = (closeBefore - 1) / closeBefore;
Assert.AreEqual(raw[4].Close * factor, anchored[4].Adjusted!.Value.Close, 1e-9);
Assert.AreEqual(raw[5].Close, anchored[5].Adjusted!.Value.Close);
Assert.AreEqual(raw[4].Volume, anchored[4].Volume, "a dividend does not touch volumes");
Assert.AreEqual(5m, Adjustments.ConvertQuantity(5m, dividend));
Assert.AreEqual(99m, Adjustments.ConvertLevel(100m, dividend, 100m));
var detected = Adjustments.Detect("TEST", anchored.Select((b, i) => raw[i] with { Adjusted = b.Adjusted }).ToList()).Single();
Assert.AreEqual(CorporateActionKinds.CashDividend, detected.Kind);
Assert.AreEqual(1m, Math.Round(detected.CashAmount!.Value, 2));
}
}
+119
View File
@@ -0,0 +1,119 @@
using Anubis.Core;
using Anubis.Data;
namespace Anubis.Tests;
/// <summary>Instrument catalogue, bar storage and the issue register on the engine of this run (issues #18, #20).</summary>
[TestClass]
public sealed class MarketDataStoreTests
{
private static readonly DateTimeOffset _start = new(2026, 11, 10, 8, 0, 0, TimeSpan.Zero);
internal static InstrumentSpec Okx(string symbol, string status = "live") =>
new(Venues.Okx, symbol, symbol, AssetClasses.Crypto, "EUR")
{
BaseCurrency = symbol.Split('-')[0],
TickSize = 0.1m,
LotSize = 0.00000001m,
MinSize = 0.00001m,
Status = status,
ListedAt = new DateTimeOffset(2023, 11, 21, 4, 11, 0, TimeSpan.Zero),
};
[TestMethod]
[TestCategory(Category.Integration)]
public async Task CatalogueAddsUpdatesAndKeepsDelistedInstruments()
{
var clock = new ManualClock(_start);
await using var test = await DatabaseTests.MigratedAsync().ConfigureAwait(false);
var catalog = new InstrumentCatalog(test.Db, clock);
var first = await catalog.SyncAsync(Venues.Okx, [Okx("BTC-EUR"), Okx("ETH-EUR")], complete: true, CancellationToken.None).ConfigureAwait(false);
Assert.AreEqual(new InstrumentCatalog.SyncResult(2, 0, 0), first);
var btc = await catalog.FindAsync(Venues.Okx, "BTC-EUR", CancellationToken.None).ConfigureAwait(false);
Assert.IsNotNull(btc);
Assert.AreEqual(0.00000001m, btc.Spec.LotSize, "the rules keep every decimal");
Assert.AreEqual(Okx("BTC-EUR"), btc.Spec);
// The next day the tick changes and ETH is gone from the list.
clock.Advance(TimeSpan.FromDays(1));
var second = await catalog.SyncAsync(Venues.Okx, [Okx("BTC-EUR") with { TickSize = 1m }], complete: true, CancellationToken.None).ConfigureAwait(false);
Assert.AreEqual(new InstrumentCatalog.SyncResult(0, 1, 1), second);
var eth = await catalog.FindAsync(Venues.Okx, "ETH-EUR", CancellationToken.None).ConfigureAwait(false);
Assert.AreEqual(InstrumentCatalog.Delisted, eth!.Spec.Status);
Assert.IsFalse(eth.IsLive);
Assert.AreEqual(1m, (await catalog.GetAsync(btc.Id, CancellationToken.None).ConfigureAwait(false))!.Spec.TickSize);
// Nothing changed: nothing is written.
Assert.AreEqual(new InstrumentCatalog.SyncResult(0, 0, 0),
await catalog.SyncAsync(Venues.Okx, [Okx("BTC-EUR") with { TickSize = 1m }], complete: true, CancellationToken.None).ConfigureAwait(false));
}
[TestMethod]
[TestCategory(Category.Integration)]
public async Task DailyAndMinuteBarsRoundTripAndUpsert()
{
var clock = new ManualClock(_start);
await using var test = await DatabaseTests.MigratedAsync().ConfigureAwait(false);
var instrument = await new InstrumentCatalog(test.Db, clock).EnsureAsync(Okx("BTC-EUR"), CancellationToken.None).ConfigureAwait(false);
var store = new BarStore(test.Db, clock);
var day = new DateOnly(2026, 11, 9);
var bars = new[]
{
new DailyBar(day.AddDays(-1), 67000.1, 67500.25, 66000, 67082.7, 12.345678901) { QuoteVolume = 828_000.5 },
new DailyBar(day, 67082.7, 68000, 66900.9, 67900, 10.5) { Adjusted = new Ohlc(1, 2, 0.5, 1.5) },
};
await store.UpsertDailyAsync(instrument.Id, bars, "okx", CancellationToken.None).ConfigureAwait(false);
var read = await store.DailyAsync(instrument.Id, day.AddDays(-5), day, CancellationToken.None).ConfigureAwait(false);
CollectionAssert.AreEqual(bars, read.ToArray());
Assert.AreEqual(day, await store.LastDayAsync(instrument.Id, CancellationToken.None).ConfigureAwait(false));
Assert.AreEqual(day.AddDays(-1), await store.FirstDayAsync(instrument.Id, CancellationToken.None).ConfigureAwait(false));
// A second download of the same day replaces it.
await store.UpsertDailyAsync(instrument.Id, [bars[1] with { Close = 67950, Quality = BarQuality.Confirmed }], "okx", CancellationToken.None).ConfigureAwait(false);
Assert.AreEqual(2, await store.CountDailyAsync(instrument.Id, CancellationToken.None).ConfigureAwait(false));
var replaced = (await store.DailyAsync(instrument.Id, day, day, CancellationToken.None).ConfigureAwait(false)).Single();
Assert.AreEqual(67950, replaced.Close);
Assert.AreEqual(BarQuality.Confirmed, replaced.Quality);
var minute = new DateTimeOffset(2026, 11, 10, 7, 0, 0, TimeSpan.Zero);
var minutes = Enumerable.Range(0, 3).Select(i => new Bar(minute.AddMinutes(i), 1 + i, 2 + i, 0.5 + i, 1.5 + i, 3)).ToList();
await store.UpsertMinuteAsync(instrument.Id, minutes, "okx", BarQuality.Ok, CancellationToken.None).ConfigureAwait(false);
await store.UpsertMinuteAsync(instrument.Id, minutes.Take(1), "okx", BarQuality.Ok, CancellationToken.None).ConfigureAwait(false);
CollectionAssert.AreEqual(minutes, (await store.MinuteAsync(instrument.Id, minute, minute.AddHours(1), CancellationToken.None).ConfigureAwait(false)).ToArray());
Assert.AreEqual(minute.AddMinutes(2), await store.LastMinuteAsync(instrument.Id, CancellationToken.None).ConfigureAwait(false));
// One-minute bars older than 400 days go.
clock.Set(minute.AddDays(400).AddMinutes(1).AddSeconds(30));
Assert.AreEqual(2, await store.PruneMinutesAsync(CancellationToken.None).ConfigureAwait(false));
}
[TestMethod]
[TestCategory(Category.Integration)]
public async Task IssuesAreRecordedOnceAndBlockEntriesUntilResolved()
{
var clock = new ManualClock(_start);
await using var test = await DatabaseTests.MigratedAsync().ConfigureAwait(false);
var instrument = await new InstrumentCatalog(test.Db, clock).EnsureAsync(Okx("SOL-EUR"), CancellationToken.None).ConfigureAwait(false);
var issues = new DataIssueStore(test.Db, clock);
var at = new DateTimeOffset(2026, 11, 9, 0, 0, 0, TimeSpan.Zero);
var jump = new QualityFinding(IssueKinds.Jump, at, at, "salto");
var id = await issues.RecordAsync(instrument.Id, Timeframes.Day, jump, CancellationToken.None).ConfigureAwait(false);
Assert.AreEqual(id, await issues.RecordAsync(instrument.Id, Timeframes.Day, jump, CancellationToken.None).ConfigureAwait(false), "the same open finding is not added twice");
await issues.RecordAsync(null, Timeframes.Minute, new QualityFinding(IssueKinds.Gap, at, at.AddMinutes(9), "buco"), CancellationToken.None).ConfigureAwait(false);
CollectionAssert.AreEquivalent(new[] { instrument.Id }, (await issues.BlockedInstrumentsAsync(CancellationToken.None).ConfigureAwait(false)).ToArray());
await issues.AttemptAsync(id, CancellationToken.None).ConfigureAwait(false);
await issues.ResolveAsync(id, IssueStatus.Confirmed, null, CancellationToken.None).ConfigureAwait(false);
Assert.IsEmpty(await issues.BlockedInstrumentsAsync(CancellationToken.None).ConfigureAwait(false));
var all = await issues.SinceAsync(at, CancellationToken.None).ConfigureAwait(false);
Assert.HasCount(2, all);
var resolved = all.Single(i => i.Id == id);
Assert.AreEqual(1, resolved.Attempts);
Assert.AreEqual(IssueStatus.Confirmed, resolved.Status);
Assert.AreEqual("salto", resolved.Detail);
}
}
+12 -3
View File
@@ -53,6 +53,8 @@ public sealed partial class SecretScanTests
Assert.IsFalse(LooksLikeSecret("REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}"));
Assert.IsFalse(LooksLikeSecret("private const string SecretKeyVariable = \"ANUBIS_SECRET_KEY\";"));
Assert.IsFalse(LooksLikeSecret("OKX_API_PASSPHRASE=<passphrase-123>"));
Assert.IsFalse(LooksLikeSecret(" \"next_page_token\": \"QUFQTHxNfDIwMjItMDEtMDNUMDk6MDA6MDAuMDAwMDAwMDAwWg==\""));
Assert.IsTrue(LooksLikeSecret("{\"next_page_token\": null, \"api_key\": \"AKZXCVBNMASDFGHJKLQWERTY12\"}"), "a cursor does not hide a key on the same line");
// Code that assigns a computed value is not a secret.
Assert.IsFalse(LooksLikeSecret("var key = RandomNumberGenerator.GetBytes(32);"));
@@ -60,9 +62,16 @@ public sealed partial class SecretScanTests
Assert.IsFalse(LooksLikeSecret("?secret={Base32.Encode(secret)}&issuer=x"));
}
private static bool LooksLikeSecret(string line) =>
PrivateKey().IsMatch(line) || BrokerHeader().IsMatch(line) || TelegramToken().IsMatch(line) || GenericSecret().IsMatch(line)
|| NamedSecret().Matches(line).Any(m => !IsPlaceholder(m.Groups["value"].Value));
private static bool LooksLikeSecret(string line)
{
// Pagination cursors of the APIs (Alpaca's next_page_token in the recorded responses) are not credentials.
line = PageCursor().Replace(line, "");
return PrivateKey().IsMatch(line) || BrokerHeader().IsMatch(line) || TelegramToken().IsMatch(line) || GenericSecret().IsMatch(line)
|| NamedSecret().Matches(line).Any(m => !IsPlaceholder(m.Groups["value"].Value));
}
[GeneratedRegex("""(?i)["']?(next_)?page_token["']?\s*[:=]\s*["']?[A-Za-z0-9/+=_\-]*["']?""")]
private static partial Regex PageCursor();
// Example values in .env.example, compose files and the CI are clearly fake.
private static bool IsPlaceholder(string value) =>