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.
- 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 +22 -97
- 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/__init__.py +7 -0
- 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
- mns_common/api/em/real_time/__init__.py +7 -0
- mns_common/api/em/{east_money_debt_api.py → real_time/east_money_debt_api.py} +154 -69
- mns_common/api/em/{east_money_etf_api.py → real_time/east_money_etf_api.py} +149 -27
- mns_common/api/em/real_time/east_money_stock_a_api.py +301 -0
- mns_common/api/em/real_time/east_money_stock_a_v2_api.py +340 -0
- 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 +288 -0
- 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/{east_money_stock_us_api.py → real_time/east_money_stock_us_api.py} +149 -72
- 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/k_line/stock_minute_data_api.py +1 -0
- 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/proxies/__init__.py +7 -0
- mns_common/api/proxies/liu_guan_proxy_api.py +115 -0
- mns_common/api/ths/company/company_product_area_industry_index_query.py +46 -0
- mns_common/api/ths/company/ths_company_info_api.py +13 -9
- 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 +10 -7
- mns_common/api/ths/zt/ths_stock_zt_pool_api.py +21 -4
- mns_common/api/ths/zt/ths_stock_zt_pool_v2_api.py +111 -40
- mns_common/api/xueqiu/__init__.py +7 -0
- mns_common/api/xueqiu/xue_qiu_k_line_api.py +83 -0
- mns_common/component/__init__.py +1 -1
- mns_common/component/classify/symbol_classify_api.py +7 -7
- mns_common/component/common_service_fun_api.py +66 -6
- mns_common/component/company/company_common_service_api.py +21 -1
- mns_common/component/company/company_common_service_new_api.py +4 -1
- mns_common/component/cookie/cookie_enum.py +15 -0
- mns_common/component/cookie/cookie_info_service.py +9 -4
- 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/__init__.py +7 -0
- mns_common/component/em/em_real_time_quotes_api.py +56 -0
- mns_common/component/em/em_stock_info_api.py +48 -0
- mns_common/component/exception/ExceptionMonitor.py +86 -0
- mns_common/component/exception/__init__.py +7 -0
- mns_common/component/k_line/common/k_line_common_service_api.py +4 -0
- mns_common/component/main_line/__init__.py +7 -0
- mns_common/component/main_line/main_line_zt_reason_service.py +237 -0
- mns_common/component/proxies/__init__.py +7 -0
- mns_common/component/proxies/proxy_common_api.py +252 -0
- mns_common/component/self_choose/__init__.py +13 -0
- 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 +125 -0
- mns_common/constant/__init__.py +1 -0
- mns_common/constant/db_name_constant.py +65 -34
- mns_common/constant/extra_income_db_name.py +154 -0
- mns_common/constant/strategy_classify.py +72 -0
- mns_common/db/MongodbUtil.py +2 -1
- mns_common/db/MongodbUtilLocal.py +1 -0
- mns_common/db/v2/MongodbUtilV2.py +0 -4
- mns_common-1.5.7.2.dist-info/METADATA +4 -0
- {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/RECORD +70 -45
- {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/WHEEL +1 -1
- mns_common/api/em/east_money_stock_api.py +0 -222
- mns_common/api/em/east_money_stock_hk_api.py +0 -318
- mns_common/api/em/east_money_stock_v2_api.py +0 -219
- 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-1.3.3.5.dist-info/METADATA +0 -4
- /mns_common/{component/qmt → api/em/concept}/__init__.py +0 -0
- /mns_common/api/em/{em_concept_index_api.py → concept/em_concept_index_api.py} +0 -0
- {mns_common-1.3.3.5.dist-info → mns_common-1.5.7.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
3
|
+
import requests
|
|
4
|
+
from loguru import logger
|
|
5
|
+
import datetime
|
|
6
|
+
|
|
7
|
+
fs = "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048"
|
|
8
|
+
fields = ("f2,f3,f5,f6,f8,"
|
|
9
|
+
"f9,f10,f22,f12,f13,"
|
|
10
|
+
"f14,f15,f16,f17,f18,"
|
|
11
|
+
"f20,f21,f23,f26,f33,"
|
|
12
|
+
"f34,f35,f37,f38,f39,"
|
|
13
|
+
"f62,f64,f65,f67,f68,"
|
|
14
|
+
"f66,f69,f70,f71,f72,"
|
|
15
|
+
"f76,f77,f78,f82,f83,"
|
|
16
|
+
"f84,f102,f184,f100,f103,"
|
|
17
|
+
"f352,f191,f193,f24,f25")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# 获取所有股票实时行情数据 f33,委比
|
|
21
|
+
def rename_real_time_quotes_df(temp_df):
|
|
22
|
+
temp_df = temp_df.rename(columns={
|
|
23
|
+
"f2": "now_price",
|
|
24
|
+
"f3": "chg",
|
|
25
|
+
"f5": "volume",
|
|
26
|
+
"f6": "amount",
|
|
27
|
+
"f8": "exchange",
|
|
28
|
+
"f10": "quantity_ratio",
|
|
29
|
+
"f22": "up_speed",
|
|
30
|
+
"f11": "up_speed_05",
|
|
31
|
+
"f12": "symbol",
|
|
32
|
+
"f14": "name",
|
|
33
|
+
"f15": "high",
|
|
34
|
+
"f16": "low",
|
|
35
|
+
"f17": "open",
|
|
36
|
+
"f18": "yesterday_price",
|
|
37
|
+
"f20": "total_mv",
|
|
38
|
+
"f21": "flow_mv",
|
|
39
|
+
"f26": "list_date",
|
|
40
|
+
"f33": "wei_bi",
|
|
41
|
+
"f34": "outer_disk",
|
|
42
|
+
"f35": "inner_disk",
|
|
43
|
+
"f62": "today_main_net_inflow",
|
|
44
|
+
"f66": "super_large_order_net_inflow",
|
|
45
|
+
"f69": "super_large_order_net_inflow_ratio",
|
|
46
|
+
"f72": "large_order_net_inflow",
|
|
47
|
+
# "f78": "medium_order_net_inflow",
|
|
48
|
+
# "f84": "small_order_net_inflow",
|
|
49
|
+
"f100": "industry",
|
|
50
|
+
# "f103": "concept",
|
|
51
|
+
"f184": "today_main_net_inflow_ratio",
|
|
52
|
+
"f352": "average_price",
|
|
53
|
+
"f211": "buy_1_num",
|
|
54
|
+
"f212": "sell_1_num"
|
|
55
|
+
})
|
|
56
|
+
if data_frame_util.is_empty(temp_df):
|
|
57
|
+
return pd.DataFrame()
|
|
58
|
+
else:
|
|
59
|
+
temp_df.loc[temp_df['buy_1_num'] == '-', 'buy_1_num'] = 0
|
|
60
|
+
temp_df.loc[temp_df['sell_1_num'] == '-', 'sell_1_num'] = 0
|
|
61
|
+
temp_df.loc[temp_df['up_speed_05'] == '-', 'up_speed_05'] = 0
|
|
62
|
+
temp_df.loc[temp_df['up_speed'] == '-', 'up_speed'] = 0
|
|
63
|
+
temp_df.loc[temp_df['average_price'] == '-', 'average_price'] = 0
|
|
64
|
+
temp_df.loc[temp_df['wei_bi'] == '-', 'wei_bi'] = 0
|
|
65
|
+
temp_df.loc[temp_df['yesterday_price'] == '-', 'yesterday_price'] = 0
|
|
66
|
+
temp_df.loc[temp_df['now_price'] == '-', 'now_price'] = 0
|
|
67
|
+
temp_df.loc[temp_df['chg'] == '-', 'chg'] = 0
|
|
68
|
+
temp_df.loc[temp_df['volume'] == '-', 'volume'] = 0
|
|
69
|
+
temp_df.loc[temp_df['amount'] == '-', 'amount'] = 0
|
|
70
|
+
temp_df.loc[temp_df['exchange'] == '-', 'exchange'] = 0
|
|
71
|
+
temp_df.loc[temp_df['quantity_ratio'] == '-', 'quantity_ratio'] = 0
|
|
72
|
+
temp_df.loc[temp_df['high'] == '-', 'high'] = 0
|
|
73
|
+
temp_df.loc[temp_df['low'] == '-', 'low'] = 0
|
|
74
|
+
temp_df.loc[temp_df['open'] == '-', 'open'] = 0
|
|
75
|
+
temp_df.loc[temp_df['total_mv'] == '-', 'total_mv'] = 0
|
|
76
|
+
temp_df.loc[temp_df['flow_mv'] == '-', 'flow_mv'] = 0
|
|
77
|
+
temp_df.loc[temp_df['inner_disk'] == '-', 'inner_disk'] = 0
|
|
78
|
+
temp_df.loc[temp_df['outer_disk'] == '-', 'outer_disk'] = 0
|
|
79
|
+
temp_df.loc[temp_df['today_main_net_inflow_ratio'] == '-', 'today_main_net_inflow_ratio'] = 0
|
|
80
|
+
temp_df.loc[temp_df['today_main_net_inflow'] == '-', 'today_main_net_inflow'] = 0
|
|
81
|
+
temp_df.loc[temp_df['super_large_order_net_inflow'] == '-', 'super_large_order_net_inflow'] = 0
|
|
82
|
+
temp_df.loc[temp_df['super_large_order_net_inflow_ratio'] == '-', 'super_large_order_net_inflow_ratio'] = 0
|
|
83
|
+
temp_df.loc[temp_df['large_order_net_inflow'] == '-', 'large_order_net_inflow'] = 0
|
|
84
|
+
# temp_df.loc[temp_df['medium_order_net_inflow'] == '-', 'medium_order_net_inflow'] = 0
|
|
85
|
+
# temp_df.loc[temp_df['small_order_net_inflow'] == '-', 'small_order_net_inflow'] = 0
|
|
86
|
+
|
|
87
|
+
temp_df["list_date"] = pd.to_numeric(temp_df["list_date"], errors="coerce")
|
|
88
|
+
temp_df["wei_bi"] = pd.to_numeric(temp_df["wei_bi"], errors="coerce")
|
|
89
|
+
temp_df["average_price"] = pd.to_numeric(temp_df["average_price"], errors="coerce")
|
|
90
|
+
temp_df["yesterday_price"] = pd.to_numeric(temp_df["yesterday_price"], errors="coerce")
|
|
91
|
+
temp_df["now_price"] = pd.to_numeric(temp_df["now_price"], errors="coerce")
|
|
92
|
+
temp_df["chg"] = pd.to_numeric(temp_df["chg"], errors="coerce")
|
|
93
|
+
temp_df["volume"] = pd.to_numeric(temp_df["volume"], errors="coerce")
|
|
94
|
+
temp_df["amount"] = pd.to_numeric(temp_df["amount"], errors="coerce")
|
|
95
|
+
temp_df["exchange"] = pd.to_numeric(temp_df["exchange"], errors="coerce")
|
|
96
|
+
temp_df["quantity_ratio"] = pd.to_numeric(temp_df["quantity_ratio"], errors="coerce")
|
|
97
|
+
temp_df["high"] = pd.to_numeric(temp_df["high"], errors="coerce")
|
|
98
|
+
temp_df["low"] = pd.to_numeric(temp_df["low"], errors="coerce")
|
|
99
|
+
temp_df["open"] = pd.to_numeric(temp_df["open"], errors="coerce")
|
|
100
|
+
temp_df["total_mv"] = pd.to_numeric(temp_df["total_mv"], errors="coerce")
|
|
101
|
+
temp_df["flow_mv"] = pd.to_numeric(temp_df["flow_mv"], errors="coerce")
|
|
102
|
+
temp_df["outer_disk"] = pd.to_numeric(temp_df["outer_disk"], errors="coerce")
|
|
103
|
+
temp_df["inner_disk"] = pd.to_numeric(temp_df["inner_disk"], errors="coerce")
|
|
104
|
+
temp_df["today_main_net_inflow"] = pd.to_numeric(temp_df["today_main_net_inflow"], errors="coerce")
|
|
105
|
+
temp_df["super_large_order_net_inflow"] = pd.to_numeric(temp_df["super_large_order_net_inflow"],
|
|
106
|
+
errors="coerce")
|
|
107
|
+
temp_df["super_large_order_net_inflow_ratio"] = pd.to_numeric(temp_df["super_large_order_net_inflow_ratio"],
|
|
108
|
+
errors="coerce")
|
|
109
|
+
temp_df["large_order_net_inflow"] = pd.to_numeric(temp_df["large_order_net_inflow"],
|
|
110
|
+
errors="coerce")
|
|
111
|
+
# temp_df["medium_order_net_inflow"] = pd.to_numeric(temp_df["medium_order_net_inflow"],
|
|
112
|
+
# errors="coerce")
|
|
113
|
+
# temp_df["small_order_net_inflow"] = pd.to_numeric(temp_df["small_order_net_inflow"], errors="coerce")
|
|
114
|
+
|
|
115
|
+
# 大单比例
|
|
116
|
+
temp_df['large_order_net_inflow_ratio'] = round((temp_df['large_order_net_inflow'] / temp_df['amount']) * 100,
|
|
117
|
+
2)
|
|
118
|
+
|
|
119
|
+
# 外盘是内盘倍数
|
|
120
|
+
temp_df['disk_ratio'] = round((temp_df['outer_disk'] - temp_df['inner_disk']) / temp_df['inner_disk'], 2)
|
|
121
|
+
# 只有外盘没有内盘
|
|
122
|
+
temp_df.loc[temp_df["inner_disk"] == 0, ['disk_ratio']] = 1688
|
|
123
|
+
temp_df = temp_df.sort_values(by=['chg'], ascending=False)
|
|
124
|
+
return temp_df
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get_stocks_num(pn, proxies, page_number, time_out):
|
|
128
|
+
"""
|
|
129
|
+
获取单页股票数据
|
|
130
|
+
"""
|
|
131
|
+
# 获取当前日期和时间
|
|
132
|
+
current_time = datetime.datetime.now()
|
|
133
|
+
|
|
134
|
+
# 将当前时间转换为时间戳(以毫秒为单位)
|
|
135
|
+
current_timestamp_ms = int(current_time.timestamp() * 1000)
|
|
136
|
+
|
|
137
|
+
url = "https://13.push2.eastmoney.com/api/qt/clist/get"
|
|
138
|
+
params = {
|
|
139
|
+
"cb": "jQuery1124046660442520420653_" + str(current_timestamp_ms),
|
|
140
|
+
"pn": str(pn),
|
|
141
|
+
"pz": str(page_number), # 每页最大200条
|
|
142
|
+
"po": "1",
|
|
143
|
+
"np": "3",
|
|
144
|
+
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
|
145
|
+
"fltt": "2",
|
|
146
|
+
"invt": "2",
|
|
147
|
+
"wbp2u": "|0|0|0|web",
|
|
148
|
+
"fid": "f3",
|
|
149
|
+
"fs": fs,
|
|
150
|
+
"fields": fields,
|
|
151
|
+
"_": current_timestamp_ms
|
|
152
|
+
}
|
|
153
|
+
try:
|
|
154
|
+
if proxies is None:
|
|
155
|
+
r = requests.get(url, params, timeout=time_out)
|
|
156
|
+
else:
|
|
157
|
+
r = requests.get(url, params, proxies=proxies, timeout=time_out)
|
|
158
|
+
data_text = r.text
|
|
159
|
+
|
|
160
|
+
begin_index_total = data_text.index('"total":')
|
|
161
|
+
end_index_total = data_text.index('"diff"')
|
|
162
|
+
return int(data_text[begin_index_total + 8:end_index_total - 1])
|
|
163
|
+
|
|
164
|
+
except Exception as e:
|
|
165
|
+
logger.error("获取股票数量异常:{}", str(e))
|
|
166
|
+
return 0
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
import mns_common.component.proxies.proxy_common_api as proxy_common_api
|
|
170
|
+
|
|
171
|
+
if __name__ == '__main__':
|
|
172
|
+
proxy_ip = proxy_common_api.generate_proxy_ip_api(1)
|
|
173
|
+
proxies = {"https": proxy_ip}
|
|
174
|
+
get_stocks_num(1, proxies, 100, 30)
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
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 pandas as pd
|
|
9
|
+
from loguru import logger
|
|
10
|
+
import requests
|
|
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
|
+
|
|
17
|
+
# 分页条数
|
|
18
|
+
page_number = 100
|
|
19
|
+
|
|
20
|
+
fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,"
|
|
21
|
+
"f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212,f103,f383")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_hk_stock_count(pn, proxies, page_size, cookie, time_out):
|
|
25
|
+
try:
|
|
26
|
+
headers = {
|
|
27
|
+
'Cookie': cookie
|
|
28
|
+
}
|
|
29
|
+
current_timestamp = str(int(round(time.time() * 1000, 0)))
|
|
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)))
|
|
66
|
+
url_new = ('https://61.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112409497467688484127_' + str(
|
|
67
|
+
current_timestamp) +
|
|
68
|
+
'&pn=' + str(pn) +
|
|
69
|
+
'&pz=' + str(page_size) +
|
|
70
|
+
'&po=1'
|
|
71
|
+
'&np=3'
|
|
72
|
+
'&ut=bd1d9ddb04089700cf9c27f6f7426281'
|
|
73
|
+
'&fltt=2'
|
|
74
|
+
'&invt=2'
|
|
75
|
+
'&wbp2u=4253366368931142|0|1|0|web'
|
|
76
|
+
'&fid=f12'
|
|
77
|
+
'&fs=m:116+t:3,m:116+t:4,m:116+t:1,m:116+t:2'
|
|
78
|
+
'&fields=' + fields +
|
|
79
|
+
'&_=' + str(current_timestamp))
|
|
80
|
+
|
|
81
|
+
if proxies is None:
|
|
82
|
+
r = requests.get(url_new, headers=headers, timeout=time_out)
|
|
83
|
+
else:
|
|
84
|
+
r = requests.get(url_new, headers=headers, proxies=proxies, timeout=time_out)
|
|
85
|
+
result = r.content.decode("utf-8")
|
|
86
|
+
startIndex = result.index('"diff"')
|
|
87
|
+
endIndex = result.index('}]}')
|
|
88
|
+
result = result[startIndex + 7:endIndex + 2]
|
|
89
|
+
data_json = json.loads(result)
|
|
90
|
+
temp_df = pd.DataFrame(data_json)
|
|
91
|
+
return temp_df
|
|
92
|
+
except Exception as e:
|
|
93
|
+
logger.error("获取港股列表,实时行情异常:{}", e)
|
|
94
|
+
return pd.DataFrame()
|
|
95
|
+
|
|
96
|
+
|
|
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
|
|
208
|
+
"""
|
|
209
|
+
per_page = page_number
|
|
210
|
+
total_pages = (max_number + per_page - 1) // per_page # 向上取整
|
|
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
|
+
# 合并所有成功获取的数据
|
|
263
|
+
if results:
|
|
264
|
+
return pd.concat(results, ignore_index=True)
|
|
265
|
+
else:
|
|
266
|
+
return pd.DataFrame()
|
|
267
|
+
|
|
268
|
+
|
|
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}
|
|
275
|
+
|
|
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)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
if __name__ == '__main__':
|
|
287
|
+
em_cookie_test = cookie_info_service.get_em_cookie()
|
|
288
|
+
get_hk_real_time_quotes(30, em_cookie_test)
|