mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
增加北京交易所数据
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user