mns-scheduler 1.4.3.5__py3-none-any.whl → 1.4.6.4__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 (46) hide show
  1. mns_scheduler/{company_info/announce → auto_da_ban}/__init__.py +1 -1
  2. mns_scheduler/auto_da_ban/auto_da_ban_service.py +89 -0
  3. mns_scheduler/company_info/clean/company_info_clean_api.py +37 -16
  4. mns_scheduler/company_info/{base → common}/__init__.py +1 -1
  5. mns_scheduler/company_info/common/company_common_query_service.py +45 -0
  6. mns_scheduler/company_info/constant/company_constant_data.py +59 -49
  7. mns_scheduler/company_info/em_stock_info/clean_em_us_hk_stock_info.py +30 -0
  8. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +100 -39
  9. mns_scheduler/company_info/{remark → sync}/__init__.py +1 -1
  10. mns_scheduler/company_info/sync/company_info_set_service.py +208 -0
  11. mns_scheduler/company_info/sync/sync_company_info_task.py +203 -0
  12. mns_scheduler/company_info/task/__init__.py +7 -0
  13. mns_scheduler/company_info/{announce/company_announce_sync_service.py → task/company_announce_info_task.py} +25 -13
  14. mns_scheduler/company_info/task/company_base_info_task.py +64 -0
  15. mns_scheduler/company_info/{base/sync_company_product_area_industry.py → task/company_business_info_task.py} +33 -17
  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/ths/common/ths_concept_sync_common_api.py +3 -3
  20. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +1 -1
  21. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +11 -3
  22. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +7 -57
  23. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +14 -25
  24. mns_scheduler/irm/stock_irm_cninfo_service.py +34 -26
  25. mns_scheduler/irm/stock_question_id_service.py +169 -0
  26. mns_scheduler/k_line/clean/k_line_info_clean_task.py +1 -0
  27. mns_scheduler/kpl/theme/__init__.py +7 -0
  28. mns_scheduler/kpl/theme/kpl_theme_sync_service.py +231 -0
  29. mns_scheduler/self_choose/ths_self_choose_service.py +53 -25
  30. mns_scheduler/trade/auto_login/trader_auto_service.py +2 -1
  31. mns_scheduler/trade/task/trader_task_service.py +13 -2
  32. mns_scheduler/trade/tfp/stock_tfp_info_sync.py +1 -1
  33. mns_scheduler/zb/stock_zb_pool_sync.py +1 -1
  34. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +45 -130
  35. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +1 -1
  36. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +49 -31
  37. mns_scheduler/zz_task/compensation/compensate_task.py +1 -1
  38. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +6 -6
  39. mns_scheduler/zz_task/data_sync_task.py +58 -37
  40. {mns_scheduler-1.4.3.5.dist-info → mns_scheduler-1.4.6.4.dist-info}/METADATA +1 -1
  41. {mns_scheduler-1.4.3.5.dist-info → mns_scheduler-1.4.6.4.dist-info}/RECORD +43 -33
  42. mns_scheduler/company_info/base/sync_company_base_info_api.py +0 -531
  43. mns_scheduler/company_info/base/sync_company_hold_info_api.py +0 -37
  44. mns_scheduler/company_info/remark/company_remark_info_sync.py +0 -46
  45. {mns_scheduler-1.4.3.5.dist-info → mns_scheduler-1.4.6.4.dist-info}/WHEEL +0 -0
  46. {mns_scheduler-1.4.3.5.dist-info → mns_scheduler-1.4.6.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,169 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
8
+
9
+ """
10
+ """
11
+
12
+ from functools import lru_cache
13
+ import pandas as pd
14
+ import requests
15
+ from bs4 import BeautifulSoup
16
+ from mns_common.db.MongodbUtil import MongodbUtil
17
+ import mns_common.constant.db_name_constant as db_name_constant
18
+ import mns_common.component.common_service_fun_api as common_service_fun_api
19
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
20
+ import mns_common.component.company.company_common_service_api as company_common_service_api
21
+ from loguru import logger
22
+ import mns_common.utils.data_frame_util as data_frame_util
23
+ from datetime import datetime, timedelta
24
+
25
+ mongodb_util = MongodbUtil('27017')
26
+ from tqdm import tqdm
27
+
28
+
29
+ # 同步所有映射表
30
+ @lru_cache()
31
+ def sync_stock_uid() -> pd.DataFrame:
32
+ """
33
+ 上证e互动-代码ID映射
34
+ https://sns.sseinfo.com/list/company.do
35
+ :return: 代码ID映射
36
+ :rtype: str
37
+ """
38
+ url = "https://sns.sseinfo.com/allcompany.do"
39
+ data = {
40
+ "code": "0",
41
+ "order": "2",
42
+ "areaId": "0",
43
+ "page": "1",
44
+ }
45
+ uid_list = list()
46
+ code_list = list()
47
+ for page in tqdm(range(1, 74), leave=False):
48
+ data.update({"page": page})
49
+ r = requests.post(url, data=data)
50
+ data_json = r.json()
51
+ soup = BeautifulSoup(data_json["content"], "lxml")
52
+ soup.find_all("a", attrs={"rel": "tag"})
53
+ uid_list.extend(
54
+ [item["uid"] for item in soup.find_all("a", attrs={"rel": "tag"})]
55
+ )
56
+ code_list.extend(
57
+ [
58
+ item.find("img")["src"].split("?")[0].split("/")[-1].split(".")[0]
59
+ for item in soup.find_all("a", attrs={"rel": "tag"})
60
+ ]
61
+ )
62
+ code_uid_df = pd.DataFrame()
63
+ code_uid_df['symbol'] = code_list
64
+ code_uid_df['uid'] = uid_list
65
+ code_uid_df['_id'] = uid_list
66
+ return code_uid_df
67
+
68
+
69
+ # 获取上海问答id
70
+ @lru_cache()
71
+ def get_sh_stock_all_uid() -> pd.DataFrame:
72
+ return mongodb_util.find_all_data(db_name_constant.SH_INFO_UID)
73
+
74
+
75
+ # 获取深圳问答id
76
+ @lru_cache()
77
+ def get_sz_stock_all_uid() -> pd.DataFrame:
78
+ return mongodb_util.find_all_data(db_name_constant.SZ_INFO_UID)
79
+
80
+
81
+ # 获取深圳互动回答单个ID
82
+ def get_one_sz_symbol_org_id(symbol):
83
+ sz_info_uid_df = get_sz_stock_all_uid()
84
+ sz_info_uid_one_df = sz_info_uid_df.loc[sz_info_uid_df['symbol'] == symbol]
85
+ if data_frame_util.is_not_empty(sz_info_uid_one_df):
86
+ return list(sz_info_uid_one_df['uid'])[0]
87
+ else:
88
+ try:
89
+ return fetch_sz_org_id(symbol)
90
+ except BaseException as e:
91
+ logger.error("获取组织代码异常:{},{}", symbol, e)
92
+ return '0'
93
+
94
+
95
+ # 获取上海互动回答单个ID
96
+ def get_one_sh_symbol_org_id(symbol):
97
+ sh_info_uid_df = get_sh_stock_all_uid()
98
+ sh_info_uid_one_df = sh_info_uid_df.loc[sh_info_uid_df['symbol'] == symbol]
99
+ if data_frame_util.is_not_empty(sh_info_uid_one_df):
100
+ return list(sh_info_uid_one_df['uid'])[0]
101
+ else:
102
+ return '0'
103
+
104
+
105
+ # 深圳股票-互动易-组织代码 单个获取
106
+ def fetch_sz_org_id(symbol: str = "000001") -> str:
107
+ """
108
+ 股票-互动易-组织代码
109
+ https://irm.cninfo.com.cn/
110
+ :return: 组织代码
111
+ :rtype: str
112
+ """
113
+ url = "https://irm.cninfo.com.cn/newircs/index/queryKeyboardInfo"
114
+ params = {"_t": "1691144074"}
115
+ data = {"keyWord": symbol}
116
+ r = requests.post(url, params=params, data=data)
117
+ data_json = r.json()
118
+ org_id = data_json["data"][0]["secid"]
119
+ return org_id
120
+
121
+
122
+ # 同步上证互动uid
123
+ def sync_sh_stock_uid():
124
+ code_uid_df = sync_stock_uid()
125
+ mongodb_util.save_mongo(code_uid_df, db_name_constant.SH_INFO_UID)
126
+
127
+
128
+ # 同步深圳互动uid
129
+ def sync_sz_stock_uid(symbol_list):
130
+ real_time_quotes_all_stocks = em_stock_info_api.get_a_stock_info()
131
+ de_list_company_symbols = company_common_service_api.get_de_list_company()
132
+ real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
133
+ ~(real_time_quotes_all_stocks['symbol'].isin(de_list_company_symbols))]
134
+ real_time_quotes_all_stocks = common_service_fun_api.classify_symbol(real_time_quotes_all_stocks)
135
+
136
+ real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
137
+ real_time_quotes_all_stocks['classification'].isin(['S', 'C'])]
138
+ if len(symbol_list) != 0:
139
+ real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
140
+ real_time_quotes_all_stocks['symbol'].isin(symbol_list)]
141
+ else:
142
+ # 获取当前时间
143
+ now_date = datetime.now()
144
+ # 计算前7天的时间(timedelta 用于表示时间间隔)
145
+ seven_days_ago = now_date - timedelta(days=30)
146
+ str_day_number = int(seven_days_ago.strftime('%Y%m%d'))
147
+ real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
148
+ (real_time_quotes_all_stocks['list_date'] >= str_day_number) | (
149
+ real_time_quotes_all_stocks['list_date'] == 19890604)]
150
+ for stock_one in real_time_quotes_all_stocks.itertuples():
151
+ try:
152
+ symbol = stock_one.symbol
153
+ uid = fetch_sz_org_id(symbol)
154
+ result_dict = {'_id': symbol, 'symbol': symbol, 'uid': uid}
155
+ result_dict_df = pd.DataFrame(result_dict, index=[1])
156
+ mongodb_util.save_mongo(result_dict_df, db_name_constant.SZ_INFO_UID)
157
+ logger.info("同步SZ互动ID:{}", stock_one.symbol)
158
+ except Exception as e:
159
+ logger.error("同步SZ互动ID异常:{},{}", stock_one.symbol, e)
160
+
161
+
162
+ if __name__ == '__main__':
163
+ sz_symbol_org_id = get_one_sz_symbol_org_id('300085')
164
+ sh_symbol_org_id = get_one_sh_symbol_org_id('600000')
165
+ print(sz_symbol_org_id)
166
+ print(sh_symbol_org_id)
167
+ sync_sz_stock_uid([])
168
+ # sync_sz_stock_uid([])
169
+ # sync_sh_stock_uid([])
@@ -116,6 +116,7 @@ def multi_threaded_k_line_sync(str_day):
116
116
  # 将list_date列中的所有NaN值设置为19890604
117
117
  real_time_quotes_now['list_date'].fillna(19890604, inplace=True)
118
118
  real_time_quotes_now['list_date'] = real_time_quotes_now['list_date'].replace(99990909, 19890604)
119
+ real_time_quotes_now['list_date'] = real_time_quotes_now['list_date'].replace(0, 19890604)
119
120
 
120
121
  # 将日期数值转换为日期时间格式
121
122
  real_time_quotes_now['list_date_01'] = pd.to_datetime(real_time_quotes_now['list_date'], format='%Y%m%d')
@@ -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,231 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
8
+
9
+ import mns_common.api.kpl.theme.kpl_theme_api as kpl_theme_api
10
+ from mns_common.db.MongodbUtil import MongodbUtil
11
+ from datetime import datetime
12
+ import pandas as pd
13
+ import mns_common.constant.db_name_constant as db_name_constant
14
+ from loguru import logger
15
+ import mns_common.component.cookie.cookie_info_service as cookie_info_service
16
+ import mns_common.utils.data_frame_util as data_frame_util
17
+ import mns_common.api.msg.push_msg_api as push_msg_api
18
+
19
+ mongodb_util = MongodbUtil('27017')
20
+
21
+
22
+ # 获取最大id
23
+ def query_max_theme_id():
24
+ kpl_theme_max_one_df = mongodb_util.descend_query({}, db_name_constant.KPL_THEME_LIST, 'theme_id', 1)
25
+ if data_frame_util.is_empty(kpl_theme_max_one_df):
26
+ return 1
27
+ else:
28
+ return list(kpl_theme_max_one_df['theme_id'])[0]
29
+
30
+
31
+ def sync_new_kpl_theme_info():
32
+ exist_max_theme_id = query_max_theme_id() + 1
33
+ max_sync_theme_id = exist_max_theme_id + 10
34
+
35
+ while exist_max_theme_id <= max_sync_theme_id:
36
+ try:
37
+ kpl_token = cookie_info_service.get_kpl_cookie()
38
+
39
+ json_data = kpl_theme_api.kpl_theme_index(exist_max_theme_id, kpl_token)
40
+ tables = json_data.get('Table')
41
+ if tables is not None and len(tables) > 0:
42
+ theme_name = json_data.get('Name')
43
+
44
+ title = '新增开盘啦题材:' + theme_name
45
+ push_msg_api.push_msg_to_wechat(title, title)
46
+
47
+ # 保存到主线列表
48
+ sync_kpl_theme_list(json_data, exist_max_theme_id)
49
+ # 保存到主线详细列表
50
+ sync_kpl_theme_detail(json_data, exist_max_theme_id)
51
+ exist_max_theme_id = exist_max_theme_id + 1
52
+ except BaseException as e:
53
+ logger.error("更新新题材信息异常:{},{}", str(exist_max_theme_id), e)
54
+
55
+
56
+ def update_all_kpl_theme_info():
57
+ theme_id = 0
58
+ while theme_id < 2000:
59
+ try:
60
+ kpl_token = cookie_info_service.get_kpl_cookie()
61
+ json_data = kpl_theme_api.kpl_theme_index(theme_id, kpl_token)
62
+ # 保存到主线列表
63
+ sync_kpl_theme_list(json_data, theme_id)
64
+ # 保存到主线详细列表
65
+ sync_kpl_theme_detail(json_data, theme_id)
66
+ theme_id = theme_id + 1
67
+ except BaseException as e:
68
+ logger.error("出现异常:{}", e)
69
+
70
+
71
+ def sync_kpl_theme_list(json_data, theme_id):
72
+ tables = json_data.get('Table')
73
+ if tables is None or len(tables) == 0:
74
+ return None
75
+
76
+ theme_name = json_data.get('Name')
77
+
78
+ logger.info("同步题材:{},{}", str(theme_id), theme_name)
79
+ brief_intro = json_data.get('BriefIntro')
80
+ introduction = json_data.get('Introduction')
81
+ kpl_create_time = covert_time(json_data.get('CreateTime'))
82
+ kpl_update_time = covert_time(json_data.get('UpdateTime'))
83
+ now_date = datetime.now()
84
+ sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
85
+
86
+ theme_dict = {
87
+ '_id': theme_id,
88
+ 'theme_id': theme_id,
89
+ 'theme_name': theme_name,
90
+ 'brief_intro': brief_intro,
91
+ 'introduction': introduction,
92
+ 'kpl_create_time': kpl_create_time,
93
+ 'kpl_update_time': kpl_update_time,
94
+ 'sync_time': sync_time,
95
+ }
96
+
97
+ ths_concept_one_df = pd.DataFrame(theme_dict, index=[1])
98
+ mongodb_util.save_mongo(ths_concept_one_df, db_name_constant.KPL_THEME_LIST)
99
+
100
+
101
+ def sync_kpl_theme_detail(json_data, theme_id):
102
+ tables = json_data.get('Table')
103
+ theme_name = json_data.get('Name')
104
+ if tables is None or len(tables) == 0:
105
+ return None
106
+ for table in tables:
107
+ save_theme_l1(table, theme_name, theme_id)
108
+
109
+ return tables
110
+
111
+
112
+ def save_theme_l1(table, theme_name, theme_id):
113
+ theme_l1 = table.get('Level1')
114
+
115
+ first_shelve_time = covert_time(theme_l1.get('FirstShelveTime'))
116
+ theme_l1_id = theme_l1.get('ID')
117
+ is_new = theme_l1.get('IsNew')
118
+ theme_l1_name = theme_l1.get('Name')
119
+ update_cache_time = covert_time(theme_l1.get('UpdateCacheTime'))
120
+ zs_code = theme_l1.get('ZSCode')
121
+ now_date = datetime.now()
122
+ sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
123
+ theme_dict = {
124
+ '_id': str(theme_l1_id),
125
+ 'theme_l1_id': str(theme_l1_id),
126
+ 'theme_l1_name': str(theme_l1_name),
127
+ 'theme_id': str(theme_id),
128
+ 'theme_name': str(theme_name),
129
+ 'first_shelve_time': first_shelve_time,
130
+ 'update_cache_time': update_cache_time,
131
+ 'zs_code': zs_code,
132
+ 'is_new': is_new,
133
+ 'sync_time': sync_time,
134
+ }
135
+
136
+ ths_concept_one_df = pd.DataFrame(theme_dict, index=[1])
137
+ mongodb_util.save_mongo(ths_concept_one_df, db_name_constant.KPL_THEME_LIST_L1)
138
+ stock_list = theme_l1.get('Stocks')
139
+ if len(stock_list) != 0:
140
+ save_theme_stocks(stock_list, theme_name, theme_id, theme_l1_name, theme_l1_id, '无', 0)
141
+ else:
142
+ theme_l2_list = table.get('Level2')
143
+ save_theme_l2(theme_l2_list, theme_name, theme_id, theme_l1_name, theme_l1_id)
144
+
145
+
146
+ def save_theme_l2(theme_l2_list, theme_name, theme_id, theme_l1_name, theme_l1_id):
147
+ for theme_l2_one in theme_l2_list:
148
+
149
+ first_shelve_time = covert_time(theme_l2_one.get('FirstShelveTime'))
150
+ theme_l2_id = theme_l2_one.get('ID')
151
+ is_new = theme_l2_one.get('IsNew')
152
+ theme_l2_name = theme_l2_one.get('Name')
153
+ update_cache_time = covert_time(theme_l2_one.get('UpdateCacheTime'))
154
+ zs_code = theme_l2_one.get('ZSCode')
155
+ now_date = datetime.now()
156
+ sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
157
+ theme_dict = {
158
+ '_id': str(theme_l2_id),
159
+ 'theme_l2_id': str(theme_l2_id),
160
+ 'theme_l2_name': str(theme_l2_name),
161
+
162
+ 'theme_l1_id': str(theme_l1_id),
163
+ 'theme_l1_name': str(theme_l1_name),
164
+ 'theme_id': str(theme_id),
165
+ 'theme_name': str(theme_name),
166
+ 'first_shelve_time': first_shelve_time,
167
+ 'update_cache_time': update_cache_time,
168
+ 'zs_code': zs_code,
169
+ 'is_new': is_new,
170
+ 'sync_time': sync_time,
171
+ }
172
+
173
+ ths_concept_one_df = pd.DataFrame(theme_dict, index=[1])
174
+ mongodb_util.save_mongo(ths_concept_one_df, db_name_constant.KPL_THEME_LIST_L2)
175
+ stock_list = theme_l2_one.get('Stocks')
176
+ if len(stock_list) != 0:
177
+ save_theme_stocks(stock_list, theme_name, theme_id, theme_l1_name, theme_l1_id, theme_l2_name, theme_l2_id)
178
+
179
+
180
+ def save_theme_stocks(stock_list, theme_name, theme_id, theme_l1_name, theme_l1_id, theme_l2_name, theme_l2_id):
181
+ stock_list_df = pd.DataFrame(stock_list)
182
+ stock_list_df = stock_list_df.rename(columns={
183
+ "StockID": "symbol",
184
+ "IsZz": "is_zz",
185
+ "IsHot": "is_hot",
186
+ "Reason": "reason",
187
+ "FirstShelveTime": "first_shelve_time",
188
+ "UpdateCacheTime": "update_cache_time",
189
+ "IsNew": "is_new",
190
+ "prod_name": "prod_name",
191
+ "Hot": "hot",
192
+ })
193
+ stock_list_df["first_shelve_time"] = stock_list_df["first_shelve_time"].apply(covert_time)
194
+ stock_list_df["update_cache_time"] = stock_list_df["update_cache_time"].apply(covert_time)
195
+
196
+ stock_list_df['theme_id'] = str(theme_id)
197
+ stock_list_df['theme_name'] = theme_name
198
+
199
+ stock_list_df['theme_l1_id'] = str(theme_l1_id)
200
+ stock_list_df['theme_l1_name'] = theme_l1_name
201
+
202
+ stock_list_df['theme_l2_name'] = theme_l2_name
203
+ stock_list_df['theme_l2_id'] = str(theme_l2_id)
204
+
205
+ stock_list_df['_id'] = (stock_list_df['symbol']
206
+ + '_'
207
+ + stock_list_df['theme_id']
208
+ + '_'
209
+ + stock_list_df['theme_l1_id']
210
+ + '_'
211
+ + stock_list_df['theme_l2_id'])
212
+ now_date = datetime.now()
213
+ sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
214
+ stock_list_df['sync_time'] = sync_time
215
+ mongodb_util.save_mongo(stock_list_df, db_name_constant.KPL_THEME_DETAILS)
216
+
217
+
218
+ def covert_time(timestamp_str):
219
+ timestamp = int(timestamp_str)
220
+ if timestamp == 0:
221
+ return "1989-06-04"
222
+ else:
223
+ # 3. 转换为本地时区的datetime对象
224
+ dt_local = datetime.fromtimestamp(timestamp)
225
+ # 4. 格式化为「年月日 时分秒」的字符串(格式可自定义)
226
+ datetime_str = dt_local.strftime('%Y-%m-%d %H:%M:%S')
227
+ return datetime_str
228
+
229
+
230
+ if __name__ == '__main__':
231
+ update_all_kpl_theme_info()
@@ -17,6 +17,7 @@ import mns_common.component.trade_date.trade_date_common_service_api as trade_da
17
17
 
18
18
  mongodb_util = MongodbUtil('27017')
19
19
 
20
+
20
21
  # 固定的选择
21
22
  # fixed_optional_list = ['USDCNH', 'XAUUSD',
22
23
  # '881279',
@@ -37,17 +38,16 @@ mongodb_util = MongodbUtil('27017')
37
38
  # ]
38
39
 
39
40
  # 固定的选择
40
- fixed_optional_list = ['899050', '881157']
41
-
41
+ # fixed_optional_list = ['899050', '881157']
42
42
 
43
- def add_fixed_optional():
44
- ths_cookie = cookie_info_service.get_ths_cookie()
45
- for symbol in fixed_optional_list:
46
- ths_self_choose_api.add_stock_to_account(symbol, ths_cookie)
43
+ #
44
+ # def add_fixed_optional():
45
+ # ths_cookie = cookie_info_service.get_ths_cookie()
46
+ # for symbol in fixed_optional_list:
47
+ # ths_self_choose_api.add_stock_to_account(symbol, ths_cookie)
47
48
 
48
-
49
- def delete_all_self_choose_stocks():
50
- ths_cookie = cookie_info_service.get_ths_cookie()
49
+ # 删除所有自选股票
50
+ def delete_all_self_choose_stocks(ths_cookie):
51
51
  all_self_choose_stock_list = ths_self_choose_api.get_all_self_choose_stock_list(ths_cookie)
52
52
  for stock_one in all_self_choose_stock_list.itertuples():
53
53
  symbol = stock_one.code
@@ -55,8 +55,7 @@ def delete_all_self_choose_stocks():
55
55
 
56
56
 
57
57
  # 添加固定自选股票
58
- def add_self_choose_symbol():
59
- ths_cookie = cookie_info_service.get_ths_cookie()
58
+ def add_self_choose_symbol(ths_cookie):
60
59
  # 固定自选
61
60
  self_choose_symbol_df = mongodb_util.find_all_data(db_name_constant.SELF_CHOOSE_STOCK)
62
61
  if data_frame_util.is_not_empty(self_choose_symbol_df):
@@ -66,8 +65,7 @@ def add_self_choose_symbol():
66
65
 
67
66
 
68
67
  # 添加今日选择股票
69
- def add_today_choose_symbol():
70
- ths_cookie = cookie_info_service.get_ths_cookie()
68
+ def add_today_choose_symbol(ths_cookie):
71
69
  now_date = datetime.now()
72
70
  str_day = now_date.strftime('%Y-%m-%d')
73
71
  last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
@@ -81,8 +79,7 @@ def add_today_choose_symbol():
81
79
 
82
80
 
83
81
  # 添加同花顺概念
84
- def add_self_choose_concept():
85
- ths_cookie = cookie_info_service.get_ths_cookie()
82
+ def add_self_choose_concept(ths_cookie):
86
83
  query_plate = {'self_type': {
87
84
  "$in": [self_choose_constant.SELF_CHOOSE_THS_CONCEPT,
88
85
  self_choose_constant.SELF_CHOOSE_THS_INDUSTRY]}}
@@ -95,7 +92,7 @@ def add_self_choose_concept():
95
92
 
96
93
 
97
94
  # 添加最近交易股票
98
- def add_trade_stocks():
95
+ def add_trade_stocks(ths_cookie):
99
96
  now_date = datetime.now()
100
97
  str_day = now_date.strftime('%Y-%m-%d')
101
98
  last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
@@ -109,15 +106,13 @@ def add_trade_stocks():
109
106
  trade_stocks_df = mongodb_util.find_query_data(db_name_constant.BUY_STOCK_NAME, query)
110
107
  if data_frame_util.is_not_empty(trade_stocks_df):
111
108
  stock_list = stock_list.union(set(trade_stocks_df['symbol']))
112
- ths_cookie = cookie_info_service.get_ths_cookie()
113
109
  if len(stock_list) > 0:
114
110
  for symbol in stock_list:
115
111
  ths_self_choose_api.add_stock_to_account(symbol, ths_cookie)
116
112
 
117
113
 
118
114
  # 添加连板到自选
119
- def add_continue_boards_zt_stocks():
120
- ths_cookie = cookie_info_service.get_ths_cookie()
115
+ def add_continue_boards_zt_stocks(ths_cookie):
121
116
  now_date = datetime.now()
122
117
  str_day = now_date.strftime('%Y-%m-%d')
123
118
  if trade_date_common_service_api.is_trade_day(str_day):
@@ -138,19 +133,52 @@ def add_continue_boards_zt_stocks():
138
133
  ths_self_choose_api.add_stock_to_account(stock_one.symbol, ths_cookie)
139
134
 
140
135
 
136
+ # 添加主线龙头
137
+ def add_main_line_leader(ths_cookie):
138
+ main_line_leader_df = mongodb_util.find_query_data('main_line_leader', {})
139
+ if data_frame_util.is_not_empty(main_line_leader_df):
140
+ main_line_leader_df = count_main_line_number(main_line_leader_df)
141
+
142
+ main_line_leader_df = main_line_leader_df.sort_values(
143
+ by=['main_line_number', 'main_line_leader_grade'],
144
+ ascending=[False, False,]
145
+ )
146
+ for stock_one in main_line_leader_df.itertuples():
147
+ ths_self_choose_api.add_stock_to_account(stock_one.symbol, ths_cookie)
148
+
149
+
150
+ # 统计主线的数量
151
+ def count_main_line_number(main_line_detail_df):
152
+ # 统计主线的数量
153
+ main_line_detail_df['main_line_number'] = main_line_detail_df.groupby('main_line')['main_line'].transform(
154
+ 'count')
155
+ # 相同主线数量 数量加1
156
+ main_line_detail_df['main_line_number'] = (
157
+ main_line_detail_df.groupby('main_line_number')['main_line']
158
+ .transform('rank', method='dense') - 1
159
+ ) * 0.1 + main_line_detail_df['main_line_number']
160
+
161
+ return main_line_detail_df
162
+
163
+
141
164
  # 自选股操作 删除当天自选股 增加新的连板股票 添加固定选择自选
142
165
  def self_choose_stock_handle():
143
- delete_all_self_choose_stocks()
166
+ ths_cookie = cookie_info_service.get_ths_cookie()
167
+
168
+ delete_all_self_choose_stocks(ths_cookie)
144
169
  # 固定自选板块
145
- add_fixed_optional()
170
+ # add_fixed_optional()
146
171
  # 添加同花顺概念
147
- add_self_choose_concept()
172
+ add_self_choose_concept(ths_cookie)
173
+ # 添加主线龙头
174
+ add_main_line_leader(ths_cookie)
148
175
  # 连板股票
149
- add_continue_boards_zt_stocks()
176
+ add_continue_boards_zt_stocks(ths_cookie)
177
+
150
178
  # 自己买入的股票
151
- add_trade_stocks()
179
+ add_trade_stocks(ths_cookie)
152
180
  # 添加自选股票
153
- add_self_choose_symbol()
181
+ add_self_choose_symbol(ths_cookie)
154
182
 
155
183
 
156
184
  if __name__ == '__main__':
@@ -10,6 +10,7 @@ from mns_common.component.deal.terminal_enum import TerminalEnum
10
10
  import time
11
11
  from loguru import logger
12
12
 
13
+
13
14
  # qmt 自动登录
14
15
  def qmt_auto_login():
15
16
  deal_service_api.auto_login(TerminalEnum.QMT.terminal_code)
@@ -29,4 +30,4 @@ def auto_login():
29
30
 
30
31
 
31
32
  if __name__ == '__main__':
32
- auto_login()
33
+ qmt_auto_login()
@@ -17,11 +17,22 @@ TRADER_SERVER_PATH = 'H:\\mns_trader_server.bat'
17
17
  TRADER_SERVER_NAME = "mns_trader_server"
18
18
 
19
19
 
20
+ # 打开qmt
21
+ def open_qmt_terminal():
22
+ logger.info('打开 [交易web服务端]')
23
+ if bool(1 - is_open_trader_server()):
24
+ cmd_util.open_bat_file(TRADER_SERVER_PATH)
25
+ else:
26
+ logger.info('交易服务端已经运行')
27
+ logger.info('自动登陆qmt')
28
+ trader_auto_service.qmt_auto_login()
29
+
30
+
20
31
  # 打开交易客户端
21
32
  def open_trader_terminal():
22
33
  # 打开 [交易web服务端]
23
34
  logger.info('打开 [交易web服务端]')
24
- if bool(1- is_open_trader_server()):
35
+ if bool(1 - is_open_trader_server()):
25
36
  cmd_util.open_bat_file(TRADER_SERVER_PATH)
26
37
  time.sleep(10)
27
38
  logger.info('自动登陆ths和qmt')
@@ -62,4 +73,4 @@ def kill_server():
62
73
 
63
74
  if __name__ == '__main__':
64
75
  # kill_server()
65
- open_trader_terminal()
76
+ open_qmt_terminal()
@@ -52,5 +52,5 @@ def sync_stock_tfp(str_day):
52
52
 
53
53
 
54
54
  if __name__ == '__main__':
55
- df = sync_stock_tfp('2025-07-30')
55
+ df = sync_stock_tfp('2025-12-25')
56
56
  print(df)
@@ -27,4 +27,4 @@ def sync_stock_zb_pool(str_now_day):
27
27
 
28
28
 
29
29
  if __name__ == '__main__':
30
- sync_stock_zb_pool('2025-11-18')
30
+ sync_stock_zb_pool('2025-12-11')