gitee.com/quant1x/engine@v1.8.4/market/shse/sse_stock.go (about)

     1  package shse
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"gitee.com/quant1x/engine/utils"
     7  	"gitee.com/quant1x/gox/api"
     8  	"gitee.com/quant1x/gox/http"
     9  	"gitee.com/quant1x/num"
    10  	urlpkg "net/url"
    11  )
    12  
    13  const (
    14  	// 数据来源: http://www.sse.com.cn/market/price/report/
    15  	kUrlMarketSseCodeList = "http://yunhq.sse.com.cn:32041/v1/sh1/list/exchange/equity"
    16  )
    17  
    18  type rawShangHaiSecurities struct {
    19  	Date  int     `json:"date"`
    20  	Time  int     `json:"time"`
    21  	Total int     `json:"total"`
    22  	Begin int     `json:"begin"`
    23  	End   int     `json:"end"`
    24  	List  [][]any `json:"list"`
    25  }
    26  
    27  type sseSecurityEntity struct {
    28  	Code         string  `array:"0"`
    29  	Name         string  `array:"1"`
    30  	Open         float64 `array:"2"`
    31  	High         float64 `array:"3"`
    32  	Low          float64 `array:"4"`
    33  	Last         float64 `array:"5"`
    34  	PrevClose    float64 `array:"6"`
    35  	ChangeRate   float64 `array:"7"`
    36  	Volume       int64   `array:"8"`
    37  	Amount       float64 `array:"9"`
    38  	TradePhase   string  `array:"10"`
    39  	Change       float64 `array:"11"`
    40  	AmpRate      float64 `array:"12"`
    41  	CpxxSubType  string  `array:"13"`
    42  	CpxxProdusta string  `array:"14"`
    43  }
    44  
    45  // GetSecurityList 获取证券代码列表
    46  func GetSecurityList() (list []sseSecurityEntity, err error) {
    47  	timestamp := utils.Timestamp()
    48  	params := urlpkg.Values{
    49  		"_":            {fmt.Sprintf("%d", timestamp)},
    50  		"isPagination": {"false"},
    51  		"begin":        {"0"},
    52  		"end":          {"5000"},
    53  		"select":       {"code,name,open,high,low,last,prev_close,chg_rate,volume,amount,tradephase,change,amp_rate,cpxxsubtype,cpxxprodusta"},
    54  		//"select": {"code,name"},
    55  	}
    56  	header := map[string]any{
    57  		"Referer": "http://www.sse.com.cn/",
    58  		//"Cookie":  "ba17301551dcbaf9_gdp_user_key=; gdp_user_id=gioenc-1aadbe52,d720,54c2,9271,29b7b6dda362; ba17301551dcbaf9_gdp_session_id_2960a971-ddff-48be-827f-6eb99e891735=true; ba17301551dcbaf9_gdp_session_id_4602911b-d360-4f09-a438-3d40bca228d7=true; ba17301551dcbaf9_gdp_session_id_86910507-dd22-4b31-9749-e3a3b18eae25=true; ba17301551dcbaf9_gdp_session_id_1bb67914-f729-4e41-b75c-d09a6b0d7873=true; JSESSIONID=7052255EE4B2357019E75B7B09D6D571; ba17301551dcbaf9_gdp_session_id=2a1f157c-1605-45e8-a68b-e4196d04b2af; ba17301551dcbaf9_gdp_session_id_2a1f157c-1605-45e8-a68b-e4196d04b2af=true; ba17301551dcbaf9_gdp_sequence_ids={\"globalKey\":42,\"VISIT\":6,\"PAGE\":14,\"VIEW_CHANGE\":2,\"CUSTOM\":3,\"VIEW_CLICK\":21}",
    59  	}
    60  	url := kUrlMarketSseCodeList + "?" + params.Encode()
    61  	//data, _, err := http.Request(url, "get", header)
    62  	data, err := http.Get(url, header)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	//fmt.Println(string(data), tm, err)
    67  	//fmt.Println(string(data))
    68  	var raw rawShangHaiSecurities
    69  	err = json.Unmarshal(data, &raw)
    70  	if err != nil {
    71  		return
    72  	}
    73  	for _, vs := range raw.List {
    74  		arr := []string{}
    75  		for _, v := range vs {
    76  			arr = append(arr, num.AnyToString(v))
    77  		}
    78  		var info sseSecurityEntity
    79  		_ = api.Convert(arr, &info)
    80  		list = append(list, info)
    81  	}
    82  	return
    83  }