diff --git a/example/GetKlineDay/main.go b/example/GetKlineDay/main.go index 0d101dd..fd82f86 100644 --- a/example/GetKlineDay/main.go +++ b/example/GetKlineDay/main.go @@ -8,7 +8,7 @@ import ( func main() { common.Test(func(c *tdx.Client) { - resp, err := c.GetKlineDay("000001", 0, 10) + resp, err := c.GetKlineDay("838971", 0, 20) logs.PanicErr(err) for _, v := range resp.List { diff --git a/protocol/types.go b/protocol/types.go index 294954a..cf08f12 100644 --- a/protocol/types.go +++ b/protocol/types.go @@ -20,8 +20,8 @@ func (this Exchange) String() string { return "sz" case ExchangeSH: return "sh" - //case ExchangeBJ: - //return "bj" + case ExchangeBJ: + return "bj" default: return "unknown" } @@ -33,8 +33,8 @@ func (this Exchange) Name() string { return "上海" case ExchangeSZ: return "深圳" - //case ExchangeBJ: - //return "北京" + case ExchangeBJ: + return "北京" default: return "未知" } @@ -43,7 +43,7 @@ func (this Exchange) Name() string { const ( ExchangeSZ Exchange = iota //深圳交易所 ExchangeSH //上海交易所 - //ExchangeBJ //北京交易所 + ExchangeBJ //北京交易所 ) const ( diff --git a/protocol/unit.go b/protocol/unit.go index 797f475..957d6c8 100644 --- a/protocol/unit.go +++ b/protocol/unit.go @@ -58,6 +58,8 @@ func DecodeCode(code string) (Exchange, string, error) { return ExchangeSH, code[2:], nil case ExchangeSZ.String(): return ExchangeSZ, code[2:], nil + case ExchangeBJ.String(): + return ExchangeBJ, code[2:], nil default: return 0, "", fmt.Errorf("股票代码错误,例如:SZ000001") } @@ -237,20 +239,34 @@ func getVolume2(val uint32) float64 { // IsStock 是否是股票,示例sz000001 func IsStock(code string) bool { - if len(code) != 8 { - return false - } - code = strings.ToLower(code) - switch { - case code[0:2] == ExchangeSH.String() && - (code[2:3] == "6"): - return true + return IsSZStock(code) || IsSHStock(code) || IsBJStock(code) - case code[0:2] == ExchangeSZ.String() && - (code[2:3] == "0" || code[2:4] == "30"): - return true - } - return false + //if len(code) != 8 { + // 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() && + // (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 @@ -290,6 +306,9 @@ func AddPrefix(code string) string { case code[:3] == "159": //深圳基金 code = ExchangeSZ.String() + code + case code[:1] == "8" || code[:2] == "92": + //北京股票 + code = ExchangeBJ.String() + code } } return code