Hi all,

I am trying to select some securities over the universe selection. After that, I will send order under the OnData function. I hit errors and here is the message:

  1. This asset symbol (KAL 0) was not found in your security list. Please add this security or check it exists before using it with 'Securities.ContainsKey("KAL 0")' in SecurityManager.cs:line 254

 

I am not able to share the backtest, so here is the main.py

  1. # region imports
  2. from AlgorithmImports import *
  3. # endregion
  4. class QCSymbolStudy(QCAlgorithm):
  5. def Initialize(self):
  6. self.SetStartDate(2023, 2, 17) # Set Start Date
  7. self.SetCash(100000) # Set Strategy Cash
  8. self.AddUniverse(self.CoarseSelect, self.FineSelect)
  9. self.UniverseSettings.Resolution = Resolution.Daily
  10. self.is_make_order = True
  11. def OnData(self, data: Slice):
  12. for d in data.Keys:
  13. self.Debug(f"{self.UtcTime} OnData: {d}")
  14. if self.is_make_order:
  15. self.is_make_order = False
  16. self.MarketOrder("KAL", 10)
  17. def CoarseSelect(self, coarse):
  18. return [c.Symbol for c in coarse]
  19. def FineSelect(self, fine):
  20. selected_list = list()
  21. for f in fine:
  22. if "KAL" in f.Symbol.Value:
  23. selected_list.append(f.Symbol)
  24. self.Debug(f"length: {len(selected_list)}")
  25. return selected_list
+ Expand

 

I printed the keys in the function and I saw my target name:

  1. 2023-02-17 05:00:00+00:00 OnData: KAL XZPS318X97QD
  2. 2023-02-17 05:00:00+00:00 OnData: KALA WMCI69Z95F1H
  3. 2023-02-17 05:00:00+00:00 OnData: KALU TK3F5EFUQ739
  4. 2023-02-17 05:00:00+00:00 OnData: CBYL VZKASE9NEYCL

It seems that there is already data received but I still cannot send out order.

I tried to use

  1. self.AddEquity("KAL", Resoltuion.Daily)

This can fix the issue, but the problem is that I need to use universe selection to do a dynamic selection.

 

I would like to ask how to fix this?

 

Thanks

Author

Sulfred

March 2023