Skip to content

fix: keep reversal deals (DEAL_ENTRY_INOUT=2) in closed_deals - #19

Merged
tanem merged 1 commit into
mainfrom
fix/keep-reversal-deals
Jun 12, 2026
Merged

fix: keep reversal deals (DEAL_ENTRY_INOUT=2) in closed_deals#19
tanem merged 1 commit into
mainfrom
fix/keep-reversal-deals

Conversation

@tanem

@tanem tanem commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

The hand-vendored DEAL_ENTRY_INOUT constant was 3, which is actually DEAL_ENTRY_OUT_BY in the official MetaTrader5 enum (IN=0, OUT=1, INOUT=2, OUT_BY=3 — verified against the MetaTrader5 5.0.5735 wheel's constant definitions).

Consequence: fetch_closed_deals silently dropped reversal deals (entry=2). A reversal closes the old position and opens the opposite one in a single deal, and that deal's profit field 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

  • Correct DEAL_ENTRY_INOUT to 2 and add DEAL_ENTRY_OUT_BY = 3 in sources/base.py.
  • Widen the closed-deal filter to OUT/INOUT/OUT_BY in sources/mt5.py.
  • New test test_fetch_closed_deals_keeps_reversal_and_close_by_deals (written first, failed with [2] == [1, 2] before the fix).
  • CLAUDE.md deal-classification gotcha updated.

Snapshot schema is unaffected — entry is stored as a raw int, so no version bump.

Test plan

  • Full suite: 91 passed, 100% coverage
  • ruff check and mypy clean

🤖 Generated with Claude Code

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>
@tanem
tanem merged commit ece8389 into main Jun 12, 2026
1 check passed
@tanem
tanem deleted the fix/keep-reversal-deals branch June 15, 2026 01:29
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