吧代码的传参方式从sz,000001改成sz000001

This commit is contained in:
钱纯净
2024-11-05 00:30:01 +08:00
parent c90adef204
commit bf5b4e5759
4 changed files with 63 additions and 61 deletions

View File

@@ -280,8 +280,8 @@ func (this *Client) GetHistoryMinuteTradeAll(date, code string) (*protocol.Histo
} }
// GetKline 获取k线数据 // GetKline 获取k线数据
func (this *Client) GetKline(Type uint8, req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKline(Type uint8, code string, start, count uint16) (*protocol.KlineResp, error) {
f, err := protocol.MKline.Frame(Type, req) f, err := protocol.MKline.Frame(Type, code, start, count)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -293,17 +293,12 @@ func (this *Client) GetKline(Type uint8, req protocol.KlineReq) (*protocol.Kline
} }
// GetKlineAll 获取全部k线数据 // GetKlineAll 获取全部k线数据
func (this *Client) GetKlineAll(Type uint8, exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineAll(Type uint8, code string) (*protocol.KlineResp, error) {
resp := &protocol.KlineResp{} resp := &protocol.KlineResp{}
size := uint16(800) size := uint16(800)
var last *protocol.Kline var last *protocol.Kline
for i := uint16(0); ; i += size { for start := uint16(0); ; start += size {
r, err := this.GetKline(Type, protocol.KlineReq{ r, err := this.GetKline(Type, code, start, size)
Exchange: exchange,
Code: code,
Start: i,
Count: size,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -323,101 +318,101 @@ func (this *Client) GetKlineAll(Type uint8, exchange protocol.Exchange, code str
} }
// GetKlineMinute 获取一分钟k线数据 // GetKlineMinute 获取一分钟k线数据
func (this *Client) GetKlineMinute(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineMinute(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineMinute, req) return this.GetKline(protocol.TypeKlineMinute, code, start, count)
} }
// GetKlineMinuteAll 获取一分钟k线全部数据 // GetKlineMinuteAll 获取一分钟k线全部数据
func (this *Client) GetKlineMinuteAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineMinuteAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineMinute, exchange, code) return this.GetKlineAll(protocol.TypeKlineMinute, code)
} }
// GetKline5Minute 获取五分钟k线数据 // GetKline5Minute 获取五分钟k线数据
func (this *Client) GetKline5Minute(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKline5Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKline5Minute, req) return this.GetKline(protocol.TypeKline5Minute, code, start, count)
} }
// GetKline5MinuteAll 获取5分钟k线全部数据 // GetKline5MinuteAll 获取5分钟k线全部数据
func (this *Client) GetKline5MinuteAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKline5MinuteAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKline5Minute, exchange, code) return this.GetKlineAll(protocol.TypeKline5Minute, code)
} }
// GetKline15Minute 获取十五分钟k线数据 // GetKline15Minute 获取十五分钟k线数据
func (this *Client) GetKline15Minute(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKline15Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKline15Minute, req) return this.GetKline(protocol.TypeKline15Minute, code, start, count)
} }
// GetKline15MinuteAll 获取十五分钟k线全部数据 // GetKline15MinuteAll 获取十五分钟k线全部数据
func (this *Client) GetKline15MinuteAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKline15MinuteAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKline15Minute, exchange, code) return this.GetKlineAll(protocol.TypeKline15Minute, code)
} }
// GetKline30Minute 获取三十分钟k线数据 // GetKline30Minute 获取三十分钟k线数据
func (this *Client) GetKline30Minute(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKline30Minute(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKline30Minute, req) return this.GetKline(protocol.TypeKline30Minute, code, start, count)
} }
// GetKline30MinuteAll 获取三十分钟k线全部数据 // GetKline30MinuteAll 获取三十分钟k线全部数据
func (this *Client) GetKline30MinuteAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKline30MinuteAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKline30Minute, exchange, code) return this.GetKlineAll(protocol.TypeKline30Minute, code)
} }
// GetKlineHour 获取小时k线数据 // GetKlineHour 获取小时k线数据
func (this *Client) GetKlineHour(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineHour(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineHour, req) return this.GetKline(protocol.TypeKlineHour, code, start, count)
} }
// GetKlineHourAll 获取小时k线全部数据 // GetKlineHourAll 获取小时k线全部数据
func (this *Client) GetKlineHourAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineHourAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineHour, exchange, code) return this.GetKlineAll(protocol.TypeKlineHour, code)
} }
// GetKlineDay 获取日k线数据 // GetKlineDay 获取日k线数据
func (this *Client) GetKlineDay(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineDay(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineDay, req) return this.GetKline(protocol.TypeKlineDay, code, start, count)
} }
// GetKlineDayAll 获取日k线全部数据 // GetKlineDayAll 获取日k线全部数据
func (this *Client) GetKlineDayAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineDayAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineDay, exchange, code) return this.GetKlineAll(protocol.TypeKlineDay, code)
} }
// GetKlineWeek 获取周k线数据 // GetKlineWeek 获取周k线数据
func (this *Client) GetKlineWeek(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineWeek(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineWeek, req) return this.GetKline(protocol.TypeKlineWeek, code, start, count)
} }
// GetKlineWeekAll 获取周k线全部数据 // GetKlineWeekAll 获取周k线全部数据
func (this *Client) GetKlineWeekAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineWeekAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineWeek, exchange, code) return this.GetKlineAll(protocol.TypeKlineWeek, code)
} }
// GetStockKlineMonth 获取月k线数据 // GetStockKlineMonth 获取月k线数据
func (this *Client) GetStockKlineMonth(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetStockKlineMonth(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineMonth, req) return this.GetKline(protocol.TypeKlineMonth, code, start, count)
} }
// GetKlineMonthAll 获取月k线全部数据 // GetKlineMonthAll 获取月k线全部数据
func (this *Client) GetKlineMonthAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineMonthAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineMonth, exchange, code) return this.GetKlineAll(protocol.TypeKlineMonth, code)
} }
// GetKlineQuarter 获取季k线数据 // GetKlineQuarter 获取季k线数据
func (this *Client) GetKlineQuarter(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineQuarter(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineQuarter, req) return this.GetKline(protocol.TypeKlineQuarter, code, start, count)
} }
// GetKlineQuarterAll 获取季k线全部数据 // GetKlineQuarterAll 获取季k线全部数据
func (this *Client) GetKlineQuarterAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineQuarterAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineQuarter, exchange, code) return this.GetKlineAll(protocol.TypeKlineQuarter, code)
} }
// GetKlineYear 获取年k线数据 // GetKlineYear 获取年k线数据
func (this *Client) GetKlineYear(req protocol.KlineReq) (*protocol.KlineResp, error) { func (this *Client) GetKlineYear(code string, start, count uint16) (*protocol.KlineResp, error) {
return this.GetKline(protocol.TypeKlineYear, req) return this.GetKline(protocol.TypeKlineYear, code, start, count)
} }
// GetKlineYearAll 获取年k线数据 // GetKlineYearAll 获取年k线数据
func (this *Client) GetKlineYearAll(exchange protocol.Exchange, code string) (*protocol.KlineResp, error) { func (this *Client) GetKlineYearAll(code string) (*protocol.KlineResp, error) {
return this.GetKlineAll(protocol.TypeKlineYear, exchange, code) return this.GetKlineAll(protocol.TypeKlineYear, code)
} }

View File

@@ -4,12 +4,11 @@ import (
"github.com/injoyai/logs" "github.com/injoyai/logs"
"github.com/injoyai/tdx" "github.com/injoyai/tdx"
"github.com/injoyai/tdx/example/common" "github.com/injoyai/tdx/example/common"
"github.com/injoyai/tdx/protocol"
) )
func main() { func main() {
common.Test(func(c *tdx.Client) { common.Test(func(c *tdx.Client) {
resp, err := c.GetKlineDayAll(protocol.ExchangeSH, "000001") resp, err := c.GetKlineDayAll("sz000001")
logs.PanicErr(err) logs.PanicErr(err)
for _, v := range resp.List { for _, v := range resp.List {

View File

@@ -78,15 +78,28 @@ func (this *Kline) RiseRate() float64 {
type kline struct{} type kline struct{}
func (kline) Frame(Type uint8, req KlineReq) (*Frame, error) { func (kline) Frame(Type uint8, code string, start, count uint16) (*Frame, error) {
bs, err := req.Bytes(Type) if count > 800 {
return nil, errors.New("单次数量不能超过800")
}
exchange, number, err := DecodeCode(code)
if err != nil { if err != nil {
return nil, err return nil, err
} }
data := []byte{exchange.Uint8(), 0x0}
data = append(data, []byte(number)...) //这里怎么是正序了?
data = append(data, Type, 0x0)
data = append(data, 0x01, 0x0)
data = append(data, Bytes(start)...)
data = append(data, Bytes(count)...)
data = append(data, make([]byte, 10)...) //未知啥含义
return &Frame{ return &Frame{
Control: Control01, Control: Control01,
Type: TypeKline, Type: TypeKline,
Data: bs, Data: data,
}, nil }, nil
} }

View File

@@ -8,12 +8,7 @@ import (
func Test_stockKline_Frame(t *testing.T) { func Test_stockKline_Frame(t *testing.T) {
//预期0c02000000001c001c002d050000303030303031 0900 0100 0000 0a00 00000000000000000000 //预期0c02000000001c001c002d050000303030303031 0900 0100 0000 0a00 00000000000000000000
// 0c00000000011c001c002d050000313030303030 0900 0000 0000 0a00 00000000000000000000 // 0c00000000011c001c002d050000313030303030 0900 0000 0000 0a00 00000000000000000000
f, _ := MKline.Frame(TypeKlineDay, KlineReq{ f, _ := MKline.Frame(TypeKlineDay, "sz000001", 0, 10)
Exchange: ExchangeSH,
Code: "000001",
Start: 0,
Count: 10,
})
t.Log(f.Bytes().HEX()) t.Log(f.Bytes().HEX())
} }