Skip to content

Commit 837d86b

Browse files
committed
refactor: simplify validate_symbol to direct comparison only (#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.
1 parent d6bcef8 commit 837d86b

3 files changed

Lines changed: 422 additions & 30 deletions

File tree

investing_algorithm_framework/app/context.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
def _validate_target_symbol(self, target_symbol, market=None):
5555
"""
5656
Validate that the target_symbol is a known symbol by checking
57-
against registered data sources and existing portfolio positions.
57+
against registered data source symbols.
5858
5959
Args:
6060
target_symbol: The symbol to validate (e.g., "BTC" or "BTC/EUR")
@@ -73,28 +73,9 @@ def _validate_target_symbol(self, target_symbol, market=None):
7373
if data_source.symbol is not None:
7474
known_symbols.add(data_source.symbol.upper())
7575

76-
# Collect symbols from existing portfolio positions
77-
portfolio = self.portfolio_service.find({"market": market})
78-
79-
if portfolio is not None:
80-
positions = self.position_service.get_all(
81-
{"portfolio": portfolio.id}
82-
)
83-
84-
for position in positions:
85-
if position.symbol is not None:
86-
symbol = f"{position.symbol.upper()}" \
87-
f"/{portfolio.trading_symbol.upper()}"
88-
known_symbols.add(symbol)
89-
90-
# Build the full symbol for comparison
91-
full_symbol = target_symbol.upper()
92-
93-
if "/" not in full_symbol and portfolio is not None:
94-
full_symbol = \
95-
f"{full_symbol}/{portfolio.trading_symbol.upper()}"
76+
target = target_symbol.upper()
9677

97-
if full_symbol not in known_symbols:
78+
if target not in known_symbols:
9879
sorted_symbols = sorted(known_symbols)
9980
raise OperationalException(
10081
f"Symbol '{target_symbol}' is not a known asset. "
@@ -255,7 +236,7 @@ def create_limit_order(
255236
portfolio of the algorithm
256237
validate_symbol (optional): Default False. If set to True,
257238
the target_symbol will be validated against known symbols
258-
from registered data sources and portfolio positions.
239+
from registered data sources.
259240
260241
Returns:
261242
Order: Instance of the order created

0 commit comments

Comments
 (0)