RC2_STATE_DICT_KEY
Dict keys must be string literals.
What it means
A class-body dict literal used a non-string key. Persistent-state dict keys are always strings — the slot is stored and restored by key, and a string key is the one form that survives that round trip unambiguously.
Why it happens
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
by_index = {1: "long", 2: "short"} # ❌ int keys
def execute(self): if self.trade.is_flat: self.buy(self.trade)How to fix it
Use string keys. If integer indexing was the real intent, a list is the better shape.
class Good(Strategy): trade = Symbol() sizing = FixedCapital()
# String-keyed dict labels = {"1": "long", "2": "short"}
# …or a list, when the position IS the identity states = ["long", "short", "flat"]
def execute(self): if self.trade.is_flat: self.buy(self.trade, reason=self.states[0])Related
- Persistent State
RC2_STATE_MIXED— the values in a dict must share one type.RC2_STATE_NESTED— a dict value may not itself be a collection.