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

NewTicker24hrService Symbols does not work, Symbol is good #20

Closed
tphan267 opened this issue Jan 11, 2024 · 3 comments
Closed

NewTicker24hrService Symbols does not work, Symbol is good #20

tphan267 opened this issue Jan 11, 2024 · 3 comments

Comments

@tphan267
Copy link

func Ticker24hr() {
	baseURL := "https://api.binance.com"

	client := binance_connector.NewClient("", "", baseURL)

	// Ticker24hr
	ticker24hr, err := client.NewTicker24hrService().
		//Symbol("BTCUSDT")
		Symbols([]string{"BTCUSDT", "ETHUSDT"}).
		.Do(context.Background())
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(binance_connector.PrettyPrint(ticker24hr))
}

Logs

<APIError> code=-1100, msg=Illegal characters found in parameter 'symbols'; legal range is '^\[("[A-Z0-9-_.]{1,20}"(,"[A-Z0-9-_.]{1,20}"){0,}){0,1}\]$'.
@HarkovJohn
Copy link

did you solve the problem?
I also faced this problem.

@HarkovJohn
Copy link

HarkovJohn commented Feb 22, 2024

To make the Ticker24hr function work, you need to rewrite the function func (s *Ticker24hr) Do(ctx context.Context, opts ...RequestOption) (res []*Ticker24hrResponse, err error) in the market.go file starting from line 662.

func (s *Ticker24hr) Do(ctx context.Context, opts ...RequestOption) (res []*Ticker24hrResponse, err error) {
	r := &request{
		method:   http.MethodGet,
		endpoint: "/api/v3/ticker/24hr",
		secType:  secTypeNone,
	}
	if s.symbol != nil {
		r.setParam("symbol", *s.symbol)
	}
	if s.symbols != nil {
		s, _ := json.Marshal(s.symbols)
		r.setParam("symbols", string(s))
	}
	data, err := s.c.callAPI(ctx, r, opts...)
	if err != nil {
		return []*Ticker24hrResponse{}, err
	}
	var raw json.RawMessage
	err = json.Unmarshal(data, &raw)
	if err != nil {
		return []*Ticker24hrResponse{}, err
	}

	if raw[0] == '[' {
		res = make([]*Ticker24hrResponse, 0)
		err = json.Unmarshal(data, &res)
		if err != nil {
			return []*Ticker24hrResponse{}, err
		}
	} else {
		// The response is a single object, not an array, make sure to add it to the slice
		singleRes := new(Ticker24hrResponse)
		err = json.Unmarshal(data, &singleRes)
		if err != nil {
			return []*Ticker24hrResponse{}, err
		}
		res = append(res, singleRes)
	}
	return res, nil
}

Please correct the code in the repository.

@alplabin
Copy link
Contributor

This has been fixed in the last release: https://github.com/binance/binance-connector-go/releases/tag/v0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants