mns-scheduler 1.2.6.4__py3-none-any.whl → 1.4.2.5__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.

Files changed (125) hide show
  1. mns_scheduler/company_info/announce/__init__.py +1 -1
  2. mns_scheduler/company_info/announce/company_announce_sync_service.py +11 -6
  3. mns_scheduler/company_info/base/__init__.py +1 -1
  4. mns_scheduler/company_info/base/sync_company_base_info_api.py +165 -75
  5. mns_scheduler/company_info/base/sync_company_hold_info_api.py +3 -6
  6. mns_scheduler/company_info/base/sync_company_product_area_industry.py +161 -0
  7. mns_scheduler/company_info/clean/__init__.py +1 -1
  8. mns_scheduler/company_info/clean/company_info_clean_api.py +3 -3
  9. mns_scheduler/company_info/constant/__init__.py +1 -1
  10. mns_scheduler/company_info/constant/company_constant_data.py +4 -0
  11. mns_scheduler/company_info/de_list_stock/__init__.py +1 -1
  12. mns_scheduler/company_info/de_list_stock/de_list_stock_service.py +1 -1
  13. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +80 -0
  14. mns_scheduler/company_info/remark/__init__.py +1 -1
  15. mns_scheduler/company_info/remark/company_remark_info_sync.py +3 -3
  16. mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
  17. mns_scheduler/concept/clean/ths_concept_clean_api.py +3 -6
  18. mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +2 -2
  19. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +2 -2
  20. mns_scheduler/db/script/__init__.py +1 -1
  21. mns_scheduler/db/script/col_move_script.py +1 -1
  22. mns_scheduler/db/script/db_move/__init__.py +7 -0
  23. mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
  24. mns_scheduler/db/script/sync/__init__.py +1 -1
  25. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +40 -8
  26. mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +36 -23
  27. mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
  28. mns_scheduler/db/script/update/__init__.py +1 -1
  29. mns_scheduler/db/script/update/update_col_field.py +1 -1
  30. mns_scheduler/finance/__init__.py +1 -1
  31. mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +2 -2
  32. mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +27 -26
  33. mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +3 -3
  34. mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py} +80 -27
  35. mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
  36. mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
  37. mns_scheduler/hk/__init__.py +1 -1
  38. mns_scheduler/hk/hk_company_info_sync_service_api.py +4 -4
  39. mns_scheduler/hk/hk_industry_info_sync_service_api.py +3 -5
  40. mns_scheduler/industry/__init__.py +1 -1
  41. mns_scheduler/industry/ths/__init__.py +1 -1
  42. mns_scheduler/industry/ths/ths_industry_index_service.py +1 -1
  43. mns_scheduler/industry/ths/ths_industry_sync_service.py +1 -1
  44. mns_scheduler/irm/__init__.py +1 -1
  45. mns_scheduler/irm/api/__init__.py +1 -1
  46. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +1 -1
  47. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +1 -1
  48. mns_scheduler/irm/stock_irm_cninfo_service.py +12 -8
  49. mns_scheduler/k_line/clean/daily/__init__.py +1 -1
  50. mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +1 -1
  51. mns_scheduler/k_line/clean/daily/daily_k_line_service.py +1 -1
  52. mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
  53. mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -15
  54. mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
  55. mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +75 -40
  56. mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +2 -2
  57. mns_scheduler/k_line/common/__init__.py +7 -0
  58. mns_scheduler/k_line/common/k_line_common_api.py +188 -0
  59. mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
  60. mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
  61. mns_scheduler/k_line/{sync → month_week_daily}/bfq_k_line_sync.py +14 -29
  62. mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +9 -11
  63. mns_scheduler/k_line/sync_status/__init__.py +7 -0
  64. mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
  65. mns_scheduler/k_line/test/__init__.py +1 -1
  66. mns_scheduler/k_line/test/k_line_info_clean_his_data.py +10 -5
  67. mns_scheduler/k_line/year_quarter/__init__.py +7 -0
  68. mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
  69. mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +1 -2
  70. mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
  71. mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +5 -0
  72. mns_scheduler/lhb/__init__.py +1 -1
  73. mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
  74. mns_scheduler/open/__init__.py +1 -1
  75. mns_scheduler/open/sync_one_day_open_data_to_db_service.py +2 -2
  76. mns_scheduler/risk/__init__.py +1 -1
  77. mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +8 -2
  78. mns_scheduler/risk/financial/annual_report_audit_check_api.py +10 -2
  79. mns_scheduler/risk/financial/net_assets_check_api.py +1 -1
  80. mns_scheduler/risk/financial/profit_income_check_api.py +2 -3
  81. mns_scheduler/risk/financial_report_risk_check_api.py +1 -1
  82. mns_scheduler/risk/major_violations/register_and_investigate_stock_sync_api.py +1 -1
  83. mns_scheduler/risk/self/wei_pan_stock_api.py +1 -1
  84. mns_scheduler/risk/test/__init__.py +1 -1
  85. mns_scheduler/risk/test/fix_blask_list.py +2 -2
  86. mns_scheduler/risk/transactions/transactions_check_api.py +7 -5
  87. mns_scheduler/self_choose/__init__.py +1 -1
  88. mns_scheduler/self_choose/ths_self_choose_service.py +37 -28
  89. mns_scheduler/trade/auto_login/trader_auto_service.py +6 -4
  90. mns_scheduler/trade/auto_sell_service_api.py +4 -4
  91. mns_scheduler/trade/balance/__init__.py +1 -1
  92. mns_scheduler/trade/balance/ths_account_balance_service.py +1 -1
  93. mns_scheduler/trade/sync_position_api.py +1 -1
  94. mns_scheduler/trade/task/trader_task_service.py +26 -9
  95. mns_scheduler/trade/tfp/__init__.py +1 -1
  96. mns_scheduler/trade/tfp/stock_tfp_info_sync.py +5 -2
  97. mns_scheduler/zb/stock_zb_pool_sync.py +1 -16
  98. mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -2
  99. mns_scheduler/zt/script/__init__.py +1 -1
  100. mns_scheduler/zt/script/fix_error_deal_day.py +1 -1
  101. mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -2
  102. mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
  103. mns_scheduler/zt/script/sync_now_higt_chg_zt.py +8 -7
  104. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +46 -18
  105. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +33 -90
  106. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +18 -5
  107. mns_scheduler/zz_task/compensation/__init__.py +0 -0
  108. mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
  109. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
  110. mns_scheduler/zz_task/data_sync_task.py +144 -120
  111. {mns_scheduler-1.2.6.4.dist-info → mns_scheduler-1.4.2.5.dist-info}/METADATA +1 -1
  112. mns_scheduler-1.4.2.5.dist-info/RECORD +169 -0
  113. {mns_scheduler-1.2.6.4.dist-info → mns_scheduler-1.4.2.5.dist-info}/WHEEL +1 -1
  114. mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
  115. mns_scheduler/db/real_time_task_check.py +0 -127
  116. mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
  117. mns_scheduler/us/baidu_yun_pan_handle_service.py +0 -131
  118. mns_scheduler/us/k_line.py +0 -91
  119. mns_scheduler/us/us_company_info_sync_service_api.py +0 -39
  120. mns_scheduler-1.2.6.4.dist-info/RECORD +0 -158
  121. /mns_scheduler/{big_deal → company_info/em_stock_info}/__init__.py +0 -0
  122. /mns_scheduler/{debt → finance/em}/__init__.py +0 -0
  123. /mns_scheduler/{us → finance/xue_qiu}/__init__.py +0 -0
  124. /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
  125. {mns_scheduler-1.2.6.4.dist-info → mns_scheduler-1.4.2.5.dist-info}/top_level.txt +0 -0
@@ -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') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  # !/usr/bin/env python
@@ -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') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  # !/usr/bin/env python
@@ -2,13 +2,13 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  import akshare as ak
9
9
  import mns_common.utils.data_frame_util as data_frame_util
10
10
  import pandas as pd
11
- import mns_common.api.em.east_money_stock_api as east_money_stock_api
11
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
12
12
  import mns_common.component.company.company_common_service_api as company_common_service_api
13
13
  from loguru import logger
14
14
  from datetime import datetime
@@ -119,18 +119,18 @@ def save_sh_stock_uid():
119
119
 
120
120
 
121
121
  # 同步所有互动问题
122
- def sync_all_interactive_questions(symbol_list):
122
+ def sync_symbols_interactive_questions(symbol_list):
123
123
  # 同步互动易映射
124
- save_sh_stock_uid()
125
-
126
- real_time_quotes_all_stocks = east_money_stock_api.get_real_time_quotes_all_stocks()
124
+ if len(symbol_list) == 0:
125
+ save_sh_stock_uid()
126
+ real_time_quotes_all_stocks = em_stock_info_api.get_a_stock_info()
127
127
  de_list_company_symbols = company_common_service_api.get_de_list_company()
128
128
  real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
129
129
  ~(real_time_quotes_all_stocks['symbol'].isin(de_list_company_symbols))]
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 is not None:
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():
@@ -149,6 +149,8 @@ def sync_all_interactive_questions(symbol_list):
149
149
 
150
150
  else:
151
151
  continue
152
+ if data_frame_util.is_empty(stock_irm_cninfo_df):
153
+ continue
152
154
  stock_irm_cninfo_df['sync_time'] = str_now_date
153
155
  stock_irm_cninfo_df['str_day'] = str_day
154
156
  stock_irm_cninfo_df.drop_duplicates('_id', keep='last', inplace=True)
@@ -191,6 +193,8 @@ def save_new_data(stock_irm_cninfo_df):
191
193
 
192
194
 
193
195
  if __name__ == '__main__':
196
+ sync_symbols_interactive_questions([])
197
+ get_stock_irm_cninfo_sh_api('688778')
194
198
  fail_symbol_list_01 = ['000638', '002886', '688778', '688766', '688733', '688778', '688793', '688787']
195
199
  # get_stock_irm_cninfo_sh_api('603633')
196
- sync_all_interactive_questions(None)
200
+ # sync_symbols_interactive_questions(None)
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -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') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  import pandas as pd
@@ -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') + 16
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
@@ -16,7 +16,7 @@ mongodb_util = MongodbUtil('27017')
16
16
 
17
17
 
18
18
  # 日线 周线 月线 成交量 筹码信息
19
- def calculate_k_line_info(str_day, symbol, diff_days):
19
+ def calculate_k_line_info(str_day, symbol, diff_days, stock_qfq_year_df):
20
20
  k_line_info = pd.DataFrame([[
21
21
  str_day,
22
22
  symbol, diff_days]],
@@ -27,7 +27,8 @@ def calculate_k_line_info(str_day, symbol, diff_days):
27
27
  # 交易天数
28
28
  deal_days = k_line_common_service_api.get_deal_days(str_day, symbol)
29
29
  # 处理周线 月线
30
- k_line_info = week_month_k_line_service.handle_month_week_line(k_line_info, str_day, symbol, deal_days)
30
+ k_line_info = week_month_k_line_service.handle_month_week_line(k_line_info, str_day, symbol,
31
+ deal_days, stock_qfq_year_df)
31
32
  # 处理日线
32
33
  k_line_info = daily_k_line_service.handle_day_line(k_line_info, str_day, symbol, deal_days)
33
34
  return k_line_info
@@ -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.api.em.east_money_stock_api as east_money_stock_api
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.sync.daily_week_month_line_sync as daily_week_month_line_sync_api
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
- k_line_result = k_line_info_clean_impl.calculate_k_line_info(str_day, symbol, diff_days)
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
- single_threaded_sync_task(fail_data_df, str_day, 88)
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
- # 将list_date列中的所有NaN值设置为99990909
101
- real_time_quotes_now['list_date'].fillna(20990909.0, inplace=True)
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
- # exclude amount==0 symbol
115
- real_time_quotes_now = common_service_fun_api.exclude_amount_zero_stock(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.loc[begin_count:end_count]
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,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -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') + 16
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
@@ -16,14 +16,13 @@ mongodb_util = MongodbUtil('27017')
16
16
 
17
17
 
18
18
  # 处理月线 周线 todo 暂时简单计算周线之和
19
- 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):
20
21
  sub_stock_new_max_deal_days = stock_type_classify_param['sub_new_stock_max_deal_days']
21
22
  if deal_days > sub_stock_new_max_deal_days:
22
- k_line_info['last_year_chg'] = 0
23
- k_line_info['now_year_chg'] = 0
24
23
  k_line_info = handle_month_line(k_line_info, str_day, symbol)
25
24
  k_line_info = handle_week_line(k_line_info, str_day, symbol)
26
-
25
+ k_line_info = set_year_k_line(k_line_info, symbol, stock_qfq_year_df, str_day)
27
26
  else:
28
27
  k_line_info['week01'] = 0
29
28
  k_line_info['week02'] = 0
@@ -39,14 +38,50 @@ def handle_month_week_line(k_line_info, str_day, symbol, deal_days):
39
38
  k_line_info['month02'] = 0
40
39
  k_line_info['month01_date'] = '19890729'
41
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
42
45
 
43
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):
44
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]
45
79
 
46
80
  return k_line_info
47
81
 
82
+ # 处理月线
83
+
48
84
 
49
- # 处理月线
50
85
  def handle_month_line(k_line_info, str_day, symbol):
51
86
  now_year = int(str_day[0:4])
52
87
  last_year = str(now_year - 1)
@@ -54,7 +89,7 @@ def handle_month_line(k_line_info, str_day, symbol):
54
89
  now_month_begin_day = str_day[0:7] + '-01'
55
90
 
56
91
  last_year_begin_day = last_year + '-01-01'
57
- now_year_begin_day = str(now_year) + '-01-01'
92
+ # now_year_begin_day = str(now_year) + '-01-01'
58
93
 
59
94
  query = {"symbol": symbol,
60
95
  'date': {"$gte": date_handle_util.no_slash_date(last_year_begin_day)}}
@@ -67,11 +102,11 @@ def handle_month_line(k_line_info, str_day, symbol):
67
102
  stock_hfq_monthly_all = stock_hfq_monthly_all.loc[
68
103
  stock_hfq_monthly_all['date'] <= date_handle_util.no_slash_date(now_month_begin_day)]
69
104
 
70
- stock_hfq_monthly_last_year = stock_hfq_monthly_all.loc[
71
- stock_hfq_monthly_all['date'] < date_handle_util.no_slash_date(now_year_begin_day)]
72
-
73
- stock_hfq_monthly_now_year = stock_hfq_monthly_all.loc[
74
- stock_hfq_monthly_all['date'] > date_handle_util.no_slash_date(now_year_begin_day)]
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)]
75
110
 
76
111
  # 最近两个月k线
77
112
  before_two_month_stock_hfq_monthly = stock_hfq_monthly_all.iloc[0:2]
@@ -99,34 +134,34 @@ def handle_month_line(k_line_info, str_day, symbol):
99
134
  open_price = before_two_month_stock_hfq_monthly.iloc[1].last_price
100
135
  sum_chg = round((close_price - open_price) * 100 / open_price, 2)
101
136
  k_line_info['sum_month'] = sum_chg
102
-
103
- last_year_month_number = stock_hfq_monthly_last_year.shape[0]
104
- if last_year_month_number == 0:
105
- k_line_info['last_year_chg'] = 0
106
- elif last_year_month_number == 1:
107
- k_line_info['last_year_chg'] = stock_hfq_monthly_last_year.iloc[0].chg
108
- else:
109
- # chg_list = list(stock_hfq_monthly_last_year['chg'])
110
- # # 将列表中的每个元素加上1
111
- # updated_list = [round((x / 100) + 1, 2) for x in chg_list]
112
- #
113
- # # 使用 functools.reduce 将列表中的所有元素相乘
114
- # last_year_chg = functools.reduce(lambda x, y: x * y, updated_list)
115
- close_price = stock_hfq_monthly_last_year.iloc[0].close
116
- open_price = stock_hfq_monthly_last_year.iloc[last_year_month_number - 1].last_price
117
- last_year_chg = round((close_price - open_price) * 100 / open_price, 2)
118
- k_line_info['last_year_chg'] = last_year_chg
119
-
120
- now_year_month_number = stock_hfq_monthly_now_year.shape[0]
121
- if now_year_month_number == 0:
122
- k_line_info['now_year_chg'] = 0
123
- elif now_year_month_number == 1:
124
- k_line_info['now_year_chg'] = stock_hfq_monthly_now_year.iloc[0].chg
125
- else:
126
- close_price = stock_hfq_monthly_now_year.iloc[0].close
127
- open_price = stock_hfq_monthly_now_year.iloc[now_year_month_number - 1].last_price
128
- last_year_chg = round((close_price - open_price) * 100 / open_price, 2)
129
- k_line_info['now_year_chg'] = last_year_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
130
165
 
131
166
  return k_line_info
132
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') + 16
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,7 @@
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)
@@ -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)
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -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') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8