utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ApiKeyVersionV1 = "1"

ApiKeyVersionV1 is v1 api key version

View Source
const ApiKeyVersionV2 = "2"

ApiKeyVersionV2 is v2 api key version

View Source
const (
	ApiSuccess = "200000"
)

The predefined API codes

Variables

View Source
var (
	SpotBaseURL    = "https://api.kucoin.com"
	FuturesBaseURL = "https://api-futures.kucoin.com"
)
View Source
var NIL = "<nil>"

Functions

func IntToString

func IntToString(i int64) string

IntToString converts int64 to string.

func ToJsonString

func ToJsonString(v interface{}) string

ToJsonString converts any value to JSON string.

Types

type ApiResponse

type ApiResponse struct {
	Resp    *HTTPResponse
	Code    string          `json:"code"`
	RawData json.RawMessage `json:"data"` // delay parsing
	Message string          `json:"msg"`
}

An ApiResponse represents a API response wrapped Response.

func (*ApiResponse) ApiSuccessful

func (ar *ApiResponse) ApiSuccessful() bool

ApiSuccessful judges the success of API.

func (*ApiResponse) HttpSuccessful

func (ar *ApiResponse) HttpSuccessful() bool

HttpSuccessful judges the success of http.

func (*ApiResponse) ReadData

func (ar *ApiResponse) ReadData(v interface{}) error

ReadData read the api response `data` as JSON into v.

func (*ApiResponse) ReadPaginationData

func (ar *ApiResponse) ReadPaginationData(v interface{}) (*PaginationModel, error)

ReadPaginationData read the data `items` as JSON into v, and returns *PaginationModel.

type HTTPRequest

type HTTPRequest struct {
	BaseURL string
	Path    string
	Method  string
	Headers map[string]string
	Query   any
	Body    any
}

func (*HTTPRequest) RequestBody

func (h *HTTPRequest) RequestBody() (string, error)

func (*HTTPRequest) RequestURI

func (h *HTTPRequest) RequestURI() (string, error)

RequestURI returns the request uri.

type HTTPResponse

type HTTPResponse struct {
	Req  *HTTPRequest
	Resp *http.Response
	Body []byte
}

A HTTPResponse represents a HTTP response.

func NewResponse

func NewResponse(
	request *HTTPRequest,
	response *http.Response,
	body []byte,
) *HTTPResponse

NewResponse Creates a new Response

func (*HTTPResponse) Error

func (r *HTTPResponse) Error() string

func (*HTTPResponse) ReadBody

func (r *HTTPResponse) ReadBody() ([]byte, error)

ReadBody read the response data, then return it.

func (*HTTPResponse) ReadJsonBody

func (r *HTTPResponse) ReadJsonBody(v interface{}) error

ReadJsonBody read the response data as JSON into v.

type KucoinClient

type KucoinClient struct {
	// contains filtered or unexported fields
}

func NewKucoinRestClient

func NewKucoinRestClient(cfg *KucoinClientCfg) (*KucoinClient, error)

func (*KucoinClient) GenSignature

func (k *KucoinClient) GenSignature(req HTTPRequest) (map[string]string, error)

func (*KucoinClient) GetBaseURL

func (k *KucoinClient) GetBaseURL() string

func (*KucoinClient) GetDebug

func (k *KucoinClient) GetDebug() bool

func (*KucoinClient) GetHeaders

func (k *KucoinClient) GetHeaders() (map[string]string, error)

func (*KucoinClient) GetKey

func (k *KucoinClient) GetKey() string

func (*KucoinClient) GetPassphrase

func (k *KucoinClient) GetPassphrase() string

func (*KucoinClient) GetSecret

func (k *KucoinClient) GetSecret() string

func (*KucoinClient) SendHTTPRequest

func (s *KucoinClient) SendHTTPRequest(ctx context.Context, req HTTPRequest) (*HTTPResponse, error)

type KucoinClientCfg

type KucoinClientCfg struct {
	Debug bool
	// Logger
	Logger *slog.Logger

	BaseURL    string `validate:"required"`
	Key        string
	KeyVersion string
	Secret     string
	Passphrase string
}

type PaginationModel

type PaginationModel struct {
	CurrentPage int64           `json:"currentPage"`
	PageSize    int64           `json:"pageSize"`
	TotalNum    int64           `json:"totalNum"`
	TotalPage   int64           `json:"totalPage"`
	RawItems    json.RawMessage `json:"items"` // delay parsing
}

A PaginationModel represents the pagination in a response.

func (*PaginationModel) ReadItems

func (p *PaginationModel) ReadItems(v interface{}) error

ReadItems read the `items` into v.

type PaginationParam

type PaginationParam struct {
	CurrentPage int64
	PageSize    int64
}

A PaginationParam represents the pagination parameters `currentPage` `pageSize` in a request .

func (*PaginationParam) ReadParam

func (p *PaginationParam) ReadParam(params map[string]string)

ReadParam read pagination parameters into params.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL