dccd 3.6.3__tar.gz → 3.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. {dccd-3.6.3 → dccd-3.8.0}/CHANGELOG.md +54 -0
  2. {dccd-3.6.3 → dccd-3.8.0}/CLAUDE.md +26 -54
  3. {dccd-3.6.3 → dccd-3.8.0}/PKG-INFO +1 -1
  4. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/config.py +8 -5
  5. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/operations.py +151 -6
  6. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/service_factory.py +2 -0
  7. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/capability.py +13 -0
  8. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/dataset.py +10 -2
  9. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/records.py +60 -1
  10. dccd-3.8.0/dccd/domain/symbol.py +101 -0
  11. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/timeutils.py +55 -0
  12. dccd-3.8.0/dccd/domain/types.py +36 -0
  13. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/api/app.py +6 -3
  14. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/data.html +18 -7
  15. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/historical.html +57 -21
  16. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/base.py +68 -1
  17. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/binance.py +223 -4
  18. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/bybit.py +145 -6
  19. dccd-3.8.0/dccd/sources/kraken_futures.py +174 -0
  20. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/parquet.py +53 -10
  21. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_api.py +63 -0
  22. dccd-3.8.0/dccd/tests/v3/test_application.py +826 -0
  23. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_domain.py +149 -1
  24. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_domain_extended.py +18 -0
  25. dccd-3.8.0/dccd/tests/v3/test_sources.py +1384 -0
  26. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_storage.py +160 -2
  27. {dccd-3.6.3 → dccd-3.8.0}/dccd/transport/paginate.py +15 -11
  28. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/PKG-INFO +1 -1
  29. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/SOURCES.txt +1 -0
  30. {dccd-3.6.3 → dccd-3.8.0}/pyproject.toml +1 -1
  31. dccd-3.6.3/dccd/domain/symbol.py +0 -63
  32. dccd-3.6.3/dccd/domain/types.py +0 -27
  33. dccd-3.6.3/dccd/tests/v3/test_application.py +0 -422
  34. dccd-3.6.3/dccd/tests/v3/test_sources.py +0 -479
  35. {dccd-3.6.3 → dccd-3.8.0}/CONTRIBUTING.md +0 -0
  36. {dccd-3.6.3 → dccd-3.8.0}/LICENSE.txt +0 -0
  37. {dccd-3.6.3 → dccd-3.8.0}/MANIFEST.in +0 -0
  38. {dccd-3.6.3 → dccd-3.8.0}/README.md +0 -0
  39. {dccd-3.6.3 → dccd-3.8.0}/dccd/__init__.py +0 -0
  40. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/__init__.py +0 -0
  41. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/events.py +0 -0
  42. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/jobs.py +0 -0
  43. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/monitor.py +0 -0
  44. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/registry.py +0 -0
  45. {dccd-3.6.3 → dccd-3.8.0}/dccd/application/scheduler.py +0 -0
  46. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/__init__.py +0 -0
  47. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/errors.py +0 -0
  48. {dccd-3.6.3 → dccd-3.8.0}/dccd/domain/transforms.py +0 -0
  49. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/__init__.py +0 -0
  50. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/api/__init__.py +0 -0
  51. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/cli/__init__.py +0 -0
  52. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/cli/main.py +0 -0
  53. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/__init__.py +0 -0
  54. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/favicon.svg +0 -0
  55. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/martian-mono-600.woff2 +0 -0
  56. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/martian-mono-700.woff2 +0 -0
  57. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-400.woff2 +0 -0
  58. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-500.woff2 +0 -0
  59. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-600.woff2 +0 -0
  60. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-700.woff2 +0 -0
  61. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/static/logo.svg +0 -0
  62. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/base.html +0 -0
  63. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/config.html +0 -0
  64. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/dashboard.html +0 -0
  65. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/live.html +0 -0
  66. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/login.html +0 -0
  67. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/logs.html +0 -0
  68. {dccd-3.6.3 → dccd-3.8.0}/dccd/interfaces/ui/templates/storage.html +0 -0
  69. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/__init__.py +0 -0
  70. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/bitfinex.py +0 -0
  71. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/bitmex.py +0 -0
  72. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/coinbase.py +0 -0
  73. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/kraken.py +0 -0
  74. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/okx.py +0 -0
  75. {dccd-3.6.3 → dccd-3.8.0}/dccd/sources/registry.py +0 -0
  76. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/__init__.py +0 -0
  77. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/coverage_sqlite.py +0 -0
  78. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/purge.py +0 -0
  79. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/remote.py +0 -0
  80. {dccd-3.6.3 → dccd-3.8.0}/dccd/storage/runs_sqlite.py +0 -0
  81. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/__init__.py +0 -0
  82. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/__init__.py +0 -0
  83. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_adapter_parsing.py +0 -0
  84. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_backfill_lookback.py +0 -0
  85. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_cli.py +0 -0
  86. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_client.py +0 -0
  87. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_coverage.py +0 -0
  88. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_monitor_webhook.py +0 -0
  89. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_network.py +0 -0
  90. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_orderbook_throttle.py +0 -0
  91. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_purge.py +0 -0
  92. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_ratelimit.py +0 -0
  93. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_remote_sync.py +0 -0
  94. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_restart.py +0 -0
  95. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_restore.py +0 -0
  96. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_scheduler_hygiene.py +0 -0
  97. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_storage_extended.py +0 -0
  98. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_stream_end_state.py +0 -0
  99. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_stream_flush.py +0 -0
  100. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_stream_nocapability.py +0 -0
  101. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_transport.py +0 -0
  102. {dccd-3.6.3 → dccd-3.8.0}/dccd/tests/v3/test_ws_subscription_honesty.py +0 -0
  103. {dccd-3.6.3 → dccd-3.8.0}/dccd/transport/__init__.py +0 -0
  104. {dccd-3.6.3 → dccd-3.8.0}/dccd/transport/http.py +0 -0
  105. {dccd-3.6.3 → dccd-3.8.0}/dccd/transport/ratelimit.py +0 -0
  106. {dccd-3.6.3 → dccd-3.8.0}/dccd/transport/ws.py +0 -0
  107. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/dependency_links.txt +0 -0
  108. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/entry_points.txt +0 -0
  109. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/requires.txt +0 -0
  110. {dccd-3.6.3 → dccd-3.8.0}/dccd.egg-info/top_level.txt +0 -0
  111. {dccd-3.6.3 → dccd-3.8.0}/setup.cfg +0 -0
@@ -16,6 +16,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
16
 
17
17
  ### Removed
18
18
 
19
+ ## [3.8.0] - 2026-07-05
20
+
21
+ ### Added
22
+
23
+ - Kraken Futures adapter (`krakenfutures`) — hourly perp funding history over
24
+ the exchange's ~1-year rolling window (`history="recent"` +
25
+ `recent_window_s` clamp, now enforced on the FUNDING backfill branch too);
26
+ 300 `PF_` linear perps addressable via `BTC/USD:perp` (XBT alias handled).
27
+ Verified on real data: ~8 750 hourly rows × BTC/ETH/SOL, values
28
+ byte-identical to the exchange. (#196)
29
+ - Kraken Futures perp klines via the charts API (`from`/`to` in seconds,
30
+ 2000-candle pages, 9 resolutions 1m–1w, deep history — verified gap-free
31
+ across page seams back to 2022); derivative capability matrix, CLAUDE.md
32
+ and the `how-to/derivatives` cadence caveat (1h vs 8h funding) updated. (#197)
33
+
34
+ ## [3.7.0] - 2026-07-05
35
+
36
+ ### Added
37
+
38
+ - `Symbol.market` (`spot`/`perp`/`quarter`/`next_quarter`) with `:market` pair
39
+ syntax (`BTC/USDT:perp`), market-suffixed storage slugs (`BTC-USDT_PERP`), and
40
+ per-market capability declarations (`Capability.markets`, `recent_window_s`)
41
+ enforced by `backfill()` — the plumbing for the derivative-markets epic. (#183)
42
+ - Binance USDS-M continuous-contract klines: `BTC/USDT:perp` / `:quarter` /
43
+ `:next_quarter` OHLC backfills route to `fapi/v1/continuousKlines` (auto-rolled
44
+ quarterly series — the futures leg of the basis signal), reusing the OHLC
45
+ machinery and storage layout verbatim (`ohlc/BTC-USDT_QUARTER/…`). (#184)
46
+ - `DataType.FUNDING` — perp funding-rate history end to end: `FundingRate`
47
+ record, annual Parquet store (`funding/{pair}/YYYY.parquet`, dedup on `TS`),
48
+ `FundingHistory` cursor protocol, bounded 365-day default lookback, and
49
+ Binance USDS-M as first source (full history; verified 2019-09→today on real
50
+ data, values byte-identical to the exchange). (#185)
51
+ - Bybit perp funding-rate history (paired `startTime`/`endTime` params,
52
+ newest-first backward pagination; depth probed to contract launch 2020-03 →
53
+ `history="full"` declared honestly) — cross-exchange funding spread now
54
+ computable. (#187)
55
+ - `DataType.OPEN_INTEREST` — span-typed OI history end to end:
56
+ `OpenInterest` record, `open_interest/{pair}/{span}/YYYY.parquet` layout with
57
+ the same gap detection as OHLC, `OpenInterestHistory` cursor protocol,
58
+ span-required validation (config + API), and a `recent_window_s` clamp for
59
+ time-bound recent windows; Bybit first with full history to symbol launch
60
+ (verified: 39.5k hourly rows since 2022-01-01, 0 % gap). (#188)
61
+ - Binance USDS-M open-interest statistics — forward collector with the 30-day
62
+ window declared honestly (`history="recent"` + `recent_window_s` → clamp +
63
+ warn at exactly the boundary), handling two verified endpoint quirks: a hard
64
+ HTTP 400 below the 30-day floor (floored with a safety margin) and
65
+ `endTime`-anchored over-full windows that would otherwise silently drop all
66
+ but the newest 500 rows (per-request `endTime` bounding + window-left
67
+ continuation). (#190)
68
+ - Funding and open-interest surfaced in the web UI: Data + Historical tabs
69
+ (span/coverage columns for OI, `:perp` pair hints, OI span select), plus a
70
+ `how-to/derivatives` guide (funding, OI forward collection, quarterly klines
71
+ → basis recipe) and the per-exchange capability matrix updated. (#191)
72
+
19
73
  ## [3.6.3] - 2026-06-20
20
74
 
21
75
  ### Fixed
@@ -9,6 +9,23 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
9
9
  > [`doc/dev/README.md`](doc/dev/README.md) for a fuller picture than this file
10
10
  > gives. `CLAUDE.md` remains authoritative for commands and invariants.
11
11
 
12
+ ## Common conventions
13
+
14
+ Shared across my repos, mirrored from `~/.claude/CLAUDE.md` (the single source of
15
+ truth — if they ever disagree, the global file wins). Restated here so the repo
16
+ stays self-contained:
17
+
18
+ - **Git Flow** — `master` (tagged releases) ← `develop` (integration) ←
19
+ `feat|fix|chore|docs/<topic>`. **Never commit directly to `develop` or `master`**
20
+ — always a feature branch + PR into `develop`; `develop` → `master` only at release.
21
+ - **Conventional Commits** — `feat:` `fix:` `chore:` `docs:`. **Never add
22
+ `Co-Authored-By` trailers** (personal repo).
23
+ - **One PR = one concern**, small and disposable — a big plan ships as several small
24
+ atomic PRs, never one catch-all branch.
25
+ - **Model: `opus`, always** — interactive sessions and every spawned subagent; a plan
26
+ leaf's `complexity` is effort/ordering only and never downgrades the model.
27
+ - **Before every commit** — `pytest` and `ruff check dccd/` must pass.
28
+
12
29
  ## Commands
13
30
 
14
31
  ```bash
@@ -42,42 +59,7 @@ python doc/dev/ui_smoke.py http://127.0.0.1:8137
42
59
  > env ships Sphinx whose source uses 3.12 `type` statements, which made mypy
43
60
  > abort under 3.11. dccd supports 3.11–3.13, so 3.12 semantics are safe.
44
61
 
45
- ## Git Flow
46
-
47
- **Branch model:**
48
- ```
49
- master ← stable releases only (tagged vX.Y.Z)
50
- └── develop ← integration branch
51
- ├── feat/<topic> new feature or modernization axis
52
- ├── fix/<topic> bug fix
53
- ├── chore/<topic> tooling, CI, deps
54
- └── docs/<topic> documentation only
55
- ```
56
-
57
- **Rules — always follow these before committing or pushing:**
58
- 1. **Never commit directly to `master`.**
59
- 2. **Never commit directly to `develop`** — always use a feature branch + PR.
60
- 3. Branch off `develop`: `git checkout develop && git checkout -b feat/my-topic`
61
- 4. Open a PR into `develop` when done. `develop` → `master` only at release time.
62
-
63
- **Commit style (Conventional Commits):**
64
- ```
65
- feat: add Bybit futures OHLC capability
66
- fix: correct paginator window for Coinbase
67
- chore: upgrade httpx to 0.28
68
- docs: update README for v3 install
69
- ```
70
-
71
- Do not add `Co-Authored-By` trailers to commits — this is a personal repo.
72
-
73
- **Before every commit:** run `pytest`. It must pass.
74
-
75
- **One PR = one concern, small and disposable.** Even a large plan ships as
76
- *several* small atomic PRs — never one fourre-tout branch. A PR you couldn't throw
77
- away without losing unrelated good work is too big: split it. This is what makes
78
- `/abandon-task` (kill a bad PR, keep the lesson) viable.
79
-
80
- ### Dev loop & docs of record
62
+ ## Dev loop & docs of record
81
63
 
82
64
  The iterative loop is tooled by skills, with four tracked docs as the sources of
83
65
  truth:
@@ -107,17 +89,6 @@ checklist) → … per leaf … → last leaf removes the roadmap line → `/rel
107
89
  backward-compatible: a repo whose `.claude/workflow.json` has **no `plans_dir`**
108
90
  falls back to the older `/pick-task → plan mode → /finish-task` loop.
109
91
 
110
- **Model per task** (advisory — you set it via `/model`, a skill spawns a subagent
111
- with an explicit `model`, or a plan **leaf's `complexity` derives it**:
112
- `low→haiku`, `medium→sonnet`, `high→opus`; subagents otherwise *inherit* the
113
- parent):
114
-
115
- | Model | For |
116
- |-------|-----|
117
- | `opus` | judgement, design, decisions, planning, review |
118
- | `sonnet` | implementation — code, tests, docstrings |
119
- | `haiku` | mechanical fan-out (doc scans, checklists) — spawn it explicitly as a subagent |
120
-
121
92
  ## Architecture (v3 — hexagonal)
122
93
 
123
94
  ### Three usage modes
@@ -148,9 +119,9 @@ Pure, synchronous, no I/O. Never import from transport/sources/storage.
148
119
 
149
120
  | Module | Contents |
150
121
  |--------|----------|
151
- | `symbol.py` | `Symbol(base, quote)` — normalises XBT→BTC |
152
- | `types.py` | `DataType` enum: `ohlc`, `trades`, `orderbook` |
153
- | `records.py` | `OHLCBar`, `Trade`, `OrderBookSnapshot` (ns timestamps) |
122
+ | `symbol.py` | `Symbol(base, quote, market)` — normalises XBT→BTC; `market` = `spot`/`perp`/`quarter`/`next_quarter` (`BTC/USDT:perp` syntax, `_PERP` slugs on disk) |
123
+ | `types.py` | `DataType` enum: `ohlc`, `trades`, `orderbook`, `funding`, `open_interest` |
124
+ | `records.py` | `OHLCBar`, `Trade`, `OrderBookSnapshot`, `FundingRate`, `OpenInterest` (ns timestamps) |
154
125
  | `dataset.py` | `DatasetId`, `Provenance` |
155
126
  | `capability.py` | `Capability` — declared per adapter per (data_type × transport × mode) |
156
127
  | `timeutils.py` | Helpers: `s_to_ns`, `align_ns`, `span_label`, `binance_interval`, … |
@@ -190,10 +161,11 @@ Adapters declare their capabilities via `capabilities() -> list[Capability]`.
190
161
 
191
162
  | Exchange | Notes |
192
163
  |----------|-------|
193
- | `binance.py` | Full history OHLC+trades, depth 5000 |
164
+ | `binance.py` | Full history OHLC+trades, depth 5000; perp/quarterly continuous futures klines, funding (full), open interest (30-day window only) |
194
165
  | `coinbase.py` | 300 candles/req (Paginator handles automatically) |
195
166
  | `kraken.py` | OHLC: 720 recent only (`history="recent"`); trades: full via `since` cursor |
196
- | `bybit.py` | No spot trades history (capability not declared → `NoCapability` early) |
167
+ | `kraken_futures.py` | Separate API surface (`krakenfutures`, `PF_` linear perps): funding **hourly** cadence, ~1-year rolling window (`history="recent"`); deep perp klines via charts API (2000/page); no OI (snapshot-only upstream) |
168
+ | `bybit.py` | No spot trades history (capability not declared → `NoCapability` early); funding + open interest full history (perp) |
197
169
  | `okx.py` | `history-candles` + `history-trades` for deep history |
198
170
  | `bitfinex.py` | Up to 10 000 items per request |
199
171
  | `bitmex.py` | Bucketed OHLC (1m/5m/1h/1d only), full trades |
@@ -230,8 +202,8 @@ Adapters declare their capabilities via `capabilities() -> list[Capability]`.
230
202
  - `api/app.py` — FastAPI `create_app()`, lifespan context manager, module-level Pydantic request models. Job CRUD lives here: `POST /api/jobs/{create,delete,update}` (body-based to allow `/`/`:` in ids), all routed through the async `_persist_and_refresh` helper (writes YAML, updates `app.state`, calls `scheduler.sync_streams` **and** `scheduler.sync_intervals` to reconcile recurring backfills live). `POST /api/jobs/update` edits `start` and/or the recurring `every` (schedule). `GET /api/jobs` exposes `start`/`every`/`trigger`/`snapshot_interval`/`depth` so the UI can render and preserve them. `POST /api/jobs/run` + `/api/jobs/run-all` trigger configured backfills on demand. SSE at `GET /api/events` uses `add_queue`/`remove_queue` for multi-consumer fan-out.
231
203
  - `cli/main.py` — Typer commands, all import from `service_factory`
232
204
  - `ui/` — Jinja2 templates + static files. Nav: `Dashboard` · `Data` flat, plus `Collect ▾` (Historical/Live) and `System ▾` (Logs/Config/Storage) dropdowns. Pages are **split by concern**:
233
- - **Data** (`data.html`, route `/data`; `/inventory` 307-redirects here) — read-only view of what's on disk: DataType tabs → per-exchange accordions with totals, freshness dot, OHLC gap %, on-disk size, file count. No action buttons.
234
- - **Historical** (`historical.html`) — backfill jobs (**OHLC + Trades only**; order books have no REST history): DataType tabs → exchange accordions → one row per dataset with editable `first_date` (defaults to the dataset's earliest stored bar), a **Schedule** select (Off/hourly/daily/custom → `every`; `manual` trigger when off), real coverage bar, inline Run/Delete. **Run all** (header) + per-exchange **Run all**. New jobs default to `manual`.
205
+ - **Data** (`data.html`, route `/data`; `/inventory` 307-redirects here) — read-only view of what's on disk: DataType tabs (incl. Funding + Open Interest) → per-exchange accordions with totals, freshness dot, OHLC/OI gap %, on-disk size, file count. No action buttons.
206
+ - **Historical** (`historical.html`) — backfill jobs (**OHLC, Trades, Funding + Open Interest**; order books have no REST history): DataType tabs → exchange accordions → one row per dataset with editable `first_date` (defaults to the dataset's earliest stored bar), a **Schedule** select (Off/hourly/daily/custom → `every`; `manual` trigger when off), real coverage bar, inline Run/Delete. Span column/select is gated by `hasSpan(dt)` (OHLC + open interest); funding has no span. Pair fields accept the `:perp` market suffix (placeholder hints it on the derivative tabs). **Run all** (header) + per-exchange **Run all**. New jobs default to `manual`.
235
207
  - **Live** (`live.html`) — stream jobs (**Trades + Order Book only**; OHLC is collected via the Historical schedule, not streamed): same tab/accordion shape, with a liveness indicator fed by `StreamSampleEvent` over SSE (numeric `value`/`bid`/`ask`, formatted client-side via `fmtNum`). Liveness is **seeded from the last on-disk point** (inventory `max_ts`) so a refresh shows freshness without waiting for a live sample. The dot's "fresh" window is span-aware (order-book `snapshot_interval` / short for trades); the freshness label is a relative "N ago" under 24h (`fmtFreshness`) and an absolute date beyond, or the last-run date-time when stopped. Cadence column + `snapshot_interval` field for order book. Inline Start/Stop/Delete.
236
208
  - Single top bar carries the brand (logo · `dccd` · version) left and the nav right. Dates render in `settings.timezone` (`local`/`UTC`/zoneinfo) via `DCCD_TZ` in `fmtNs`/`fmtDate`; relative ages are tz-independent.
237
209
  - `dashboard.html` (KPIs + Active now / Recent runs / Data), `logs.html` (recent runs first, live console secondary, human run labels), `config.html` (Settings incl. `timezone`/Alerts/Storage + Raw JSON — **no jobs form**; jobs are managed on Historical/Live), `storage.html` (sizes via `fmtBytes`; no migrate tool).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dccd
3
- Version: 3.6.3
3
+ Version: 3.8.0
4
4
  Summary: Download Crypto Currency Data — hexagonal architecture, async-first.
5
5
  Author-email: Arthur Bernard <arthur.bernard.92@gmail.com>
6
6
  License: MIT
@@ -32,7 +32,8 @@ _XDG_CONFIG_HOME = pathlib.Path(
32
32
  DEFAULT_CONFIG_PATH = _XDG_CONFIG_HOME / "dccd" / "config.yml"
33
33
 
34
34
  SUPPORTED_EXCHANGES: frozenset[str] = frozenset(
35
- {"binance", "kraken", "bybit", "okx", "coinbase", "bitfinex", "bitmex"}
35
+ {"binance", "kraken", "krakenfutures", "bybit", "okx", "coinbase",
36
+ "bitfinex", "bitmex"}
36
37
  )
37
38
 
38
39
 
@@ -119,7 +120,7 @@ class JobConfig(BaseModel):
119
120
 
120
121
  Validation enforces:
121
122
  - ``exchange`` must be a known exchange name.
122
- - ``data_type='ohlc'`` requires ``span`` to be set.
123
+ - ``data_type='ohlc'`` or ``'open_interest'`` requires ``span`` to be set.
123
124
  - ``pairs`` must be non-empty and use ``BASE/QUOTE`` format.
124
125
  """
125
126
 
@@ -157,9 +158,11 @@ class JobConfig(BaseModel):
157
158
  return v
158
159
 
159
160
  @model_validator(mode="after")
160
- def _validate_span_for_ohlc(self) -> "JobConfig":
161
- if self.data_type == "ohlc" and self.span is None:
162
- raise ValueError("'span' is required when data_type='ohlc'")
161
+ def _validate_span_required(self) -> "JobConfig":
162
+ if self.data_type in ("ohlc", "open_interest") and self.span is None:
163
+ raise ValueError(
164
+ "'span' is required when data_type='ohlc' or 'open_interest'"
165
+ )
163
166
  return self
164
167
 
165
168
  def to_job_specs(self) -> list[JobSpec]:
@@ -22,10 +22,16 @@ from dccd.application.events import RunEvents
22
22
  from dccd.application.jobs import JobSpec, JobTarget
23
23
  from dccd.domain.dataset import DatasetId, Provenance
24
24
  from dccd.domain.errors import NoCapability
25
- from dccd.domain.records import OHLCBar, Trade
25
+ from dccd.domain.records import FundingRate, OHLCBar, OpenInterest, Trade
26
26
  from dccd.domain.timeutils import NS, ns_now, ns_to_dt
27
27
  from dccd.domain.types import DataType
28
- from dccd.sources.base import OHLCHistory, OrderBookSnapshotREST, TradesHistory
28
+ from dccd.sources.base import (
29
+ FundingHistory,
30
+ OHLCHistory,
31
+ OpenInterestHistory,
32
+ OrderBookSnapshotREST,
33
+ TradesHistory,
34
+ )
29
35
  from dccd.sources.registry import SourceRegistry
30
36
  from dccd.storage.coverage_sqlite import CoverageStore
31
37
  from dccd.storage.parquet import ParquetStore
@@ -62,12 +68,29 @@ _STREAM_FLUSH_INTERVAL_S = 60.0
62
68
  # Bounds the very first backfill so it can't silently run for millions of rows
63
69
  # (trades) or from epoch 0. Deep history is opt-in via an explicit start date.
64
70
  _DEFAULT_LOOKBACK_NS = {
65
- DataType.OHLC: 30 * 86400 * NS, # ~720 1h bars / 43k 1m bars
66
- DataType.TRADES: 3600 * NS, # 1 hour of trades
67
- DataType.ORDERBOOK: 3600 * NS, # single snapshot anyway
71
+ DataType.OHLC: 30 * 86400 * NS, # ~720 1h bars / 43k 1m bars
72
+ DataType.TRADES: 3600 * NS, # 1 hour of trades
73
+ DataType.ORDERBOOK: 3600 * NS, # single snapshot anyway
74
+ DataType.FUNDING: 365 * 86400 * NS, # ~1095 events/yr at 8h cadence — cheap
75
+ DataType.OPEN_INTEREST: 30 * 86400 * NS, # ~720 1h observations — same as OHLC
68
76
  }
69
77
 
70
78
 
79
+ def _check_market(cap: Any, target: JobTarget) -> None:
80
+ """Reject a non-spot target the capability has not declared.
81
+
82
+ ``Capability.markets`` defaults to ``None`` (spot-only) for every
83
+ existing declaration, so this preserves the capability-honesty invariant:
84
+ a source must opt in explicitly (``markets=[...]``) before a derivative
85
+ target is accepted, and rejection happens before any fetch is attempted.
86
+ """
87
+ market = target.symbol.market
88
+ if market != "spot" and market not in (cap.markets or []):
89
+ raise NoCapability(
90
+ target.exchange, f"{target.data_type.value}[{market}]", "historical"
91
+ )
92
+
93
+
71
94
  def _make_dataset_id(target: JobTarget) -> DatasetId:
72
95
  return DatasetId(
73
96
  exchange=target.exchange,
@@ -212,7 +235,12 @@ async def backfill(
212
235
  # short recent window (use a custom start date for deep history).
213
236
  lookback = _DEFAULT_LOOKBACK_NS.get(target.data_type, 30 * 86400 * NS)
214
237
  start_ns = end_ns - lookback
215
- human = "1 hour" if target.data_type == DataType.TRADES else "30 days"
238
+ if target.data_type == DataType.TRADES:
239
+ human = "1 hour"
240
+ elif target.data_type == DataType.FUNDING:
241
+ human = "365 days"
242
+ else:
243
+ human = "30 days"
216
244
  _emit_log(events, runs_store, run_id,
217
245
  f"No existing data — starting from {human} ago "
218
246
  "(set a custom start date for more)")
@@ -277,6 +305,7 @@ async def backfill(
277
305
  cap = adapter.capability_for(DataType.OHLC, "rest", "historical")
278
306
  if cap is None:
279
307
  raise NoCapability(target.exchange, "ohlc", "historical")
308
+ _check_market(cap, target)
280
309
 
281
310
  from dccd.transport.paginate import paginate_ohlc
282
311
 
@@ -328,6 +357,7 @@ async def backfill(
328
357
  cap = adapter.capability_for(DataType.TRADES, "rest", "historical")
329
358
  if cap is None:
330
359
  raise NoCapability(target.exchange, "trades", "historical")
360
+ _check_market(cap, target)
331
361
 
332
362
  from dccd.transport.paginate import paginate_trades
333
363
 
@@ -362,9 +392,124 @@ async def backfill(
362
392
  if not (stop_event and stop_event.is_set()):
363
393
  _emit_time(end_ns)
364
394
 
395
+ elif target.data_type == DataType.FUNDING:
396
+ if not isinstance(adapter, FundingHistory):
397
+ raise NoCapability(target.exchange, "funding", "historical")
398
+ cap = adapter.capability_for(DataType.FUNDING, "rest", "historical")
399
+ if cap is None:
400
+ raise NoCapability(target.exchange, "funding", "historical")
401
+ _check_market(cap, target)
402
+
403
+ # Honour a time-bound "recent" window (used by Kraken
404
+ # Futures, ~1 rolling year): paginating further back just
405
+ # re-fetches the same recent events — clamp + warn instead,
406
+ # mirroring the OPEN_INTEREST clamp below. Binance/Bybit
407
+ # funding declare history="full" and are unaffected.
408
+ if cap.history == "recent" and cap.recent_window_s:
409
+ earliest = end_ns - cap.recent_window_s * NS
410
+ if start_ns < earliest:
411
+ _emit_log(
412
+ events, runs_store, run_id,
413
+ f"{target.exchange} funding serves only the "
414
+ f"last {cap.recent_window_s}s; clamping start "
415
+ f"to {ns_to_dt(earliest).isoformat()}.",
416
+ level="warning",
417
+ )
418
+ start_ns = earliest
419
+
420
+ # paginate_trades is duck-typed on ``.ts`` (see _get_ts in
421
+ # transport/paginate.py) and drives any cursor-paged record
422
+ # stream — funding events reuse it unchanged, no renaming.
423
+ from dccd.transport.paginate import paginate_trades
424
+
425
+ sym = target.symbol
426
+
427
+ async def _fetch_funding(
428
+ s_ns: int, e_ns: int, limit: int, cursor: str | None,
429
+ ) -> tuple[list[FundingRate], str | None]:
430
+ return await adapter.fetch_funding_page(sym, s_ns, e_ns, limit, cursor)
431
+
432
+ funding_batch: list[FundingRate] = []
433
+ async for rate in paginate_trades(_fetch_funding, cap, start_ns, end_ns):
434
+ if stop_event and stop_event.is_set():
435
+ break
436
+ funding_batch.append(rate)
437
+ _collected[0] += 1
438
+ _track_ts(rate.ts)
439
+ if _collected[0] % 200 == 0:
440
+ _emit_time(rate.ts)
441
+ if len(funding_batch) >= _FLUSH_BATCH:
442
+ total_written += await _flush(store, ds, funding_batch, prov_src)
443
+
444
+ total_written += await _flush(store, ds, funding_batch, prov_src)
445
+ if not (stop_event and stop_event.is_set()):
446
+ _emit_time(end_ns)
447
+
448
+ elif target.data_type == DataType.OPEN_INTEREST:
449
+ if not isinstance(adapter, OpenInterestHistory):
450
+ raise NoCapability(target.exchange, "open_interest", "historical")
451
+ cap = adapter.capability_for(DataType.OPEN_INTEREST, "rest", "historical")
452
+ if cap is None:
453
+ raise NoCapability(target.exchange, "open_interest", "historical")
454
+ _check_market(cap, target)
455
+
456
+ span = target.span or 3600
457
+ if cap.spans and span not in cap.spans:
458
+ raise ValueError(
459
+ f"Span {span}s not supported by {target.exchange}. "
460
+ f"Supported spans: {sorted(cap.spans)}"
461
+ )
462
+
463
+ # Honour a time-bound "recent" window (used by Binance, leaf
464
+ # 06): paginating further back just re-fetches the same recent
465
+ # observations — clamp + warn instead, mirroring the Kraken
466
+ # OHLC clamp above.
467
+ if cap.history == "recent" and cap.recent_window_s:
468
+ earliest = end_ns - cap.recent_window_s * NS
469
+ if start_ns < earliest:
470
+ _emit_log(
471
+ events, runs_store, run_id,
472
+ f"{target.exchange} open interest serves only the "
473
+ f"last {cap.recent_window_s}s; clamping start "
474
+ f"to {ns_to_dt(earliest).isoformat()}.",
475
+ level="warning",
476
+ )
477
+ start_ns = earliest
478
+
479
+ # Span-typed like OHLC but cursor-paged like TRADES/FUNDING —
480
+ # paginate_trades is duck-typed on ``.ts`` and drives it unchanged.
481
+ from dccd.transport.paginate import paginate_trades
482
+
483
+ sym = target.symbol
484
+
485
+ async def _fetch_oi(
486
+ s_ns: int, e_ns: int, limit: int, cursor: str | None,
487
+ ) -> tuple[list[OpenInterest], str | None]:
488
+ return await adapter.fetch_oi_page(sym, span, s_ns, e_ns, limit, cursor)
489
+
490
+ oi_batch: list[OpenInterest] = []
491
+ async for oi in paginate_trades(_fetch_oi, cap, start_ns, end_ns):
492
+ if stop_event and stop_event.is_set():
493
+ break
494
+ oi_batch.append(oi)
495
+ _collected[0] += 1
496
+ _track_ts(oi.ts)
497
+ if _collected[0] % 200 == 0:
498
+ _emit_time(oi.ts)
499
+ if len(oi_batch) >= _FLUSH_BATCH:
500
+ total_written += await _flush(store, ds, oi_batch, prov_src)
501
+
502
+ total_written += await _flush(store, ds, oi_batch, prov_src)
503
+ if not (stop_event and stop_event.is_set()):
504
+ _emit_time(end_ns)
505
+
365
506
  elif target.data_type == DataType.ORDERBOOK:
366
507
  if not isinstance(adapter, OrderBookSnapshotREST):
367
508
  raise NoCapability(target.exchange, "orderbook", "snapshot")
509
+ cap = adapter.capability_for(DataType.ORDERBOOK, "rest", "historical")
510
+ if cap is None:
511
+ raise NoCapability(target.exchange, "orderbook", "historical")
512
+ _check_market(cap, target)
368
513
  depth = params.depth or 50
369
514
  snap = await adapter.fetch_orderbook(target.symbol, depth)
370
515
  _track_ts(snap.ts)
@@ -40,6 +40,7 @@ def build_registry() -> "SourceRegistry":
40
40
  from dccd.sources.bybit import BybitSource
41
41
  from dccd.sources.coinbase import CoinbaseSource
42
42
  from dccd.sources.kraken import KrakenSource
43
+ from dccd.sources.kraken_futures import KrakenFuturesSource
43
44
  from dccd.sources.okx import OKXSource
44
45
  from dccd.sources.registry import SourceRegistry
45
46
 
@@ -47,6 +48,7 @@ def build_registry() -> "SourceRegistry":
47
48
  reg.register("binance", BinanceSource())
48
49
  reg.register("coinbase", CoinbaseSource())
49
50
  reg.register("kraken", KrakenSource())
51
+ reg.register("krakenfutures", KrakenFuturesSource())
50
52
  reg.register("bybit", BybitSource())
51
53
  reg.register("okx", OKXSource())
52
54
  reg.register("bitfinex", BitfinexSource())
@@ -39,6 +39,17 @@ class Capability(BaseModel, frozen=True):
39
39
  a "live" stream that never writes anything.
40
40
  auth_required : bool
41
41
  Whether this capability requires authentication.
42
+ markets : list[str] or None
43
+ Non-spot markets this capability serves (e.g. ``['perp']``,
44
+ ``['perp', 'quarter']``). ``None`` means spot-only — the honest
45
+ default for every existing declaration; a source must opt in
46
+ explicitly before a derivative-market target is accepted.
47
+ recent_window_s : int or None
48
+ Length, in seconds, of the recent window served when ``history``
49
+ is ``'recent'`` and that window is time-bound rather than
50
+ bar-count-bound (``max_per_request`` bars). ``None`` when the
51
+ recent window is bar-count-bound or not applicable. Used by the
52
+ Binance open-interest adapter.
42
53
 
43
54
  Examples
44
55
  --------
@@ -58,3 +69,5 @@ class Capability(BaseModel, frozen=True):
58
69
  max_depth: int | None = None
59
70
  depths: list[int] | None = None
60
71
  auth_required: bool = False
72
+ markets: list[str] | None = None
73
+ recent_window_s: int | None = None
@@ -28,8 +28,16 @@ class DatasetId(BaseModel, frozen=True):
28
28
  span: int | None = None
29
29
 
30
30
  def pair_slug(self) -> str:
31
- """Return filesystem-safe pair string (e.g. ``'BTC-USDT'``)."""
32
- return f"{self.symbol.base}-{self.symbol.quote}"
31
+ """Return filesystem-safe pair string.
32
+
33
+ Spot: ``'BTC-USDT'``. Non-spot markets append the upper-cased market
34
+ as a suffix so derivative datasets never collide with spot ones on
35
+ disk, e.g. ``'BTC-USDT_PERP'``, ``'BTC-USDT_QUARTER'``.
36
+ """
37
+ slug = f"{self.symbol.base}-{self.symbol.quote}"
38
+ if self.symbol.market != "spot":
39
+ slug += f"_{self.symbol.market.upper()}"
40
+ return slug
33
41
 
34
42
  def __str__(self) -> str:
35
43
  parts = [self.exchange, str(self.symbol), self.data_type.value]
@@ -6,7 +6,14 @@ from typing import Literal
6
6
 
7
7
  from pydantic import BaseModel
8
8
 
9
- __all__ = ["OHLCBar", "Trade", "OrderBookLevel", "OrderBookSnapshot"]
9
+ __all__ = [
10
+ "OHLCBar",
11
+ "Trade",
12
+ "OrderBookLevel",
13
+ "OrderBookSnapshot",
14
+ "FundingRate",
15
+ "OpenInterest",
16
+ ]
10
17
 
11
18
 
12
19
  class OHLCBar(BaseModel, frozen=True):
@@ -112,3 +119,55 @@ class OrderBookSnapshot(BaseModel, frozen=True):
112
119
  bids: list[OrderBookLevel]
113
120
  asks: list[OrderBookLevel]
114
121
  is_snapshot: bool = True
122
+
123
+
124
+ class FundingRate(BaseModel, frozen=True):
125
+ """One realized perpetual-futures funding event.
126
+
127
+ Attributes
128
+ ----------
129
+ ts : int
130
+ Funding time, **nanoseconds UTC**.
131
+ rate : float
132
+ Realized funding rate for this event (e.g. ``0.0001`` = 0.01%).
133
+ mark_price : float or None
134
+ Mark price at funding time (not always available).
135
+
136
+ Examples
137
+ --------
138
+ >>> f = FundingRate(ts=1_000_000_000_000_000_000, rate=0.0001)
139
+ >>> f.mark_price is None
140
+ True
141
+ """
142
+
143
+ ts: int
144
+ rate: float
145
+ mark_price: float | None = None
146
+
147
+
148
+ class OpenInterest(BaseModel, frozen=True):
149
+ """One open-interest observation for a derivative instrument.
150
+
151
+ Span-typed like OHLC: one row per fixed-cadence bucket (e.g. hourly),
152
+ rather than one row per event like :class:`FundingRate`.
153
+
154
+ Attributes
155
+ ----------
156
+ ts : int
157
+ Observation time, **nanoseconds UTC**, aligned to the requested span.
158
+ open_interest : float
159
+ Open interest in contracts/base units.
160
+ open_interest_value : float or None
161
+ Open interest expressed as notional value (quote units), when the
162
+ exchange provides it. ``None`` when not available.
163
+
164
+ Examples
165
+ --------
166
+ >>> oi = OpenInterest(ts=1_000_000_000_000_000_000, open_interest=5000.0)
167
+ >>> oi.open_interest_value is None
168
+ True
169
+ """
170
+
171
+ ts: int
172
+ open_interest: float
173
+ open_interest_value: float | None = None