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):