RC2_STATE_NESTED
תוכן זה אינו זמין עדיין בשפה שלך.
Nested collections are not allowed in persistent-state literals.
What it means
A class-body list or dict literal contained another collection — a list element that was itself a list or dict, or a dict value that was. Persistent-state collections are one level deep, holding a single scalar type (int, decimal, bool, or string).
Why it happens
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
matrix = [[1, 2], [3, 4]] # ❌ list of lists
def execute(self): if self.trade.is_flat: self.buy(self.trade){"asian": [0.0, 0.0]} (dict of list) and {"limits": {"max": 100}} (dict of dict) are the same rejection.
How to fix it
Flatten. Parallel collections, or flat named keys, cover almost every real case:
class Good(Strategy): trade = Symbol() sizing = FixedCapital()
# Was: sessions = {"asian": [0.0, 0.0], "london": [0.0, 0.0]} session_highs = {"asian": 0.0, "london": 0.0, "ny": 0.0} session_lows = {"asian": 999999.0, "london": 999999.0, "ny": 999999.0}
def execute(self): if self.trade.high > self.session_highs["asian"]: self.session_highs["asian"] = self.trade.high if self.trade.is_flat: self.buy(self.trade)Or two index-paired lists, when the position is the natural identifier:
class Paired(Strategy): trade = Symbol() sizing = FixedCapital()
highs = [0.0]*5 lows = [999999.0]*5
def execute(self): if self.trade.high > self.highs[0]: self.highs[0] = self.trade.high if self.trade.low < self.lows[0]: self.lows[0] = self.trade.low if self.trade.is_flat: self.buy(self.trade)Related
- Persistent State
RC2_STATE_MIXED— mixed element types in a single list or dict.RC2_STATE_DICT_KEY— dict keys must be string literals.