改进内容: 1.ctaEngine.py saveSyncData中的content不是unicode字符串,和上下文不一致,而且在ubuntu上会有兼容问题 2. vtEngine.py LogEngine的单例模式无效,采用了新的单例模式
This commit is contained in:
parent
1abb73c7ab
commit
1b385cfa11
@ -590,7 +590,7 @@ class CtaEngine(object):
|
|||||||
self.mainEngine.dbUpdate(POSITION_DB_NAME, strategy.className,
|
self.mainEngine.dbUpdate(POSITION_DB_NAME, strategy.className,
|
||||||
d, flt, True)
|
d, flt, True)
|
||||||
|
|
||||||
content = '策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos)
|
content = u'策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos)
|
||||||
self.writeCtaLog(content)
|
self.writeCtaLog(content)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
@ -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):
|
class LogEngine(object):
|
||||||
"""日志引擎"""
|
"""日志引擎"""
|
||||||
|
|
||||||
|
# 单例模式
|
||||||
|
__metaclass__ = Singleton
|
||||||
|
|
||||||
# 日志级别
|
# 日志级别
|
||||||
LEVEL_DEBUG = logging.DEBUG
|
LEVEL_DEBUG = logging.DEBUG
|
||||||
LEVEL_INFO = logging.INFO
|
LEVEL_INFO = logging.INFO
|
||||||
LEVEL_WARN = logging.WARN
|
LEVEL_WARN = logging.WARN
|
||||||
LEVEL_ERROR = logging.ERROR
|
LEVEL_ERROR = logging.ERROR
|
||||||
LEVEL_CRITICAL = logging.CRITICAL
|
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):
|
def __init__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user