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: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ApiKeyVersionV2 = "2"

ApiKeyVersionV2 is v2 api key version

Variables

View Source
var (
	SpotBaseURL    = "https://api.huobi.pro"
	SpotAWSBaseURL = "https://api-aws.huobi.pro"

	UsdmBaseURL    = "https://api.hbdm.com"
	UsdmAWSBaseURL = "https://api.hbdm.vn"
)
View Source
var ErrAuth = errors.New("auth error, you should reinitialize client using key and secret")
View Source
var NIL = "<nil>"

Functions

func GZipCompress

func GZipCompress(input string) ([]byte, error)

func GZipDecompress

func GZipDecompress(input []byte) (string, error)

Types

type DefaultAuthParam

type DefaultAuthParam struct {
	AccessKeyId      string `url:"AccessKeyId,omitempty" validate:"omitempty"`
	SignatureMethod  string `url:"SignatureMethod,omitempty" validate:"omitempty"`
	SignatureVersion string `url:"SignatureVersion,omitempty" validate:"omitempty"`
	Timestamp        string `url:"Timestamp,omitempty" validate:"omitempty"`
	Signature        string `url:"Signature,omitempty" validate:"omitempty"`
}

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 HTXClient

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

func NewHTXRestClient

func NewHTXRestClient(cfg *HTXClientCfg) (*HTXClient, error)

func (*HTXClient) CheckAuth

func (htx *HTXClient) CheckAuth() error

func (*HTXClient) GenAuthParams

func (htx *HTXClient) GenAuthParams() DefaultAuthParam

func (*HTXClient) GetBaseURL

func (htx *HTXClient) GetBaseURL() string

func (*HTXClient) GetDebug

func (htx *HTXClient) GetDebug() bool

func (*HTXClient) GetHeaders

func (htx *HTXClient) GetHeaders() (map[string]string, error)

func (*HTXClient) GetKey

func (htx *HTXClient) GetKey() string

func (*HTXClient) GetSecret

func (htx *HTXClient) GetSecret() string

func (*HTXClient) GetSignVersion

func (htx *HTXClient) GetSignVersion() string

func (*HTXClient) NormalizeRequestContent

func (htx *HTXClient) NormalizeRequestContent(req HTTPRequest, tempQuery any) (string, error)

func (*HTXClient) SendHTTPRequest

func (htx *HTXClient) SendHTTPRequest(ctx context.Context, req HTTPRequest) (*HTTPResponse, error)

func (*HTXClient) Sign

func (htx *HTXClient) Sign(plain []byte) string

sign makes a signature by sha256.

type HTXClientCfg

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

	BaseURL     string `validate:"required"`
	Key         string
	Secret      string
	SignVersion string
}

type V1Response

type V1Response struct {
	Status string `json:"messsage"`
	Ch     string `json:"ch"`
}

type V2Response

type V2Response struct {
	Code    int    `json:"code"`
	Message string `json:"messsage"`
}

Jump to

Keyboard shortcuts

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