Merge pull request #1888 from hlxstc/dev

解决类变量重复赋值的Bug
This commit is contained in:
vn.py 2019-07-02 14:54:14 +08:00 committed by GitHub
commit 3d8da45184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,6 +33,9 @@ class CtaTemplate(ABC):
self.trading = False
self.pos = 0
# 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")