Skip to content

Commit

Permalink
获取指数成分股
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jun 12, 2022
1 parent e4e37b2 commit d99eb8c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
60 changes: 60 additions & 0 deletions datacenter/eastmoney/zscfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 指数成分股

package eastmoney

import (
"context"
"fmt"

"github.com/axiaoxin-com/goutils"
"github.com/corpix/uarand"
)

// ZSCFGItem 指数成分股信息
type ZSCFGItem struct {
IndexCode string `json:"IndexCode"` // 指数代码
IndexName string `json:"IndexName"` // 指数名称
StockCode string `json:"StockCode"` // 股票代码
StockName string `json:"StockName"` // 股票名称
Snewprice string `json:"SNEWPRICE"`
Snewchg string `json:"SNEWCHG"`
Marketcappct string `json:"MARKETCAPPCT"` // 持仓比例(%)
StockTEXCH string `json:"StockTEXCH"`
Dctexch string `json:"DCTEXCH"`
}

// RspZSCFG ZSCFG接口返回结构
type RspZSCFG struct {
Datas []ZSCFGItem `json:"Datas"`
ErrCode int `json:"ErrCode"`
Success bool `json:"Success"`
ErrMsg interface{} `json:"ErrMsg"`
Message interface{} `json:"Message"`
ErrorCode string `json:"ErrorCode"`
ErrorMessage interface{} `json:"ErrorMessage"`
ErrorMsgLst interface{} `json:"ErrorMsgLst"`
TotalCount int `json:"TotalCount"`
Expansion interface{} `json:"Expansion"`
}

// ZSCFG 返回指数成分股列表
func (e EastMoney) ZSCFG(ctx context.Context, indexCode string) (results []ZSCFGItem, err error) {
apiurl := fmt.Sprintf(
"https://fundztapi.eastmoney.com/FundSpecialApiNew/FundSpecialZSB30ZSCFG?IndexCode=%s&Version=6.5.5&deviceid=-&pageIndex=1&pageSize=10000&plat=Iphone&product=EFund",
indexCode,
)
header := map[string]string{
"user-agent": uarand.GetRandom(),
}
rsp := RspZSCFG{}
if err := goutils.HTTPGET(ctx, e.HTTPClient, apiurl, header, &rsp); err != nil {
return nil, err
}
if rsp.ErrCode != 0 {
return nil, fmt.Errorf("ZSCFG rsp code error, rsp:%+v", rsp)
}
if len(rsp.Datas) != rsp.TotalCount {
return nil, fmt.Errorf("ZSCFG rsp data len:%d != TotalCount:%d", len(rsp.Datas), rsp.TotalCount)
}
return rsp.Datas, nil
}
13 changes: 13 additions & 0 deletions datacenter/eastmoney/zscfg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package eastmoney

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestZSCFG(t *testing.T) {
results, err := _em.ZSCFG(_ctx, "000905")
require.Nil(t, err)
t.Log(results)
}
24 changes: 5 additions & 19 deletions statics/html/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,12 @@ <h5 class="white-text">友情链接</h5>
</ul>
</div>
<div class="col l3 s12">
<h5 class="white-text">研报</h5>
<h5 class="white-text">东方财富数据中心</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="http://data.eastmoney.com/report/" target="_blank">东方财富研报中心</a></li>
<li><a class="grey-text text-lighten-3" href="https://www.valuelist.top" target="_blank">价值目录</a></li>
<li><a class="grey-text text-lighten-3" href="https://www.hanghangcha.com" target="_blank">行行查</a></li>
<li><a class="grey-text text-lighten-3" href="https://robo.datayes.com/v2/selection" target="_blank">萝卜投研研报精选</a></li>
</ul>
</div>
<div class="col l3 s12">
<h5 class="white-text">工具</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="http://fund.eastmoney.com/compare/" target="_blank">基金对比</a></li>
<li><a class="grey-text text-lighten-3" href="http://data.eastmoney.com/money/calc/FundCalcDTSY.html" target="_blank">基金定投收益计算器</a></li>
</ul>
</div>
<div class="col l3 s12">
<h5 class="white-text">网站</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="http://www.mof.gov.cn/index.htm" target="_blank">财政部</a></li>
<li><a class="grey-text text-lighten-3" href="http://www.stats.gov.cn/" target="_blank">统计局</a></li>
<li><a class="grey-text text-lighten-3" href="https://data.eastmoney.com/cjsj/cpi.html" target="_blank">经济数据</a></li>
<li><a class="grey-text text-lighten-3" href="https://data.eastmoney.com/other/index/" target="_blank">成分股数据</a></li>
<li><a class="grey-text text-lighten-3" href="https://data.eastmoney.com/yjfp/" target="_blank">分红送配</a></li>
<li><a class="grey-text text-lighten-3" href="https://data.eastmoney.com/report/" target="_blank">研报中心</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit d99eb8c

Please sign in to comment.