Skip to content

Expose the total order count and share the paging window guard across the api read methods - #9808

Open
jhonabreul wants to merge 10 commits into
QuantConnect:masterfrom
jhonabreul:bug-9798-read-orders-pagination
Open

jhonabreul wants to merge 10 commits into
QuantConnect:masterfrom
jhonabreul:bug-9798-read-orders-pagination

Conversation

@jhonabreul

@jhonabreul jhonabreul commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Description

Api.ReadBacktestOrders and Api.ReadLiveOrders deserialized the total order count the API returns and then discarded it, so a caller could not page. Their default window also sent start=500, end=100 when only start was given.

The fix:

  • ReadBacktestOrders and ReadLiveOrders return the OrdersResponseWrapper, exposing Length next to the page of orders.
  • One private Api.ResolveWindowEnd helper validates the window and defaults an unset end to a full page, used by the orders, insights and logs methods with a cap per endpoint.
  • ReadLiveOrders takes the documented optional algorithmId, placed after projectId like its siblings.
  • New Api.ReadBacktestLog for backtests/read/log, with the query filter; ReadLiveLogs sends the documented query and deploymentLogs.
  • Both log endpoints cap the window at 200 lines; live orders at the documented 1000.
  • The order, log and object store endpoint methods that were public on Api are now declared on IApi.
  • OrderJsonConverter reads the documented triggerTouched field of limit-if-touched orders, which was never deserialized.

Related Issue

#9798

Motivation and Context

Paging through an algorithm's orders is the only way to reconcile fills from research, and the total count is required to do it correctly.

Requires Documentation Change

Yes. The spec should document a 200-line window for both log endpoints (it says 250 for live logs and nothing for backtest logs), and name the trailing stop flag trailingAsPercentage, which is what the API sends, instead of trailingPercentage.

How Has This Been Tested?

  • OrdersTests: offline fixture against a loopback stub asserting the request bodies, the exposed Length, the window guard and the algorithmId handling. 22 passed.
  • LogsTests: same pattern for both log endpoints, including the query and deploymentLogs fields and the 200-line cap. 12 passed.
  • ProjectTests.ReadBacktestOrdersPaginatesThroughAllOrders: pages a real backtest's orders with windows of 20, 50 and 100 and checks every order arrives once. Manual run with api credentials.
  • ProjectTests.ReadBacktestLogPaginatesThroughAllLines and ReadBacktestLogFiltersLinesByQuery: same for the backtest log, with and without a query. Manual run with api credentials.
  • OrderJsonConverterTests: existing suite, 55 passed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

…alidate the paging window

ReadBacktestOrders and ReadLiveOrders now return the OrdersResponseWrapper, whose
Length holds the total order count, instead of only the page of orders, so callers can
page through the whole collection. Both methods share the insights methods' window
guard: a window larger than 100 throws and an end of 0 defaults to start + 100.

Part of QuantConnect#9798
…ing window guard across the api methods

ReadLiveOrders takes an optional algorithmId, documented in the API spec. The window
guard used by the orders, insights and logs methods is now a single helper with a
per-endpoint cap, the log line range defaults to a full window like its siblings, and
the order json converter reads the documented stopTriggered, triggerTouched and
trailingPercentage fields.

Part of QuantConnect#9798
…nt filters to the live logs method

ReadBacktestLog posts to backtests/read/log with the optional query keyword filter and
the shared paging window guard. ReadLiveLogs now sends the documented query and
deploymentLogs fields. The loopback stub server moves out of the orders test fixture
so the new logs fixture can share it.
Adds ReadBacktestOrders, ReadLiveOrders, ReadBacktestLog, UpdateBacktestTags,
CreateLiveCommand and ListObjectStore to the interface, widens ReadLiveLogs to the
query and deploymentLogs arguments, and drops the explicit forwarding implementation
that kept the old arity.
…and search the backtest log

The backtest log endpoint accepts windows of up to 200 lines, unlike the live logs
endpoint's 250, so it gets its own cap. The new credentialed tests run an algorithm
that logs a numbered line per bar, page through the whole log with different window
sizes, and search it with the query filter.
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.

1 participant