Skip to content

Commit

Permalink
fix: fix spot_goods
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandking committed Dec 26, 2024
1 parent c9376c9 commit 8b04050
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
14 changes: 9 additions & 5 deletions akshare/index/index_spot.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/6/11 21:30
Date: 2024/12/26 18:30
Desc: 商品现货价格指数
http://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0
https://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0
"""

import pandas as pd
import requests


def spot_goods(symbol: str = "波罗的海干散货指数") -> pd.DataFrame:
"""
新浪财经-商品现货价格指数
http://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0
https://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0
:param symbol: choice of {"波罗的海干散货指数", "钢坯价格指数", "澳大利亚粉矿价格"}
:type symbol: str
:return: 商品现货价格指数
:rtype: pandas.DataFrame
"""
url = "http://stock.finance.sina.com.cn/futures/api/openapi.php/GoodsIndexService.get_goods_index"
url = "https://stock.finance.sina.com.cn/futures/api/openapi.php/GoodsIndexService.get_goods_index"
symbol_url_dict = {
"波罗的海干散货指数": "BDI",
"钢坯价格指数": "GP",
Expand All @@ -31,10 +32,13 @@ def spot_goods(symbol: str = "波罗的海干散货指数") -> pd.DataFrame:
temp_df = pd.DataFrame(data_json["result"]["data"]["data"])
temp_df = temp_df[["opendate", "price", "zde", "zdf"]]
temp_df.columns = ["日期", "指数", "涨跌额", "涨跌幅"]
temp_df["日期"] = pd.to_datetime(temp_df["日期"], format="%Y-%m-%d", errors="coerce").dt.date
temp_df["日期"] = pd.to_datetime(
temp_df["日期"], format="%Y-%m-%d", errors="coerce"
).dt.date
temp_df["指数"] = pd.to_numeric(temp_df["指数"], errors="coerce")
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
temp_df.dropna(inplace=True, ignore_index=True)
return temp_df


Expand Down
26 changes: 13 additions & 13 deletions docs/data/index/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2404,19 +2404,19 @@ print(spot_goods_df)
数据示例

```
日期 指数 涨跌额 涨跌幅
0 NaT 919.0 -18.0 -1.9200
1 2006-06-23 2808.0 83.0 0.0305
2 2006-06-30 2964.0 156.0 0.0556
3 2006-07-07 2870.0 -94.0 -0.0317
4 2006-07-14 2968.0 98.0 0.0341
... ... ... ...
3284 2023-06-02 919.0 -18.0 -1.9200
3285 2023-06-05 939.0 20.0 2.1800
3286 2023-06-06 1016.0 77.0 8.2000
3287 2023-06-07 1020.0 4.0 0.3900
3288 2023-06-08 1040.0 20.0 1.9600
[3289 rows x 4 columns]
日期 指数 涨跌额 涨跌幅
0 2006-06-23 2808.0 83.0 0.0305
1 2006-06-30 2964.0 156.0 0.0556
2 2006-07-07 2870.0 -94.0 -0.0317
3 2006-07-14 2968.0 98.0 0.0341
4 2006-07-21 3191.0 223.0 0.0751
... ... ... ... ...
3673 2024-12-18 1028.0 -25.0 -2.3700
3674 2024-12-19 976.0 -52.0 -5.0600
3675 2024-12-20 990.0 14.0 1.4300
3676 2024-12-23 994.0 4.0 0.4000
3677 2024-12-24 997.0 3.0 0.3000
[3678 rows x 4 columns]
```

### 义乌小商品指数
Expand Down

0 comments on commit 8b04050

Please sign in to comment.