def save_all(tday, prod_md = misc.PROD_USER): logging.basicConfig(filename="save_all_agent.log",level=logging.INFO,format='%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s') save_insts = filter_main_cont(tday) app_name = 'SaveAgent' config = {'daily_data_days': 0, 'min_data_days': 0} my_agent = agent.SaveAgent(name = app_name, trader = None, cuser = None, instruments=save_insts,tday = tday, config = config) ctp_api.make_user(my_agent, prod_md) try: while 1: time.sleep(1) except KeyboardInterrupt: my_agent.mdapis = []; my_agent.trader = None
def semi_mock(curr_date, user_cfg, insts=[['IF1412', 'IF1503']]): ''' 半模拟 实际行情,mock交易 ''' logging.basicConfig( filename="ctp_semi_mock.log", level=logging.INFO, format= '%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s' ) instruments = list(set(itertools.chain(*insts))) data_func = [ ('d', BaseObject(name = 'ATR_20', sfunc=fcustom(data_handler.ATR, n=20), rfunc=fcustom(data_handler.atr, n=20))), \ ('d', BaseObject(name = 'DONCH_L10', sfunc=fcustom(data_handler.DONCH_L, n=10), rfunc=fcustom(data_handler.donch_l, n=10))),\ ('d', BaseObject(name = 'DONCH_H10', sfunc=fcustom(data_handler.DONCH_H, n=10), rfunc=fcustom(data_handler.donch_h, n=10))),\ ('d', BaseObject(name = 'DONCH_L20', sfunc=fcustom(data_handler.DONCH_L, n=20), rfunc=fcustom(data_handler.donch_l, n=20))),\ ('d', BaseObject(name = 'DONCH_H20', sfunc=fcustom(data_handler.DONCH_H, n=20), rfunc=fcustom(data_handler.donch_h, n=20))),\ ('1m',BaseObject(name = 'EMA_3', sfunc=fcustom(data_handler.EMA, n=3), rfunc=fcustom(data_handler.ema, n=3))), \ ('1m',BaseObject(name = 'EMA_30', sfunc=fcustom(data_handler.EMA, n=30), rfunc=fcustom(data_handler.ema, n=30))) \ ] test_strat = strat.Strategy('TestStrat', [insts], None, data_func, [[1, -1]]) strat_cfg = {'strategies': [test_strat], \ 'folder': 'C:\\dev\\src\\ktlib\\pythonctp\\pyctp\\', \ 'daily_data_days':25, \ 'min_data_days':2 } agent_name = "Test" tday = curr_date my_agent, my_trader = create_agent_with_mocktrader(agent_name, instruments, strat_cfg, tday) ctp_api.make_user(my_agent, user_cfg) req = BaseObject(InstrumentID='cu1502') my_trader.ReqQryInstrumentMarginRate(req) my_trader.ReqQryInstrument(req) my_trader.ReqQryTradingAccount(req) my_agent.resume() try: while 1: time.sleep(1) except KeyboardInterrupt: my_agent.mdapis = [] my_agent.trader = None pass
def save_ctp(tday): prod_md = misc.HT_PROD_MD base.config_logging("save_all_agent.log", level=logging.DEBUG, format = '%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s', to_console = True, console_level = logging.INFO) save_insts = filter_main_cont(tday, filter = False) print "total inst = %s" % len(save_insts) app_name = 'SaveAgent' config = {'daily_data_days': 0, 'min_data_days': 0} my_agent = agent.SaveAgent(name = app_name, trader = None, cuser = None, instruments=save_insts,tday = tday, config = config) ctp_api.make_user(my_agent, prod_md) try: my_agent.resume() while 1: time.sleep(1) except KeyboardInterrupt: my_agent.exit()
def semi_mock(curr_date, user_cfg, insts = [['IF1412', 'IF1503']]): ''' 半模拟 实际行情,mock交易 ''' logging.basicConfig(filename="ctp_semi_mock.log",level=logging.INFO,format='%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s') instruments = list(set(itertools.chain(*insts))) data_func = [ ('d', BaseObject(name = 'ATR_20', sfunc=fcustom(data_handler.ATR, n=20), rfunc=fcustom(data_handler.atr, n=20))), \ ('d', BaseObject(name = 'DONCH_L10', sfunc=fcustom(data_handler.DONCH_L, n=10), rfunc=fcustom(data_handler.donch_l, n=10))),\ ('d', BaseObject(name = 'DONCH_H10', sfunc=fcustom(data_handler.DONCH_H, n=10), rfunc=fcustom(data_handler.donch_h, n=10))),\ ('d', BaseObject(name = 'DONCH_L20', sfunc=fcustom(data_handler.DONCH_L, n=20), rfunc=fcustom(data_handler.donch_l, n=20))),\ ('d', BaseObject(name = 'DONCH_H20', sfunc=fcustom(data_handler.DONCH_H, n=20), rfunc=fcustom(data_handler.donch_h, n=20))),\ ('1m',BaseObject(name = 'EMA_3', sfunc=fcustom(data_handler.EMA, n=3), rfunc=fcustom(data_handler.ema, n=3))), \ ('1m',BaseObject(name = 'EMA_30', sfunc=fcustom(data_handler.EMA, n=30), rfunc=fcustom(data_handler.ema, n=30))) \ ] test_strat = strat.Strategy('TestStrat', [insts], None, data_func, [[1,-1]]) strat_cfg = {'strategies': [test_strat], \ 'folder': 'C:\\dev\\src\\ktlib\\pythonctp\\pyctp\\', \ 'daily_data_days':25, \ 'min_data_days':2 } agent_name = "Test" tday = curr_date my_agent, my_trader = create_agent_with_mocktrader(agent_name, instruments, strat_cfg, tday) ctp_api.make_user(my_agent,user_cfg) req = BaseObject(InstrumentID='cu1502') my_trader.ReqQryInstrumentMarginRate(req) my_trader.ReqQryInstrument(req) my_trader.ReqQryTradingAccount(req) my_agent.resume() try: while 1: time.sleep(1) except KeyboardInterrupt: my_agent.mdapis = []; my_agent.trader = None pass
def save_all(tday, prod_md=misc.PROD_USER): logging.basicConfig( filename="save_all_agent.log", level=logging.INFO, format= '%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s' ) save_insts = filter_main_cont(tday) app_name = 'SaveAgent' config = {'daily_data_days': 0, 'min_data_days': 0} my_agent = agent.SaveAgent(name=app_name, trader=None, cuser=None, instruments=save_insts, tday=tday, config=config) ctp_api.make_user(my_agent, prod_md) try: while 1: time.sleep(1) except KeyboardInterrupt: my_agent.mdapis = [] my_agent.trader = None