Skip to content

Commit 48ee0ed

Browse files
hyper.jianghyperjiang
authored andcommitted
fix copy-paste bugs, select case order, and add safety checks
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
1 parent 0726015 commit 48ee0ed

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

adapt/adapt.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func NewSecurities(codes []string) []*qotcommon.Security {
3737

3838
// SecurityToCode converts a Security to a code string, e.g. "HK.00700".
3939
func SecurityToCode(s *qotcommon.Security) string {
40+
if s == nil {
41+
return ""
42+
}
4043
return GetMarketName(s.GetMarket()) + "." + s.GetCode()
4144
}
4245

@@ -125,7 +128,9 @@ func NewCustomIndicatorFilter(opts ...Option) *qotstockfilter.CustomIndicatorFil
125128
o["isNoFilter"] = false
126129

127130
var f qotstockfilter.CustomIndicatorFilter
128-
_ = o.ToProto(&f)
131+
if err := o.ToProto(&f); err != nil {
132+
return nil
133+
}
129134

130135
return &f
131136
}
@@ -134,7 +139,9 @@ func NewCustomIndicatorFilter(opts ...Option) *qotstockfilter.CustomIndicatorFil
134139
func NewFilterConditions(opts ...Option) *trdcommon.TrdFilterConditions {
135140
o := NewOptions(opts...)
136141
var f trdcommon.TrdFilterConditions
137-
_ = o.ToProto(&f)
142+
if err := o.ToProto(&f); err != nil {
143+
return nil
144+
}
138145

139146
return &f
140147
}

client/quote.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,13 @@ func (client *Client) QotGetMarketState(ctx context.Context, c2s *qotgetmarketst
805805
select {
806806
case <-ctx.Done():
807807
return nil, ctx.Err()
808+
case <-client.closed:
809+
return nil, ErrInterrupted
808810
case resp, ok := <-ch:
809811
if !ok {
810812
return nil, ErrChannelClosed
811813
}
812814
return resp.GetS2C(), infra.Error(resp)
813-
case <-client.closed:
814-
return nil, ErrInterrupted
815815
}
816816
}
817817

@@ -830,12 +830,12 @@ func (client *Client) QotGetOptionExpirationDate(ctx context.Context, c2s *qotge
830830
select {
831831
case <-ctx.Done():
832832
return nil, ctx.Err()
833+
case <-client.closed:
834+
return nil, ErrInterrupted
833835
case resp, ok := <-ch:
834836
if !ok {
835837
return nil, ErrChannelClosed
836838
}
837839
return resp.GetS2C(), infra.Error(resp)
838-
case <-client.closed:
839-
return nil, ErrInterrupted
840840
}
841841
}

client/trade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (ts *ClientTestSuite) TestTrdGetAccList_TrdGetFunds() {
5656
}
5757

5858
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
59-
defer cancel()
6059
res, err := ts.client.TrdGetFunds(ctx, c2s)
60+
cancel()
6161
should.NoError(err)
6262
log.Info().Interface("data", res.GetFunds()).Msg("TrdGetFunds")
6363
}

sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (sdk *SDK) GetPositionList(header *trdcommon.TrdHeader, opts ...adapt.Optio
135135
return sdk.GetPositionListWithContext(ctx, header, opts...)
136136
}
137137

138-
// GetOrderList 2111 - gets the maximum available trading quantities.
138+
// GetMaxTrdQtys 2111 - gets the maximum available trading quantities.
139139
//
140140
// header: trading header
141141
//
@@ -193,7 +193,7 @@ func (sdk *SDK) ModifyOrder(header *trdcommon.TrdHeader, orderID uint64, modifyO
193193
return sdk.ModifyOrderWithContext(ctx, header, orderID, modifyOrderOp, opts...)
194194
}
195195

196-
// GetHistoryOrderList 2211 - gets the filled order list.
196+
// GetOrderFillList 2211 - gets the filled order list.
197197
func (sdk *SDK) GetOrderFillList(header *trdcommon.TrdHeader, opts ...adapt.Option) ([]*trdcommon.OrderFill, error) {
198198
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
199199
defer cancel()

0 commit comments

Comments
 (0)