From f8b249500d487225b8d8b3734803be332edc1390 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 2 Jul 2019 14:54:01 +0800 Subject: [PATCH] Update template.py --- vnpy/app/cta_strategy/template.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vnpy/app/cta_strategy/template.py b/vnpy/app/cta_strategy/template.py index 7a97bdbd..e88f7afc 100644 --- a/vnpy/app/cta_strategy/template.py +++ b/vnpy/app/cta_strategy/template.py @@ -1,5 +1,6 @@ """""" from abc import ABC +from copy import copy from typing import Any, Callable from vnpy.trader.constant import Interval, Direction, Offset @@ -32,12 +33,12 @@ class CtaTemplate(ABC): self.trading = False self.pos = 0 - if "inited" not in self.variables: - self.variables.insert(0, "inited") - if "trading" not in self.variables: - self.variables.insert(1, "trading") - if "pos" not in self.variables: - self.variables.insert(2, "pos") + # Copy a new variables list here to avoid duplicate insert when multiple + # strategy instances are created with the same strategy class. + self.variables = copy(self.variables) + self.variables.insert(0, "inited") + self.variables.insert(1, "trading") + self.variables.insert(2, "pos") self.update_setting(setting)