fix: add end_str to aggregate_trade_iter to bound iteration - #1695
Open
tiyaagarwal wants to merge 1 commit into
Open
fix: add end_str to aggregate_trade_iter to bound iteration#1695tiyaagarwal wants to merge 1 commit into
tiyaagarwal wants to merge 1 commit into
Conversation
aggregate_trade_iter has no way to stop before "now", so collecting trades over a long historical range runs out of memory (sammchardy#497). Adds an optional end_str parameter, following the same convention as get_historical_klines_generator's start_str/end_str pair: the iterator now stops once it has yielded the last trade at or before end_str. Fixed in both Client and AsyncClient, which share this logic. Co-Authored-By: Claude Sonnet 5 <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.
Summary
Fixes #497.
aggregate_trade_iterhad no way to stop before "now" — pullingtrades over a long historical range would keep paginating forever and run
the caller out of memory, exactly as reported.
Adds an optional
end_strparameter, following the same convention alreadyused by
get_historical_klines_generator(start_str/end_str, parsed viaconvert_ts_str). The iterator now stops once it has yielded the last tradeat or before
end_str. Backward compatible: omittingend_strpreservesthe existing unbounded behavior exactly.
Client.aggregate_trade_iterandAsyncClient.aggregate_trade_itersharethis logic (the async version reuses the sync docstring), so both are fixed.
Test plan
start_str,spanning multiple
fromIdpages before hittingend_str, and aregression test confirming behavior without
end_stris unchanged.All run fully offline (mocked
get_aggregate_trades,Client(..., ping=False)to avoid the constructor's network ping).ruff check/ruff formatclean on the changed lines.pytest tests/test_client.py tests/test_async_client.py -k aggregate_trade_iter— 4 passed.Disclosure
I used Claude (Anthropic) to help implement and test this fix; I reviewed
and understand the change. Happy to adjust based on maintainer feedback.