forked from harvey1673/pyktrader2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_launcher.py
61 lines (57 loc) · 2.26 KB
/
app_launcher.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
56
57
58
59
60
61
import tradeagent as agent
import datetime
import sys
import time
import logging
import mysqlaccess
import misc
import base
import json
from agent_gui import *
def get_option_map(underliers, expiries, strikes):
opt_map = {}
for under, expiry, ks in zip(underliers, expiries, strikes):
for otype in ['C', 'P']:
for strike in ks:
cont_mth = int(under[-4:]) + 200000
key = (str(under), cont_mth, otype, strike)
instID = under
if instID[:2] == "IF":
instID = instID.replace('IF', 'IO')
instID = instID + '-' + otype + '-' + str(strike)
opt_map[key] = instID
return opt_map
def save(name, config_file, tday, filter):
base.config_logging(name + "\\" + name + ".log", level=logging.DEBUG,
format = '%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s',
to_console = True,
console_level = logging.INFO)
scur_day = datetime.datetime.strptime(tday, '%Y%m%d').date()
filter_flag = (int(filter)>0)
with open(config_file, 'r') as infile:
config = json.load(infile)
save_agent = agent.SaveAgent(name = name, tday = scur_day, config = config)
curr_insts = misc.filter_main_cont(tday, filter_flag)
for inst in curr_insts:
save_agent.add_instrument(inst)
try:
save_agent.restart()
while 1:
time.sleep(1)
except KeyboardInterrupt:
save_agent.exit()
def run(name, config_file, tday, agent_class = 'agent.Agent'):
base.config_logging(name + "\\" + name + ".log", level=logging.DEBUG,
format = '%(name)s:%(funcName)s:%(lineno)d:%(asctime)s %(levelname)s %(message)s',
to_console = True,
console_level = logging.INFO)
scur_day = datetime.datetime.strptime(tday, '%Y%m%d').date()
myApp = MainApp(name, scur_day, config_file, agent_class = agent_class, master = None)
myGui = Gui(myApp)
# myGui.iconbitmap(r'c:\Python27\DLLs\thumbs-up-emoticon.ico')
myGui.mainloop()
if __name__ == '__main__':
args = sys.argv[1:]
app_name = args[0]
params = (args[1], args[2], args[3], args[4], )
getattr(sys.modules[__name__], app_name)(*params)