Repository navigation
Keep is_buyer_maker aligned with its trade when TradesData sorts and de-duplicates - #9
Merged
Conversation
terbed
self-requested a review
October 25, 2026 21:52
terbed
approved these changes
Oct 25, 2026
terbed
left a comment
Owner
There was a problem hiding this comment.
Nice catch, thanks for the fix!
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
TradesData._sort_tradessorts price, time, amount and id by trade id (and then by timestamp), butis_buyer_makeris held as a separate array and is never re-ordered._merge_tradesthen pairs the sorted columns with the unsorted side array, so for a trades file that is not already in id order every side ends up on the wrong trade. Prices, times and quantities stay correct, so the damage is easy to miss.sideagrees with kline taker-buy volume only at chance level (about 0.0 correlation of 15-minute signed delta), against 0.9999 for months that happen to be in order.preprocess=True,is_buyer_makeris stored as a column of the internal data frame, so sorting and de-duplicating re-order it together with its trade, and_merge_tradesreads it back from the sorted frame. A length check raises aValueErrorifis_buyer_makerdoes not match the number of trades. Inputs that are already sorted behave exactly as before.Related Issues
Testing
NUMBA_DISABLE_JIT=1 pytest -qtests/bars/test_trades_data_side_alignment.pywere run directly (pytest was not available in my environment). The shuffled-input test fails onmainand passes with this change; the sorted-input test passes on both. I also fed the first 3 million rows of a real, out-of-order BTCUSDT trades dump throughTradesDataand compared the result with the same rows pre-sorted by (time, id): timestamps, prices and sides are identical with this change.Documentation
Checklist