Skip to content

fix(trade): keep rows sharing an id when paging history executions and orders - #634

Open
hogan-yuan wants to merge 2 commits into
mainfrom
fix/trade-paging-dedup
Open

hogan-yuan wants to merge 2 commits into
mainfrom
fix/trade-paging-dedup

Conversation

@hogan-yuan

@hogan-yuan hogan-yuan commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

history_executions and history_orders (paging added in #591 / #627) dedupe every row by trade_id / order_id alone — including rows on the same page. Any rows the server returns under one id collapse into the first one, silently.

What changes

  • Rows are returned exactly as the server sends them; nothing is deduplicated. Keying any dedup on an id that can legitimately repeat would make the result depend on where the 1000-record page boundary falls.
  • The guard the dedup was really for — a gateway that ignores page and answers every request with page 1 — is kept in a different form: paging stops when a page repeats the previous page exactly (same (order_id, trade_id, symbol) / (order_id, symbol) sequence). It also stops on an empty page, when has_more is false, or after 1000 pages.
  • The two near-identical loops are folded into one private helper, fetch_all_pages.

Return types are unchanged, so no binding needed touching.

Trade-off

A later page that partially overlaps an earlier one (e.g. rows shifting between requests) is no longer deduplicated. With these history endpoints the window is fixed by start_at / end_at, so this should not occur; I chose not to drop rows over a hypothetical overlap.

What I could not verify

I have not observed the gateway returning two rows with the same trade_id / order_id; multi-leg orders are the obvious candidate. If ids are always unique, the result is identical to today.

Tests

fetch_all_pages_tests: same-key rows kept within a page and across a page boundary, has_more paging, a gateway ignoring page stops after page 2, an empty page stops.

🤖 Generated with Claude Code

…d orders

history_executions and history_orders deduplicated every row by trade_id / order_id alone, including rows within a single page, so executions or orders reported under one id (e.g. the legs of a multi-leg order) collapsed into the first one. Keep every row of a page and only drop rows a later page repeats from an earlier one, keyed by (order_id, trade_id, symbol) for executions and (order_id, symbol) for orders. Both methods now share fetch_all_pages, which still stops when a page adds nothing new.
…repetition

Keying the cross-page dedup on the same id the previous commit kept within a page made the result depend on where the page boundary fell. Return every row as sent and only stop when a page repeats the previous one exactly (same keys, same order), which is the gateway-ignores-page case the dedup guarded against. Keys are computed once per row.

This branch has not been deployed

No deployments
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