mns-common 1.3.9.2__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 +20 -82
- 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 +31 -23
- 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/exception/ExceptionMonitor.py +86 -0
- mns_common/component/exception/__init__.py +7 -0
- 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 +199 -31
- 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 +97 -11
- 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.2.dist-info → mns_common-1.6.1.4.dist-info}/METADATA +1 -1
- {mns_common-1.3.9.2.dist-info → mns_common-1.6.1.4.dist-info}/RECORD +64 -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.2.dist-info → mns_common-1.6.1.4.dist-info}/WHEEL +0 -0
- {mns_common-1.3.9.2.dist-info → mns_common-1.6.1.4.dist-info}/top_level.txt +0 -0
|
@@ -5,36 +5,69 @@ file_path = os.path.abspath(__file__)
|
|
|
5
5
|
end = file_path.index('mns') + 16
|
|
6
6
|
project_path = file_path[0:end]
|
|
7
7
|
sys.path.append(project_path)
|
|
8
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
9
8
|
import pandas as pd
|
|
10
9
|
from loguru import logger
|
|
11
10
|
import requests
|
|
12
|
-
import json
|
|
13
11
|
import time
|
|
12
|
+
import mns_common.component.proxies.proxy_common_api as proxy_common_api
|
|
13
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
14
|
+
import json
|
|
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
|
|
14
17
|
|
|
15
|
-
# 最大返回条数
|
|
16
|
-
max_number = 4500
|
|
17
|
-
# 最小返回条数
|
|
18
|
-
min_number = 4400
|
|
19
18
|
# 分页条数
|
|
20
19
|
page_number = 100
|
|
21
20
|
|
|
22
|
-
fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,"
|
|
23
|
-
"f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212")
|
|
21
|
+
fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,f19,"
|
|
22
|
+
"f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212,f103,f383")
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
def
|
|
25
|
+
def get_hk_stock_count(pn, proxies, page_size, cookie, time_out):
|
|
27
26
|
try:
|
|
28
27
|
headers = {
|
|
29
28
|
'Cookie': cookie
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
current_timestamp = str(int(round(time.time() * 1000, 0)))
|
|
33
31
|
|
|
32
|
+
url_new = ('https://push2.eastmoney.com/api/qt/clist/get?cb=jQuery371026074131356896413_' + str(
|
|
33
|
+
current_timestamp) +
|
|
34
|
+
'&np=1'
|
|
35
|
+
'&fltt=1'
|
|
36
|
+
'&invt=2'
|
|
37
|
+
'&fs=m:128+t:3,m:128+t:4,m:128+t:1,m:128+t:2'
|
|
38
|
+
'&fields=' + fields +
|
|
39
|
+
'&fid=f12'
|
|
40
|
+
'&pn=' + str(pn) +
|
|
41
|
+
'&pz=' + str(page_size) +
|
|
42
|
+
'&po=1'
|
|
43
|
+
'&dect=1'
|
|
44
|
+
'&ut=fa5fd1943c7b386f172d6893dbfba10b'
|
|
45
|
+
'&wbp2u=4253366368931142|0|1|0|web'
|
|
46
|
+
'&_' + str(current_timestamp))
|
|
47
|
+
|
|
48
|
+
if proxies is None:
|
|
49
|
+
r = requests.get(url_new, headers=headers, timeout=time_out)
|
|
50
|
+
else:
|
|
51
|
+
r = requests.get(url_new, headers=headers, proxies=proxies, timeout=time_out)
|
|
52
|
+
result = r.content.decode("utf-8")
|
|
53
|
+
begin_index_total = result.index('"total":')
|
|
54
|
+
end_index_total = result.index('"diff"')
|
|
55
|
+
return int(result[begin_index_total + 8:end_index_total - 1])
|
|
56
|
+
except Exception as e:
|
|
57
|
+
logger.error("获取港股股票列表,实时行情异常:{}", e)
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_hk_real_time_quotes_page_df(pn, proxies, page_size, cookie, time_out):
|
|
62
|
+
try:
|
|
63
|
+
headers = {
|
|
64
|
+
'Cookie': cookie
|
|
65
|
+
}
|
|
66
|
+
current_timestamp = str(int(round(time.time() * 1000, 0)))
|
|
34
67
|
url_new = ('https://61.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112409497467688484127_' + str(
|
|
35
68
|
current_timestamp) +
|
|
36
69
|
'&pn=' + str(pn) +
|
|
37
|
-
'&pz=
|
|
70
|
+
'&pz=' + str(page_size) +
|
|
38
71
|
'&po=1'
|
|
39
72
|
'&np=3'
|
|
40
73
|
'&ut=bd1d9ddb04089700cf9c27f6f7426281'
|
|
@@ -47,291 +80,239 @@ def hk_real_time_quotes_page_df(cookie, pn, proxies):
|
|
|
47
80
|
'&_=' + str(current_timestamp))
|
|
48
81
|
|
|
49
82
|
if proxies is None:
|
|
50
|
-
r = requests.get(url_new, headers=headers)
|
|
83
|
+
r = requests.get(url_new, headers=headers, timeout=time_out)
|
|
51
84
|
else:
|
|
52
|
-
r = requests.get(url_new, headers=headers, proxies=proxies)
|
|
85
|
+
r = requests.get(url_new, headers=headers, proxies=proxies, timeout=time_out)
|
|
53
86
|
result = r.content.decode("utf-8")
|
|
54
|
-
|
|
55
|
-
if pn == 1:
|
|
56
|
-
try:
|
|
57
|
-
begin_index_total = result.index('"total":')
|
|
58
|
-
|
|
59
|
-
end_index_total = result.index('"diff"')
|
|
60
|
-
global max_number
|
|
61
|
-
max_number = int(result[begin_index_total + 8:end_index_total - 1])
|
|
62
|
-
except Exception as e:
|
|
63
|
-
logger.error(f"获取第{pn}页港股列表异常: {e}")
|
|
64
|
-
return pd.DataFrame()
|
|
65
|
-
|
|
66
87
|
startIndex = result.index('"diff"')
|
|
67
88
|
endIndex = result.index('}]}')
|
|
68
|
-
|
|
69
89
|
result = result[startIndex + 7:endIndex + 2]
|
|
70
|
-
|
|
71
90
|
data_json = json.loads(result)
|
|
72
|
-
|
|
73
91
|
temp_df = pd.DataFrame(data_json)
|
|
74
|
-
|
|
75
|
-
temp_df = temp_df.rename(columns={
|
|
76
|
-
|
|
77
|
-
"f12": "symbol",
|
|
78
|
-
"f14": "name",
|
|
79
|
-
"f3": "chg",
|
|
80
|
-
"f2": "now_price",
|
|
81
|
-
"f5": "volume",
|
|
82
|
-
"f6": "amount",
|
|
83
|
-
"f8": "exchange",
|
|
84
|
-
"f10": "quantity_ratio",
|
|
85
|
-
"f22": "up_speed",
|
|
86
|
-
"f11": "up_speed_05",
|
|
87
|
-
|
|
88
|
-
"f15": "high",
|
|
89
|
-
"f16": "low",
|
|
90
|
-
"f17": "open",
|
|
91
|
-
"f18": "yesterday_price",
|
|
92
|
-
"f20": "total_mv",
|
|
93
|
-
"f21": "flow_mv",
|
|
94
|
-
"f26": "list_date",
|
|
95
|
-
"f33": "wei_bi",
|
|
96
|
-
"f34": "outer_disk",
|
|
97
|
-
"f35": "inner_disk",
|
|
98
|
-
"f62": "today_main_net_inflow",
|
|
99
|
-
"f66": "super_large_order_net_inflow",
|
|
100
|
-
"f69": "super_large_order_net_inflow_ratio",
|
|
101
|
-
"f72": "large_order_net_inflow",
|
|
102
|
-
# "f78": "medium_order_net_inflow",
|
|
103
|
-
# "f84": "small_order_net_inflow",
|
|
104
|
-
"f100": "industry",
|
|
105
|
-
# "f103": "concept",
|
|
106
|
-
"f184": "today_main_net_inflow_ratio",
|
|
107
|
-
"f352": "average_price",
|
|
108
|
-
"f211": "buy_1_num",
|
|
109
|
-
"f212": "sell_1_num"
|
|
110
|
-
})
|
|
111
|
-
temp_df.loc[temp_df['buy_1_num'] == '-', 'buy_1_num'] = 0
|
|
112
|
-
temp_df.loc[temp_df['sell_1_num'] == '-', 'sell_1_num'] = 0
|
|
113
|
-
temp_df.loc[temp_df['up_speed_05'] == '-', 'up_speed_05'] = 0
|
|
114
|
-
temp_df.loc[temp_df['up_speed'] == '-', 'up_speed'] = 0
|
|
115
|
-
temp_df.loc[temp_df['average_price'] == '-', 'average_price'] = 0
|
|
116
|
-
temp_df.loc[temp_df['wei_bi'] == '-', 'wei_bi'] = 0
|
|
117
|
-
temp_df.loc[temp_df['yesterday_price'] == '-', 'yesterday_price'] = 0
|
|
118
|
-
temp_df.loc[temp_df['now_price'] == '-', 'now_price'] = 0
|
|
119
|
-
temp_df.loc[temp_df['chg'] == '-', 'chg'] = 0
|
|
120
|
-
temp_df.loc[temp_df['volume'] == '-', 'volume'] = 0
|
|
121
|
-
temp_df.loc[temp_df['amount'] == '-', 'amount'] = 0
|
|
122
|
-
temp_df.loc[temp_df['exchange'] == '-', 'exchange'] = 0
|
|
123
|
-
temp_df.loc[temp_df['quantity_ratio'] == '-', 'quantity_ratio'] = 0
|
|
124
|
-
temp_df.loc[temp_df['high'] == '-', 'high'] = 0
|
|
125
|
-
temp_df.loc[temp_df['low'] == '-', 'low'] = 0
|
|
126
|
-
temp_df.loc[temp_df['open'] == '-', 'open'] = 0
|
|
127
|
-
temp_df.loc[temp_df['total_mv'] == '-', 'total_mv'] = 0
|
|
128
|
-
temp_df.loc[temp_df['flow_mv'] == '-', 'flow_mv'] = 0
|
|
129
|
-
temp_df.loc[temp_df['inner_disk'] == '-', 'inner_disk'] = 0
|
|
130
|
-
temp_df.loc[temp_df['outer_disk'] == '-', 'outer_disk'] = 0
|
|
131
|
-
temp_df.loc[temp_df['today_main_net_inflow_ratio'] == '-', 'today_main_net_inflow_ratio'] = 0
|
|
132
|
-
temp_df.loc[temp_df['today_main_net_inflow'] == '-', 'today_main_net_inflow'] = 0
|
|
133
|
-
temp_df.loc[temp_df['super_large_order_net_inflow'] == '-', 'super_large_order_net_inflow'] = 0
|
|
134
|
-
temp_df.loc[temp_df['super_large_order_net_inflow_ratio'] == '-', 'super_large_order_net_inflow_ratio'] = 0
|
|
135
|
-
temp_df.loc[temp_df['large_order_net_inflow'] == '-', 'large_order_net_inflow'] = 0
|
|
136
|
-
# temp_df.loc[temp_df['medium_order_net_inflow'] == '-', 'medium_order_net_inflow'] = 0
|
|
137
|
-
# temp_df.loc[temp_df['small_order_net_inflow'] == '-', 'small_order_net_inflow'] = 0
|
|
138
|
-
|
|
139
|
-
temp_df["list_date"] = pd.to_numeric(temp_df["list_date"], errors="coerce")
|
|
140
|
-
temp_df["wei_bi"] = pd.to_numeric(temp_df["wei_bi"], errors="coerce")
|
|
141
|
-
temp_df["average_price"] = pd.to_numeric(temp_df["average_price"], errors="coerce")
|
|
142
|
-
temp_df["yesterday_price"] = pd.to_numeric(temp_df["yesterday_price"], errors="coerce")
|
|
143
|
-
temp_df["now_price"] = pd.to_numeric(temp_df["now_price"], errors="coerce")
|
|
144
|
-
temp_df["chg"] = pd.to_numeric(temp_df["chg"], errors="coerce")
|
|
145
|
-
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
|
|
146
|
-
temp_df["amount"] = pd.to_numeric(temp_df["amount"], errors="coerce")
|
|
147
|
-
temp_df["exchange"] = pd.to_numeric(temp_df["exchange"], errors="coerce")
|
|
148
|
-
temp_df["quantity_ratio"] = pd.to_numeric(temp_df["quantity_ratio"], errors="coerce")
|
|
149
|
-
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
|
|
150
|
-
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
|
|
151
|
-
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
|
|
152
|
-
temp_df["total_mv"] = pd.to_numeric(temp_df["total_mv"], errors="coerce")
|
|
153
|
-
temp_df["flow_mv"] = pd.to_numeric(temp_df["flow_mv"], errors="coerce")
|
|
154
|
-
temp_df["outer_disk"] = pd.to_numeric(temp_df["outer_disk"], errors="coerce")
|
|
155
|
-
temp_df["inner_disk"] = pd.to_numeric(temp_df["inner_disk"], errors="coerce")
|
|
156
|
-
temp_df["today_main_net_inflow"] = pd.to_numeric(temp_df["today_main_net_inflow"], errors="coerce")
|
|
157
|
-
temp_df["super_large_order_net_inflow"] = pd.to_numeric(temp_df["super_large_order_net_inflow"],
|
|
158
|
-
errors="coerce")
|
|
159
|
-
temp_df["super_large_order_net_inflow_ratio"] = pd.to_numeric(temp_df["super_large_order_net_inflow_ratio"],
|
|
160
|
-
errors="coerce")
|
|
161
|
-
temp_df["large_order_net_inflow"] = pd.to_numeric(temp_df["large_order_net_inflow"],
|
|
162
|
-
errors="coerce")
|
|
163
|
-
# temp_df["medium_order_net_inflow"] = pd.to_numeric(temp_df["medium_order_net_inflow"],
|
|
164
|
-
# errors="coerce")
|
|
165
|
-
# temp_df["small_order_net_inflow"] = pd.to_numeric(temp_df["small_order_net_inflow"], errors="coerce")
|
|
166
|
-
|
|
167
|
-
# 大单比例
|
|
168
|
-
temp_df['large_order_net_inflow_ratio'] = round((temp_df['large_order_net_inflow'] / temp_df['amount']) * 100,
|
|
169
|
-
2)
|
|
170
|
-
|
|
171
|
-
# 外盘是内盘倍数
|
|
172
|
-
temp_df['disk_ratio'] = round((temp_df['outer_disk'] - temp_df['inner_disk']) / temp_df['inner_disk'], 2)
|
|
173
|
-
# 只有外盘没有内盘
|
|
174
|
-
temp_df.loc[temp_df["inner_disk"] == 0, ['disk_ratio']] = 1688
|
|
175
|
-
temp_df['disk_diff_amount'] = round(
|
|
176
|
-
(temp_df['outer_disk'] - temp_df['inner_disk']) * temp_df[
|
|
177
|
-
"average_price"],
|
|
178
|
-
2)
|
|
179
92
|
return temp_df
|
|
180
93
|
except Exception as e:
|
|
181
94
|
logger.error("获取港股列表,实时行情异常:{}", e)
|
|
182
95
|
return pd.DataFrame()
|
|
183
96
|
|
|
184
97
|
|
|
185
|
-
|
|
98
|
+
# 改名
|
|
99
|
+
def rename_hk_field(temp_df):
|
|
100
|
+
temp_df = temp_df.rename(columns={
|
|
101
|
+
"f12": "symbol",
|
|
102
|
+
"f19": "voucher_type",
|
|
103
|
+
"f14": "name",
|
|
104
|
+
"f3": "chg",
|
|
105
|
+
"f2": "now_price",
|
|
106
|
+
"f5": "volume",
|
|
107
|
+
"f6": "amount",
|
|
108
|
+
"f8": "exchange",
|
|
109
|
+
"f10": "quantity_ratio",
|
|
110
|
+
"f22": "up_speed",
|
|
111
|
+
"f11": "up_speed_05",
|
|
112
|
+
"f15": "high",
|
|
113
|
+
"f16": "low",
|
|
114
|
+
"f17": "open",
|
|
115
|
+
"f18": "yesterday_price",
|
|
116
|
+
"f20": "total_mv",
|
|
117
|
+
"f21": "flow_mv",
|
|
118
|
+
"f26": "list_date",
|
|
119
|
+
"f33": "wei_bi",
|
|
120
|
+
"f34": "outer_disk",
|
|
121
|
+
"f35": "inner_disk",
|
|
122
|
+
"f62": "today_main_net_inflow",
|
|
123
|
+
"f66": "super_large_order_net_inflow",
|
|
124
|
+
"f69": "super_large_order_net_inflow_ratio",
|
|
125
|
+
"f72": "large_order_net_inflow",
|
|
126
|
+
# "f78": "medium_order_net_inflow",
|
|
127
|
+
# "f84": "small_order_net_inflow",
|
|
128
|
+
"f100": "industry",
|
|
129
|
+
"f103": "concept_name_str",
|
|
130
|
+
"f383": "concept_code_str",
|
|
131
|
+
"f184": "today_main_net_inflow_ratio",
|
|
132
|
+
"f352": "average_price",
|
|
133
|
+
"f211": "buy_1_num",
|
|
134
|
+
"f212": "sell_1_num"
|
|
135
|
+
})
|
|
136
|
+
temp_df.loc[temp_df['buy_1_num'] == '-', 'buy_1_num'] = 0
|
|
137
|
+
temp_df.loc[temp_df['sell_1_num'] == '-', 'sell_1_num'] = 0
|
|
138
|
+
temp_df.loc[temp_df['up_speed_05'] == '-', 'up_speed_05'] = 0
|
|
139
|
+
temp_df.loc[temp_df['up_speed'] == '-', 'up_speed'] = 0
|
|
140
|
+
temp_df.loc[temp_df['average_price'] == '-', 'average_price'] = 0
|
|
141
|
+
temp_df.loc[temp_df['wei_bi'] == '-', 'wei_bi'] = 0
|
|
142
|
+
temp_df.loc[temp_df['yesterday_price'] == '-', 'yesterday_price'] = 0
|
|
143
|
+
temp_df.loc[temp_df['now_price'] == '-', 'now_price'] = 0
|
|
144
|
+
temp_df.loc[temp_df['chg'] == '-', 'chg'] = 0
|
|
145
|
+
temp_df.loc[temp_df['volume'] == '-', 'volume'] = 0
|
|
146
|
+
temp_df.loc[temp_df['amount'] == '-', 'amount'] = 0
|
|
147
|
+
temp_df.loc[temp_df['exchange'] == '-', 'exchange'] = 0
|
|
148
|
+
temp_df.loc[temp_df['quantity_ratio'] == '-', 'quantity_ratio'] = 0
|
|
149
|
+
temp_df.loc[temp_df['high'] == '-', 'high'] = 0
|
|
150
|
+
temp_df.loc[temp_df['low'] == '-', 'low'] = 0
|
|
151
|
+
temp_df.loc[temp_df['open'] == '-', 'open'] = 0
|
|
152
|
+
temp_df.loc[temp_df['total_mv'] == '-', 'total_mv'] = 0
|
|
153
|
+
temp_df.loc[temp_df['flow_mv'] == '-', 'flow_mv'] = 0
|
|
154
|
+
temp_df.loc[temp_df['inner_disk'] == '-', 'inner_disk'] = 0
|
|
155
|
+
temp_df.loc[temp_df['outer_disk'] == '-', 'outer_disk'] = 0
|
|
156
|
+
temp_df.loc[temp_df['today_main_net_inflow_ratio'] == '-', 'today_main_net_inflow_ratio'] = 0
|
|
157
|
+
temp_df.loc[temp_df['today_main_net_inflow'] == '-', 'today_main_net_inflow'] = 0
|
|
158
|
+
temp_df.loc[temp_df['super_large_order_net_inflow'] == '-', 'super_large_order_net_inflow'] = 0
|
|
159
|
+
temp_df.loc[temp_df['super_large_order_net_inflow_ratio'] == '-', 'super_large_order_net_inflow_ratio'] = 0
|
|
160
|
+
temp_df.loc[temp_df['large_order_net_inflow'] == '-', 'large_order_net_inflow'] = 0
|
|
161
|
+
# temp_df.loc[temp_df['medium_order_net_inflow'] == '-', 'medium_order_net_inflow'] = 0
|
|
162
|
+
# temp_df.loc[temp_df['small_order_net_inflow'] == '-', 'small_order_net_inflow'] = 0
|
|
163
|
+
|
|
164
|
+
temp_df["list_date"] = pd.to_numeric(temp_df["list_date"], errors="coerce")
|
|
165
|
+
temp_df["wei_bi"] = pd.to_numeric(temp_df["wei_bi"], errors="coerce")
|
|
166
|
+
temp_df["average_price"] = pd.to_numeric(temp_df["average_price"], errors="coerce")
|
|
167
|
+
temp_df["yesterday_price"] = pd.to_numeric(temp_df["yesterday_price"], errors="coerce")
|
|
168
|
+
temp_df["now_price"] = pd.to_numeric(temp_df["now_price"], errors="coerce")
|
|
169
|
+
temp_df["chg"] = pd.to_numeric(temp_df["chg"], errors="coerce")
|
|
170
|
+
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
|
|
171
|
+
temp_df["amount"] = pd.to_numeric(temp_df["amount"], errors="coerce")
|
|
172
|
+
temp_df["exchange"] = pd.to_numeric(temp_df["exchange"], errors="coerce")
|
|
173
|
+
temp_df["quantity_ratio"] = pd.to_numeric(temp_df["quantity_ratio"], errors="coerce")
|
|
174
|
+
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
|
|
175
|
+
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
|
|
176
|
+
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
|
|
177
|
+
temp_df["total_mv"] = pd.to_numeric(temp_df["total_mv"], errors="coerce")
|
|
178
|
+
temp_df["flow_mv"] = pd.to_numeric(temp_df["flow_mv"], errors="coerce")
|
|
179
|
+
temp_df["outer_disk"] = pd.to_numeric(temp_df["outer_disk"], errors="coerce")
|
|
180
|
+
temp_df["inner_disk"] = pd.to_numeric(temp_df["inner_disk"], errors="coerce")
|
|
181
|
+
temp_df["today_main_net_inflow"] = pd.to_numeric(temp_df["today_main_net_inflow"], errors="coerce")
|
|
182
|
+
temp_df["super_large_order_net_inflow"] = pd.to_numeric(temp_df["super_large_order_net_inflow"],
|
|
183
|
+
errors="coerce")
|
|
184
|
+
temp_df["super_large_order_net_inflow_ratio"] = pd.to_numeric(temp_df["super_large_order_net_inflow_ratio"],
|
|
185
|
+
errors="coerce")
|
|
186
|
+
temp_df["large_order_net_inflow"] = pd.to_numeric(temp_df["large_order_net_inflow"],
|
|
187
|
+
errors="coerce")
|
|
188
|
+
# temp_df["medium_order_net_inflow"] = pd.to_numeric(temp_df["medium_order_net_inflow"],
|
|
189
|
+
# errors="coerce")
|
|
190
|
+
# temp_df["small_order_net_inflow"] = pd.to_numeric(temp_df["small_order_net_inflow"], errors="coerce")
|
|
191
|
+
|
|
192
|
+
# 大单比例
|
|
193
|
+
temp_df['large_order_net_inflow_ratio'] = round((temp_df['large_order_net_inflow'] / temp_df['amount']) * 100,
|
|
194
|
+
2)
|
|
195
|
+
|
|
196
|
+
# 外盘是内盘倍数
|
|
197
|
+
temp_df['disk_ratio'] = round((temp_df['outer_disk'] - temp_df['inner_disk']) / temp_df['inner_disk'], 2)
|
|
198
|
+
# 只有外盘没有内盘
|
|
199
|
+
temp_df.loc[temp_df["inner_disk"] == 0, ['disk_ratio']] = 1688
|
|
200
|
+
temp_df['disk_diff_amount'] = round(
|
|
201
|
+
(temp_df['outer_disk'] - temp_df['inner_disk']) * temp_df[
|
|
202
|
+
"average_price"],
|
|
203
|
+
2)
|
|
204
|
+
return temp_df
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def all_hk_stock_ticker_data_new(initial_proxies, time_out, em_cookie, max_number) -> pd.DataFrame:
|
|
208
|
+
"""
|
|
209
|
+
使用多线程获取所有股票数据,失败页面会使用新IP重试,最多使用10个IP
|
|
186
210
|
"""
|
|
187
|
-
使用多线程获取所有ETF数据
|
|
188
|
-
"""
|
|
189
|
-
# 计算总页数,假设总共有1000条数据,每页200条
|
|
190
|
-
|
|
191
211
|
per_page = page_number
|
|
192
212
|
total_pages = (max_number + per_page - 1) // per_page # 向上取整
|
|
193
|
-
|
|
194
|
-
#
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
all_pages = set(range(1, total_pages + 1)) # 所有需要获取的页码
|
|
214
|
+
success_pages = set() # 成功获取的页码
|
|
215
|
+
results = [] # 存储成功获取的数据
|
|
216
|
+
used_ip_count = 1 # 已使用IP计数器(初始IP算第一个)
|
|
217
|
+
MAX_IP_LIMIT = 10 # IP使用上限
|
|
218
|
+
|
|
219
|
+
# 循环处理直到所有页面成功或达到IP上限
|
|
220
|
+
while (all_pages - success_pages) and (used_ip_count < MAX_IP_LIMIT):
|
|
221
|
+
# 获取当前需要处理的失败页码
|
|
222
|
+
current_failed_pages = all_pages - success_pages
|
|
223
|
+
if used_ip_count > 1:
|
|
224
|
+
logger.info("当前需要处理的失败页码: {}, 已使用IP数量: {}/{}", current_failed_pages, used_ip_count,
|
|
225
|
+
MAX_IP_LIMIT)
|
|
226
|
+
|
|
227
|
+
# 首次使用初始代理,后续获取新代理
|
|
228
|
+
if len(success_pages) == 0:
|
|
229
|
+
proxies = initial_proxies
|
|
230
|
+
else:
|
|
231
|
+
# 每次重试前获取新代理并计数
|
|
232
|
+
# logger.info("获取新代理IP处理失败页面")
|
|
233
|
+
new_proxy_ip = proxy_common_api.generate_proxy_ip_api(1)
|
|
234
|
+
proxies = {"https": new_proxy_ip}
|
|
235
|
+
# logger.info("新代理IP: {}, 已使用IP数量: {}/{}", new_proxy_ip, used_ip_count + 1, MAX_IP_LIMIT)
|
|
236
|
+
used_ip_count += 1 # 增加IP计数器
|
|
237
|
+
|
|
238
|
+
# 创建线程池处理当前失败的页码
|
|
239
|
+
with ThreadPoolExecutor(max_workers=10) as executor:
|
|
240
|
+
futures = {
|
|
241
|
+
executor.submit(get_hk_real_time_quotes_page_df, pn, proxies,
|
|
242
|
+
per_page, em_cookie, time_out): pn
|
|
243
|
+
for pn in current_failed_pages
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
# 收集结果并记录成功页码
|
|
247
|
+
for future, pn in futures.items():
|
|
248
|
+
try:
|
|
249
|
+
result = future.result()
|
|
250
|
+
if not result.empty:
|
|
251
|
+
results.append(result)
|
|
252
|
+
success_pages.add(pn)
|
|
253
|
+
# else:
|
|
254
|
+
# logger.warning("页码 {} 未返回有效数据", pn)
|
|
255
|
+
except Exception as e:
|
|
256
|
+
continue
|
|
257
|
+
# logger.error("页码 {} 处理异常: {}", pn, str(e))
|
|
258
|
+
|
|
259
|
+
# 检查是否达到IP上限
|
|
260
|
+
if used_ip_count >= MAX_IP_LIMIT and (all_pages - success_pages):
|
|
261
|
+
remaining_pages = all_pages - success_pages
|
|
262
|
+
logger.warning("已达到最大IP使用限制({}个),剩余未获取页码: {}, 返回现有数据", MAX_IP_LIMIT, remaining_pages)
|
|
263
|
+
|
|
264
|
+
# 合并所有成功获取的数据
|
|
208
265
|
if results:
|
|
209
266
|
return pd.concat(results, ignore_index=True)
|
|
210
267
|
else:
|
|
211
268
|
return pd.DataFrame()
|
|
212
269
|
|
|
213
270
|
|
|
214
|
-
def get_hk_real_time_quotes(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
271
|
+
def get_hk_real_time_quotes(time_out, em_cookie):
|
|
272
|
+
try_numer = 3
|
|
273
|
+
while try_numer > 0:
|
|
274
|
+
proxy_ip = proxy_common_api.generate_proxy_ip_api(1)
|
|
275
|
+
initial_proxies = {"https": proxy_ip,
|
|
276
|
+
"http": proxy_ip}
|
|
277
|
+
|
|
278
|
+
max_number = get_hk_stock_count(1, initial_proxies, 20, em_cookie, time_out)
|
|
279
|
+
if max_number > 0:
|
|
280
|
+
break
|
|
281
|
+
try_numer = try_numer - 1
|
|
282
|
+
if max_number == 0:
|
|
283
|
+
max_number = 5000
|
|
284
|
+
all_hk_stock_ticker_data_new_df = all_hk_stock_ticker_data_new(initial_proxies, time_out, em_cookie, max_number)
|
|
285
|
+
return rename_hk_field(all_hk_stock_ticker_data_new_df)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def get_hk_real_time_quotes_local_ip(time_out, em_cookie):
|
|
289
|
+
try_numer = 3
|
|
290
|
+
while try_numer > 0:
|
|
291
|
+
max_number = get_hk_stock_count(1, None, 20, em_cookie, time_out)
|
|
292
|
+
if max_number > 0:
|
|
293
|
+
break
|
|
294
|
+
try_numer = try_numer - 1
|
|
295
|
+
if max_number == 0:
|
|
296
|
+
max_number = 6000
|
|
297
|
+
total_pages = (max_number + page_number - 1) // page_number # 向上取整
|
|
298
|
+
results_df = pd.DataFrame()
|
|
229
299
|
pn = 1
|
|
230
|
-
|
|
231
|
-
"""
|
|
232
|
-
东方财富网-行情中心-港股市场-港股通成份股
|
|
233
|
-
https://quote.eastmoney.com/center/gridlist.html#hk_components
|
|
234
|
-
:return: 港股通成份股
|
|
235
|
-
:rtype: pandas.DataFrame
|
|
236
|
-
"""
|
|
237
|
-
result_df = pd.DataFrame()
|
|
238
|
-
while True:
|
|
239
|
-
url = "https://33.push2.eastmoney.com/api/qt/clist/get"
|
|
240
|
-
params = {
|
|
241
|
-
"pn": str(pn),
|
|
242
|
-
"pz": "5000",
|
|
243
|
-
"po": "1",
|
|
244
|
-
"np": "2",
|
|
245
|
-
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
|
246
|
-
"fltt": "2",
|
|
247
|
-
"fid": "f3",
|
|
248
|
-
"fs": "b:DLMK0146,b:DLMK0144",
|
|
249
|
-
"fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f23,f24,"
|
|
250
|
-
"f25,f26,f22,f33,f11,f62,f128,f136,f115,f152",
|
|
251
|
-
"_": "1639974456250",
|
|
252
|
-
}
|
|
300
|
+
while pn <= total_pages:
|
|
253
301
|
try:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
temp_df = pd.DataFrame(data_json["data"]["diff"]).T
|
|
261
|
-
temp_df.reset_index(inplace=True)
|
|
262
|
-
temp_df["index"] = temp_df.index + 1
|
|
263
|
-
|
|
264
|
-
temp_df.columns = [
|
|
265
|
-
"序号",
|
|
266
|
-
"-",
|
|
267
|
-
"最新价",
|
|
268
|
-
"涨跌幅",
|
|
269
|
-
"涨跌额",
|
|
270
|
-
"成交量",
|
|
271
|
-
"成交额",
|
|
272
|
-
"-",
|
|
273
|
-
"-",
|
|
274
|
-
"-",
|
|
275
|
-
"-",
|
|
276
|
-
"-",
|
|
277
|
-
"代码",
|
|
278
|
-
"-",
|
|
279
|
-
"名称",
|
|
280
|
-
"最高",
|
|
281
|
-
"最低",
|
|
282
|
-
"今开",
|
|
283
|
-
"昨收",
|
|
284
|
-
"-",
|
|
285
|
-
"-",
|
|
286
|
-
"-",
|
|
287
|
-
"-",
|
|
288
|
-
"-",
|
|
289
|
-
"-",
|
|
290
|
-
"-",
|
|
291
|
-
"-",
|
|
292
|
-
"-",
|
|
293
|
-
"-",
|
|
294
|
-
"-",
|
|
295
|
-
"-",
|
|
296
|
-
"-",
|
|
297
|
-
"-",
|
|
298
|
-
"-",
|
|
299
|
-
"-",
|
|
300
|
-
]
|
|
301
|
-
temp_df = temp_df[
|
|
302
|
-
[
|
|
303
|
-
"序号",
|
|
304
|
-
"代码",
|
|
305
|
-
"名称",
|
|
306
|
-
"最新价",
|
|
307
|
-
"涨跌额",
|
|
308
|
-
"涨跌幅",
|
|
309
|
-
"今开",
|
|
310
|
-
"最高",
|
|
311
|
-
"最低",
|
|
312
|
-
"昨收",
|
|
313
|
-
"成交量",
|
|
314
|
-
"成交额",
|
|
315
|
-
]
|
|
316
|
-
]
|
|
317
|
-
result_df = pd.concat([result_df, temp_df])
|
|
318
|
-
if temp_df.shape[0] < page_number:
|
|
319
|
-
break
|
|
302
|
+
page_df = get_hk_real_time_quotes_page_df(pn, None, page_number, em_cookie, time_out)
|
|
303
|
+
while data_frame_util.is_empty(page_df):
|
|
304
|
+
page_df = get_hk_real_time_quotes_page_df(pn, None, page_number, em_cookie, time_out)
|
|
305
|
+
time.sleep(1)
|
|
306
|
+
results_df = pd.concat([results_df, page_df])
|
|
307
|
+
logger.info("同步HK市场STOCK第几{}页成功", pn)
|
|
320
308
|
pn = pn + 1
|
|
321
|
-
except
|
|
322
|
-
logger.error("
|
|
323
|
-
return
|
|
309
|
+
except BaseException as e:
|
|
310
|
+
logger.error("同步HK市场STOCK信息失败:{},{}", e, pn)
|
|
311
|
+
return rename_hk_field(results_df)
|
|
324
312
|
|
|
325
313
|
|
|
326
314
|
if __name__ == '__main__':
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
df_hk_df = get_hk_real_time_quotes(cookie_test, None)
|
|
332
|
-
df_hk_df = df_hk_df[[
|
|
333
|
-
"symbol",
|
|
334
|
-
"name",
|
|
335
|
-
"chg", "amount"
|
|
336
|
-
]]
|
|
337
|
-
logger.info('test')
|
|
315
|
+
em_cookie_test = cookie_info_service.get_em_cookie()
|
|
316
|
+
test_df = get_hk_real_time_quotes_local_ip(30, em_cookie_test)
|
|
317
|
+
test_df = test_df.sort_values(by=['amount'], ascending=False)
|
|
318
|
+
print(test_df)
|