准备解析k线图

This commit is contained in:
injoyai
2024-10-29 16:43:41 +08:00
parent f9c7047f78
commit cbb2aabb7e
6 changed files with 89 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ const (
TypeStockMinute = 0x051D //分时数据
TypeStockMinuteTrade = 0x0FC5 //分时交易
TypeStockHistoryMinuteTrade = 0x0FB5 //历史分时交易
TypeStockKline = 0x052D //K线图
)
/*

View File

@@ -13,6 +13,7 @@ var (
MStockMinute = stockMinute{}
MStockMinuteTrade = stockMinuteTrade{}
MStockHistoryMinuteTrade = stockHistoryMinuteTrade{}
MStockKline = stockKline{}
)
type ConnectResp struct {

View File

@@ -50,7 +50,7 @@ func (stockHistoryMinuteTrade) Decode(bs []byte, code string) (*StockHistoryMinu
lastPrice := Price(0)
for i := uint16(0); i < resp.Count; i++ {
mt := &StockMinuteTrade{
Time: GetTime([2]byte(bs[:2])),
Time: GetDate([2]byte(bs[:2])),
}
var sub Price
bs, sub = GetPrice(bs[2:])

View File

@@ -0,0 +1,80 @@
package protocol
import (
"errors"
"github.com/injoyai/base/g"
"time"
)
type StockKlineReq struct {
Exchange Exchange
Code string
Type uint16 //类型 1分 5分 等等
Start uint16
Count uint16
}
func (this *StockKlineReq) Bytes() (g.Bytes, error) {
if len(this.Code) != 6 {
return nil, errors.New("股票代码长度错误")
}
data := []byte{this.Exchange.Uint8(), 0x0}
data = append(data, Bytes(this.Code)...)
data = append(data, Bytes(this.Type)...)
data = append(data, 0x0, 0x0)
data = append(data, Bytes(this.Start)...)
data = append(data, Bytes(this.Count)...)
data = append(data, make([]byte, 10)...) //未知啥含义
return data, nil
}
type StockKlineResp struct {
Count uint16
List []*StockKline
}
type StockKline struct {
Open Price
High Price
Low Price
Close Price
Volume int //成交量
Number int //成交数
Time time.Time
Year int
Month int
Day int
Hour int
Minute int
}
type stockKline struct{}
func (stockKline) Frame(req *StockKlineReq) (*Frame, error) {
bs, err := req.Bytes()
if err != nil {
return nil, err
}
return &Frame{
Control: Control01,
Type: TypeStockKline,
Data: bs,
}, nil
}
func (stockKline) Decode(bs []byte) (*StockKlineResp, error) {
if len(bs) < 2 {
return nil, errors.New("数据长度不足")
}
resp := &StockKlineResp{
Count: Uint16(bs[:2]),
}
for i := uint16(0); i < resp.Count; i++ {
}
return nil, nil
}

View File

@@ -84,7 +84,7 @@ func (stockMinuteTrade) Decode(bs []byte, code string) (*StockMinuteTradeResp, e
lastPrice := Price(0)
for i := uint16(0); i < resp.Count; i++ {
mt := &StockMinuteTrade{
Time: GetTime([2]byte(bs[:2])),
Time: GetDate([2]byte(bs[:2])),
}
var sub Price
bs, sub = GetPrice(bs[2:])

View File

@@ -71,13 +71,17 @@ func IntUnitString(n int) string {
return FloatUnitString(float64(n))
}
func GetTime(bs [2]byte) string {
func GetDate(bs [2]byte) string {
n := Uint16(bs[:])
h := n / 60
m := n % 60
return fmt.Sprintf("%02d:%02d", h, m)
}
func GetTime(bs [4]byte) string {
return ""
}
func basePrice(code string) Price {
if len(code) == 0 {
return 1