Skip to content

Fix history paging and trade tick source - #17

Open
AlexCatarino wants to merge 5 commits into
QuantConnect:masterfrom
AlexCatarino:bug-16-trade-ticks-and-pagination
Open

AlexCatarino wants to merge 5 commits into
QuantConnect:masterfrom
AlexCatarino:bug-16-trade-ticks-and-pagination

Conversation

@AlexCatarino

@AlexCatarino AlexCatarino commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Closes #16.

Paging now continues until a page comes back short, because Databento returns 200 OK even when it truncates. Each page resumes at the previous page's last index timestamp (ts_recv, or ts_event when a schema has no ts_recv) and skips the records already emitted. Trade ticks are read from the trades schema instead of mbp-1.

CI has failed on every run since this repo was created. This PR fixes it:

  • The workflow pointed at the SDK template's project paths.
  • On pull requests it checked out Lean's own PR with the same number.
  • The test config's empty job-user-id broke LEAN's setup.
  • ReturnsCorrectDataBentoDataSet was out of date.

CI now runs only the offline tests, because it has no Databento key.

Also fixes the DataBentoHistoryProivder.cs file name typo.

AlexCatarino and others added 5 commits November 20, 2026 17:16
Page until a short page, resume at the last index timestamp without
gaps or duplicates, and read trade ticks from the trades schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The workflow still pointed at the SDK template's projects. Tests that call the Databento API are left out because CI has no key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github.ref is refs/pull/N/merge there, which fetched Lean's own PR N.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LEAN parses it as an int, so the empty value failed every test's setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexCatarino AlexCatarino added the kronos:review Request review label Nov 20, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 20, 2026

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Requesting changes: the paging and trade-source fixes look right, but nothing shows they work against Databento.

1. Missing proof that the fix works against Databento. The description doesn't say how the change was tested. CI runs only the offline converter and mapper tests, so it doesn't cover the paging loop or the switch to the trades schema. GetTradesPagesPastLimitWithoutGapsOrDuplicates, GetLevelOneDataPagesPastLimitWithoutGapsOrDuplicates and ShouldFetchTicks need an API key, and nothing records that they ran. Please run them and add the results to the description: pass or fail, the record counts, and how many pages each one took. Please also add the outcome of an end-to-end tick trade history request through the history provider. Before and after this change, does it return more than 10,000 ticks with no book updates? That run is what users will see, and it's the evidence risk:low would need.

I checked the loop offline against a stubbed server that filters start (inclusive) and end on ts_recv and truncates at limit with 200 OK. With 20k–30k records and 1, 7 or 50 records per timestamp across page boundaries, it returned every record once, in order, in 3–4 requests. So the logic holds under those assumptions about the API. What's still missing is proof that Databento behaves that way.

2. The file rename is out of scope. Renaming DataBentoHistoryProivder.cs to DataBentoHistoryProvider.cs isn't part of #16. Please move it to its own PR. I'm leaving the CI workflow and test config fixes in: CI can't check this change without them.

Label: risk:high. This changes the history data users get, and there's no run against Databento yet. The results in item 1 would lower it.

Assert.Greater(trades.Count, 10_000, "The window must span more than one page");
Assert.IsTrue(trades.All(t => t.Action == ActionType.Trade));
var barVolume = _client.GetHistoricalOhlcvBars("ESH5", start, end, Resolution.Minute, Dataset).Sum(b => b.Volume);
Assert.AreEqual(barVolume, trades.Sum(t => (decimal)t.Size));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this hold exactly at the window edges? ohlcv-1m filters on ts_event, but trades filters on ts_recv. A trade whose ts_event is just before end and whose ts_recv is just after it is in the bars but not in the trades, and the reverse can happen at start. At 14:30 UTC on ESH5 that can happen. The run result in the review body would answer it. If the test fails for that reason, comparing over bars whose ts_event lies strictly inside the window would avoid the edges.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:high High risk and removed kronos:review:working review: in progress labels Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high High risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

History requests truncate at the page limit and return book updates as trade ticks

1 participant