forked from lemonche/capitalfarmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapitalflow.py
162 lines (117 loc) · 4.48 KB
/
capitalflow.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from .network import *
import json
def moneyflow(code, **kwargs):
"""
当日资金流向
"""
url = 'http://ff.eastmoney.com/EM_CapitalFlowInterface/api/js'
params = {'id': params_converter.symbol_code_2(code),
'type': 'ff',
'rtntype': kwargs.get('rtntype', 2),
'acces_token': '1942f5da9b46b069953c873404aad4b5',
}
fields = ['time', 'inflow', 'outflow', 'net_inflow', 'super_infow', 'super_outflow',
'super_net_inflow', 'large_inflow', 'large_outflow', 'large_net_inflow',
'mid_inflow', 'mid_outflow', 'mid_net_inflow', 'small_inflow',
'small_outflow', 'small_net_inflow', 'col1']
h = html(url=url, params=params)
try:
data = [x.split(",") for x in json.loads(h.content[1:-1])]
return fields, data
except Exception as e:
print(e)
return h
def hist_moneyflow(code, **kwargs):
"""
历史资金流向,只能获取最近100个交易日的数据
"""
url = 'http://ff.eastmoney.com/EM_CapitalFlowInterface/api/js'
params = {'id': params_converter.symbol_code_2(code),
'type': 'hff',
'rtntype': kwargs.get('rtntype', 2),
'acces_token': '1942f5da9b46b069953c873404aad4b5',
}
fields = ['date', 'inflow', 'outflow', 'net_inflow', 'net_infow_percentage',
'super_inflow', 'super_outflow', 'super_net_inflow', 'super_net_infow_percentage',
'large_inflow', 'large_outflow', 'large_net_inflow', 'large_net_infow_percentage',
'mid_inflow', 'mid_outflow', 'mid_net_inflow', 'mid_net_infow_percentage',
'small_inflow', 'small_outflow', 'small_net_inflow', 'small_net_infow_percentage',
'close', 'up_down_percentage', 'col1']
h = html(url=url, params=params)
try:
data = [x.split(",") for x in json.loads(h.content[1:-1])]
return fields, data
except Exception as e:
print(e)
return h
def insti_position(code, date, insti_type='', **kwargs):
"""
机构持仓仓位
:param date: 报告期, 2019-03-31
:param insti_type: 机构类型
空值:所有机构;
1:基金;
2:QFII;
3:社保;
5:保险;
4:券商;
6:信托
:param SHCode: 指定投资产品代码,查看持有该股状况
:return:
"""
url = "http://datainterface3.eastmoney.com/EM_DataCenter_V3/api/ZLCCMX/GetZLCCMX"
params = {"tkn": "eastmoney",
"cfg": "ZLCCMX",
"SHType": insti_type,
"SCode": code,
"ReportDate": date,
"pageNum": kwargs.get('page', ''), # 空值表示不分页
"pageSize": kwargs.get('pagesize', ''),
"sortField": kwargs.get("sortField", 'ShareHDNum'),
"sortDirec": kwargs.get("sortDirec", 1),
"SHCode": kwargs.get("SHCode", '')
}
h = html(url, params)
try:
info = json.loads(h.content)['Data'][0]
info['fields'] = info["FieldName"].split(",")
data = [x.split(info['SplitSymbol']) for x in info.pop("Data")]
return info, data
except Exception as e:
print(e)
return h
def biggest_stock_holder(code, date, type='Lt'):
"""
前十大流通股东、前十大股东
:param date: 报告期
:param type: Lt:十大流通股东;Sd:十大股东
:return:
"""
url = "http://data.eastmoney.com/DataCenter_V3/gdfx/stockholder.ashx"
params = {'type': type,
'code': code[:6],
'date': date,
}
h = html(url, params)
try:
data = json.loads(h.content.decode(encoding='gbk'))['data']
return data
except Exception as e:
print(e)
return h
def stock_holder_number(code, **kwargs):
"""
股东户数
"""
url = "http://data.eastmoney.com/DataCenter_V3/gdhs/GetDetial.ashx"
params = {'page': kwargs.get('page', ''),
'pagesize': kwargs.get('pagesize', ''),
'code': code[:6],
}
h = html(url, params)
try:
data = json.loads(h.content.decode(encoding='gbk'))['data']
return data
except Exception as e:
print(e)
return h