Get chagnes to GetCandles
This commit is contained in:
parent
bd0154310b
commit
bd2354b81e
44
rest/rest.go
44
rest/rest.go
@ -44,18 +44,51 @@ type RESTAPIResult struct {
|
|||||||
TotalUsedTime time.Duration `json:"totalUsedTime"`
|
TotalUsedTime time.Duration `json:"totalUsedTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResponseData 定义统一的响应数据接口
|
||||||
|
type ResponseData interface {
|
||||||
|
GetCode() string
|
||||||
|
GetMsg() string
|
||||||
|
GetData() interface{}
|
||||||
|
}
|
||||||
|
|
||||||
type Okexv5APIResponse struct {
|
type Okexv5APIResponse struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CandleData struct {
|
// 实现 ResponseData 接口
|
||||||
|
func (r Okexv5APIResponse) GetCode() string {
|
||||||
|
return r.Code
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Okexv5APIResponse) GetMsg() string {
|
||||||
|
return r.Msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Okexv5APIResponse) GetData() interface{} {
|
||||||
|
return r.Data
|
||||||
|
}
|
||||||
|
|
||||||
|
type CandleDataResponse struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Data [][]interface{} `json:"data"` // 用二维数组来接收 candles 数据
|
Data [][]interface{} `json:"data"` // 用二维数组来接收 candles 数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 实现 ResponseData 接口
|
||||||
|
func (r CandleDataResponse) GetCode() string {
|
||||||
|
return r.Code
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r CandleDataResponse) GetMsg() string {
|
||||||
|
return r.Msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r CandleDataResponse) GetData() interface{} {
|
||||||
|
return r.Data
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
endPoint:请求地址
|
endPoint:请求地址
|
||||||
apiKey
|
apiKey
|
||||||
@ -153,11 +186,16 @@ func (this *RESTAPI) Post(ctx context.Context, uri string, param *map[string]int
|
|||||||
return this.Run(ctx)
|
return this.Run(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RESTAPI) Run(ctx context.Context) (res *RESTAPIResult, err error) {
|
func (this *RESTAPI) Run(ctx context.Context) (ResponseData, error) {
|
||||||
|
var res *RESTAPIResult
|
||||||
|
var err error
|
||||||
|
|
||||||
if this.ApiKeyInfo == nil {
|
if this.ApiKeyInfo == nil {
|
||||||
err = errors.New("APIKey不可为空")
|
err = errors.New("APIKey不可为空")
|
||||||
return
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return res.V5Response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
procStart := time.Now()
|
procStart := time.Now()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user