mns-scheduler 1.3.5.0__py3-none-any.whl → 1.4.3.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-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 +161 -0
- 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/{debt → finance/em}/__init__.py +1 -1
- mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +1 -1
- mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +5 -3
- mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py} +75 -22
- mns_scheduler/finance/xue_qiu/__init__.py +7 -0
- mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
- mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
- 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/k_line/sync_status/__init__.py +7 -0
- mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
- mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +7 -1
- mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +1 -1
- 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/zt/zt_pool/em_zt_pool_sync_api.py +36 -17
- 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 +27 -7
- {mns_scheduler-1.3.5.0.dist-info → mns_scheduler-1.4.3.0.dist-info}/METADATA +1 -1
- {mns_scheduler-1.3.5.0.dist-info → mns_scheduler-1.4.3.0.dist-info}/RECORD +31 -26
- mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
- /mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +0 -0
- {mns_scheduler-1.3.5.0.dist-info → mns_scheduler-1.4.3.0.dist-info}/WHEEL +0 -0
- {mns_scheduler-1.3.5.0.dist-info → mns_scheduler-1.4.3.0.dist-info}/top_level.txt +0 -0
mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py}
RENAMED
|
@@ -8,15 +8,16 @@ sys.path.append(project_path)
|
|
|
8
8
|
from datetime import datetime
|
|
9
9
|
|
|
10
10
|
import mns_common.constant.db_name_constant as db_name_constant
|
|
11
|
-
import mns_scheduler.finance.em_financial_profit_sync_service_api as em_financial_profit_sync_service_api
|
|
11
|
+
import mns_scheduler.finance.em.em_financial_profit_sync_service_api as em_financial_profit_sync_service_api
|
|
12
12
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
13
13
|
from loguru import logger
|
|
14
14
|
import \
|
|
15
|
-
mns_scheduler.finance.em_financial_asset_liability_sync_service_api as em_financial_asset_liability_sync_service_api
|
|
15
|
+
mns_scheduler.finance.em.em_financial_asset_liability_sync_service_api as em_financial_asset_liability_sync_service_api
|
|
16
16
|
import mns_scheduler.risk.financial_report_risk_check_api as financial_report_risk_check_api
|
|
17
17
|
import mns_common.utils.data_frame_util as data_frame_util
|
|
18
|
-
import mns_scheduler.finance.finance_common_api as finance_common_api
|
|
18
|
+
import mns_scheduler.finance.em.finance_common_api as finance_common_api
|
|
19
19
|
import mns_scheduler.risk.compliance.undisclosed_annual_report_api as undisclosed_annual_report_api
|
|
20
|
+
import mns_scheduler.finance.xue_qiu.sync_xue_qiu_fiance_data as sync_xue_qiu_fiance_data
|
|
20
21
|
|
|
21
22
|
mongodb_util = MongodbUtil('27017')
|
|
22
23
|
|
|
@@ -26,39 +27,90 @@ mongodb_util = MongodbUtil('27017')
|
|
|
26
27
|
# 3、上市公司季报披露时间:
|
|
27
28
|
# 1季报:每年4月1日-- -4月30日。
|
|
28
29
|
# 2季报(中报) :每年7月1日--8月30日。
|
|
29
|
-
# 3季报:每年10月1日--10月31日
|
|
30
|
+
# 3季报:每年10月1日--10月31日
|
|
31
|
+
# 4季报(年报) :每年1月1日--4月30日
|
|
30
32
|
|
|
31
33
|
def sync_financial_report():
|
|
32
34
|
now_date = datetime.now()
|
|
33
35
|
now_year = now_date.year
|
|
34
36
|
now_month = now_date.month
|
|
35
37
|
sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
36
|
-
|
|
37
|
-
if 1
|
|
38
|
+
|
|
39
|
+
if now_month in [1, 2, 3, 4]:
|
|
40
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year - 1) + '年报', None)
|
|
41
|
+
|
|
42
|
+
# 年报
|
|
38
43
|
period = 4
|
|
39
44
|
period_time = str(now_year - 1) + "-12-31 00:00:00"
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
sync_em_profit_report(period_time, sync_time, period)
|
|
46
|
+
sync_em_asset_liability_report(period_time, sync_time, period)
|
|
47
|
+
|
|
48
|
+
# 一季报
|
|
49
|
+
if now_month == 4:
|
|
50
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '一季报', None)
|
|
51
|
+
|
|
52
|
+
period = 1
|
|
53
|
+
period_time = str(now_year) + "-03-31 00:00:00"
|
|
54
|
+
sync_em_profit_report(period_time, sync_time, period)
|
|
55
|
+
sync_em_asset_liability_report(period_time, sync_time, period)
|
|
56
|
+
|
|
42
57
|
|
|
43
|
-
# 一季报
|
|
44
|
-
elif now_month == 5:
|
|
45
|
-
period = 1
|
|
46
|
-
period_time = str(now_year) + "-03-31 00:00:00"
|
|
47
|
-
sync_profit_report(period_time, sync_time, period)
|
|
48
|
-
sync_asset_liability_report(period_time, sync_time, period)
|
|
49
58
|
|
|
50
59
|
# 二季报
|
|
51
|
-
elif
|
|
60
|
+
elif now_month in [7, 8]:
|
|
61
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '中报', None)
|
|
62
|
+
|
|
52
63
|
period = 2
|
|
53
64
|
period_time = str(now_year) + "-06-30 00:00:00"
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
sync_em_profit_report(period_time, sync_time, period)
|
|
66
|
+
sync_em_asset_liability_report(period_time, sync_time, period)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
56
70
|
# 三季报
|
|
57
71
|
elif now_month == 10:
|
|
72
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '三季报', None)
|
|
73
|
+
|
|
58
74
|
period = 3
|
|
59
75
|
period_time = str(now_year) + "-09-30 00:00:00"
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
sync_em_profit_report(period_time, sync_time, period)
|
|
77
|
+
sync_em_asset_liability_report(period_time, sync_time, period)
|
|
78
|
+
|
|
79
|
+
elif now_month == 5:
|
|
80
|
+
|
|
81
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year - 1) + '年报', None)
|
|
82
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '一季报', None)
|
|
83
|
+
|
|
84
|
+
# 补偿年报和一季度,出不了报告的
|
|
85
|
+
miss_period_04 = 4
|
|
86
|
+
miss_period_time_04 = str(now_year - 1) + "-12-31 00:00:00"
|
|
87
|
+
|
|
88
|
+
sync_em_profit_report(miss_period_time_04, sync_time, miss_period_04)
|
|
89
|
+
sync_em_asset_liability_report(miss_period_time_04, sync_time, miss_period_04)
|
|
90
|
+
|
|
91
|
+
period_01 = 1
|
|
92
|
+
period_time_01 = str(now_year) + "-03-31 00:00:00"
|
|
93
|
+
sync_em_profit_report(period_time_01, sync_time, period_01)
|
|
94
|
+
sync_em_asset_liability_report(period_time_01, sync_time, period_01)
|
|
95
|
+
|
|
96
|
+
elif now_month == 9:
|
|
97
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '中报', None)
|
|
98
|
+
|
|
99
|
+
# 补偿二季度
|
|
100
|
+
period_02 = 2
|
|
101
|
+
period_time_02 = str(now_year) + "-06-30 00:00:00"
|
|
102
|
+
sync_em_profit_report(period_time_02, sync_time, period_02)
|
|
103
|
+
sync_em_asset_liability_report(period_time_02, sync_time, period_02)
|
|
104
|
+
|
|
105
|
+
elif now_month in [11, 12]:
|
|
106
|
+
sync_xue_qiu_fiance_data.sync_xue_qiu_very_period_report(str(now_year) + '三季报', None)
|
|
107
|
+
|
|
108
|
+
# 补偿三季度
|
|
109
|
+
period_03 = 3
|
|
110
|
+
period_time_03 = str(now_year) + "-09-30 00:00:00"
|
|
111
|
+
sync_em_profit_report(period_time_03, sync_time, period_03)
|
|
112
|
+
sync_em_asset_liability_report(period_time_03, sync_time, period_03)
|
|
113
|
+
|
|
62
114
|
# 未出报告check
|
|
63
115
|
undisclosed_annual_report_api.un_disclosed_report_check(sync_time, now_year, period, period_time)
|
|
64
116
|
# 新股或者未出报告的
|
|
@@ -66,7 +118,7 @@ def sync_financial_report():
|
|
|
66
118
|
|
|
67
119
|
|
|
68
120
|
# 同步资产表
|
|
69
|
-
def
|
|
121
|
+
def sync_em_asset_liability_report(period_time, sync_time, period):
|
|
70
122
|
un_report_asset_df = finance_common_api.find_un_report_symbol(period_time,
|
|
71
123
|
db_name_constant.EM_STOCK_ASSET_LIABILITY)
|
|
72
124
|
for un_report_asset_one in un_report_asset_df.itertuples():
|
|
@@ -91,8 +143,8 @@ def sync_asset_liability_report(period_time, sync_time, period):
|
|
|
91
143
|
logger.error("同步资产表异常:{},{},{}", symbol, period_time, e)
|
|
92
144
|
|
|
93
145
|
|
|
94
|
-
#
|
|
95
|
-
def
|
|
146
|
+
# 同步em利润表
|
|
147
|
+
def sync_em_profit_report(period_time, sync_time, period):
|
|
96
148
|
un_report_profit_df = finance_common_api.find_un_report_symbol(period_time, db_name_constant.EM_STOCK_PROFIT)
|
|
97
149
|
for un_report_profit_one in un_report_profit_df.itertuples():
|
|
98
150
|
try:
|
|
@@ -146,4 +198,5 @@ if __name__ == '__main__':
|
|
|
146
198
|
now_year_test = now_date_test.year
|
|
147
199
|
now_month_test = now_date_test.month
|
|
148
200
|
sync_time_test = now_date_test.strftime('%Y-%m-%d %H:%M:%S')
|
|
201
|
+
sync_miss_report(sync_time_test)
|
|
149
202
|
sync_financial_report()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 16
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
import requests
|
|
9
|
+
import pandas as pd
|
|
10
|
+
from loguru import logger
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# report_type income 利润表
|
|
14
|
+
# cash_flow 现金流量
|
|
15
|
+
# balance 资产负债
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_xue_qiu_report(symbol, report_type, cookie, count, period_type):
|
|
19
|
+
# 请求 URL
|
|
20
|
+
url = (f"https://stock.xueqiu.com/v5/stock/finance/cn/{report_type}.json?symbol={symbol}&type={period_type}"
|
|
21
|
+
f"&is_detail=true&count={count}")
|
|
22
|
+
|
|
23
|
+
# 请求头(关键是 cookies)
|
|
24
|
+
headers = {
|
|
25
|
+
"accept": "application/json, text/plain, */*",
|
|
26
|
+
"accept-language": "zh-CN,zh;q=0.9",
|
|
27
|
+
"origin": "https://xueqiu.com",
|
|
28
|
+
"referer": f"https://xueqiu.com/snowman/S/{symbol}/detail",
|
|
29
|
+
"sec-fetch-mode": "cors",
|
|
30
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
31
|
+
# ⚠ 替换为你浏览器访问雪球后的 Cookie(需含 xq_a_token)
|
|
32
|
+
"cookie": cookie,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# 发送请求
|
|
36
|
+
response = requests.get(url, headers=headers)
|
|
37
|
+
|
|
38
|
+
# 检查结果
|
|
39
|
+
if response.status_code == 200:
|
|
40
|
+
data = response.json()
|
|
41
|
+
|
|
42
|
+
# 提取财报数据列表
|
|
43
|
+
raw_list = data['data']['list']
|
|
44
|
+
processed_list = []
|
|
45
|
+
|
|
46
|
+
for entry in raw_list:
|
|
47
|
+
flat_entry = {}
|
|
48
|
+
for key, value in entry.items():
|
|
49
|
+
if isinstance(value, list) and len(value) == 2:
|
|
50
|
+
# 处理列表字段:提取两个值,空则填 0
|
|
51
|
+
v0 = value[0] if value[0] is not None else 0
|
|
52
|
+
v1 = value[1] if value[1] is not None else 0
|
|
53
|
+
flat_entry[key] = v0
|
|
54
|
+
flat_entry[key + "_chg"] = round(v1 * 100, 2)
|
|
55
|
+
elif value is None:
|
|
56
|
+
# 整个字段为空,设置为 0 和 0(变化量)
|
|
57
|
+
flat_entry[key] = 0
|
|
58
|
+
else:
|
|
59
|
+
flat_entry[key] = value
|
|
60
|
+
processed_list.append(flat_entry)
|
|
61
|
+
|
|
62
|
+
# 转换为 DataFrame
|
|
63
|
+
df = pd.DataFrame(processed_list)
|
|
64
|
+
return df
|
|
65
|
+
|
|
66
|
+
else:
|
|
67
|
+
logger.error("请求失败,状态码:{}", response.status_code)
|
|
68
|
+
return pd.DataFrame()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
72
|
+
|
|
73
|
+
if __name__ == '__main__':
|
|
74
|
+
cash_flow_df = get_xue_qiu_report('SZ301662', 'cash_flow', cookie_info_service.get_xue_qiu_cookie(), 1, 'all')
|
|
75
|
+
income_df = get_xue_qiu_report('SZ301662', 'income', cookie_info_service.get_xue_qiu_cookie(), 1, 'all')
|
|
76
|
+
balance_df = get_xue_qiu_report('SZ301662', 'balance', cookie_info_service.get_xue_qiu_cookie(), 1, 'all')
|
|
77
|
+
pass
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 16
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
|
|
9
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
10
|
+
import mns_common.constant.extra_income_db_name as extra_income_db_name
|
|
11
|
+
import mns_scheduler.finance.xue_qiu.down_load_xueqiu_report_api as down_load_xueqiu_report_api
|
|
12
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
13
|
+
import pandas as pd
|
|
14
|
+
from loguru import logger
|
|
15
|
+
import time
|
|
16
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
17
|
+
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
18
|
+
from datetime import datetime
|
|
19
|
+
import mns_common.component.em.em_stock_info_api as em_stock_info_api
|
|
20
|
+
|
|
21
|
+
mongodb_util_27017 = MongodbUtil('27017')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# report_type income 利润表
|
|
25
|
+
# cash_flow 现金流量
|
|
26
|
+
# balance 资产负债
|
|
27
|
+
# 同步所有股票 报表
|
|
28
|
+
def sync_all_stocks_report():
|
|
29
|
+
em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
|
|
30
|
+
em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
|
|
31
|
+
# 或等效写法 df['A'].str[0:6]
|
|
32
|
+
|
|
33
|
+
fail_list = []
|
|
34
|
+
|
|
35
|
+
xue_qiu_cookie = cookie_info_service.get_xue_qiu_cookie()
|
|
36
|
+
report_type_list = ['income', 'balance', 'cash_flow']
|
|
37
|
+
for stock_one in em_a_stock_info_df.itertuples():
|
|
38
|
+
fail_list = save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, True, fail_list, '', False)
|
|
39
|
+
|
|
40
|
+
handle_number = 0
|
|
41
|
+
# 处理失败的
|
|
42
|
+
while len(fail_list) > 0:
|
|
43
|
+
fail_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'].isin(fail_list)]
|
|
44
|
+
for fail_one in fail_df.itertuples():
|
|
45
|
+
fail_list = save_one_symbol_data(fail_one, report_type_list, xue_qiu_cookie, True, fail_list, '', False)
|
|
46
|
+
handle_number = handle_number + 1
|
|
47
|
+
if handle_number > 10:
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, save_tag, fail_list, report_name, check_exist):
|
|
52
|
+
try:
|
|
53
|
+
symbol_prefix = stock_one.symbol_prefix
|
|
54
|
+
name = stock_one.name
|
|
55
|
+
symbol = stock_one.symbol
|
|
56
|
+
for report_type in report_type_list:
|
|
57
|
+
if report_type == 'income':
|
|
58
|
+
col_name = extra_income_db_name.XUE_QIU_LRB_INCOME
|
|
59
|
+
elif report_type == 'balance':
|
|
60
|
+
col_name = extra_income_db_name.XUE_QIU_ASSET_DEBT
|
|
61
|
+
elif report_type == 'cash_flow':
|
|
62
|
+
col_name = extra_income_db_name.XUE_QIU_CASH_FLOW
|
|
63
|
+
if check_exist:
|
|
64
|
+
query_exist = {'symbol': symbol, 'report_name': report_name}
|
|
65
|
+
# 存在数据 不在同步
|
|
66
|
+
if mongodb_util_27017.exist_data_query(col_name, query_exist):
|
|
67
|
+
continue
|
|
68
|
+
|
|
69
|
+
index_create = [('symbol', 1), ('report_date', 1)]
|
|
70
|
+
mongodb_util_27017.create_index(col_name, index_create)
|
|
71
|
+
|
|
72
|
+
index_create_01 = [('symbol', 1), ('sync_time', 1)]
|
|
73
|
+
mongodb_util_27017.create_index(col_name, index_create_01)
|
|
74
|
+
|
|
75
|
+
if check_exist:
|
|
76
|
+
# 季度同步只同步一条数据
|
|
77
|
+
result_df = down_load_xueqiu_report_api.get_xue_qiu_report(symbol_prefix, report_type, xue_qiu_cookie,
|
|
78
|
+
1,
|
|
79
|
+
'all')
|
|
80
|
+
else:
|
|
81
|
+
result_df = down_load_xueqiu_report_api.get_xue_qiu_report(symbol_prefix, report_type, xue_qiu_cookie,
|
|
82
|
+
200,
|
|
83
|
+
'all')
|
|
84
|
+
|
|
85
|
+
now_date = datetime.now()
|
|
86
|
+
sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
87
|
+
|
|
88
|
+
if data_frame_util.is_empty(result_df):
|
|
89
|
+
logger.error("财务信息为空,代码:{}:{}", symbol, name)
|
|
90
|
+
continue
|
|
91
|
+
else:
|
|
92
|
+
# 季度同步check
|
|
93
|
+
if check_exist:
|
|
94
|
+
result_df = result_df.loc[result_df['report_name'] == report_name]
|
|
95
|
+
if data_frame_util.is_empty(result_df):
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
result_df['sync_time'] = sync_time
|
|
99
|
+
time.sleep(0.5)
|
|
100
|
+
# 1. 将毫秒时间戳转为 datetime
|
|
101
|
+
result_df['report_date'] = pd.to_datetime(result_df['report_date'], unit='ms')
|
|
102
|
+
|
|
103
|
+
# 2. 格式化为 '%Y-%m-%d' 字符串
|
|
104
|
+
result_df['report_date'] = result_df['report_date'].dt.strftime('%Y-%m-%d')
|
|
105
|
+
|
|
106
|
+
result_df['_id'] = symbol + '_' + result_df['report_date']
|
|
107
|
+
result_df['symbol'] = symbol
|
|
108
|
+
|
|
109
|
+
# 1. 将毫秒时间戳转为 datetime
|
|
110
|
+
result_df['ctime'] = pd.to_datetime(result_df['ctime'], unit='ms')
|
|
111
|
+
|
|
112
|
+
# 2. 格式化为 '%Y-%m-%d' 字符串
|
|
113
|
+
result_df['ctime'] = result_df['ctime'].dt.strftime('%Y-%m-%d')
|
|
114
|
+
result_df.loc[result_df['report_name'].str.contains('年报'), 'period'] = 4
|
|
115
|
+
result_df.loc[result_df['report_name'].str.contains('一季报'), 'period'] = 1
|
|
116
|
+
result_df.loc[result_df['report_name'].str.contains('中报'), 'period'] = 2
|
|
117
|
+
result_df.loc[result_df['report_name'].str.contains('三季报'), 'period'] = 3
|
|
118
|
+
result_df['year'] = result_df['report_name'].str[:4]
|
|
119
|
+
if save_tag:
|
|
120
|
+
mongodb_util_27017.save_mongo(result_df, col_name)
|
|
121
|
+
else:
|
|
122
|
+
mongodb_util_27017.insert_mongo(result_df, col_name)
|
|
123
|
+
|
|
124
|
+
if symbol in fail_list:
|
|
125
|
+
fail_list.remove(symbol)
|
|
126
|
+
logger.info("同步财务数据完成:{}:{}", symbol, name, report_name)
|
|
127
|
+
except BaseException as e:
|
|
128
|
+
logger.error("同步错误:{},异常信息:{}", symbol, e)
|
|
129
|
+
fail_list.append(symbol)
|
|
130
|
+
return fail_list
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def sync_xue_qiu_very_period_report(report_name, symbol):
|
|
134
|
+
em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
|
|
135
|
+
if symbol is not None:
|
|
136
|
+
em_a_stock_info_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'] == symbol]
|
|
137
|
+
em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
|
|
138
|
+
# 或等效写法 df['A'].str[0:6]
|
|
139
|
+
|
|
140
|
+
fail_list = []
|
|
141
|
+
|
|
142
|
+
xue_qiu_cookie = cookie_info_service.get_xue_qiu_cookie()
|
|
143
|
+
report_type_list = ['income', 'balance', 'cash_flow']
|
|
144
|
+
for stock_one in em_a_stock_info_df.itertuples():
|
|
145
|
+
fail_list = save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, False, fail_list, report_name,
|
|
146
|
+
True)
|
|
147
|
+
|
|
148
|
+
handle_number = 0
|
|
149
|
+
# 处理失败的
|
|
150
|
+
while len(fail_list) > 0:
|
|
151
|
+
fail_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'].isin(fail_list)]
|
|
152
|
+
for fail_one in fail_df.itertuples():
|
|
153
|
+
fail_list = save_one_symbol_data(fail_one, report_type_list, xue_qiu_cookie, False, fail_list, report_name,
|
|
154
|
+
True)
|
|
155
|
+
handle_number = handle_number + 1
|
|
156
|
+
if handle_number > 10:
|
|
157
|
+
break
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == '__main__':
|
|
161
|
+
sync_all_stocks_report()
|
|
@@ -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')
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 16
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
|
|
10
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
11
|
+
import mns_common.constant.db_name_constant as db_name_constant
|
|
12
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
13
|
+
import mns_common.api.msg.push_msg_api as push_msg_api
|
|
14
|
+
|
|
15
|
+
mongodb_util = MongodbUtil('27017')
|
|
16
|
+
|
|
17
|
+
min_k_line_count = 5200
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# check下一个交易日k线同步状态
|
|
21
|
+
def check_k_line_sync_count():
|
|
22
|
+
now_date = datetime.now()
|
|
23
|
+
str_day = now_date.strftime('%Y-%m-%d')
|
|
24
|
+
hour = now_date.hour
|
|
25
|
+
# 是否是交易日
|
|
26
|
+
if trade_date_common_service_api.is_trade_day(str_day):
|
|
27
|
+
if hour > 15:
|
|
28
|
+
qfq_day = str_day
|
|
29
|
+
k_line_day = trade_date_common_service_api.get_further_trade_date(str_day, 2)
|
|
30
|
+
else:
|
|
31
|
+
qfq_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
32
|
+
k_line_day = str_day
|
|
33
|
+
else:
|
|
34
|
+
qfq_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
35
|
+
k_line_day = trade_date_common_service_api.get_further_trade_date(str_day, 1)
|
|
36
|
+
|
|
37
|
+
# check 当日k线同步状态
|
|
38
|
+
query_qfq = {'date': date_handle_util.no_slash_date(qfq_day)}
|
|
39
|
+
qfq_k_line_count = mongodb_util.count(query_qfq, db_name_constant.STOCK_QFQ_DAILY)
|
|
40
|
+
if qfq_k_line_count < min_k_line_count:
|
|
41
|
+
title = '当日k线同步数量不对'
|
|
42
|
+
msg = '当日k线同步数量不对,当前k线数量:' + str(qfq_k_line_count)
|
|
43
|
+
push_msg_api.push_msg_to_wechat(title, msg)
|
|
44
|
+
|
|
45
|
+
query_last_trade = {'str_day': k_line_day}
|
|
46
|
+
last_trade_day_k_line_count = mongodb_util.count(query_last_trade, 'k_line_info')
|
|
47
|
+
if last_trade_day_k_line_count < min_k_line_count:
|
|
48
|
+
title = '下一个交易日策略k线数量不对'
|
|
49
|
+
msg = '下一个交易日策略k线数量不对,当前数量:' + str(last_trade_day_k_line_count)
|
|
50
|
+
push_msg_api.push_msg_to_wechat(title, msg)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == '__main__':
|
|
54
|
+
check_k_line_sync_count()
|
|
@@ -51,6 +51,9 @@ def update_symbol_new_concept_reason(plate_code, kpl_symbol_list):
|
|
|
51
51
|
symbol_str = ','.join(kpl_symbol_list)
|
|
52
52
|
choose_reason_df = kpl_common_api.get_kpl_concept_choose_reason(plate_code, symbol_str)
|
|
53
53
|
if data_frame_util.is_not_empty(choose_reason_df):
|
|
54
|
+
choose_reason_df = choose_reason_df[choose_reason_df['choose_reason'] != '']
|
|
55
|
+
if data_frame_util.is_empty(choose_reason_df):
|
|
56
|
+
return
|
|
54
57
|
for choose_reason_one in choose_reason_df.itertuples():
|
|
55
58
|
symbol = choose_reason_one.symbol
|
|
56
59
|
try:
|
|
@@ -60,6 +63,9 @@ def update_symbol_new_concept_reason(plate_code, kpl_symbol_list):
|
|
|
60
63
|
new_values = {"$set": {"long": choose_reason}}
|
|
61
64
|
mongodb_util.update_many(update_query, new_values,
|
|
62
65
|
db_name_constant.KPL_BEST_CHOOSE_INDEX_DETAIL)
|
|
66
|
+
# 更新今日新增概念列表 入选原因
|
|
67
|
+
mongodb_util.update_many(update_query, new_values,
|
|
68
|
+
db_name_constant.TODAY_NEW_CONCEPT_LIST)
|
|
63
69
|
except BaseException as e:
|
|
64
70
|
logger.error("更新开票啦入选原因异常:{},{},{}", symbol, plate_code, e)
|
|
65
71
|
|
|
@@ -69,7 +75,7 @@ def update_null_choose_reason():
|
|
|
69
75
|
now = datetime.now()
|
|
70
76
|
|
|
71
77
|
# 计算前15天的日期时间
|
|
72
|
-
days_ago_15 = now - timedelta(days=
|
|
78
|
+
days_ago_15 = now - timedelta(days=30)
|
|
73
79
|
|
|
74
80
|
# 按指定格式输出
|
|
75
81
|
formatted_date = days_ago_15.strftime("%Y-%m-%d %H:%M:%S")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
import mns_common.component.self_choose.black_list_service_api as black_list_service_api
|
|
3
|
-
import mns_scheduler.finance.finance_common_api as finance_common_api
|
|
3
|
+
import mns_scheduler.finance.em.finance_common_api as finance_common_api
|
|
4
4
|
from loguru import logger
|
|
5
5
|
import mns_common.constant.db_name_constant as db_name_constant
|
|
6
6
|
import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
|
|
@@ -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__':
|