dccd 3.7.0__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.
- {dccd-3.7.0 → dccd-3.8.0}/CHANGELOG.md +15 -0
- {dccd-3.7.0 → dccd-3.8.0}/CLAUDE.md +1 -0
- {dccd-3.7.0 → dccd-3.8.0}/PKG-INFO +1 -1
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/config.py +2 -1
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/operations.py +17 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/service_factory.py +2 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/timeutils.py +28 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/historical.html +1 -1
- dccd-3.8.0/dccd/sources/kraken_futures.py +174 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_application.py +58 -2
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_domain.py +17 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_domain_extended.py +8 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_sources.py +223 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/PKG-INFO +1 -1
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/SOURCES.txt +1 -0
- {dccd-3.7.0 → dccd-3.8.0}/pyproject.toml +1 -1
- {dccd-3.7.0 → dccd-3.8.0}/CONTRIBUTING.md +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/LICENSE.txt +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/MANIFEST.in +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/README.md +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/events.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/jobs.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/monitor.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/registry.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/application/scheduler.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/capability.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/dataset.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/errors.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/records.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/symbol.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/transforms.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/domain/types.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/api/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/api/app.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/cli/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/cli/main.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/favicon.svg +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/martian-mono-600.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/martian-mono-700.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-400.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-500.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-600.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/fonts/spline-sans-700.woff2 +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/static/logo.svg +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/base.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/config.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/dashboard.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/data.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/live.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/login.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/logs.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/interfaces/ui/templates/storage.html +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/base.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/binance.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/bitfinex.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/bitmex.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/bybit.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/coinbase.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/kraken.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/okx.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/sources/registry.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/coverage_sqlite.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/parquet.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/purge.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/remote.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/storage/runs_sqlite.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_adapter_parsing.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_api.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_backfill_lookback.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_cli.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_client.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_coverage.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_monitor_webhook.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_network.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_orderbook_throttle.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_purge.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_ratelimit.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_remote_sync.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_restart.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_restore.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_scheduler_hygiene.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_storage.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_storage_extended.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_stream_end_state.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_stream_flush.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_stream_nocapability.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_transport.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/tests/v3/test_ws_subscription_honesty.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/transport/__init__.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/transport/http.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/transport/paginate.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/transport/ratelimit.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd/transport/ws.py +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/dependency_links.txt +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/entry_points.txt +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/requires.txt +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/dccd.egg-info/top_level.txt +0 -0
- {dccd-3.7.0 → dccd-3.8.0}/setup.cfg +0 -0
|
@@ -16,6 +16,21 @@ 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
|
+
|
|
19
34
|
## [3.7.0] - 2026-07-05
|
|
20
35
|
|
|
21
36
|
### Added
|
|
@@ -164,6 +164,7 @@ Adapters declare their capabilities via `capabilities() -> list[Capability]`.
|
|
|
164
164
|
| `binance.py` | Full history OHLC+trades, depth 5000; perp/quarterly continuous futures klines, funding (full), open interest (30-day window only) |
|
|
165
165
|
| `coinbase.py` | 300 candles/req (Paginator handles automatically) |
|
|
166
166
|
| `kraken.py` | OHLC: 720 recent only (`history="recent"`); trades: full via `since` cursor |
|
|
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) |
|
|
167
168
|
| `bybit.py` | No spot trades history (capability not declared → `NoCapability` early); funding + open interest full history (perp) |
|
|
168
169
|
| `okx.py` | `history-candles` + `history-trades` for deep history |
|
|
169
170
|
| `bitfinex.py` | Up to 10 000 items per request |
|
|
@@ -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", "
|
|
35
|
+
{"binance", "kraken", "krakenfutures", "bybit", "okx", "coinbase",
|
|
36
|
+
"bitfinex", "bitmex"}
|
|
36
37
|
)
|
|
37
38
|
|
|
38
39
|
|
|
@@ -400,6 +400,23 @@ async def backfill(
|
|
|
400
400
|
raise NoCapability(target.exchange, "funding", "historical")
|
|
401
401
|
_check_market(cap, target)
|
|
402
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
|
+
|
|
403
420
|
# paginate_trades is duck-typed on ``.ts`` (see _get_ts in
|
|
404
421
|
# transport/paginate.py) and drives any cursor-paged record
|
|
405
422
|
# stream — funding events reuse it unchanged, no renaming.
|
|
@@ -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())
|
|
@@ -26,6 +26,7 @@ __all__ = [
|
|
|
26
26
|
"bybit_oi_interval",
|
|
27
27
|
"okx_interval",
|
|
28
28
|
"kraken_interval",
|
|
29
|
+
"kraken_futures_resolution",
|
|
29
30
|
"coinbase_granularity",
|
|
30
31
|
]
|
|
31
32
|
|
|
@@ -306,6 +307,33 @@ def kraken_interval(span: int) -> int | None:
|
|
|
306
307
|
return minutes
|
|
307
308
|
|
|
308
309
|
|
|
310
|
+
def kraken_futures_resolution(span: int) -> str | None:
|
|
311
|
+
"""Return Kraken Futures charts-API resolution string for *span* seconds.
|
|
312
|
+
|
|
313
|
+
The charts endpoint (``/api/charts/v1/trade/{symbol}/{resolution}``) accepts
|
|
314
|
+
a fixed set of resolutions — distinct from spot Kraken's minute integers
|
|
315
|
+
(:func:`kraken_interval`).
|
|
316
|
+
|
|
317
|
+
Examples
|
|
318
|
+
--------
|
|
319
|
+
>>> kraken_futures_resolution(3600)
|
|
320
|
+
'1h'
|
|
321
|
+
>>> kraken_futures_resolution(86400)
|
|
322
|
+
'1d'
|
|
323
|
+
>>> kraken_futures_resolution(7200) is None
|
|
324
|
+
True
|
|
325
|
+
"""
|
|
326
|
+
_map = {
|
|
327
|
+
60: "1m", 300: "5m", 900: "15m", 1800: "30m",
|
|
328
|
+
3600: "1h", 14400: "4h", 43200: "12h",
|
|
329
|
+
86400: "1d", 604800: "1w",
|
|
330
|
+
}
|
|
331
|
+
result = _map.get(span)
|
|
332
|
+
if result is None:
|
|
333
|
+
_logger.warning("No Kraken Futures resolution for span=%d", span)
|
|
334
|
+
return result
|
|
335
|
+
|
|
336
|
+
|
|
309
337
|
def coinbase_granularity(span: int) -> int | None:
|
|
310
338
|
"""Return Coinbase granularity (seconds) for *span*.
|
|
311
339
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
{% block scripts %}
|
|
39
39
|
<script>
|
|
40
|
-
const EXCHANGES = ['binance','coinbase','kraken','bybit','okx','bitfinex','bitmex'];
|
|
40
|
+
const EXCHANGES = ['binance','coinbase','kraken','krakenfutures','bybit','okx','bitfinex','bitmex'];
|
|
41
41
|
const SPANS = [[60,'1m'],[300,'5m'],[900,'15m'],[1800,'30m'],[3600,'1h'],
|
|
42
42
|
[14400,'4h'],[86400,'1d'],[604800,'1w']];
|
|
43
43
|
// Open-interest endpoints are span-typed too, but serve a narrower span set
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Kraken Futures source adapter — hourly perp funding history + perp klines."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
# Built-in
|
|
6
|
+
import logging
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
# Local
|
|
11
|
+
from dccd.domain.capability import Capability
|
|
12
|
+
from dccd.domain.records import FundingRate, OHLCBar
|
|
13
|
+
from dccd.domain.symbol import Symbol
|
|
14
|
+
from dccd.domain.timeutils import NS, kraken_futures_resolution
|
|
15
|
+
from dccd.domain.types import DataType
|
|
16
|
+
from dccd.sources.base import FundingHistory, OHLCHistory, default_http_client
|
|
17
|
+
from dccd.transport.http import AsyncHTTPClient
|
|
18
|
+
|
|
19
|
+
__all__ = ["KrakenFuturesSource"]
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
_BASE = "https://futures.kraken.com/derivatives/api"
|
|
24
|
+
_BASE_CHARTS = "https://futures.kraken.com/api/charts/v1"
|
|
25
|
+
|
|
26
|
+
# Kraken names Bitcoin XBT on both spot and futures; canonical Symbols carry
|
|
27
|
+
# BTC (Symbol.parse normalises the other direction), so alias at render time.
|
|
28
|
+
_KRAKEN_ALIASES = {"BTC": "XBT"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class KrakenFuturesSource(FundingHistory, OHLCHistory):
|
|
32
|
+
"""Kraken Futures source adapter (linear ``PF_`` perpetuals: funding + klines).
|
|
33
|
+
|
|
34
|
+
Kraken Futures is a **separate API surface** from spot Kraken — different
|
|
35
|
+
host (``futures.kraken.com``), different symbology (``PF_XBTUSD``) and
|
|
36
|
+
different JSON shapes — so it gets its own adapter and exchange name
|
|
37
|
+
(``krakenfutures``) rather than extra methods on
|
|
38
|
+
:class:`~dccd.sources.kraken.KrakenSource`.
|
|
39
|
+
|
|
40
|
+
- **Funding backfill**: realized funding rates (``perp`` market only), at
|
|
41
|
+
Kraken's **1-hour cadence** — denser than the ~8h cadence of
|
|
42
|
+
Binance/Bybit; normalise before any cross-exchange comparison. The
|
|
43
|
+
endpoint serves a hard **~1-year rolling window** in a single
|
|
44
|
+
unpaginated response (``history="recent"`` + ``recent_window_s``); run
|
|
45
|
+
a recurring job to accumulate history forward.
|
|
46
|
+
- **OHLC backfill**: perp klines via the **charts API**
|
|
47
|
+
(``/api/charts/v1/trade/{symbol}/{resolution}``) — deep history
|
|
48
|
+
(``history="full"``), ~2 000 candles per page, forward-paged,
|
|
49
|
+
9 resolutions (1m…1w).
|
|
50
|
+
|
|
51
|
+
No WebSocket channels or open interest are declared — Kraken Futures has
|
|
52
|
+
no OI *history* endpoint (snapshot only), and undeclared capabilities
|
|
53
|
+
must stay undeclared (honesty invariant).
|
|
54
|
+
|
|
55
|
+
See Also
|
|
56
|
+
--------
|
|
57
|
+
dccd.Client : the public facade.
|
|
58
|
+
dccd.sources.kraken.KrakenSource : the spot adapter (separate API).
|
|
59
|
+
|
|
60
|
+
Examples
|
|
61
|
+
--------
|
|
62
|
+
>>> from dccd.sources.kraken_futures import KrakenFuturesSource
|
|
63
|
+
>>> sorted({c.data_type.value for c in KrakenFuturesSource().capabilities()})
|
|
64
|
+
['funding', 'ohlc']
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
exchange = "krakenfutures"
|
|
68
|
+
|
|
69
|
+
def __init__(self, http: AsyncHTTPClient | None = None) -> None:
|
|
70
|
+
self._http = http or default_http_client(self.exchange)
|
|
71
|
+
|
|
72
|
+
def capabilities(self) -> list[Capability]:
|
|
73
|
+
"""Declared capabilities, one per (data type × transport × mode)."""
|
|
74
|
+
return [
|
|
75
|
+
Capability(
|
|
76
|
+
data_type=DataType.FUNDING, transport="rest", mode="historical",
|
|
77
|
+
history="recent", recent_window_s=365 * 86400,
|
|
78
|
+
max_per_request=10000, page_direction=None,
|
|
79
|
+
markets=["perp"],
|
|
80
|
+
),
|
|
81
|
+
Capability(
|
|
82
|
+
data_type=DataType.OHLC, transport="rest", mode="historical",
|
|
83
|
+
history="full", max_per_request=2000, page_direction="forward",
|
|
84
|
+
spans=[60, 300, 900, 1800, 3600, 14400, 43200, 86400, 604800],
|
|
85
|
+
markets=["perp"],
|
|
86
|
+
),
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
def render_symbol(self, s: Symbol) -> str:
|
|
90
|
+
"""Kraken Futures linear-perp format: ``PF_XBTUSD`` (BTC aliased to XBT)."""
|
|
91
|
+
base = _KRAKEN_ALIASES.get(s.base, s.base)
|
|
92
|
+
return f"PF_{base}{s.quote}"
|
|
93
|
+
|
|
94
|
+
async def fetch_funding_page(
|
|
95
|
+
self,
|
|
96
|
+
symbol: Symbol,
|
|
97
|
+
start_ns: int,
|
|
98
|
+
end_ns: int,
|
|
99
|
+
limit: int,
|
|
100
|
+
cursor: str | None = None,
|
|
101
|
+
) -> tuple[list[FundingRate], str | None]:
|
|
102
|
+
"""Fetch the full available funding history in one unpaginated response.
|
|
103
|
+
|
|
104
|
+
``GET /v4/historicalfundingrates`` takes only ``symbol`` and ignores
|
|
105
|
+
any time/limit parameters: it always returns the entire ~1-year
|
|
106
|
+
rolling window (~8.8k hourly entries), ascending. *limit* and *cursor*
|
|
107
|
+
are therefore ignored and ``next_cursor`` is always ``None`` — one
|
|
108
|
+
page IS the whole window. Entries carry ISO-8601 ``Z`` timestamps;
|
|
109
|
+
``rate`` stores ``relativeFundingRate`` (the comparable per-period
|
|
110
|
+
rate), NOT the absolute per-contract ``fundingRate``. Entries outside
|
|
111
|
+
``[start_ns, end_ns]`` are filtered here (cheap; the paginator filters
|
|
112
|
+
again — harmless).
|
|
113
|
+
"""
|
|
114
|
+
params: dict[str, Any] = {"symbol": self.render_symbol(symbol)}
|
|
115
|
+
async with self._http as client:
|
|
116
|
+
data = await client.get(f"{_BASE}/v4/historicalfundingrates", params)
|
|
117
|
+
|
|
118
|
+
if data.get("result") != "success":
|
|
119
|
+
logger.error("Kraken Futures funding error: %s", data)
|
|
120
|
+
return [], None
|
|
121
|
+
|
|
122
|
+
rates = []
|
|
123
|
+
for e in data.get("rates", []):
|
|
124
|
+
dt = datetime.fromisoformat(e["timestamp"].replace("Z", "+00:00"))
|
|
125
|
+
# ms precision is exact in float64 at this epoch; ns would not be.
|
|
126
|
+
ts = int(dt.timestamp() * 1000) * 1_000_000
|
|
127
|
+
if start_ns <= ts <= end_ns:
|
|
128
|
+
rates.append(FundingRate(ts=ts, rate=float(e["relativeFundingRate"])))
|
|
129
|
+
return rates, None
|
|
130
|
+
|
|
131
|
+
async def fetch_ohlc_page(
|
|
132
|
+
self,
|
|
133
|
+
symbol: Symbol,
|
|
134
|
+
span: int,
|
|
135
|
+
start_ns: int,
|
|
136
|
+
end_ns: int,
|
|
137
|
+
limit: int,
|
|
138
|
+
) -> list[OHLCBar]:
|
|
139
|
+
"""Fetch one page of perp klines from the charts API.
|
|
140
|
+
|
|
141
|
+
``GET /api/charts/v1/trade/{symbol}/{resolution}`` with ``from``/``to``
|
|
142
|
+
in **seconds** (live-probed; the response candle ``time`` is in ms).
|
|
143
|
+
The response is ascending, anchored on ``from``, ~2 000 candles max
|
|
144
|
+
per call — the generic forward paginator windows accordingly
|
|
145
|
+
(``max_per_request=2000``). OHLCV fields arrive as **strings** and are
|
|
146
|
+
parsed to floats; the endpoint provides no quote volume or trade
|
|
147
|
+
count, so those stay ``None`` (never fabricated). Unsupported *span*
|
|
148
|
+
→ ``[]`` without any HTTP call.
|
|
149
|
+
"""
|
|
150
|
+
resolution = kraken_futures_resolution(span)
|
|
151
|
+
if not resolution:
|
|
152
|
+
return []
|
|
153
|
+
|
|
154
|
+
params: dict[str, Any] = {
|
|
155
|
+
"from": start_ns // NS,
|
|
156
|
+
"to": end_ns // NS,
|
|
157
|
+
}
|
|
158
|
+
url = f"{_BASE_CHARTS}/trade/{self.render_symbol(symbol)}/{resolution}"
|
|
159
|
+
async with self._http as client:
|
|
160
|
+
data = await client.get(url, params)
|
|
161
|
+
|
|
162
|
+
return [
|
|
163
|
+
OHLCBar(
|
|
164
|
+
ts=int(c["time"]) * 1_000_000,
|
|
165
|
+
open=float(c["open"]),
|
|
166
|
+
high=float(c["high"]),
|
|
167
|
+
low=float(c["low"]),
|
|
168
|
+
close=float(c["close"]),
|
|
169
|
+
volume=float(c["volume"]),
|
|
170
|
+
quote_volume=None,
|
|
171
|
+
trades=None,
|
|
172
|
+
)
|
|
173
|
+
for c in data.get("candles", [])
|
|
174
|
+
]
|
|
@@ -367,18 +367,28 @@ class _FundingFakeSource(FundingHistory):
|
|
|
367
367
|
|
|
368
368
|
exchange = "fake"
|
|
369
369
|
|
|
370
|
-
def __init__(
|
|
370
|
+
def __init__(
|
|
371
|
+
self,
|
|
372
|
+
rates: list[FundingRate],
|
|
373
|
+
markets: list[str] | None,
|
|
374
|
+
max_per_request: int = 2,
|
|
375
|
+
history: str = "full",
|
|
376
|
+
recent_window_s: int | None = None,
|
|
377
|
+
) -> None:
|
|
371
378
|
self._rates = rates
|
|
372
379
|
self._markets = markets
|
|
373
380
|
self._max_per_request = max_per_request
|
|
381
|
+
self._history = history
|
|
382
|
+
self._recent_window_s = recent_window_s
|
|
374
383
|
self.calls: list[tuple[int, int, int, str | None]] = []
|
|
375
384
|
|
|
376
385
|
def capabilities(self) -> list[Capability]:
|
|
377
386
|
return [
|
|
378
387
|
Capability(
|
|
379
388
|
data_type=DataType.FUNDING, transport="rest", mode="historical",
|
|
380
|
-
history=
|
|
389
|
+
history=self._history, max_per_request=self._max_per_request,
|
|
381
390
|
page_direction="forward", markets=self._markets,
|
|
391
|
+
recent_window_s=self._recent_window_s,
|
|
382
392
|
),
|
|
383
393
|
]
|
|
384
394
|
|
|
@@ -466,6 +476,52 @@ class TestBackfillFunding:
|
|
|
466
476
|
assert "error" not in result
|
|
467
477
|
assert src.calls
|
|
468
478
|
|
|
479
|
+
@pytest.mark.asyncio
|
|
480
|
+
async def test_recent_window_clamp_fires_at_boundary(self, tmp_path):
|
|
481
|
+
# Kraken Futures pattern: a time-bound ~1-year rolling window.
|
|
482
|
+
recent_window_s = 365 * 86400
|
|
483
|
+
src = _FundingFakeSource(
|
|
484
|
+
[FundingRate(ts=NS, rate=0.0001)], markets=["perp"],
|
|
485
|
+
history="recent", recent_window_s=recent_window_s,
|
|
486
|
+
)
|
|
487
|
+
store = ParquetStore(tmp_path)
|
|
488
|
+
# Requested start (2020) is far older than the 1-year recent window.
|
|
489
|
+
spec = self._spec(start="2020-01-01")
|
|
490
|
+
|
|
491
|
+
bus = EventBus()
|
|
492
|
+
received = []
|
|
493
|
+
bus.subscribe(received.append)
|
|
494
|
+
events = bus.for_run("r1")
|
|
495
|
+
|
|
496
|
+
result = await backfill(spec, registry=_FundingFakeReg(src), store=store, events=events)
|
|
497
|
+
|
|
498
|
+
assert "error" not in result
|
|
499
|
+
assert result["start_ns"] == result["end_ns"] - recent_window_s * NS
|
|
500
|
+
warnings = [e for e in received if isinstance(e, LogEvent) and e.level == "warning"]
|
|
501
|
+
assert any("clamping start" in w.message for w in warnings)
|
|
502
|
+
|
|
503
|
+
@pytest.mark.asyncio
|
|
504
|
+
async def test_full_history_funding_not_clamped(self, tmp_path):
|
|
505
|
+
# Regression: Binance/Bybit funding declare history="full" — a deep
|
|
506
|
+
# start must be honoured verbatim, with no clamp warning.
|
|
507
|
+
src = _FundingFakeSource(
|
|
508
|
+
[FundingRate(ts=1_622_505_600 * NS, rate=0.0002)], markets=["perp"],
|
|
509
|
+
)
|
|
510
|
+
store = ParquetStore(tmp_path)
|
|
511
|
+
spec = self._spec(start="2020-01-01")
|
|
512
|
+
|
|
513
|
+
bus = EventBus()
|
|
514
|
+
received = []
|
|
515
|
+
bus.subscribe(received.append)
|
|
516
|
+
events = bus.for_run("r1")
|
|
517
|
+
|
|
518
|
+
result = await backfill(spec, registry=_FundingFakeReg(src), store=store, events=events)
|
|
519
|
+
|
|
520
|
+
assert "error" not in result
|
|
521
|
+
assert result["start_ns"] == 1_577_836_800 * NS # 2020-01-01, untouched
|
|
522
|
+
warnings = [e for e in received if isinstance(e, LogEvent) and e.level == "warning"]
|
|
523
|
+
assert not any("clamping start" in w.message for w in warnings)
|
|
524
|
+
|
|
469
525
|
|
|
470
526
|
# ---------------------------------------------------------------------------
|
|
471
527
|
# Backfill — OPEN_INTEREST (span-typed like OHLC, cursor-paged like TRADES)
|
|
@@ -23,6 +23,7 @@ from dccd.domain.timeutils import (
|
|
|
23
23
|
bybit_interval,
|
|
24
24
|
bybit_oi_interval,
|
|
25
25
|
coinbase_granularity,
|
|
26
|
+
kraken_futures_resolution,
|
|
26
27
|
kraken_interval,
|
|
27
28
|
ns_to_s,
|
|
28
29
|
okx_interval,
|
|
@@ -306,6 +307,22 @@ class TestTimeutils:
|
|
|
306
307
|
assert kraken_interval(3600) == 60
|
|
307
308
|
assert kraken_interval(86400) == 1440
|
|
308
309
|
|
|
310
|
+
def test_kraken_futures_resolution(self):
|
|
311
|
+
assert kraken_futures_resolution(60) == "1m"
|
|
312
|
+
assert kraken_futures_resolution(300) == "5m"
|
|
313
|
+
assert kraken_futures_resolution(900) == "15m"
|
|
314
|
+
assert kraken_futures_resolution(1800) == "30m"
|
|
315
|
+
assert kraken_futures_resolution(3600) == "1h"
|
|
316
|
+
assert kraken_futures_resolution(14400) == "4h"
|
|
317
|
+
assert kraken_futures_resolution(43200) == "12h"
|
|
318
|
+
assert kraken_futures_resolution(86400) == "1d"
|
|
319
|
+
assert kraken_futures_resolution(604800) == "1w"
|
|
320
|
+
|
|
321
|
+
def test_kraken_futures_resolution_unsupported_span(self):
|
|
322
|
+
assert kraken_futures_resolution(180) is None
|
|
323
|
+
assert kraken_futures_resolution(7200) is None
|
|
324
|
+
assert kraken_futures_resolution(2592000) is None
|
|
325
|
+
|
|
309
326
|
def test_coinbase_granularity(self):
|
|
310
327
|
assert coinbase_granularity(3600) == 3600
|
|
311
328
|
assert coinbase_granularity(7200) is None
|
|
@@ -137,6 +137,14 @@ class TestJobConfigValidation:
|
|
|
137
137
|
)
|
|
138
138
|
assert jc.span == 3600
|
|
139
139
|
|
|
140
|
+
def test_krakenfutures_funding_job_valid(self) -> None:
|
|
141
|
+
jc = JobConfig(
|
|
142
|
+
exchange="krakenfutures", pairs=["BTC/USD:perp"], data_type="funding",
|
|
143
|
+
)
|
|
144
|
+
assert jc.exchange == "krakenfutures"
|
|
145
|
+
specs = jc.to_job_specs()
|
|
146
|
+
assert specs[0].target.symbol.market == "perp"
|
|
147
|
+
|
|
140
148
|
|
|
141
149
|
class TestAppConfigValidation:
|
|
142
150
|
def test_empty_jobs_allowed(self) -> None:
|
|
@@ -22,6 +22,7 @@ from dccd.sources.binance import BinanceSource
|
|
|
22
22
|
from dccd.sources.bybit import BybitSource
|
|
23
23
|
from dccd.sources.coinbase import CoinbaseSource
|
|
24
24
|
from dccd.sources.kraken import KrakenSource
|
|
25
|
+
from dccd.sources.kraken_futures import KrakenFuturesSource
|
|
25
26
|
from dccd.sources.okx import OKXSource
|
|
26
27
|
from dccd.sources.registry import SourceRegistry
|
|
27
28
|
|
|
@@ -454,6 +455,228 @@ class TestBybitOpenInterestHistory:
|
|
|
454
455
|
assert captured == []
|
|
455
456
|
|
|
456
457
|
|
|
458
|
+
class TestKrakenFuturesFunding:
|
|
459
|
+
"""``PF_`` linear-perp funding — single unpaginated ~1-year window."""
|
|
460
|
+
|
|
461
|
+
def _make_stub_http(self, captured: list[tuple[str, dict]], response):
|
|
462
|
+
"""Return a fake ``AsyncHTTPClient`` returning *response* on every call."""
|
|
463
|
+
|
|
464
|
+
class _FakeClient:
|
|
465
|
+
async def get(self, url, params):
|
|
466
|
+
captured.append((url, dict(params)))
|
|
467
|
+
return response
|
|
468
|
+
|
|
469
|
+
client = _FakeClient()
|
|
470
|
+
|
|
471
|
+
class _FakeHTTP:
|
|
472
|
+
async def __aenter__(self):
|
|
473
|
+
return client
|
|
474
|
+
|
|
475
|
+
async def __aexit__(self, *exc):
|
|
476
|
+
return False
|
|
477
|
+
|
|
478
|
+
return _FakeHTTP()
|
|
479
|
+
|
|
480
|
+
def test_implements_funding_history(self):
|
|
481
|
+
assert isinstance(KrakenFuturesSource(), FundingHistory)
|
|
482
|
+
|
|
483
|
+
def test_render_symbol_btc_aliased_to_xbt(self):
|
|
484
|
+
src = KrakenFuturesSource()
|
|
485
|
+
assert src.render_symbol(Symbol.parse("BTC/USD:perp")) == "PF_XBTUSD"
|
|
486
|
+
|
|
487
|
+
def test_render_symbol_eth_unaliased(self):
|
|
488
|
+
src = KrakenFuturesSource()
|
|
489
|
+
assert src.render_symbol(Symbol.parse("ETH/USD:perp")) == "PF_ETHUSD"
|
|
490
|
+
|
|
491
|
+
def test_funding_capability_is_honest_recent(self):
|
|
492
|
+
src = KrakenFuturesSource()
|
|
493
|
+
cap = src.capability_for(DataType.FUNDING, "rest", "historical")
|
|
494
|
+
assert cap is not None
|
|
495
|
+
assert cap.history == "recent"
|
|
496
|
+
assert cap.recent_window_s == 365 * 86400
|
|
497
|
+
assert cap.max_per_request == 10000
|
|
498
|
+
assert cap.page_direction is None
|
|
499
|
+
assert cap.markets == ["perp"]
|
|
500
|
+
|
|
501
|
+
@pytest.mark.asyncio
|
|
502
|
+
async def test_request_sends_symbol_only(self):
|
|
503
|
+
captured: list[tuple[str, dict]] = []
|
|
504
|
+
response = {"result": "success", "rates": []}
|
|
505
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
506
|
+
|
|
507
|
+
await src.fetch_funding_page(Symbol.parse("BTC/USD:perp"), 0, 2**63 - 1, 10000)
|
|
508
|
+
|
|
509
|
+
assert len(captured) == 1
|
|
510
|
+
url, params = captured[0]
|
|
511
|
+
assert url == "https://futures.kraken.com/derivatives/api/v4/historicalfundingrates"
|
|
512
|
+
assert params == {"symbol": "PF_XBTUSD"}
|
|
513
|
+
|
|
514
|
+
@pytest.mark.asyncio
|
|
515
|
+
async def test_iso_z_timestamp_to_ns_exact_and_relative_rate(self):
|
|
516
|
+
captured: list[tuple[str, dict]] = []
|
|
517
|
+
response = {"result": "success", "rates": [
|
|
518
|
+
# 2025-07-02T08:00:00Z == 1751443200 s epoch.
|
|
519
|
+
{"timestamp": "2025-07-02T08:00:00Z",
|
|
520
|
+
"fundingRate": 0.669129677269492056,
|
|
521
|
+
"relativeFundingRate": 0.000006246193055556},
|
|
522
|
+
]}
|
|
523
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
524
|
+
|
|
525
|
+
rates, _ = await src.fetch_funding_page(
|
|
526
|
+
Symbol.parse("BTC/USD:perp"), 0, 2**63 - 1, 10000)
|
|
527
|
+
|
|
528
|
+
assert len(rates) == 1
|
|
529
|
+
assert rates[0].ts == 1_751_443_200 * NS
|
|
530
|
+
# rate is the comparable relativeFundingRate, NOT the absolute fundingRate.
|
|
531
|
+
assert rates[0].rate == 0.000006246193055556
|
|
532
|
+
|
|
533
|
+
@pytest.mark.asyncio
|
|
534
|
+
async def test_window_filter_and_cursor_always_none(self):
|
|
535
|
+
captured: list[tuple[str, dict]] = []
|
|
536
|
+
response = {"result": "success", "rates": [
|
|
537
|
+
{"timestamp": "2025-07-02T08:00:00Z", "fundingRate": 0.1,
|
|
538
|
+
"relativeFundingRate": 0.0001}, # 1751443200 — before window
|
|
539
|
+
{"timestamp": "2026-07-04T12:00:00Z", "fundingRate": 0.2,
|
|
540
|
+
"relativeFundingRate": 0.0002}, # 1783166400 — inside window
|
|
541
|
+
]}
|
|
542
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
543
|
+
|
|
544
|
+
start_ns = 1_783_000_000 * NS
|
|
545
|
+
end_ns = 1_784_000_000 * NS
|
|
546
|
+
rates, next_cursor = await src.fetch_funding_page(
|
|
547
|
+
Symbol.parse("BTC/USD:perp"), start_ns, end_ns, 10000)
|
|
548
|
+
|
|
549
|
+
assert [r.rate for r in rates] == [0.0002]
|
|
550
|
+
assert next_cursor is None
|
|
551
|
+
|
|
552
|
+
@pytest.mark.asyncio
|
|
553
|
+
async def test_next_cursor_none_even_on_full_window(self):
|
|
554
|
+
# Even a maximal response is one page: the endpoint is unpaginated.
|
|
555
|
+
captured: list[tuple[str, dict]] = []
|
|
556
|
+
response = {"result": "success", "rates": [
|
|
557
|
+
{"timestamp": "2026-07-04T12:00:00Z", "fundingRate": 0.2,
|
|
558
|
+
"relativeFundingRate": 0.0002},
|
|
559
|
+
]}
|
|
560
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
561
|
+
|
|
562
|
+
_, next_cursor = await src.fetch_funding_page(
|
|
563
|
+
Symbol.parse("BTC/USD:perp"), 0, 2**63 - 1, 1, cursor="ignored")
|
|
564
|
+
|
|
565
|
+
assert next_cursor is None
|
|
566
|
+
assert len(captured) == 1 # cursor/limit ignored, no extra params sent
|
|
567
|
+
assert captured[0][1] == {"symbol": "PF_XBTUSD"}
|
|
568
|
+
|
|
569
|
+
@pytest.mark.asyncio
|
|
570
|
+
async def test_error_result_returns_empty_no_crash(self):
|
|
571
|
+
captured: list[tuple[str, dict]] = []
|
|
572
|
+
response = {"result": "error", "errors": [{"code": "not_found"}]}
|
|
573
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
574
|
+
|
|
575
|
+
rates, next_cursor = await src.fetch_funding_page(
|
|
576
|
+
Symbol.parse("BTC/USD:perp"), 0, 2**63 - 1, 10000)
|
|
577
|
+
|
|
578
|
+
assert rates == []
|
|
579
|
+
assert next_cursor is None
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
class TestKrakenFuturesKlines:
|
|
583
|
+
"""Perp klines via the charts API — seconds params, string OHLCV fields."""
|
|
584
|
+
|
|
585
|
+
def _make_stub_http(self, captured: list[tuple[str, dict]], response):
|
|
586
|
+
"""Return a fake ``AsyncHTTPClient`` returning *response* on every call."""
|
|
587
|
+
|
|
588
|
+
class _FakeClient:
|
|
589
|
+
async def get(self, url, params):
|
|
590
|
+
captured.append((url, dict(params)))
|
|
591
|
+
return response
|
|
592
|
+
|
|
593
|
+
client = _FakeClient()
|
|
594
|
+
|
|
595
|
+
class _FakeHTTP:
|
|
596
|
+
async def __aenter__(self):
|
|
597
|
+
return client
|
|
598
|
+
|
|
599
|
+
async def __aexit__(self, *exc):
|
|
600
|
+
return False
|
|
601
|
+
|
|
602
|
+
return _FakeHTTP()
|
|
603
|
+
|
|
604
|
+
def test_implements_ohlc_history(self):
|
|
605
|
+
assert isinstance(KrakenFuturesSource(), OHLCHistory)
|
|
606
|
+
|
|
607
|
+
def test_ohlc_capability_full_history_perp_only(self):
|
|
608
|
+
src = KrakenFuturesSource()
|
|
609
|
+
cap = src.capability_for(DataType.OHLC, "rest", "historical")
|
|
610
|
+
assert cap is not None
|
|
611
|
+
assert cap.history == "full"
|
|
612
|
+
assert cap.max_per_request == 2000
|
|
613
|
+
assert cap.page_direction == "forward"
|
|
614
|
+
assert cap.markets == ["perp"]
|
|
615
|
+
assert cap.spans == [60, 300, 900, 1800, 3600, 14400, 43200, 86400,
|
|
616
|
+
604800]
|
|
617
|
+
|
|
618
|
+
def test_no_ws_or_oi_capabilities_declared(self):
|
|
619
|
+
# Honesty invariant: no WS channels, no open interest (snapshot-only
|
|
620
|
+
# upstream → no honest history declaration possible).
|
|
621
|
+
src = KrakenFuturesSource()
|
|
622
|
+
assert src.capability_for(DataType.OHLC, "ws", "live") is None
|
|
623
|
+
assert src.capability_for(DataType.TRADES, "ws", "live") is None
|
|
624
|
+
assert src.capability_for(DataType.ORDERBOOK, "ws", "live") is None
|
|
625
|
+
assert src.capability_for(
|
|
626
|
+
DataType.OPEN_INTEREST, "rest", "historical") is None
|
|
627
|
+
|
|
628
|
+
@pytest.mark.asyncio
|
|
629
|
+
async def test_charts_url_and_seconds_params(self):
|
|
630
|
+
captured: list[tuple[str, dict]] = []
|
|
631
|
+
response = {"candles": []}
|
|
632
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
633
|
+
|
|
634
|
+
await src.fetch_ohlc_page(
|
|
635
|
+
Symbol.parse("BTC/USD:perp"), 3600, START_NS, END_NS, 2000)
|
|
636
|
+
|
|
637
|
+
assert len(captured) == 1
|
|
638
|
+
url, params = captured[0]
|
|
639
|
+
assert url == "https://futures.kraken.com/api/charts/v1/trade/PF_XBTUSD/1h"
|
|
640
|
+
# from/to are SECONDS (live-probed), not ms or ns.
|
|
641
|
+
assert params == {"from": 1_600_000_000, "to": 1_600_003_600}
|
|
642
|
+
|
|
643
|
+
@pytest.mark.asyncio
|
|
644
|
+
async def test_string_ohlcv_fields_parsed_to_floats(self):
|
|
645
|
+
captured: list[tuple[str, dict]] = []
|
|
646
|
+
response = {"candles": [
|
|
647
|
+
{"time": 1_600_000_000_000, "open": "10912.5", "high": "10921.0",
|
|
648
|
+
"low": "10904.5", "close": "10917.5", "volume": "1573129"},
|
|
649
|
+
]}
|
|
650
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
651
|
+
|
|
652
|
+
bars = await src.fetch_ohlc_page(
|
|
653
|
+
Symbol.parse("BTC/USD:perp"), 3600, START_NS, END_NS, 2000)
|
|
654
|
+
|
|
655
|
+
assert len(bars) == 1
|
|
656
|
+
bar = bars[0]
|
|
657
|
+
assert bar.ts == 1_600_000_000 * NS # response time is ms → ns
|
|
658
|
+
assert bar.open == 10912.5
|
|
659
|
+
assert bar.high == 10921.0
|
|
660
|
+
assert bar.low == 10904.5
|
|
661
|
+
assert bar.close == 10917.5
|
|
662
|
+
assert bar.volume == 1573129.0
|
|
663
|
+
# Not provided by the endpoint — must stay null, never fabricated.
|
|
664
|
+
assert bar.quote_volume is None
|
|
665
|
+
assert bar.trades is None
|
|
666
|
+
|
|
667
|
+
@pytest.mark.asyncio
|
|
668
|
+
async def test_unsupported_span_returns_empty_no_request(self):
|
|
669
|
+
captured: list[tuple[str, dict]] = []
|
|
670
|
+
response = {"candles": []}
|
|
671
|
+
src = KrakenFuturesSource(http=self._make_stub_http(captured, response))
|
|
672
|
+
|
|
673
|
+
bars = await src.fetch_ohlc_page(
|
|
674
|
+
Symbol.parse("BTC/USD:perp"), 7200, START_NS, END_NS, 2000)
|
|
675
|
+
|
|
676
|
+
assert bars == []
|
|
677
|
+
assert captured == []
|
|
678
|
+
|
|
679
|
+
|
|
457
680
|
class TestStreamCapabilityHonesty:
|
|
458
681
|
"""Declared WS capabilities must match a real implementation (D8)."""
|
|
459
682
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|