mns-common 1.3.6.8__py3-none-any.whl → 1.3.7.0__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 (23) 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} +32 -76
  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/constant/db_name_constant.py +15 -0
  17. {mns_common-1.3.6.8.dist-info → mns_common-1.3.7.0.dist-info}/METADATA +1 -1
  18. {mns_common-1.3.6.8.dist-info → mns_common-1.3.7.0.dist-info}/RECORD +21 -17
  19. mns_common/api/em/east_money_stock_api.py +0 -233
  20. mns_common/api/em/east_money_stock_quotes_sync_api.py +0 -250
  21. /mns_common/api/em/{em_concept_index_api.py → concept/em_concept_index_api.py} +0 -0
  22. {mns_common-1.3.6.8.dist-info → mns_common-1.3.7.0.dist-info}/WHEEL +0 -0
  23. {mns_common-1.3.6.8.dist-info → mns_common-1.3.7.0.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)
@@ -13,10 +13,23 @@ from concurrent.futures import ThreadPoolExecutor
13
13
  import datetime
14
14
  from loguru import logger
15
15
 
16
- fields_02 = "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36,f37,f38,f39,f40,f41,f42,f43,f44,f45,f46,f47,f48,f49,f50,f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65,f66,f67,f68,f69,f70,f71,f72,f73,f74,f75,f76,f77,f78,f79,f80,f81,f82,f83,f84,f85,f86,f87,f88,f89,f90,f91,f92,f93,f94,f95,f96,f97,f98,f99,f100,f101,f102,f103,f104,f105,f106,f107,f108" \
17
- ",f109,f110,f111,f112,f113,f114,f115,f116,f117,f118,f119,f120,f121,f122,f123,f124,f125,f126,f127,f128,f129,f130,f131,f132,f133,f134,f135,f136,f137,f138,f139,f140,f141,f142,f143,f144,f145,f146,f147,f148,f149,f150,f151,f152,f153,f154,f155,f156,f157,f158,f159,f160,f161,f162,f163,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183,f184,f185,f186,f187,f188,f189,f190,f191,f192,f193,f194,f195,f196,f197,f198,f199,f200" \
18
- ",f209,f210,f212,f213,f214,f215,f216,f217,f218,f219,f220,f221,f222,f223,f224,f225,f226,f227,f228,f229,f230,f231,f232,f233,f234,f235,f236,f237,f238,f239,f240,f241,f242,f243,f244,f245,f246,f247,f248,f249,f250,f251,f252,f253,f254,f255,f256,f257,f258,f259,f260,f261,f262,f263,f264,f265,f266,f267,f268,f269,f270,f271,f272,f273,f274,f275,f276,f277,f278,f279,f280,f281,f282,f283,f284,f285,f286,f287,f288,f289,f290,f291,f292,f293,f294,f295,f296,f297,f298,f299,f300" \
19
- ",f309,f310,f312,f313,f314,f315,f316,f317,f318,f319,f320,f321,f322,f323,f324,f325,f326,f327,f328,f329,f330,f331,f332,f333,f334,f335,f336,f337,f338,f339,f340,f341,f342,f343,f344,f345,f346,f347,f348,f349,f350,f351,f352,f353,f354,f355,f356,f357,f358,f359,f360,f361,f362,f363,f364,f365,f366,f367,f368,f369,f370,f371,f372,f373,f374,f375,f376,f377,f378,f379,f380,f381,f382,f383,f384,f385,f386,f387,f388,f389,f390,f391,f392,f393,f394,f395,f396,f397,f398,f399,f401"
16
+ #
17
+ # fields_02 = "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,f25,f26,f27,f28,f29,f30,f31,f32,f33,f34,f35,f36,f37,f38,f39,f40,f41,f42,f43,f44,f45,f46,f47,f48,f49,f50,f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65,f66,f67,f68,f69,f70,f71,f72,f73,f74,f75,f76,f77,f78,f79,f80,f81,f82,f83,f84,f85,f86,f87,f88,f89,f90,f91,f92,f93,f94,f95,f96,f97,f98,f99,f100,f101,f102,f103,f104,f105,f106,f107,f108" \
18
+ # ",f109,f110,f111,f112,f113,f114,f115,f116,f117,f118,f119,f120,f121,f122,f123,f124,f125,f126,f127,f128,f129,f130,f131,f132,f133,f134,f135,f136,f137,f138,f139,f140,f141,f142,f143,f144,f145,f146,f147,f148,f149,f150,f151,f152,f153,f154,f155,f156,f157,f158,f159,f160,f161,f162,f163,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183,f184,f185,f186,f187,f188,f189,f190,f191,f192,f193,f194,f195,f196,f197,f198,f199,f200" \
19
+ # ",f209,f210,f212,f213,f214,f215,f216,f217,f218,f219,f220,f221,f222,f223,f224,f225,f226,f227,f228,f229,f230,f231,f232,f233,f234,f235,f236,f237,f238,f239,f240,f241,f242,f243,f244,f245,f246,f247,f248,f249,f250,f251,f252,f253,f254,f255,f256,f257,f258,f259,f260,f261,f262,f263,f264,f265,f266,f267,f268,f269,f270,f271,f272,f273,f274,f275,f276,f277,f278,f279,f280,f281,f282,f283,f284,f285,f286,f287,f288,f289,f290,f291,f292,f293,f294,f295,f296,f297,f298,f299,f300" \
20
+ # ",f309,f310,f312,f313,f314,f315,f316,f317,f318,f319,f320,f321,f322,f323,f324,f325,f326,f327,f328,f329,f330,f331,f332,f333,f334,f335,f336,f337,f338,f339,f340,f341,f342,f343,f344,f345,f346,f347,f348,f349,f350,f351,f352,f353,f354,f355,f356,f357,f358,f359,f360,f361,f362,f363,f364,f365,f366,f367,f368,f369,f370,f371,f372,f373,f374,f375,f376,f377,f378,f379,f380,f381,f382,f383,f384,f385,f386,f387,f388,f389,f390,f391,f392,f393,f394,f395,f396,f397,f398,f399,f401"
21
+
22
+
23
+ fields = ("f2,f3,f5,f6,f8,"
24
+ "f9,f10,f22,f12,f13,"
25
+ "f14,f15,f16,f17,f18,"
26
+ "f20,f21,f23,f26,f33,"
27
+ "f34,f35,f37,f38,f39,"
28
+ "f62,f64,f65,f67,f68,"
29
+ "f66,f69,f70,f71,f72,"
30
+ "f76,f77,f78,f82,f83,"
31
+ "f84,f102,f184,f100,f103,"
32
+ "f352,f191,f193,f24,f25")
20
33
 
21
34
  # 最大返回条数
22
35
  max_number = 5800
@@ -26,7 +39,7 @@ min_number = 5600
26
39
  page_number = 100
27
40
 
28
41
 
29
- def get_stock_page_data(pn, fields, fs):
42
+ def get_stock_page_data(pn, fields, fs, proxies):
30
43
  """
31
44
  获取单页股票数据
32
45
  """
@@ -53,7 +66,10 @@ def get_stock_page_data(pn, fields, fs):
53
66
  "_": current_timestamp_ms
54
67
  }
55
68
  try:
56
- r = requests.get(url, params)
69
+ if proxies is None:
70
+ r = requests.get(url, params)
71
+ else:
72
+ r = requests.get(url, params, proxies=proxies)
57
73
  data_text = r.text
58
74
  begin_index = data_text.index('[')
59
75
  end_index = data_text.index(']')
@@ -68,7 +84,7 @@ def get_stock_page_data(pn, fields, fs):
68
84
  return pd.DataFrame()
69
85
 
70
86
 
71
- def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
87
+ def all_stock_ticker_data_new(fields, fs, proxies) -> pd.DataFrame:
72
88
  """
73
89
  使用多线程获取所有股票数据
74
90
  """
@@ -79,7 +95,7 @@ def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
79
95
  # 创建线程池
80
96
  with ThreadPoolExecutor(max_workers=10) as executor:
81
97
  # 提交任务,获取每页数据
82
- futures = [executor.submit(get_stock_page_data, pn, fields, fs)
98
+ futures = [executor.submit(get_stock_page_data, pn, fields, fs, proxies)
83
99
  for pn in range(1, total_pages + 1)]
84
100
 
85
101
  # 收集结果
@@ -96,16 +112,16 @@ def all_stock_ticker_data_new(fields, fs) -> pd.DataFrame:
96
112
  return pd.DataFrame()
97
113
 
98
114
 
99
- def get_all_real_time_quotes():
115
+ def get_all_real_time_quotes(proxies):
100
116
  fs = "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048"
101
117
  # 获取第一页数据
102
- page_one_df = get_stock_page_data(1, fields_02, fs)
118
+ page_one_df = get_stock_page_data(1, fields, fs, proxies)
103
119
  # 数据接口正常返回5600以上的数量
104
120
  if page_one_df.shape[0] > min_number:
105
121
  page_one_df = rename_real_time_quotes_df(page_one_df)
106
122
  return page_one_df
107
123
  else:
108
- page_df = all_stock_ticker_data_new(fields_02, fs)
124
+ page_df = all_stock_ticker_data_new(fields, fs, proxies)
109
125
  page_df = rename_real_time_quotes_df(page_df)
110
126
  return page_df
111
127
 
@@ -149,16 +165,19 @@ def rename_real_time_quotes_df(temp_df):
149
165
  "f70": "large_order_inflow",
150
166
  "f71": "large_order_outflow",
151
167
  "f72": "large_order_net_inflow",
168
+
152
169
  "f76": "medium_order_inflow",
153
170
  "f77": "medium_order_outflow",
154
171
  "f78": "medium_order_net_inflow",
155
172
  "f82": "small_order_inflow",
156
173
  "f83": "small_order_outflow",
174
+
157
175
  "f84": "small_order_net_inflow",
158
176
  "f102": "area",
159
177
  "f184": "today_main_net_inflow_ratio",
160
178
  "f100": "industry",
161
179
  "f103": "concept",
180
+
162
181
  "f352": "average_price",
163
182
  "f191": "hk_stock_code",
164
183
  "f193": "hk_stock_name",
@@ -267,74 +286,11 @@ def rename_real_time_quotes_df(temp_df):
267
286
  return temp_df
268
287
 
269
288
 
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
289
  # 示例调用
334
290
  if __name__ == "__main__":
335
- get_sum_north_south_net_buy_amt()
291
+
336
292
  while True:
337
- df = get_all_real_time_quotes()
293
+ df = get_all_real_time_quotes(None)
338
294
  print(df)
339
295
  zt_df = df.loc[df['wei_bi'] == 100]
340
296
  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()