增加北京交易所数据

This commit is contained in:
钱纯净
2025-09-21 15:28:32 +08:00
parent 0a1a6194af
commit 3f3438fca8
3 changed files with 38 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ import (
func main() { func main() {
common.Test(func(c *tdx.Client) { common.Test(func(c *tdx.Client) {
resp, err := c.GetKlineDay("000001", 0, 10) resp, err := c.GetKlineDay("838971", 0, 20)
logs.PanicErr(err) logs.PanicErr(err)
for _, v := range resp.List { for _, v := range resp.List {

View File

@@ -20,8 +20,8 @@ func (this Exchange) String() string {
return "sz" return "sz"
case ExchangeSH: case ExchangeSH:
return "sh" return "sh"
//case ExchangeBJ: case ExchangeBJ:
//return "bj" return "bj"
default: default:
return "unknown" return "unknown"
} }
@@ -33,8 +33,8 @@ func (this Exchange) Name() string {
return "上海" return "上海"
case ExchangeSZ: case ExchangeSZ:
return "深圳" return "深圳"
//case ExchangeBJ: case ExchangeBJ:
//return "北京" return "北京"
default: default:
return "未知" return "未知"
} }
@@ -43,7 +43,7 @@ func (this Exchange) Name() string {
const ( const (
ExchangeSZ Exchange = iota //深圳交易所 ExchangeSZ Exchange = iota //深圳交易所
ExchangeSH //上海交易所 ExchangeSH //上海交易所
//ExchangeBJ //北京交易所 ExchangeBJ //北京交易所
) )
const ( const (

View File

@@ -58,6 +58,8 @@ func DecodeCode(code string) (Exchange, string, error) {
return ExchangeSH, code[2:], nil return ExchangeSH, code[2:], nil
case ExchangeSZ.String(): case ExchangeSZ.String():
return ExchangeSZ, code[2:], nil return ExchangeSZ, code[2:], nil
case ExchangeBJ.String():
return ExchangeBJ, code[2:], nil
default: default:
return 0, "", fmt.Errorf("股票代码错误,例如:SZ000001") return 0, "", fmt.Errorf("股票代码错误,例如:SZ000001")
} }
@@ -237,20 +239,34 @@ func getVolume2(val uint32) float64 {
// IsStock 是否是股票,示例sz000001 // IsStock 是否是股票,示例sz000001
func IsStock(code string) bool { func IsStock(code string) bool {
if len(code) != 8 { return IsSZStock(code) || IsSHStock(code) || IsBJStock(code)
return false
}
code = strings.ToLower(code)
switch {
case code[0:2] == ExchangeSH.String() &&
(code[2:3] == "6"):
return true
case code[0:2] == ExchangeSZ.String() && //if len(code) != 8 {
(code[2:3] == "0" || code[2:4] == "30"): // return false
return true //}
} //code = strings.ToLower(code)
return false //switch {
//case code[0:2] == ExchangeSH.String() &&
// (code[2:3] == "6"):
// return true
//
//case code[0:2] == ExchangeSZ.String() &&
// (code[2:3] == "0" || code[2:4] == "30"):
// return true
//}
//return false
}
func IsSZStock(code string) bool {
return len(code) == 8 && strings.ToLower(code[0:2]) == ExchangeSZ.String() && code[2:3] == "0"
}
func IsSHStock(code string) bool {
return len(code) == 8 && strings.ToLower(code[0:2]) == ExchangeSH.String() && code[2:3] == "6"
}
func IsBJStock(code string) bool {
return len(code) == 8 && strings.ToLower(code[0:2]) == ExchangeBJ.String() && (code[2:4] == "92" || code[2:3] == "8")
} }
// IsETF 是否是基金,示例sz159558 // IsETF 是否是基金,示例sz159558
@@ -290,6 +306,9 @@ func AddPrefix(code string) string {
case code[:3] == "159": case code[:3] == "159":
//深圳基金 //深圳基金
code = ExchangeSZ.String() + code code = ExchangeSZ.String() + code
case code[:1] == "8" || code[:2] == "92":
//北京股票
code = ExchangeBJ.String() + code
} }
} }
return code return code