mns-common 1.4.1.8__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.
- 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 +10 -3
- 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 +140 -70
- mns_common/api/em/real_time/east_money_etf_api.py +138 -27
- mns_common/api/em/real_time/east_money_stock_a_api.py +24 -28
- 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 +223 -272
- mns_common/api/em/real_time/east_money_stock_hk_gtt_api.py +260 -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 +146 -82
- mns_common/api/em/real_time/real_time_quotes_repeat_api.py +195 -0
- mns_common/api/k_line/stock_k_line_data_api.py +11 -1
- mns_common/api/kpl/common/kpl_common_api.py +35 -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/xueqiu/xue_qiu_k_line_api.py +2 -2
- mns_common/component/common_service_fun_api.py +26 -6
- 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 +9 -3
- mns_common/component/main_line/main_line_zt_reason_service.py +237 -0
- mns_common/component/proxies/proxy_common_api.py +141 -45
- mns_common/component/us/us_stock_etf_info_api.py +125 -0
- mns_common/constant/db_name_constant.py +40 -16
- mns_common/constant/extra_income_db_name.py +79 -19
- mns_common/constant/strategy_classify.py +17 -2
- mns_common/db/MongodbUtil.py +3 -0
- mns_common/db/MongodbUtilLocal.py +3 -0
- {mns_common-1.4.1.8.dist-info → mns_common-1.5.7.2.dist-info}/METADATA +1 -1
- {mns_common-1.4.1.8.dist-info → mns_common-1.5.7.2.dist-info}/RECORD +47 -41
- 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 -110
- /mns_common/component/{qmt → main_line}/__init__.py +0 -0
- /mns_common/component/{task → us}/__init__.py +0 -0
- {mns_common-1.4.1.8.dist-info → mns_common-1.5.7.2.dist-info}/WHEEL +0 -0
- {mns_common-1.4.1.8.dist-info → mns_common-1.5.7.2.dist-info}/top_level.txt +0 -0
|
@@ -5,36 +5,68 @@ 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
|
|
14
16
|
|
|
15
|
-
# 最大返回条数
|
|
16
|
-
max_number = 4500
|
|
17
|
-
# 最小返回条数
|
|
18
|
-
min_number = 4400
|
|
19
17
|
# 分页条数
|
|
20
18
|
page_number = 100
|
|
21
19
|
|
|
22
20
|
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
|
+
"f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212,f103,f383")
|
|
24
22
|
|
|
25
23
|
|
|
26
|
-
def
|
|
24
|
+
def get_hk_stock_count(pn, proxies, page_size, cookie, time_out):
|
|
27
25
|
try:
|
|
28
26
|
headers = {
|
|
29
27
|
'Cookie': cookie
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
current_timestamp = str(int(round(time.time() * 1000, 0)))
|
|
33
30
|
|
|
31
|
+
url_new = ('https://push2.eastmoney.com/api/qt/clist/get?cb=jQuery371026074131356896413_' + str(
|
|
32
|
+
current_timestamp) +
|
|
33
|
+
'&np=1'
|
|
34
|
+
'&fltt=1'
|
|
35
|
+
'&invt=2'
|
|
36
|
+
'&fs=m:128+t:3,m:128+t:4,m:128+t:1,m:128+t:2'
|
|
37
|
+
'&fields=' + fields +
|
|
38
|
+
'&fid=f12'
|
|
39
|
+
'&pn=' + str(pn) +
|
|
40
|
+
'&pz=' + str(page_size) +
|
|
41
|
+
'&po=1'
|
|
42
|
+
'&dect=1'
|
|
43
|
+
'&ut=fa5fd1943c7b386f172d6893dbfba10b'
|
|
44
|
+
'&wbp2u=4253366368931142|0|1|0|web'
|
|
45
|
+
'&_' + str(current_timestamp))
|
|
46
|
+
|
|
47
|
+
if proxies is None:
|
|
48
|
+
r = requests.get(url_new, headers=headers, timeout=time_out)
|
|
49
|
+
else:
|
|
50
|
+
r = requests.get(url_new, headers=headers, proxies=proxies, timeout=time_out)
|
|
51
|
+
result = r.content.decode("utf-8")
|
|
52
|
+
begin_index_total = result.index('"total":')
|
|
53
|
+
end_index_total = result.index('"diff"')
|
|
54
|
+
return int(result[begin_index_total + 8:end_index_total - 1])
|
|
55
|
+
except Exception as e:
|
|
56
|
+
logger.error("获取港股股票列表,实时行情异常:{}", e)
|
|
57
|
+
return 0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_hk_real_time_quotes_page_df(pn, proxies, page_size, cookie, time_out):
|
|
61
|
+
try:
|
|
62
|
+
headers = {
|
|
63
|
+
'Cookie': cookie
|
|
64
|
+
}
|
|
65
|
+
current_timestamp = str(int(round(time.time() * 1000, 0)))
|
|
34
66
|
url_new = ('https://61.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112409497467688484127_' + str(
|
|
35
67
|
current_timestamp) +
|
|
36
68
|
'&pn=' + str(pn) +
|
|
37
|
-
'&pz=
|
|
69
|
+
'&pz=' + str(page_size) +
|
|
38
70
|
'&po=1'
|
|
39
71
|
'&np=3'
|
|
40
72
|
'&ut=bd1d9ddb04089700cf9c27f6f7426281'
|
|
@@ -47,291 +79,210 @@ def hk_real_time_quotes_page_df(cookie, pn, proxies):
|
|
|
47
79
|
'&_=' + str(current_timestamp))
|
|
48
80
|
|
|
49
81
|
if proxies is None:
|
|
50
|
-
r = requests.get(url_new, headers=headers)
|
|
82
|
+
r = requests.get(url_new, headers=headers, timeout=time_out)
|
|
51
83
|
else:
|
|
52
|
-
r = requests.get(url_new, headers=headers, proxies=proxies)
|
|
84
|
+
r = requests.get(url_new, headers=headers, proxies=proxies, timeout=time_out)
|
|
53
85
|
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
86
|
startIndex = result.index('"diff"')
|
|
67
87
|
endIndex = result.index('}]}')
|
|
68
|
-
|
|
69
88
|
result = result[startIndex + 7:endIndex + 2]
|
|
70
|
-
|
|
71
89
|
data_json = json.loads(result)
|
|
72
|
-
|
|
73
90
|
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
91
|
return temp_df
|
|
180
92
|
except Exception as e:
|
|
181
93
|
logger.error("获取港股列表,实时行情异常:{}", e)
|
|
182
94
|
return pd.DataFrame()
|
|
183
95
|
|
|
184
96
|
|
|
185
|
-
|
|
97
|
+
# 改名
|
|
98
|
+
def rename_hk_field(temp_df):
|
|
99
|
+
temp_df = temp_df.rename(columns={
|
|
100
|
+
"f12": "symbol",
|
|
101
|
+
"f14": "name",
|
|
102
|
+
"f3": "chg",
|
|
103
|
+
"f2": "now_price",
|
|
104
|
+
"f5": "volume",
|
|
105
|
+
"f6": "amount",
|
|
106
|
+
"f8": "exchange",
|
|
107
|
+
"f10": "quantity_ratio",
|
|
108
|
+
"f22": "up_speed",
|
|
109
|
+
"f11": "up_speed_05",
|
|
110
|
+
"f15": "high",
|
|
111
|
+
"f16": "low",
|
|
112
|
+
"f17": "open",
|
|
113
|
+
"f18": "yesterday_price",
|
|
114
|
+
"f20": "total_mv",
|
|
115
|
+
"f21": "flow_mv",
|
|
116
|
+
"f26": "list_date",
|
|
117
|
+
"f33": "wei_bi",
|
|
118
|
+
"f34": "outer_disk",
|
|
119
|
+
"f35": "inner_disk",
|
|
120
|
+
"f62": "today_main_net_inflow",
|
|
121
|
+
"f66": "super_large_order_net_inflow",
|
|
122
|
+
"f69": "super_large_order_net_inflow_ratio",
|
|
123
|
+
"f72": "large_order_net_inflow",
|
|
124
|
+
# "f78": "medium_order_net_inflow",
|
|
125
|
+
# "f84": "small_order_net_inflow",
|
|
126
|
+
"f100": "industry",
|
|
127
|
+
"f103": "concept_name_str",
|
|
128
|
+
"f383": "concept_code_str",
|
|
129
|
+
"f184": "today_main_net_inflow_ratio",
|
|
130
|
+
"f352": "average_price",
|
|
131
|
+
"f211": "buy_1_num",
|
|
132
|
+
"f212": "sell_1_num"
|
|
133
|
+
})
|
|
134
|
+
temp_df.loc[temp_df['buy_1_num'] == '-', 'buy_1_num'] = 0
|
|
135
|
+
temp_df.loc[temp_df['sell_1_num'] == '-', 'sell_1_num'] = 0
|
|
136
|
+
temp_df.loc[temp_df['up_speed_05'] == '-', 'up_speed_05'] = 0
|
|
137
|
+
temp_df.loc[temp_df['up_speed'] == '-', 'up_speed'] = 0
|
|
138
|
+
temp_df.loc[temp_df['average_price'] == '-', 'average_price'] = 0
|
|
139
|
+
temp_df.loc[temp_df['wei_bi'] == '-', 'wei_bi'] = 0
|
|
140
|
+
temp_df.loc[temp_df['yesterday_price'] == '-', 'yesterday_price'] = 0
|
|
141
|
+
temp_df.loc[temp_df['now_price'] == '-', 'now_price'] = 0
|
|
142
|
+
temp_df.loc[temp_df['chg'] == '-', 'chg'] = 0
|
|
143
|
+
temp_df.loc[temp_df['volume'] == '-', 'volume'] = 0
|
|
144
|
+
temp_df.loc[temp_df['amount'] == '-', 'amount'] = 0
|
|
145
|
+
temp_df.loc[temp_df['exchange'] == '-', 'exchange'] = 0
|
|
146
|
+
temp_df.loc[temp_df['quantity_ratio'] == '-', 'quantity_ratio'] = 0
|
|
147
|
+
temp_df.loc[temp_df['high'] == '-', 'high'] = 0
|
|
148
|
+
temp_df.loc[temp_df['low'] == '-', 'low'] = 0
|
|
149
|
+
temp_df.loc[temp_df['open'] == '-', 'open'] = 0
|
|
150
|
+
temp_df.loc[temp_df['total_mv'] == '-', 'total_mv'] = 0
|
|
151
|
+
temp_df.loc[temp_df['flow_mv'] == '-', 'flow_mv'] = 0
|
|
152
|
+
temp_df.loc[temp_df['inner_disk'] == '-', 'inner_disk'] = 0
|
|
153
|
+
temp_df.loc[temp_df['outer_disk'] == '-', 'outer_disk'] = 0
|
|
154
|
+
temp_df.loc[temp_df['today_main_net_inflow_ratio'] == '-', 'today_main_net_inflow_ratio'] = 0
|
|
155
|
+
temp_df.loc[temp_df['today_main_net_inflow'] == '-', 'today_main_net_inflow'] = 0
|
|
156
|
+
temp_df.loc[temp_df['super_large_order_net_inflow'] == '-', 'super_large_order_net_inflow'] = 0
|
|
157
|
+
temp_df.loc[temp_df['super_large_order_net_inflow_ratio'] == '-', 'super_large_order_net_inflow_ratio'] = 0
|
|
158
|
+
temp_df.loc[temp_df['large_order_net_inflow'] == '-', 'large_order_net_inflow'] = 0
|
|
159
|
+
# temp_df.loc[temp_df['medium_order_net_inflow'] == '-', 'medium_order_net_inflow'] = 0
|
|
160
|
+
# temp_df.loc[temp_df['small_order_net_inflow'] == '-', 'small_order_net_inflow'] = 0
|
|
161
|
+
|
|
162
|
+
temp_df["list_date"] = pd.to_numeric(temp_df["list_date"], errors="coerce")
|
|
163
|
+
temp_df["wei_bi"] = pd.to_numeric(temp_df["wei_bi"], errors="coerce")
|
|
164
|
+
temp_df["average_price"] = pd.to_numeric(temp_df["average_price"], errors="coerce")
|
|
165
|
+
temp_df["yesterday_price"] = pd.to_numeric(temp_df["yesterday_price"], errors="coerce")
|
|
166
|
+
temp_df["now_price"] = pd.to_numeric(temp_df["now_price"], errors="coerce")
|
|
167
|
+
temp_df["chg"] = pd.to_numeric(temp_df["chg"], errors="coerce")
|
|
168
|
+
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
|
|
169
|
+
temp_df["amount"] = pd.to_numeric(temp_df["amount"], errors="coerce")
|
|
170
|
+
temp_df["exchange"] = pd.to_numeric(temp_df["exchange"], errors="coerce")
|
|
171
|
+
temp_df["quantity_ratio"] = pd.to_numeric(temp_df["quantity_ratio"], errors="coerce")
|
|
172
|
+
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
|
|
173
|
+
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
|
|
174
|
+
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
|
|
175
|
+
temp_df["total_mv"] = pd.to_numeric(temp_df["total_mv"], errors="coerce")
|
|
176
|
+
temp_df["flow_mv"] = pd.to_numeric(temp_df["flow_mv"], errors="coerce")
|
|
177
|
+
temp_df["outer_disk"] = pd.to_numeric(temp_df["outer_disk"], errors="coerce")
|
|
178
|
+
temp_df["inner_disk"] = pd.to_numeric(temp_df["inner_disk"], errors="coerce")
|
|
179
|
+
temp_df["today_main_net_inflow"] = pd.to_numeric(temp_df["today_main_net_inflow"], errors="coerce")
|
|
180
|
+
temp_df["super_large_order_net_inflow"] = pd.to_numeric(temp_df["super_large_order_net_inflow"],
|
|
181
|
+
errors="coerce")
|
|
182
|
+
temp_df["super_large_order_net_inflow_ratio"] = pd.to_numeric(temp_df["super_large_order_net_inflow_ratio"],
|
|
183
|
+
errors="coerce")
|
|
184
|
+
temp_df["large_order_net_inflow"] = pd.to_numeric(temp_df["large_order_net_inflow"],
|
|
185
|
+
errors="coerce")
|
|
186
|
+
# temp_df["medium_order_net_inflow"] = pd.to_numeric(temp_df["medium_order_net_inflow"],
|
|
187
|
+
# errors="coerce")
|
|
188
|
+
# temp_df["small_order_net_inflow"] = pd.to_numeric(temp_df["small_order_net_inflow"], errors="coerce")
|
|
189
|
+
|
|
190
|
+
# 大单比例
|
|
191
|
+
temp_df['large_order_net_inflow_ratio'] = round((temp_df['large_order_net_inflow'] / temp_df['amount']) * 100,
|
|
192
|
+
2)
|
|
193
|
+
|
|
194
|
+
# 外盘是内盘倍数
|
|
195
|
+
temp_df['disk_ratio'] = round((temp_df['outer_disk'] - temp_df['inner_disk']) / temp_df['inner_disk'], 2)
|
|
196
|
+
# 只有外盘没有内盘
|
|
197
|
+
temp_df.loc[temp_df["inner_disk"] == 0, ['disk_ratio']] = 1688
|
|
198
|
+
temp_df['disk_diff_amount'] = round(
|
|
199
|
+
(temp_df['outer_disk'] - temp_df['inner_disk']) * temp_df[
|
|
200
|
+
"average_price"],
|
|
201
|
+
2)
|
|
202
|
+
return temp_df
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def all_hk_stock_ticker_data_new(initial_proxies, time_out, em_cookie, max_number) -> pd.DataFrame:
|
|
206
|
+
"""
|
|
207
|
+
使用多线程获取所有股票数据,失败页面会使用新IP重试,最多使用10个IP
|
|
186
208
|
"""
|
|
187
|
-
使用多线程获取所有ETF数据
|
|
188
|
-
"""
|
|
189
|
-
# 计算总页数,假设总共有1000条数据,每页200条
|
|
190
|
-
|
|
191
209
|
per_page = page_number
|
|
192
210
|
total_pages = (max_number + per_page - 1) // per_page # 向上取整
|
|
193
|
-
|
|
194
|
-
#
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
211
|
+
all_pages = set(range(1, total_pages + 1)) # 所有需要获取的页码
|
|
212
|
+
success_pages = set() # 成功获取的页码
|
|
213
|
+
results = [] # 存储成功获取的数据
|
|
214
|
+
used_ip_count = 1 # 已使用IP计数器(初始IP算第一个)
|
|
215
|
+
MAX_IP_LIMIT = 10 # IP使用上限
|
|
216
|
+
|
|
217
|
+
# 循环处理直到所有页面成功或达到IP上限
|
|
218
|
+
while (all_pages - success_pages) and (used_ip_count < MAX_IP_LIMIT):
|
|
219
|
+
# 获取当前需要处理的失败页码
|
|
220
|
+
current_failed_pages = all_pages - success_pages
|
|
221
|
+
if used_ip_count > 1:
|
|
222
|
+
logger.info("当前需要处理的失败页码: {}, 已使用IP数量: {}/{}", current_failed_pages, used_ip_count,
|
|
223
|
+
MAX_IP_LIMIT)
|
|
224
|
+
|
|
225
|
+
# 首次使用初始代理,后续获取新代理
|
|
226
|
+
if len(success_pages) == 0:
|
|
227
|
+
proxies = initial_proxies
|
|
228
|
+
else:
|
|
229
|
+
# 每次重试前获取新代理并计数
|
|
230
|
+
# logger.info("获取新代理IP处理失败页面")
|
|
231
|
+
new_proxy_ip = proxy_common_api.generate_proxy_ip_api(1)
|
|
232
|
+
proxies = {"https": new_proxy_ip}
|
|
233
|
+
# logger.info("新代理IP: {}, 已使用IP数量: {}/{}", new_proxy_ip, used_ip_count + 1, MAX_IP_LIMIT)
|
|
234
|
+
used_ip_count += 1 # 增加IP计数器
|
|
235
|
+
|
|
236
|
+
# 创建线程池处理当前失败的页码
|
|
237
|
+
with ThreadPoolExecutor(max_workers=10) as executor:
|
|
238
|
+
futures = {
|
|
239
|
+
executor.submit(get_hk_real_time_quotes_page_df, pn, proxies,
|
|
240
|
+
per_page, em_cookie, time_out): pn
|
|
241
|
+
for pn in current_failed_pages
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# 收集结果并记录成功页码
|
|
245
|
+
for future, pn in futures.items():
|
|
246
|
+
try:
|
|
247
|
+
result = future.result()
|
|
248
|
+
if not result.empty:
|
|
249
|
+
results.append(result)
|
|
250
|
+
success_pages.add(pn)
|
|
251
|
+
# else:
|
|
252
|
+
# logger.warning("页码 {} 未返回有效数据", pn)
|
|
253
|
+
except Exception as e:
|
|
254
|
+
continue
|
|
255
|
+
# logger.error("页码 {} 处理异常: {}", pn, str(e))
|
|
256
|
+
|
|
257
|
+
# 检查是否达到IP上限
|
|
258
|
+
if used_ip_count >= MAX_IP_LIMIT and (all_pages - success_pages):
|
|
259
|
+
remaining_pages = all_pages - success_pages
|
|
260
|
+
logger.warning("已达到最大IP使用限制({}个),剩余未获取页码: {}, 返回现有数据", MAX_IP_LIMIT, remaining_pages)
|
|
261
|
+
|
|
262
|
+
# 合并所有成功获取的数据
|
|
208
263
|
if results:
|
|
209
264
|
return pd.concat(results, ignore_index=True)
|
|
210
265
|
else:
|
|
211
266
|
return pd.DataFrame()
|
|
212
267
|
|
|
213
268
|
|
|
214
|
-
def get_hk_real_time_quotes(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return page_one_df
|
|
221
|
-
else:
|
|
222
|
-
page_df = thread_pool_executor(cookie, proxies)
|
|
223
|
-
page_df.drop_duplicates('symbol', keep='last', inplace=True)
|
|
224
|
-
return page_df
|
|
269
|
+
def get_hk_real_time_quotes(time_out, em_cookie):
|
|
270
|
+
try_numer = 3
|
|
271
|
+
while try_numer > 0:
|
|
272
|
+
proxy_ip = proxy_common_api.generate_proxy_ip_api(1)
|
|
273
|
+
initial_proxies = {"https": proxy_ip,
|
|
274
|
+
"http": proxy_ip}
|
|
225
275
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
}
|
|
253
|
-
try:
|
|
254
|
-
if proxies is None:
|
|
255
|
-
r = requests.get(url, params=params)
|
|
256
|
-
else:
|
|
257
|
-
r = requests.get(url, params=params, proxies=proxies)
|
|
258
|
-
|
|
259
|
-
data_json = r.json()
|
|
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
|
|
320
|
-
pn = pn + 1
|
|
321
|
-
except Exception as e:
|
|
322
|
-
logger.error("获取港股通列表:{}", e)
|
|
323
|
-
return result_df
|
|
276
|
+
max_number = get_hk_stock_count(1, initial_proxies, 20, em_cookie, time_out)
|
|
277
|
+
if max_number > 0:
|
|
278
|
+
break
|
|
279
|
+
try_numer = try_numer - 1
|
|
280
|
+
if max_number == 0:
|
|
281
|
+
return pd.DataFrame()
|
|
282
|
+
all_hk_stock_ticker_data_new_df = all_hk_stock_ticker_data_new(initial_proxies, time_out, em_cookie, max_number)
|
|
283
|
+
return rename_hk_field(all_hk_stock_ticker_data_new_df)
|
|
324
284
|
|
|
325
285
|
|
|
326
286
|
if __name__ == '__main__':
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
cookie_test = 'qgqp_b_id=1e0d79428176ed54bef8434efdc0e8c3; mtp=1; ct=QVRY_s8Tiag1WfK2tSW2n03qpsX-PD8aH_rIjKVooawX8K33UVnpIofK088lD1lguWlE_OEIpQwn3PJWFPhHvSvyvYr4Zka3l4vxtZfH1Uikjtyy9z1H4Swo0rQzMKXncVzBXiOo5TjE-Dy9fcoG3ZF7UVdQ35jp_cFwzOlpK5Y; ut=FobyicMgeV51lVMr4ZJXvn-72bp0oeSOvtzifFY_U7kBFtR6og4Usd-VtBM5XBBvHq0lvd9xXkvpIqWro9EDKmv6cbKOQGyawUSMcKVP57isZCaM7lWQ6jWXajvTfvV4mIR-W_MZNK8VY0lL9W4qNMniJ6PBn_gkJsSAJCadmsyI9cxmjx--gR4m54pdF_nie_y4iWHys83cmWR2R7Bt1KKqB25OmkfCQTJJqIf7QsqangVGMUHwMC39Z9QhrfCFHKVNrlqS503O6b9GitQnXtvUdJhCmomu; pi=4253366368931142%3Bp4253366368931142%3B%E8%82%A1%E5%8F%8B9x56I87727%3BYNigLZRW%2FzMdGgVDOJbwReDWnTPHl51dB0gQLiwaCf1XY98mlJYx6eJbsoYr5Nie%2BX1L%2BzaMsec99KkX%2BT29Ds1arfST7sIBXxjUQ3dp11IPUnXy64PaBFRTHzMRWnCFJvvhc%2FAI41rXSGXolC8YMxI%2BvyPS%2BuErwgOVjC5vvsIiKeO7TLyKkhqqQJPX%2F7RWC5Sf3QLh%3Bdwjn4Xho10%2FKjqOgTWs%2FJF4%2FkdKzeuBwM8sz9aLvJovejAkCAyGMyGYA6AE67Xk2Ki7x8zdfBifF2DG%2Fvf2%2BXAYN8ZVISSEWTIXh32Z5MxEacK4JBTkqyiD93e1vFBOFQ82BqaiVmntUq0V6FrTUHGeh1gG5Sg%3D%3D; uidal=4253366368931142%e8%82%a1%e5%8f%8b9x56I87727; sid=170711377; vtpst=|; quote_lt=1; websitepoptg_api_time=1715777390466; emshistory=%5B%22%E8%BD%AC%E5%80%BA%E6%A0%87%22%2C%22%E8%BD%AC%E5%80%BA%E6%A0%87%E7%9A%84%22%5D; st_si=00364513876913; st_asi=delete; HAList=ty-116-00700-%u817E%u8BAF%u63A7%u80A1%2Cty-1-688695-%u4E2D%u521B%u80A1%u4EFD%2Cty-1-600849-%u4E0A%u836F%u8F6C%u6362%2Cty-1-603361-%u6D59%u6C5F%u56FD%u7965%2Cty-1-603555-ST%u8D35%u4EBA%2Cty-0-000627-%u5929%u8302%u96C6%u56E2%2Cty-0-002470-%u91D1%u6B63%u5927%2Cty-0-832876-%u6167%u4E3A%u667A%u80FD%2Cty-0-300059-%u4E1C%u65B9%u8D22%u5BCC%2Cty-107-CWB-%u53EF%u8F6C%u503AETF-SPDR; st_pvi=26930719093675; st_sp=2024-04-28%2017%3A27%3A05; st_inirUrl=https%3A%2F%2Fcn.bing.com%2F; st_sn=23; st_psi=20240517111108288-113200301321-2767127768'
|
|
330
|
-
while True:
|
|
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')
|
|
287
|
+
em_cookie_test = cookie_info_service.get_em_cookie()
|
|
288
|
+
get_hk_real_time_quotes(30, em_cookie_test)
|