ok
This commit is contained in:
213
tushare/index.go
Normal file
213
tushare/index.go
Normal file
@@ -0,0 +1,213 @@
|
||||
package tushare
|
||||
|
||||
/*
|
||||
IndexBasic 获取大盘指数基本信息
|
||||
|
||||
ts_code: 指数代码,支持多个,逗号分隔
|
||||
exchange: 交易所代码,SSE 上交所,SZSE 深交所
|
||||
*/
|
||||
func (cli *TushareClient) IndexBasic(ts_code, exchange string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if ts_code != "" {
|
||||
params["ts_code"] = ts_code
|
||||
}
|
||||
if exchange != "" {
|
||||
params["exchange"] = exchange
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "index_basic",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"ts_code": "指数代码"},
|
||||
{"name": "指数名称"},
|
||||
{"market": "市场类别"},
|
||||
{"publisher": "发布方"},
|
||||
{"category": "指数类别"},
|
||||
{"base_date": "基日"},
|
||||
{"base_point": "基点"},
|
||||
{"list_date": "发布日期"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
|
||||
/*
|
||||
IndexWeight 获取指数成分和权重
|
||||
|
||||
index_code: 指数代码,如 000300.SH(沪深 300)
|
||||
trade_date: 交易日期,格式:YYYYMMDD
|
||||
start_date: 开始日期,格式:YYYYMMDD
|
||||
end_date: 结束日期,格式:YYYYMMDD
|
||||
*/
|
||||
func (cli *TushareClient) IndexWeight(index_code, trade_date, start_date, end_date string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if index_code != "" {
|
||||
params["index_code"] = index_code
|
||||
}
|
||||
if trade_date != "" {
|
||||
params["trade_date"] = trade_date
|
||||
}
|
||||
if start_date != "" {
|
||||
params["start_date"] = start_date
|
||||
}
|
||||
if end_date != "" {
|
||||
params["end_date"] = end_date
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "index_weight",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"index_code": "指数代码"},
|
||||
{"trade_date": "交易日期"},
|
||||
{"ts_code": "成分股票代码"},
|
||||
{"weight": "权重%"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
|
||||
/*
|
||||
IndexClassify 获取指数分类信息
|
||||
|
||||
level: 指数级别,L1/L2/L3/L4
|
||||
src: 指数来源,SW 申万,ZJW 证监会,ICS iFinD
|
||||
parent_code: 父级代码
|
||||
*/
|
||||
func (cli *TushareClient) IndexClassify(level, src, parent_code string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if level != "" {
|
||||
params["level"] = level
|
||||
}
|
||||
if src != "" {
|
||||
params["src"] = src
|
||||
}
|
||||
if parent_code != "" {
|
||||
params["parent_code"] = parent_code
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "index_classify",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"index_code": "指数代码"},
|
||||
{"industry_name": "行业名称"},
|
||||
{"industry_code": "行业代码"},
|
||||
{"parent_code": "父级代码"},
|
||||
{"level": "级别"},
|
||||
{"src": "来源"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
|
||||
/*
|
||||
IndexMember 获取指数成分股
|
||||
|
||||
index_code: 指数代码,如 000300.SH(沪深 300)
|
||||
trade_date: 交易日期,格式:YYYYMMDD
|
||||
start_date: 开始日期,格式:YYYYMMDD
|
||||
end_date: 结束日期,格式:YYYYMMDD
|
||||
*/
|
||||
func (cli *TushareClient) IndexMember(index_code, trade_date, start_date, end_date string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if index_code != "" {
|
||||
params["index_code"] = index_code
|
||||
}
|
||||
if trade_date != "" {
|
||||
params["trade_date"] = trade_date
|
||||
}
|
||||
if start_date != "" {
|
||||
params["start_date"] = start_date
|
||||
}
|
||||
if end_date != "" {
|
||||
params["end_date"] = end_date
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "index_member",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"index_code": "指数代码"},
|
||||
{"trade_date": "交易日期"},
|
||||
{"ts_code": "成分股票代码"},
|
||||
{"symbol": "成分股票代码"},
|
||||
{"name": "成分股票名称"},
|
||||
{"is_new": "是否新增"},
|
||||
{"in_date": "纳入日期"},
|
||||
{"out_date": "剔除日期"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
|
||||
/*
|
||||
Concept 获取概念板块信息
|
||||
|
||||
ts_code: 板块代码,支持多个,逗号分隔
|
||||
name: 板块名称,支持模糊匹配
|
||||
*/
|
||||
func (cli *TushareClient) Concept(ts_code, name string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if ts_code != "" {
|
||||
params["ts_code"] = ts_code
|
||||
}
|
||||
if name != "" {
|
||||
params["name"] = name
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "concept",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"ts_code": "板块代码"},
|
||||
{"name": "板块名称"},
|
||||
{"src": "来源"},
|
||||
{"pub_date": "发布日期"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
|
||||
/*
|
||||
ConceptDetail 获取概念板块详情
|
||||
|
||||
ts_code: 板块代码
|
||||
*/
|
||||
func (cli *TushareClient) ConceptDetail(ts_code string) (*TushareRespData, error) {
|
||||
params := map[string]any{}
|
||||
|
||||
if ts_code != "" {
|
||||
params["ts_code"] = ts_code
|
||||
}
|
||||
|
||||
req := TushareReq{
|
||||
APIName: "concept_detail",
|
||||
Params: params,
|
||||
}
|
||||
|
||||
fields := []map[string]string{
|
||||
{"ts_code": "板块代码"},
|
||||
{"name": "板块名称"},
|
||||
{"concept_name": "概念名称"},
|
||||
{"stock_count": "成分股票数量"},
|
||||
}
|
||||
|
||||
return cli.Do(req, fields)
|
||||
}
|
||||
Reference in New Issue
Block a user