QMT Python API
全市场涨跌幅度统计
全市场涨跌幅度统计
1
# coding:gbk2
'''3
内置python,全市场涨跌幅度统计 4
'''5
6
data = {7
"涨停" : 0,8
"跌停" : 0,9
"涨" : 0,10
"平" : 0,11
"跌" : 0,12
"停牌" : 013
}14
UpSection = {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+" : 022
}23
DownSection = {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+" : 031
}32
33
def init(C): 34
return 35
36
def 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
52
def 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
60
def UpDownTie(tick):61
lastClose, lastPrice = tick['lastClose'], tick['lastPrice']62
gap = round((lastPrice / lastClose - 1) * 100,2)63
if lastPrice > lastClose:64
data['涨'] += 165
gapRate(gap,1)66
elif lastPrice < lastClose:67
data['跌'] += 168
gapRate(0 - gap,-1)69
else:70
data['平'] += 171
return72
73
def UpDownStop(tick, detail):74
UpStop = DownStop = 075
if tick['lastPrice'] >= detail['UpStopPrice']:76
data['涨停'] += 177
elif tick['lastPrice'] <= detail['DownStopPrice']:78
data['跌停'] += 179
return80
81
def 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["停牌"] += 192
93
print(data)94
print(UpSection)95
print(DownSection)96
return97
98
def handlebar(C):99
return