mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
开发中...
This commit is contained in:
@@ -4,5 +4,8 @@
|
||||
|
||||
### 开发进度
|
||||
|
||||
#### 能通讯,有响应数据,还未解析响应数据
|
||||

|
||||
#### 开发进度
|
||||
* 能通讯,有响应数据,还未解析响应数据
|
||||

|
||||
* 基本信息(5档报价)
|
||||

|
||||
@@ -1,10 +1,8 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/injoyai/logs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -109,10 +107,10 @@ type SecurityQuote struct {
|
||||
InsideDish int // 内盘(东财的盘口-外盘)(和东财对不上)
|
||||
OuterDisc int // 外盘(东财的盘口-外盘)(和东财对不上)
|
||||
|
||||
ReversedBytes2 int // 保留,未知
|
||||
ReversedBytes3 int // 保留,未知
|
||||
BuyLevel [5]PriceLevel // 5档买盘(买1-5)
|
||||
SellLevel [5]PriceLevel // 5档卖盘(卖1-5)
|
||||
ReversedBytes2 int // 保留,未知
|
||||
ReversedBytes3 int // 保留,未知
|
||||
BuyLevel PriceLevels // 5档买盘(买1-5)
|
||||
SellLevel PriceLevels // 5档卖盘(卖1-5)
|
||||
|
||||
ReversedBytes4 uint16 // 保留,未知
|
||||
ReversedBytes5 int // 保留,未知
|
||||
@@ -125,10 +123,16 @@ type SecurityQuote struct {
|
||||
}
|
||||
|
||||
func (this *SecurityQuote) String() string {
|
||||
return this.K.String() + fmt.Sprintf(", 总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s",
|
||||
IntUnitString(this.TotalHand), IntUnitString(this.Intuition), FloatUnitString(this.Amount),
|
||||
IntUnitString(this.InsideDish), IntUnitString(this.OuterDisc)) + "\n" +
|
||||
fmt.Sprintf("%#v\n", this)
|
||||
return fmt.Sprintf(`%s%s
|
||||
%s
|
||||
总量:%s, 现量:%s, 总金额:%s, 内盘:%s, 外盘:%s
|
||||
%s%s
|
||||
`,
|
||||
this.Exchange.String(), this.Code, this.K,
|
||||
IntUnitString(this.TotalHand), IntUnitString(this.Intuition),
|
||||
FloatUnitString(this.Amount), IntUnitString(this.InsideDish), IntUnitString(this.OuterDisc),
|
||||
this.SellLevel.String(), this.BuyLevel.String(),
|
||||
)
|
||||
}
|
||||
|
||||
type securityQuote struct{}
|
||||
@@ -180,7 +184,7 @@ c005bed2668e05be15804d8ba12cb3b13a0083c3034100badc029d014201bc990384f70443029da5
|
||||
*/
|
||||
func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
||||
|
||||
logs.Debug(hex.EncodeToString(bs))
|
||||
//logs.Debug(hex.EncodeToString(bs))
|
||||
|
||||
resp := SecurityQuotesResp{}
|
||||
|
||||
@@ -210,7 +214,7 @@ func (this securityQuote) Decode(bs []byte) SecurityQuotesResp {
|
||||
|
||||
var p Price
|
||||
for i := 0; i < 5; i++ {
|
||||
buyLevel := PriceLevel{}
|
||||
buyLevel := PriceLevel{Buy: true}
|
||||
sellLevel := PriceLevel{}
|
||||
|
||||
bs, p = GetPrice(bs)
|
||||
@@ -13,16 +13,32 @@ func (this Price) Float64() float64 {
|
||||
}
|
||||
|
||||
func (this Price) String() string {
|
||||
return fmt.Sprintf("%0.2f 元", this.Float64())
|
||||
return fmt.Sprintf("%0.2f元", this.Float64())
|
||||
}
|
||||
|
||||
type PriceLevel struct {
|
||||
Buy bool //买卖
|
||||
Price Price //价 想买卖的价格
|
||||
Number int //量 想买卖的数量
|
||||
}
|
||||
|
||||
type PriceLevels [5]PriceLevel
|
||||
|
||||
func (this PriceLevels) String() string {
|
||||
s := ""
|
||||
if this[0].Buy {
|
||||
for i, v := range this {
|
||||
s += fmt.Sprintf("买%d %s %s\n", i+1, v.Price, IntUnitString(v.Number))
|
||||
}
|
||||
|
||||
} else {
|
||||
for i := 4; i >= 0; i-- {
|
||||
s += fmt.Sprintf("卖%d %s %s\n", i+1, this[i].Price, IntUnitString(this[i].Number))
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// K k线图
|
||||
type K struct {
|
||||
Last Price //昨天收盘价
|
||||
@@ -33,7 +49,7 @@ type K struct {
|
||||
}
|
||||
|
||||
func (this K) String() string {
|
||||
return fmt.Sprintf("昨收:%0.2f, 今开:%0.2f, 最高:%0.2f, 最低:%0.2f, 今收:%0.2f", this.Last.Float64(), this.Open.Float64(), this.High.Float64(), this.Low.Float64(), this.Close.Float64())
|
||||
return fmt.Sprintf("昨收:%s, 今开:%s, 最高:%s, 最低:%s, 今收:%s", this.Last, this.Open, this.High, this.Low, this.Close)
|
||||
}
|
||||
|
||||
// DecodeK 一般是占用6字节
|
||||
@@ -48,6 +48,9 @@ func FloatUnitString(f float64) string {
|
||||
for i := 0; f > 1e4 && i < len(m); f /= 1e4 {
|
||||
unit = m[i]
|
||||
}
|
||||
if unit == "" {
|
||||
return conv.String(f)
|
||||
}
|
||||
return fmt.Sprintf("%0.2f%s", f, unit)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user