Skip to content

docs(0211): state that the ohlcv window is inclusive on bucket start - #434

Merged
karczuRF merged 3 commits into
developfrom
docs/0211_document-ohlcv-window-boundary-semantics
Nov 30, 2026
Merged

karczuRF merged 3 commits into
developfrom
docs/0211_document-ohlcv-window-boundary-semantics

Conversation

@karczuRF

Copy link
Copy Markdown
Collaborator

Summary

  • /ohlcv docs now say what the window means: a candle is returned when its bucket's start time falls inside [start, end], both ends inclusive. Example from 0120: start=2026-08-14&end=2026-08-19 at 1d returns six candles.
  • A start inside a bucket leaves that bucket out; an end inside one keeps it. The newest candle can be the still-open current bucket and changes until it ends.
  • Stated in the OpenAPI description and start/end params (bundled web/portal/public/openapi.json refreshed) and in overview §4.2, with a revision-history row.
  • §4.2's auto-granularity table no longer claims all → 1d: all and start/end windows take the finest size within 5000 candles.
  • No behaviour change. openapi:verify-bundled, openapi:lint and prices-api unit tests pass.

Task: lore 0211.

…tart

A candle is returned when its bucket starts inside [start, end]: a mid-bucket start drops that bucket, a mid-bucket end keeps it, and the newest candle can be the still-open current bucket. Stated in the /ohlcv OpenAPI description and params (bundled portal copy refreshed) and in overview section 4.2, whose auto-granularity table also stops claiming all defaults to 1d.

@stkrolikiewicz stkrolikiewicz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the whole diff against the handler and the rollup MVs. The inclusive bucket-start semantics match the SQL. One issue on the "still open" bullet: coarse candles keep changing after their bucket ends, so the client rule there isn't safe. Two nits inline.

Comment thread docs/prices-api-general-overview.md Outdated
past `end`.
- `timeframe` anchors to `end` (task 0119): `end=…&timeframe=7d` is the seven days ending
there; without `end` it ends now.
- **The newest candle can be the current bucket, still open.** It is returned while the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this holds for 1m only. /ohlcv reads price_ohlcv_{g} directly, and the coarser tables are filled by refreshable MVs: 15m every minute, 1h every 15 min, 4h hourly, mv_ohlcv_4h_to_1d every 4 h, 1w and 1M once a day. On top of that the mv_reconcile_* views rewrite buckets up to INTERVAL 7 DAY back. So a 1d candle read at 00:30 UTC passes the timestamp + granularity check but can still be missing its last ~4 h, and it can change again for a week. A client caching by this rule keeps a truncated candle.

I'd state the refresh lag and the 7-day reconcile window instead of the client rule. The same sentence is in the OpenAPI description (handlers.rs, openapi.json) and in the revision-history row.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the client rule was only safe for 1m. Replaced it in all four places (overview §4.2, the /ohlcv OpenAPI description + bundled openapi.json, and the revision row): sizes above 1m are rebuilt from the size below on a schedule (15m every minute, 1h every 15 min, 4h hourly, 1d every 4 h, 1w/1M daily), an hourly reconcile pass rewrites them up to 7 days back, so a candle should not be cached as final until its bucket ended more than 7 days ago. The overview now also says outright that timestamp + granularity being past is not "final". ebc4d05

Comment thread docs/prices-api-general-overview.md Outdated
| `end` | ISO8601 | — | Custom range end |
| `granularity` | string | auto | `1m`, `15m`, `1h`, `4h`, `1d`, `1w`, `1M`. Auto-selected if omitted (table below) |
| `start` | ISO8601 | — | Custom range start, **inclusive** (overrides the timeframe's start) |
| `end` | ISO8601 | now | Custom range end, **inclusive**. With `end` alone, the `timeframe` window ends there |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: end alone also switches the grain. explicit_window is start.is_some() || end.is_some(), so timeframe=7d&end=… returns 15m candles, not the table's 1h. Maybe say so here or in the start/end window row.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both now say it: the table row is "start and/or end window", the end row says end alone switches to the finest grain within 5000 candles (timeframe=7d&end=… returns 15m), and the OpenAPI granularity default reads "when start or end is given". ebc4d05

Comment thread docs/prices-api-general-overview.md Outdated
| `30d` | `4h` | ~180 |
| `1y` | `1d` | ~365 |
| `all` | `1d` | variable |
| `all` | finest size within 5000 candles (`1d` until 2029-06-08, then `1w`) | ≤ 5000 |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2029-06-07, not 06-08. 1d holds only while the span is under 5000 days, i.e. up to 4999 days after 2015-09-30 (same note on #432).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ff0a28c together with your #432 note: the table now reads 1d through 2029-06-07 00:00 UTC, then 1w.

finest_for_span keeps 1d only while span.div_ceil(DAY) < 5000, so from
Stellar genesis (2015-09-30) the grain turns weekly after 4999 days, on
2029-06-07 00:00:01 UTC, not on 2029-06-08 as stated. Spotted in review of
PR #432.
Sizes above 1m are rebuilt from the size below on a schedule (15m every
minute up to 1w/1M once a day) and rewritten hourly up to 7 days back, so
the 'timestamp + granularity is past now' rule for a closed candle was
unsafe: a 1d candle read at 00:30 UTC can still lack its last hours.
State the refresh lag and the 7-day reconcile window instead, in the
overview, the /ohlcv OpenAPI description and the revision row.

Also state that end alone switches to the computed granularity, as start
does (timeframe=7d&end=... returns 15m). Spotted in review of PR #434.
@karczuRF
karczuRF merged commit 638beb8 into develop Nov 30, 2026
4 checks passed
karczuRF added a commit that referenced this pull request Nov 30, 2026
All four PRs merged into develop on 2026-11-30 after Stan's review:
- 0253: #432 (d3bee99)
- 0302: #433 (ef601af), writer probe on production recorded
- 0211: #434 (638beb8), overview revision row now links the archive
- 0288: #435 (9ea7b6c)

Each task records the review fixes, status completed, and moves to
archive/.
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