rest

package
v0.0.0-...-cb51c14 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_OK    = "ok"
	HTTP_ERROR = "error"
)

Variables

This section is empty.

Functions

func ApiKeyGet

func ApiKeyGet(mapParams map[string]string, strRequestPath string, params *ApiParameter) (string, error)

进行签名后的HTTP GET请求, 参考官方Python Demo写的 mapParams: map类型的请求参数, key:value strRequest: API路由路径 return: 请求结果

func ComputeHmac256

func ComputeHmac256(strMessage string, strSecret string) string

HMAC SHA256加密 strMessage: 需要加密的信息 strSecret: 密钥 return: BASE64编码的密文

func CreatePrivateSignByJWT

func CreatePrivateSignByJWT(sign string, PrivateKeyPrime256 string) (string, error)

func CreateSign

func CreateSign(mapParams map[string]string, strMethod, strHostUrl, strRequestPath, strSecretKey string) string

构造签名 mapParams: 送进来参与签名的参数, Map类型 strMethod: 请求的方法 GET, POST...... strHostUrl: 请求的主机 strRequestPath: 请求的路由路径 strSecretKey: 进行签名的密钥

func HttpGetRequest

func HttpGetRequest(strUrl string, mapParams map[string]string) (string, error)

Http Get请求基础函数, 通过封装Go语言Http请求, 支持火币网REST API的HTTP Get请求 strUrl: 请求的URL strParams: string类型的请求参数, user=lxz&pwd=lxz return: 请求结果

func HttpPostRequest

func HttpPostRequest(strUrl string, mapParams map[string]string) string

Http POST请求基础函数, 通过封装Go语言Http请求, 支持火币网REST API的HTTP POST请求 strUrl: 请求的URL mapParams: map类型的请求参数 return: 请求结果

func HttpPostRequestBatchorder

func HttpPostRequestBatchorder(strUrl string, mapParams map[string]interface{}) string

func Map2UrlQuery

func Map2UrlQuery(mapParams map[string]string) string

将map格式的请求参数转换为字符串格式的 mapParams: map格式的参数键值对 return: 查询字符串

func Map2UrlQueryBySort

func Map2UrlQueryBySort(mapParams map[string]string) string

将map格式的请求参数转换为字符串格式的,并按照Map的key升序排列 mapParams: map格式的参数键值对 return: 查询字符串

func MapSortByKey

func MapSortByKey(mapValue map[string]string) map[string]string

对Map按着ASCII码进行排序 mapValue: 需要进行排序的map return: 排序后的map

func MapValueEncodeURI

func MapValueEncodeURI(mapValue map[string]string) map[string]string

对Map的值进行URI编码 mapParams: 需要进行URI编码的map return: 编码后的map

Types

type ApiParameter

type ApiParameter struct {
	AccessKey          string
	HostName           string
	SecretKey          string
	EnablePrivateSign  bool
	Url                string
	PrivateKeyPrime256 string
}

func CreateDefaultFutureApiParameter

func CreateDefaultFutureApiParameter() *ApiParameter

func CreateDefaultSpotApiParameter

func CreateDefaultSpotApiParameter() *ApiParameter

type Data

type Data struct {
	Id   int64   `json:"id"`
	Data []Trade `json:"data"`
}

type DepthRequestDepth

type DepthRequestDepth int32
const (
	DEPTH_FIVE    DepthRequestDepth = 5
	DEPTH_TEN     DepthRequestDepth = 10
	DEPTH_TWENTY  DepthRequestDepth = 20
	DEPTH_DEFAULT DepthRequestDepth = 150
)

type DepthResponse

type DepthResponse struct {
	Status string `json:"status"`
	Tick   Tick   `json:"tick"`
	Ts     int64  `json:"ts"`
	Ch     string `json:"ch"`
}

type DepthStep

type DepthStep string
const (
	DEPTH_STEP0 DepthStep = "step0"
	DEPTH_STEP1 DepthStep = "step1"
	DEPTH_STEP2 DepthStep = "step2"
	DEPTH_STEP3 DepthStep = "step3"
	DEPTH_STEP4 DepthStep = "step4"
	DEPTH_STEP5 DepthStep = "step5"
)

type Error

type Error struct {
	Ts      int    `json:"ts"`
	Status  string `json:"status"`
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
}

type FutureSymbolType

type FutureSymbolType string
const (
	CW FutureSymbolType = "_CW"
	CQ FutureSymbolType = "_CQ"
	NW FutureSymbolType = "_NW"
)

type Handler

type Handler struct {
	Params *ApiParameter
	// contains filtered or unexported fields
}

func NewDefaultFutureRestHandler

func NewDefaultFutureRestHandler() *Handler

func NewDefaultSpotRestHandler

func NewDefaultSpotRestHandler() *Handler

func NewRestHandler

func NewRestHandler(apiParams *ApiParameter) *Handler

func (*Handler) GetFutureMarketDepth

func (handler *Handler) GetFutureMarketDepth(symbol string, cycle FutureSymbolType, depthType DepthStep) (*DepthResponse, error)

func (*Handler) GetSpotDepth

func (handler *Handler) GetSpotDepth(symbol string, depth DepthRequestDepth, depthType DepthStep) (*DepthResponse, error)

func (*Handler) GetSpotDepths

func (handler *Handler) GetSpotDepths(symbols []string, depth DepthRequestDepth, depthType DepthStep) ([]*DepthResponse, error)

func (*Handler) Listen

func (handler *Handler) Listen() <-chan interface{}

func (*Handler) SubscribeFutureContractIndex

func (handler *Handler) SubscribeFutureContractIndex(symbols []string)

*

  • 获取合约指数 *
  • @param symbol
  • ["BTC","ETH"...]
  • @return

func (*Handler) SubscribeFutureMarketDepth

func (handler *Handler) SubscribeFutureMarketDepth(symbols []string, depthType DepthStep)

func (*Handler) SubscribeFutureMarketTrade

func (handler *Handler) SubscribeFutureMarketTrade(symbols []string)

func (*Handler) SubscribeSpotDepth

func (handler *Handler) SubscribeSpotDepth(symbols []string, depth DepthRequestDepth, depthType DepthStep)

func (*Handler) SubscribeSpotTrade

func (handler *Handler) SubscribeSpotTrade(symbols []string)

type Index

type Index struct {
	Symbol     string  `json:"symbol"`
	IndexPrice float64 `json:"index_price"`
	IndexTs    int64   `json:"index_ts"`
}

type IndexResponse

type IndexResponse struct {
	Status string  `json:"status"`
	Data   []Index `json:"data"`
	Ts     int64   `json:"ts"`
}

type Tick

type Tick struct {
	Bids [][]float64 `json:"bids"`
	Asks [][]float64 `json:"asks"`
}

type Trade

type Trade struct {
	Amount    float64 `json:"amount"`
	Ts        int64   `json:"ts"`
	Price     float64 `json:"price"`
	Direction string  `json:"direction"`
}

type TradeResponse

type TradeResponse struct {
	Status string `json:"status"`
	Data   []Data `json:"data"`
	Ts     int64  `json:"ts"`
	Ch     string `json:"ch"`
}

Jump to

Keyboard shortcuts

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