[Mod]改进周末过滤的代码格式
This commit is contained in:
parent
d54bd105ba
commit
d965e52a5b
@ -1,53 +0,0 @@
|
|||||||
{
|
|
||||||
"CTP_Stock":
|
|
||||||
[
|
|
||||||
[["09:25:00","09:30:00"]],
|
|
||||||
[["09:30:00","11:30:03"],["13:00:00","15:00:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"CTP_Day":
|
|
||||||
[
|
|
||||||
[["08:59:00","09:00:00"]],
|
|
||||||
[["09:00:00","10:15:03"],["10:30:00","11:30:03"],
|
|
||||||
["13:30:00","15:00:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"CTP_N_23_00":
|
|
||||||
[
|
|
||||||
[["08:59:00","09:00:00"],["20:59:00","21:00:00"]],
|
|
||||||
[["09:00:00","10:15:03"],["10:30:00","11:30:03"],
|
|
||||||
["13:30:00","15:00:03"],["21:00:00","23:00:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"CTP_N_23_30":
|
|
||||||
[
|
|
||||||
[["08:59:00","09:00:00"],["20:59:00","21:00:00"]],
|
|
||||||
[["09:00:00","10:15:03"],["10:30:00","11:30:03"],
|
|
||||||
["13:30:00","15:00:03"],["21:00:00","23:30:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"CTP_N_01_00":
|
|
||||||
[
|
|
||||||
[["08:59:00","09:00:00"],["20:59:00","21:00:00"]],
|
|
||||||
[["09:00:00","10:15:03"],["10:30:00","11:30:03"],
|
|
||||||
["13:30:00","15:00:03"],["21:00:00","24:00:00"],["00:00:00","01:00:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"CTP_N_02_30":
|
|
||||||
[
|
|
||||||
[["08:59:00","09:00:00"],["20:59:00","21:00:00"]],
|
|
||||||
[["09:00:00","10:15:03"],["10:30:00","11:30:03"],
|
|
||||||
["13:30:00","15:00:03"],["21:00:00","24:00:00"],["00:00:00","02:30:03"]]
|
|
||||||
],
|
|
||||||
|
|
||||||
"rb": "CTP_N_23_00",
|
|
||||||
"hc": "CTP_N_23_00",
|
|
||||||
"j": "CTP_N_23_30",
|
|
||||||
"jm": "CTP_N_23_30",
|
|
||||||
"m": "CTP_N_23_30",
|
|
||||||
"au": "CTP_N_02_30",
|
|
||||||
"ag": "CTP_N_02_30",
|
|
||||||
"IF": "CTP_Stock",
|
|
||||||
"IC": "CTP_Stock",
|
|
||||||
"IH": "CTP_Stock"
|
|
||||||
}
|
|
@ -9,25 +9,32 @@ from vnpy.trader.vtEvent import EVENT_LOG
|
|||||||
from vnpy.trader.vtEngine import MainEngine, LogEngine
|
from vnpy.trader.vtEngine import MainEngine, LogEngine
|
||||||
from vnpy.trader.gateway import ctpGateway
|
from vnpy.trader.gateway import ctpGateway
|
||||||
from vnpy.trader.app import dataRecorder
|
from vnpy.trader.app import dataRecorder
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def runChildProcess():
|
def runChildProcess():
|
||||||
"""子进程运行函数"""
|
"""子进程运行函数"""
|
||||||
print '-'*20
|
print '-'*20
|
||||||
|
|
||||||
# 创建日志引擎
|
# 创建日志引擎
|
||||||
le = LogEngine()
|
le = LogEngine()
|
||||||
le.setLogLevel(le.LEVEL_INFO)
|
le.setLogLevel(le.LEVEL_INFO)
|
||||||
le.addConsoleHandler()
|
le.addConsoleHandler()
|
||||||
le.info(u'启动行情记录运行子进程')
|
le.info(u'启动行情记录运行子进程')
|
||||||
|
|
||||||
ee = EventEngine2()
|
ee = EventEngine2()
|
||||||
le.info(u'事件引擎创建成功')
|
le.info(u'事件引擎创建成功')
|
||||||
|
|
||||||
me = MainEngine(ee)
|
me = MainEngine(ee)
|
||||||
me.addGateway(ctpGateway)
|
me.addGateway(ctpGateway)
|
||||||
me.addApp(dataRecorder)
|
me.addApp(dataRecorder)
|
||||||
le.info(u'主引擎创建成功')
|
le.info(u'主引擎创建成功')
|
||||||
|
|
||||||
ee.register(EVENT_LOG, le.processLogEvent)
|
ee.register(EVENT_LOG, le.processLogEvent)
|
||||||
le.info(u'注册日志事件监听')
|
le.info(u'注册日志事件监听')
|
||||||
|
|
||||||
me.connect('CTP')
|
me.connect('CTP')
|
||||||
le.info(u'连接CTP接口')
|
le.info(u'连接CTP接口')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
@ -39,29 +46,37 @@ def runParentProcess():
|
|||||||
le.setLogLevel(le.LEVEL_INFO)
|
le.setLogLevel(le.LEVEL_INFO)
|
||||||
le.addConsoleHandler()
|
le.addConsoleHandler()
|
||||||
le.info(u'启动行情记录守护父进程')
|
le.info(u'启动行情记录守护父进程')
|
||||||
|
|
||||||
DAY_START = time(8, 57) # 日盘启动和停止时间
|
DAY_START = time(8, 57) # 日盘启动和停止时间
|
||||||
DAY_END = time(15, 18)
|
DAY_END = time(15, 18)
|
||||||
NIGHT_START = time(20, 57) # 夜盘启动和停止时间
|
NIGHT_START = time(20, 57) # 夜盘启动和停止时间
|
||||||
NIGHT_END = time(2, 33)
|
NIGHT_END = time(2, 33)
|
||||||
|
|
||||||
p = None # 子进程句柄
|
p = None # 子进程句柄
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
currentTime = datetime.now().time()
|
currentTime = datetime.now().time()
|
||||||
recording = False
|
recording = False
|
||||||
|
|
||||||
# 判断当前处于的时间段
|
# 判断当前处于的时间段
|
||||||
if ((currentTime >= DAY_START and currentTime <= DAY_END) or
|
if ((currentTime >= DAY_START and currentTime <= DAY_END) or
|
||||||
(currentTime >= NIGHT_START) or
|
(currentTime >= NIGHT_START) or
|
||||||
(currentTime <= NIGHT_END)):
|
(currentTime <= NIGHT_END)):
|
||||||
recording = True
|
recording = True
|
||||||
if (datetime.today().weekday() == 6 or (datetime.today().weekday() == 5 and
|
|
||||||
(currentTime > NIGHT_END)) or (datetime.today().weekday() == 0 and
|
# 过滤周末时间段:周六全天,周五夜盘,周日日盘
|
||||||
currentTime < DAY_START )):
|
if ((datetime.today().weekday() == 6) or
|
||||||
|
(datetime.today().weekday() == 5 and currentTime > NIGHT_END) or
|
||||||
|
(datetime.today().weekday() == 0 and currentTime < DAY_START)):
|
||||||
recording = False
|
recording = False
|
||||||
|
|
||||||
# 记录时间则需要启动子进程
|
# 记录时间则需要启动子进程
|
||||||
if recording and p is None:
|
if recording and p is None:
|
||||||
le.info(u'启动子进程')
|
le.info(u'启动子进程')
|
||||||
p = multiprocessing.Process(target=runChildProcess)
|
p = multiprocessing.Process(target=runChildProcess)
|
||||||
p.start()
|
p.start()
|
||||||
le.info(u'子进程启动成功')
|
le.info(u'子进程启动成功')
|
||||||
|
|
||||||
# 非记录时间则退出子进程
|
# 非记录时间则退出子进程
|
||||||
if not recording and p is not None:
|
if not recording and p is not None:
|
||||||
le.info(u'关闭子进程')
|
le.info(u'关闭子进程')
|
||||||
@ -69,12 +84,10 @@ def runParentProcess():
|
|||||||
p.join()
|
p.join()
|
||||||
p = None
|
p = None
|
||||||
le.info(u'子进程关闭成功')
|
le.info(u'子进程关闭成功')
|
||||||
|
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#runChildProcess()
|
#runChildProcess()
|
||||||
import sys
|
|
||||||
reload(sys)
|
|
||||||
sys.setdefaultencoding('UTF-8')
|
|
||||||
runParentProcess()
|
runParentProcess()
|
||||||
|
@ -17,7 +17,7 @@ from vnpy.data.datayes import DatayesApi
|
|||||||
from vnpy.trader.vtGlobal import globalSetting
|
from vnpy.trader.vtGlobal import globalSetting
|
||||||
from vnpy.trader.vtConstant import *
|
from vnpy.trader.vtConstant import *
|
||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from .ctaBase import SETTING_DB_NAME, TICK_DB_NAME, MINUTE_DB_NAME
|
from .ctaBase import SETTING_DB_NAME, TICK_DB_NAME, MINUTE_DB_NAME, DAILY_DB_NAME
|
||||||
|
|
||||||
|
|
||||||
# 以下为vn.trader和通联数据规定的交易所代码映射
|
# 以下为vn.trader和通联数据规定的交易所代码映射
|
||||||
|
Loading…
Reference in New Issue
Block a user