Skip to content

Commit

Permalink
Date (#4522)
Browse files Browse the repository at this point in the history
* add version 1.12.65

* fix futures_foreign_commodity_realtime
  • Loading branch information
albertandking authored Feb 22, 2024
1 parent ee34ba2 commit fa8fc68
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
3 changes: 2 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions akshare/futures/futures_hq_sina.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -12,6 +12,7 @@
from bs4 import BeautifulSoup

from akshare.utils import demjson
from typing import Union, List


def _get_real_name_list() -> list:
Expand Down Expand Up @@ -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': '*/*',
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 接口
Expand Down Expand Up @@ -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
Expand Down
32 changes: 25 additions & 7 deletions docs/data/futures/futures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()** 获取字段及代码对应表 |

输出参数

Expand All @@ -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)
```

数据示例
数据示例-传入列表

```
名称 最新价 ... 行情时间 日期
Expand Down

0 comments on commit fa8fc68

Please sign in to comment.