mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1416 from c9s/edwin/bitget/add-restful-api-validator
FEATURE: [bitget] add response validator
This commit is contained in:
commit
8ca8e4c946
|
@ -7,6 +7,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -164,3 +165,17 @@ type APIResponse struct {
|
|||
Message string `json:"msg"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
|
||||
func (a APIResponse) Validate() error {
|
||||
// v1, v2 use the same success code.
|
||||
// https://www.bitget.com/api-doc/spot/error-code/restapi
|
||||
// https://bitgetlimited.github.io/apidoc/en/mix/#restapi-error-codes
|
||||
if a.Code != "00000" {
|
||||
return a.Error()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a APIResponse) Error() error {
|
||||
return fmt.Errorf("code: %s, msg: %s, data: %q", a.Code, a.Message, a.Data)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user