From c88f74264ed06979cfc0430f0efd3d746a573df1 Mon Sep 17 00:00:00 2001 From: "hyper.jiang" Date: Thu, 21 May 2026 18:38:13 +0800 Subject: [PATCH] fix copy-paste bugs, select case order, and add safety checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix incorrect godoc method names in sdk.go, reorder select cases in quote.go to match the standard pattern used everywhere else, replace defer-in-loop with immediate cancel in trade_test.go, add nil guard to SecurityToCode, and stop silently discarding ToProto errors in NewCustomIndicatorFilter and NewFilterConditions. 💘 Generated with Crush Assisted-by: Crush:mimo-v2.5-pro --- adapt/adapt.go | 11 +++++++++-- client/quote.go | 8 ++++---- client/trade_test.go | 2 +- sdk.go | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/adapt/adapt.go b/adapt/adapt.go index bd5b0be..86eb7c7 100644 --- a/adapt/adapt.go +++ b/adapt/adapt.go @@ -37,6 +37,9 @@ func NewSecurities(codes []string) []*qotcommon.Security { // SecurityToCode converts a Security to a code string, e.g. "HK.00700". func SecurityToCode(s *qotcommon.Security) string { + if s == nil { + return "" + } return GetMarketName(s.GetMarket()) + "." + s.GetCode() } @@ -125,7 +128,9 @@ func NewCustomIndicatorFilter(opts ...Option) *qotstockfilter.CustomIndicatorFil o["isNoFilter"] = false var f qotstockfilter.CustomIndicatorFilter - _ = o.ToProto(&f) + if err := o.ToProto(&f); err != nil { + return nil + } return &f } @@ -134,7 +139,9 @@ func NewCustomIndicatorFilter(opts ...Option) *qotstockfilter.CustomIndicatorFil func NewFilterConditions(opts ...Option) *trdcommon.TrdFilterConditions { o := NewOptions(opts...) var f trdcommon.TrdFilterConditions - _ = o.ToProto(&f) + if err := o.ToProto(&f); err != nil { + return nil + } return &f } diff --git a/client/quote.go b/client/quote.go index be7c1a8..f03a3fc 100644 --- a/client/quote.go +++ b/client/quote.go @@ -805,13 +805,13 @@ func (client *Client) QotGetMarketState(ctx context.Context, c2s *qotgetmarketst select { case <-ctx.Done(): return nil, ctx.Err() + case <-client.closed: + return nil, ErrInterrupted case resp, ok := <-ch: if !ok { return nil, ErrChannelClosed } return resp.GetS2C(), infra.Error(resp) - case <-client.closed: - return nil, ErrInterrupted } } @@ -830,12 +830,12 @@ func (client *Client) QotGetOptionExpirationDate(ctx context.Context, c2s *qotge select { case <-ctx.Done(): return nil, ctx.Err() + case <-client.closed: + return nil, ErrInterrupted case resp, ok := <-ch: if !ok { return nil, ErrChannelClosed } return resp.GetS2C(), infra.Error(resp) - case <-client.closed: - return nil, ErrInterrupted } } diff --git a/client/trade_test.go b/client/trade_test.go index 18fd282..a9a9513 100644 --- a/client/trade_test.go +++ b/client/trade_test.go @@ -56,8 +56,8 @@ func (ts *ClientTestSuite) TestTrdGetAccList_TrdGetFunds() { } ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() res, err := ts.client.TrdGetFunds(ctx, c2s) + cancel() should.NoError(err) log.Info().Interface("data", res.GetFunds()).Msg("TrdGetFunds") } diff --git a/sdk.go b/sdk.go index 6fcade3..56126d8 100644 --- a/sdk.go +++ b/sdk.go @@ -135,7 +135,7 @@ func (sdk *SDK) GetPositionList(header *trdcommon.TrdHeader, opts ...adapt.Optio return sdk.GetPositionListWithContext(ctx, header, opts...) } -// GetOrderList 2111 - gets the maximum available trading quantities. +// GetMaxTrdQtys 2111 - gets the maximum available trading quantities. // // header: trading header // @@ -193,7 +193,7 @@ func (sdk *SDK) ModifyOrder(header *trdcommon.TrdHeader, orderID uint64, modifyO return sdk.ModifyOrderWithContext(ctx, header, orderID, modifyOrderOp, opts...) } -// GetHistoryOrderList 2211 - gets the filled order list. +// GetOrderFillList 2211 - gets the filled order list. func (sdk *SDK) GetOrderFillList(header *trdcommon.TrdHeader, opts ...adapt.Option) ([]*trdcommon.OrderFill, error) { ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) defer cancel()