feat: add opt-in validate_symbol parameter to order creation#467
Merged
Conversation
Add validate_symbol parameter (default False) to create_limit_order and create_order in Context and TradingStrategy. When enabled, validates the target_symbol against registered data sources and portfolio positions, raising OperationalException for unknown symbols. Closes #247
Remove symbol format construction from _validate_target_symbol. Validation now does a simple direct comparison of target_symbol against registered data source symbols. The framework should not guess or construct symbol formats. Updates tests to use exact data source symbols.
…mbol (#247) validate_symbol now only prevents nonsensical orders where target_symbol equals trading_symbol (e.g. EUR/EUR). No data source lookups or symbol format construction needed.
validate_symbol now checks two things: 1. target_symbol != trading_symbol (prevents EUR/EUR) 2. A data source is registered for the target_symbol/trading_symbol combination (e.g. BTC/EUR) to ensure price history tracking
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
Adds an opt-in
validate_symbolparameter (defaultFalse) tocreate_limit_order()andcreate_order()on bothContextandTradingStrategy.When enabled, it validates two things:
EUR/EUR)target_symbol/trading_symbolcombination (e.g.BTC/EUR) to ensure price history trackingChanges
investing_algorithm_framework/app/context.py: Added_validate_target_symbol()method andvalidate_symbolparameter tocreate_order()andcreate_limit_order()investing_algorithm_framework/app/strategy.py: Addedvalidate_symbolpassthrough tocreate_limit_order()tests/app/algorithm/test_validate_symbol.py: 11 tests covering:create_order()validationUsage
Closes #247