From 1b385cfa1181df20097beeeba138494d5c900fb7 Mon Sep 17 00:00:00 2001 From: XueShan Date: Fri, 15 Dec 2017 13:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=86=85=E5=AE=B9=EF=BC=9A?= =?UTF-8?q?=201.ctaEngine.py=20saveSyncData=E4=B8=AD=E7=9A=84content?= =?UTF-8?q?=E4=B8=8D=E6=98=AFunicode=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C?= =?UTF-8?q?=E5=92=8C=E4=B8=8A=E4=B8=8B=E6=96=87=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=EF=BC=8C=E8=80=8C=E4=B8=94=E5=9C=A8ubuntu=E4=B8=8A=E4=BC=9A?= =?UTF-8?q?=E6=9C=89=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98=202.=20vtEngine.p?= =?UTF-8?q?y=20LogEngine=E7=9A=84=E5=8D=95=E4=BE=8B=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=97=A0=E6=95=88=EF=BC=8C=E9=87=87=E7=94=A8=E4=BA=86=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E4=BE=8B=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/app/ctaStrategy/ctaEngine.py | 2 +- vnpy/trader/vtEngine.py | 26 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 55fb2f8a..73938707 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -590,7 +590,7 @@ class CtaEngine(object): self.mainEngine.dbUpdate(POSITION_DB_NAME, strategy.className, d, flt, True) - content = '策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos) + content = u'策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos) self.writeCtaLog(content) #---------------------------------------------------------------------- diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 50aeb05d..94492c8d 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -535,25 +535,31 @@ class DataEngine(object): ######################################################################## +class Singleton(type): + """ + 单例,应用方式:静态变量 __metaclass__ = Singleton + """ + def __init__(cls, name, bases, dict): + super(Singleton, cls).__init__(name, bases, dict) + cls._instance = None + + def __call__(cls, *args, **kw): + if cls._instance is None: + cls._instance = super(Singleton, cls).__call__(*args, **kw) + return cls._instance + class LogEngine(object): """日志引擎""" + # 单例模式 + __metaclass__ = Singleton + # 日志级别 LEVEL_DEBUG = logging.DEBUG LEVEL_INFO = logging.INFO LEVEL_WARN = logging.WARN LEVEL_ERROR = logging.ERROR LEVEL_CRITICAL = logging.CRITICAL - - # 单例对象 - instance = None - - #---------------------------------------------------------------------- - def __new__(cls, *args, **kwargs): - """创建对象,保证单例""" - if not cls.instance: - cls.instance = super(LogEngine, cls).__new__(cls, *args, **kwargs) - return cls.instance #---------------------------------------------------------------------- def __init__(self):