def log_handler(self): """自定义 log 记录方式""" this_time = dt.datetime.now() date_str = this_time.strftime('%Y%m%d') return DefaultLogHandler(self.name, log_type='file', filepath='exit_strategry_%s.log' % date_str)
def run_child(): """ Running in the child process. """ subSymbols = CBMomSub + ETFMomSub class myEngine(PushBaseEngine): EventType = 'sina' def init(self): self.source = easyquotation.use('sina') def fetch_quotation(self): return self.source.stocks(subSymbols) broker = 'ht' need_data = 'ht.json' quotation_engine = myEngine # DefaultQuotationEngine quotation_engine.PushInterval = int(3) # 每秒推送一次行情 log_type = 'file' # 'stdout' log_filepath = 'htMulti.log' log_handler = DefaultLogHandler(name='华泰多策略', log_type=log_type, filepath=log_filepath) m = easyquant.MainEngine( broker, need_data, quotation_engines=[quotation_engine], log_handler=log_handler ) m.load_strategy(names=['CBMom', 'ETFMom']) m.start() while True: sleep(1)
def startTHS(): broker = 'ths' need_data = "ht.json" quotation_engine = DefaultQuotationEngine quotation_engine.PushInterval = 10 log_handler = DefaultLogHandler(name='macd', log_type="file", filepath="engine.log") m = easyquant.MainEngine(broker, need_data, quotation_engines=[quotation_engine], log_handler=log_handler) # m.is_watch_strategy = True # 策略文件出现改动时,自动重载,不建议在生产环境下使用 m.load_strategy() m.start()
def init(self): self.source = easyquotation.use('lf') def fetch_quotation(self): return self.source.stocks(['162411', '000002']) quotation_choose = input( '请输入使用行情引擎 1: sina 2: leverfun 十档 行情(目前只选择了 162411, 000002)\n:') quotation_engine = DefaultQuotationEngine if quotation_choose == '1' else LFEngine push_interval = int(input('请输入行情推送间隔(s)\n:')) quotation_engine.PushInterval = push_interval log_type_choose = input('请输入 log 记录方式: 1: 显示在屏幕 2: 记录到指定文件\n: ') log_type = 'stdout' if log_type_choose == '1' else 'file' log_filepath = input('请输入 log 文件记录路径\n: ') if log_type == 'file' else '' log_handler = DefaultLogHandler(name='测试', log_type=log_type, filepath=log_filepath) m = easyquant.MainEngine(broker, need_data, quotation_engines=[quotation_engine], log_handler=log_handler) m.load_strategy() m.start()
def log_handler(self): """自定义 log 记录方式""" return DefaultLogHandler(self.name, log_type='file', filepath='strategy.log')
def log_handler(self): """自定义 log 记录方式""" return DefaultLogHandler(self.name, log_type='stdout', filepath='demo1.log')
def log_handler(self): return DefaultLogHandler(self.name, log_type='file', filepath='%s.log' % self.name)
#!/usr/bin/python3 import easyquotation import easyquant from easyquant import DefaultQuotationEngine, DefaultLogHandler, PushBaseEngine quotation_engine = DefaultQuotationEngine push_interval = int(input('请输入行情推送间隔(s)\n:')) quotation_engine.PushInterval = push_interval log_handler = DefaultLogHandler(name='Monitor', log_type='stdout', filepath='') m = easyquant.MainEngine(None, None, quotation_engines=[quotation_engine], log_handler=log_handler) m.is_watch_strategy = True # 策略文件出现改动时,自动重载,不建议在生产环境下使用 m.load_strategy() m.start()
def log_handler(self): """自定义 log 记录方式""" log = self.name + '.log' return DefaultLogHandler(self.name, log_type='file', filepath=log)
def init(self): self.source = easyquotation.use('lf') def fetch_quotation(self): return self.source.stocks(['162411', '000002']) # quotation_choose = input('请输入使用行情引擎 1: sina 2: leverfun 十档 行情(目前只选择了 162411, 000002)\n:') quotation_engine = DefaultQuotationEngine # if quotation_choose == '1' else LFEngine push_interval = int(input('请输入行情推送间隔(s)\n:')) quotation_engine.PushInterval = push_interval #log_type_choose = input('请输入 log 记录方式: 1: 显示在屏幕 2: 记录到指定文件\n: ') #log_type = 'stdout' if log_type_choose == '1' else 'file' log_type = 'stdout' #log_filepath = input('请输入 log 文件记录路径\n: ') if log_type == 'file' else '' log_handler = DefaultLogHandler(name='测试', log_type=log_type) m = easyquant.MainEngine(broker, need_data, quotation_engines=[quotation_engine], log_handler=log_handler) m.is_watch_strategy = True # 策略文件出现改动时,自动重载,不建议在生产环境下使用 m.load_strategy() m.start()