rest

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	/*
	  http headers
	*/
	OK_ACCESS_KEY        = "OK-ACCESS-KEY"
	OK_ACCESS_SIGN       = "OK-ACCESS-SIGN"
	OK_ACCESS_TIMESTAMP  = "OK-ACCESS-TIMESTAMP"
	OK_ACCESS_PASSPHRASE = "OK-ACCESS-PASSPHRASE"
	X_SIMULATE_TRADING   = "x-simulated-trading"

	CONTENT_TYPE = "Content-Type"
	ACCEPT       = "Accept"
	COOKIE       = "Cookie"
	LOCALE       = "locale="

	APPLICATION_JSON      = "application/json"
	APPLICATION_JSON_UTF8 = "application/json; charset=UTF-8"

	/*
	  i18n: internationalization
	*/
	ENGLISH            = "en_US"
	SIMPLIFIED_CHINESE = "zh_CN"
	//zh_TW || zh_HK
	TRADITIONAL_CHINESE = "zh_HK"

	GET  = "GET"
	POST = "POST"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyInfo

type APIKeyInfo struct {
	ApiKey     string
	PassPhrase string
	SecKey     string
	UserId     string
}

type Okexv5APIResponse

type Okexv5APIResponse struct {
	Code string                   `json:"code"`
	Msg  string                   `json:"msg"`
	Data []map[string]interface{} `json:"data"`
}

type RESTAPI

type RESTAPI struct {
	EndPoint string `json:"endPoint"`
	// GET/POST
	Method     string                 `json:"method"`
	Uri        string                 `json:"uri"`
	Param      map[string]interface{} `json:"param"`
	Timeout    time.Duration
	ProxyUrl   *string
	ApiKeyInfo *APIKeyInfo
	// contains filtered or unexported fields
}

func NewRESTAPI

func NewRESTAPI(ep, method, uri string, param *map[string]interface{}) *RESTAPI

func NewRESTClient

func NewRESTClient(endPoint string, apiKey *APIKeyInfo, isSimulate bool) *RESTAPI

endPoint:请求地址 apiKey isSimulate: 是否为模拟环境

func (*RESTAPI) GenReqInfo

func (this *RESTAPI) GenReqInfo() (uri string, body string, err error)

生成请求对应的参数

func (*RESTAPI) Get

func (this *RESTAPI) Get(ctx context.Context, uri string, param *map[string]interface{}) (res *RESTAPIResult, err error)

GET请求

func (*RESTAPI) Post

func (this *RESTAPI) Post(ctx context.Context, uri string, param *map[string]interface{}) (res *RESTAPIResult, err error)

POST请求

func (*RESTAPI) PrintRequest

func (this *RESTAPI) PrintRequest(request *http.Request, body string, preHash string)

打印header信息

func (*RESTAPI) Run

func (this *RESTAPI) Run(ctx context.Context) (res *RESTAPIResult, err error)

func (*RESTAPI) SetAPIKey

func (this *RESTAPI) SetAPIKey(apiKey, secKey, passPhrase string) *RESTAPI

func (*RESTAPI) SetHeaders

func (this *RESTAPI) SetHeaders(request *http.Request, timestamp string, sign string) (header string)

Set http request headers: Accept: application/json Content-Type: application/json; charset=UTF-8 (default) Cookie: locale=en_US (English) OK-ACCESS-KEY: (Your setting) OK-ACCESS-SIGN: (Use your setting, auto sign and add) OK-ACCESS-TIMESTAMP: (Auto add) OK-ACCESS-PASSPHRASE: Your setting

func (*RESTAPI) SetProxyUrl added in v1.0.1

func (this *RESTAPI) SetProxyUrl(proxyUrl string) *RESTAPI

func (*RESTAPI) SetSimulate

func (this *RESTAPI) SetSimulate(b bool) *RESTAPI

func (*RESTAPI) SetTimeOut

func (this *RESTAPI) SetTimeOut(timeout time.Duration) *RESTAPI

func (*RESTAPI) SetUserId

func (this *RESTAPI) SetUserId(userId string) *RESTAPI

type RESTAPIResult

type RESTAPIResult struct {
	Url    string `json:"url"`
	Param  string `json:"param"`
	Header string `json:"header"`
	Code   int    `json:"code"`
	// 原始返回信息
	Body string `json:"body"`
	// okexV5返回的数据
	V5Response    Okexv5APIResponse `json:"v5Response"`
	ReqUsedTime   time.Duration     `json:"reqUsedTime"`
	TotalUsedTime time.Duration     `json:"totalUsedTime"`
}

Jump to

Keyboard shortcuts

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