mns-common 1.3.9.9__py3-none-any.whl → 1.6.1.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-common might be problematic. Click here for more details.
- mns_common/__init__.py +1 -0
- mns_common/api/akshare/__init__.py +0 -1
- mns_common/api/akshare/k_line_api.py +19 -2
- mns_common/api/akshare/stock_bid_ask_api.py +21 -14
- mns_common/api/akshare/stock_zb_pool.py +2 -0
- mns_common/api/akshare/stock_zt_pool_api.py +1 -1
- mns_common/api/em/gd/east_money_stock_gdfx_free_top_10_api.py +62 -7
- mns_common/api/em/real_time/__init__.py +1 -1
- mns_common/api/em/real_time/east_money_debt_api.py +168 -71
- mns_common/api/em/real_time/east_money_etf_api.py +165 -27
- mns_common/api/em/real_time/east_money_stock_a_api.py +37 -38
- mns_common/api/em/real_time/east_money_stock_a_v2_api.py +97 -53
- mns_common/api/em/real_time/east_money_stock_common_api.py +174 -0
- mns_common/api/em/real_time/east_money_stock_hk_api.py +252 -271
- mns_common/api/em/real_time/east_money_stock_hk_gtt_api.py +291 -0
- mns_common/api/em/real_time/east_money_stock_multi_thread_api_v3.py +154 -0
- mns_common/api/em/real_time/east_money_stock_us_api.py +210 -82
- mns_common/api/em/real_time/real_time_quotes_repeat_api.py +195 -0
- mns_common/api/foreign_exchange/foreign_exchange_api.py +38 -0
- mns_common/api/k_line/stock_k_line_data_api.py +11 -1
- mns_common/api/kpl/common/__init__.py +3 -2
- mns_common/api/kpl/common/kpl_common_api.py +35 -0
- mns_common/api/kpl/symbol/symbol_his_quotes_api.py +1 -1
- mns_common/api/kpl/theme/kpl_theme_api.py +69 -0
- mns_common/api/kpl/yidong/__init__.py +7 -0
- mns_common/api/kpl/yidong/stock_bid_yi_dong_api.py +52 -0
- mns_common/api/proxies/liu_guan_proxy_api.py +55 -5
- mns_common/api/ths/company/company_product_area_industry_index_query.py +46 -0
- mns_common/api/ths/company/ths_company_info_api.py +2 -1
- mns_common/api/ths/company/ths_company_info_web.py +159 -0
- mns_common/api/ths/concept/app/ths_concept_index_app.py +3 -1
- mns_common/api/ths/wen_cai/ths_wen_cai_api.py +1 -1
- mns_common/api/ths/zt/ths_stock_zt_pool_api.py +20 -1
- mns_common/api/ths/zt/ths_stock_zt_pool_v2_api.py +105 -29
- mns_common/api/ths/zt/ths_stock_zt_reason_web_api.py +100 -0
- mns_common/api/us/ths_us_company_info_api.py +131 -0
- mns_common/api/xueqiu/xue_qiu_k_line_api.py +16 -5
- mns_common/component/common_service_fun_api.py +28 -8
- mns_common/component/company/company_common_service_new_api.py +2 -0
- mns_common/component/cookie/cookie_enum.py +16 -0
- mns_common/component/cookie/cookie_info_service.py +18 -8
- mns_common/component/data/data_init_api.py +13 -8
- mns_common/component/deal/deal_service_api.py +70 -8
- mns_common/component/deal/deal_service_v2_api.py +167 -0
- mns_common/component/em/em_stock_info_api.py +12 -3
- mns_common/component/main_line/__init__.py +7 -0
- mns_common/component/main_line/main_line_zt_reason_service.py +257 -0
- mns_common/component/proxies/proxy_common_api.py +169 -109
- mns_common/component/tfp/stock_tfp_api.py +82 -12
- mns_common/component/us/__init__.py +7 -0
- mns_common/component/us/us_stock_etf_info_api.py +130 -0
- mns_common/constant/db_name_constant.py +75 -26
- mns_common/constant/extra_income_db_name.py +94 -17
- mns_common/constant/strategy_classify.py +72 -0
- mns_common/db/MongodbUtil.py +3 -0
- mns_common/db/MongodbUtilLocal.py +3 -0
- {mns_common-1.3.9.9.dist-info → mns_common-1.6.1.4.dist-info}/METADATA +1 -1
- {mns_common-1.3.9.9.dist-info → mns_common-1.6.1.4.dist-info}/RECORD +62 -47
- mns_common/api/ths/concept/web/ths_company_info_web.py +0 -163
- mns_common/component/qmt/qmt_buy_service.py +0 -172
- mns_common/component/task/real_time_data_sync_check.py +0 -97
- /mns_common/{component/qmt → api/foreign_exchange}/__init__.py +0 -0
- /mns_common/{component/task → api/kpl/theme}/__init__.py +0 -0
- {mns_common-1.3.9.9.dist-info → mns_common-1.6.1.4.dist-info}/WHEEL +0 -0
- {mns_common-1.3.9.9.dist-info → mns_common-1.6.1.4.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
|
-
|
|
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
|
-
|
|
143
|
-
get_position(
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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')
|
|
@@ -13,7 +13,12 @@ mongodb_util = MongodbUtil('27017')
|
|
|
13
13
|
|
|
14
14
|
# 获取东方财富A股全部信息
|
|
15
15
|
def get_a_stock_info():
|
|
16
|
-
|
|
16
|
+
em_a_stock_info = mongodb_util.find_all_data(extra_income_db_name.EM_A_STOCK_INFO)
|
|
17
|
+
em_a_stock_info['list_date'].fillna(19890604, inplace=True)
|
|
18
|
+
em_a_stock_info['list_date'] = em_a_stock_info['list_date'].replace(99990909, 19890604)
|
|
19
|
+
em_a_stock_info['list_date'] = em_a_stock_info['list_date'].replace(0, 19890604)
|
|
20
|
+
em_a_stock_info = em_a_stock_info[~em_a_stock_info['symbol'].str.startswith(('8', '4'))]
|
|
21
|
+
return em_a_stock_info
|
|
17
22
|
|
|
18
23
|
|
|
19
24
|
# 获取东方财富ETF全部信息
|
|
@@ -28,15 +33,19 @@ def get_kzz_info():
|
|
|
28
33
|
|
|
29
34
|
# 获取东方财富美股全部信息
|
|
30
35
|
def get_us_stock_info():
|
|
31
|
-
return mongodb_util.find_all_data(extra_income_db_name.
|
|
36
|
+
return mongodb_util.find_all_data(extra_income_db_name.US_STOCK_INFO_EM)
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
# 获取东方财富美股 eft全部信息
|
|
35
40
|
def get_us_etf_info():
|
|
36
|
-
return mongodb_util.find_all_data(extra_income_db_name.
|
|
41
|
+
return mongodb_util.find_all_data(extra_income_db_name.US_ETF_INFO_EM)
|
|
37
42
|
|
|
38
43
|
|
|
39
44
|
# 获取东方财富港股全部信息
|
|
40
45
|
|
|
41
46
|
def get_hk_stock_info():
|
|
42
47
|
return mongodb_util.find_all_data(extra_income_db_name.EM_HK_STOCK_INFO)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == '__main__':
|
|
51
|
+
get_a_stock_info()
|
|
@@ -0,0 +1,257 @@
|
|
|
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.constant.db_name_constant as db_name_constant
|
|
9
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
10
|
+
import mns_common.api.ths.zt.ths_stock_zt_pool_api as ths_stock_zt_pool_api
|
|
11
|
+
from mns_common.utils.async_fun import async_fun
|
|
12
|
+
import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
|
|
13
|
+
import mns_common.api.ths.zt.ths_stock_zt_reason_web_api as ths_stock_zt_reason_web_api
|
|
14
|
+
|
|
15
|
+
mongodb_util = MongodbUtil('27017')
|
|
16
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
17
|
+
import time
|
|
18
|
+
from loguru import logger
|
|
19
|
+
import pandas as pd
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
import mns_common.component.cookie.cookie_info_service as cookie_info_service
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# 添加主线和涨停分析临时数据
|
|
25
|
+
def merge_main_line_info(str_day, data_df):
|
|
26
|
+
# 保证数据完整性
|
|
27
|
+
if 'main_line' not in data_df.columns:
|
|
28
|
+
data_df['main_line'] = ''
|
|
29
|
+
else:
|
|
30
|
+
data_df.fillna({'main_line': ''}, inplace=True)
|
|
31
|
+
|
|
32
|
+
if 'sub_main_line' not in data_df.columns:
|
|
33
|
+
data_df['sub_main_line'] = ''
|
|
34
|
+
else:
|
|
35
|
+
data_df.fillna({'sub_main_line': ''}, inplace=True)
|
|
36
|
+
|
|
37
|
+
if 'zt_analysis' not in data_df.columns:
|
|
38
|
+
data_df['zt_analysis'] = ''
|
|
39
|
+
|
|
40
|
+
else:
|
|
41
|
+
data_df.fillna({'zt_analysis': ''}, inplace=True)
|
|
42
|
+
|
|
43
|
+
if 'zt_reason' not in data_df.columns:
|
|
44
|
+
data_df['zt_reason'] = ''
|
|
45
|
+
else:
|
|
46
|
+
data_df.fillna({'zt_reason': ''}, inplace=True)
|
|
47
|
+
|
|
48
|
+
if 'main_line_choose_source' not in data_df.columns:
|
|
49
|
+
data_df['main_line_choose_source'] = 'now_zt'
|
|
50
|
+
else:
|
|
51
|
+
data_df.fillna({'main_line_choose_source': 'now_zt'}, inplace=True)
|
|
52
|
+
|
|
53
|
+
if 'main_line_grade' not in data_df.columns:
|
|
54
|
+
data_df['main_line_grade'] = 1
|
|
55
|
+
else:
|
|
56
|
+
data_df.fillna({'main_line_grade': 1}, inplace=True)
|
|
57
|
+
|
|
58
|
+
query_zt_now = {'symbol': {"$in": list(data_df['symbol'])}, 'str_day': str_day}
|
|
59
|
+
# merge 主线 涨停详情
|
|
60
|
+
main_line_detail_df = mongodb_util.find_query_data(db_name_constant.MAIN_LINE_DETAIL, query_zt_now)
|
|
61
|
+
if data_frame_util.is_not_empty(main_line_detail_df):
|
|
62
|
+
symbol_mapping_zt_reason_now = dict(
|
|
63
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['zt_reason']))
|
|
64
|
+
|
|
65
|
+
symbol_mapping_zt_analysis_now = dict(
|
|
66
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['zt_analysis']))
|
|
67
|
+
|
|
68
|
+
symbol_mapping_main_line_now = dict(
|
|
69
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['main_line']))
|
|
70
|
+
|
|
71
|
+
symbol_mapping_sub_main_line_now = dict(
|
|
72
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['sub_main_line']))
|
|
73
|
+
|
|
74
|
+
symbol_mapping_main_line_choose_source = dict(
|
|
75
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['main_line_choose_source']))
|
|
76
|
+
|
|
77
|
+
symbol_mapping_main_line_grade = dict(
|
|
78
|
+
zip(main_line_detail_df['symbol'], main_line_detail_df['main_line_grade']))
|
|
79
|
+
|
|
80
|
+
data_df['main_line_grade'] = data_df['symbol'].map(
|
|
81
|
+
symbol_mapping_main_line_grade).fillna(
|
|
82
|
+
data_df['main_line_grade'])
|
|
83
|
+
|
|
84
|
+
data_df['main_line'] = data_df['symbol'].map(
|
|
85
|
+
symbol_mapping_main_line_now).fillna(
|
|
86
|
+
data_df['main_line'])
|
|
87
|
+
|
|
88
|
+
data_df['sub_main_line'] = data_df['symbol'].map(
|
|
89
|
+
symbol_mapping_sub_main_line_now).fillna(
|
|
90
|
+
data_df['sub_main_line'])
|
|
91
|
+
data_df['zt_reason'] = data_df['symbol'].map(
|
|
92
|
+
symbol_mapping_zt_reason_now).fillna(
|
|
93
|
+
data_df['zt_reason'])
|
|
94
|
+
data_df['zt_analysis'] = data_df['symbol'].map(
|
|
95
|
+
symbol_mapping_zt_analysis_now).fillna(
|
|
96
|
+
data_df['zt_analysis'])
|
|
97
|
+
|
|
98
|
+
data_df['main_line_choose_source'] = data_df['symbol'].map(
|
|
99
|
+
symbol_mapping_main_line_choose_source).fillna(
|
|
100
|
+
data_df['main_line_choose_source'])
|
|
101
|
+
|
|
102
|
+
return data_df
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# merge涨停分析 原因
|
|
106
|
+
def merge_zt_reason_info(str_day, data_df):
|
|
107
|
+
if 'zt_analysis' not in data_df.columns:
|
|
108
|
+
data_df['zt_analysis'] = ''
|
|
109
|
+
|
|
110
|
+
else:
|
|
111
|
+
data_df.fillna({'zt_analysis': ''}, inplace=True)
|
|
112
|
+
|
|
113
|
+
if 'zt_reason' not in data_df.columns:
|
|
114
|
+
data_df['zt_reason'] = ''
|
|
115
|
+
else:
|
|
116
|
+
data_df.fillna({'zt_reason': ''}, inplace=True)
|
|
117
|
+
|
|
118
|
+
query_zt_now = {'symbol': {"$in": list(data_df['symbol'])}, 'str_day': str_day}
|
|
119
|
+
# merge 主线 涨停详情
|
|
120
|
+
zt_reason_analysis_df = mongodb_util.find_query_data(db_name_constant.ZT_REASON_ANALYSIS, query_zt_now)
|
|
121
|
+
if data_frame_util.is_not_empty(zt_reason_analysis_df):
|
|
122
|
+
symbol_mapping_zt_reason_now = dict(
|
|
123
|
+
zip(zt_reason_analysis_df['symbol'], zt_reason_analysis_df['zt_reason']))
|
|
124
|
+
|
|
125
|
+
symbol_mapping_zt_analysis_now = dict(
|
|
126
|
+
zip(zt_reason_analysis_df['symbol'], zt_reason_analysis_df['zt_analysis']))
|
|
127
|
+
|
|
128
|
+
data_df['zt_reason'] = data_df['symbol'].map(
|
|
129
|
+
symbol_mapping_zt_reason_now).fillna(
|
|
130
|
+
data_df['zt_reason'])
|
|
131
|
+
data_df['zt_analysis'] = data_df['symbol'].map(
|
|
132
|
+
symbol_mapping_zt_analysis_now).fillna(
|
|
133
|
+
data_df['zt_analysis'])
|
|
134
|
+
|
|
135
|
+
return data_df
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def update_zt_reason_analysis(symbol, str_day, name, need_update):
|
|
139
|
+
try:
|
|
140
|
+
key_id = symbol + "_" + str_day
|
|
141
|
+
query_zt = {"_id": key_id}
|
|
142
|
+
|
|
143
|
+
# 已经存在的数据
|
|
144
|
+
zt_reason_analysis_exists_df = mongodb_util.find_query_data(db_name_constant.ZT_REASON_ANALYSIS,
|
|
145
|
+
query_zt)
|
|
146
|
+
|
|
147
|
+
if data_frame_util.is_not_empty(zt_reason_analysis_exists_df):
|
|
148
|
+
zt_analysis = list(zt_reason_analysis_exists_df['zt_analysis'])[0]
|
|
149
|
+
zt_reason = list(zt_reason_analysis_exists_df['zt_reason'])[0]
|
|
150
|
+
# 需要更新数据
|
|
151
|
+
if data_frame_util.is_string_empty(zt_analysis) or data_frame_util.is_string_empty(
|
|
152
|
+
zt_reason) or need_update:
|
|
153
|
+
|
|
154
|
+
# web端更新数据
|
|
155
|
+
try:
|
|
156
|
+
web_zt_result_dict = ths_stock_zt_reason_web_api.get_ths_web_zt_reason_info(symbol,
|
|
157
|
+
cookie_info_service.get_ths_cookie())
|
|
158
|
+
zt_analysis = web_zt_result_dict['zt_analysis']
|
|
159
|
+
zt_reason = web_zt_result_dict['zt_reason']
|
|
160
|
+
time.sleep(1)
|
|
161
|
+
except BaseException as e:
|
|
162
|
+
time.sleep(1)
|
|
163
|
+
zt_analysis = ''
|
|
164
|
+
zt_reason = ''
|
|
165
|
+
|
|
166
|
+
# 问财更新数据
|
|
167
|
+
if data_frame_util.is_string_empty(zt_analysis) or data_frame_util.is_string_empty(
|
|
168
|
+
zt_reason):
|
|
169
|
+
try:
|
|
170
|
+
zt_result_dict = ths_stock_zt_pool_api.zt_analyse_reason(symbol)
|
|
171
|
+
zt_analysis = zt_result_dict['zt_analyse_detail']
|
|
172
|
+
zt_reason = zt_result_dict['zt_reason']
|
|
173
|
+
time.sleep(1)
|
|
174
|
+
except BaseException as e:
|
|
175
|
+
time.sleep(1)
|
|
176
|
+
zt_analysis = ''
|
|
177
|
+
zt_reason = ''
|
|
178
|
+
|
|
179
|
+
zt_reason_analysis_exists_df['zt_analysis'] = zt_analysis
|
|
180
|
+
zt_reason_analysis_exists_df['zt_reason'] = zt_reason
|
|
181
|
+
now_date = datetime.now()
|
|
182
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
183
|
+
zt_reason_analysis_exists_df['update_time'] = str_now_date
|
|
184
|
+
mongodb_util.save_mongo(zt_reason_analysis_exists_df, db_name_constant.ZT_REASON_ANALYSIS)
|
|
185
|
+
else:
|
|
186
|
+
# 不存在临时主线数据
|
|
187
|
+
try:
|
|
188
|
+
zt_result_dict = ths_stock_zt_pool_api.zt_analyse_reason(symbol)
|
|
189
|
+
zt_analysis = zt_result_dict['zt_analyse_detail']
|
|
190
|
+
zt_reason = zt_result_dict['zt_reason']
|
|
191
|
+
time.sleep(1)
|
|
192
|
+
except BaseException as e:
|
|
193
|
+
time.sleep(1)
|
|
194
|
+
zt_analysis = ''
|
|
195
|
+
zt_reason = ''
|
|
196
|
+
now_date = datetime.now()
|
|
197
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
198
|
+
reason_dict = {'_id': key_id,
|
|
199
|
+
'symbol': symbol,
|
|
200
|
+
'name': name,
|
|
201
|
+
'zt_analysis': zt_analysis,
|
|
202
|
+
'zt_reason': zt_reason,
|
|
203
|
+
'str_day': str_day,
|
|
204
|
+
'update_time': str_now_date,
|
|
205
|
+
}
|
|
206
|
+
reason_df = pd.DataFrame(reason_dict, index=[1])
|
|
207
|
+
mongodb_util.save_mongo(reason_df, db_name_constant.ZT_REASON_ANALYSIS)
|
|
208
|
+
except BaseException as e:
|
|
209
|
+
logger.error("添加涨停原因详情异常:{},{}", e, name)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def update_symbol_list_zt_reason_analysis(data_df, need_update):
|
|
213
|
+
for stock_one in data_df.itertuples():
|
|
214
|
+
str_day = stock_one.str_day
|
|
215
|
+
symbol = stock_one.symbol
|
|
216
|
+
name = stock_one.name
|
|
217
|
+
update_zt_reason_analysis(symbol, str_day, name, need_update)
|
|
218
|
+
if need_update:
|
|
219
|
+
time.sleep(5)
|
|
220
|
+
else:
|
|
221
|
+
time.sleep(1)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# 保存连板股票主线
|
|
225
|
+
@async_fun
|
|
226
|
+
def save_last_trade_day_main_line(str_day, stock_em_zt_pool_df_data):
|
|
227
|
+
last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
228
|
+
stock_em_zt_pool_connected_df = stock_em_zt_pool_df_data.loc[
|
|
229
|
+
stock_em_zt_pool_df_data['connected_boards_numbers'] > 1]
|
|
230
|
+
if data_frame_util.is_empty(stock_em_zt_pool_connected_df):
|
|
231
|
+
return
|
|
232
|
+
else:
|
|
233
|
+
query = {'str_day': last_trade_day, 'symbol': {"$in": list(stock_em_zt_pool_connected_df['symbol'])}}
|
|
234
|
+
last_trade_day_main_line_detail_df = mongodb_util.find_query_data(db_name_constant.MAIN_LINE_DETAIL, query)
|
|
235
|
+
if data_frame_util.is_empty(last_trade_day_main_line_detail_df):
|
|
236
|
+
return
|
|
237
|
+
else:
|
|
238
|
+
last_trade_day_main_line_detail_df['_id'] = last_trade_day_main_line_detail_df['symbol'] + '_' + str_day
|
|
239
|
+
last_trade_day_main_line_detail_df['str_day'] = str_day
|
|
240
|
+
last_trade_day_main_line_detail_df['connected_boards_numbers'] = last_trade_day_main_line_detail_df[
|
|
241
|
+
'connected_boards_numbers'] + 1
|
|
242
|
+
now_date = datetime.now()
|
|
243
|
+
str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
|
|
244
|
+
last_trade_day_main_line_detail_df['update_time'] = str_now_date
|
|
245
|
+
today_exist_main_line_df = mongodb_util.find_query_data(db_name_constant.MAIN_LINE_DETAIL,
|
|
246
|
+
{'str_day': str_day, 'symbol': {"$in": list(
|
|
247
|
+
last_trade_day_main_line_detail_df['symbol'])}})
|
|
248
|
+
if data_frame_util.is_not_empty(today_exist_main_line_df):
|
|
249
|
+
today_new_main_line_df = last_trade_day_main_line_detail_df.loc[~
|
|
250
|
+
last_trade_day_main_line_detail_df['symbol'].isin(list(today_exist_main_line_df['symbol']))]
|
|
251
|
+
else:
|
|
252
|
+
today_new_main_line_df = last_trade_day_main_line_detail_df.copy()
|
|
253
|
+
mongodb_util.save_mongo(today_new_main_line_df, db_name_constant.MAIN_LINE_DETAIL)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if __name__ == '__main__':
|
|
257
|
+
update_zt_reason_analysis('600362', '2025-12-26', '江西铜业', True)
|