fix: Add _open_positions guard in MarketMakingStrategy.close_position()#117
Merged
Conversation
…() (#117) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
keitaj
commented
Apr 22, 2026
keitaj
left a comment
Owner
Author
There was a problem hiding this comment.
Review: close_position() _open_positions guard
Clean 11-line override that closes the last remaining reduce_only race condition gap. PR #116 covered PositionCloser paths; this covers the BaseStrategy close path used by close_immediately and QUIET hours.
The guard is consistent with the pattern established in PR #116: check _open_positions (updated instantly by FillFeed) rather than relying on the 2-second TTL cache.
Verdict: LGTM
Minimal change, correct logic, good test coverage. Ship it.
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
close_position()in MarketMakingStrategy to check_closer._open_positionsbefore sending reduce_only order_open_positionsis updated by FillFeed on the WS thread with zero cache delay, more reliable than the 2-second TTL position cacheChanges
strategies/market_making_strategy.py: Addclose_position()override with_open_positionsguardtests/test_close_position_guard.py: 3 new tests (skip when not tracked, proceed when tracked, skip for untracked coin)tests/test_reduce_only_force_close.py: Add_closermock with_open_positionsto existing test helperTest plan
flake8passespytestpasses (712 tests)🤖 Generated with Claude Code