bitget: add more public api tests

This commit is contained in:
c9s 2023-05-17 18:04:24 +08:00
parent c347a2423a
commit 3154961d72
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 27 additions and 2 deletions

View File

@ -35,3 +35,13 @@ func TestClient_GetAccountAssetsRequest(t *testing.T) {
assert.NoError(t, err)
t.Logf("assets: %+v", assets)
}
func TestClient_GetTickerRequest(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()
req := client.NewGetTickerRequest()
req.Symbol("BTCUSDT_SPBL")
ticker, err := req.Do(ctx)
assert.NoError(t, err)
t.Logf("ticker: %+v", ticker)
}

View File

@ -31,6 +31,8 @@ type Ticker struct {
//go:generate GetRequest -url "/api/spot/v1/market/ticker" -type GetTickerRequest -responseDataType .Ticker
type GetTickerRequest struct {
client requestgen.APIClient
symbol string `param:"symbol"`
}
func (c *RestClient) NewGetTickerRequest() *GetTickerRequest {

View File

@ -11,6 +11,11 @@ import (
"regexp"
)
func (g *GetTickerRequest) Symbol(symbol string) *GetTickerRequest {
g.symbol = symbol
return g
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (g *GetTickerRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
@ -26,6 +31,11 @@ func (g *GetTickerRequest) GetQueryParameters() (url.Values, error) {
// GetParameters builds and checks the parameters and return the result in a map object
func (g *GetTickerRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := g.symbol
// assign parameter of symbol
params["symbol"] = symbol
return params, nil
}
@ -111,9 +121,12 @@ func (g *GetTickerRequest) GetSlugsMap() (map[string]string, error) {
func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) {
// no body params
// empty params for GET operation
var params interface{}
query := url.Values{}
query, err := g.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/api/spot/v1/market/ticker"