mns-scheduler 1.1.8.4__py3-none-any.whl → 1.4.5.7__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.
Files changed (139) hide show
  1. mns_scheduler/__init__.py +1 -3
  2. mns_scheduler/auto_da_ban/auto_da_ban_service.py +89 -0
  3. mns_scheduler/company_info/clean/__init__.py +1 -1
  4. mns_scheduler/company_info/clean/company_info_clean_api.py +62 -21
  5. mns_scheduler/company_info/common/company_common_query_service.py +45 -0
  6. mns_scheduler/company_info/constant/__init__.py +1 -1
  7. mns_scheduler/company_info/constant/company_constant_data.py +335 -224
  8. mns_scheduler/company_info/de_list_stock/__init__.py +1 -1
  9. mns_scheduler/company_info/de_list_stock/de_list_stock_service.py +1 -1
  10. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +134 -0
  11. mns_scheduler/company_info/sync/company_info_set_service.py +208 -0
  12. mns_scheduler/company_info/sync/sync_company_info_task.py +203 -0
  13. mns_scheduler/company_info/task/company_announce_info_task.py +77 -0
  14. mns_scheduler/company_info/task/company_base_info_task.py +64 -0
  15. mns_scheduler/company_info/task/company_business_info_task.py +177 -0
  16. mns_scheduler/company_info/task/company_hold_info_task.py +66 -0
  17. mns_scheduler/company_info/task/company_industry_info_task.py +167 -0
  18. mns_scheduler/company_info/task/company_total_task.py +69 -0
  19. mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
  20. mns_scheduler/concept/clean/ths_concept_clean_api.py +20 -4
  21. mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +23 -18
  22. mns_scheduler/concept/ths/common/ths_concept_update_common_api.py +4 -1
  23. mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +7 -7
  24. mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_new_index_api.py +9 -4
  25. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +2 -2
  26. mns_scheduler/db/col_move_service.py +3 -3
  27. mns_scheduler/db/script/__init__.py +1 -1
  28. mns_scheduler/db/script/col_move_script.py +1 -1
  29. mns_scheduler/db/script/db_move/__init__.py +7 -0
  30. mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
  31. mns_scheduler/db/script/sync/__init__.py +1 -1
  32. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +65 -4
  33. mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +80 -0
  34. mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
  35. mns_scheduler/db/script/update/__init__.py +7 -0
  36. mns_scheduler/db/script/update/update_col_field.py +36 -0
  37. mns_scheduler/finance/__init__.py +1 -1
  38. mns_scheduler/finance/em/__init__.py +7 -0
  39. mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +2 -2
  40. mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +27 -26
  41. mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +3 -3
  42. mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py} +80 -27
  43. mns_scheduler/finance/xue_qiu/__init__.py +7 -0
  44. mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
  45. mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
  46. mns_scheduler/hk/__init__.py +1 -1
  47. mns_scheduler/hk/hk_company_info_sync_service_api.py +4 -4
  48. mns_scheduler/hk/hk_industry_info_sync_service_api.py +3 -5
  49. mns_scheduler/industry/__init__.py +7 -0
  50. mns_scheduler/industry/ths/__init__.py +7 -0
  51. mns_scheduler/industry/ths/ths_industry_index_service.py +58 -0
  52. mns_scheduler/industry/ths/ths_industry_sync_service.py +68 -0
  53. mns_scheduler/irm/__init__.py +1 -1
  54. mns_scheduler/irm/api/__init__.py +1 -1
  55. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +8 -58
  56. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +15 -26
  57. mns_scheduler/irm/stock_irm_cninfo_service.py +43 -31
  58. mns_scheduler/irm/stock_question_id_service.py +169 -0
  59. mns_scheduler/k_line/clean/daily/__init__.py +1 -1
  60. mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +52 -6
  61. mns_scheduler/k_line/clean/daily/daily_k_line_service.py +7 -2
  62. mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
  63. mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -15
  64. mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
  65. mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +124 -26
  66. mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +2 -2
  67. mns_scheduler/k_line/common/__init__.py +7 -0
  68. mns_scheduler/k_line/common/k_line_common_api.py +188 -0
  69. mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
  70. mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
  71. mns_scheduler/k_line/{sync → month_week_daily}/bfq_k_line_sync.py +14 -29
  72. mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +11 -12
  73. mns_scheduler/k_line/sync_status/__init__.py +7 -0
  74. mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
  75. mns_scheduler/k_line/test/__init__.py +1 -1
  76. mns_scheduler/k_line/test/k_line_info_clean_his_data.py +14 -3
  77. mns_scheduler/k_line/year_quarter/__init__.py +7 -0
  78. mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
  79. mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +1 -2
  80. mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
  81. mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +5 -0
  82. mns_scheduler/lhb/__init__.py +1 -1
  83. mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
  84. mns_scheduler/open/__init__.py +1 -1
  85. mns_scheduler/open/sync_one_day_open_data_to_db_service.py +2 -3
  86. mns_scheduler/risk/__init__.py +1 -1
  87. mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +8 -2
  88. mns_scheduler/risk/financial/annual_report_audit_check_api.py +13 -3
  89. mns_scheduler/risk/financial/net_assets_check_api.py +21 -18
  90. mns_scheduler/risk/financial/profit_income_check_api.py +7 -2
  91. mns_scheduler/risk/financial_report_risk_check_api.py +1 -1
  92. mns_scheduler/risk/major_violations/register_and_investigate_stock_sync_api.py +1 -1
  93. mns_scheduler/risk/self/wei_pan_stock_api.py +1 -1
  94. mns_scheduler/risk/test/__init__.py +1 -1
  95. mns_scheduler/risk/test/fix_blask_list.py +4 -6
  96. mns_scheduler/risk/transactions/transactions_check_api.py +22 -4
  97. mns_scheduler/self_choose/__init__.py +1 -1
  98. mns_scheduler/self_choose/ths_self_choose_service.py +99 -43
  99. mns_scheduler/trade/auto_login/trader_auto_service.py +7 -4
  100. mns_scheduler/trade/auto_sell_service_api.py +4 -4
  101. mns_scheduler/trade/balance/__init__.py +7 -0
  102. mns_scheduler/trade/balance/ths_account_balance_service.py +7 -0
  103. mns_scheduler/trade/sync_position_api.py +39 -6
  104. mns_scheduler/trade/task/trader_task_service.py +38 -10
  105. mns_scheduler/trade/tfp/__init__.py +7 -0
  106. mns_scheduler/trade/tfp/stock_tfp_info_sync.py +56 -0
  107. mns_scheduler/zb/stock_zb_pool_sync.py +1 -16
  108. mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -2
  109. mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +1 -1
  110. mns_scheduler/zt/script/__init__.py +1 -1
  111. mns_scheduler/zt/script/fix_error_deal_day.py +41 -0
  112. mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -2
  113. mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
  114. mns_scheduler/zt/script/sync_now_higt_chg_zt.py +8 -7
  115. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +260 -83
  116. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +33 -90
  117. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +27 -13
  118. mns_scheduler/zz_task/compensation/__init__.py +0 -0
  119. mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
  120. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
  121. mns_scheduler/zz_task/data_sync_task.py +197 -103
  122. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.dist-info}/METADATA +1 -1
  123. mns_scheduler-1.4.5.7.dist-info/RECORD +176 -0
  124. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.dist-info}/WHEEL +1 -1
  125. mns_scheduler/2014-2015-test/2014_2015_chg_statistics.py +0 -87
  126. mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
  127. mns_scheduler/company_info/base/sync_company_base_info_api.py +0 -439
  128. mns_scheduler/company_info/base/sync_company_hold_info_api.py +0 -40
  129. mns_scheduler/company_info/remark/company_remark_info_sync.py +0 -46
  130. mns_scheduler/db/real_time_task_check.py +0 -84
  131. mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
  132. mns_scheduler-1.1.8.4.dist-info/RECORD +0 -142
  133. /mns_scheduler/{2014-2015-test → auto_da_ban}/__init__.py +0 -0
  134. /mns_scheduler/company_info/{base → common}/__init__.py +0 -0
  135. /mns_scheduler/{big_deal → company_info/em_stock_info}/__init__.py +0 -0
  136. /mns_scheduler/company_info/{remark → sync}/__init__.py +0 -0
  137. /mns_scheduler/{debt → company_info/task}/__init__.py +0 -0
  138. /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
  139. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.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
  import pandas as pd
@@ -85,6 +85,12 @@ def init_day_line_data(k_line_info, stock_qfq_daily):
85
85
  k_line_info.loc[:, 'avg_thirty_last'] = 0
86
86
  k_line_info.loc[:, 'avg_sixty_last'] = 0
87
87
 
88
+ k_line_info.loc[:, 'slope_five_last'] = 0
89
+ k_line_info.loc[:, 'slope_ten_last'] = 0
90
+ k_line_info.loc[:, 'slope_twenty_last'] = 0
91
+ k_line_info.loc[:, 'slope_thirty_last'] = 0
92
+ k_line_info.loc[:, 'slope_sixty_last'] = 0
93
+
88
94
  k_line_info.loc[:, 'std_amount_ten'] = 0
89
95
  k_line_info.loc[:, 'mean_amount_ten'] = 0
90
96
  k_line_info.loc[:, 'std_amount_thirty'] = 0
@@ -200,24 +206,31 @@ def calculate_exchange_and_k_line_avg_param(stock_qfq_daily):
200
206
 
201
207
  # 收盘价格与均线差值
202
208
  stock_qfq_daily['close_difference_five'] = round(
203
- 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_five']) / stock_qfq_daily['close'],
209
+ 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_five']) / stock_qfq_daily['avg_five'],
204
210
  2)
205
211
 
206
212
  stock_qfq_daily['close_difference_ten'] = round(
207
- 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_ten']) / stock_qfq_daily['close'],
213
+ 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_ten']) / stock_qfq_daily['avg_ten'],
208
214
  2)
209
215
 
210
216
  stock_qfq_daily['close_difference_twenty'] = round(
211
- 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_twenty']) / stock_qfq_daily['close'],
217
+ 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_twenty']) / stock_qfq_daily['avg_twenty'],
212
218
  2)
213
219
 
214
220
  stock_qfq_daily['close_difference_thirty'] = round(
215
- 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_thirty']) / stock_qfq_daily['close'],
221
+ 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_thirty']) / stock_qfq_daily['avg_thirty'],
216
222
  2)
217
223
 
218
224
  stock_qfq_daily['close_difference_sixty'] = round(
219
- 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_sixty']) / stock_qfq_daily['close'],
225
+ 100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_sixty']) / stock_qfq_daily['avg_sixty'],
220
226
  2)
227
+ if (('slope_' + 'five' not in stock_qfq_daily.columns)
228
+ or ('slope_' + 'ten' not in stock_qfq_daily.columns) \
229
+ or ('slope_' + 'twenty' not in stock_qfq_daily.columns) \
230
+ or ('slope_' + 'thirty' not in stock_qfq_daily.columns) \
231
+ or ('slope_' + 'sixty' not in stock_qfq_daily.columns)):
232
+ # 计算均线斜率
233
+ stock_qfq_daily = calculate_slope(stock_qfq_daily, windows=['five', 'ten', 'twenty', 'thirty', 'sixty'])
221
234
 
222
235
  stock_qfq_daily = stock_qfq_daily[[
223
236
  "symbol",
@@ -255,6 +268,11 @@ def calculate_exchange_and_k_line_avg_param(stock_qfq_daily):
255
268
  "avg_twenty",
256
269
  'avg_thirty',
257
270
  'avg_sixty',
271
+ "slope_five",
272
+ "slope_ten",
273
+ "slope_twenty",
274
+ 'slope_thirty',
275
+ 'slope_sixty',
258
276
  "classification",
259
277
  "_id",
260
278
  "date"
@@ -265,6 +283,34 @@ def calculate_exchange_and_k_line_avg_param(stock_qfq_daily):
265
283
  return stock_qfq_daily
266
284
 
267
285
 
286
+ def fix_avg_slope_name(k_line_info, stock_qfq_daily):
287
+ stock_qfq_daily_one = stock_qfq_daily.iloc[0:1]
288
+ k_line_info['slope_five_last'] = stock_qfq_daily_one['slope_five']
289
+ k_line_info['slope_ten_last'] = stock_qfq_daily_one['slope_ten']
290
+ k_line_info['slope_twenty_last'] = stock_qfq_daily_one['slope_twenty']
291
+ k_line_info['slope_thirty_last'] = stock_qfq_daily_one['slope_thirty']
292
+ k_line_info['slope_sixty_last'] = stock_qfq_daily_one['slope_sixty']
293
+ return k_line_info
294
+
295
+
296
+ # 计算均线
297
+ def calculate_moving_averages(data, windows=['five', 'ten', 'twenty', 'thirty', 'sixty']):
298
+ for window in windows:
299
+ data[f'avg_{window}', window] = data['close'].rolling(window=window).mean()
300
+ return data
301
+
302
+
303
+ # 计算均线斜率
304
+ def calculate_slope(data, windows=['five', 'ten', 'twenty', 'thirty', 'sixty']):
305
+ for window in windows:
306
+ if 'slope_' + window in data.columns:
307
+ continue
308
+ data[f'slope_{window}'] = data[f'avg_{window}'].diff() / data[f'avg_{window}'].shift(1)
309
+ data[f'slope_{window}'] = data[f'slope_{window}'] * 100
310
+ data[f'slope_{window}'] = round(data[f'slope_{window}'], 2)
311
+ return data
312
+
313
+
268
314
  # 设置当天k线形态 下一个交易日判断当前交易日k线形态
269
315
  def set_k_line_patterns(stock_qfq_daily_one):
270
316
  open = list(stock_qfq_daily_one['open'])[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
  from mns_common.db.MongodbUtil import MongodbUtil
@@ -71,6 +71,9 @@ def handle_day_line_sub_new(k_line_info, str_day, symbol, deal_days):
71
71
  # 排除最近有三板以上的股票 todo
72
72
  # 计算最近热门大涨的股票
73
73
  recent_hot_stocks_clean_service.calculate_recent_hot_stocks(stock_qfq_daily, symbol, str_day)
74
+ # 修改 avg name
75
+ k_line_info = daily_k_line_clean_common_service.fix_avg_slope_name(k_line_info, stock_qfq_daily)
76
+
74
77
  return k_line_info
75
78
 
76
79
 
@@ -107,9 +110,11 @@ def handle_day_line_normal(k_line_info, str_day, symbol, deal_days):
107
110
  # 排除最近有三板以上的股票 todo
108
111
  # 计算最近热门大涨的股票
109
112
  recent_hot_stocks_clean_service.calculate_recent_hot_stocks(stock_qfq_daily, symbol, str_day)
110
-
113
+ # 修改 avg name
114
+ k_line_info = daily_k_line_clean_common_service.fix_avg_slope_name(k_line_info, stock_qfq_daily)
111
115
  return k_line_info
112
116
 
117
+
113
118
  # if __name__ == '__main__':
114
119
  # query1 = {"symbol": '301596', 'date': {"$lte": date_handle_util.no_slash_date('2024-05-31')}}
115
120
  # stock_qfq_daily_301596 = mongodb_util.descend_query(query1, 'stock_qfq_daily', 'date', 15)
@@ -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,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') + 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
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
- month_begin_day = str_day[0:7] + '-01'
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': {"$lt": date_handle_util.no_slash_date(month_begin_day)}}
44
- stock_hfq_monthly = mongodb_util.descend_query(query, 'stock_qfq_monthly', 'date', 2)
45
- month_num = stock_hfq_monthly.shape[0]
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
- if month_num == 0:
53
- k_line_info['month01'] = 0
54
- k_line_info['month02'] = 0
55
- k_line_info['month01_date'] = '19890729'
56
- k_line_info['month02_date'] = '19890729'
57
- elif month_num == 1:
58
- k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
59
- k_line_info['month02'] = 0
60
- k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
61
- k_line_info['month02_date'] = '19890729'
62
- elif month_num == 2:
63
- k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
64
- k_line_info['month02'] = stock_hfq_monthly.iloc[1].chg
65
- k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
66
- k_line_info['month02_date'] = stock_hfq_monthly.iloc[1].date
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') + 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)