diff --git a/HISTORY.md b/HISTORY.md index ac0bb31..fba6364 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,11 @@ master 专注股票量化数据,为Ai(爱)发电,向阳而生。 +2.4.0 (2024-07-15) +------------------ +1. 新增:股票:单只股票龙虎榜信息接口。 +2. 修复:基金:行情空值等bug。 + 2.3.0 (2024-07-06) ------------------ 1. 新增:股票:百度的概念接口。 diff --git a/README.md b/README.md index e3668ae..25d2aa8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) | | | | | ---------------------------------------------------------------------- diff --git a/adata/__version__.py b/adata/__version__.py index e841060..40c6a3e 100644 --- a/adata/__version__.py +++ b/adata/__version__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -VERSION = (2, 3, 1) +VERSION = (2, 4, 0) PRERELEASE = None # alpha, beta or rc REVISION = None diff --git a/adata/fund/market/etf_market_ths.py b/adata/fund/market/etf_market_ths.py index 10432a4..76d7229 100644 --- a/adata/fund/market/etf_market_ths.py +++ b/adata/fund/market/etf_market_ths.py @@ -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]) diff --git a/adata/sentiment/alist.py b/adata/sentiment/alist.py index 09592da..2f3acfc 100644 --- a/adata/sentiment/alist.py +++ b/adata/sentiment/alist.py @@ -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): """ @@ -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')) diff --git a/tests/adata_test/sentiment/sentiment_hot_test.py b/tests/adata_test/sentiment/sentiment_hot_test.py index b6e41b1..1cef29f 100644 --- a/tests/adata_test/sentiment/sentiment_hot_test.py +++ b/tests/adata_test/sentiment/sentiment_hot_test.py @@ -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()