Skip to content

fix(candles): unify completed reads across live and backtest - #660

Open
Jeremy891102 wants to merge 4 commits into
jesse-ai:masterfrom
Jeremy891102:feature/closed-candles
Open

Jeremy891102 wants to merge 4 commits into
jesse-ai:masterfrom
Jeremy891102:feature/closed-candles

Conversation

@Jeremy891102

@Jeremy891102 Jeremy891102 commented Nov 22, 2026 •

Copy link
Copy Markdown

A 30m strategy reading a 4h data route previously went through different get_candles() branches in live and backtest modes. Backtest reads could synthesize and store a forming anchor, and a delayed live execution only filtered by open time, leaving an unclosed higher-timeframe bar visible.

Use one completed-candle contract for the existing get_candles() service, Strategy.get_candles() and Strategy.candles: include a stored row only when open + timeframe <= boundary. Prefer the strategy's thread-local execution cutoff; otherwise use the simulation/live clock. An exact close is included. Reads no longer generate bars or modify storage. No additional public getter is introduced.

For example, at 12:30 UTC a 30m strategy excludes the 12:00–16:00 anchor; at 16:00 it includes it. A delayed execution for 12:30 continues to exclude it even after wall time reaches 16:00.

get_current_candle() retains access to forming bars, including causal higher-timeframe reads during delayed execution. Live aggregation, backtest aggregation/warmup, and intrabar order simulation consume raw observed source rows so the completed-only strategy filter does not remove their forming inputs.

Related to #656. Compatibility: this changes existing getter semantics for strategies that relied on a forming last row, including 1m live reads. Forming-bar consumers should use the existing current-candle service (Strategy.current_candle for the trading route). Completion means elapsed timeframe, not confirmation that a venue's final update has arrived. This intentional change to the default contract needs maintainer review.

Validation:

  • Before implementation, 56 of 66 completed-read cases failed against the existing getter. Tests now cover legacy backtest, timestamp backtest and live storage; 1m/30m/4h/1D; exact and just-before closes; future rows; missing/empty routes; sparse history; storage immutability; a zero cutoff; and per-thread delayed execution.
  • A real 30m strategy / 4h data-route case runs on both backtest engines in step and fast modes. Separate regressions preserve causal forming reads and live candle generation.
  • Affected tests: 230 passed, including the upstream sparse-session cases. Decision times, OHLC checks and trade/balance assertions are retained; forming-bar expectations now use current reads.
  • Existing long-window strategy fingerprints change intentionally: single-route trades 69 -> 64; multi-route 104 -> 100. Recomputed with an independent boolean-mask reader (open + timeframe <= boundary) on the unchanged scenarios, seeds and strategies. Both captures pass, and exact metrics plus complete trade hashes remain asserted. The actual getter reproduces both fingerprints; step/fast equivalence also passes.
  • Pyrefly: 0 errors on the changed service/Strategy and test strategies (6 existing suppressions; no added suppression).
  • Complete final suite: 2,764 passed, 49 skipped, 0 failures/errors in 220.77 seconds, with isolated Rust on PATH so native coordinator checks run.
  • git diff --check passes. Synced with upstream master at 5b97b13a.

Environment: macOS arm64, isolated Python 3.12.4, NumPy 2.5.5, pytest 6.2.5. Native extension built from unchanged jesse-rust in release mode. Synthetic/stored-data tests exercise live storage and clocks; no live exchange, external PostgreSQL integration, or private jesse-live installation was exercised. No new runtime dependencies.

Assisted-by: OpenAI Codex (GPT-6). AI implemented and tested this proposal. No human code review before submission is claimed.

@aminilich

aminilich commented Nov 25, 2026 •

Copy link
Copy Markdown

As far as I understood your proposed fix, its not fixing what I mentioned.
The problem is two separate branch / behavior between Live and Backtest, not accessing to candles.
and I believe defining get_closed_candels( ) is redundant, or?
Not assisted by AI :)

@Jeremy891102

Copy link
Copy Markdown
Author

yea your right, I'll revisit the existing get_candles() paths and establish a shared behavior contract, with cross-mode regression tests, before proposing further changes.

@Jeremy891102
Jeremy891102 marked this pull request as draft November 25, 2026 14:47
@Jeremy891102 Jeremy891102 changed the title feat(candles): add explicit completed-only candle reads fix(candles): unify completed reads across live and backtest Nov 25, 2026
@Jeremy891102
Jeremy891102 marked this pull request as ready for review November 25, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants