默认按股票处理,不用配置DefaultCodes,基金才需要

This commit is contained in:
injoyai
2025-04-16 10:44:06 +08:00
parent 78e2ead79c
commit b00f1b65d5
4 changed files with 40 additions and 27 deletions

View File

@@ -235,12 +235,18 @@ func (this *Client) GetCodeAll(exchange protocol.Exchange) (*protocol.CodeResp,
// GetQuote 获取盘口五档报价
func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
if DefaultCodes == nil {
return nil, errors.New("DefaultCodes未初始化")
}
for i := range codes {
codes[i] = DefaultCodes.AddExchange(codes[i])
//如果是股票代码,则加上前缀
codes[i] = protocol.AddPrefix(codes[i])
if !protocol.IsStock(codes[i]) {
if DefaultCodes == nil {
return nil, errors.New("DefaultCodes未初始化")
}
//不是股票代码的话根据codes的信息加上前缀
codes[i] = DefaultCodes.AddExchange(codes[i])
}
}
f, err := protocol.MQuote.Frame(codes...)
if err != nil {
return nil, err
@@ -256,26 +262,25 @@ func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error) {
if len(quotes) != len(codes) {
return nil, fmt.Errorf("预期%d个实际%d个", len(codes), len(quotes))
}
if DefaultCodes == nil {
return nil, errors.New("DefaultCodes未初始化")
}
for i, code := range codes {
m := DefaultCodes.Get(code)
if m == nil {
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
}
for ii, v := range quotes[i].SellLevel {
quotes[i].SellLevel[ii].Price = m.Price(v.Price)
}
for ii, v := range quotes[i].BuyLevel {
quotes[i].BuyLevel[ii].Price = m.Price(v.Price)
}
quotes[i].K = protocol.K{
Last: m.Price(quotes[i].K.Last),
Open: m.Price(quotes[i].K.Open),
High: m.Price(quotes[i].K.High),
Low: m.Price(quotes[i].K.Low),
Close: m.Price(quotes[i].K.Close),
if !protocol.IsStock(code) {
m := DefaultCodes.Get(code)
if m == nil {
return nil, fmt.Errorf("未查询到代码[%s]相关信息", code)
}
for ii, v := range quotes[i].SellLevel {
quotes[i].SellLevel[ii].Price = m.Price(v.Price)
}
for ii, v := range quotes[i].BuyLevel {
quotes[i].BuyLevel[ii].Price = m.Price(v.Price)
}
quotes[i].K = protocol.K{
Last: m.Price(quotes[i].K.Last),
Open: m.Price(quotes[i].K.Open),
High: m.Price(quotes[i].K.High),
Low: m.Price(quotes[i].K.Low),
Close: m.Price(quotes[i].K.Close),
}
}
}
}

View File

@@ -314,7 +314,8 @@ func (this *CodeModel) FullCode() string {
}
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 {

View File

@@ -47,7 +47,7 @@ type Quote struct {
func (this *Quote) String() string {
return fmt.Sprintf(`%s%s
%s
%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
%s%s
`,
this.Exchange.String(), this.Code, this.K,
@@ -142,9 +142,9 @@ func (this quote) Decode(bs []byte) QuotesResp {
sellLevel := PriceLevel{}
bs, p = GetPrice(bs)
buyLevel.Price = p + sec.K.Close
buyLevel.Price = p*10 + sec.K.Close
bs, p = GetPrice(bs)
sellLevel.Price = p + sec.K.Close
sellLevel.Price = p*10 + sec.K.Close
bs, buyLevel.Number = CutInt(bs)
bs, sellLevel.Number = CutInt(bs)

View File

@@ -78,6 +78,13 @@ func DecodeK(bs []byte) ([]byte, K) {
bs, k.Low = GetPrice(bs)
k.Low += k.Close
//默认按股票展示
k.Last *= 10
k.Open *= 10
k.Close *= 10
k.High *= 10
k.Low *= 10
return bs, k
}