Micro-sheep / efinance

efinance 是一个可以快速获取基金、股票、债券、期货数据的 Python 库,回测以及量化交易的好帮手!🚀🚀🚀
MIT License
1.89k stars 477 forks source link

有办法获取ETF”跟踪标的“的指数吗? #20

Open creatiezo opened 3 years ago

creatiezo commented 3 years ago

举个例子,515790的跟踪标的是:”中证光伏产业指数“。这个指数的代码是:931151。 http://fundf10.eastmoney.com/jbgk_515790.html

上面这个网页好像没有发用东财api获取 跟踪标的(”中证光伏产业指数“)这个值。 更没办法找到这个指数的代码931151。

Micro-sheep commented 3 years ago

直接通过基金代码获取其跟踪的指数比较难。不过有 API 可以查询跟踪指数的基金列表。所以你可以先获取全部指数,查询跟踪它的基金,然后就可以知道哪只基金跟踪什么指数了。

creatiezo commented 3 years ago

直接通过基金代码获取其跟踪的指数比较难。不过有 API 可以查询跟踪指数的基金列表。所以你可以先获取全部指数,查询跟踪它的基金,然后就可以知道哪只基金跟踪什么指数了。

能告知是哪个api吗?谢谢。

Micro-sheep commented 3 years ago

API 示例如下

import requests

params = (
    # 页数
    ('pageIndex', '1'),
    # 每一页大小
    ('pageSize', '10'),
    ('sortName', 'RZDF'),
    ('sortType', 'DESC'),
    # 指数代码
    ('filterName1', '399300'),
    ('BKID', '12'),
    ('deviceid', '1234567890'),
    ('version', '6.9.9'),
    ('product', 'EFund'),
    ('plat', 'Iphone'),
    ('ServerVersion', '6.9.9'),
)

response = requests.get(
    'https://fundztapi.eastmoney.com/FundSpecialApiNew/FundSpecialZSB30GZJJ',  params=params)
# 解析这个
json = response.json()

解析里面的 json 即可。这是从东方财富 APP,点击指数界面的购买指数之后出现的。

creatiezo commented 3 years ago

感谢

vensentzhou commented 3 years ago

https://fundztapi.eastmoney.com/FundSpecialApiNew/FundSpecialZSB30GZJJ?pageIndex=1&pageSize=10&sortName=RZDF&sortType=DESC&filterName1=399300&BKID=12&deviceid=1234567890&version=6.9.9&product=EFund&plat=Iphone&ServerVersion=6.9.9 { "Datas": { "FSRQ": "2021-10-08", "GZJJList": [ { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "163407", "SHORTNAME": "兴全沪深300指数(LOF)A", "FSRQ": "2021-10-08", "RZDF": "2.04", "SYL_Z": "2.04", "SYL_Y": "-1.07", "SYL_3Y": "-2.62", "SYL_6Y": "-7.31", "SYL_1N": "3.40", "SYL_2N": "27.71", "ENDNAV": "5006784584.56", "TRKERROR": "0.3263" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "007230", "SHORTNAME": "兴全沪深300指数(LOF)C", "FSRQ": "2021-10-08", "RZDF": "2.03", "SYL_Z": "2.03", "SYL_Y": "-1.10", "SYL_3Y": "-2.72", "SYL_6Y": "-7.49", "SYL_1N": "2.97", "SYL_2N": "26.88", "ENDNAV": "145863551.5", "TRKERROR": "0.3263" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "004789", "SHORTNAME": "富荣沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.57", "SYL_Z": "1.57", "SYL_Y": "1.08", "SYL_3Y": "1.52", "SYL_6Y": "4.93", "SYL_1N": "24.52", "SYL_2N": "111.14", "ENDNAV": "1134989080.24", "TRKERROR": "0.496" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "004788", "SHORTNAME": "富荣沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.57", "SYL_Z": "1.57", "SYL_Y": "1.09", "SYL_3Y": "1.55", "SYL_6Y": "4.98", "SYL_1N": "24.64", "SYL_2N": "111.57", "ENDNAV": "505629505.4", "TRKERROR": "0.496" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "001015", "SHORTNAME": "华夏沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.55", "SYL_Z": "1.55", "SYL_Y": "-0.85", "SYL_3Y": "-1.69", "SYL_6Y": "1.70", "SYL_1N": "14.84", "SYL_2N": "45.32", "ENDNAV": "958617843.09", "TRKERROR": "0.2125" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "001016", "SHORTNAME": "华夏沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.55", "SYL_Z": "1.55", "SYL_Y": "-0.88", "SYL_3Y": "-1.79", "SYL_6Y": "1.40", "SYL_1N": "14.25", "SYL_2N": "43.93", "ENDNAV": "423947559.16", "TRKERROR": "0.2125" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "010736", "SHORTNAME": "易方达沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.51", "SYL_Z": "1.51", "SYL_Y": "1.22", "SYL_3Y": "-3.88", "SYL_6Y": "-8.26", "SYL_1N": "--", "SYL_2N": "--", "ENDNAV": "2308249010.41", "TRKERROR": "--" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "010737", "SHORTNAME": "易方达沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.50", "SYL_Z": "1.50", "SYL_Y": "1.20", "SYL_3Y": "-3.95", "SYL_6Y": "-8.40", "SYL_1N": "--", "SYL_2N": "--", "ENDNAV": "553383552.56", "TRKERROR": "--" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "003015", "SHORTNAME": "中金沪深300A", "FSRQ": "2021-10-08", "RZDF": "1.38", "SYL_Z": "1.38", "SYL_Y": "0.06", "SYL_3Y": "-0.76", "SYL_6Y": "-0.39", "SYL_1N": "13.70", "SYL_2N": "56.83", "ENDNAV": "280529828.66", "TRKERROR": "0.1852" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "003579", "SHORTNAME": "中金沪深300C", "FSRQ": "2021-10-08", "RZDF": "1.37", "SYL_Z": "1.37", "SYL_Y": "0.02", "SYL_3Y": "-0.87", "SYL_6Y": "-0.59", "SYL_1N": "13.23", "SYL_2N": "55.61", "ENDNAV": "214463909.46", "TRKERROR": "0.1852" } ] }, "ErrCode": 0, "Success": true, "ErrMsg": null, "Message": null, "ErrorCode": "0", "ErrorMessage": null, "ErrorMsgLst": null, "TotalCount": 137, "Expansion": null } 这里查询到的都是场外基金。 请教大佬:如果我想查寻跟踪“中证畜牧养殖指数”的ETF有哪些?有什么好方法?

Micro-sheep commented 3 years ago

https://fundztapi.eastmoney.com/FundSpecialApiNew/FundSpecialZSB30GZJJ?pageIndex=1&pageSize=10&sortName=RZDF&sortType=DESC&filterName1=399300&BKID=12&deviceid=1234567890&version=6.9.9&product=EFund&plat=Iphone&ServerVersion=6.9.9 { "Datas": { "FSRQ": "2021-10-08", "GZJJList": [ { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "163407", "SHORTNAME": "兴全沪深300指数(LOF)A", "FSRQ": "2021-10-08", "RZDF": "2.04", "SYL_Z": "2.04", "SYL_Y": "-1.07", "SYL_3Y": "-2.62", "SYL_6Y": "-7.31", "SYL_1N": "3.40", "SYL_2N": "27.71", "ENDNAV": "5006784584.56", "TRKERROR": "0.3263" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "007230", "SHORTNAME": "兴全沪深300指数(LOF)C", "FSRQ": "2021-10-08", "RZDF": "2.03", "SYL_Z": "2.03", "SYL_Y": "-1.10", "SYL_3Y": "-2.72", "SYL_6Y": "-7.49", "SYL_1N": "2.97", "SYL_2N": "26.88", "ENDNAV": "145863551.5", "TRKERROR": "0.3263" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "004789", "SHORTNAME": "富荣沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.57", "SYL_Z": "1.57", "SYL_Y": "1.08", "SYL_3Y": "1.52", "SYL_6Y": "4.93", "SYL_1N": "24.52", "SYL_2N": "111.14", "ENDNAV": "1134989080.24", "TRKERROR": "0.496" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "004788", "SHORTNAME": "富荣沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.57", "SYL_Z": "1.57", "SYL_Y": "1.09", "SYL_3Y": "1.55", "SYL_6Y": "4.98", "SYL_1N": "24.64", "SYL_2N": "111.57", "ENDNAV": "505629505.4", "TRKERROR": "0.496" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "001015", "SHORTNAME": "华夏沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.55", "SYL_Z": "1.55", "SYL_Y": "-0.85", "SYL_3Y": "-1.69", "SYL_6Y": "1.70", "SYL_1N": "14.84", "SYL_2N": "45.32", "ENDNAV": "958617843.09", "TRKERROR": "0.2125" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "001016", "SHORTNAME": "华夏沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.55", "SYL_Z": "1.55", "SYL_Y": "-0.88", "SYL_3Y": "-1.79", "SYL_6Y": "1.40", "SYL_1N": "14.25", "SYL_2N": "43.93", "ENDNAV": "423947559.16", "TRKERROR": "0.2125" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "010736", "SHORTNAME": "易方达沪深300指数增强A", "FSRQ": "2021-10-08", "RZDF": "1.51", "SYL_Z": "1.51", "SYL_Y": "1.22", "SYL_3Y": "-3.88", "SYL_6Y": "-8.26", "SYL_1N": "--", "SYL_2N": "--", "ENDNAV": "2308249010.41", "TRKERROR": "--" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "010737", "SHORTNAME": "易方达沪深300指数增强C", "FSRQ": "2021-10-08", "RZDF": "1.50", "SYL_Z": "1.50", "SYL_Y": "1.20", "SYL_3Y": "-3.95", "SYL_6Y": "-8.40", "SYL_1N": "--", "SYL_2N": "--", "ENDNAV": "553383552.56", "TRKERROR": "--" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "003015", "SHORTNAME": "中金沪深300A", "FSRQ": "2021-10-08", "RZDF": "1.38", "SYL_Z": "1.38", "SYL_Y": "0.06", "SYL_3Y": "-0.76", "SYL_6Y": "-0.39", "SYL_1N": "13.70", "SYL_2N": "56.83", "ENDNAV": "280529828.66", "TRKERROR": "0.1852" }, { "BKID": "12", "IndexCode": "000300", "IndexName": "沪深300指数", "FCODE": "003579", "SHORTNAME": "中金沪深300C", "FSRQ": "2021-10-08", "RZDF": "1.37", "SYL_Z": "1.37", "SYL_Y": "0.02", "SYL_3Y": "-0.87", "SYL_6Y": "-0.59", "SYL_1N": "13.23", "SYL_2N": "55.61", "ENDNAV": "214463909.46", "TRKERROR": "0.1852" } ] }, "ErrCode": 0, "Success": true, "ErrMsg": null, "Message": null, "ErrorCode": "0", "ErrorMessage": null, "ErrorMsgLst": null, "TotalCount": 137, "Expansion": null } 这里查询到的都是场外基金。 请教大佬:如果我想查寻跟踪“中证畜牧养殖指数”的ETF有哪些?有什么好方法?

我看了一下你说的这个指数,目前想到的方法是:逐个获取全部 ETF 跟踪的指数名称,比如下面这个

示例 ETF

image 获取到之后,通过关键词匹配操作,大致匹配出可能的 ETF,然后再人工筛选一下应该就可以了。