File size: 18,899 Bytes
5b8bfb9 ff18f05 5b8bfb9 7c9672f 5b8bfb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | ---
language:
- en
license: other
tags:
- cryptocurrency
- order-book
- level2
- timescaledb
- postgres
- coinbase
- financial-data
- cbb26
- market-microstructure
pretty_name: CBB26 Timescale Market Data (Coinbase L2 replay shards)
size_categories:
- 10G<n<100G
---
# CBB26 Timescale market data (`cbb26-timeseries-db`)
Public **Timescale/Postgres replay shards** for the [cbb26](https://github.com/deusmos/cbb26) monorepo: canonical Coinbase Advanced Trade **level-2 order book** history stored in the `market_data` schema, packaged as restorable `pg_dump` files for research, corpus materialization, and reproducibility.
**Canonical Hub repo:** [`deusmos/cbb26-timeseries-db`](https://huggingface.co/datasets/deusmos/cbb26-timeseries-db)
**Source-of-truth for this card (edit here, then publish):** `docs/datasets/cbb26-timeseries-db/README.md` in the cbb26 git repo.
---
## Start here
| I want… | Use this |
|---------|----------|
| ML tensors / training corpus | [`cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1) — [Path A Quickstart](https://github.com/deusmos/cbb26/blob/main/docs/standards/QUICKSTART.md#path-a--use-pre-materialized-corpus-1015-min) |
| Raw L2 replay / own materialize | **This repo** — restore + materialize ([Path B](https://github.com/deusmos/cbb26/blob/main/docs/standards/QUICKSTART.md#path-b--restore-replay-shards--materialize-one-day-advanced-hours), hours) |
| Run a live collector | [cbb26 repo](https://github.com/deusmos/cbb26) + [local Docker stack](https://github.com/deusmos/cbb26/blob/main/docs/standards/QUICKSTART.md#path-c--run-your-own-collector-days) |
> **Not a row-oriented HF dataset.** Files are `pg_dump` shards and JSON sidecars. **Do not expect `load_dataset()`** to return tabular rows. Use `hf download` + the restore workflow below.
> **NDDS** = *Normalized Decimated Day Slabs* — 10-second decimated, loader-normalized tensor slabs cached under `_ndds_cache/` (~300 MiB/day on Hub). For pre-built NDDS bundles use [`cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1). Implementation: [`libs/day_raster_corpus/ndds_cache.py`](https://github.com/deusmos/cbb26/blob/main/libs/day_raster_corpus/ndds_cache.py).
---
## Why replay shards?
Timescale replay is **base truth** for what happened on the Coinbase L2 order book: checkpoints, anchors, and per-second deltas with carry-forward semantics. Materializing to tensors is **lossy** — bucket sizes, normalization, and decimation are design choices, not facts stored in the exchange feed.
Publishing replay as restorable `pg_dump` shards lets you pick **your own** materialization profile instead of being locked into the maintainer's. [`cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1) is the fast path when you want our standard geometry; **this repo** is for when you need fidelity and flexibility. Restore + materialize takes longer — that is an intentional tradeoff.
| Layer | Fidelity | User flexibility |
|-------|----------|------------------|
| **This dataset** (replay) | Lossless L2 replay truth | Choose resolution, buckets, normalization |
| Day corpus / NDDS on Hub | Lossy, fixed profile | Fast path for one training geometry |
---
## What this dataset is
This is **not** a training corpus of pre-built tensors. It is the **raw replay layer** that cbb26 services write and read before materialization:
| Layer | What it is | Where it lives |
|-------|------------|----------------|
| **This dataset** | Timescale `market_data` replay tables, one shard per UTC day × product | HF `data/{YYYY-MM-DD}/{PRODUCT}.dump` |
| **Materialized corpus** | Day-bundle rasters derived from replay | Local disk or [`deusmos/cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1) |
| **Training run** | Checkpoints, TensorBoard, eval metrics | Separate HF model repos / local `tmp/` |
### Schema (`market_data`)
Each shard exports the four **core replay tables** required for deterministic order-book replay in cbb26:
| Table | Role |
|-------|------|
| `orderbook_second_deltas` | One row per `(product_id, UTC second)` where the end-of-second book changed vs. the last persisted second |
| `orderbook_replay_anchors` | Full retained L2 book at anchor seconds (includes baseline anchor at or before day start) |
| `orderbook_checkpoints` | Full retained L2 book once per product per UTC hour |
| `orderbook_replay_metadata` | Operational replay continuity / gap metadata (not source of truth for book state) |
DDL and migrations ship in-repo on the dataset:
- `migrations/0001_init.sql` … `0004_replay_metadata_window_end_index.sql`
- `schema/market_data_schema.dump` — schema-only `pg_dump -Fc` for empty restores
Hypertables use TimescaleDB 2.x on **Postgres 16**. See `services/timeseries-db/migrations/` in cbb26 for the live definition.
### Products (20)
Shards use Coinbase product ids (`BASE-QUOTE`):
`AAVE-USD`, `ADA-USD`, `APT-USD`, `ATOM-USD`, `AVAX-USD`, `BCH-USD`, `BTC-USD`, `DOGE-USD`, `DOT-USD`, `ETH-USD`, `HBAR-USD`, `LINK-USD`, `LTC-USD`, `NEAR-USD`, `PEPE-USD`, `SHIB-USD`, `SOL-USD`, `UNI-USD`, `XLM-USD`, `XRP-USD`
This matches the default **`MARKET_COLLECTOR_PRODUCTS`** basket in `deploy/compose/slice-a.yml`.
### Coverage snapshot (live)
<!-- COVERAGE:START -->
| Metric | Value |
|--------|-------|
| **Last verified** | 2026-05-25 22:41 UTC |
| **Hub revision** | `b6c9773744ca346dba5c37c05939349f1ae3225e` |
| **Shard files (`.dump`)** | 1220 |
| **UTC days with ≥1 shard** | 61 |
| **Days with 20/20 products** | 61 |
| **Distinct products** | 20 |
| **Date span** | `2024-12-01` → `2026-05-25` |
| **Manifest DB bytes (operator snapshot)** | 111622336995 (~104.0 GiB) |
Refresh: `uv run python scripts/generate_hf_dataset_coverage.py --update-readme`
<!-- COVERAGE:END -->
Each shard sidecar (`data/.../{product}.json`) records `row_counts`, `dump_size_bytes`, and UTC day bounds (`cbb26_timeseries_shard_manifest_v1`).
---
## Data dictionary (replay rows)
Full contract: [`docs/standards/specs/STORAGE_REPLAY.md`](https://github.com/deusmos/cbb26/blob/main/docs/standards/specs/STORAGE_REPLAY.md) · JSON source: [`libs/contracts/storage_and_snapshot_spec.json`](https://github.com/deusmos/cbb26/blob/main/libs/contracts/storage_and_snapshot_spec.json)
| Column | Type | Meaning |
|--------|------|---------|
| `product_id` | TEXT | Coinbase product, e.g. `BTC-USD` |
| `changed_second` | TIMESTAMPTZ | UTC second truncated; primary key with `product_id` |
| `source_sequence_num_start` / `_end` | BIGINT | L2 sequence range incorporated in this second |
| `best_bid` / `best_ask` | NUMERIC | End-of-second BBO after applying `changes` |
| `changes` | JSONB | Array of `[side, price, new_quantity]` — `bid` or `offer`; quantity `0` removes level |
| `change_count` | INTEGER | Length of `changes` array |
**Example `orderbook_second_deltas` row** (sanitized static illustration):
```json
{
"product_id": "BTC-USD",
"changed_second": "2024-12-01T12:34:56+00:00",
"source_sequence_num_start": 9876543210,
"source_sequence_num_end": 9876543299,
"best_bid": "96543.21000000",
"best_ask": "96543.22000000",
"changes": [
["bid", "96540.00", "1.25000000"],
["offer", "96543.22", "0.50000000"],
["offer", "96544.00", "0"]
],
"change_count": 3
}
```
---
## Repository layout
```text
deusmos/cbb26-timeseries-db/
├── README.md ← dataset card (this file on Hub)
├── backup_manifest.json ← export inventory + restore notes (updated at bootstrap)
├── schema/
│ └── market_data_schema.dump ← schema-only pg_dump (market_data)
├── migrations/
│ ├── 0001_init.sql
│ ├── 0002_checkpoint_delta_upgrade.sql
│ ├── 0003_replay_anchor_support.sql
│ └── 0004_replay_metadata_window_end_index.sql
└── data/
└── {YYYY-MM-DD}/
├── {PRODUCT}.dump ← pg_dump -Fc (core-replay tables for that day+product)
└── {PRODUCT}.json ← shard sidecar (row counts, sizes)
```
### Naming conventions
- **`{YYYY-MM-DD}`** — UTC calendar **trade date** (inclusive day window `00:00:00` … `23:59:59` UTC).
- **`{PRODUCT}`** — uppercase Coinbase id, e.g. `BTC-USD` (regex `^[A-Z0-9]+-[A-Z0-9]+$`).
- **One Hub commit per shard** during sync upload (rate-limit friendly; ~30 s spacing).
### Manifests and revision pinning
| File | Purpose |
|------|---------|
| `backup_manifest.json` | Dataset-level manifest (`cbb26_timeseries_db_backup_manifest_v2`): scope, table list, row counts, time ranges, restore notes, migration list |
| `data/.../*.json` | Per-shard sidecar with `row_counts` and `dump_size_bytes` |
| **Git revision SHA** | Pin downloads with `HF_TIMESERIES_DATASET_REVISION=<sha>` or `hf download … --revision <sha>` |
There are **no separate checksum files**; verify restores with sidecar `row_counts`, `pg_restore` exit code, and `scripts/smoke_restore_hf_shard.sh`.
---
## Download and restore
### Quick inspect (no Postgres)
```bash
git clone https://github.com/deusmos/cbb26.git && cd cbb26
./examples/download_one_timeseries_shard.sh
```
### Prerequisites
- Docker (for `pg_dump`/`pg_restore` client **Postgres 16** — use image `pgvector/pgvector:pg16` or `timescale/timescaledb:2.14.2-pg16`)
- A running Postgres 16 + TimescaleDB target (see [Run your own collector](#run-your-own-collector-local-docker-stack) below)
- [Hugging Face CLI](https://huggingface.co/docs/huggingface_hub/guides/cli): `uv run hf auth login` or `HF_TOKEN` in environment
### Download
**Full dataset** (large):
```bash
export HF_TOKEN=... # optional for public repo; required for uploads
uv run hf download deusmos/cbb26-timeseries-db --repo-type dataset --local-dir ./cbb26-timeseries-db
```
**Pin a revision** (recommended for reproducible materialization):
```bash
export HF_TIMESERIES_DATASET_REVISION=b6c9773744ca346dba5c37c05939349f1ae3225e # example; get latest from Hub
uv run hf download deusmos/cbb26-timeseries-db \
--repo-type dataset \
--revision "$HF_TIMESERIES_DATASET_REVISION" \
--local-dir ./cbb26-timeseries-db
```
**Single day / product**:
```bash
uv run hf download deusmos/cbb26-timeseries-db \
--repo-type dataset \
--include "data/2024-12-01/BTC-USD.*" \
--local-dir ./cbb26-timeseries-db
```
Python (`huggingface_hub`):
```python
import os
from huggingface_hub import snapshot_download
path = snapshot_download(
repo_id="deusmos/cbb26-timeseries-db",
repo_type="dataset",
revision=os.environ["HF_TIMESERIES_DATASET_REVISION"], # pin SHA
allow_patterns=["data/2024-12-01/*", "migrations/*", "schema/*"],
)
```
### Restore workflow
1. **Start Timescale** with an empty or compatible database (see collector section).
2. **Apply migrations** if the volume is fresh:
```bash
# migrations are in the downloaded tree under migrations/
psql -h 127.0.0.1 -U cbb26 -d cbb26 -f migrations/0001_init.sql
# … or rely on docker-entrypoint-initdb.d on first volume init
```
3. **Restore schema** (if needed):
```bash
docker run --rm --network host \
-e PGPASSWORD="$POSTGRES_PASSWORD" \
-v "$PWD/cbb26-timeseries-db:/in" \
pgvector/pgvector:pg16 \
pg_restore -h 127.0.0.1 -p 5432 -U cbb26 -d cbb26 --schema-only \
/in/schema/market_data_schema.dump
```
4. **Restore one shard** (data-only into staging schema):
```bash
scripts/smoke_restore_hf_shard.sh \
--shard-dir ./cbb26-timeseries-db \
--date 2024-12-01 --product BTC-USD
```
Or manually with `pg_restore` + merge SQL (see script for merge statements).
5. **Verify** sidecar expectations — script **fails closed** on row-count mismatch vs sidecar.
> **Replay invariant:** Each shard includes the **baseline replay anchor at or before** `day_start_utc`. Without it, same-day replay cannot be reconstructed.
---
## Run your own collector (local Docker stack)
You can collect the same schema locally and later upload missing shards (see [Contributing](#contributing-missing-shards-and-days)).
### Prerequisites
- Docker + Docker Compose
- Linux or macOS host with ~50+ GiB free for sustained multi-product collection
- Network access to Coinbase Advanced Trade websocket
### 1. Configure environment
From the cbb26 repo root:
```bash
cp .env.example .env
# Edit POSTGRES_PASSWORD, optional ports, and MARKET_COLLECTOR_PRODUCTS
```
Key variables (see `.env.example` and `deploy/compose/slice-a.yml`):
| Variable | Default | Purpose |
|----------|---------|---------|
| `POSTGRES_DB` | `cbb26` | Database name |
| `POSTGRES_USER` | `cbb26` | Database user |
| `POSTGRES_PASSWORD` | `change-me` | **Change in production** |
| `POSTGRES_PORT` | `5432` | Host-published Postgres port |
| `MARKET_COLLECTOR_PRODUCTS` | 20-product CSV | Coinbase products to subscribe |
| `MARKET_COLLECTOR_PORT` | `8080` | Collector HTTP / metrics |
| `TENSOR_MATERIALIZER_PORT` | `8081` | Materializer API |
Inside Compose containers, services use `DB_HOST=timeseries-db` (not `localhost`).
### 2. Start the stack
```bash
scripts/up_slice_a.sh
scripts/check_slice_a.sh
```
Services: `timeseries-db`, `market-collector`, `tensor-materializer`, `prometheus`, `grafana`.
### 3. Verify health
Expected endpoints:
- Collector: `http://localhost:8080/healthz`, `http://localhost:8080/readyz`
- Materializer: `http://localhost:8081/healthz`
After the collector runs, confirm replay rows exist:
```bash
DB_HOST=localhost DB_PORT=5432 uv run python scripts/_timeseries_db_hf_backup.py inventory --scope core-replay
```
Internal runbook: [`docs/runbooks/slice-a.md`](https://github.com/deusmos/cbb26/blob/main/docs/runbooks/slice-a.md).
---
## Contributing missing shards and days
See [`docs/standards/CONTRIBUTING_DATA.md`](https://github.com/deusmos/cbb26/blob/main/docs/standards/CONTRIBUTING_DATA.md) (operator guide).
The dataset grows by **incremental sync** from contributors with a populated Timescale instance. Uploads are **idempotent**: shards already on Hub are skipped.
```bash
export HF_TIMESERIES_DATASET_REPO=deusmos/cbb26-timeseries-db
scripts/upload_timeseries_db_to_hf.sh --sync \
--start-date 2026-05-22 --end-date 2026-05-31
```
---
## Tools for researchers
This repo is **replay truth**, not pre-rendered tensors. To **see** what NDDS windows look like without restoring Postgres, use the day-corpus tooling:
| Tool | Link |
|------|------|
| Preview PNG + gallery | [`examples/preview_corpus_day.sh`](https://github.com/deusmos/cbb26/blob/main/examples/preview_corpus_day.sh) on [`cbb26-day-corpus-v1`](../cbb26-day-corpus-v1/README.md) |
| PyTorch DataLoader | [`libs/day_raster_corpus/pytorch_loader.py`](https://github.com/deusmos/cbb26/blob/main/libs/day_raster_corpus/pytorch_loader.py) |
| Hub thumbnails | [`previews/`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1/tree/main/previews) on day-corpus |
| Live peek | [HF Space `deusmos/cbb26-corpus-peek`](https://huggingface.co/spaces/deusmos/cbb26-corpus-peek) |
Raw shard preview without Postgres restore is **not shipped in v1** — restore + materialize (Path B) or use day-corpus previews. See [shared FAQ](../_shared/FAQ.md#why-cant-i-preview-timeseries-shards-directly).
---
## FAQ
### Can I use this commercially?
Market data is governed by [Coinbase market data terms](https://www.coinbase.com/legal/market-data-terms). Software and schema in cbb26 are [MIT licensed](https://github.com/deusmos/cbb26/blob/main/LICENSE). Not legal advice.
### Why Postgres dumps not Parquet?
Replay fidelity requires full L2 book state. See [ADR-003](https://github.com/deusmos/cbb26/blob/main/docs/standards/adr/003-pgdump-shards-vs-parquet.md).
### Why two datasets?
Raw replay (this repo) vs materialized NDDS day bundles ([`cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1)).
### How complete is UTC day X?
**20/20 products** under `data/{YYYY-MM-DD}/`; sidecar `orderbook_second_deltas` ≈ **86400** for a full continuous day.
### How do I cite this?
```bibtex
@dataset{cbb26_timeseries_db,
title = {CBB26 Coinbase L2 Order Book Replay Shards},
author = {deusmos},
year = {2026},
url = {https://huggingface.co/datasets/deusmos/cbb26-timeseries-db}
}
```
### Is this affiliated with Coinbase?
No. Independent research project using public market feeds.
Full FAQ source: [`docs/datasets/_shared/FAQ.md`](https://github.com/deusmos/cbb26/blob/main/docs/datasets/_shared/FAQ.md).
---
## Licensing and data use
- **Software / schema / scripts:** [MIT License](https://github.com/deusmos/cbb26/blob/main/LICENSE) (cbb26 repository).
- **Market data:** sourced from Coinbase public market feeds. Respect [Coinbase market data terms](https://www.coinbase.com/legal/market-data-terms). Provided for research and reproducibility **without warranty**.
Policy: [`docs/standards/DATA_USE_POLICY.md`](https://github.com/deusmos/cbb26/blob/main/docs/standards/DATA_USE_POLICY.md).
---
## Related (downstream)
Restoring HF shards into local Timescale lets you **materialize new days/products** without operator infrastructure. Pre-built **NDDS day bundles** for cloud training live in **`deusmos/cbb26-day-corpus-v1`**.
```mermaid
flowchart LR
CB[Coinbase L2 websocket] --> MC[market-collector]
MC --> TS[(timeseries-db / market_data)]
TS --> TM[tensor-materializer / materialize scripts]
TM --> CORP[Corpus artifacts]
TS --> HF[(HF timeseries shards)]
CORP --> HFC[(HF day-corpus-v1 NDDS)]
CORP --> TR[train_latent_encoder.py]
```
Materialization entrypoints: `scripts/materialize_valid_day_bundles.py`, `scripts/materialize_free_tardis_17d_day_bundles.py`. Training: `scripts/train_latent_encoder.py` (v2 contract). Vast/JOJAT runbook: [`docs/runbooks/vast_jojat_training.md`](https://github.com/deusmos/cbb26/blob/main/docs/runbooks/vast_jojat_training.md).
---
## References
| Resource | Location |
|----------|----------|
| **Orderbook data standards (v1)** | `docs/standards/README.md` |
| **Examples** | `examples/download_one_timeseries_shard.sh` |
| cbb26 repo | GitHub `deusmos/cbb26` |
| Upload entrypoint | `scripts/upload_timeseries_db_to_hf.sh` |
| Coverage refresh | `scripts/generate_hf_dataset_coverage.py` |
| Materialized training corpus (NDDS) | [`deusmos/cbb26-day-corpus-v1`](https://huggingface.co/datasets/deusmos/cbb26-day-corpus-v1) |
| Publish this README to Hub | `scripts/publish_timeseries_dataset_readme.sh` |
---
## Changelog
| Date | Notes |
|------|-------|
| 2026-05-25 | A+++ upgrade: decision tree, live coverage, restore smoke enforcement, FAQ, BibTeX |
| 2026-05-25 | Initial public dataset card (shards `2024-12-01`+, 20 products, core-replay export) |
|