Skip to content

feat: add opt-in validate_symbol parameter to order creation (#247)#465

Closed
MDUYN wants to merge 5 commits into
mainfrom
dev
Closed

feat: add opt-in validate_symbol parameter to order creation (#247)#465
MDUYN wants to merge 5 commits into
mainfrom
dev

Conversation

@MDUYN

@MDUYN MDUYN commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an opt-in validate_symbol parameter (default False) to create_limit_order() and create_order() on both Context and TradingStrategy.

When enabled, it validates two things:

  1. target_symbol ≠ trading_symbol — prevents nonsensical orders (e.g. EUR/EUR)
  2. Data source exists — checks that a data source is registered for the target_symbol/trading_symbol combination (e.g. BTC/EUR) to ensure price history tracking

Changes

  • investing_algorithm_framework/app/context.py: Added _validate_target_symbol() method and validate_symbol parameter to create_order() and create_limit_order()
  • investing_algorithm_framework/app/strategy.py: Added validate_symbol passthrough to create_limit_order()
  • tests/app/algorithm/test_validate_symbol.py: 11 tests covering:
    • Default behavior (no validation)
    • target_symbol == trading_symbol rejection (case-insensitive)
    • Missing data source rejection
    • Matching data source acceptance
    • Wrong data source rejection
    • Error messages with registered symbols
    • create_order() validation

Usage

# Default: no validation (backward compatible)
context.create_limit_order(target_symbol="BTC", ...)

# Opt-in: validates target != trading_symbol and data source exists
context.create_limit_order(target_symbol="BTC", ..., validate_symbol=True)

Closes #247

MDUYN added 5 commits April 21, 2026 23:46
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
)

Add 3 tests covering create_order with validate_symbol:
- rejects when no data source registered for the pair
- accepts when matching data source exists
- default behavior skips validation
@MDUYN

MDUYN commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: commits were pushed directly to dev. Will follow proper branch workflow going forward.

@MDUYN MDUYN closed this Apr 22, 2026
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.

Validate target_symbol exists before order is created

1 participant