kucoin: rewrite GetAllTickersRequest api

This commit is contained in:
c9s 2021-12-30 02:33:07 +08:00
parent 0fc91500e4
commit 3cf499b605
2 changed files with 89 additions and 21 deletions

View File

@ -0,0 +1,82 @@
// Code generated by "requestgen -method GET -responseType .APIResponse -responseDataField Data -type GetAllTickersRequest -url /api/v1/market/allTickers -responseDataType AllTickers"; DO NOT EDIT.
package kucoinapi
import (
"context"
"encoding/json"
"fmt"
"net/url"
)
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (g *GetAllTickersRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for k, v := range params {
query.Add(k, fmt.Sprintf("%v", v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (g *GetAllTickersRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (g *GetAllTickersRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := g.GetParameters()
if err != nil {
return query, err
}
for k, v := range params {
query.Add(k, fmt.Sprintf("%v", v))
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (g *GetAllTickersRequest) GetParametersJSON() ([]byte, error) {
params, err := g.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
func (g *GetAllTickersRequest) Do(ctx context.Context) (*AllTickers, error) {
// no body params
var params interface{}
query := url.Values{}
req, err := g.client.NewRequest(ctx, "GET", "/api/v1/market/allTickers", query, params)
if err != nil {
return nil, err
}
response, err := g.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse APIResponse
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
var data AllTickers
if err := json.Unmarshal(apiResponse.Data, &data); err != nil {
return nil, err
}
return &data, nil
}

View File

@ -156,28 +156,14 @@ type AllTickers struct {
Ticker []Ticker24H `json:"ticker"`
}
//go:generate GetRequest -type GetAllTickersRequest -url "/api/v1/market/allTickers" -responseDataType AllTickers
type GetAllTickersRequest struct {
client requestgen.APIClient
}
func (s *MarketDataService) ListTickers() (*AllTickers, error) {
req, err := s.client.NewRequest(context.Background(), "GET", "/api/v1/market/allTickers", nil, nil)
if err != nil {
return nil, err
}
response, err := s.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse struct {
Code string `json:"code"`
Message string `json:"msg"`
Data *AllTickers `json:"data"`
}
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse.Data, nil
req := &GetAllTickersRequest{client: s.client}
return req.Do(context.Background())
}
func (s *MarketDataService) GetTicker24HStat(symbol string) (*Ticker24H, error) {