diff --git a/akshare/__init__.py b/akshare/__init__.py index b2c90a62287..26ca2223c06 100644 --- a/akshare/__init__.py +++ b/akshare/__init__.py @@ -2677,9 +2677,10 @@ 1.12.62 fix: fix stock_fund_flow_individual interface 1.12.63 add: add akqmt interface 1.12.64 fix: fix stock_board_industry_index_ths interface +1.12.65 fix: fix futures_foreign_commodity_realtime interface """ -__version__ = "1.12.64" +__version__ = "1.12.65" __author__ = "AKFamily" import sys diff --git a/akshare/futures/futures_hq_sina.py b/akshare/futures/futures_hq_sina.py index b8c876b9ec7..8479cef668e 100644 --- a/akshare/futures/futures_hq_sina.py +++ b/akshare/futures/futures_hq_sina.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- """ -Date: 2024/1/17 15:30 +Date: 2024/2/22 14:00 Desc: 新浪财经-外盘期货 https://finance.sina.com.cn/money/future/hf.html """ @@ -12,6 +12,7 @@ from bs4 import BeautifulSoup from akshare.utils import demjson +from typing import Union, List def _get_real_name_list() -> list: @@ -95,16 +96,20 @@ def futures_hq_subscribe_exchange_symbol() -> pd.DataFrame: return temp_df -def futures_foreign_commodity_realtime(subscribe_list: list) -> pd.DataFrame: +def futures_foreign_commodity_realtime(symbol: Union[str, List[str]]) -> pd.DataFrame: """ 新浪-外盘期货-行情数据 https://finance.sina.com.cn/money/future/hf.html - :param subscribe_list: 通过调用 ak.futures_hq_subscribe_exchange_symbol() 函数来获取 - :type subscribe_list: list + :param symbol: 通过调用 ak.futures_hq_subscribe_exchange_symbol() 函数来获取 + :type symbol: list or str :return: 行情数据 :rtype: pandas.DataFrame """ - payload = "?list=" + ",".join(["hf_" + item for item in subscribe_list]) + if isinstance(symbol, list): + payload = "?list=" + ",".join(["hf_" + item for item in symbol]) + else: + symbol = symbol.split(",") + payload = "?list=" + ",".join(["hf_" + item for item in symbol]) url = "http://hq.sinajs.cn/" + payload headers = { 'Accept': '*/*', @@ -153,7 +158,7 @@ def futures_foreign_commodity_realtime(subscribe_list: list) -> pd.DataFrame: ] temp_symbol_code_df = futures_hq_subscribe_exchange_symbol() temp_symbol_code_dict = dict(zip(temp_symbol_code_df['code'], temp_symbol_code_df['symbol'])) - data_df["symbol"] = [temp_symbol_code_dict[subscribe] for subscribe in subscribe_list] + data_df["symbol"] = [temp_symbol_code_dict[subscribe] for subscribe in symbol] data_df = data_df[ [ "symbol", @@ -256,13 +261,18 @@ def futures_foreign_commodity_realtime(subscribe_list: list) -> pd.DataFrame: subscribes = futures_foreign_commodity_subscribe_exchange_symbol() futures_foreign_commodity_realtime_df = futures_foreign_commodity_realtime( - subscribe_list=['CT', 'NID'] + symbol='CT,NID' + ) + print(futures_foreign_commodity_realtime_df) + + futures_foreign_commodity_realtime_df = futures_foreign_commodity_realtime( + symbol=['CT', 'NID'] ) print(futures_foreign_commodity_realtime_df) while True: futures_foreign_commodity_realtime_df = futures_foreign_commodity_realtime( - subscribe_list=subscribes + symbol=subscribes ) print(futures_foreign_commodity_realtime_df) time.sleep(3) diff --git a/docs/changelog.md b/docs/changelog.md index 6ee335841bd..5dfd4755bad 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -71,6 +71,10 @@ ## 更新说明详情 +1.12.65 fix: fix futures_foreign_commodity_realtime interface + + 1. 修复 futures_foreign_commodity_realtime 接口 + 1.12.64 fix: fix stock_board_industry_index_ths interface 1. 修复 stock_board_industry_index_ths 接口 @@ -3568,6 +3572,8 @@ ## 版本更新说明 +1.12.65 fix: fix futures_foreign_commodity_realtime interface + 1.12.64 fix: fix stock_board_industry_index_ths interface 1.12.63 add: add akqmt interface diff --git a/docs/data/futures/futures.md b/docs/data/futures/futures.md index 3886c98fa84..ff1b3dc222b 100644 --- a/docs/data/futures/futures.md +++ b/docs/data/futures/futures.md @@ -2561,9 +2561,9 @@ print(futures_hq_subscribe_exchange_symbol_df) 输入参数 -| 名称 | 类型 | 描述 | -|----------------|------|------------------------------------------------------------------------| -| subscribe_list | list | 需要订阅的合约代码; 调用 **ak.futures_hq_subscribe_exchange_symbol()** 获取字段及代码对应表 | +| 名称 | 类型 | 描述 | +|--------|-------------|------------------------------------------------------------------------| +| symbol | list or str | 需要订阅的合约代码; 调用 **ak.futures_hq_subscribe_exchange_symbol()** 获取字段及代码对应表 | 输出参数 @@ -2584,21 +2584,39 @@ print(futures_hq_subscribe_exchange_symbol_df) | 行情时间 | object | - | | 日期 | object | - | -接口示例 +接口示例-传入字符串 + +```python +import akshare as ak + +futures_foreign_commodity_realtime_df = ak.futures_foreign_commodity_realtime(symbol='CT,NID') +print(futures_foreign_commodity_realtime_df) +``` + +数据示例-传入字符串 + +``` + 名称 最新价 人民币报价 ... 卖价 行情时间 日期 +0 NYBOT-棉花 93.492 6.721607 ... 93.49 14:34:21 2024-02-22 +1 LME镍3个月 16974.000 3923.411522 ... 16980.00 14:31:46 2024-02-22 +[2 rows x 14 columns] +``` + +接口示例-传入列表 ```python import time import akshare as ak print("开始接收实时行情, 每 3 秒刷新一次") -subscribe_list = ak.futures_foreign_commodity_subscribe_exchange_symbol() +subscribe_list = ak.futures_foreign_commodity_subscribe_exchange_symbol() # 其中 subscribe_list 为列表 while True: time.sleep(3) - futures_foreign_commodity_realtime_df = ak.futures_foreign_commodity_realtime(subscribe_list=subscribe_list) + futures_foreign_commodity_realtime_df = ak.futures_foreign_commodity_realtime(symbol=subscribe_list) print(futures_foreign_commodity_realtime_df) ``` -数据示例 +数据示例-传入列表 ``` 名称 最新价 ... 行情时间 日期