Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version #82

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ master

专注股票量化数据,为Ai(爱)发电,向阳而生。

2.4.0 (2024-07-15)
------------------
1. 新增:股票:单只股票龙虎榜信息接口。
2. 修复:基金:行情空值等bug。

2.3.0 (2024-07-06)
------------------
1. 新增:股票:百度的概念接口。
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ print(res_df)
| | sentiment.hot.hot_rank_100_ths() | 同花顺热度100排行榜 | 来源:[同花顺](https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/stock?stock_type=a&type=hour&list_type=normal) |
| | sentiment.hot.hot_concept_20_ths() | 同花顺热门概念板块20排行榜 | 来源:[同花顺](https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/stock?stock_type=a&type=hour&list_type=normal) |
| | sentiment.hot.list_a_list_daily() | 龙虎榜单列表 | 来源:[东方财富](https://data.eastmoney.com/stock/lhb/yyb/10033779.html) |
| | sentiment.get_a_list_info() | 单只股票龙虎榜信息详情 | 来源:[东方财富](https://data.eastmoney.com/stock/lhb/yyb/10033779.html) |
| 其它数据排期中 | TODO | 若您有相关资源可以一起参与贡献 | |

## 三、[数据源](https://adata.30006124.xyz/dataSource.html)
Expand Down Expand Up @@ -269,9 +270,9 @@ print(res_df)

> 对于项目有支持,包括但不仅限:内容贡献,bug提交,思想交流等等,对项目有影响的个人和机构

| Simon | [bigbigbigfish](https://github.com/bigbigbigfish) | [LuneZ99](https://github.com/LuneZ99) | 匿名用户 | thue | [Triones009](https://github.com/Triones009) | **[adaaaaaa](https://github.com/adaaaaaa)** | **[LeslieWuboy](https://github.com/LeslieWuboy)** | [yinzhengxin](https://github.com/yinzhengxin) |
| ------------------------------------- | ------------------------------------------------- | --------------------------------------------- | -------- | ---- | ------------------------------------------- | ------------------------------------------- | ------------------------------------------------- | --------------------------------------------- |
| [yxm0513](https://github.com/yxm0513) | [hanxuanliang](https://github.com/hanxuanliang) | [akihara-sam](https://github.com/akihara-sam) | | | | | | |
| Simon | [bigbigbigfish](https://github.com/bigbigbigfish) | [LuneZ99](https://github.com/LuneZ99) | 匿名用户 | thue | [Triones009](https://github.com/Triones009) | **[adaaaaaa](https://github.com/adaaaaaa)** | **[LeslieWuboy](https://github.com/LeslieWuboy)** | [yinzhengxin](https://github.com/yinzhengxin) |
| ------------------------------------- | ------------------------------------------------- | --------------------------------------------- | -------- | --------------------------------------- | ------------------------------------------- | ------------------------------------------- | ------------------------------------------------- | --------------------------------------------- |
| [yxm0513](https://github.com/yxm0513) | [hanxuanliang](https://github.com/hanxuanliang) | [akihara-sam](https://github.com/akihara-sam) | Andy | [baei2048](https://github.com/baei2048) | | | | |

----------------------------------------------------------------------

Expand Down
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, 3, 1)
VERSION = (2, 4, 0)
PRERELEASE = None # alpha, beta or rc
REVISION = None

Expand Down
6 changes: 4 additions & 2 deletions adata/fund/market/etf_market_ths.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def get_market_etf_ths(self, fund_code: str = '512880', k_type: int = 1, start_d
text = self._get_text(api_url, fund_code)
if THS_IP_LIMIT_RES in text:
return Exception(THS_IP_LIMIT_MSG)
result_text = text[text.index('{'):-1]
data_list = json.loads(result_text)['data'].split(';')
result_json = json.loads(text[text.index('{'):-1])
if result_json['total'] == 0:
return pd.DataFrame()
data_list = result_json['data'].split(';')
data = []
for d in data_list:
data.append(str(d).split(',')[0:7])
Expand Down
35 changes: 30 additions & 5 deletions adata/sentiment/alist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class AList(BaseThs):
'a_net_amount', 'a_buy_amount', 'a_sell_amount', 'a_amount', 'amount',
'net_amount_rate', 'a_amount_rate', 'reason']

__A_LIST_INFO_COLUMNS = ['trade_date', 'stock_code', 'operate_code', 'operate_name', 'a_buy_amount',
'a_sell_amount', 'a_net_amount', 'a_buy_amount_rate', 'a_sell_amount_rate', 'reason']

# 东方财富人气榜
def list_a_list_daily(self, report_date=None):
"""
Expand Down Expand Up @@ -54,15 +57,37 @@ def list_a_list_daily(self, report_date=None):
df['short_name'] = df['short_name'].str.replace(' ', '')
return df[self.__A_LIST_DAILY_COLUMNS]

def get_a_list(self, stock_code, report_date=None):
def get_a_list_info(self, stock_code, report_date=None):
"""
获取单个龙虎榜的数据,买5和卖5
https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery112307421020653512591_1716975849191&reportName=RPT_BILLBOARD_DAILYDETAILSBUY&columns=ALL&filter=(TRADE_DATE%3D%272024-05-21%27)(SECURITY_CODE%3D%22000070%22)&pageNumber=1&pageSize=50&sortTypes=-1&sortColumns=BUY&source=WEB&client=WEB&_=1716975849193
https://data.eastmoney.com/stock/tradedetail.html
https://datacenter-web.eastmoney.com/api/data/v1/get?callback=jQuery1123015874658470862357_1721014447038&reportName=RPT_BILLBOARD_DAILYDETAILSBUY&columns=ALL&filter=(TRADE_DATE='2024-07-12')(SECURITY_CODE="600297")&pageNumber=1&pageSize=50&sortTypes=-1&sortColumns=BUY&source=WEB&client=WEB&_=1721014447040
"""
pass
# 1. url
urls = [
f"""https://datacenter-web.eastmoney.com/api/data/v1/get?reportName=RPT_BILLBOARD_DAILYDETAILSBUY&columns=ALL&filter=(TRADE_DATE='{report_date}')(SECURITY_CODE="{stock_code}")&pageNumber=1&pageSize=50&sortTypes=-1&sortColumns=BUY&source=WEB&client=WEB&_=1721014447040""",
f"""https://datacenter-web.eastmoney.com/api/data/v1/get?reportName=RPT_BILLBOARD_DAILYDETAILSSELL&columns=ALL&filter=(TRADE_DATE='{report_date}')(SECURITY_CODE="{stock_code}")&pageNumber=1&pageSize=50&sortTypes=-1&sortColumns=BUY&source=WEB&client=WEB&_=1721014447040"""]

# 2. 请求数据
data = []
for url in urls:
res = requests.request(method='post', url=url).json()
if res['result'] is None:
return pd.DataFrame()
data.extend(res['result']["data"])
# ['trade_date', 'stock_code', 'operate_code', 'operate_name', 'buy_amount',
# 'sell_amount','net_amount', 'buy_amount_rate', 'sell_amount_rate', 'reason']
# 3. 解析封装数据
rename = {'SECURITY_CODE': 'stock_code', 'TRADE_DATE': 'trade_date',
'OPERATEDEPT_CODE': 'operate_code', 'OPERATEDEPT_NAME': 'operate_name',
'BUY': 'a_buy_amount', 'SELL': 'a_sell_amount', 'NET': 'a_net_amount',
'TOTAL_BUYRIO': 'a_buy_amount_rate', 'TOTAL_SELLRIO': 'a_sell_amount_rate',
'EXPLANATION': 'reason', }
df = pd.DataFrame(data).rename(columns=rename)
df['trade_date'] = pd.to_datetime(df['trade_date']).dt.strftime('%Y-%m-%d')
df = df.sort_values(by=['reason', 'a_buy_amount', 'a_sell_amount'], ascending=[True, False, False])
return df[self.__A_LIST_INFO_COLUMNS]


if __name__ == '__main__':
print(AList().list_a_list_daily(report_date='2024-07-04'))
print(AList().list_a_list_daily())
print(AList().get_a_list_info(stock_code='600297', report_date='2024-07-12'))
6 changes: 6 additions & 0 deletions tests/adata_test/sentiment/sentiment_hot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def test_list_a_list_daily(self):
print(df)
self.assertEqual(True, len(df) >= 20)

def test_get_a_list_info(self):
print("开始测试:get_a_list_info")
df = adata.sentiment.hot.get_a_list_info(stock_code='600297', report_date='2024-07-12')
print(df)
self.assertEqual(True, len(df) >= 10)


if __name__ == '__main__':
unittest.main()
Loading