mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
默认按股票处理,不用配置DefaultCodes,基金才需要
This commit is contained in:
13
client.go
13
client.go
@@ -235,12 +235,18 @@ func (this *Client) GetCodeAll(exchange protocol.Exchange) (*protocol.CodeResp,
|
|||||||
|
|
||||||
// GetQuote 获取盘口五档报价
|
// GetQuote 获取盘口五档报价
|
||||||
func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
||||||
|
for i := range codes {
|
||||||
|
//如果是股票代码,则加上前缀
|
||||||
|
codes[i] = protocol.AddPrefix(codes[i])
|
||||||
|
if !protocol.IsStock(codes[i]) {
|
||||||
if DefaultCodes == nil {
|
if DefaultCodes == nil {
|
||||||
return nil, errors.New("DefaultCodes未初始化")
|
return nil, errors.New("DefaultCodes未初始化")
|
||||||
}
|
}
|
||||||
for i := range codes {
|
//不是股票代码的话,根据codes的信息加上前缀
|
||||||
codes[i] = DefaultCodes.AddExchange(codes[i])
|
codes[i] = DefaultCodes.AddExchange(codes[i])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
f, err := protocol.MQuote.Frame(codes...)
|
f, err := protocol.MQuote.Frame(codes...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -256,10 +262,8 @@ func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
|||||||
if len(quotes) != len(codes) {
|
if len(quotes) != len(codes) {
|
||||||
return nil, fmt.Errorf("预期%d个,实际%d个", len(codes), len(quotes))
|
return nil, fmt.Errorf("预期%d个,实际%d个", len(codes), len(quotes))
|
||||||
}
|
}
|
||||||
if DefaultCodes == nil {
|
|
||||||
return nil, errors.New("DefaultCodes未初始化")
|
|
||||||
}
|
|
||||||
for i, code := range codes {
|
for i, code := range codes {
|
||||||
|
if !protocol.IsStock(code) {
|
||||||
m := DefaultCodes.Get(code)
|
m := DefaultCodes.Get(code)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
|
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
|
||||||
@@ -279,6 +283,7 @@ func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return quotes, nil
|
return quotes, nil
|
||||||
}
|
}
|
||||||
|
|||||||
3
codes.go
3
codes.go
@@ -314,7 +314,8 @@ func (this *CodeModel) FullCode() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *CodeModel) Price(p protocol.Price) protocol.Price {
|
func (this *CodeModel) Price(p protocol.Price) protocol.Price {
|
||||||
return p * protocol.Price(math.Pow10(int(3-this.Decimal)))
|
return protocol.Price(float64(p) * math.Pow10(int(2-this.Decimal)))
|
||||||
|
return p * protocol.Price(math.Pow10(int(2-this.Decimal)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error {
|
func NewSessionFunc(db *xorm.Engine, fn func(session *xorm.Session) error) error {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ type Quote struct {
|
|||||||
func (this *Quote) String() string {
|
func (this *Quote) String() string {
|
||||||
return fmt.Sprintf(`%s%s
|
return fmt.Sprintf(`%s%s
|
||||||
%s
|
%s
|
||||||
总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
|
总手:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
|
||||||
%s%s
|
%s%s
|
||||||
`,
|
`,
|
||||||
this.Exchange.String(), this.Code, this.K,
|
this.Exchange.String(), this.Code, this.K,
|
||||||
@@ -142,9 +142,9 @@ func (this quote) Decode(bs []byte) QuotesResp {
|
|||||||
sellLevel := PriceLevel{}
|
sellLevel := PriceLevel{}
|
||||||
|
|
||||||
bs, p = GetPrice(bs)
|
bs, p = GetPrice(bs)
|
||||||
buyLevel.Price = p + sec.K.Close
|
buyLevel.Price = p*10 + sec.K.Close
|
||||||
bs, p = GetPrice(bs)
|
bs, p = GetPrice(bs)
|
||||||
sellLevel.Price = p + sec.K.Close
|
sellLevel.Price = p*10 + sec.K.Close
|
||||||
|
|
||||||
bs, buyLevel.Number = CutInt(bs)
|
bs, buyLevel.Number = CutInt(bs)
|
||||||
bs, sellLevel.Number = CutInt(bs)
|
bs, sellLevel.Number = CutInt(bs)
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ func DecodeK(bs []byte) ([]byte, K) {
|
|||||||
bs, k.Low = GetPrice(bs)
|
bs, k.Low = GetPrice(bs)
|
||||||
k.Low += k.Close
|
k.Low += k.Close
|
||||||
|
|
||||||
|
//默认按股票展示
|
||||||
|
k.Last *= 10
|
||||||
|
k.Open *= 10
|
||||||
|
k.Close *= 10
|
||||||
|
k.High *= 10
|
||||||
|
k.Low *= 10
|
||||||
|
|
||||||
return bs, k
|
return bs, k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user