@@ -43,8 +43,8 @@ class TradingStrategy:
4343 context : Context = None
4444 metadata : Dict [str , Any ] = None
4545 position_sizes : List [PositionSize ] = []
46- stop_loss_rules : List [StopLossRule ] = []
47- take_profit_rules : List [TakeProfitRule ] = []
46+ stop_losses : List [StopLossRule ] = []
47+ take_profits : List [TakeProfitRule ] = []
4848 symbols : List [str ] = []
4949 trading_symbol : str = None
5050
@@ -56,6 +56,8 @@ def __init__(
5656 data_sources = None ,
5757 metadata = None ,
5858 position_sizes = None ,
59+ stop_losses = None ,
60+ take_profits = None ,
5961 symbols = None ,
6062 trading_symbol = None ,
6163 worker_id = None ,
@@ -111,6 +113,9 @@ def __init__(
111113 f"Interval not set for strategy instance { self .strategy_id } "
112114 )
113115
116+ self .stop_losses = stop_losses
117+ self .take_profits = take_profits
118+
114119 # context initialization
115120 self ._context = None
116121 self ._last_run = None
@@ -360,11 +365,11 @@ def get_take_profit_rule(self, symbol: str) -> Union[TakeProfitRule, None]:
360365 None otherwise.
361366 """
362367
363- if len (self .take_profit_rules ) == 0 :
368+ if self . take_profits is not None and len (self .take_profits ) == 0 :
364369 return None
365370
366371 if self .take_profit_rules_lookup == {}:
367- for tp in self .take_profit_rules :
372+ for tp in self .take_profits :
368373 self .take_profit_rules_lookup [tp .symbol ] = tp
369374
370375 return self .take_profit_rules_lookup .get (symbol , None )
@@ -381,11 +386,11 @@ def get_stop_loss_rule(self, symbol: str) -> Union[StopLossRule, None]:
381386 None otherwise.
382387 """
383388
384- if len (self .stop_loss_rules ) == 0 :
389+ if self . stop_losses is not None and len (self .stop_losses ) == 0 :
385390 return None
386391
387392 if self .stop_loss_rules_lookup == {}:
388- for sl in self .stop_loss_rules :
393+ for sl in self .stop_losses :
389394 self .stop_loss_rules_lookup [sl .symbol ] = sl
390395
391396 return self .stop_loss_rules_lookup .get (symbol , None )
@@ -402,7 +407,7 @@ def get_position_size(self, symbol: str) -> Union[PositionSize, None]:
402407 None otherwise.
403408 """
404409
405- if len (self .position_sizes ) == 0 :
410+ if self . position_sizes is not None and len (self .position_sizes ) == 0 :
406411 raise OperationalException (
407412 f"No position size defined for symbol "
408413 f"{ symbol } in strategy "
0 commit comments