mns-common 1.5.1.8__py3-none-any.whl → 1.5.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mns-common might be problematic. Click here for more details.
- mns_common/api/em/concept/__init__.py +7 -0
- mns_common/api/em/concept/em_concept_index_api.py +230 -0
- mns_common/api/em/gd/__init__.py +7 -0
- mns_common/api/em/gd/east_money_stock_gdfx_free_top_10_api.py +252 -0
- mns_common/api/em/real_time/__init__.py +7 -0
- mns_common/api/em/real_time/east_money_debt_api.py +422 -0
- mns_common/api/em/real_time/east_money_etf_api.py +504 -0
- mns_common/api/em/real_time/east_money_stock_a_api.py +305 -0
- mns_common/api/em/real_time/east_money_stock_a_v2_api.py +296 -0
- mns_common/api/em/real_time/east_money_stock_hk_api.py +469 -0
- mns_common/api/em/real_time/east_money_stock_us_api.py +234 -0
- mns_common/api/em/real_time/real_time_quotes_repeat_api.py +359 -0
- {mns_common-1.5.1.8.dist-info → mns_common-1.5.2.0.dist-info}/METADATA +1 -1
- {mns_common-1.5.1.8.dist-info → mns_common-1.5.2.0.dist-info}/RECORD +16 -4
- {mns_common-1.5.1.8.dist-info → mns_common-1.5.2.0.dist-info}/WHEEL +0 -0
- {mns_common-1.5.1.8.dist-info → mns_common-1.5.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 14
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
import pandas as pd
|
|
11
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
12
|
+
from loguru import logger
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def stock_board_concept_name_em() -> pd.DataFrame:
|
|
16
|
+
"""
|
|
17
|
+
东方财富网-行情中心-沪深京板块-概念板块-名称
|
|
18
|
+
https://quote.eastmoney.com/center/boardlist.html#concept_board
|
|
19
|
+
:return: 概念板块-名称
|
|
20
|
+
:rtype: pandas.DataFrame
|
|
21
|
+
"""
|
|
22
|
+
url = "http://79.push2.eastmoney.com/api/qt/clist/get"
|
|
23
|
+
params = {
|
|
24
|
+
"pn": "1",
|
|
25
|
+
"pz": "2000",
|
|
26
|
+
"po": "1",
|
|
27
|
+
"np": "3",
|
|
28
|
+
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
|
29
|
+
"fltt": "2",
|
|
30
|
+
"invt": "2",
|
|
31
|
+
"fid": "f3",
|
|
32
|
+
"fs": "m:90 t:3 f:!50",
|
|
33
|
+
"fields": "f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f26,f33,f11,f62,f128,f124,f107,f104,f105,f136",
|
|
34
|
+
"_": "1626075887768",
|
|
35
|
+
}
|
|
36
|
+
r = requests.get(url, params=params)
|
|
37
|
+
data_json = r.json()
|
|
38
|
+
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
|
39
|
+
temp_df.reset_index(inplace=True)
|
|
40
|
+
temp_df["index"] = range(1, len(temp_df) + 1)
|
|
41
|
+
temp_df.columns = [
|
|
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
|
+
temp_df = temp_df[
|
|
72
|
+
[
|
|
73
|
+
"排名",
|
|
74
|
+
"板块名称",
|
|
75
|
+
"板块代码",
|
|
76
|
+
"最新价",
|
|
77
|
+
"涨跌额",
|
|
78
|
+
"涨跌幅",
|
|
79
|
+
"总市值",
|
|
80
|
+
"换手率",
|
|
81
|
+
"新增日期",
|
|
82
|
+
"上涨家数",
|
|
83
|
+
"下跌家数",
|
|
84
|
+
"领涨股票",
|
|
85
|
+
"领涨股票-涨跌幅",
|
|
86
|
+
]
|
|
87
|
+
]
|
|
88
|
+
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
|
|
89
|
+
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
|
|
90
|
+
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
|
91
|
+
temp_df["总市值"] = pd.to_numeric(temp_df["总市值"], errors="coerce")
|
|
92
|
+
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
|
93
|
+
temp_df["上涨家数"] = pd.to_numeric(temp_df["上涨家数"], errors="coerce")
|
|
94
|
+
temp_df["下跌家数"] = pd.to_numeric(temp_df["下跌家数"], errors="coerce")
|
|
95
|
+
temp_df["领涨股票-涨跌幅"] = pd.to_numeric(temp_df["领涨股票-涨跌幅"], errors="coerce")
|
|
96
|
+
return temp_df
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# 同步所有概念
|
|
100
|
+
def sync_all_concept():
|
|
101
|
+
try:
|
|
102
|
+
stock_board_concept_name_em_df = stock_board_concept_name_em()
|
|
103
|
+
stock_board_concept_name_em_df = stock_board_concept_name_em_df.rename(columns={"排名": "index",
|
|
104
|
+
"板块名称": "concept_name",
|
|
105
|
+
"板块代码": "concept_code",
|
|
106
|
+
"最新价": "now_price",
|
|
107
|
+
"涨跌额": "change",
|
|
108
|
+
"涨跌幅": "chg",
|
|
109
|
+
"总市值": "total_mv",
|
|
110
|
+
"换手率": "exchange",
|
|
111
|
+
"新增日期": "list_day",
|
|
112
|
+
"上涨家数": "up_number",
|
|
113
|
+
"下跌家数": "down_number",
|
|
114
|
+
"领涨股票": "up_header",
|
|
115
|
+
"领涨股票-涨跌幅": "up_header_chg"
|
|
116
|
+
})
|
|
117
|
+
return stock_board_concept_name_em_df
|
|
118
|
+
except BaseException as e:
|
|
119
|
+
logger.error("同步东方财富概念信息异常:{}", e)
|
|
120
|
+
return None
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def stock_board_concept_cons_em(stock_board_code: str = "BK1134") -> pd.DataFrame:
|
|
124
|
+
"""
|
|
125
|
+
东方财富-沪深板块-概念板块-板块成份
|
|
126
|
+
https://quote.eastmoney.com/center/boardlist.html#boards-BK06551
|
|
127
|
+
:param symbol: 板块名称
|
|
128
|
+
:type symbol: str
|
|
129
|
+
:return: 板块成份
|
|
130
|
+
:rtype: pandas.DataFrame
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
url = "http://29.push2.eastmoney.com/api/qt/clist/get"
|
|
134
|
+
params = {
|
|
135
|
+
"pn": "1",
|
|
136
|
+
"pz": "2000",
|
|
137
|
+
"po": "1",
|
|
138
|
+
"np": "3",
|
|
139
|
+
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
|
140
|
+
"fltt": "2",
|
|
141
|
+
"invt": "2",
|
|
142
|
+
"fid": "f3",
|
|
143
|
+
"fs": f"b:{stock_board_code} f:!50",
|
|
144
|
+
"fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152,f45",
|
|
145
|
+
"_": "1626081702127",
|
|
146
|
+
}
|
|
147
|
+
r = requests.get(url, params=params)
|
|
148
|
+
data_json = r.json()
|
|
149
|
+
data_df = pd.DataFrame(data_json["data"])
|
|
150
|
+
if data_frame_util.is_empty(data_df):
|
|
151
|
+
return None
|
|
152
|
+
temp_df_copy = pd.DataFrame(data_json["data"]["diff"])
|
|
153
|
+
temp_df_copy.reset_index(inplace=True)
|
|
154
|
+
temp_df_copy["index"] = range(1, len(temp_df_copy) + 1)
|
|
155
|
+
temp_df_copy.columns = [
|
|
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
|
+
temp_df_copy = temp_df_copy[
|
|
191
|
+
[
|
|
192
|
+
"序号",
|
|
193
|
+
"代码",
|
|
194
|
+
"名称",
|
|
195
|
+
"最新价",
|
|
196
|
+
"涨跌幅",
|
|
197
|
+
"涨跌额",
|
|
198
|
+
"成交量",
|
|
199
|
+
"成交额",
|
|
200
|
+
"振幅",
|
|
201
|
+
"最高",
|
|
202
|
+
"最低",
|
|
203
|
+
"今开",
|
|
204
|
+
"昨收",
|
|
205
|
+
"换手率",
|
|
206
|
+
"市盈率-动态",
|
|
207
|
+
"市净率",
|
|
208
|
+
]
|
|
209
|
+
]
|
|
210
|
+
temp_df = temp_df_copy.copy()
|
|
211
|
+
|
|
212
|
+
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
|
|
213
|
+
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
|
214
|
+
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
|
|
215
|
+
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
|
|
216
|
+
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
|
|
217
|
+
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"], errors="coerce")
|
|
218
|
+
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
|
|
219
|
+
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
|
|
220
|
+
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce")
|
|
221
|
+
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce")
|
|
222
|
+
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
|
223
|
+
temp_df["市盈率-动态"] = pd.to_numeric(temp_df["市盈率-动态"], errors="coerce")
|
|
224
|
+
temp_df["市净率"] = pd.to_numeric(temp_df["市净率"], errors="coerce")
|
|
225
|
+
return temp_df
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if __name__ == '__main__':
|
|
229
|
+
df = stock_board_concept_cons_em()
|
|
230
|
+
print(df)
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 14
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
import akshare as ak
|
|
9
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
10
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
11
|
+
from loguru import logger
|
|
12
|
+
import mns_common.component.em.em_stock_info_api as em_stock_info_api
|
|
13
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
14
|
+
import mns_common.constant.db_name_constant as db_name_constant
|
|
15
|
+
import mns_common.component.company.company_common_service_new_api as company_common_service_new_api
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
|
|
18
|
+
mongodb_util = MongodbUtil('27017')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 获取十大股东
|
|
22
|
+
|
|
23
|
+
def get_stock_gdfx_free_top_10_em_api(str_day, symbol):
|
|
24
|
+
try:
|
|
25
|
+
stock_gdfx_free_top_10_em_df = ak.stock_gdfx_free_top_10_em(symbol=symbol, date=str_day)
|
|
26
|
+
stock_gdfx_free_top_10_em_df.rename(columns={
|
|
27
|
+
"名次": "index",
|
|
28
|
+
"股东名称": "shareholder_name",
|
|
29
|
+
"股东性质": "shareholder_nature",
|
|
30
|
+
"股份性质": "shares_nature",
|
|
31
|
+
"股份类型": "shares_type",
|
|
32
|
+
"持股数": "shares_number",
|
|
33
|
+
"占总流通股本持股比例": "circulation_ratio",
|
|
34
|
+
"增减": "change",
|
|
35
|
+
"变动比率": "change_ratio"
|
|
36
|
+
}, inplace=True)
|
|
37
|
+
except BaseException as e:
|
|
38
|
+
# logger.error("同步十大流通股东信息异常:{}", e)
|
|
39
|
+
return None
|
|
40
|
+
stock_gdfx_free_top_10_em_df = stock_gdfx_free_top_10_em_df.fillna(0)
|
|
41
|
+
stock_gdfx_free_top_10_em_df.index = stock_gdfx_free_top_10_em_df.index.astype(str)
|
|
42
|
+
stock_gdfx_free_top_10_em_df.drop_duplicates('shareholder_name', keep='last', inplace=True)
|
|
43
|
+
|
|
44
|
+
return stock_gdfx_free_top_10_em_df
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_stock_gdfx_top_10_em_api(str_day, symbol):
|
|
48
|
+
try:
|
|
49
|
+
stock_gdfx_top_10_em_df = ak.stock_gdfx_top_10_em(symbol=symbol, date=str_day)
|
|
50
|
+
stock_gdfx_top_10_em_df.rename(columns={
|
|
51
|
+
"名次": "index",
|
|
52
|
+
"股东名称": "shareholder_name",
|
|
53
|
+
"股份类型": "shares_type",
|
|
54
|
+
"持股数": "shares_number",
|
|
55
|
+
"占总股本持股比例": "circulation_ratio",
|
|
56
|
+
"增减": "change",
|
|
57
|
+
"变动比率": "change_ratio"
|
|
58
|
+
}, inplace=True)
|
|
59
|
+
except BaseException as e:
|
|
60
|
+
# logger.error("同步十大股东信息异常:{}", e)
|
|
61
|
+
return None
|
|
62
|
+
stock_gdfx_top_10_em_df = stock_gdfx_top_10_em_df.fillna(0)
|
|
63
|
+
stock_gdfx_top_10_em_df.index = stock_gdfx_top_10_em_df.index.astype(str)
|
|
64
|
+
stock_gdfx_top_10_em_df.drop_duplicates('shareholder_name', keep='last', inplace=True)
|
|
65
|
+
return stock_gdfx_top_10_em_df
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_stock_gdfx_free_top_10_em(str_day, symbol):
|
|
69
|
+
symbol_init = symbol
|
|
70
|
+
classification = common_service_fun_api.classify_symbol_one(symbol)
|
|
71
|
+
if classification in ["S", "C"]:
|
|
72
|
+
symbol = 'sz' + symbol
|
|
73
|
+
elif classification in ["K", "H"]:
|
|
74
|
+
symbol = 'sh' + symbol
|
|
75
|
+
else:
|
|
76
|
+
symbol = 'bj' + symbol
|
|
77
|
+
|
|
78
|
+
str_day_no_slash = date_handle_util.no_slash_date(str_day)
|
|
79
|
+
date_day = date_handle_util.str_to_date(str_day_no_slash, '%Y%m%d')
|
|
80
|
+
month = date_day.month
|
|
81
|
+
year = date_day.year
|
|
82
|
+
one = '0331'
|
|
83
|
+
two = '0630'
|
|
84
|
+
three = '0930'
|
|
85
|
+
four = '1231'
|
|
86
|
+
|
|
87
|
+
if 0 < month <= 4:
|
|
88
|
+
period_04 = str(year - 1) + four
|
|
89
|
+
# 流通十大股东
|
|
90
|
+
stock_gdfx_free_top_10_04 = get_stock_gdfx_free_top_10_em_api(period_04, symbol)
|
|
91
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_04, period_04, symbol_init, str_day)
|
|
92
|
+
|
|
93
|
+
# 十大股东
|
|
94
|
+
stock_gdfx_top_10_04 = get_stock_gdfx_top_10_em_api(period_04, symbol)
|
|
95
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_04, period_04, symbol_init, str_day)
|
|
96
|
+
|
|
97
|
+
if stock_gdfx_free_top_10_04 is None or stock_gdfx_free_top_10_04.shape[0] == 0:
|
|
98
|
+
period_03 = str(year - 1) + three
|
|
99
|
+
stock_gdfx_free_top_10_03 = get_stock_gdfx_free_top_10_em_api(period_03, symbol)
|
|
100
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_03, period_03, symbol_init, str_day)
|
|
101
|
+
|
|
102
|
+
# 十大股东
|
|
103
|
+
stock_gdfx_top_10_03 = get_stock_gdfx_top_10_em_api(period_03, symbol)
|
|
104
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_03, period_03, symbol_init, str_day)
|
|
105
|
+
|
|
106
|
+
period_01 = str(year) + one
|
|
107
|
+
stock_gdfx_free_top_10_01 = get_stock_gdfx_free_top_10_em_api(period_01, symbol)
|
|
108
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_01, period_01, symbol_init, str_day)
|
|
109
|
+
|
|
110
|
+
# 十大股东
|
|
111
|
+
stock_gdfx_top_10_01 = get_stock_gdfx_top_10_em_api(period_01, symbol)
|
|
112
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_01, period_01, symbol_init, str_day)
|
|
113
|
+
|
|
114
|
+
elif 4 < month <= 6:
|
|
115
|
+
# 十大流通股东
|
|
116
|
+
period_01 = str(year) + one
|
|
117
|
+
stock_gdfx_free_top_10_01 = get_stock_gdfx_free_top_10_em_api(period_01, symbol)
|
|
118
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_01, period_01, symbol_init, str_day)
|
|
119
|
+
period_02 = str(year) + two
|
|
120
|
+
stock_gdfx_free_top_10_02 = get_stock_gdfx_free_top_10_em_api(period_02, symbol)
|
|
121
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_02, period_02, symbol_init, str_day)
|
|
122
|
+
|
|
123
|
+
# 十大股东
|
|
124
|
+
stock_gdfx_top_10_01 = get_stock_gdfx_top_10_em_api(period_01, symbol)
|
|
125
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_01, period_01, symbol_init, str_day)
|
|
126
|
+
|
|
127
|
+
stock_gdfx_top_10_02 = get_stock_gdfx_top_10_em_api(period_02, symbol)
|
|
128
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_02, period_02, symbol_init, str_day)
|
|
129
|
+
|
|
130
|
+
elif 6 < month <= 10:
|
|
131
|
+
# 十大流通股东
|
|
132
|
+
period_02 = str(year) + two
|
|
133
|
+
stock_gdfx_free_top_10_02 = get_stock_gdfx_free_top_10_em_api(period_02, symbol)
|
|
134
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_02, period_02, symbol_init, str_day)
|
|
135
|
+
period_03 = str(year) + three
|
|
136
|
+
stock_gdfx_free_top_10_03 = get_stock_gdfx_free_top_10_em_api(period_03, symbol)
|
|
137
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_03, period_03, symbol_init, str_day)
|
|
138
|
+
|
|
139
|
+
# 十大股东
|
|
140
|
+
|
|
141
|
+
stock_gdfx_top_10_02 = get_stock_gdfx_top_10_em_api(period_02, symbol)
|
|
142
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_02, period_02, symbol_init, str_day)
|
|
143
|
+
|
|
144
|
+
stock_gdfx_top_10_03 = get_stock_gdfx_top_10_em_api(period_03, symbol)
|
|
145
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_03, period_03, symbol_init, str_day)
|
|
146
|
+
elif 10 < month <= 12:
|
|
147
|
+
# 十大流通股东
|
|
148
|
+
period_03 = str(year) + three
|
|
149
|
+
stock_gdfx_free_top_10_03 = get_stock_gdfx_free_top_10_em_api(period_03, symbol)
|
|
150
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_03, period_03, symbol_init, str_day)
|
|
151
|
+
period_04 = str(year) + four
|
|
152
|
+
stock_gdfx_free_top_10_04 = get_stock_gdfx_free_top_10_em_api(period_04, symbol)
|
|
153
|
+
sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_04, period_04, symbol_init, str_day)
|
|
154
|
+
|
|
155
|
+
# 十大股东
|
|
156
|
+
stock_gdfx_top_10_03 = get_stock_gdfx_top_10_em_api(period_03, symbol)
|
|
157
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_03, period_03, symbol_init, str_day)
|
|
158
|
+
|
|
159
|
+
stock_gdfx_top_10_04 = get_stock_gdfx_top_10_em_api(period_04, symbol)
|
|
160
|
+
sync_stock_gdfx_top_10(stock_gdfx_top_10_04, period_04, symbol_init, str_day)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# 保存10大流通股东
|
|
164
|
+
def sync_stock_gdfx_free_top_10(stock_gdfx_free_top_10_em_df, period, symbol, str_day):
|
|
165
|
+
if stock_gdfx_free_top_10_em_df is not None and stock_gdfx_free_top_10_em_df.shape[0] > 0:
|
|
166
|
+
# 更新日期
|
|
167
|
+
stock_gdfx_free_top_10_em_df['str_day'] = str_day
|
|
168
|
+
|
|
169
|
+
stock_gdfx_free_top_10_em_df['symbol'] = symbol
|
|
170
|
+
|
|
171
|
+
stock_gdfx_free_top_10_em_df['shares_number_str'] = stock_gdfx_free_top_10_em_df['shares_number'].astype(str)
|
|
172
|
+
|
|
173
|
+
stock_gdfx_free_top_10_em_df[
|
|
174
|
+
'_id'] = symbol + '_' + period + '_' + stock_gdfx_free_top_10_em_df.shares_number_str
|
|
175
|
+
stock_gdfx_free_top_10_em_df['period'] = period
|
|
176
|
+
|
|
177
|
+
query_exist = {'symbol': symbol, 'period': period}
|
|
178
|
+
exist_df = mongodb_util.find_query_data(db_name_constant.STOCK_GDFX_FREE_TOP_10, query_exist)
|
|
179
|
+
now_date = datetime.now()
|
|
180
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
181
|
+
# 不存在的时候更新创建时间
|
|
182
|
+
if exist_df.shape[0] == 0:
|
|
183
|
+
stock_gdfx_free_top_10_em_df['create_day'] = str_day
|
|
184
|
+
stock_gdfx_free_top_10_em_df['sync_time'] = str_now_date
|
|
185
|
+
else:
|
|
186
|
+
if 'create_day' in exist_df.columns:
|
|
187
|
+
stock_gdfx_free_top_10_em_df['create_day'] = list(exist_df['create_day'])[0]
|
|
188
|
+
else:
|
|
189
|
+
stock_gdfx_free_top_10_em_df['create_day'] = str_day
|
|
190
|
+
if 'sync_time' in exist_df.columns:
|
|
191
|
+
stock_gdfx_free_top_10_em_df['sync_time'] = list(exist_df['sync_time'])[0]
|
|
192
|
+
else:
|
|
193
|
+
stock_gdfx_free_top_10_em_df['sync_time'] = str_now_date
|
|
194
|
+
mongodb_util.save_mongo(stock_gdfx_free_top_10_em_df, db_name_constant.STOCK_GDFX_FREE_TOP_10)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
# 保存10大股东
|
|
198
|
+
def sync_stock_gdfx_top_10(stock_gdfx_top_10_em_df, period, symbol, str_day):
|
|
199
|
+
if stock_gdfx_top_10_em_df is not None and stock_gdfx_top_10_em_df.shape[0] > 0:
|
|
200
|
+
stock_gdfx_top_10_em_df['str_day'] = str_day
|
|
201
|
+
stock_gdfx_top_10_em_df['symbol'] = symbol
|
|
202
|
+
|
|
203
|
+
stock_gdfx_top_10_em_df['shares_number_str'] = stock_gdfx_top_10_em_df['shares_number'].astype(str)
|
|
204
|
+
|
|
205
|
+
stock_gdfx_top_10_em_df['_id'] = symbol + '_' + period + '_' + stock_gdfx_top_10_em_df.shares_number_str
|
|
206
|
+
stock_gdfx_top_10_em_df['period'] = period
|
|
207
|
+
|
|
208
|
+
query_exist = {'symbol': symbol, 'period': period}
|
|
209
|
+
exist_df = mongodb_util.find_query_data(db_name_constant.STOCK_GDFX_TOP_10, query_exist)
|
|
210
|
+
now_date = datetime.now()
|
|
211
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
212
|
+
|
|
213
|
+
# 不存在的时候更新创建时间
|
|
214
|
+
if exist_df.shape[0] == 0:
|
|
215
|
+
stock_gdfx_top_10_em_df['create_day'] = str_day
|
|
216
|
+
stock_gdfx_top_10_em_df['sync_time'] = str_now_date
|
|
217
|
+
else:
|
|
218
|
+
if 'create_day' in exist_df.columns:
|
|
219
|
+
stock_gdfx_top_10_em_df['create_day'] = list(exist_df['create_day'])[0]
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
else:
|
|
223
|
+
stock_gdfx_top_10_em_df['create_day'] = str_day
|
|
224
|
+
|
|
225
|
+
if 'sync_time' in exist_df.columns:
|
|
226
|
+
stock_gdfx_top_10_em_df['sync_time'] = list(exist_df['sync_time'])[0]
|
|
227
|
+
else:
|
|
228
|
+
stock_gdfx_top_10_em_df['sync_time'] = str_now_date
|
|
229
|
+
|
|
230
|
+
mongodb_util.save_mongo(stock_gdfx_top_10_em_df, db_name_constant.STOCK_GDFX_TOP_10)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# 十大股东+十大流通股东
|
|
234
|
+
def sync_stock_gdfx_free_top_10_one_day(str_day):
|
|
235
|
+
real_time_quotes = em_stock_info_api.get_a_stock_info()
|
|
236
|
+
real_time_quotes = real_time_quotes.loc[~(
|
|
237
|
+
real_time_quotes['symbol'].isin(company_common_service_new_api.get_de_list_company()))]
|
|
238
|
+
for real_time_one in real_time_quotes.itertuples():
|
|
239
|
+
try:
|
|
240
|
+
get_stock_gdfx_free_top_10_em(str_day, real_time_one.symbol)
|
|
241
|
+
logger.info('同步股票前十大流通东:{},{}', real_time_one.symbol, real_time_one.name)
|
|
242
|
+
except BaseException as e:
|
|
243
|
+
logger.error('同步所有股票前十大流通股本异常:{},{}', real_time_one.symbol, e)
|
|
244
|
+
logger.info('同步所有股票股东列表完成:{}', str_day)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
if __name__ == '__main__':
|
|
248
|
+
get_stock_gdfx_free_top_10_em('20250930', '300697')
|
|
249
|
+
now_date_test = datetime.now()
|
|
250
|
+
str_day_test = now_date_test.strftime('%Y-%m-%d')
|
|
251
|
+
logger.info('同步所有股票前十大流通股本')
|
|
252
|
+
sync_stock_gdfx_free_top_10_one_day(str_day_test)
|