Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on getting exchange info with multiple symbols (issue #269) #315

Merged
merged 2 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions v2/exchange_info_service.go
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"net/http"
"strings"
)

// ExchangeInfoService exchange info service
type ExchangeInfoService struct {
c *Client
symbol string
symbols []string
symbols string
}

// Symbol set symbol
Expand All @@ -21,7 +22,11 @@ func (s *ExchangeInfoService) Symbol(symbol string) *ExchangeInfoService {

// Symbols set symbol
func (s *ExchangeInfoService) Symbols(symbols ...string) *ExchangeInfoService {
s.symbols = symbols
if len(symbols) == 0 {
s.symbols = "[]"
} else {
s.symbols = "[\"" + strings.Join(symbols, "\",\"") + "\"]"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use json.Marshal instead of manually concatenating json strings?

Copy link
Contributor Author

@icamys icamys Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adshao Thanks for responding. I would prefer concatenation for three reasons:

  1. It's the fastest way to get the needed string
  2. json.Marshall returns an error that should be either ignored or handled - unnecessary code and memory allocation
  3. json.Marshall returns bytes that should be further converted to string - unnecessary operation and memory allocation

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @icamys , this looks good to me, could you please rebase the code since there is code conflict with the master branch.

Copy link
Contributor Author

@icamys icamys Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adshao Done.

}
return s
}

Expand Down
2 changes: 1 addition & 1 deletion v2/exchange_info_service_test.go
Expand Up @@ -63,7 +63,7 @@ func (s *exchangeInfoServiceTestSuite) TestExchangeInfo() {
s.assertReq(func(r *request) {
e := newRequest().setParams(map[string]interface{}{
"symbol": symbol,
"symbols": symbols,
"symbols": `["ETHBTC","LTCBTC"]`,
})
s.assertRequestEqual(e, r)
})
Expand Down