protocol.HistoryTradeResp替换成protocol.TradeResp

This commit is contained in:
injoyai
2025-07-02 15:53:38 +08:00
parent 1783643f47
commit accda98f3b
3 changed files with 11 additions and 14 deletions

View File

@@ -360,14 +360,14 @@ func (this *Client) GetMinuteTradeAll(code string) (*protocol.TradeResp, error)
return resp, nil
}
func (this *Client) GetHistoryTrade(date, code string, start, count uint16) (*protocol.HistoryTradeResp, error) {
func (this *Client) GetHistoryTrade(date, code string, start, count uint16) (*protocol.TradeResp, error) {
return this.GetHistoryMinuteTrade(date, code, start, count)
}
// GetHistoryMinuteTrade 获取历史分时交易
// 只能获取昨天及之前的数据,服务器最多返回2000条,count-start<=2000,如果日期输入错误,则返回0
// 历史数据sz000001在20241116只能查到21111112,13年差几天,3141天,或者其他规则
func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16) (*protocol.HistoryTradeResp, error) {
func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16) (*protocol.TradeResp, error) {
code = protocol.AddPrefix(code)
f, err := protocol.MHistoryTrade.Frame(date, code, start, count)
if err != nil {
@@ -380,17 +380,17 @@ func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16
if err != nil {
return nil, err
}
return result.(*protocol.HistoryTradeResp), nil
return result.(*protocol.TradeResp), nil
}
func (this *Client) GetHistoryTradeAll(date, code string) (*protocol.HistoryTradeResp, error) {
func (this *Client) GetHistoryTradeAll(date, code string) (*protocol.TradeResp, error) {
return this.GetHistoryMinuteTradeAll(date, code)
}
// GetHistoryMinuteTradeAll 获取历史分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据
// 历史数据sz000001在20241116只能查到21111112,13年差几天,3141天,或者其他规则
func (this *Client) GetHistoryMinuteTradeAll(date, code string) (*protocol.HistoryTradeResp, error) {
resp := &protocol.HistoryTradeResp{}
func (this *Client) GetHistoryMinuteTradeAll(date, code string) (*protocol.TradeResp, error) {
resp := &protocol.TradeResp{}
size := uint16(2000)
for start := uint16(0); ; start += size {
r, err := this.GetHistoryMinuteTrade(date, code, start, size)

View File

@@ -54,7 +54,7 @@ func (this *PullTrade) PullYear(ctx context.Context, m *tdx.Manage, year int, co
date := t.Format("20060102")
var resp *protocol.HistoryTradeResp
var resp *protocol.TradeResp
err = m.Do(func(c *tdx.Client) error {
resp, err = c.GetHistoryTradeAll(date, code)
return err

View File

@@ -6,11 +6,8 @@ import (
"time"
)
// HistoryTradeResp 历史分时交易比实时少了单量
type HistoryTradeResp struct {
Count uint16
List Trades
}
// HistoryTradeResp 兼容之前的版本
type HistoryTradeResp = TradeResp
type historyTrade struct{}
@@ -31,7 +28,7 @@ func (historyTrade) Frame(date, code string, start, count uint16) (*Frame, error
}, nil
}
func (historyTrade) Decode(bs []byte, c TradeCache) (*HistoryTradeResp, error) {
func (historyTrade) Decode(bs []byte, c TradeCache) (*TradeResp, error) {
if len(bs) < 2 {
return nil, errors.New("数据长度不足")
}
@@ -41,7 +38,7 @@ func (historyTrade) Decode(bs []byte, c TradeCache) (*HistoryTradeResp, error) {
return nil, err
}
resp := &HistoryTradeResp{
resp := &TradeResp{
Count: Uint16(bs[:2]),
}