From accda98f3b935b2ebdaaea6999186c91392114dc Mon Sep 17 00:00:00 2001 From: injoyai <1113655791@qq.com> Date: Wed, 2 Jul 2025 15:53:38 +0800 Subject: [PATCH] =?UTF-8?q?protocol.HistoryTradeResp=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E6=88=90protocol.TradeResp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 12 ++++++------ extend/pull-trade.go | 2 +- protocol/model_history_trade.go | 11 ++++------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/client.go b/client.go index 1fca3dd..249dae3 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/extend/pull-trade.go b/extend/pull-trade.go index 643425e..bf92087 100644 --- a/extend/pull-trade.go +++ b/extend/pull-trade.go @@ -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 diff --git a/protocol/model_history_trade.go b/protocol/model_history_trade.go index d1cd3ad..bd17129 100644 --- a/protocol/model_history_trade.go +++ b/protocol/model_history_trade.go @@ -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]), }