mns-scheduler 1.1.8.4__py3-none-any.whl → 1.4.3.2__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.
- mns_scheduler/__init__.py +1 -3
- mns_scheduler/company_info/announce/company_announce_sync_service.py +65 -0
- mns_scheduler/company_info/base/__init__.py +1 -1
- mns_scheduler/company_info/base/sync_company_base_info_api.py +171 -79
- mns_scheduler/company_info/base/sync_company_hold_info_api.py +3 -6
- mns_scheduler/company_info/base/sync_company_product_area_industry.py +161 -0
- mns_scheduler/company_info/clean/__init__.py +1 -1
- mns_scheduler/company_info/clean/company_info_clean_api.py +29 -9
- mns_scheduler/company_info/constant/__init__.py +1 -1
- mns_scheduler/company_info/constant/company_constant_data.py +285 -184
- mns_scheduler/company_info/de_list_stock/__init__.py +1 -1
- mns_scheduler/company_info/de_list_stock/de_list_stock_service.py +1 -1
- mns_scheduler/company_info/em_stock_info/__init__.py +7 -0
- mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +80 -0
- mns_scheduler/company_info/remark/__init__.py +1 -1
- mns_scheduler/company_info/remark/company_remark_info_sync.py +3 -3
- mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
- mns_scheduler/concept/clean/ths_concept_clean_api.py +20 -4
- mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +21 -16
- mns_scheduler/concept/ths/common/ths_concept_update_common_api.py +4 -1
- mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +7 -7
- mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_new_index_api.py +9 -4
- mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +3 -3
- mns_scheduler/db/col_move_service.py +3 -3
- mns_scheduler/db/script/__init__.py +1 -1
- mns_scheduler/db/script/col_move_script.py +1 -1
- mns_scheduler/db/script/db_move/__init__.py +7 -0
- mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
- mns_scheduler/db/script/sync/__init__.py +1 -1
- mns_scheduler/db/script/sync/remote_data_sync_to_local.py +57 -4
- mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +80 -0
- mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
- mns_scheduler/db/script/update/__init__.py +7 -0
- mns_scheduler/db/script/update/update_col_field.py +36 -0
- mns_scheduler/finance/__init__.py +1 -1
- mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +2 -2
- mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +27 -26
- mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +3 -3
- mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py} +80 -27
- 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/hk/__init__.py +1 -1
- mns_scheduler/hk/hk_company_info_sync_service_api.py +4 -4
- mns_scheduler/hk/hk_industry_info_sync_service_api.py +3 -5
- mns_scheduler/industry/__init__.py +7 -0
- mns_scheduler/industry/ths/__init__.py +7 -0
- mns_scheduler/industry/ths/ths_industry_index_service.py +58 -0
- mns_scheduler/industry/ths/ths_industry_sync_service.py +68 -0
- mns_scheduler/irm/__init__.py +1 -1
- mns_scheduler/irm/api/__init__.py +1 -1
- mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +1 -1
- mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +1 -1
- mns_scheduler/irm/stock_irm_cninfo_service.py +12 -8
- mns_scheduler/k_line/clean/daily/__init__.py +1 -1
- mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +52 -6
- mns_scheduler/k_line/clean/daily/daily_k_line_service.py +7 -2
- mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
- mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -15
- mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
- mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +124 -26
- mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +2 -2
- mns_scheduler/k_line/common/__init__.py +7 -0
- mns_scheduler/k_line/common/k_line_common_api.py +188 -0
- mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
- mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
- mns_scheduler/k_line/{sync → month_week_daily}/bfq_k_line_sync.py +14 -29
- mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +11 -12
- 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/k_line/test/__init__.py +1 -1
- mns_scheduler/k_line/test/k_line_info_clean_his_data.py +14 -3
- mns_scheduler/k_line/year_quarter/__init__.py +7 -0
- mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
- mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +1 -2
- mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
- mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +5 -0
- mns_scheduler/lhb/__init__.py +1 -1
- mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
- mns_scheduler/open/__init__.py +1 -1
- mns_scheduler/open/sync_one_day_open_data_to_db_service.py +2 -3
- mns_scheduler/risk/__init__.py +1 -1
- mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +8 -2
- mns_scheduler/risk/financial/annual_report_audit_check_api.py +13 -3
- mns_scheduler/risk/financial/net_assets_check_api.py +21 -18
- mns_scheduler/risk/financial/profit_income_check_api.py +7 -2
- mns_scheduler/risk/financial_report_risk_check_api.py +1 -1
- mns_scheduler/risk/major_violations/register_and_investigate_stock_sync_api.py +1 -1
- mns_scheduler/risk/self/wei_pan_stock_api.py +1 -1
- mns_scheduler/risk/test/__init__.py +1 -1
- mns_scheduler/risk/test/fix_blask_list.py +4 -6
- mns_scheduler/risk/transactions/transactions_check_api.py +22 -4
- mns_scheduler/self_choose/__init__.py +1 -1
- mns_scheduler/self_choose/ths_self_choose_service.py +60 -32
- mns_scheduler/trade/auto_login/trader_auto_service.py +6 -4
- mns_scheduler/trade/auto_sell_service_api.py +4 -4
- mns_scheduler/trade/balance/__init__.py +7 -0
- mns_scheduler/trade/balance/ths_account_balance_service.py +7 -0
- mns_scheduler/trade/sync_position_api.py +39 -6
- mns_scheduler/trade/task/trader_task_service.py +26 -9
- mns_scheduler/trade/tfp/__init__.py +7 -0
- mns_scheduler/trade/tfp/stock_tfp_info_sync.py +56 -0
- mns_scheduler/zb/stock_zb_pool_sync.py +1 -16
- mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -2
- mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +1 -1
- mns_scheduler/zt/script/__init__.py +1 -1
- mns_scheduler/zt/script/fix_error_deal_day.py +41 -0
- mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -2
- mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
- mns_scheduler/zt/script/sync_now_higt_chg_zt.py +8 -7
- mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +256 -55
- mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +33 -90
- mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +24 -13
- mns_scheduler/zz_task/compensation/__init__.py +0 -0
- mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
- mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
- mns_scheduler/zz_task/data_sync_task.py +177 -91
- {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.3.2.dist-info}/METADATA +1 -1
- mns_scheduler-1.4.3.2.dist-info/RECORD +169 -0
- {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.3.2.dist-info}/WHEEL +1 -1
- mns_scheduler/2014-2015-test/2014_2015_chg_statistics.py +0 -87
- mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
- mns_scheduler/db/real_time_task_check.py +0 -84
- mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
- mns_scheduler-1.1.8.4.dist-info/RECORD +0 -142
- /mns_scheduler/{big_deal → company_info/announce}/__init__.py +0 -0
- /mns_scheduler/{2014-2015-test → finance/em}/__init__.py +0 -0
- /mns_scheduler/{debt → finance/xue_qiu}/__init__.py +0 -0
- /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
- {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.3.2.dist-info}/top_level.txt +0 -0
|
@@ -9,15 +9,16 @@ sys.path.append(project_path)
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import mns_common.utils.date_handle_util as date_handle_util
|
|
11
11
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
12
|
-
import mns_common.
|
|
12
|
+
import mns_common.component.em.em_stock_info_api as em_stock_info_api
|
|
13
13
|
from loguru import logger
|
|
14
14
|
import threading
|
|
15
15
|
import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
|
|
16
16
|
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
17
|
-
import mns_scheduler.k_line.
|
|
17
|
+
import mns_scheduler.k_line.month_week_daily.daily_week_month_line_sync as daily_week_month_line_sync_api
|
|
18
18
|
import mns_scheduler.k_line.clean.k_line_info_clean_impl as k_line_info_clean_impl
|
|
19
19
|
import mns_common.utils.data_frame_util as data_frame_util
|
|
20
20
|
import mns_common.component.company.company_common_service_api as company_common_service_api
|
|
21
|
+
import mns_common.constant.db_name_constant as db_name_constant
|
|
21
22
|
|
|
22
23
|
K_LINE_CLEAN_DB_NAME = 'k_line_clean_fail_name'
|
|
23
24
|
|
|
@@ -67,7 +68,14 @@ def sync_k_line_info(str_day, symbol_list):
|
|
|
67
68
|
|
|
68
69
|
diff_days = list(company_info_df['diff_days'])[0]
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
now_year = int(str_day[0:4])
|
|
72
|
+
last_year = now_year - 1
|
|
73
|
+
|
|
74
|
+
query_year_line = {'symbol': symbol, 'year': {"$in": [str(now_year), str(last_year)]}}
|
|
75
|
+
stock_qfq_year_df = mongodb_util.find_query_data(db_name_constant.STOCK_QFQ_YEAR, query_year_line)
|
|
76
|
+
|
|
77
|
+
k_line_result = k_line_info_clean_impl.calculate_k_line_info(str_day, symbol, diff_days,
|
|
78
|
+
stock_qfq_year_df)
|
|
71
79
|
save_k_line_data(symbol, str_day, k_line_result)
|
|
72
80
|
if result_k_line_list_df is None:
|
|
73
81
|
result_k_line_list_df = k_line_result
|
|
@@ -87,18 +95,27 @@ def handle_fail_data(str_day, real_time_quotes_now):
|
|
|
87
95
|
k_line_fail_df = mongodb_util.find_query_data(K_LINE_CLEAN_DB_NAME, query)
|
|
88
96
|
if data_frame_util.is_not_empty(k_line_fail_df):
|
|
89
97
|
fail_data_df = real_time_quotes_now.loc[real_time_quotes_now['symbol'].isin(k_line_fail_df['symbol'])]
|
|
90
|
-
|
|
98
|
+
now_year = int(str_day[0:4])
|
|
99
|
+
last_year = now_year - 1
|
|
100
|
+
|
|
101
|
+
query_year_line = {'year': {"$in": [str(now_year), str(last_year)]}}
|
|
102
|
+
stock_qfq_year_df = mongodb_util.find_query_data(db_name_constant.STOCK_QFQ_YEAR, query_year_line)
|
|
103
|
+
single_threaded_sync_task(fail_data_df, str_day, 88, stock_qfq_year_df)
|
|
91
104
|
|
|
92
105
|
|
|
93
106
|
# 多线程同步任务
|
|
94
107
|
def multi_threaded_k_line_sync(str_day):
|
|
95
108
|
# 退市代码
|
|
96
|
-
de_list_company_symbols = company_common_service_api.get_de_list_company()
|
|
97
|
-
real_time_quotes_now = east_money_stock_api.get_real_time_quotes_all_stocks()
|
|
98
|
-
real_time_quotes_now = real_time_quotes_now.loc[~(real_time_quotes_now['symbol'].isin(de_list_company_symbols))]
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
de_list_company_df = mongodb_util.find_all_data(db_name_constant.DE_LIST_STOCK)
|
|
111
|
+
de_list_company_df = de_list_company_df.loc[de_list_company_df['de_list_date'] < str_day]
|
|
112
|
+
real_time_quotes_now = em_stock_info_api.get_a_stock_info()
|
|
113
|
+
real_time_quotes_now = real_time_quotes_now.loc[
|
|
114
|
+
~(real_time_quotes_now['symbol'].isin(de_list_company_df['symbol']))]
|
|
115
|
+
|
|
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)
|
|
102
119
|
|
|
103
120
|
# 将日期数值转换为日期时间格式
|
|
104
121
|
real_time_quotes_now['list_date_01'] = pd.to_datetime(real_time_quotes_now['list_date'], format='%Y%m%d')
|
|
@@ -111,8 +128,15 @@ def multi_threaded_k_line_sync(str_day):
|
|
|
111
128
|
|
|
112
129
|
# exclude b symbol
|
|
113
130
|
real_time_quotes_now = common_service_fun_api.exclude_b_symbol(real_time_quotes_now.copy())
|
|
114
|
-
|
|
115
|
-
real_time_quotes_now =
|
|
131
|
+
|
|
132
|
+
real_time_quotes_now = real_time_quotes_now.loc[real_time_quotes_now['list_date_01'] <= now_date]
|
|
133
|
+
|
|
134
|
+
now_year = int(str_day[0:4])
|
|
135
|
+
last_year = now_year - 1
|
|
136
|
+
|
|
137
|
+
query_year_line = {'year': {"$in": [str(now_year), str(last_year)]}}
|
|
138
|
+
stock_qfq_year_df = mongodb_util.find_query_data(db_name_constant.STOCK_QFQ_YEAR, query_year_line)
|
|
139
|
+
|
|
116
140
|
total_count = real_time_quotes_now.shape[0]
|
|
117
141
|
global result
|
|
118
142
|
result = pd.DataFrame() # 重新初始化 result 变量
|
|
@@ -125,9 +149,9 @@ def multi_threaded_k_line_sync(str_day):
|
|
|
125
149
|
|
|
126
150
|
end_count = (page + 1) * MAX_PAGE_NUMBER
|
|
127
151
|
begin_count = page * MAX_PAGE_NUMBER
|
|
128
|
-
page_df = real_time_quotes_now.
|
|
152
|
+
page_df = real_time_quotes_now.iloc[begin_count:end_count]
|
|
129
153
|
|
|
130
|
-
thread = threading.Thread(target=single_threaded_sync_task, args=(page_df, str_day, page))
|
|
154
|
+
thread = threading.Thread(target=single_threaded_sync_task, args=(page_df, str_day, page, stock_qfq_year_df))
|
|
131
155
|
threads.append(thread)
|
|
132
156
|
thread.start()
|
|
133
157
|
|
|
@@ -141,11 +165,12 @@ def multi_threaded_k_line_sync(str_day):
|
|
|
141
165
|
|
|
142
166
|
|
|
143
167
|
# 单线程同步任务
|
|
144
|
-
def single_threaded_sync_task(page_df, str_day, page):
|
|
168
|
+
def single_threaded_sync_task(page_df, str_day, page, stock_qfq_year_df):
|
|
145
169
|
global result
|
|
146
170
|
for stock_one in page_df.itertuples():
|
|
147
171
|
try:
|
|
148
|
-
k_line_df = k_line_info_clean_impl.calculate_k_line_info(str_day, stock_one.symbol, stock_one.diff_days
|
|
172
|
+
k_line_df = k_line_info_clean_impl.calculate_k_line_info(str_day, stock_one.symbol, stock_one.diff_days,
|
|
173
|
+
stock_qfq_year_df)
|
|
149
174
|
save_k_line_data(stock_one.symbol, str_day, k_line_df)
|
|
150
175
|
if k_line_df is None:
|
|
151
176
|
result = k_line_df
|
|
@@ -176,3 +201,5 @@ def create_k_line_index():
|
|
|
176
201
|
mongodb_util.create_index('k_line_info', [("str_day", 1), ("symbol", 1)])
|
|
177
202
|
|
|
178
203
|
|
|
204
|
+
if __name__ == '__main__':
|
|
205
|
+
sync_k_line_info_task('2025-11-13')
|
|
@@ -2,22 +2,27 @@ import sys
|
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
4
|
file_path = os.path.abspath(__file__)
|
|
5
|
-
end = file_path.index('mns') +
|
|
5
|
+
end = file_path.index('mns') + 17
|
|
6
6
|
project_path = file_path[0:end]
|
|
7
7
|
sys.path.append(project_path)
|
|
8
8
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
9
9
|
import mns_common.utils.date_handle_util as date_handle_util
|
|
10
10
|
from mns_common.component.classify.symbol_classify_param import stock_type_classify_param
|
|
11
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
12
|
+
|
|
13
|
+
# import functools
|
|
11
14
|
|
|
12
15
|
mongodb_util = MongodbUtil('27017')
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
# 处理月线 周线 todo 暂时简单计算周线之和
|
|
16
|
-
def handle_month_week_line(k_line_info, str_day, symbol, deal_days
|
|
19
|
+
def handle_month_week_line(k_line_info, str_day, symbol, deal_days,
|
|
20
|
+
stock_qfq_year_df):
|
|
17
21
|
sub_stock_new_max_deal_days = stock_type_classify_param['sub_new_stock_max_deal_days']
|
|
18
22
|
if deal_days > sub_stock_new_max_deal_days:
|
|
19
23
|
k_line_info = handle_month_line(k_line_info, str_day, symbol)
|
|
20
24
|
k_line_info = handle_week_line(k_line_info, str_day, symbol)
|
|
25
|
+
k_line_info = set_year_k_line(k_line_info, symbol, stock_qfq_year_df, str_day)
|
|
21
26
|
else:
|
|
22
27
|
k_line_info['week01'] = 0
|
|
23
28
|
k_line_info['week02'] = 0
|
|
@@ -33,37 +38,130 @@ def handle_month_week_line(k_line_info, str_day, symbol, deal_days):
|
|
|
33
38
|
k_line_info['month02'] = 0
|
|
34
39
|
k_line_info['month01_date'] = '19890729'
|
|
35
40
|
k_line_info['month02_date'] = '19890729'
|
|
41
|
+
# 上市交易日不到100天的默认设置年线数据为0
|
|
42
|
+
k_line_info['now_year_chg'] = 0
|
|
43
|
+
k_line_info['now_year_open_from_high_chg'] = 0
|
|
44
|
+
k_line_info['now_year_low_from_high_chg'] = 0
|
|
45
|
+
|
|
46
|
+
k_line_info['last_year_chg'] = 0
|
|
47
|
+
k_line_info['last_year_open_from_high_chg'] = 0
|
|
48
|
+
k_line_info['last_year_low_from_high_chg'] = 0
|
|
49
|
+
|
|
50
|
+
return k_line_info
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# 年线数据设置
|
|
54
|
+
def set_year_k_line(k_line_info, symbol, stock_qfq_year_df, str_day):
|
|
55
|
+
now_year = int(str_day[0:4])
|
|
56
|
+
last_year = str(now_year - 1)
|
|
57
|
+
stock_qfq_now_year_df = stock_qfq_year_df.loc[(stock_qfq_year_df['symbol'] == symbol)
|
|
58
|
+
& (stock_qfq_year_df['year'] == str(now_year))]
|
|
59
|
+
if data_frame_util.is_empty(stock_qfq_now_year_df):
|
|
60
|
+
k_line_info['now_year_chg'] = 0
|
|
61
|
+
k_line_info['now_year_open_from_high_chg'] = 0
|
|
62
|
+
k_line_info['now_year_low_from_high_chg'] = 0
|
|
63
|
+
else:
|
|
64
|
+
k_line_info['now_year_chg'] = list(stock_qfq_now_year_df['chg'])[0]
|
|
65
|
+
k_line_info['now_year_open_from_high_chg'] = list(stock_qfq_now_year_df['open_to_high_pct'])[0]
|
|
66
|
+
k_line_info['now_year_low_from_high_chg'] = list(stock_qfq_now_year_df['low_to_high_pct'])[0]
|
|
67
|
+
|
|
68
|
+
stock_qfq_last_year_df = stock_qfq_year_df.loc[(stock_qfq_year_df['symbol'] == symbol)
|
|
69
|
+
& (stock_qfq_year_df['year'] == last_year)]
|
|
70
|
+
|
|
71
|
+
if data_frame_util.is_empty(stock_qfq_last_year_df):
|
|
72
|
+
k_line_info['last_year_chg'] = 0
|
|
73
|
+
k_line_info['last_year_open_from_high_chg'] = 0
|
|
74
|
+
k_line_info['last_year_low_from_high_chg'] = 0
|
|
75
|
+
else:
|
|
76
|
+
k_line_info['last_year_chg'] = list(stock_qfq_last_year_df['chg'])[0]
|
|
77
|
+
k_line_info['last_year_open_from_high_chg'] = list(stock_qfq_last_year_df['open_to_high_pct'])[0]
|
|
78
|
+
k_line_info['last_year_low_from_high_chg'] = list(stock_qfq_last_year_df['low_to_high_pct'])[0]
|
|
79
|
+
|
|
36
80
|
return k_line_info
|
|
37
81
|
|
|
82
|
+
# 处理月线
|
|
83
|
+
|
|
38
84
|
|
|
39
|
-
# 处理月线
|
|
40
85
|
def handle_month_line(k_line_info, str_day, symbol):
|
|
41
|
-
|
|
86
|
+
now_year = int(str_day[0:4])
|
|
87
|
+
last_year = str(now_year - 1)
|
|
88
|
+
|
|
89
|
+
now_month_begin_day = str_day[0:7] + '-01'
|
|
90
|
+
|
|
91
|
+
last_year_begin_day = last_year + '-01-01'
|
|
92
|
+
# now_year_begin_day = str(now_year) + '-01-01'
|
|
93
|
+
|
|
42
94
|
query = {"symbol": symbol,
|
|
43
|
-
'date': {"$
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
k_line_info['month_num'] = month_num
|
|
47
|
-
if month_num > 0:
|
|
48
|
-
k_line_info['sum_month'] = round(sum(stock_hfq_monthly['chg']), 2)
|
|
49
|
-
else:
|
|
95
|
+
'date': {"$gte": date_handle_util.no_slash_date(last_year_begin_day)}}
|
|
96
|
+
stock_hfq_monthly_all = mongodb_util.find_query_data('stock_qfq_monthly', query)
|
|
97
|
+
if data_frame_util.is_empty(stock_hfq_monthly_all):
|
|
50
98
|
k_line_info['sum_month'] = 0
|
|
51
99
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
k_line_info['
|
|
100
|
+
else:
|
|
101
|
+
stock_hfq_monthly_all = stock_hfq_monthly_all.sort_values(by=['date'], ascending=False)
|
|
102
|
+
stock_hfq_monthly_all = stock_hfq_monthly_all.loc[
|
|
103
|
+
stock_hfq_monthly_all['date'] <= date_handle_util.no_slash_date(now_month_begin_day)]
|
|
104
|
+
|
|
105
|
+
# stock_hfq_monthly_last_year = stock_hfq_monthly_all.loc[
|
|
106
|
+
# stock_hfq_monthly_all['date'] < date_handle_util.no_slash_date(now_year_begin_day)]
|
|
107
|
+
#
|
|
108
|
+
# stock_hfq_monthly_now_year = stock_hfq_monthly_all.loc[
|
|
109
|
+
# stock_hfq_monthly_all['date'] > date_handle_util.no_slash_date(now_year_begin_day)]
|
|
110
|
+
|
|
111
|
+
# 最近两个月k线
|
|
112
|
+
before_two_month_stock_hfq_monthly = stock_hfq_monthly_all.iloc[0:2]
|
|
113
|
+
month_num = before_two_month_stock_hfq_monthly.shape[0]
|
|
114
|
+
k_line_info['month_num'] = month_num
|
|
115
|
+
|
|
116
|
+
if month_num == 0:
|
|
117
|
+
k_line_info['sum_month'] = 0
|
|
118
|
+
k_line_info['month01'] = 0
|
|
119
|
+
k_line_info['month02'] = 0
|
|
120
|
+
k_line_info['month01_date'] = '19890729'
|
|
121
|
+
k_line_info['month02_date'] = '19890729'
|
|
122
|
+
elif month_num == 1:
|
|
123
|
+
k_line_info['month01'] = before_two_month_stock_hfq_monthly.iloc[0].chg
|
|
124
|
+
k_line_info['month02'] = 0
|
|
125
|
+
k_line_info['month01_date'] = before_two_month_stock_hfq_monthly.iloc[0].date
|
|
126
|
+
k_line_info['month02_date'] = '19890729'
|
|
127
|
+
k_line_info['sum_month'] = before_two_month_stock_hfq_monthly.iloc[0].chg
|
|
128
|
+
elif month_num == 2:
|
|
129
|
+
k_line_info['month01'] = before_two_month_stock_hfq_monthly.iloc[0].chg
|
|
130
|
+
k_line_info['month02'] = before_two_month_stock_hfq_monthly.iloc[1].chg
|
|
131
|
+
k_line_info['month01_date'] = before_two_month_stock_hfq_monthly.iloc[0].date
|
|
132
|
+
k_line_info['month02_date'] = before_two_month_stock_hfq_monthly.iloc[1].date
|
|
133
|
+
close_price = before_two_month_stock_hfq_monthly.iloc[0].close
|
|
134
|
+
open_price = before_two_month_stock_hfq_monthly.iloc[1].last_price
|
|
135
|
+
sum_chg = round((close_price - open_price) * 100 / open_price, 2)
|
|
136
|
+
k_line_info['sum_month'] = sum_chg
|
|
137
|
+
#
|
|
138
|
+
# last_year_month_number = stock_hfq_monthly_last_year.shape[0]
|
|
139
|
+
# if last_year_month_number == 0:
|
|
140
|
+
# k_line_info['last_year_chg'] = 0
|
|
141
|
+
# elif last_year_month_number == 1:
|
|
142
|
+
# k_line_info['last_year_chg'] = stock_hfq_monthly_last_year.iloc[0].chg
|
|
143
|
+
# else:
|
|
144
|
+
# # chg_list = list(stock_hfq_monthly_last_year['chg'])
|
|
145
|
+
# # # 将列表中的每个元素加上1
|
|
146
|
+
# # updated_list = [round((x / 100) + 1, 2) for x in chg_list]
|
|
147
|
+
# #
|
|
148
|
+
# # # 使用 functools.reduce 将列表中的所有元素相乘
|
|
149
|
+
# # last_year_chg = functools.reduce(lambda x, y: x * y, updated_list)
|
|
150
|
+
# close_price = stock_hfq_monthly_last_year.iloc[0].close
|
|
151
|
+
# open_price = stock_hfq_monthly_last_year.iloc[last_year_month_number - 1].last_price
|
|
152
|
+
# last_year_chg = round((close_price - open_price) * 100 / open_price, 2)
|
|
153
|
+
# k_line_info['last_year_chg'] = last_year_chg
|
|
154
|
+
#
|
|
155
|
+
# now_year_month_number = stock_hfq_monthly_now_year.shape[0]
|
|
156
|
+
# if now_year_month_number == 0:
|
|
157
|
+
# k_line_info['now_year_chg'] = 0
|
|
158
|
+
# elif now_year_month_number == 1:
|
|
159
|
+
# k_line_info['now_year_chg'] = stock_hfq_monthly_now_year.iloc[0].chg
|
|
160
|
+
# else:
|
|
161
|
+
# close_price = stock_hfq_monthly_now_year.iloc[0].close
|
|
162
|
+
# open_price = stock_hfq_monthly_now_year.iloc[now_year_month_number - 1].last_price
|
|
163
|
+
# last_year_chg = round((close_price - open_price) * 100 / open_price, 2)
|
|
164
|
+
# k_line_info['now_year_chg'] = last_year_chg
|
|
67
165
|
|
|
68
166
|
return k_line_info
|
|
69
167
|
|
|
@@ -2,7 +2,7 @@ import sys
|
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
4
|
file_path = os.path.abspath(__file__)
|
|
5
|
-
end = file_path.index('mns') +
|
|
5
|
+
end = file_path.index('mns') + 17
|
|
6
6
|
project_path = file_path[0:end]
|
|
7
7
|
sys.path.append(project_path)
|
|
8
8
|
|
|
@@ -36,7 +36,7 @@ def handle_month_line(k_line_info, stock_qfq_daily, deal_days):
|
|
|
36
36
|
if k_line_length != MAX_TRADE_DAYS_PER_MONTH:
|
|
37
37
|
k_line_info['month02_date'] = list(stock_qfq_daily_month_02.iloc[0:1]['date'])[0]
|
|
38
38
|
else:
|
|
39
|
-
k_line_info['month02_date'] = ''
|
|
39
|
+
k_line_info['month02_date'] = '19890729'
|
|
40
40
|
elif deal_days > MAX_TRADE_DAYS_PER_MONTH * 2:
|
|
41
41
|
stock_qfq_daily_month_01 = stock_qfq_daily.iloc[0:MAX_TRADE_DAYS_PER_MONTH]
|
|
42
42
|
month_01 = round(sum(stock_qfq_daily_month_01['chg']), 2)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
file_path = os.path.abspath(__file__)
|
|
7
|
+
end = file_path.index('mns') + 16
|
|
8
|
+
project_path = file_path[0:end]
|
|
9
|
+
sys.path.append(project_path)
|
|
10
|
+
import mns_common.api.akshare.k_line_api as k_line_api
|
|
11
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
12
|
+
import mns_common.api.xueqiu.xue_qiu_k_line_api as xue_qiu_k_line_api
|
|
13
|
+
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
14
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
15
|
+
from datetime import datetime, timedelta
|
|
16
|
+
import mns_common.api.msg.push_msg_api as push_msg_api
|
|
17
|
+
import numpy as np
|
|
18
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
19
|
+
from loguru import logger
|
|
20
|
+
import threading
|
|
21
|
+
|
|
22
|
+
# source_type = 'xue_qiu'
|
|
23
|
+
source_type = 'xue_qiu'
|
|
24
|
+
error_no = 1
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# 自定义报警处理函数
|
|
28
|
+
def custom_alert(current: int, threshold: int):
|
|
29
|
+
push_msg_api.push_msg_to_wechat('获取k线数据异常', "当前次数:" + str(current) + "阈值:" + str(threshold))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# 定义一个带超时的函数调用
|
|
33
|
+
def call_with_timeout(func, *args, timeout=10, **kwargs):
|
|
34
|
+
# 用于存储函数执行结果
|
|
35
|
+
result = None
|
|
36
|
+
exception = None
|
|
37
|
+
|
|
38
|
+
# 定义一个线程目标函数
|
|
39
|
+
def target():
|
|
40
|
+
nonlocal result, exception
|
|
41
|
+
try:
|
|
42
|
+
result = func(*args, **kwargs)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
exception = e
|
|
45
|
+
|
|
46
|
+
# 创建线程并启动
|
|
47
|
+
thread = threading.Thread(target=target)
|
|
48
|
+
thread.start()
|
|
49
|
+
|
|
50
|
+
# 等待线程完成,最多等待 timeout 秒
|
|
51
|
+
thread.join(timeout)
|
|
52
|
+
|
|
53
|
+
# 如果线程仍然存活,说明函数超时了
|
|
54
|
+
if thread.is_alive():
|
|
55
|
+
raise TimeoutError(f"Function exceeded timeout of {timeout} seconds")
|
|
56
|
+
|
|
57
|
+
# 如果函数抛出了异常,重新抛出
|
|
58
|
+
if exception is not None:
|
|
59
|
+
raise exception
|
|
60
|
+
return result
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_k_line_common_adapter(symbol, period, hq, end_date):
|
|
64
|
+
global error_no
|
|
65
|
+
df = pd.DataFrame()
|
|
66
|
+
try:
|
|
67
|
+
if source_type == 'em':
|
|
68
|
+
|
|
69
|
+
df = call_with_timeout(get_em_k_line_api,
|
|
70
|
+
symbol,
|
|
71
|
+
period,
|
|
72
|
+
hq,
|
|
73
|
+
end_date,
|
|
74
|
+
timeout=10)
|
|
75
|
+
elif source_type == 'xue_qiu':
|
|
76
|
+
df = call_with_timeout(get_xueqiu_k_line_api,
|
|
77
|
+
symbol,
|
|
78
|
+
period,
|
|
79
|
+
hq,
|
|
80
|
+
end_date,
|
|
81
|
+
timeout=10)
|
|
82
|
+
|
|
83
|
+
if data_frame_util.is_empty(df):
|
|
84
|
+
error_no = error_no + 1
|
|
85
|
+
except BaseException as e:
|
|
86
|
+
logger.error("获取k线异常:{}", e)
|
|
87
|
+
error_no = error_no + 1
|
|
88
|
+
if error_no == 1000:
|
|
89
|
+
push_msg_api.push_msg_to_wechat('获取k线数据异常', "当前次数:" + str(error_no))
|
|
90
|
+
return df
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# 应用带参数的装饰器
|
|
94
|
+
# @exception_counter(
|
|
95
|
+
# threshold=1500,
|
|
96
|
+
# alert_handler=custom_alert,
|
|
97
|
+
# auto_reset=False
|
|
98
|
+
# )
|
|
99
|
+
def get_em_k_line_api(symbol, period, hq, end_date):
|
|
100
|
+
# 检查symbol是否以'6'开头
|
|
101
|
+
if symbol.startswith('6'):
|
|
102
|
+
symbol_a = '1.' + symbol
|
|
103
|
+
else:
|
|
104
|
+
symbol_a = '0.' + symbol
|
|
105
|
+
stock_hfq_df = k_line_api.stock_zh_a_hist(symbol=symbol_a,
|
|
106
|
+
period=period,
|
|
107
|
+
start_date=date_handle_util.no_slash_date('1990-12-19'),
|
|
108
|
+
end_date=date_handle_util.no_slash_date(end_date),
|
|
109
|
+
adjust=hq)
|
|
110
|
+
|
|
111
|
+
stock_hfq_df.rename(columns={"日期": "date", "开盘": "open",
|
|
112
|
+
"收盘": "close", "最高": "high",
|
|
113
|
+
"最低": "low", "成交量": "volume",
|
|
114
|
+
"成交额": "amount", "振幅": "pct_chg",
|
|
115
|
+
"涨跌幅": "chg", "涨跌额": "change",
|
|
116
|
+
"换手率": "exchange"}, inplace=True)
|
|
117
|
+
stock_hfq_df['symbol'] = symbol
|
|
118
|
+
stock_hfq_df['_id'] = symbol + '-' + stock_hfq_df['date']
|
|
119
|
+
return stock_hfq_df
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# period : year quarter month week day
|
|
123
|
+
# hq: qfq:before ,hfq:after, bfq:normal
|
|
124
|
+
|
|
125
|
+
def get_xueqiu_k_line_api(symbol, period, hq, end_date):
|
|
126
|
+
if hq == 'qfq':
|
|
127
|
+
adjust = 'before'
|
|
128
|
+
elif hq == 'hfq':
|
|
129
|
+
adjust = 'after'
|
|
130
|
+
else:
|
|
131
|
+
adjust = 'normal'
|
|
132
|
+
|
|
133
|
+
period_time = 'day'
|
|
134
|
+
if period == 'daily':
|
|
135
|
+
period_time = 'day'
|
|
136
|
+
elif period == 'weekly':
|
|
137
|
+
period_time = 'week'
|
|
138
|
+
elif period == 'monthly':
|
|
139
|
+
period_time = 'month'
|
|
140
|
+
|
|
141
|
+
cookie = cookie_info_service.get_xue_qiu_cookie()
|
|
142
|
+
symbol_pre_fix = common_service_fun_api.add_pre_prefix_one(symbol)
|
|
143
|
+
dt = datetime.strptime(end_date, '%Y-%m-%d')
|
|
144
|
+
dt += timedelta(days=1)
|
|
145
|
+
timestamp = str(int(dt.timestamp() * 1000)) # 转换为毫秒
|
|
146
|
+
stock_k_line_df = xue_qiu_k_line_api.get_xue_qiu_k_line(symbol_pre_fix, period_time,
|
|
147
|
+
cookie, timestamp, adjust)
|
|
148
|
+
|
|
149
|
+
stock_k_line_df['pct_chg'] = round(abs(stock_k_line_df['high'] - stock_k_line_df['low'] / stock_k_line_df['high']),
|
|
150
|
+
2)
|
|
151
|
+
stock_k_line_df.rename(columns={"chg": "change",
|
|
152
|
+
"percent": "chg",
|
|
153
|
+
"str_day": "date",
|
|
154
|
+
"market_capital": "flow_mv",
|
|
155
|
+
"turnoverrate": "exchange"}, inplace=True)
|
|
156
|
+
stock_k_line_df = stock_k_line_df[[
|
|
157
|
+
"date",
|
|
158
|
+
"open",
|
|
159
|
+
"close",
|
|
160
|
+
"high",
|
|
161
|
+
"low",
|
|
162
|
+
"volume",
|
|
163
|
+
"amount",
|
|
164
|
+
"pct_chg",
|
|
165
|
+
"chg",
|
|
166
|
+
"change",
|
|
167
|
+
"exchange"
|
|
168
|
+
]]
|
|
169
|
+
stock_k_line_df['symbol'] = symbol
|
|
170
|
+
stock_k_line_df['date'] = stock_k_line_df['date'].str.replace('-', '')
|
|
171
|
+
stock_k_line_df['_id'] = symbol + '-' + stock_k_line_df['date']
|
|
172
|
+
stock_k_line_df['last_price'] = round(((stock_k_line_df['close']) / (1 + stock_k_line_df['chg'] / 100)), 2)
|
|
173
|
+
stock_k_line_df['max_chg'] = round(
|
|
174
|
+
((stock_k_line_df['high'] - stock_k_line_df['last_price']) / stock_k_line_df['last_price']) * 100, 2)
|
|
175
|
+
stock_k_line_df['amount_level'] = round((stock_k_line_df['amount'] / common_service_fun_api.HUNDRED_MILLION), 2)
|
|
176
|
+
stock_k_line_df['flow_mv'] = round(stock_k_line_df['amount'] * 100 / stock_k_line_df['exchange'], 2)
|
|
177
|
+
stock_k_line_df['flow_mv_sp'] = round(stock_k_line_df['flow_mv'] / common_service_fun_api.HUNDRED_MILLION, 2)
|
|
178
|
+
|
|
179
|
+
stock_k_line_df.replace([np.inf, -np.inf], 0, inplace=True)
|
|
180
|
+
stock_k_line_df.fillna(0, inplace=True)
|
|
181
|
+
stock_k_line_df['date'] = stock_k_line_df['date'].astype(str).str[:8]
|
|
182
|
+
return stock_k_line_df
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
if __name__ == '__main__':
|
|
186
|
+
while True:
|
|
187
|
+
test_df = get_k_line_common_adapter('000001', 'day', 'qfq', '2025-05-25')
|
|
188
|
+
print(test_df)
|
|
@@ -7,41 +7,26 @@ project_path = file_path[0:end]
|
|
|
7
7
|
sys.path.append(project_path)
|
|
8
8
|
|
|
9
9
|
from loguru import logger
|
|
10
|
-
import mns_common.
|
|
10
|
+
import mns_common.component.em.em_stock_info_api as em_stock_info_api
|
|
11
11
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
12
|
-
import mns_common.utils.date_handle_util as date_handle_util
|
|
13
12
|
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
14
|
-
import
|
|
13
|
+
import mns_scheduler.k_line.common.k_line_common_api as k_line_common_api
|
|
15
14
|
import mns_common.component.company.company_common_service_new_api as company_common_service_new_api
|
|
16
15
|
|
|
16
|
+
|
|
17
|
+
|
|
17
18
|
mongodb_util = MongodbUtil('27017')
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
def sync_bfq_k_line_data(period='daily',
|
|
21
22
|
hq='hfq',
|
|
22
23
|
hq_col='stock_hfq_daily',
|
|
23
|
-
end_date='
|
|
24
|
+
end_date='2222-01-01',
|
|
24
25
|
symbol=None):
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stock_hfq_df.rename(columns={"日期": "date", "开盘": "open",
|
|
31
|
-
"收盘": "close", "最高": "high",
|
|
32
|
-
"最低": "low", "成交量": "volume",
|
|
33
|
-
"成交额": "amount", "振幅": "pct_chg",
|
|
34
|
-
"涨跌幅": "chg", "涨跌额": "change",
|
|
35
|
-
"换手率": "exchange"}, inplace=True)
|
|
36
|
-
|
|
37
|
-
stock_hfq_df['symbol'] = symbol
|
|
38
|
-
stock_hfq_df['_id'] = stock_hfq_df['symbol'] + '-' + stock_hfq_df['date']
|
|
39
|
-
stock_hfq_df['last_price'] = round(((stock_hfq_df['close']) / (1 + stock_hfq_df['chg'] / 100)), 2)
|
|
40
|
-
stock_hfq_df['max_chg'] = round(
|
|
41
|
-
((stock_hfq_df['high'] - stock_hfq_df['last_price']) / stock_hfq_df['last_price']) * 100, 2)
|
|
42
|
-
stock_hfq_df['amount_level'] = round((stock_hfq_df['amount'] / common_service_fun_api.HUNDRED_MILLION), 2)
|
|
43
|
-
stock_hfq_df['flow_mv'] = round(stock_hfq_df['amount'] * 100 / stock_hfq_df['exchange'], 2)
|
|
44
|
-
stock_hfq_df['flow_mv_sp'] = round(stock_hfq_df['flow_mv'] / common_service_fun_api.HUNDRED_MILLION, 2)
|
|
26
|
+
|
|
27
|
+
stock_hfq_df = k_line_common_api.get_k_line_common_adapter(symbol, period, hq, end_date)
|
|
28
|
+
|
|
29
|
+
|
|
45
30
|
|
|
46
31
|
classification = common_service_fun_api.classify_symbol_one(symbol)
|
|
47
32
|
stock_hfq_df['classification'] = classification
|
|
@@ -55,8 +40,8 @@ def sync_all_bfq_k_line(period='daily',
|
|
|
55
40
|
hq='hfq',
|
|
56
41
|
hq_col='stock_hfq_daily',
|
|
57
42
|
end_date='22220101',
|
|
58
|
-
symbol=
|
|
59
|
-
real_time_quotes_now_es =
|
|
43
|
+
symbol='300085'):
|
|
44
|
+
real_time_quotes_now_es = em_stock_info_api.get_a_stock_info()
|
|
60
45
|
|
|
61
46
|
symbol_list = list(real_time_quotes_now_es['symbol'])
|
|
62
47
|
# 退市公司
|
|
@@ -86,7 +71,7 @@ def insert_data(stock_hfq_df, hq_col, symbol):
|
|
|
86
71
|
|
|
87
72
|
if __name__ == '__main__':
|
|
88
73
|
sync_all_bfq_k_line('daily',
|
|
89
|
-
'',
|
|
74
|
+
'qfq',
|
|
90
75
|
'stock_bfq_daily',
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
'2025-05-25',
|
|
77
|
+
'000001')
|