Skip to content
Merged

Dev #127

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adata/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

VERSION = (2, 8, 2)
VERSION = (2, 8, 3)
PRERELEASE = None # alpha, beta or rc
REVISION = None

Expand Down
28 changes: 18 additions & 10 deletions adata/stock/info/concept/stock_concept_east.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ def all_concept_code_east(self):
https://push2.eastmoney.com/api/qt/clist/get?pn=1&pz=1000&po=1&np=1&fields=f12%2Cf13%2Cf14%2Cf62&fid=f62&fs=m%3A90%2Bt%3A3
:return: 概念[[name,index_code,concept_code]]
"""
url = f"https://push2.eastmoney.com/api/qt/clist/get" \
f"?pn=1&pz=1000&po=1&np=1&fields=f12%2Cf13%2Cf14%2Cf62&fid=f62&fs=m%3A90%2Bt%3A3"
res_json = requests.request('get', url, headers={}, proxies={}).json()
res_data = res_json['data']['diff']
curr_page = 1
page_size = 100
data = []
for _ in res_data:
data.append({'index_code': _['f12'], 'concept_code': _['f12'], 'name': _['f14'], 'source': '东方财富'})
while curr_page < 50:
url = f"https://push2.eastmoney.com/api/qt/clist/get" \
f"?pn={curr_page}&pz={page_size}&po=1&np=1&fields=f12%2Cf13%2Cf14%2Cf62&fid=f62&fs=m%3A90%2Bt%3A3"
res_json = requests.request('get', url, headers={}, proxies={}).json()
res_data = res_json['data']['diff']
if not res_data:
break
for _ in res_data:
data.append({'index_code': _['f12'], 'concept_code': _['f12'], 'name': _['f14'], 'source': '东方财富'})
if len(res_data) < page_size:
break
curr_page += 1
result_df = pd.DataFrame(data=data, columns=self._CONCEPT_CODE_COLUMNS)
return result_df

Expand All @@ -51,9 +59,9 @@ def concept_constituent_east(self, concept_code=None, wait_time=None):
"""
curr_page = 1
data = []
while curr_page < 6:
while curr_page < 100:
url = f"https://push2.eastmoney.com/api/qt/clist/get" \
f"?fid=f62&po=1&pz=1000&pn={curr_page}&np=1&fltt=2&invt=2&fs=b:{concept_code}&fields=f12,f14"
f"?fid=f62&po=1&pz=200&pn={curr_page}&np=1&fltt=2&invt=2&fs=b:{concept_code}&fields=f12,f14"
res_json = requests.request('get', url, headers={}, proxies={}, wait_time=wait_time).json()
res_data = res_json['data']
if not res_data:
Expand Down Expand Up @@ -135,5 +143,5 @@ def get_plate_east(self, stock_code: str = '000001', plate_type=None):
if __name__ == '__main__':
print(StockConceptEast().all_concept_code_east())
print(StockConceptEast().concept_constituent_east(concept_code="BK0637"))
print(StockConceptEast().get_concept_east(stock_code="600020").to_string())
print(StockConceptEast().get_plate_east(stock_code="600020", plate_type=1).to_string())
# print(StockConceptEast().get_concept_east(stock_code="600020").to_string())
# print(StockConceptEast().get_plate_east(stock_code="600020", plate_type=1).to_string())
39 changes: 25 additions & 14 deletions adata/stock/info/stock_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,32 @@ def __market_rank_east(self):
https://quote.eastmoney.com/center/gridlist.html
"""
url = "https://82.push2.eastmoney.com/api/qt/clist/get"
params = {
"pn": "1", "pz": "50000",
"po": "1", "np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2", "invt": "2", "fid": "f3",
"fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
"fields": "f12,f14",
"_": "1623833739532",
}
# 请求数据
r = requests.request(url=url, timeout=15, params=params)
data_json = r.json()
if not data_json["data"]["diff"]:
curr_page = 1
page_size = 200
data = []
while curr_page < 50:
params = {
"pn": curr_page, "pz": page_size,
"po": "1", "np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2", "invt": "2", "fid": "f3",
"fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
"fields": "f12,f14",
"_": "1623833739532",
}
# 请求数据
r = requests.request(url=url, timeout=15, params=params)
data_json = r.json()
p_data = data_json["data"]["diff"]
if not p_data:
break
data = data.append(p_data)
if len(p_data) < page_size:
break
curr_page += 1
if len(data) == 0:
return pd.DataFrame()
df = pd.DataFrame(data=data_json["data"]["diff"])
df = pd.DataFrame(data=data)
df.columns = ['stock_code', 'short_name']
# 数据etl
df['exchange'] = df['stock_code'].apply(lambda x: get_exchange_by_stock_code(x))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def get_capital_flow(self, stock_code: str = '000001', start_date=None, end_date

if __name__ == '__main__':
print(StockCapitalFlowBaidu().get_capital_flow_min(stock_code='300059'))
print(StockCapitalFlowBaidu().get_capital_flow(stock_code='300059', start_date='2024-01-01', end_date='2024-04-01'))
print(StockCapitalFlowBaidu().get_capital_flow(stock_code='688403', start_date='2024-01-01', end_date='2024-04-01'))
2 changes: 1 addition & 1 deletion tests/adata_test/stock/capital_flow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_get_flow_min(self):

def test_get_flow(self):
print("开始测试:get_flow")
df = adata.stock.market.get_capital_flow(stock_code='000001')
df = adata.stock.market.get_capital_flow(stock_code='688403')
print(df)
self.assertEqual(True, len(df) > 200)

Expand Down