mns-scheduler 1.4.0.2__py3-none-any.whl → 1.4.3.3__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-scheduler might be problematic. Click here for more details.
- mns_scheduler/company_info/base/sync_company_base_info_api.py +148 -65
- mns_scheduler/company_info/base/sync_company_hold_info_api.py +2 -5
- mns_scheduler/company_info/base/sync_company_product_area_industry.py +0 -5
- mns_scheduler/company_info/clean/company_info_clean_api.py +1 -1
- mns_scheduler/company_info/constant/company_constant_data.py +3 -0
- mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +33 -30
- mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +4 -5
- mns_scheduler/irm/stock_irm_cninfo_service.py +3 -2
- mns_scheduler/k_line/clean/k_line_info_clean_task.py +7 -2
- mns_scheduler/risk/transactions/transactions_check_api.py +1 -1
- mns_scheduler/self_choose/ths_self_choose_service.py +21 -13
- mns_scheduler/trade/sync_position_api.py +38 -5
- mns_scheduler/zb/stock_zb_pool_sync.py +1 -1
- mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +250 -55
- mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +23 -12
- mns_scheduler/zz_task/compensation/compensate_task_one_day.py +2 -2
- mns_scheduler/zz_task/data_sync_task.py +6 -6
- {mns_scheduler-1.4.0.2.dist-info → mns_scheduler-1.4.3.3.dist-info}/METADATA +1 -1
- {mns_scheduler-1.4.0.2.dist-info → mns_scheduler-1.4.3.3.dist-info}/RECORD +21 -23
- mns_scheduler/debt/__init__.py +0 -7
- mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
- {mns_scheduler-1.4.0.2.dist-info → mns_scheduler-1.4.3.3.dist-info}/WHEEL +0 -0
- {mns_scheduler-1.4.0.2.dist-info → mns_scheduler-1.4.3.3.dist-info}/top_level.txt +0 -0
|
@@ -34,67 +34,6 @@ result_lock = threading.Lock()
|
|
|
34
34
|
result = []
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
# 计算实际流通比例
|
|
38
|
-
def calculate_circulation_ratio(symbol):
|
|
39
|
-
query = {"symbol": symbol}
|
|
40
|
-
stock_gdfx_free_top_10 = mongodb_util.descend_query(query, 'stock_gdfx_free_top_10', "period", 10)
|
|
41
|
-
if stock_gdfx_free_top_10.shape[0] == 0:
|
|
42
|
-
mv_circulation_ratio = 1
|
|
43
|
-
else:
|
|
44
|
-
# 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
|
|
45
|
-
stock_gdfx_free_top_10['is_hk'] = stock_gdfx_free_top_10['shareholder_name'].apply(
|
|
46
|
-
lambda shareholder_name: "HK" if shareholder_name.startswith('香港中央结算') or shareholder_name.startswith(
|
|
47
|
-
'HKSCC') else "A")
|
|
48
|
-
|
|
49
|
-
# 持股大于5% # 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
|
|
50
|
-
stock_gdfx_free_top_10 = stock_gdfx_free_top_10.loc[
|
|
51
|
-
(stock_gdfx_free_top_10['circulation_ratio'] >= 5) & (stock_gdfx_free_top_10['is_hk'] == 'A')]
|
|
52
|
-
|
|
53
|
-
circulation_ratio = sum(stock_gdfx_free_top_10['circulation_ratio'])
|
|
54
|
-
mv_circulation_ratio = round((100 - circulation_ratio) / 100, 2)
|
|
55
|
-
# 防止错误数据
|
|
56
|
-
if mv_circulation_ratio < 0:
|
|
57
|
-
mv_circulation_ratio = 1
|
|
58
|
-
return mv_circulation_ratio
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def get_east_money_stock_info():
|
|
62
|
-
all_real_time_quotes = em_stock_info_api.get_a_stock_info()
|
|
63
|
-
all_real_time_quotes = all_real_time_quotes[['symbol',
|
|
64
|
-
'name',
|
|
65
|
-
"now_price",
|
|
66
|
-
'total_mv',
|
|
67
|
-
'flow_mv',
|
|
68
|
-
'pe_ttm',
|
|
69
|
-
'sz_sh',
|
|
70
|
-
'area',
|
|
71
|
-
'pb',
|
|
72
|
-
'list_date',
|
|
73
|
-
'ROE',
|
|
74
|
-
'total_share',
|
|
75
|
-
'flow_share',
|
|
76
|
-
'industry',
|
|
77
|
-
'amount',
|
|
78
|
-
"hk_stock_code",
|
|
79
|
-
"hk_stock_name",
|
|
80
|
-
'concept']]
|
|
81
|
-
|
|
82
|
-
return all_real_time_quotes
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def create_index():
|
|
86
|
-
mongodb_util.create_index('company_info',
|
|
87
|
-
[("classification", 1)])
|
|
88
|
-
mongodb_util.create_index('company_info',
|
|
89
|
-
[("industry", 1)])
|
|
90
|
-
mongodb_util.create_index('company_info',
|
|
91
|
-
[("flow_mv", 1)])
|
|
92
|
-
mongodb_util.create_index('company_info',
|
|
93
|
-
[("list_date", 1)])
|
|
94
|
-
mongodb_util.create_index('company_info',
|
|
95
|
-
[("symbol", 1)])
|
|
96
|
-
|
|
97
|
-
|
|
98
37
|
# 同步公司基本信息
|
|
99
38
|
|
|
100
39
|
def sync_company_base_info(symbol_list):
|
|
@@ -102,6 +41,8 @@ def sync_company_base_info(symbol_list):
|
|
|
102
41
|
result = []
|
|
103
42
|
create_index()
|
|
104
43
|
east_money_stock_info = get_east_money_stock_info()
|
|
44
|
+
east_money_stock_info = east_money_stock_info.sort_values(by=['list_date'], ascending=False)
|
|
45
|
+
|
|
105
46
|
de_listed_stock_list = company_common_service_api.get_de_list_company()
|
|
106
47
|
east_money_stock_info = east_money_stock_info.loc[~(
|
|
107
48
|
east_money_stock_info['symbol'].isin(de_listed_stock_list))]
|
|
@@ -145,6 +86,30 @@ def sync_company_base_info(symbol_list):
|
|
|
145
86
|
single_thread_sync_company_info(fail_df, kpl_real_time_quotes, exist_company_df)
|
|
146
87
|
|
|
147
88
|
|
|
89
|
+
def get_east_money_stock_info():
|
|
90
|
+
all_real_time_quotes = em_stock_info_api.get_a_stock_info()
|
|
91
|
+
all_real_time_quotes = all_real_time_quotes[['symbol',
|
|
92
|
+
'name',
|
|
93
|
+
"now_price",
|
|
94
|
+
'total_mv',
|
|
95
|
+
'flow_mv',
|
|
96
|
+
'pe_ttm',
|
|
97
|
+
'sz_sh',
|
|
98
|
+
'area',
|
|
99
|
+
'pb',
|
|
100
|
+
'list_date',
|
|
101
|
+
'ROE',
|
|
102
|
+
'total_share',
|
|
103
|
+
'flow_share',
|
|
104
|
+
'industry',
|
|
105
|
+
'amount',
|
|
106
|
+
"hk_stock_code",
|
|
107
|
+
"hk_stock_name",
|
|
108
|
+
'concept']]
|
|
109
|
+
|
|
110
|
+
return all_real_time_quotes
|
|
111
|
+
|
|
112
|
+
|
|
148
113
|
def single_thread_sync_company_info(east_money_stock_info,
|
|
149
114
|
kpl_real_time_quotes, exist_company_df):
|
|
150
115
|
global result
|
|
@@ -201,12 +166,23 @@ def single_thread_sync_company_info(east_money_stock_info,
|
|
|
201
166
|
company_info_type['total_mv_sp'] = company_one.total_mv_sp
|
|
202
167
|
company_info_type['flow_mv_level'] = company_one.flow_mv_level
|
|
203
168
|
company_info_type['classification'] = company_one.classification
|
|
204
|
-
|
|
205
|
-
# 获取同花顺最新概念
|
|
206
|
-
company_info_type = ths_concept_common_service_api.set_ths_concept(company_one.symbol, company_info_type)
|
|
169
|
+
|
|
207
170
|
now_date = datetime.now()
|
|
208
171
|
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
172
|
+
|
|
173
|
+
now_str_day = now_date.strftime('%Y-%m-%d')
|
|
209
174
|
company_info_type['sync_date'] = str_now_date
|
|
175
|
+
|
|
176
|
+
result_dict = calculate_circulation_ratio(company_one.symbol, now_str_day)
|
|
177
|
+
|
|
178
|
+
company_info_type['mv_circulation_ratio'] = result_dict['mv_circulation_ratio']
|
|
179
|
+
company_info_type['qfii_type'] = result_dict['qfii_type']
|
|
180
|
+
company_info_type['qfii_number'] = result_dict['qfii_number']
|
|
181
|
+
company_info_type['share_holder_sync_day'] = result_dict['share_holder_sync_day']
|
|
182
|
+
|
|
183
|
+
# 获取同花顺最新概念
|
|
184
|
+
company_info_type = ths_concept_common_service_api.set_ths_concept(company_one.symbol, company_info_type)
|
|
185
|
+
|
|
210
186
|
fix_symbol_industry_df = company_constant_data.get_fix_symbol_industry()
|
|
211
187
|
if company_one.symbol in list(fix_symbol_industry_df['symbol']):
|
|
212
188
|
# fix sw_industry
|
|
@@ -257,6 +233,113 @@ def single_thread_sync_company_info(east_money_stock_info,
|
|
|
257
233
|
result = fail_list
|
|
258
234
|
|
|
259
235
|
|
|
236
|
+
# 计算实际流通比例
|
|
237
|
+
def calculate_circulation_ratio(symbol, now_str_day):
|
|
238
|
+
query = {"symbol": symbol}
|
|
239
|
+
stock_gdfx_free_top_1 = mongodb_util.descend_query(query, 'stock_gdfx_free_top_10', "period", 1)
|
|
240
|
+
if stock_gdfx_free_top_1.shape[0] == 0:
|
|
241
|
+
mv_circulation_ratio = 1
|
|
242
|
+
qfii_number = 0
|
|
243
|
+
qfii_type = 'A股'
|
|
244
|
+
share_holder_sync_day = now_str_day
|
|
245
|
+
else:
|
|
246
|
+
period_time = list(stock_gdfx_free_top_1['period'])[0]
|
|
247
|
+
|
|
248
|
+
query_free = {'symbol': symbol, 'period': period_time}
|
|
249
|
+
stock_gdfx_free_top_10 = mongodb_util.find_query_data('stock_gdfx_free_top_10', query_free)
|
|
250
|
+
|
|
251
|
+
stock_gdfx_free_top_10['shares_number_str'] = stock_gdfx_free_top_10['shares_number'].astype(str)
|
|
252
|
+
|
|
253
|
+
stock_gdfx_free_top_10['id_key'] = stock_gdfx_free_top_10['symbol'] + '_' + stock_gdfx_free_top_10[
|
|
254
|
+
'period'] + '_' + stock_gdfx_free_top_10.shares_number_str
|
|
255
|
+
|
|
256
|
+
stock_gdfx_free_top_10.drop_duplicates('id_key', keep='last', inplace=True)
|
|
257
|
+
|
|
258
|
+
# 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
|
|
259
|
+
stock_gdfx_free_top_10['is_hk'] = stock_gdfx_free_top_10['shareholder_name'].apply(
|
|
260
|
+
lambda shareholder_name: "HK" if shareholder_name.startswith('香港中央结算') or shareholder_name.startswith(
|
|
261
|
+
'HKSCC') else "A")
|
|
262
|
+
|
|
263
|
+
# 持股大于5% 减持需要发公告
|
|
264
|
+
# 排除香港结算公司不发公共 小于5%减持不用发公告
|
|
265
|
+
# 香港中央结算 HKSCC
|
|
266
|
+
stock_free_top_greater_than_5 = stock_gdfx_free_top_10.loc[
|
|
267
|
+
(stock_gdfx_free_top_10['circulation_ratio'] >= 5) & (stock_gdfx_free_top_10['is_hk'] == 'A')]
|
|
268
|
+
|
|
269
|
+
stock_free_qfii = stock_gdfx_free_top_10.loc[stock_gdfx_free_top_10['shareholder_nature'] == 'QFII']
|
|
270
|
+
|
|
271
|
+
share_holder_sync_day = list(stock_gdfx_free_top_10['create_day'])[0]
|
|
272
|
+
|
|
273
|
+
# qfii 数量
|
|
274
|
+
qfii_number = stock_free_qfii.shape[0]
|
|
275
|
+
# qfii 类型
|
|
276
|
+
qfii_type = set_qfii_type(qfii_number, stock_free_qfii.copy())
|
|
277
|
+
|
|
278
|
+
circulation_ratio = sum(stock_free_top_greater_than_5['circulation_ratio'])
|
|
279
|
+
mv_circulation_ratio = round((100 - circulation_ratio) / 100, 2)
|
|
280
|
+
# 防止错误数据
|
|
281
|
+
if mv_circulation_ratio < 0:
|
|
282
|
+
mv_circulation_ratio = 1
|
|
283
|
+
|
|
284
|
+
result_dict = {
|
|
285
|
+
'mv_circulation_ratio': mv_circulation_ratio,
|
|
286
|
+
'qfii_type': qfii_type,
|
|
287
|
+
'qfii_number': qfii_number,
|
|
288
|
+
'share_holder_sync_day': share_holder_sync_day
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
return result_dict
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def set_qfii_type(qfii_number, stock_free_qfii):
|
|
295
|
+
if qfii_number > 0:
|
|
296
|
+
stock_free_qfii['new_change'] = stock_free_qfii['change']
|
|
297
|
+
stock_free_qfii.loc[stock_free_qfii['change_ratio'] == 0, 'new_change'] = 0
|
|
298
|
+
stock_free_qfii.loc[stock_free_qfii['change'] == '新进', 'new_change'] = \
|
|
299
|
+
stock_free_qfii['shares_number']
|
|
300
|
+
stock_free_qfii['new_change'] = stock_free_qfii['new_change'].astype(float)
|
|
301
|
+
|
|
302
|
+
stock_free_qfii_new_in = stock_free_qfii.loc[stock_free_qfii['change'] == '新进']
|
|
303
|
+
if data_frame_util.is_not_empty(stock_free_qfii_new_in):
|
|
304
|
+
qfii_type = 1
|
|
305
|
+
return qfii_type
|
|
306
|
+
|
|
307
|
+
stock_free_qfii_add = stock_free_qfii.loc[
|
|
308
|
+
(~stock_free_qfii['change'].isin(['不变', '新进'])) & (stock_free_qfii['new_change'] > 0)]
|
|
309
|
+
|
|
310
|
+
if data_frame_util.is_not_empty(stock_free_qfii_add):
|
|
311
|
+
qfii_type = 2
|
|
312
|
+
return qfii_type
|
|
313
|
+
|
|
314
|
+
stock_free_qfii_not_change = stock_free_qfii.loc[stock_free_qfii['change'] == '不变']
|
|
315
|
+
|
|
316
|
+
if data_frame_util.is_not_empty(stock_free_qfii_not_change):
|
|
317
|
+
qfii_type = 3
|
|
318
|
+
return qfii_type
|
|
319
|
+
|
|
320
|
+
stock_free_qfii_reduce = stock_free_qfii.loc[
|
|
321
|
+
(~stock_free_qfii['change'].isin(['不变', '新进'])) & (stock_free_qfii['new_change'] < 0)]
|
|
322
|
+
|
|
323
|
+
if data_frame_util.is_not_empty(stock_free_qfii_reduce):
|
|
324
|
+
qfii_type = 4
|
|
325
|
+
return qfii_type
|
|
326
|
+
else:
|
|
327
|
+
return 0
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def create_index():
|
|
331
|
+
mongodb_util.create_index('company_info',
|
|
332
|
+
[("classification", 1)])
|
|
333
|
+
mongodb_util.create_index('company_info',
|
|
334
|
+
[("industry", 1)])
|
|
335
|
+
mongodb_util.create_index('company_info',
|
|
336
|
+
[("flow_mv", 1)])
|
|
337
|
+
mongodb_util.create_index('company_info',
|
|
338
|
+
[("list_date", 1)])
|
|
339
|
+
mongodb_util.create_index('company_info',
|
|
340
|
+
[("symbol", 1)])
|
|
341
|
+
|
|
342
|
+
|
|
260
343
|
def set_kpl_data(kpl_real_time_quotes_one, company_info_type, company_one):
|
|
261
344
|
if data_frame_util.is_not_empty(kpl_real_time_quotes_one):
|
|
262
345
|
company_info_type['kpl_plate_name'] = list(kpl_real_time_quotes_one['plate_name_list'])[0]
|
|
@@ -444,5 +527,5 @@ if __name__ == '__main__':
|
|
|
444
527
|
# query = {"total_operate_income": 0}
|
|
445
528
|
# un_report_company_info = mongodb_util.find_query_data(db_name_constant.COMPANY_INFO, query)
|
|
446
529
|
# symbol_list = list(un_report_company_info['symbol'])
|
|
530
|
+
sync_company_base_info(['920009'])
|
|
447
531
|
sync_company_base_info(None)
|
|
448
|
-
# group_by_industry()
|
|
@@ -27,11 +27,8 @@ def sync_company_hold_info(symbol):
|
|
|
27
27
|
now_date = datetime.now()
|
|
28
28
|
sync_str_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
29
29
|
if data_frame_util.is_not_empty(company_hold_info_df):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if result.acknowledged:
|
|
33
|
-
company_hold_info_df['sync_str_date'] = sync_str_date
|
|
34
|
-
mongodb_util.insert_mongo(company_hold_info_df, db_name_constant.COMPANY_HOLDING_INFO)
|
|
30
|
+
company_hold_info_df['sync_str_date'] = sync_str_date
|
|
31
|
+
mongodb_util.insert_mongo(company_hold_info_df, db_name_constant.COMPANY_HOLDING_INFO)
|
|
35
32
|
except BaseException as e:
|
|
36
33
|
logger.error("同步公司控股子公司信息:{},{}", symbol, e)
|
|
37
34
|
|
|
@@ -49,11 +49,6 @@ def sync_company_product_area_industry(symbol, date):
|
|
|
49
49
|
try:
|
|
50
50
|
symbol = stock_one.symbol
|
|
51
51
|
|
|
52
|
-
if date is not None:
|
|
53
|
-
query_exist = {"symbol": symbol, "time": date}
|
|
54
|
-
if mongodb_util.exist_data_query(db_name_constant.COMPANY_BUSINESS_INFO, query_exist):
|
|
55
|
-
continue
|
|
56
|
-
|
|
57
52
|
classification = stock_one.classification
|
|
58
53
|
if classification in ['H', 'K']:
|
|
59
54
|
market = '17'
|
|
@@ -47,7 +47,7 @@ def clean_company_info(symbol):
|
|
|
47
47
|
company_info['company_type'] = company_info['business_nature']
|
|
48
48
|
|
|
49
49
|
# 将list_date列中的所有NaN值设置为99990909
|
|
50
|
-
company_info.fillna({'list_date':
|
|
50
|
+
company_info.fillna({'list_date': 19890604}, inplace=True)
|
|
51
51
|
|
|
52
52
|
# 将日期数值转换为日期时间格式
|
|
53
53
|
company_info['list_date_01'] = pd.to_datetime(company_info['list_date'], format='%Y%m%d')
|
|
@@ -6,66 +6,69 @@ end = file_path.index('mns') + 17
|
|
|
6
6
|
project_path = file_path[0:end]
|
|
7
7
|
sys.path.append(project_path)
|
|
8
8
|
|
|
9
|
-
import mns_common.component.proxies.proxy_common_api as proxy_common_api
|
|
10
9
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
11
10
|
from loguru import logger
|
|
12
|
-
import mns_common.api.em.real_time.east_money_stock_a_v2_api as east_money_stock_a_v2_api
|
|
13
11
|
import mns_common.api.em.real_time.east_money_debt_api as east_money_debt_api
|
|
14
12
|
import mns_common.api.em.real_time.east_money_etf_api as east_money_etf_api
|
|
15
|
-
import mns_common.api.em.real_time.
|
|
13
|
+
import mns_common.api.em.real_time.east_money_stock_a_v2_api as east_money_stock_a_v2_api
|
|
14
|
+
from datetime import datetime
|
|
16
15
|
import mns_common.constant.extra_income_db_name as extra_income_db_name
|
|
16
|
+
import mns_common.api.em.real_time.east_money_stock_hk_api as east_money_stock_hk_api
|
|
17
17
|
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
18
|
-
|
|
19
18
|
import mns_common.api.em.real_time.east_money_stock_us_api as east_money_stock_us_api
|
|
20
19
|
|
|
21
20
|
mongodb_util = MongodbUtil('27017')
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
def sync_all_em_stock_info():
|
|
24
|
+
now_date = datetime.now()
|
|
25
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
26
|
+
|
|
25
27
|
logger.info("同步东方财富a,etf,kzz,us,hk,信息开始")
|
|
26
|
-
|
|
27
|
-
proxies = {"https": proxy_ip}
|
|
28
|
+
|
|
28
29
|
try:
|
|
29
30
|
# 这里需要使用详情接口 获取全量数据
|
|
30
|
-
em_a_stock_info_df = east_money_stock_a_v2_api.
|
|
31
|
+
em_a_stock_info_df = east_money_stock_a_v2_api.get_stock_real_time_quotes(60)
|
|
32
|
+
em_a_stock_info_df['list_date'] = em_a_stock_info_df['list_date'].fillna(19890604)
|
|
31
33
|
em_a_stock_info_df['_id'] = em_a_stock_info_df['symbol']
|
|
34
|
+
em_a_stock_info_df['sync_time'] = str_now_date
|
|
32
35
|
mongodb_util.save_mongo(em_a_stock_info_df, extra_income_db_name.EM_A_STOCK_INFO)
|
|
33
36
|
except BaseException as e:
|
|
34
37
|
logger.error("同步东方财富A股信息异常:{}", e)
|
|
35
38
|
try:
|
|
36
|
-
em_etf_info = east_money_etf_api.get_etf_real_time_quotes(
|
|
37
|
-
em_etf_info['
|
|
39
|
+
em_etf_info = east_money_etf_api.get_etf_real_time_quotes(30, 6)
|
|
40
|
+
em_etf_info['sync_time'] = str_now_date
|
|
38
41
|
mongodb_util.save_mongo(em_etf_info, extra_income_db_name.EM_ETF_INFO)
|
|
39
42
|
except BaseException as e:
|
|
40
43
|
logger.error("同步东方财富ETF信息异常:{}", e)
|
|
41
44
|
|
|
42
45
|
try:
|
|
43
|
-
em_kzz_info = east_money_debt_api.
|
|
44
|
-
|
|
46
|
+
em_kzz_info = east_money_debt_api.get_kzz_real_time_quotes(30, 6)
|
|
45
47
|
em_kzz_info['_id'] = em_kzz_info['symbol']
|
|
48
|
+
em_kzz_info['sync_time'] = str_now_date
|
|
46
49
|
mongodb_util.save_mongo(em_kzz_info, extra_income_db_name.EM_KZZ_INFO)
|
|
47
50
|
except BaseException as e:
|
|
48
51
|
logger.error("同步东方财富可转债信息异常:{}", e)
|
|
49
52
|
|
|
50
|
-
em_cookie = cookie_info_service.get_em_cookie()
|
|
51
|
-
try:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
except BaseException as e:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
try:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
except BaseException as e:
|
|
68
|
-
|
|
53
|
+
# em_cookie = cookie_info_service.get_em_cookie()
|
|
54
|
+
# try:
|
|
55
|
+
# em_hk_stock_info = east_money_stock_hk_api.get_hk_real_time_quotes(em_cookie, proxies)
|
|
56
|
+
# em_hk_stock_info['_id'] = em_hk_stock_info['symbol']
|
|
57
|
+
# mongodb_util.save_mongo(em_hk_stock_info, extra_income_db_name.EM_HK_STOCK_INFO)
|
|
58
|
+
# except BaseException as e:
|
|
59
|
+
# logger.error("同步东方财富港股信息异常:{}", e)
|
|
60
|
+
#
|
|
61
|
+
# try:
|
|
62
|
+
# em_cookie = cookie_info_service.get_em_cookie()
|
|
63
|
+
# em_us_stock_info = east_money_stock_us_api.get_us_stock_real_time_quotes(em_cookie, proxies)
|
|
64
|
+
# em_us_stock_info['_id'] = em_us_stock_info['symbol']
|
|
65
|
+
# mongodb_util.save_mongo(em_us_stock_info, extra_income_db_name.EM_US_STOCK_INFO)
|
|
66
|
+
# em_us_etf_info = em_us_stock_info.loc[(em_us_stock_info['amount'] != 0) & (em_us_stock_info['total_mv'] == 0)]
|
|
67
|
+
# em_us_etf_info = em_us_etf_info.sort_values(by=['amount'], ascending=False)
|
|
68
|
+
# mongodb_util.save_mongo(em_us_etf_info, extra_income_db_name.EM_US_ETF_INFO)
|
|
69
|
+
#
|
|
70
|
+
# except BaseException as e:
|
|
71
|
+
# logger.error("同步东方财富美股信息异常:{}", e)
|
|
69
72
|
logger.info("同步东方财富a,etf,kzz,us,hk,信息完成")
|
|
70
73
|
|
|
71
74
|
|
|
@@ -16,6 +16,7 @@ import time
|
|
|
16
16
|
import mns_common.utils.data_frame_util as data_frame_util
|
|
17
17
|
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
18
18
|
from datetime import datetime
|
|
19
|
+
import mns_common.component.em.em_stock_info_api as em_stock_info_api
|
|
19
20
|
|
|
20
21
|
mongodb_util_27017 = MongodbUtil('27017')
|
|
21
22
|
|
|
@@ -25,9 +26,7 @@ mongodb_util_27017 = MongodbUtil('27017')
|
|
|
25
26
|
# balance 资产负债
|
|
26
27
|
# 同步所有股票 报表
|
|
27
28
|
def sync_all_stocks_report():
|
|
28
|
-
em_a_stock_info_df =
|
|
29
|
-
em_a_stock_info_df = em_a_stock_info_df[~em_a_stock_info_df['symbol'].astype(str).str.startswith(('8', '4'))]
|
|
30
|
-
|
|
29
|
+
em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
|
|
31
30
|
em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
|
|
32
31
|
# 或等效写法 df['A'].str[0:6]
|
|
33
32
|
|
|
@@ -124,7 +123,7 @@ def save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, save_tag,
|
|
|
124
123
|
|
|
125
124
|
if symbol in fail_list:
|
|
126
125
|
fail_list.remove(symbol)
|
|
127
|
-
logger.info("
|
|
126
|
+
logger.info("同步财务数据完成:{}:{}", symbol, name, report_name)
|
|
128
127
|
except BaseException as e:
|
|
129
128
|
logger.error("同步错误:{},异常信息:{}", symbol, e)
|
|
130
129
|
fail_list.append(symbol)
|
|
@@ -132,7 +131,7 @@ def save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, save_tag,
|
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
def sync_xue_qiu_very_period_report(report_name, symbol):
|
|
135
|
-
em_a_stock_info_df =
|
|
134
|
+
em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
|
|
136
135
|
if symbol is not None:
|
|
137
136
|
em_a_stock_info_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'] == symbol]
|
|
138
137
|
em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
|
|
@@ -130,7 +130,7 @@ def sync_symbols_interactive_questions(symbol_list):
|
|
|
130
130
|
real_time_quotes_all_stocks = common_service_fun_api.classify_symbol(real_time_quotes_all_stocks)
|
|
131
131
|
real_time_quotes_all_stocks = real_time_quotes_all_stocks.sort_values(by=['chg'], ascending=False)
|
|
132
132
|
fail_symbol_list = []
|
|
133
|
-
if symbol_list
|
|
133
|
+
if len(symbol_list) != 0:
|
|
134
134
|
real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
|
|
135
135
|
real_time_quotes_all_stocks['symbol'].isin(symbol_list)]
|
|
136
136
|
for stock_one in real_time_quotes_all_stocks.itertuples():
|
|
@@ -193,7 +193,8 @@ def save_new_data(stock_irm_cninfo_df):
|
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
if __name__ == '__main__':
|
|
196
|
+
sync_symbols_interactive_questions([])
|
|
196
197
|
get_stock_irm_cninfo_sh_api('688778')
|
|
197
198
|
fail_symbol_list_01 = ['000638', '002886', '688778', '688766', '688733', '688778', '688793', '688787']
|
|
198
199
|
# get_stock_irm_cninfo_sh_api('603633')
|
|
199
|
-
sync_symbols_interactive_questions(
|
|
200
|
+
# sync_symbols_interactive_questions(None)
|
|
@@ -113,8 +113,9 @@ def multi_threaded_k_line_sync(str_day):
|
|
|
113
113
|
real_time_quotes_now = real_time_quotes_now.loc[
|
|
114
114
|
~(real_time_quotes_now['symbol'].isin(de_list_company_df['symbol']))]
|
|
115
115
|
|
|
116
|
-
# 将list_date列中的所有NaN值设置为
|
|
117
|
-
real_time_quotes_now['list_date'].fillna(
|
|
116
|
+
# 将list_date列中的所有NaN值设置为19890604
|
|
117
|
+
real_time_quotes_now['list_date'].fillna(19890604, inplace=True)
|
|
118
|
+
real_time_quotes_now['list_date'] = real_time_quotes_now['list_date'].replace(99990909, 19890604)
|
|
118
119
|
|
|
119
120
|
# 将日期数值转换为日期时间格式
|
|
120
121
|
real_time_quotes_now['list_date_01'] = pd.to_datetime(real_time_quotes_now['list_date'], format='%Y%m%d')
|
|
@@ -198,3 +199,7 @@ def create_k_line_index():
|
|
|
198
199
|
mongodb_util.create_index('k_line_info', [("symbol", 1)])
|
|
199
200
|
mongodb_util.create_index('k_line_info', [("str_day", 1)])
|
|
200
201
|
mongodb_util.create_index('k_line_info', [("str_day", 1), ("symbol", 1)])
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == '__main__':
|
|
205
|
+
sync_k_line_info_task('2025-11-13')
|
|
@@ -49,7 +49,7 @@ def transactions_check_task():
|
|
|
49
49
|
now_day_number = float(now_day_str)
|
|
50
50
|
|
|
51
51
|
real_time_quotes_now = em_stock_info_api.get_a_stock_info()
|
|
52
|
-
real_time_quotes_now['list_date'] = real_time_quotes_now['list_date'].fillna(
|
|
52
|
+
real_time_quotes_now['list_date'] = real_time_quotes_now['list_date'].fillna(19890604)
|
|
53
53
|
real_time_quotes_now = real_time_quotes_now.loc[real_time_quotes_now['list_date'] <= now_day_number]
|
|
54
54
|
real_time_quotes_now = common_service_fun_api.classify_symbol(real_time_quotes_now)
|
|
55
55
|
real_time_quotes_now = common_service_fun_api.exclude_ts_symbol(real_time_quotes_now)
|
|
@@ -40,9 +40,6 @@ mongodb_util = MongodbUtil('27017')
|
|
|
40
40
|
fixed_optional_list = ['899050', '881157']
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
43
|
def add_fixed_optional():
|
|
47
44
|
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
48
45
|
for symbol in fixed_optional_list:
|
|
@@ -50,15 +47,16 @@ def add_fixed_optional():
|
|
|
50
47
|
|
|
51
48
|
|
|
52
49
|
def delete_all_self_choose_stocks():
|
|
53
|
-
ths_cookie =
|
|
50
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
54
51
|
all_self_choose_stock_list = ths_self_choose_api.get_all_self_choose_stock_list(ths_cookie)
|
|
55
52
|
for stock_one in all_self_choose_stock_list.itertuples():
|
|
56
53
|
symbol = stock_one.code
|
|
57
54
|
ths_self_choose_api.del_stock_from_account(symbol, ths_cookie)
|
|
58
55
|
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
# 添加固定自选股票
|
|
58
|
+
def add_self_choose_symbol():
|
|
59
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
62
60
|
# 固定自选
|
|
63
61
|
self_choose_symbol_df = mongodb_util.find_all_data(db_name_constant.SELF_CHOOSE_STOCK)
|
|
64
62
|
if data_frame_util.is_not_empty(self_choose_symbol_df):
|
|
@@ -66,6 +64,10 @@ def add_self_choose_local():
|
|
|
66
64
|
for stock_one in self_choose_symbol_df.itertuples():
|
|
67
65
|
ths_self_choose_api.add_stock_to_account(stock_one.symbol, ths_cookie)
|
|
68
66
|
|
|
67
|
+
|
|
68
|
+
# 添加今日选择股票
|
|
69
|
+
def add_today_choose_symbol():
|
|
70
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
69
71
|
now_date = datetime.now()
|
|
70
72
|
str_day = now_date.strftime('%Y-%m-%d')
|
|
71
73
|
last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
@@ -77,6 +79,10 @@ def add_self_choose_local():
|
|
|
77
79
|
for stock_one in self_choose_symbol_today_df.itertuples():
|
|
78
80
|
ths_self_choose_api.add_stock_to_account(stock_one.symbol, ths_cookie)
|
|
79
81
|
|
|
82
|
+
|
|
83
|
+
# 添加同花顺概念
|
|
84
|
+
def add_self_choose_concept():
|
|
85
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
80
86
|
query_plate = {'self_type': {
|
|
81
87
|
"$in": [self_choose_constant.SELF_CHOOSE_THS_CONCEPT,
|
|
82
88
|
self_choose_constant.SELF_CHOOSE_THS_INDUSTRY]}}
|
|
@@ -103,7 +109,7 @@ def add_trade_stocks():
|
|
|
103
109
|
trade_stocks_df = mongodb_util.find_query_data(db_name_constant.BUY_STOCK_NAME, query)
|
|
104
110
|
if data_frame_util.is_not_empty(trade_stocks_df):
|
|
105
111
|
stock_list = stock_list.union(set(trade_stocks_df['symbol']))
|
|
106
|
-
ths_cookie =
|
|
112
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
107
113
|
if len(stock_list) > 0:
|
|
108
114
|
for symbol in stock_list:
|
|
109
115
|
ths_self_choose_api.add_stock_to_account(symbol, ths_cookie)
|
|
@@ -111,7 +117,7 @@ def add_trade_stocks():
|
|
|
111
117
|
|
|
112
118
|
# 添加连板到自选
|
|
113
119
|
def add_continue_boards_zt_stocks():
|
|
114
|
-
ths_cookie =
|
|
120
|
+
ths_cookie = cookie_info_service.get_ths_cookie()
|
|
115
121
|
now_date = datetime.now()
|
|
116
122
|
str_day = now_date.strftime('%Y-%m-%d')
|
|
117
123
|
if trade_date_common_service_api.is_trade_day(str_day):
|
|
@@ -135,14 +141,16 @@ def add_continue_boards_zt_stocks():
|
|
|
135
141
|
# 自选股操作 删除当天自选股 增加新的连板股票 添加固定选择自选
|
|
136
142
|
def self_choose_stock_handle():
|
|
137
143
|
delete_all_self_choose_stocks()
|
|
138
|
-
#
|
|
144
|
+
# 固定自选板块
|
|
139
145
|
add_fixed_optional()
|
|
140
|
-
#
|
|
141
|
-
|
|
142
|
-
# 本地自选
|
|
143
|
-
add_self_choose_local()
|
|
146
|
+
# 添加同花顺概念
|
|
147
|
+
add_self_choose_concept()
|
|
144
148
|
# 连板股票
|
|
145
149
|
add_continue_boards_zt_stocks()
|
|
150
|
+
# 自己买入的股票
|
|
151
|
+
add_trade_stocks()
|
|
152
|
+
# 添加自选股票
|
|
153
|
+
add_self_choose_symbol()
|
|
146
154
|
|
|
147
155
|
|
|
148
156
|
if __name__ == '__main__':
|
|
@@ -9,16 +9,16 @@ import mns_common.component.deal.deal_service_api as deal_service_api
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import mns_common.utils.data_frame_util as data_frame_util
|
|
11
11
|
import mns_common.constant.db_name_constant as db_name_constant
|
|
12
|
-
import datetime
|
|
13
|
-
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from mns_common.component.deal.terminal_enum import TerminalEnum
|
|
14
14
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
15
15
|
|
|
16
16
|
mongodb_util = MongodbUtil('27017')
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
# 同步持仓
|
|
20
|
-
def
|
|
21
|
-
now_date = datetime.
|
|
20
|
+
def sync_position_ths():
|
|
21
|
+
now_date = datetime.now()
|
|
22
22
|
str_day = now_date.strftime('%Y-%m-%d')
|
|
23
23
|
query_exist = {'str_day': str_day}
|
|
24
24
|
if mongodb_util.exist_data_query(db_name_constant.POSITION_STOCK, query_exist):
|
|
@@ -52,5 +52,38 @@ def sync_position():
|
|
|
52
52
|
mongodb_util.save_mongo(position_df, db_name_constant.POSITION_STOCK)
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
def sync_position_qmt():
|
|
56
|
+
now_date = datetime.now()
|
|
57
|
+
str_day = now_date.strftime('%Y-%m-%d')
|
|
58
|
+
query_exist = {'str_day': str_day}
|
|
59
|
+
# if mongodb_util.exist_data_query(db_name_constant.POSITION_STOCK, query_exist):
|
|
60
|
+
# return None
|
|
61
|
+
position_list = deal_service_api.get_position(TerminalEnum.QMT.terminal_code)
|
|
62
|
+
if len(position_list) == 0:
|
|
63
|
+
return None
|
|
64
|
+
position_df = pd.DataFrame(position_list)
|
|
65
|
+
position_df = position_df.rename(columns={
|
|
66
|
+
"stock_code": "symbol",
|
|
67
|
+
"avg_price": "cost_price",
|
|
68
|
+
"profit_loss": "floating_profit_loss",
|
|
69
|
+
"market_value": "flow_mv",
|
|
70
|
+
"can_use_volume": "available_position",
|
|
71
|
+
"frozen_volume": "frozen_position",
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
position_df['cost_price'] = round(position_df['cost_price'], 2)
|
|
75
|
+
position_df['open_price'] = round(position_df['open_price'], 2)
|
|
76
|
+
|
|
77
|
+
position_df['open_position'] = position_df['available_position'] + position_df['frozen_position'] + position_df[
|
|
78
|
+
'on_road_volume']
|
|
79
|
+
|
|
80
|
+
position_df['symbol'] = position_df['symbol'].str.slice(0, 6)
|
|
81
|
+
|
|
82
|
+
position_df["_id"] = position_df['symbol'] + '-' + str_day
|
|
83
|
+
position_df["str_day"] = str_day
|
|
84
|
+
position_df["valid"] = True
|
|
85
|
+
mongodb_util.save_mongo(position_df, db_name_constant.POSITION_STOCK)
|
|
86
|
+
|
|
87
|
+
|
|
55
88
|
if __name__ == '__main__':
|
|
56
|
-
|
|
89
|
+
sync_position_qmt()
|