mns-common 1.3.6.7__py3-none-any.whl → 1.3.6.9__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.

Files changed (24) hide show
  1. mns_common/api/em/concept/__init__.py +7 -0
  2. mns_common/api/em/gd/__init__.py +7 -0
  3. mns_common/api/em/{east_money_stock_gdfx_free_top_10_api.py → gd/east_money_stock_gdfx_free_top_10_api.py} +2 -2
  4. mns_common/api/em/real_time/__init__.py +7 -0
  5. mns_common/api/em/{east_money_debt_api.py → real_time/east_money_debt_api.py} +11 -8
  6. mns_common/api/em/{east_money_etf_api.py → real_time/east_money_etf_api.py} +11 -8
  7. mns_common/api/em/{east_money_stock_api_v3.py → real_time/east_money_stock_a_api.py} +70 -3
  8. mns_common/api/em/{east_money_stock_v2_api.py → real_time/east_money_stock_a_v2_api.py} +12 -72
  9. mns_common/api/em/{east_money_stock_hk_api.py → real_time/east_money_stock_hk_api.py} +13 -9
  10. mns_common/api/em/{east_money_stock_us_api.py → real_time/east_money_stock_us_api.py} +11 -8
  11. mns_common/api/ths/zt/ths_stock_zt_pool_api.py +2 -4
  12. mns_common/api/ths/zt/ths_stock_zt_pool_v2_api.py +2 -2
  13. mns_common/component/em/__init__.py +7 -0
  14. mns_common/component/em/em_real_time_quotes_api.py +56 -0
  15. mns_common/component/em/em_stock_info_api.py +37 -0
  16. mns_common/component/proxies/proxy_common_api.py +20 -16
  17. mns_common/constant/db_name_constant.py +15 -0
  18. {mns_common-1.3.6.7.dist-info → mns_common-1.3.6.9.dist-info}/METADATA +1 -1
  19. {mns_common-1.3.6.7.dist-info → mns_common-1.3.6.9.dist-info}/RECORD +22 -18
  20. mns_common/api/em/east_money_stock_api.py +0 -233
  21. mns_common/api/em/east_money_stock_quotes_sync_api.py +0 -250
  22. /mns_common/api/em/{em_concept_index_api.py → concept/em_concept_index_api.py} +0 -0
  23. {mns_common-1.3.6.7.dist-info → mns_common-1.3.6.9.dist-info}/WHEEL +0 -0
  24. {mns_common-1.3.6.7.dist-info → mns_common-1.3.6.9.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,7 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
@@ -0,0 +1,7 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
@@ -9,7 +9,7 @@ import akshare as ak
9
9
  import mns_common.component.common_service_fun_api as common_service_fun_api
10
10
  import mns_common.utils.date_handle_util as date_handle_util
11
11
  from loguru import logger
12
- import mns_common.api.em.east_money_stock_api as east_money_stock_api
12
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
13
13
  from mns_common.db.MongodbUtil import MongodbUtil
14
14
  import mns_common.constant.db_name_constant as db_name_constant
15
15
  import mns_common.component.company.company_common_service_new_api as company_common_service_new_api
@@ -178,7 +178,7 @@ def sync_stock_gdfx_top_10(stock_gdfx_top_10_em_df, period, symbol, str_day):
178
178
 
179
179
  # 十大股东+十大流通股东
180
180
  def sync_stock_gdfx_free_top_10_one_day(str_day):
181
- real_time_quotes = east_money_stock_api.get_real_time_quotes_all_stocks()
181
+ real_time_quotes = em_stock_info_api.get_a_stock_info()
182
182
  real_time_quotes = real_time_quotes.loc[~(
183
183
  real_time_quotes['symbol'].isin(company_common_service_new_api.get_de_list_company()))]
184
184
  for real_time_one in real_time_quotes.itertuples():
@@ -0,0 +1,7 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
@@ -36,7 +36,7 @@ page_number = 100
36
36
  # =8a086bfc3570bdde64a6a1c585cccb35&fltt=1&invt=1&fs=m:0+e:11,m:1+e:11,m:1+e:11+s:4194304,
37
37
  # m:0+e:11+s:8388608&dpt=zqsc.zpg&fields=f1,f2,f3,f4,f5,f6,f8,f10,f12,f13,f14,f18,f22,f152,
38
38
  # f237&wbp2u=|0|0|0|wap&fid=f3&po=1&pz=2000&_=1718163189870
39
- def get_debt_page_data(fields, pn) -> pd.DataFrame:
39
+ def get_debt_page_data(fields, pn, proxies) -> pd.DataFrame:
40
40
  current_timestamp = str(int(round(time.time() * 1000, 0)))
41
41
  url = "https://push2.eastmoney.com/api/qt/clist/get"
42
42
 
@@ -57,7 +57,10 @@ def get_debt_page_data(fields, pn) -> pd.DataFrame:
57
57
  "_": current_timestamp
58
58
  }
59
59
  try:
60
- r = requests.get(url, params)
60
+ if proxies is None:
61
+ r = requests.get(url, params)
62
+ else:
63
+ r = requests.get(url, params, proxies=proxies)
61
64
  data_text = r.text
62
65
 
63
66
  if pn == 1:
@@ -84,7 +87,7 @@ def get_debt_page_data(fields, pn) -> pd.DataFrame:
84
87
  return pd.DataFrame()
85
88
 
86
89
 
87
- def all_debt_ticker_data(fields) -> pd.DataFrame:
90
+ def all_debt_ticker_data(fields, proxies) -> pd.DataFrame:
88
91
  """
89
92
  使用多线程获取所有债券数据
90
93
  """
@@ -96,7 +99,7 @@ def all_debt_ticker_data(fields) -> pd.DataFrame:
96
99
  # 创建线程池
97
100
  with ThreadPoolExecutor(max_workers=3) as executor:
98
101
  # 提交任务,获取每页数据
99
- futures = [executor.submit(get_debt_page_data, fields, pn)
102
+ futures = [executor.submit(get_debt_page_data, fields, pn, proxies)
100
103
  for pn in range(1, total_pages + 1)]
101
104
 
102
105
  # 收集结果
@@ -113,18 +116,18 @@ def all_debt_ticker_data(fields) -> pd.DataFrame:
113
116
  return pd.DataFrame()
114
117
 
115
118
 
116
- def get_debt_real_time_quotes():
119
+ def get_debt_real_time_quotes(proxies):
117
120
  fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,f33,f34,f35,f62,f66,f69,f72,f184,"
118
121
  "f211,f212,f232,f233,f234")
119
122
  # 获取第一页数据
120
- page_one_df = get_debt_page_data(fields, 1)
123
+ page_one_df = get_debt_page_data(fields, 1, proxies)
121
124
  # 数据接口正常返回5600以上的数量
122
125
  if page_one_df.shape[0] > min_number:
123
126
  page_one_df = rename_real_time_quotes_df(page_one_df)
124
127
  page_one_df.drop_duplicates('symbol', keep='last', inplace=True)
125
128
  return page_one_df
126
129
  else:
127
- page_df = all_debt_ticker_data(fields)
130
+ page_df = all_debt_ticker_data(fields, proxies)
128
131
  page_df = rename_real_time_quotes_df(page_df)
129
132
  page_df.drop_duplicates('symbol', keep='last', inplace=True)
130
133
  return page_df
@@ -299,5 +302,5 @@ if __name__ == '__main__':
299
302
  info_df = get_kzz_bond_info()
300
303
  print(info_df)
301
304
  while True:
302
- df = get_debt_real_time_quotes()
305
+ df = get_debt_real_time_quotes(None)
303
306
  logger.info(df)
@@ -21,7 +21,7 @@ min_number = 1000
21
21
  page_number = 100
22
22
 
23
23
 
24
- def get_fund_etf_page_df(pn) -> pd.DataFrame:
24
+ def get_fund_etf_page_df(pn, proxies) -> pd.DataFrame:
25
25
  """
26
26
  东方财富-ETF 实时行情
27
27
  https://quote.eastmoney.com/center/gridlist.html#fund_etf
@@ -52,7 +52,10 @@ def get_fund_etf_page_df(pn) -> pd.DataFrame:
52
52
  "_": str(current_timestamp),
53
53
  }
54
54
  try:
55
- r = requests.get(url, timeout=15, params=params)
55
+ if proxies is None:
56
+ r = requests.get(url, params)
57
+ else:
58
+ r = requests.get(url, params, proxies=proxies)
56
59
  data_json = r.json()
57
60
  if pn == 1:
58
61
  try:
@@ -218,7 +221,7 @@ def get_fund_etf_page_df(pn) -> pd.DataFrame:
218
221
  return pd.DataFrame()
219
222
 
220
223
 
221
- def thread_pool_executor():
224
+ def thread_pool_executor(proxies):
222
225
  """
223
226
  使用多线程获取所有ETF数据
224
227
  """
@@ -230,7 +233,7 @@ def thread_pool_executor():
230
233
  # 创建线程池
231
234
  with ThreadPoolExecutor(max_workers=3) as executor:
232
235
  # 提交任务,获取每页数据
233
- futures = [executor.submit(get_fund_etf_page_df, pn)
236
+ futures = [executor.submit(get_fund_etf_page_df, pn, proxies)
234
237
  for pn in range(1, total_pages + 1)]
235
238
 
236
239
  # 收集结果
@@ -349,23 +352,23 @@ def rename_etf(fund_etf_spot_em_df):
349
352
  return fund_etf_spot_em_df
350
353
 
351
354
 
352
- def get_etf_real_time_quotes():
355
+ def get_etf_real_time_quotes(proxies):
353
356
  # 获取第一页数据
354
- page_one_df = get_fund_etf_page_df(1)
357
+ page_one_df = get_fund_etf_page_df(1, proxies)
355
358
  # 数据接口正常返回5600以上的数量
356
359
  if page_one_df.shape[0] > min_number:
357
360
  page_one_df = rename_etf(page_one_df)
358
361
  page_one_df.drop_duplicates('symbol', keep='last', inplace=True)
359
362
  return page_one_df
360
363
  else:
361
- page_df = thread_pool_executor()
364
+ page_df = thread_pool_executor(proxies)
362
365
  page_df = rename_etf(page_df)
363
366
  page_df.drop_duplicates('symbol', keep='last', inplace=True)
364
367
  return page_df
365
368
 
366
369
 
367
370
  if __name__ == '__main__':
368
- fund_etf_df = get_etf_real_time_quotes()
371
+ fund_etf_df = get_etf_real_time_quotes(None)
369
372
  fund_etf_df = fund_etf_df.sort_values(by=['amount'], ascending=False)
370
373
  fund_etf_df = fund_etf_df.fillna(0)
371
374
  print(fund_etf_df)
@@ -31,7 +31,7 @@ def get_stock_page_data(pn, fields, fs, proxies):
31
31
  # 将当前时间转换为时间戳(以毫秒为单位)
32
32
  current_timestamp_ms = int(current_time.timestamp() * 1000)
33
33
 
34
- url = "https://13.push2.eastmoney.com/api/qt/clist/get"
34
+ url = "https://33.push2.eastmoney.com/api/qt/clist/get"
35
35
  params = {
36
36
  "cb": "jQuery1124046660442520420653_" + str(current_timestamp_ms),
37
37
  "pn": str(pn),
@@ -48,7 +48,11 @@ def get_stock_page_data(pn, fields, fs, proxies):
48
48
  "_": current_timestamp_ms
49
49
  }
50
50
  try:
51
- r = requests.get(url, params, proxies=proxies)
51
+ if proxies is None:
52
+ r = requests.get(url, params)
53
+ else:
54
+ r = requests.get(url, params, proxies=proxies)
55
+
52
56
  data_text = r.text
53
57
  if pn == 1:
54
58
  try:
@@ -224,8 +228,71 @@ def rename_real_time_quotes_df(temp_df):
224
228
  return temp_df
225
229
 
226
230
 
231
+ # 北向/南向资金状况 北向已经停止
232
+ def get_sum_north_south_net_buy_amt():
233
+ # 设置请求头部信息
234
+ headers = {
235
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
236
+ }
237
+
238
+ # 设置请求URL
239
+ url = 'http://push2.eastmoney.com/api/qt/kamt/get?fields1=f1,f2,f3,f4&fields2=f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65,f66,f67,f68,f69,f70&ut=b2884a393a59ad640022ce1e1e78431c&deviceid=0&cb=jsonp_1622790712837&_=1622790712926'
240
+
241
+ # 发送HTTP请求
242
+ response = requests.get(url, headers=headers, params={"type": "json"})
243
+
244
+ # 解析JSON数据
245
+ data = json.loads(response.text.lstrip('jsonp_1622790712837(').rstrip(');'))
246
+
247
+ # 处理数据
248
+
249
+ # 单位(万元)
250
+ # dayNetAmtIn 资金净流入
251
+ # dayAmtRemain 当日资金余额
252
+ # dayAmtThreshold 当日资金限额
253
+ # monthNetAmtIn 当月净流入
254
+ # yearNetAmtIn 年度净流入
255
+ # allNetAmtIn 总净流入
256
+ # buyAmt 当日买入金额
257
+ # sellAmt 当日卖出金额
258
+ # buySellAmt 当日买入卖出总金额
259
+ # netBuyAmt 成交净买额
260
+
261
+ # Hongkong to Shanghai
262
+ hk2sh = data['data']['hk2sh']
263
+ hk2sh_df = pd.DataFrame(hk2sh, index=[0])
264
+ # Hongkong to ShenZhen
265
+ hk2sz = data['data']['hk2sz']
266
+ hk2sz_df = pd.DataFrame(hk2sz, index=[0])
267
+
268
+ # Shanghai to Hongkong
269
+ sh2hk = data['data']['sh2hk']
270
+ sh2hk_df = pd.DataFrame(sh2hk, index=[0])
271
+
272
+ # ShenZhen to Hongkong
273
+ sz2hk = data['data']['sz2hk']
274
+ sz2hk_df = pd.DataFrame(sz2hk, index=[0])
275
+ # 北向总额
276
+ sum_north_netBuyAmt = hk2sh_df['netBuyAmt'] + hk2sz_df['netBuyAmt']
277
+
278
+ sum_south_netBuyAmt = sh2hk_df['netBuyAmt'] + sz2hk_df['netBuyAmt']
279
+
280
+ df = pd.DataFrame([[
281
+ list(hk2sh_df['netBuyAmt'])[0],
282
+ list(hk2sz_df['netBuyAmt'])[0],
283
+ list(sum_north_netBuyAmt)[0],
284
+ list(sh2hk_df['netBuyAmt'])[0],
285
+ list(sz2hk_df['netBuyAmt'])[0],
286
+ list(sum_south_netBuyAmt)[0]]],
287
+ columns=['sh_netBuyAmt', 'sz_netBuyAmt', 'sum_north_netBuyAmt',
288
+ 'sh_hk_netBuyAmt', 'sz_hk_netBuyAmt', 'sum_south_netBuyAmt'])
289
+
290
+ # 打印结果
291
+ return df
292
+
293
+
227
294
  # 示例调用
228
295
  if __name__ == "__main__":
229
296
  while True:
230
- df = get_real_time_quotes_all_stocks()
297
+ df = get_real_time_quotes_all_stocks(None)
231
298
  logger.info("涨停数据,{}", 1)
@@ -26,7 +26,7 @@ min_number = 5600
26
26
  page_number = 100
27
27
 
28
28
 
29
- def get_stock_page_data(pn, fields, fs):
29
+ def get_stock_page_data(pn, fields, fs, proxies):
30
30
  """
31
31
  获取单页股票数据
32
32
  """
@@ -53,7 +53,10 @@ def get_stock_page_data(pn, fields, fs):
53
53
  "_": current_timestamp_ms
54
54
  }
55
55
  try:
56
- r = requests.get(url, params)
56
+ if proxies is None:
57
+ r = requests.get(url, params)
58
+ else:
59
+ r = requests.get(url, params, proxies=proxies)
57
60
  data_text = r.text
58
61
  begin_index = data_text.index('[')
59
62
  end_index = data_text.index(']')
@@ -68,7 +71,7 @@ def get_stock_page_data(pn, fields, fs):
68
71
  return pd.DataFrame()
69
72
 
70
73
 
71
- def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
74
+ def all_stock_ticker_data_new(fields, fs, proxies) -> pd.DataFrame:
72
75
  """
73
76
  使用多线程获取所有股票数据
74
77
  """
@@ -79,7 +82,7 @@ def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
79
82
  # 创建线程池
80
83
  with ThreadPoolExecutor(max_workers=10) as executor:
81
84
  # 提交任务,获取每页数据
82
- futures = [executor.submit(get_stock_page_data, pn, fields, fs)
85
+ futures = [executor.submit(get_stock_page_data, pn, fields, fs, proxies)
83
86
  for pn in range(1, total_pages + 1)]
84
87
 
85
88
  # 收集结果
@@ -96,16 +99,16 @@ def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
96
99
  return pd.DataFrame()
97
100
 
98
101
 
99
- def get_all_real_time_quotes():
102
+ def get_all_real_time_quotes(proxies):
100
103
  fs = "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048"
101
104
  # 获取第一页数据
102
- page_one_df = get_stock_page_data(1, fields_02, fs)
105
+ page_one_df = get_stock_page_data(1, fields_02, fs, proxies)
103
106
  # 数据接口正常返回5600以上的数量
104
107
  if page_one_df.shape[0] > min_number:
105
108
  page_one_df = rename_real_time_quotes_df(page_one_df)
106
109
  return page_one_df
107
110
  else:
108
- page_df = all_stock_ticker_data_new(fields_02, fs)
111
+ page_df = all_stock_ticker_data_new(fields_02, fs, proxies)
109
112
  page_df = rename_real_time_quotes_df(page_df)
110
113
  return page_df
111
114
 
@@ -267,74 +270,11 @@ def rename_real_time_quotes_df(temp_df):
267
270
  return temp_df
268
271
 
269
272
 
270
- # 北向/南向资金状况 北向已经停止
271
- def get_sum_north_south_net_buy_amt():
272
- # 设置请求头部信息
273
- headers = {
274
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
275
- }
276
-
277
- # 设置请求URL
278
- url = 'http://push2.eastmoney.com/api/qt/kamt/get?fields1=f1,f2,f3,f4&fields2=f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65,f66,f67,f68,f69,f70&ut=b2884a393a59ad640022ce1e1e78431c&deviceid=0&cb=jsonp_1622790712837&_=1622790712926'
279
-
280
- # 发送HTTP请求
281
- response = requests.get(url, headers=headers, params={"type": "json"})
282
-
283
- # 解析JSON数据
284
- data = json.loads(response.text.lstrip('jsonp_1622790712837(').rstrip(');'))
285
-
286
- # 处理数据
287
-
288
- # 单位(万元)
289
- # dayNetAmtIn 资金净流入
290
- # dayAmtRemain 当日资金余额
291
- # dayAmtThreshold 当日资金限额
292
- # monthNetAmtIn 当月净流入
293
- # yearNetAmtIn 年度净流入
294
- # allNetAmtIn 总净流入
295
- # buyAmt 当日买入金额
296
- # sellAmt 当日卖出金额
297
- # buySellAmt 当日买入卖出总金额
298
- # netBuyAmt 成交净买额
299
-
300
- # Hongkong to Shanghai
301
- hk2sh = data['data']['hk2sh']
302
- hk2sh_df = pd.DataFrame(hk2sh, index=[0])
303
- # Hongkong to ShenZhen
304
- hk2sz = data['data']['hk2sz']
305
- hk2sz_df = pd.DataFrame(hk2sz, index=[0])
306
-
307
- # Shanghai to Hongkong
308
- sh2hk = data['data']['sh2hk']
309
- sh2hk_df = pd.DataFrame(sh2hk, index=[0])
310
-
311
- # ShenZhen to Hongkong
312
- sz2hk = data['data']['sz2hk']
313
- sz2hk_df = pd.DataFrame(sz2hk, index=[0])
314
- # 北向总额
315
- sum_north_netBuyAmt = hk2sh_df['netBuyAmt'] + hk2sz_df['netBuyAmt']
316
-
317
- sum_south_netBuyAmt = sh2hk_df['netBuyAmt'] + sz2hk_df['netBuyAmt']
318
-
319
- df = pd.DataFrame([[
320
- list(hk2sh_df['netBuyAmt'])[0],
321
- list(hk2sz_df['netBuyAmt'])[0],
322
- list(sum_north_netBuyAmt)[0],
323
- list(sh2hk_df['netBuyAmt'])[0],
324
- list(sz2hk_df['netBuyAmt'])[0],
325
- list(sum_south_netBuyAmt)[0]]],
326
- columns=['sh_netBuyAmt', 'sz_netBuyAmt', 'sum_north_netBuyAmt',
327
- 'sh_hk_netBuyAmt', 'sz_hk_netBuyAmt', 'sum_south_netBuyAmt'])
328
-
329
- # 打印结果
330
- return df
331
-
332
-
333
273
  # 示例调用
334
274
  if __name__ == "__main__":
335
- get_sum_north_south_net_buy_amt()
275
+
336
276
  while True:
337
- df = get_all_real_time_quotes()
277
+ df = get_all_real_time_quotes(None)
338
278
  print(df)
339
279
  zt_df = df.loc[df['wei_bi'] == 100]
340
280
  logger.info("涨停数据,{}", zt_df)
@@ -1,5 +1,5 @@
1
- import sys
2
1
  import os
2
+ import sys
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
5
  end = file_path.index('mns') + 16
@@ -23,7 +23,7 @@ fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,"
23
23
  "f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212")
24
24
 
25
25
 
26
- def hk_real_time_quotes_page_df(cookie, pn):
26
+ def hk_real_time_quotes_page_df(cookie, pn, proxies):
27
27
  try:
28
28
  headers = {
29
29
  'Cookie': cookie
@@ -46,7 +46,10 @@ def hk_real_time_quotes_page_df(cookie, pn):
46
46
  '&fields=' + fields +
47
47
  '&_=' + str(current_timestamp))
48
48
 
49
- r = requests.get(url_new, headers=headers)
49
+ if proxies is None:
50
+ r = requests.get(url_new, headers=headers)
51
+ else:
52
+ r = requests.get(url_new, headers=headers, proxies=proxies)
50
53
  result = r.content.decode("utf-8")
51
54
 
52
55
  if pn == 1:
@@ -179,7 +182,7 @@ def hk_real_time_quotes_page_df(cookie, pn):
179
182
  return pd.DataFrame()
180
183
 
181
184
 
182
- def thread_pool_executor(cookie):
185
+ def thread_pool_executor(cookie, proxies):
183
186
  """
184
187
  使用多线程获取所有ETF数据
185
188
  """
@@ -191,7 +194,7 @@ def thread_pool_executor(cookie):
191
194
  # 创建线程池
192
195
  with ThreadPoolExecutor(max_workers=3) as executor:
193
196
  # 提交任务,获取每页数据
194
- futures = [executor.submit(hk_real_time_quotes_page_df, cookie, pn)
197
+ futures = [executor.submit(hk_real_time_quotes_page_df, cookie, pn, proxies)
195
198
  for pn in range(1, total_pages + 1)]
196
199
 
197
200
  # 收集结果
@@ -208,19 +211,20 @@ def thread_pool_executor(cookie):
208
211
  return pd.DataFrame()
209
212
 
210
213
 
211
- def get_hk_real_time_quotes(cookie):
214
+ def get_hk_real_time_quotes(cookie, proxies):
212
215
  # 获取第一页数据
213
- page_one_df = hk_real_time_quotes_page_df(cookie, 1)
216
+ page_one_df = hk_real_time_quotes_page_df(cookie, 1, proxies)
214
217
  # 数据接口正常返回5600以上的数量
215
218
  if page_one_df.shape[0] > min_number:
216
219
  page_one_df.drop_duplicates('symbol', keep='last', inplace=True)
217
220
  return page_one_df
218
221
  else:
219
- page_df = thread_pool_executor(cookie)
222
+ page_df = thread_pool_executor(cookie, proxies)
220
223
  page_df.drop_duplicates('symbol', keep='last', inplace=True)
221
224
  return page_df
222
225
 
223
226
 
227
+ # 获取港股通名单 todo 被封以后替换
224
228
  def stock_hk_ggt_components_em() -> pd.DataFrame:
225
229
  pn = 1
226
230
 
@@ -320,7 +324,7 @@ if __name__ == '__main__':
320
324
  result_df = stock_hk_ggt_components_em()
321
325
  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'
322
326
  while True:
323
- df_hk_df = get_hk_real_time_quotes(cookie_test)
327
+ df_hk_df = get_hk_real_time_quotes(cookie_test, None)
324
328
  df_hk_df = df_hk_df[[
325
329
  "symbol",
326
330
  "name",
@@ -22,7 +22,7 @@ fields = ("f352,f2,f3,f5,f6,f8,f10,f11,f22,f12,f14,f15,f16,f17,f18,f20,f21,f26,"
22
22
  "f33,f34,f35,f62,f66,f69,f72,f100,f184,f211,f212")
23
23
 
24
24
 
25
- def us_real_time_quotes_page_df(cookie, pn):
25
+ def us_real_time_quotes_page_df(cookie, pn, proxies):
26
26
  try:
27
27
  headers = {
28
28
  'Cookie': cookie
@@ -44,7 +44,10 @@ def us_real_time_quotes_page_df(cookie, pn):
44
44
  "fields": fields,
45
45
  "_": str(current_timestamp),
46
46
  }
47
- r = requests.get(url, params=params, headers=headers, timeout=15)
47
+ if proxies is None:
48
+ r = requests.get(url, params=params, headers=headers)
49
+ else:
50
+ r = requests.get(url, params=params, headers=headers, proxies=proxies)
48
51
  data_json = r.json()
49
52
  if pn == 1:
50
53
  try:
@@ -64,7 +67,7 @@ def us_real_time_quotes_page_df(cookie, pn):
64
67
  return pd.DataFrame()
65
68
 
66
69
 
67
- def thread_pool_executor(cookie):
70
+ def thread_pool_executor(cookie, proxies):
68
71
  """
69
72
  使用多线程获取所有美股数据
70
73
  """
@@ -76,7 +79,7 @@ def thread_pool_executor(cookie):
76
79
  # 创建线程池
77
80
  with ThreadPoolExecutor(max_workers=3) as executor:
78
81
  # 提交任务,获取每页数据
79
- futures = [executor.submit(us_real_time_quotes_page_df, cookie, pn)
82
+ futures = [executor.submit(us_real_time_quotes_page_df, cookie, pn, proxies)
80
83
  for pn in range(1, total_pages + 1)]
81
84
 
82
85
  # 收集结果
@@ -93,16 +96,16 @@ def thread_pool_executor(cookie):
93
96
  return pd.DataFrame()
94
97
 
95
98
 
96
- def get_us_stock_real_time_quotes(cookie):
99
+ def get_us_stock_real_time_quotes(cookie, proxies):
97
100
  # 获取第一页数据
98
- page_one_df = us_real_time_quotes_page_df(cookie, 1)
101
+ page_one_df = us_real_time_quotes_page_df(cookie, 1, proxies)
99
102
  # 数据接口正常返回5600以上的数量
100
103
  if page_one_df.shape[0] > min_number:
101
104
  page_one_df = rename_us_stock(page_one_df)
102
105
  page_one_df.drop_duplicates('symbol', keep='last', inplace=True)
103
106
  return page_one_df
104
107
  else:
105
- page_df = thread_pool_executor(cookie)
108
+ page_df = thread_pool_executor(cookie, proxies)
106
109
  page_df = rename_us_stock(page_df)
107
110
  page_df.drop_duplicates('symbol', keep='last', inplace=True)
108
111
  return page_df
@@ -219,7 +222,7 @@ def rename_us_stock(temp_df):
219
222
  if __name__ == '__main__':
220
223
  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'
221
224
  while True:
222
- us_df = get_us_stock_real_time_quotes(cookie_test)
225
+ us_df = get_us_stock_real_time_quotes(cookie_test, None)
223
226
  us_df = us_df.loc[us_df['flow_mv'] != 0]
224
227
  us_df = us_df.sort_values(by=['amount'], ascending=False)
225
228
  us_stock_df = us_df[[
@@ -31,7 +31,7 @@ import mns_common.component.company.company_common_service_api as company_common
31
31
  # 当设置具体数值n时,循环请求n页,返回n页合并数据。
32
32
 
33
33
 
34
- import mns_common.api.em.east_money_stock_api as east_money_stock_api
34
+ import mns_common.component.em.em_real_time_quotes_api as em_real_time_quotes_api
35
35
  from mns_common.db.MongodbUtil import MongodbUtil
36
36
  import pandas as pd
37
37
  import mns_common.component.common_service_fun_api as common_service_fun_api
@@ -122,7 +122,7 @@ def get_real_time_zt_info():
122
122
  zt_df = get_zt_reason(str_day)
123
123
  if data_frame_util.is_empty(zt_df):
124
124
  return None
125
- real_time_df = east_money_stock_api.get_real_time_quotes_all_stocks()
125
+ real_time_df = em_real_time_quotes_api.get_real_time_quotes_now(None, None)
126
126
 
127
127
  zt_df = merge_high_chg(real_time_df, zt_df)
128
128
 
@@ -274,7 +274,5 @@ def zt_reason_group(zt_pool_df):
274
274
  return result_group_df
275
275
 
276
276
 
277
- import mns_common.api.ths.self_choose.ths_self_choose_api as ths_self_choose_api
278
-
279
277
  if __name__ == '__main__':
280
278
  get_real_time_zt_info()
@@ -40,7 +40,7 @@ from loguru import logger
40
40
  # 当设置具体数值n时,循环请求n页,返回n页合并数据。
41
41
 
42
42
 
43
- import mns_common.api.em.east_money_stock_api as east_money_stock_api
43
+ import mns_common.component.em.em_real_time_quotes_api as em_real_time_quotes_api
44
44
  from mns_common.db.MongodbUtil import MongodbUtil
45
45
  import pandas as pd
46
46
  import mns_common.component.common_service_fun_api as common_service_fun_api
@@ -139,7 +139,7 @@ def convert_statistics(stat):
139
139
 
140
140
  # 获取实时行情涨停列表
141
141
  def get_real_time_zt_info():
142
- real_time_df = east_money_stock_api.get_real_time_quotes_all_stocks()
142
+ real_time_df = em_real_time_quotes_api.get_real_time_quotes_now(None, None)
143
143
  real_time_df_zt = real_time_df.loc[real_time_df['chg'] > common_service_fun_api.ZT_CHG]
144
144
  if data_frame_util.is_empty(real_time_df_zt):
145
145
  return pd.DataFrame()
@@ -0,0 +1,7 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
@@ -0,0 +1,56 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
8
+
9
+ from mns_common.db.MongodbUtil import MongodbUtil
10
+ import mns_common.utils.data_frame_util as data_frame_util
11
+ import mns_common.component.common_service_fun_api as common_service_fun_api
12
+ import mns_common.constant.db_name_constant as db_name_constant
13
+ import mns_common.utils.db_util as db_util
14
+
15
+ mongodb_util = MongodbUtil('27017')
16
+
17
+
18
+ # 获取当天最新实时数据
19
+ def get_real_time_quotes_now(symbol_list, selected_date):
20
+ db_name = db_name_constant.REAL_TIME_QUOTES_NOW
21
+ if selected_date is not None:
22
+ query_day = selected_date[0:10]
23
+ db_name = db_name + '_' + query_day
24
+ db_util_mongo = db_util.get_db(query_day)
25
+ query = {'symbol': '000001'}
26
+ query_field = {"str_now_date": 1, "number": 1, "symbol": 1}
27
+ df = db_util_mongo.find_query_data_choose_field(db_name, query, query_field)
28
+ if df is None or df.shape[0] == 0:
29
+ number = 1
30
+ else:
31
+ df = df[df['str_now_date'] <= selected_date]
32
+ df = df.sort_values(by=['str_now_date'], ascending=False)
33
+ number = list(df['number'])[0]
34
+ # 最新number数据可能还正在写库
35
+
36
+ query = {'number': number}
37
+ real_time_quotes_now = db_util_mongo.find_query_data(db_name, query)
38
+
39
+ else:
40
+
41
+ number = common_service_fun_api.realtime_quotes_now_max_number(db_name,
42
+ 'number')
43
+ # 最新number数据可能还正在写库
44
+ real_time_quotes_now = common_service_fun_api.get_last_new_real_time_data(
45
+ db_name
46
+ , number - 1)
47
+ if (symbol_list is not None
48
+ and data_frame_util.is_not_empty(real_time_quotes_now)):
49
+ real_time_quotes_now = real_time_quotes_now.loc[real_time_quotes_now['symbol'].isin(symbol_list)]
50
+
51
+ return real_time_quotes_now
52
+
53
+
54
+ if __name__ == '__main__':
55
+ df = get_real_time_quotes_now(None, None)
56
+ print(df)