gitee.com/quant1x/engine@v1.8.4/datasource/dfcf/capital.go (about) 1 package dfcf 2 3 import ( 4 "encoding/json" 5 "gitee.com/quant1x/exchange" 6 "gitee.com/quant1x/gox/api" 7 "gitee.com/quant1x/gox/http" 8 urlpkg "net/url" 9 "strings" 10 "time" 11 ) 12 13 type rawCapital struct { 14 Xsjj []struct { 15 SECUCODE string `json:"SECUCODE"` 16 SECURITYCODE string `json:"SECURITY_CODE"` 17 LIFTDATE string `json:"LIFT_DATE"` 18 LIFTNUM int `json:"LIFT_NUM"` 19 LIFTTYPE string `json:"LIFT_TYPE"` 20 TOTALSHARESRATIO float64 `json:"TOTAL_SHARES_RATIO"` 21 UNLIMITEDASHARESRATIO float64 `json:"UNLIMITED_A_SHARES_RATIO"` 22 } `json:"xsjj"` // 限售解禁 23 Gbjg []struct { 24 SECUCODE string `json:"SECUCODE"` 25 SECURITYCODE string `json:"SECURITY_CODE"` 26 NONFREESHARES int `json:"NON_FREE_SHARES"` 27 LIMITEDSHARES int `json:"LIMITED_SHARES"` 28 UNLIMITEDSHARES int `json:"UNLIMITED_SHARES"` 29 TOTALSHARES int `json:"TOTAL_SHARES"` 30 LISTEDASHARES int `json:"LISTED_A_SHARES"` 31 BFREESHARE int `json:"B_FREE_SHARE"` 32 HFREESHARE int `json:"H_FREE_SHARE"` 33 OTHERFREESHARES int `json:"OTHER_FREE_SHARES"` 34 NONFREESHARESRATIO int `json:"NON_FREESHARES_RATIO"` 35 LIMITEDSHARESRATIO float64 `json:"LIMITED_SHARES_RATIO"` 36 LISTEDSHARESRATIO float64 `json:"LISTED_SHARES_RATIO"` 37 TOTALSHARESRATIO string `json:"TOTAL_SHARES_RATIO"` 38 LISTEDARATIOPC float64 `json:"LISTED_A_RATIOPC"` 39 LISTEDBRATIOPC float64 `json:"LISTED_B_RATIOPC"` 40 LISTEDHRATIOPC float64 `json:"LISTED_H_RATIOPC"` 41 LISTEDOTHERRATIOPC float64 `json:"LISTED_OTHER_RATIOPC"` 42 LISTEDSUMRATIOPC int `json:"LISTED_SUM_RATIOPC"` 43 } `json:"gbjg"` // 股本结构 44 Lngbbd []struct { 45 SECUCODE string `json:"SECUCODE"` 46 SECURITYCODE string `json:"SECURITY_CODE"` 47 ENDDATE string `json:"END_DATE"` 48 TOTALSHARES int `json:"TOTAL_SHARES"` 49 LIMITEDSHARES int `json:"LIMITED_SHARES"` 50 LIMITEDOTHARS int `json:"LIMITED_OTHARS"` 51 LIMITEDDOMESTICNATURAL int `json:"LIMITED_DOMESTIC_NATURAL"` 52 LIMITEDSTATELEGAL int `json:"LIMITED_STATE_LEGAL"` 53 LIMITEDOVERSEASNOSTATE interface{} `json:"LIMITED_OVERSEAS_NOSTATE"` 54 LIMITEDOVERSEASNATURAL interface{} `json:"LIMITED_OVERSEAS_NATURAL"` 55 UNLIMITEDSHARES int `json:"UNLIMITED_SHARES"` 56 LISTEDASHARES int `json:"LISTED_A_SHARES"` 57 BFREESHARE interface{} `json:"B_FREE_SHARE"` 58 HFREESHARE interface{} `json:"H_FREE_SHARE"` 59 FREESHARES int `json:"FREE_SHARES"` 60 LIMITEDASHARES int `json:"LIMITED_A_SHARES"` 61 NONFREESHARES interface{} `json:"NON_FREE_SHARES"` 62 LIMITEDBSHARES interface{} `json:"LIMITED_B_SHARES"` 63 OTHERFREESHARES interface{} `json:"OTHER_FREE_SHARES"` 64 LIMITEDSTATESHARES interface{} `json:"LIMITED_STATE_SHARES"` 65 LIMITEDDOMESTICNOSTATE int `json:"LIMITED_DOMESTIC_NOSTATE"` 66 LOCKSHARES int `json:"LOCK_SHARES"` 67 LIMITEDFOREIGNSHARES interface{} `json:"LIMITED_FOREIGN_SHARES"` 68 LIMITEDHSHARES interface{} `json:"LIMITED_H_SHARES"` 69 SPONSORSHARES interface{} `json:"SPONSOR_SHARES"` 70 STATESPONSORSHARES interface{} `json:"STATE_SPONSOR_SHARES"` 71 SPONSORSOCIALSHARES interface{} `json:"SPONSOR_SOCIAL_SHARES"` 72 RAISESHARES interface{} `json:"RAISE_SHARES"` 73 RAISESTATESHARES interface{} `json:"RAISE_STATE_SHARES"` 74 RAISEDOMESTICSHARES interface{} `json:"RAISE_DOMESTIC_SHARES"` 75 RAISEOVERSEASSHARES interface{} `json:"RAISE_OVERSEAS_SHARES"` 76 CHANGEREASON string `json:"CHANGE_REASON"` 77 } `json:"lngbbd"` // 历年股本变动 78 Gbgc []struct { 79 SECUCODE string `json:"SECUCODE"` 80 SECURITYCODE string `json:"SECURITY_CODE"` 81 ENDDATE string `json:"END_DATE"` 82 TOTALSHARES int `json:"TOTAL_SHARES"` 83 LISTEDASHARES int `json:"LISTED_A_SHARES"` 84 LIMITEDSHARES int `json:"LIMITED_SHARES"` 85 } `json:"gbgc"` // 股本构成 86 } 87 88 const ( 89 urlCapitalStockStructure = "https://emweb.securities.eastmoney.com/PC_HSF10/CapitalStockStructure/PageAjax" 90 ) 91 92 type StockCapital struct { 93 Code string // 证券代码 94 Date string // 变动日期 95 TotalShares int // 总股本 96 UnlimitedShares int // 已流通股本 97 ListedAShares int // 已上市流通A股 98 ChangeReson string // 变动原因 99 UpdateTime string // 更新时间 100 } 101 102 // CapitalChange 获取股本变动记录 103 // 104 // deprecated: 不推荐, 太慢 105 func CapitalChange(securityCode string) (list []StockCapital) { 106 code := exchange.CorrectSecurityCode(securityCode) 107 params := urlpkg.Values{ 108 "code": {strings.ToUpper(code)}, 109 } 110 111 url := urlCapitalStockStructure + "?" + params.Encode() 112 data, lastModified, err := http.Request(url, http.MethodGet, "") 113 //fmt.Println(api.Bytes2String(data)) 114 if err != nil { 115 return 116 } 117 var css rawCapital 118 err = json.Unmarshal(data, &css) 119 if err != nil { 120 return 121 } 122 if lastModified.UnixMilli() > 0 { 123 lastModified = time.Now() 124 } 125 updateTime := lastModified.Format(time.DateTime) 126 for _, v := range css.Lngbbd { 127 sc := StockCapital{ 128 Code: securityCode, 129 Date: exchange.FixTradeDate(v.ENDDATE), 130 TotalShares: v.TOTALSHARES, 131 UnlimitedShares: v.UNLIMITEDSHARES, 132 ListedAShares: v.LISTEDASHARES, 133 ChangeReson: v.CHANGEREASON, 134 UpdateTime: updateTime, 135 } 136 list = append(list, sc) 137 } 138 api.SliceSort(list, func(a, b StockCapital) bool { 139 return a.Date > b.Date 140 }) 141 return 142 }