QMT Python API

全市场资金流向

全市场资金流向

qmt://docs/python
Python
1# coding:gbk
2'''
3内置python, 全市场资金流向
4'''
5from datetime import datetime
6 
7 
8def init(C):
9 return
10 
11def after_init(C):
12 stockLst = ["000001.SH","399001.SZ"]
13 today = datetime.today().strftime(r'%Y%m%d')
14 need_download = 1
15 data = {
16 "机构" : 0.0,
17 "主力" : 0.0,
18 "大户" : 0.0,
19 "散户" : 0.0
20 }
21 
22 if need_download:
23 for code in stockLst:
24 download_history_data(code,"transactioncount1d",today,"")
25 
26 market_data = C.get_market_data_ex([],stockLst,period="transactioncount1d",start_time = today, end_time = "")
27 for code in market_data:
28 try:
29 detail = market_data[code]
30 counter = 0
31 data["机构"] += (detail['bidMostAmount'][0] - detail['offMostAmount'][0])
32 counter += 1
33 data["主力"] += (detail['bidBigAmount'][0] - detail['offBigAmount'][0])
34 counter += 1
35 data["大户"] += (detail['bidMediumAmount'][0] - detail['offMediumAmount'][0])
36 counter += 1
37 data["散户"] += (detail['bidSmallAmount'][0] - detail['offSmallAmount'][0])
38 except IndexError:
39 if counter == 1:
40 data["机构"] -= (detail['bidMostAmount'][0] - detail['offMostAmount'][0])
41 elif counter == 2:
42 data["机构"] -= (detail['bidMostAmount'][0] - detail['offMostAmount'][0])
43 data["主力"] -= (detail['bidBigAmount'][0] - detail['offBigAmount'][0])
44 elif counter == 3:
45 data["机构"] -= (detail['bidMostAmount'][0] - detail['offMostAmount'][0])
46 data["主力"] -= (detail['bidBigAmount'][0] - detail['offBigAmount'][0])
47 data["大户"] += (detail['bidMediumAmount'][0] - detail['offMediumAmount'][0])
48 print(f"{code}的数据有问题")
49 continue
50 except KeyError:
51 print(f"{code}的数据有问题")
52 continue
53
54 print(data)
55 return
56
57def handlebar(C):
58 return

智能助手

咨询式 AI · 带入当前文档

智能助手加载中...