Repository navigation
fix(history): period totals read the window or say they are incomplete - #99
Merged
Merged
Conversation
…omplete Hyperliquid getFundingPayments(200) returns at most 200 rows / 7 days; portfolio funding24h, MCP get_funding_analysis / get_pnl_analysis and `account pnl --period` summed that list as the period total (240 rows in 24 h gave -200 with fundingIncomplete false; "30d" covered 7 days). Hyperliquid gets a windowed read (getFundingPaymentsSince: one page for a small window, else chunks backward from now; past 20 requests, the newest stretch with how far back it reached). An incomplete window is funding24h null + fundingError in portfolio, meta.incomplete in the MCP tools (trades included for fees), and the new fundingIncomplete / tradesIncomplete fields of `account pnl`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…covers the period "Fewer rows than asked" does not prove a history covers a period: Aster getFundingPayments reads 7 days and getTradeHistory finds its symbols in 7 days of income, so a 30-day total claimed complete. Hyperliquid getTradeHistory filters the latest 2000 fills, and other venues' time windows and page caps are not documented. A list is complete when the venue ends it. Lighter follows the cursor to the end (historyReach). Pacifica trades ([start, now] via start_time / end_time) and funding (no time filter: read whole) follow next_cursor until has_more is false, up to 10 pages — correct whatever the row order; past that nothing is proven. Hyperliquid userFills under 2000 fills is the whole list (getTradesSince, tradesInWindow). Aster gets a windowed funding read (getFundingPaymentsSince): the whole window in one request when it holds fewer than 1000 rows, else day slices newest first, labelled past its request cap; only the documented 7 days are proven, so an older window stays labelled. Elsewhere only rows reaching past the window start prove it; an empty list proves nothing (coveredFrom Infinity, so the label no longer depends on the clock). history pnl, history funding and MCP get_pnl_analysis / get_arb_compare move to the same helpers (new incomplete map; partial still means a venue read failed; --limit applies only to venues without a period read). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getFundingPaymentsSince spent its page budget on empty chunks before the first funding, so a complete 30-day history read with window 0 ended partial after 20 requests. Chunks now stop at the earliest row of the first, oldest-first page: 30 days / 7200 rows is complete, and 10 days / 720 rows takes 5 requests instead of 16. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… read It was 0, which reads as a known zero (TESTING section 4: unknown = null); the --serve envelope, which reads no funding, carried 0 too. The type is now number | null, listed under JSON contract changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…incomplete history compare summed getFundingPayments(--limit) filtered to the period with no marker. It now uses fundingPaymentsInWindow (like MCP get_arb_compare) and reports an incomplete map plus a warning line. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…abels them history report summed the newest 50 trades / funding payments with no time filter under period: <since>. It now reads tradesInWindow / fundingPaymentsInWindow for the period and reports an incomplete map; an unparseable --since is an error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
handleFundingPositions filtered getFundingPayments(100) to the last 24 h. It now uses fundingPaymentsInWindow; a read not proven to cover the day leaves actual24h null and records why in fundingHistoryErrors. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… period incomplete getTradeHistory passed --limit through to userTrades unbounded. It now asks at most 1000 rows per symbol, and the new getTradesSince reports a symbol's full page as coverage back to its oldest fill only. Symbol discovery's COMMISSION-row dependency is documented. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…stricter period rule Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…complete false The code (buildTotals with zero venues, the --serve envelope) already reports null + false; the entry said null implies true. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… not cover it A full page (Hyperliquid's 2000 fills, a capped getFundingPayments / getTradeHistory list) may have cut other rows of its oldest millisecond, so coverage now requires that row to be strictly before the window start. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ions null reason Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…art does not cover it Same tie rule as Hyperliquid getTradesSince and the capped helpers (1b5f144). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…indowed reads report coverage) historyReach was no longer read by tradesInWindow / fundingPaymentsInWindow once getTradesSince / getFundingPaymentsSince existed; null says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… reach A window from 0 (history report / compare with no period) listed ~20 000 day slices before the 60-request cap stopped it; only the newest ASTER_INCOME_MAX_PAGES are built now. Results are unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e errors; the cost of a whole-history report Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
If it holds more than one logical change, consider splitting it for review. |
This was referenced Nov 13, 2026
Conflicts: CHANGELOG.md (both sides kept); portfolio.ts (main's openOrdersForView with this branch's windowed 24 h funding read). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Period totals (funding, fees, PnL over
--since/--period/ 24 h) summed a capped list and presented it as the whole period. They now read the window, and when the window cannot be proven complete they say so: a label on history commands,nullplus a reason on 24 h figures. Never a silent partial sum (SSOT Rule #2).history pnl,history funding, MCPget_arb_compareincompletemap and a warning line when coverage is unprovenportfoliofunding24hnullwithfundingIncomplete/fundingErrorhistory compare --periodincomplete["<venue>.funding"]history report --sinceincomplete; an unparseable--sinceis an errorarb scan --positionsActual 24hnullwith the reason infundingHistoryErrorsgetFundingPaymentsSince/getTradesSince(1000 per symbol; a full page is incomplete)JSON contract changes are in the CHANGELOG with migration notes: new
incompletemaps,funding24h/actual24hcan benull,history report --since <unparseable>isok: false.Costs and limits — please read
/funding/historyhas no time filter, so the read pages the account's whole funding list (up to 10 × 200 rows). An account with more than 2000 lifetime funding rows getsfunding24h: nullwith a warning, and each read costs up to 10 requests (portfolio --watchrepeats this per refresh). Pacifica is the default venue, so this is visible. Stopping early needs the row order confirmed live; it is not guessed here.funding24hisnull. Their end-of-list behaviour needs a live check.--since/--period:history report/compareread the whole history: Hyperliquid up to 20 requests, Aster up to 60, Pacifica up to 10 per list.userTradeslimit of 1000, that a full page holds the newest rows, and income retention. Symbol discovery relies on COMMISSION income rows, so a zero-fee fill on a symbol with no open position or order can be missed.history report/compare/pnl/fundingprint a lower-bound number with an incomplete label, while the 24 h figures arenull. This difference is deliberate and documented.Known, not fixed here (same class, follow-up):
arb/index.ts:1811,arb-auto.ts:3001,funding-arb-strategy.ts:146,spot-perp-arb-strategy.ts:139,funding-auto.ts:573(realized PnL from 50 rows),trade.ts:2247.Size: 17 files, +1128 / −112. This is the last of 4 PRs split from the portfolio-totals work; it could be split again (first-round fixes vs. the
history compare/report/arb scanfollow-ups) if preferred.Checklist
pnpm testpasses (336 files / 7313 tests)tsc --noEmitandtypecheck:testpassTesting standard (docs/TESTING.md §7)
test.skip/.onlyThree independent reviews. The third asked for one MEDIUM (the Aster tie rule) and five LOW items; all are applied in the last five commits. Those five commits were read by the session lead but not sent back for a fourth review. One of them (
35a3016, building fewer Aster day slices) has no test, because its effect is not observable from outside.Live ↔ Unit Test Cross-Validation
Unit tests only. Nothing here was run against live venues; the items under "Costs and limits" list what needs a live check before release.
Merge note
Every open fix PR adds entries to
CHANGELOG.md[Unreleased](keep both sides).🤖 Generated with Claude Code