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
@@ -1,98 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 17
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.utils.date_handle_util as date_handle_util
9
- from datetime import datetime, time, timedelta
10
- from loguru import logger
11
- import mns_common.utils.data_frame_util as data_frame_util
12
- from mns_common.db.MongodbUtil import MongodbUtil
13
- import mns_common.api.ths.big_deal.ths_big_deal_api as ths_big_deal_api
14
- import time as sleep_time
15
- import mns_common.constant.db_name_constant as db_name_constant
16
-
17
- mongodb_util = MongodbUtil('27017')
18
-
19
-
20
- #
21
- def get_last_number(str_day):
22
- query = {'str_day': str_day}
23
- big_deal_df = mongodb_util.descend_query(query, db_name_constant.BIG_DEAL_NAME, "number", 1)
24
- if data_frame_util.is_empty(big_deal_df):
25
- return 1
26
- else:
27
- return list(big_deal_df['number'])[0]
28
-
29
-
30
- def create_index():
31
- mongodb_util.create_index(db_name_constant.BIG_DEAL_NAME, [("symbol", 1)])
32
- mongodb_util.create_index(db_name_constant.BIG_DEAL_NAME, [("str_day", 1)])
33
- mongodb_util.create_index(db_name_constant.BIG_DEAL_NAME, [("symbol", 1), ("str_day", 1)])
34
- mongodb_util.create_index(db_name_constant.BIG_DEAL_NAME, [("number", 1), ("str_day", 1)])
35
-
36
-
37
- def sync_ths_big_deal(tag):
38
- create_index()
39
- now_date_begin = datetime.now()
40
- str_day_begin = now_date_begin.strftime('%Y-%m-%d')
41
- number = get_last_number(str_day_begin)
42
- while True:
43
- now_date = datetime.now()
44
- begin_date = now_date + timedelta(minutes=-2)
45
- if tag or date_handle_util.is_trade_time(now_date):
46
- try:
47
- str_day = now_date.strftime('%Y-%m-%d')
48
- str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
49
-
50
- begin_str_date = begin_date.strftime('%Y-%m-%d %H:%M:%S')
51
-
52
- target_time_09_30 = time(9, 30)
53
- if now_date.time() < target_time_09_30:
54
- continue
55
- ths_big_deal_df = ths_big_deal_api.stock_fund_flow_big_deal(begin_str_date, str_now_date)
56
- if data_frame_util.is_empty(ths_big_deal_df):
57
- sleep_time.sleep(10)
58
- continue
59
- ths_big_deal_df['str_day'] = ths_big_deal_df['deal_time'].str.slice(0, 10)
60
- ths_big_deal_df = ths_big_deal_df.loc[ths_big_deal_df['str_day'] == str_day]
61
- ths_big_deal_df['number'] = number
62
- ths_big_deal_df['amount_str'] = ths_big_deal_df.amount.astype(str)
63
- ths_big_deal_df['type'] = ths_big_deal_df['type'].replace('买盘', 'buy')
64
- ths_big_deal_df['type'] = ths_big_deal_df['type'].replace("卖盘", "sell")
65
-
66
- ths_big_deal_df["_id"] = (ths_big_deal_df['deal_time'] + "-" + ths_big_deal_df['symbol'] + "-"
67
- + ths_big_deal_df['amount_str'] + "-" + ths_big_deal_df['type'])
68
- ths_big_deal_df.drop_duplicates('_id', keep='last', inplace=True)
69
- ths_big_deal_df['sync_str_date'] = str_now_date
70
- # 设置卖盘为负数
71
- ths_big_deal_df.loc[ths_big_deal_df['type'] == 'sell', 'amount'] = -ths_big_deal_df.loc[
72
- ths_big_deal_df['type'] == 'sell', 'amount']
73
-
74
- ths_big_deal_df['chg'] = ths_big_deal_df['chg'].str.replace('%', '')
75
- ths_big_deal_df['chg'] = ths_big_deal_df['chg'].astype(float)
76
-
77
- del ths_big_deal_df['amount_str']
78
- exist_code_df = mongodb_util.find_query_data_choose_field(db_name_constant.BIG_DEAL_NAME,
79
- {},
80
- {"_id": 1})
81
- if data_frame_util.is_empty(exist_code_df):
82
- new_df = ths_big_deal_df
83
- else:
84
- exist_code_list = list(exist_code_df['_id'])
85
- new_df = ths_big_deal_df.loc[~(ths_big_deal_df['_id'].isin(exist_code_list))]
86
-
87
- if data_frame_util.is_empty(new_df):
88
- continue
89
- mongodb_util.insert_mongo(new_df, db_name_constant.BIG_DEAL_NAME)
90
- number = number + 1
91
- except Exception as e:
92
- logger.error('策略执行异常:{}', e)
93
- elif date_handle_util.is_close_time(now_date):
94
- break
95
-
96
-
97
- if __name__ == '__main__':
98
- sync_ths_big_deal(False)
@@ -1,127 +0,0 @@
1
- import os
2
- import sys
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.constant.db_name_constant as db_name_constant
9
- import mns_common.component.common_service_fun_api as common_service_fun_api
10
- import mns_common.component.cache.cache_service as cache_service
11
- import mns_common.utils.cmd_util as cmd_util
12
- import mns_common.utils.data_frame_util as data_frame_util
13
- from loguru import logger
14
- from datetime import datetime
15
- import mns_common.utils.date_handle_util as date_handle_util
16
- from mns_common.db.MongodbUtil import MongodbUtil
17
- import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
18
- import time
19
-
20
- mongodb_util = MongodbUtil('27017')
21
-
22
- MAX_NUMBER_KEY = 'max_number_key'
23
- # 定时任务 python名称
24
- REAL_TIME_SCHEDULER_NAME = "sync_realtime_quotes_task"
25
- # 实时同步 python名称
26
- REAL_TIME_TASK_NAME = "realtime_quotes_now_sync"
27
- # 实时同步 bat
28
- REAL_TIME_TASK_NAME_PATH = 'H:\\real_time_task.bat'
29
- # 定时任务 bat
30
- REAL_TIME_SCHEDULER_NAME_PATH = 'H:\\real_time_scheduler.bat'
31
-
32
-
33
- def get_real_time_max_number():
34
- number = common_service_fun_api.realtime_quotes_now_max_number(db_name_constant.REAL_TIME_QUOTES_NOW,
35
- 'number')
36
-
37
- return number
38
-
39
-
40
- # 检查数据同步最大值
41
- def check_max_number():
42
- now_max_number = get_real_time_max_number()
43
- last_minute_number = cache_service.get_cache(MAX_NUMBER_KEY)
44
- cache_service.set_cache(MAX_NUMBER_KEY, now_max_number)
45
- if last_minute_number is None:
46
- return True
47
- elif now_max_number == last_minute_number:
48
- logger.error("数据相等:{}", now_max_number)
49
- return False
50
- else:
51
- return True
52
-
53
-
54
- # 实时行情数据同步状态check
55
- def run_check_real_time_data_sync_status():
56
- now_date = datetime.now()
57
- hour = now_date.hour
58
- minute = now_date.minute
59
- second = now_date.second
60
- str_day = now_date.strftime('%Y-%m-%d')
61
-
62
- if bool(1 - trade_date_common_service_api.is_trade_day(str_day)):
63
- return False
64
-
65
- # 关闭上午定时同步
66
- if hour == 11 and minute == 31:
67
- all_cmd_processes = cmd_util.get_all_process()
68
- if data_frame_util.is_empty(all_cmd_processes):
69
- return False
70
- all_cmd_processes_real_time_task = get_real_time_quotes_task(all_cmd_processes)
71
- if data_frame_util.is_empty(all_cmd_processes_real_time_task):
72
- return False
73
- for match_task_one in all_cmd_processes_real_time_task.itertuples():
74
- try:
75
- processes_pid = match_task_one.process_pid
76
- # 关闭当前进程
77
- cmd_util.kill_process_by_pid(processes_pid)
78
- except BaseException as e:
79
- logger.error("关闭实时行情任务异常:{}", e)
80
-
81
- # 重开下午定时同步
82
- if hour == 12 and minute == 59:
83
- all_cmd_processes = cmd_util.get_all_process()
84
- if data_frame_util.is_empty(all_cmd_processes):
85
- return False
86
- all_cmd_processes_real_time_task = get_real_time_quotes_task(all_cmd_processes)
87
- if data_frame_util.is_empty(all_cmd_processes_real_time_task):
88
- # 重开定时任务
89
- cmd_util.open_bat_file(REAL_TIME_SCHEDULER_NAME_PATH)
90
- # 防止太快重开多个
91
- time.sleep(3)
92
-
93
- # 普通轮训
94
-
95
- if bool(1 - date_handle_util.is_trade_time(now_date)):
96
- return False
97
- flag = check_max_number()
98
- if bool(1 - flag):
99
- all_cmd_processes = cmd_util.get_all_process()
100
- if data_frame_util.is_empty(all_cmd_processes):
101
- return False
102
- all_cmd_processes_real_time_task = get_real_time_quotes_task(all_cmd_processes)
103
- if data_frame_util.is_empty(all_cmd_processes_real_time_task):
104
- return None
105
- for match_task_one in all_cmd_processes_real_time_task.itertuples():
106
- try:
107
- processes_pid = match_task_one.process_pid
108
- # 关闭当前进程
109
- cmd_util.kill_process_by_pid(processes_pid)
110
- # 清空临时数据表
111
- mongodb_util.remove_all_data(db_name_constant.REAL_TIME_QUOTES_NOW)
112
-
113
- except BaseException as e:
114
- logger.error("关闭实时行情任务异常:{}", e)
115
- # 重开任务进程
116
- cmd_util.open_bat_file(REAL_TIME_TASK_NAME_PATH)
117
-
118
-
119
- def get_real_time_quotes_task(all_cmd_processes):
120
- return all_cmd_processes[
121
- (all_cmd_processes['total_info'].str.contains(REAL_TIME_SCHEDULER_NAME, case=False, na=False))
122
- | (all_cmd_processes['total_info'].str.contains(REAL_TIME_TASK_NAME, case=False, na=False))]
123
-
124
-
125
- if __name__ == '__main__':
126
- while True:
127
- run_check_real_time_data_sync_status()
@@ -1,33 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.api.em.east_money_debt_api as east_money_debt_api
9
- from datetime import datetime
10
- import mns_common.constant.db_name_constant as db_name_constant
11
- from mns_common.db.MongodbUtil import MongodbUtil
12
-
13
- mongodb_util = MongodbUtil('27017')
14
-
15
-
16
- # 同步可转债信息
17
- def sync_debt_info():
18
- now_date = datetime.now()
19
- str_now_day = now_date.strftime('%Y-%m-%d')
20
- kzz_bond_info_df = east_money_debt_api.get_kzz_bond_info()
21
- kzz_bond_info_df = kzz_bond_info_df.fillna(0)
22
- kzz_bond_info_df['apply_date'] = kzz_bond_info_df['apply_date'].astype(str)
23
- kzz_bond_info_df['winning_date'] = kzz_bond_info_df['winning_date'].astype(str)
24
- kzz_bond_info_df['list_date'] = kzz_bond_info_df['list_date'].astype(str)
25
- kzz_bond_info_df['due_date'] = kzz_bond_info_df['due_date'].astype(str)
26
- kzz_bond_info_df = kzz_bond_info_df.loc[kzz_bond_info_df['due_date'] >= str_now_day]
27
- mongodb_util.remove_all_data(db_name_constant.KZZ_DEBT_INFO)
28
- kzz_bond_info_df['_id'] = kzz_bond_info_df['symbol']
29
- mongodb_util.insert_mongo(kzz_bond_info_df, db_name_constant.KZZ_DEBT_INFO)
30
-
31
-
32
- if __name__ == '__main__':
33
- sync_debt_info()
@@ -1,131 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- from bypy import ByPy
9
- from mns_common.db.MongodbUtil import MongodbUtil
10
- import tempfile
11
- from loguru import logger
12
- import akshare as ak
13
-
14
- mongodb_util = MongodbUtil('27017')
15
-
16
- import subprocess
17
-
18
-
19
- def get_file_list(path):
20
- """
21
- 获取百度网盘指定路径下的文件列表
22
- :param path: 百度网盘中的路径,例如 '/我的资源'
23
- :return: 文件列表
24
- """
25
- try:
26
- # 调用 bypy list 命令
27
- result = subprocess.run(['bypy', 'list', path], capture_output=True, text=True, check=True)
28
-
29
- # 输出结果
30
- if result.returncode == 0:
31
- file_list = result.stdout.splitlines() # 按行分割结果
32
- return file_list
33
- else:
34
- logger.error("获取文件路径异常:{}", result.stderr)
35
- return []
36
- except subprocess.CalledProcessError as e:
37
- logger.error("获取文件路径异常:{}", e)
38
- return []
39
-
40
-
41
- def upload_to_baidu(file_name, folder_name, data_df):
42
- bp = ByPy()
43
- file_name = file_name + '.csv'
44
- with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as temp_file:
45
- data_df.to_csv(temp_file, index=False)
46
- temp_file_path = temp_file.name # 获取临时文件的路径
47
-
48
- # 上传临时文件到百度云
49
- remote_path = f'/{folder_name}/{file_name}'
50
- result = bp.upload(temp_file_path, remote_path)
51
- if result == 0:
52
- logger.info("上传成功:{}", file_name)
53
- else:
54
- logger.error("上传失败:{}", file_name)
55
- return result
56
-
57
-
58
- def mkdir_baidu_new_folder(remote_path):
59
- bp = ByPy()
60
- try:
61
- # 调用 mkdir 方法创建文件夹
62
- result = bp.mkdir(remote_path)
63
-
64
- if result == 0:
65
- logger.info("成功创建文件夹:{}", remote_path)
66
- else:
67
- logger.error("创建文件夹失败:{}", result)
68
-
69
- except Exception as e:
70
- logger.error("创建文件夹失败:{}", e)
71
-
72
-
73
- def del_baidu_old_folder(remote_path):
74
- bp = ByPy()
75
- try:
76
- # 调用 mkdir 方法创建文件夹
77
- result = bp.delete(remote_path)
78
-
79
- if result == 0:
80
- logger.info("成功删除文件夹:{}", remote_path)
81
- else:
82
- logger.error("删除文件夹失败:{}", result)
83
-
84
- except Exception as e:
85
- logger.error("删除文件夹失败:{}", e)
86
-
87
-
88
- if __name__ == '__main__':
89
- folder_name1 = '/美股/不复权日线'
90
- mkdir_baidu_new_folder(folder_name1)
91
- # get_file_list(folder_name1)
92
- stock_us_spot_em_df = ak.stock_us_spot_em()
93
- stock_us_spot_em_df = stock_us_spot_em_df.rename(columns={
94
- "序号": "index",
95
- "代码": "symbol",
96
- "名称": "name",
97
- "涨跌额": "change_price",
98
- "涨跌幅": "chg",
99
- "开盘价": "open",
100
- "最高价": "high",
101
- "最低价": "low",
102
- "最新价": "now_price",
103
- "昨收价": "last_price",
104
- "总市值": "total_mv",
105
- "市盈率": "pe",
106
- "成交量": "volume",
107
- "成交额": "amount",
108
- "振幅": "pct_chg",
109
- "换手率": "exchange"
110
- })
111
- stock_us_spot_em_df = stock_us_spot_em_df.sort_values(by=['amount'], ascending=False)
112
- stock_us_spot_em_df = stock_us_spot_em_df.fillna(0)
113
- stock_us_spot_em_df = stock_us_spot_em_df.loc[stock_us_spot_em_df['total_mv'] != 0]
114
- for stock_one in stock_us_spot_em_df.itertuples():
115
- try:
116
- symbol = stock_one.symbol
117
- name = stock_one.name
118
- query = {'symbol': symbol, 'amount': {"$gt": 0}}
119
- us_stock_bfq_daily_df_one = mongodb_util.find_query_data('us_stock_bfq_daily', query)
120
- del us_stock_bfq_daily_df_one['_id']
121
- del us_stock_bfq_daily_df_one['name']
122
- file_name_one = name + '_' + symbol
123
- upload_to_baidu(file_name_one, folder_name1, us_stock_bfq_daily_df_one)
124
-
125
- except BaseException as e:
126
- logger.error("同步数据发生异常:{}", e)
127
-
128
- # data_df = mongodb_util.find_query_data('us_stock_bfq_daily', query={'name': file_name1})
129
- # upload_to_baidu(file_name1, folder_name1, data_df)
130
-
131
-
@@ -1,91 +0,0 @@
1
- import akshare as ak
2
- import pandas as pd
3
- from mns_common.db.MongodbUtil import MongodbUtil
4
-
5
- mongodb_util = MongodbUtil('27017')
6
-
7
-
8
- def us_stock():
9
- # 输入参数
10
- symbol = input("请输入股票代码(all:全量(时间很长),特定代码:106.TTE):")
11
- start_date = input("请输入开始日期(格式:YYYYMMDD):")
12
- end_date = input("请输入结束日期(格式:YYYYMMDD):")
13
- fq = input("请输入复权信息(前复权:qfq,不复权:bfq,后复权:hfq):")
14
- k_line_period = input("请输入k线周期(日线:daily,周线:weekly,月线:monthly):")
15
- db_name = "us_stock_" + fq + "_" + k_line_period
16
- if fq == 'bfq':
17
- fq = ''
18
- if symbol != 'all':
19
- # 获取股票历史数据
20
- stock_us_hist_df = ak.stock_us_hist(symbol=symbol,
21
- period=k_line_period,
22
- start_date=start_date,
23
- end_date=end_date,
24
- adjust=fq)
25
- # 保存数据到 CSV 文件
26
- stock_us_hist_df.to_csv(f"{symbol}_historical_data.csv", index=False)
27
- print(f"数据已保存到 {symbol}_historical_data.csv")
28
- else:
29
- stock_us_spot_em_df = ak.stock_us_spot_em()
30
- stock_us_spot_em_df = stock_us_spot_em_df.rename(columns={
31
- "序号": "index",
32
- "代码": "symbol",
33
- "名称": "name",
34
- "涨跌额": "change_price",
35
- "涨跌幅": "chg",
36
- "开盘价": "open",
37
- "最高价": "high",
38
- "最低价": "low",
39
- "最新价": "now_price",
40
- "昨收价": "last_price",
41
- "总市值": "total_mv",
42
- "市盈率": "pe",
43
- "成交量": "volume",
44
- "成交额": "amount",
45
- "振幅": "pct_chg",
46
- "换手率": "exchange"
47
- })
48
- stock_us_spot_em_df = stock_us_spot_em_df.sort_values(by=['amount'], ascending=False)
49
- stock_us_spot_em_df = stock_us_spot_em_df.fillna(0)
50
- stock_us_spot_em_df = stock_us_spot_em_df.loc[stock_us_spot_em_df['total_mv'] != 0]
51
-
52
- k_line_result = pd.DataFrame()
53
-
54
- for stock_us_one in stock_us_spot_em_df.itertuples():
55
- try:
56
- # 获取股票历史数据
57
- stock_us_hist_df = ak.stock_us_hist(symbol=stock_us_one.symbol,
58
- period=k_line_period,
59
- start_date=start_date,
60
- end_date=end_date,
61
- adjust=fq)
62
- stock_us_hist_df = stock_us_hist_df.rename(columns={
63
- "日期": "date",
64
- "涨跌额": "change_price",
65
- "涨跌幅": "chg",
66
- "开盘": "open",
67
- "最高": "high",
68
- "最低": "low",
69
- "收盘": "close",
70
- "成交量": "volume",
71
- "成交额": "amount",
72
- "振幅": "pct_chg",
73
- "换手率": "exchange"
74
- })
75
-
76
- k_line_result = pd.concat([stock_us_hist_df, k_line_result])
77
- stock_us_hist_df['_id'] = stock_us_one.symbol + '_' + stock_us_hist_df['date']
78
- stock_us_hist_df['symbol'] = stock_us_one.symbol
79
- stock_us_hist_df['name'] = stock_us_one.name
80
- mongodb_util.insert_mongo(stock_us_hist_df, db_name)
81
- print(f"同步k线数据到: {stock_us_one.name}")
82
- except BaseException as e:
83
- print(f"同步数据发生异常: {stock_us_one.name}, {e}")
84
-
85
- # 保存数据到 CSV 文件
86
- k_line_result.to_csv(f"{symbol}_historical_data.csv", index=False)
87
- print(f"数据已保存到 {symbol}_historical_data.csv")
88
-
89
-
90
- if __name__ == "__main__":
91
- us_stock()
@@ -1,39 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import akshare as ak
9
-
10
-
11
- def sync_us_company_info():
12
- stock_us_spot_em_df = ak.stock_us_spot_em()
13
- stock_us_spot_em_df = stock_us_spot_em_df.rename(columns={
14
- "序号": "index",
15
- "代码": "symbol",
16
- "名称": "name",
17
- "涨跌额": "change_price",
18
- "涨跌幅": "chg",
19
- "开盘价": "open",
20
- "最高价": "high",
21
- "最低价": "low",
22
- "最新价": "now_price",
23
- "昨收价": "last_price",
24
- "总市值": "total_mv",
25
- "市盈率": "pe",
26
- "成交量": "volume",
27
- "成交额": "amount",
28
- "振幅": "pct_chg",
29
- "换手率": "exchange"
30
- })
31
- stock_us_spot_em_df = stock_us_spot_em_df.sort_values(by=['amount'], ascending=False)
32
- stock_us_spot_em_df = stock_us_spot_em_df.fillna(0)
33
- stock_us_spot_em_df = stock_us_spot_em_df.loc[stock_us_spot_em_df['total_mv']!=0]
34
- stock_us_spot_em_df.to_csv('us_stock.csv', index=False)
35
- return stock_us_spot_em_df
36
-
37
-
38
- if __name__ == '__main__':
39
- sync_us_company_info()