fix: keep reversal deals (DEAL_ENTRY_INOUT=2) in closed_deals - #19
Merged
Conversation
The hand-vendored DEAL_ENTRY_INOUT was 3, which is actually DEAL_ENTRY_OUT_BY in the official MetaTrader5 enum (IN=0, OUT=1, INOUT=2, OUT_BY=3). fetch_closed_deals therefore dropped reversal deals (entry=2) entirely — their realised P&L landed in neither closed_deals nor cash_flows, undercounting P&L whenever an EA reversed a position in a single order. Close-by deals were kept, but under the wrong name. Correct the constants, add DEAL_ENTRY_OUT_BY, and widen the closed-deal filter to OUT/INOUT/OUT_BY. Snapshot schema is unaffected (entry is stored as a raw int). Verified against the MetaTrader5 5.0.5735 wheel's constant definitions. Co-Authored-By: Claude Fable 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
The hand-vendored
DEAL_ENTRY_INOUTconstant was3, which is actuallyDEAL_ENTRY_OUT_BYin the official MetaTrader5 enum (IN=0, OUT=1, INOUT=2, OUT_BY=3— verified against theMetaTrader55.0.5735 wheel's constant definitions).Consequence:
fetch_closed_dealssilently dropped reversal deals (entry=2). A reversal closes the old position and opens the opposite one in a single deal, and that deal'sprofitfield carries the closed leg's realised P&L — so the snapshot undercounted P&L whenever an EA reversed a position in one order. Close-by deals (entry=3) were kept, just under the wrong name.Changes
DEAL_ENTRY_INOUTto 2 and addDEAL_ENTRY_OUT_BY = 3insources/base.py.OUT/INOUT/OUT_BYinsources/mt5.py.test_fetch_closed_deals_keeps_reversal_and_close_by_deals(written first, failed with[2] == [1, 2]before the fix).Snapshot schema is unaffected —
entryis stored as a raw int, so no version bump.Test plan
ruff checkandmypyclean🤖 Generated with Claude Code