129 lines
3.0 KiB
Go
129 lines
3.0 KiB
Go
|
// Code generated by "requestgen -method GET -responseType .APIResponse -responseDataField Data -type GetTickerRequest -url /api/v1/market/orderbook/level1 -responseDataType Ticker"; DO NOT EDIT.
|
||
|
|
||
|
package kucoinapi
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"net/url"
|
||
|
"regexp"
|
||
|
)
|
||
|
|
||
|
func (g *GetTickerRequest) Symbol(symbol string) *GetTickerRequest {
|
||
|
g.symbol = symbol
|
||
|
return g
|
||
|
}
|
||
|
|
||
|
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
||
|
func (g *GetTickerRequest) GetQueryParameters() (url.Values, error) {
|
||
|
var params = map[string]interface{}{}
|
||
|
// check symbol field -> json key symbol
|
||
|
symbol := g.symbol
|
||
|
|
||
|
// assign parameter of symbol
|
||
|
params["symbol"] = symbol
|
||
|
|
||
|
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 *GetTickerRequest) 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 *GetTickerRequest) 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 *GetTickerRequest) GetParametersJSON() ([]byte, error) {
|
||
|
params, err := g.GetParameters()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return json.Marshal(params)
|
||
|
}
|
||
|
|
||
|
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||
|
func (g *GetTickerRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||
|
var params = map[string]interface{}{}
|
||
|
|
||
|
return params, nil
|
||
|
}
|
||
|
|
||
|
func (g *GetTickerRequest) applySlugsToUrl(url string, slugs map[string]string) string {
|
||
|
for k, v := range slugs {
|
||
|
needleRE := regexp.MustCompile(":" + k + "\\b")
|
||
|
url = needleRE.ReplaceAllString(url, v)
|
||
|
}
|
||
|
|
||
|
return url
|
||
|
}
|
||
|
|
||
|
func (g *GetTickerRequest) GetSlugsMap() (map[string]string, error) {
|
||
|
slugs := map[string]string{}
|
||
|
params, err := g.GetSlugParameters()
|
||
|
if err != nil {
|
||
|
return slugs, nil
|
||
|
}
|
||
|
|
||
|
for k, v := range params {
|
||
|
slugs[k] = fmt.Sprintf("%v", v)
|
||
|
}
|
||
|
|
||
|
return slugs, nil
|
||
|
}
|
||
|
|
||
|
func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) {
|
||
|
|
||
|
// no body params
|
||
|
var params interface{}
|
||
|
query, err := g.GetQueryParameters()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
apiURL := "/api/v1/market/orderbook/level1"
|
||
|
|
||
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, 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 Ticker
|
||
|
if err := json.Unmarshal(apiResponse.Data, &data); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &data, nil
|
||
|
}
|