forked from harvey1673/pyktrader
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_run.py
55 lines (49 loc) · 1.86 KB
/
test_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import agent
import ctp_api
import lts_api
import base
import time
import logging
import mysqlaccess
import datetime
import misc
def save_LTS(user, insts, run_date):
app_name = 'SaveAgent'
my_agent = agent.SaveAgent(name = app_name, trader = None, cuser = None, instruments=insts, daily_data_days=0, min_data_days=0, tday = run_date)
lts_api.make_user(my_agent, user, insts)
try:
while 1: time.sleep(1)
except KeyboardInterrupt:
my_agent.mdapis = []; my_agent.trader = None
def filter_main_cont(sdate):
insts, prods = mysqlaccess.load_alive_cont(sdate)
main_cont = {}
for pc in prods:
main_cont[pc], exch = mysqlaccess.prod_main_cont_exch(pc)
main_insts = []
for inst in insts:
pc = misc.inst2product(inst)
mth = int(inst[-2:])
if mth in main_cont[pc]:
main_insts.append(inst)
return main_insts
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 save_lts_test(tday):
logging.basicConfig(filename="save_lts_test.log",level=logging.INFO,format='%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s')
save_insts = ['510050', '510050C1502M02500', '510050P1502M02500']
save_LTS(misc.LTS_SO_USER,save_insts)
pass
if __name__ == '__main__':
save_all()
pass