refactor(constants): single source of truth for A-share constants (P1.1)#64
Merged
Conversation
…nts (#47) Closes #47 (P1.1). The lot size, commission/stamp rates, max-position cap, and board price limits were re-declared as literal defaults across trading, strategy, backtest, and risk modules. Introduce src/utils/ashare_constants.py as the canonical source and import the shared values instead of re-hardcoding: - strategy/base.py: PRICE_LIMITS now imported from the canonical module (and re-exported, so backtest/engine's `from src.strategy.base import PRICE_LIMITS` is unchanged); numeric defaults reference LOT_SIZE/COMMISSION_RATE/STAMP_DUTY_RATE. - trading/constraints.py: CHINEXT/STAR prefixes + numeric defaults from canonical. - risk/position_sizer.py: LOT_SIZE / MAX_SINGLE_POSITION from canonical. All values are identical to before — behavior-preserving (verified: PRICE_LIMITS identity-equal across the re-export chain, 249 strategy/backtest/constraint/ risk tests green, ruff clean). Note: each module's board-*detection* logic and rule application still live locally (they genuinely diverge — decimal vs percent limits, differing BSE handling). Unifying that logic is a deeper, behavior-sensitive follow-up; this PR consolidates the constants, which was the drift hazard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Jcstack
enabled auto-merge (squash)
June 26, 2026 03:32
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.
Closes #47. The lot size, commission/stamp rates, max-position cap, and board price limits were re-declared as literal defaults in trading, strategy, backtest, and risk modules. Introduces
src/utils/ashare_constants.pyas the canonical source; the sites now import the shared values instead of re-hardcoding them.strategy/base.py:PRICE_LIMITSimported from canonical and re-exported (sobacktest/engine'sfrom src.strategy.base import PRICE_LIMITSis unchanged); numeric defaults referenceLOT_SIZE/COMMISSION_RATE/STAMP_DUTY_RATE.trading/constraints.py: CHINEXT/STAR prefixes + numeric defaults from canonical.risk/position_sizer.py:LOT_SIZE/MAX_SINGLE_POSITIONfrom canonical.Behavior-preserving — all values identical. Verified:
PRICE_LIMITSidentity-equal across the re-export chain; 249 strategy/backtest/constraint/risk tests green; ruff clean.Scope note: each module's board-detection logic still lives locally (the implementations genuinely diverge — decimal vs percent limits, differing BSE handling). Unifying that logic is a deeper, behavior-sensitive follow-up; this PR removes the duplicated constants, which was the drift hazard. Simulation-only; not investment advice.