QMT Python API

全市场涨跌幅度统计

全市场涨跌幅度统计

qmt://docs/python
Python
1# coding:gbk
2'''
3内置python,全市场涨跌幅度统计
4'''
5 
6data = {
7 "涨停" : 0,
8 "跌停" : 0,
9 "涨" : 0,
10 "平" : 0,
11 "跌" : 0,
12 "停牌" : 0
13}
14UpSection = {
15 "0~2" : 0,
16 "2~4" : 0,
17 "4~7" : 0,
18 "7~10" : 0,
19 "10~20" : 0,
20 "20~30" : 0,
21 "30~30+" : 0
22}
23DownSection = {
24 "-0~-2" : 0,
25 "-2~-4" : 0,
26 "-4~-7" : 0,
27 "-7~-10" : 0,
28 "-10~-20" : 0,
29 "-20~-30" : 0,
30 "-30~-30+" : 0
31}
32 
33def init(C):
34 return
35
36def generateKey(gap):
37 if gap <= 2:
38 return "0~2"
39 elif gap <= 4:
40 return "2~4"
41 elif gap <= 7:
42 return "4~7"
43 elif gap <= 10:
44 return "7~10"
45 elif gap <= 20:
46 return "10~20"
47 elif gap <= 30:
48 return "20~30"
49 else:
50 return "30~30+"
51 
52def gapRate(gap, sign):
53 key = generateKey(gap)
54 if sign < 0:
55 key = '-' + key.replace('~', '~-')
56 DownSection[key] += 1
57 else:
58 UpSection[key] += 1
59 
60def UpDownTie(tick):
61 lastClose, lastPrice = tick['lastClose'], tick['lastPrice']
62 gap = round((lastPrice / lastClose - 1) * 100,2)
63 if lastPrice > lastClose:
64 data['涨'] += 1
65 gapRate(gap,1)
66 elif lastPrice < lastClose:
67 data['跌'] += 1
68 gapRate(0 - gap,-1)
69 else:
70 data['平'] += 1
71 return
72 
73def UpDownStop(tick, detail):
74 UpStop = DownStop = 0
75 if tick['lastPrice'] >= detail['UpStopPrice']:
76 data['涨停'] += 1
77 elif tick['lastPrice'] <= detail['DownStopPrice']:
78 data['跌停'] += 1
79 return
80
81def after_init(C):
82 stockLst = C.get_stock_list_in_sector('沪深A股')
83 ticks = C.get_full_tick(stockLst)
84 
85 for code in ticks:
86 detail = C.get_instrumentdetail(code)
87 tick = ticks[code]
88 UpDownTie(tick)
89 UpDownStop(tick,detail)
90 if tick['openInt'] == 1:
91 data["停牌"] += 1
92 
93 print(data)
94 print(UpSection)
95 print(DownSection)
96 return
97
98def handlebar(C):
99 return

智能助手

咨询式 AI · 带入当前文档

智能助手加载中...