mns-common 1.3.3.5__py3-none-any.whl → 1.5.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. mns_common/api/akshare/__init__.py +0 -1
  2. mns_common/api/akshare/k_line_api.py +20 -82
  3. mns_common/api/akshare/stock_bid_ask_api.py +22 -97
  4. mns_common/api/akshare/stock_zb_pool.py +2 -0
  5. mns_common/api/akshare/stock_zt_pool_api.py +1 -1
  6. mns_common/api/em/gd/__init__.py +7 -0
  7. mns_common/api/em/{east_money_stock_gdfx_free_top_10_api.py → gd/east_money_stock_gdfx_free_top_10_api.py} +64 -9
  8. mns_common/api/em/real_time/__init__.py +7 -0
  9. mns_common/api/em/{east_money_debt_api.py → real_time/east_money_debt_api.py} +154 -69
  10. mns_common/api/em/{east_money_etf_api.py → real_time/east_money_etf_api.py} +149 -27
  11. mns_common/api/em/real_time/east_money_stock_a_api.py +301 -0
  12. mns_common/api/em/real_time/east_money_stock_a_v2_api.py +340 -0
  13. mns_common/api/em/real_time/east_money_stock_common_api.py +174 -0
  14. mns_common/api/em/real_time/east_money_stock_hk_api.py +288 -0
  15. mns_common/api/em/real_time/east_money_stock_hk_gtt_api.py +260 -0
  16. mns_common/api/em/real_time/east_money_stock_multi_thread_api_v3.py +154 -0
  17. mns_common/api/em/{east_money_stock_us_api.py → real_time/east_money_stock_us_api.py} +149 -72
  18. mns_common/api/em/real_time/real_time_quotes_repeat_api.py +195 -0
  19. mns_common/api/k_line/stock_k_line_data_api.py +11 -1
  20. mns_common/api/k_line/stock_minute_data_api.py +1 -0
  21. mns_common/api/kpl/common/kpl_common_api.py +35 -0
  22. mns_common/api/kpl/symbol/symbol_his_quotes_api.py +1 -1
  23. mns_common/api/proxies/__init__.py +7 -0
  24. mns_common/api/proxies/liu_guan_proxy_api.py +115 -0
  25. mns_common/api/ths/company/company_product_area_industry_index_query.py +46 -0
  26. mns_common/api/ths/company/ths_company_info_api.py +13 -9
  27. mns_common/api/ths/company/ths_company_info_web.py +159 -0
  28. mns_common/api/ths/concept/app/ths_concept_index_app.py +3 -1
  29. mns_common/api/ths/wen_cai/ths_wen_cai_api.py +10 -7
  30. mns_common/api/ths/zt/ths_stock_zt_pool_api.py +21 -4
  31. mns_common/api/ths/zt/ths_stock_zt_pool_v2_api.py +111 -40
  32. mns_common/api/xueqiu/__init__.py +7 -0
  33. mns_common/api/xueqiu/xue_qiu_k_line_api.py +83 -0
  34. mns_common/component/__init__.py +1 -1
  35. mns_common/component/classify/symbol_classify_api.py +7 -7
  36. mns_common/component/common_service_fun_api.py +66 -6
  37. mns_common/component/company/company_common_service_api.py +21 -1
  38. mns_common/component/company/company_common_service_new_api.py +4 -1
  39. mns_common/component/cookie/cookie_enum.py +15 -0
  40. mns_common/component/cookie/cookie_info_service.py +9 -4
  41. mns_common/component/data/data_init_api.py +13 -8
  42. mns_common/component/deal/deal_service_api.py +70 -8
  43. mns_common/component/deal/deal_service_v2_api.py +167 -0
  44. mns_common/component/em/__init__.py +7 -0
  45. mns_common/component/em/em_real_time_quotes_api.py +56 -0
  46. mns_common/component/em/em_stock_info_api.py +48 -0
  47. mns_common/component/exception/ExceptionMonitor.py +86 -0
  48. mns_common/component/exception/__init__.py +7 -0
  49. mns_common/component/k_line/common/k_line_common_service_api.py +4 -0
  50. mns_common/component/main_line/__init__.py +7 -0
  51. mns_common/component/main_line/main_line_zt_reason_service.py +237 -0
  52. mns_common/component/proxies/__init__.py +7 -0
  53. mns_common/component/proxies/proxy_common_api.py +252 -0
  54. mns_common/component/self_choose/__init__.py +13 -0
  55. mns_common/component/tfp/stock_tfp_api.py +82 -12
  56. mns_common/component/us/__init__.py +7 -0
  57. mns_common/component/us/us_stock_etf_info_api.py +125 -0
  58. mns_common/constant/__init__.py +1 -0
  59. mns_common/constant/db_name_constant.py +65 -34
  60. mns_common/constant/extra_income_db_name.py +154 -0
  61. mns_common/constant/strategy_classify.py +72 -0
  62. mns_common/db/MongodbUtil.py +2 -1
  63. mns_common/db/MongodbUtilLocal.py +1 -0
  64. mns_common/db/v2/MongodbUtilV2.py +0 -4
  65. mns_common-1.5.7.2.dist-info/METADATA +4 -0
  66. {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/RECORD +70 -45
  67. {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/WHEEL +1 -1
  68. mns_common/api/em/east_money_stock_api.py +0 -222
  69. mns_common/api/em/east_money_stock_hk_api.py +0 -318
  70. mns_common/api/em/east_money_stock_v2_api.py +0 -219
  71. mns_common/api/ths/concept/web/ths_company_info_web.py +0 -163
  72. mns_common/component/qmt/qmt_buy_service.py +0 -172
  73. mns_common-1.3.3.5.dist-info/METADATA +0 -4
  74. /mns_common/{component/qmt → api/em/concept}/__init__.py +0 -0
  75. /mns_common/api/em/{em_concept_index_api.py → concept/em_concept_index_api.py} +0 -0
  76. {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/top_level.txt +0 -0
@@ -7,6 +7,7 @@ project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  import json
9
9
  import requests
10
+ from loguru import logger
10
11
 
11
12
  '''
12
13
 
@@ -89,7 +90,12 @@ def get_position(terminal):
89
90
  if response.status_code != 200:
90
91
  result = {"message": '获取持仓失败'}
91
92
  else:
92
- result = response.json()
93
+ try:
94
+ result = response.json()
95
+ except BaseException as e:
96
+ result_test = response.text
97
+ result = json.loads(result_test)
98
+
93
99
  return result
94
100
 
95
101
 
@@ -126,7 +132,24 @@ def auto_login(terminal):
126
132
  if response.status_code != 200:
127
133
  result = {"message": '获取持仓失败'}
128
134
  else:
135
+
136
+ result = response.json()
137
+
138
+ return result
139
+
140
+
141
+ # 查询订单
142
+ def query_orders(terminal):
143
+ param_order = {
144
+ 'terminal': terminal}
145
+ param_json = json.dumps(param_order)
146
+ response = request_trader('/order', param_json)
147
+ if response.status_code != 200:
148
+ result = {"message": '查询订单失败'}
149
+ else:
150
+
129
151
  result = response.json()
152
+
130
153
  return result
131
154
 
132
155
 
@@ -138,18 +161,57 @@ def request_trader(url, param):
138
161
  return requests.post(total_url, data=param, headers=headers)
139
162
 
140
163
 
164
+ # 获取交易价格
165
+ def get_trade_price(terminal, symbol, price_code, limit_chg):
166
+ param_position = {
167
+ 'symbol': symbol,
168
+ 'terminal': terminal,
169
+ 'price_code': price_code,
170
+ 'limit_chg': limit_chg}
171
+
172
+ param_json = json.dumps(param_position)
173
+ response = request_trader('/trade/price', param_json)
174
+ if response.status_code != 200:
175
+ result = {"message": '获取行情失败'}
176
+ else:
177
+ result = response.json()
178
+ return result
179
+
180
+
181
+ # 获取qmt 行情
182
+ def get_qmt_real_time_quotes_detail(terminal, symbol_list):
183
+ param_position = {
184
+ 'symbol_list': symbol_list,
185
+ 'terminal': terminal}
186
+
187
+ param_json = json.dumps(param_position)
188
+ response = request_trader('/qmt/real/time/quotes/detail', param_json)
189
+ if response.status_code != 200:
190
+ result = {"message": '获取行情失败'}
191
+ else:
192
+ result = response.json()
193
+ return result
194
+
195
+
196
+ from mns_common.component.deal.terminal_enum import TerminalEnum
197
+
141
198
  if __name__ == '__main__':
142
- auto_login('qmt')
143
- get_position('qmt')
199
+ terminal_test = TerminalEnum.QMT.terminal_code
200
+ get_position(terminal_test)
201
+ symbol_one_test = ['301181.SZ']
202
+ result_json = get_qmt_real_time_quotes_detail(terminal_test, symbol_one_test)
203
+ print(result_json)
204
+ # auto_login('qmt')
205
+ # get_position('qmt')
144
206
  # terminal_test = 'easy_trader'
145
207
  # order_cancel('251145121', terminal_test)
146
208
  # get_position(terminal_test)
147
209
  # auto_ipo_buy(terminal_test)
148
- trade_buy(
149
- '301314.SZ',
150
- 35.77,
151
- 1000000,
152
- 'qmt')
210
+ # trade_buy(
211
+ # '301314.SZ',
212
+ # 35.77,
213
+ # 1000000,
214
+ # 'qmt')
153
215
  # trade_sell(
154
216
  # '301314',
155
217
  # 35.77,
@@ -0,0 +1,167 @@
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 json
9
+ import requests
10
+
11
+ '''
12
+
13
+ '''
14
+
15
+
16
+ def trade_buy(symbol, buy_price, buy_volume, terminal):
17
+ '''
18
+ 买入
19
+ :param symbol:
20
+ :param buy_price:
21
+ :param buy_volume:
22
+ :param terminal:
23
+ :return:
24
+ '''
25
+ param_buy = {
26
+ 'symbol': symbol,
27
+ 'buy_price': buy_price,
28
+ 'buy_volume': buy_volume,
29
+ 'terminal': terminal}
30
+ param_json = json.dumps(param_buy)
31
+ response = request_trader_post('/buy', param_json)
32
+ if response.status_code != 200:
33
+ buy_result = {"message": '买入失败'}
34
+ else:
35
+ buy_result = response.json()
36
+ return buy_result
37
+
38
+
39
+ def trade_sell(symbol, sell_price, sell_volume, terminal):
40
+ '''
41
+ 卖出
42
+ :param symbol:
43
+ :param sell_price:
44
+ :param sell_volume:
45
+ :param terminal:
46
+ :return:
47
+ '''
48
+ param_sell = {
49
+ 'symbol': symbol,
50
+ 'sell_price': sell_price,
51
+ 'sell_volume': sell_volume,
52
+ 'terminal': terminal}
53
+ param_json = json.dumps(param_sell)
54
+ response = request_trader_post('/sell', param_json)
55
+ if response.status_code != 200:
56
+ sell_result = {"message": '卖出失败'}
57
+ else:
58
+ sell_result = response.json()
59
+ return sell_result
60
+
61
+
62
+ def auto_ipo_buy(terminal):
63
+ '''
64
+ 自动打新
65
+ :param terminal:
66
+ :return:
67
+ '''
68
+ param_auto_ipo = {
69
+ 'terminal': terminal}
70
+ param_json = json.dumps(param_auto_ipo)
71
+ response = request_trader_get('/auto/ipo/buy', param_json)
72
+ if response.status_code != 200:
73
+ result = {"message": '自动打新失败'}
74
+ else:
75
+ result = response.json()
76
+ return result
77
+
78
+
79
+ def get_position(terminal):
80
+ '''
81
+ 获取持仓
82
+ :param terminal:
83
+ :return:
84
+ '''
85
+ param_position = {
86
+ 'terminal': terminal}
87
+ param_json = json.dumps(param_position)
88
+ response = request_trader_get('/position', param_json)
89
+ if response.status_code != 200:
90
+ result = {"message": '获取持仓失败'}
91
+ else:
92
+ result = response.json()
93
+ return result
94
+
95
+
96
+ def order_cancel(entrust_no, terminal):
97
+ '''
98
+ 撤单
99
+ :param entrust_no:
100
+ :param terminal:
101
+ :return:
102
+ '''
103
+ param_cancel = {
104
+ "entrust_no": entrust_no,
105
+ 'terminal': terminal}
106
+ param_json = json.dumps(param_cancel)
107
+ response = request_trader_post('/cancel', param_json)
108
+ if response.status_code != 200:
109
+ result = {"message": '撤单失败'}
110
+ else:
111
+ result = response.json()
112
+ return result
113
+
114
+
115
+ # 自动登陆接口
116
+ def auto_login(terminal):
117
+ '''
118
+ 自动登陆客户端
119
+ :param terminal:
120
+ :return:
121
+ '''
122
+ param_position = {
123
+ 'terminal': terminal}
124
+ param_json = json.dumps(param_position)
125
+ response = request_trader_post('/auto/login', param_json)
126
+ if response.status_code != 200:
127
+ result = {"message": '获取持仓失败'}
128
+ else:
129
+ result = response.json()
130
+ return result
131
+
132
+
133
+ def request_trader_post(url, param):
134
+ total_url = "http://127.0.0.1:5002/api/trade" + url
135
+ headers = {
136
+ "Content-Type": "application/json"
137
+ }
138
+ return requests.post(total_url, data=param, headers=headers)
139
+
140
+
141
+ def request_trader_get(url, param):
142
+ total_url = "http://127.0.0.1:5002/api/trade" + url
143
+ headers = {
144
+ "Content-Type": "application/json"
145
+ }
146
+ return requests.get(total_url, data=param, headers=headers)
147
+
148
+
149
+ if __name__ == '__main__':
150
+ # auto_login('qmt')
151
+ # get_position('qmt')
152
+ # terminal_test = 'easy_trader'
153
+ # order_cancel('251145121', terminal_test)
154
+ # get_position(terminal_test)
155
+ # auto_ipo_buy(terminal_test)
156
+ buy_result_test = trade_buy(
157
+ '688693.SH',
158
+ 36.39,
159
+ 1000,
160
+ 'ths')
161
+ entrust_no_test = buy_result_test['entrust_no']
162
+ order_cancel(entrust_no_test, 'ths')
163
+ # trade_sell(
164
+ # '301314',
165
+ # 35.77,
166
+ # 100,
167
+ # 'easy_trader')
@@ -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,56 @@
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
+ from mns_common.db.MongodbUtil import MongodbUtil
10
+ import mns_common.utils.data_frame_util as data_frame_util
11
+ import mns_common.component.common_service_fun_api as common_service_fun_api
12
+ import mns_common.constant.db_name_constant as db_name_constant
13
+ import mns_common.utils.db_util as db_util
14
+
15
+ mongodb_util = MongodbUtil('27017')
16
+
17
+
18
+ # 获取当天最新实时数据
19
+ def get_real_time_quotes_now(symbol_list, selected_date):
20
+ db_name = db_name_constant.REAL_TIME_QUOTES_NOW
21
+ if selected_date is not None:
22
+ query_day = selected_date[0:10]
23
+ db_name = db_name + '_' + query_day
24
+ db_util_mongo = db_util.get_db(query_day)
25
+ query = {'symbol': '000001'}
26
+ query_field = {"str_now_date": 1, "number": 1, "symbol": 1}
27
+ df = db_util_mongo.find_query_data_choose_field(db_name, query, query_field)
28
+ if df is None or df.shape[0] == 0:
29
+ number = 1
30
+ else:
31
+ df = df[df['str_now_date'] <= selected_date]
32
+ df = df.sort_values(by=['str_now_date'], ascending=False)
33
+ number = list(df['number'])[0]
34
+ # 最新number数据可能还正在写库
35
+
36
+ query = {'number': number}
37
+ real_time_quotes_now = db_util_mongo.find_query_data(db_name, query)
38
+
39
+ else:
40
+
41
+ number = common_service_fun_api.realtime_quotes_now_max_number(db_name,
42
+ 'number')
43
+ # 最新number数据可能还正在写库
44
+ real_time_quotes_now = common_service_fun_api.get_last_new_real_time_data(
45
+ db_name
46
+ , number - 1)
47
+ if (symbol_list is not None
48
+ and data_frame_util.is_not_empty(real_time_quotes_now)):
49
+ real_time_quotes_now = real_time_quotes_now.loc[real_time_quotes_now['symbol'].isin(symbol_list)]
50
+
51
+ return real_time_quotes_now
52
+
53
+
54
+ if __name__ == '__main__':
55
+ df = get_real_time_quotes_now(None, None)
56
+ print(df)
@@ -0,0 +1,48 @@
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 mns_common.db.MongodbUtil import MongodbUtil
9
+ import mns_common.constant.extra_income_db_name as extra_income_db_name
10
+
11
+ mongodb_util = MongodbUtil('27017')
12
+
13
+
14
+ # 获取东方财富A股全部信息
15
+ def get_a_stock_info():
16
+ em_a_stock_info = mongodb_util.find_all_data(extra_income_db_name.EM_A_STOCK_INFO)
17
+ em_a_stock_info = em_a_stock_info[~em_a_stock_info['symbol'].str.startswith(('8', '4'))]
18
+ return em_a_stock_info
19
+
20
+
21
+ # 获取东方财富ETF全部信息
22
+ def get_etf_info():
23
+ return mongodb_util.find_all_data(extra_income_db_name.EM_ETF_INFO)
24
+
25
+
26
+ # 获取东方财富可转债全部信息
27
+ def get_kzz_info():
28
+ return mongodb_util.find_all_data(extra_income_db_name.EM_KZZ_INFO)
29
+
30
+
31
+ # 获取东方财富美股全部信息
32
+ def get_us_stock_info():
33
+ return mongodb_util.find_all_data(extra_income_db_name.US_STOCK_INFO_EM)
34
+
35
+
36
+ # 获取东方财富美股 eft全部信息
37
+ def get_us_etf_info():
38
+ return mongodb_util.find_all_data(extra_income_db_name.US_ETF_INFO_EM)
39
+
40
+
41
+ # 获取东方财富港股全部信息
42
+
43
+ def get_hk_stock_info():
44
+ return mongodb_util.find_all_data(extra_income_db_name.EM_HK_STOCK_INFO)
45
+
46
+
47
+ if __name__ == '__main__':
48
+ get_a_stock_info()
@@ -0,0 +1,86 @@
1
+ import threading
2
+ from functools import wraps
3
+ from typing import Optional, Callable
4
+
5
+ class ExceptionMonitor:
6
+ """支持动态配置的异常监控器"""
7
+ def __init__(
8
+ self,
9
+ threshold: int = 1000,
10
+ alert_handler: Optional[Callable[[int, int], None]] = None,
11
+ auto_reset: bool = True
12
+ ):
13
+ """
14
+ :param threshold: 报警阈值,默认1000次
15
+ :param alert_handler: 自定义报警函数,格式 func(current_count, threshold)
16
+ :param auto_reset: 触发报警后是否自动重置计数器
17
+ """
18
+ self.counter = 0
19
+ self._threshold = threshold
20
+ self.alert_handler = alert_handler
21
+ self.auto_reset = auto_reset
22
+ self.lock = threading.Lock()
23
+
24
+ @property
25
+ def threshold(self) -> int:
26
+ """当前报警阈值"""
27
+ return self._threshold
28
+
29
+ @threshold.setter
30
+ def threshold(self, value: int):
31
+ """动态设置报警阈值"""
32
+ with self.lock:
33
+ self._threshold = value
34
+
35
+ def increment(self):
36
+ """线程安全的计数器递增"""
37
+ with self.lock:
38
+ self.counter += 1
39
+ if self.counter >= self.threshold:
40
+ self.trigger_alert()
41
+ if self.auto_reset:
42
+ self.reset_counter()
43
+
44
+ def reset_counter(self):
45
+ """手动重置计数器"""
46
+ with self.lock:
47
+ self.counter = 0
48
+
49
+ def trigger_alert(self):
50
+ """触发报警(支持自定义处理逻辑)"""
51
+ if self.alert_handler:
52
+ self.alert_handler(self.counter, self.threshold)
53
+ else:
54
+ print(f"[ALERT] Exception count {self.counter} exceeded threshold {self.threshold}")
55
+
56
+ def exception_counter(
57
+ threshold: int = 1000,
58
+ alert_handler: Optional[Callable[[int, int], None]] = None,
59
+ auto_reset: bool = True
60
+ ):
61
+ """
62
+ 异常计数装饰器工厂
63
+ :param threshold: 报警阈值
64
+ :param alert_handler: 自定义报警处理函数
65
+ :param auto_reset: 是否自动重置计数器
66
+ """
67
+ def decorator(func):
68
+ # 为每个被装饰函数创建独立监控实例
69
+ monitor = ExceptionMonitor(
70
+ threshold=threshold,
71
+ alert_handler=alert_handler,
72
+ auto_reset=auto_reset
73
+ )
74
+
75
+ @wraps(func)
76
+ def wrapper(*args, **kwargs):
77
+ try:
78
+ return func(*args, **kwargs)
79
+ except Exception as e:
80
+ monitor.increment()
81
+ raise # 保持原始异常栈
82
+
83
+ # 暴露监控器以便外部访问
84
+ wrapper.monitor = monitor
85
+ return wrapper
86
+ return decorator
@@ -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)
@@ -33,6 +33,10 @@ def calculate_real_time_k_line_param(real_time_quotes_now):
33
33
  real_time_quotes_now['chg_from_open'] = round(
34
34
  (((real_time_quotes_now['now_price'] - real_time_quotes_now['open']) / real_time_quotes_now[
35
35
  'open']) * 100), 2)
36
+ # 最低和最高之间的差值
37
+ real_time_quotes_now['high_from_low_chg'] = round(
38
+ (((real_time_quotes_now['high'] - real_time_quotes_now['low']) / real_time_quotes_now[
39
+ 'low']) * 100), 2)
36
40
 
37
41
  if 'average_price' in real_time_quotes_now.columns:
38
42
  # 高于平均线的差值 越大表明极速拉伸
@@ -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)