-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCtpRealTimeDump.py
More file actions
48 lines (42 loc) · 1.49 KB
/
CtpRealTimeDump.py
File metadata and controls
48 lines (42 loc) · 1.49 KB
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
from pi.ctp.ctpClient import MdApiClient
from optparse import OptionParser
from datetime import date
contractID=[["01","02","03","06","09"],
["02","03","04","06","09"],
["03","04","05","06","09"],
["04","05","06","09","12"],
["05","06","07","09","12"],
["06","07","08","09","12"],
["07","08","09","12","03"],
["08","09","10","12","03"],
["09","10","11","12","03"],
["10","11","12","03","06"],
["11","12","01","03","06"],
["12","01","02","03","06"]]
def get_options():
parser = OptionParser()
parser.add_option('-d', '--dumpToMysql', dest='dump', default=False, action='store_true',
help='dump data to MySQL')
parser.add_option('-f', '--dumpToFile', dest='file', default=True, action='store_true',
help='dump date to file')
opts, args = parser.parse_args()
return opts
def dataDump(options):
year = date.today().year%100
month = date.today().month
MonID = contractID[month-1]
symbols = []
for mon in MonID:
m = int(mon)
if m < month:
year = year + 1
symbols.append("IF" + str(year) + str(mon))
print symbols
print "start dump", "Mysql ", options.dump, "File ", options.file
mdclient = MdApiClient()
for symbol in symbols:
mdclient.addSymbol(symbol)
mdclient.dumpToMysql(options.dump)
mdclient.run()
if __name__ == "__main__":
dataDump(get_options())