-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl_service.py
215 lines (177 loc) · 3.94 KB
/
crawl_service.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
"""
通过开源tushare接口从网络抓取证券数据
Created on 2018/05/14
@author: yudong chou
@contact: 33836858@qq.com
"""
import tushare as ts
def get_all_stock_list():
"""
获取沪深上市公司上一个交易日基本情况
"""
return ts.get_stock_basics()
def get_stock_by_code(code, start, end):
"""
根据股票代码获取该股票历史行情
"""
con = ts.get_apis()
try:
res = ts.bar(code,
conn=con,
freq='D',
start_date=start,
end_date=end,
ma=[5, 10, 20, 60],
factors=['vr', 'tor'],
retry_count=2)
return res
except Exception as e:
print('抓取失败个股行情', e)
return None
finally:
ts.close_apis(con)
def get_all_index_list():
"""
获取沪深指数上一个交易日基本情况
"""
return ts.get_index()
def get_index_by_code(code, start, end):
"""
获取指数历史行情
"""
con = ts.get_apis()
try:
res = ts.bar(code,
conn=con,
freq='D',
start_date=start,
end_date=end,
asset='INDEX',
ma=[5, 10, 20, 60],
factors=['vr', 'tor'],
retry_count=2)
return res
except Exception as e:
print('抓取指数行情失败', e)
return None
finally:
ts.close_apis(con)
def get_stock_concept():
"""
获取股票概念
"""
return ts.get_concept_classified()
def get_stock_hs300():
"""
获取沪深300成份及权重
"""
return ts.get_hs300s()
def get_stock_sz50():
"""
获取上证50成份股
"""
return ts.get_sz50s()
def get_stock_zz500():
"""
获取中证500成份股
"""
return ts.get_zz500s()
def get_stock_report(nd, jd):
"""
获取业绩报告(主表)
"""
try:
res = ts.get_report_data(nd, jd)
return res
except:
return None
def get_stock_profit(nd, jd):
"""
获取盈利能力
"""
try:
res = ts.get_profit_data(nd, jd)
return res
except:
return None
def get_stock_operation(nd, jd):
"""
获取营运能力
"""
try:
res = ts.get_operation_data(nd, jd)
return res
except:
return None
def get_stock_growth(nd, jd):
"""
获取成长能力
"""
try:
res = ts.get_growth_data(nd, jd)
return res
except:
return None
def get_stock_debtpaying(nd, jd):
"""
获取偿债能力
"""
try:
res = ts.get_debtpaying_data(nd, jd)
return res
except:
return None
def get_stock_cashflow(nd, jd):
"""
获取现金流量
"""
try:
res = ts.get_cashflow_data(nd, jd)
return res
except:
return None
def get_stock_forecast(nd, jd):
"""
获取业绩预告
"""
try:
res = ts.forecast_data(nd, jd)
return res
except:
return None
def get_stock_xsgjj(nd, yf):
"""
获取限售股解禁
"""
try:
res = ts.xsg_data(nd, yf)
return res
except:
return None
def get_stock_jjcg(nd, jd):
"""
获取基金持股
"""
try:
res = ts.fund_holdings(nd, jd)
return res
except:
return None
def get_stock_winner(datetime):
"""
获取每日龙虎榜列表
"""
try:
res = ts.top_list(datetime)
return res
except:
return None
def main():
print('bac')
if __name__ == '__main__':
#maoyan_example()
print(get_all_index_list())
# start = '2019-06-24'
# end = '2019-07-12'
# code = '600460'
# print(get_stock_by_code(code, start, end))