mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
bitget: update generated request files and fix account assets api data type
This commit is contained in:
parent
e31a6ca3c8
commit
c347a2423a
37
pkg/exchange/bitget/bitgetapi/client_test.go
Normal file
37
pkg/exchange/bitget/bitgetapi/client_test.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package bitgetapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/testutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getTestClientOrSkip(t *testing.T) *RestClient {
|
||||||
|
if b, _ := strconv.ParseBool(os.Getenv("CI")); b {
|
||||||
|
t.Skip("skip test for CI")
|
||||||
|
}
|
||||||
|
|
||||||
|
key, secret, ok := testutil.IntegrationTestConfigured(t, "BITGET")
|
||||||
|
if !ok {
|
||||||
|
t.Skip("BITGET_* env vars are not configured")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
client := NewClient()
|
||||||
|
client.Auth(key, secret, os.Getenv("BITGET_API_PASSPHRASE"))
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_GetAccountAssetsRequest(t *testing.T) {
|
||||||
|
client := getTestClientOrSkip(t)
|
||||||
|
ctx := context.Background()
|
||||||
|
req := client.NewGetAccountAssetsRequest()
|
||||||
|
assets, err := req.Do(ctx)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
t.Logf("assets: %+v", assets)
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountAsset struct {
|
type AccountAsset struct {
|
||||||
CoinId string `json:"coinId"`
|
CoinId int64 `json:"coinId"`
|
||||||
CoinName string `json:"coinName"`
|
CoinName string `json:"coinName"`
|
||||||
Available fixedpoint.Value `json:"available"`
|
Available fixedpoint.Value `json:"available"`
|
||||||
Frozen fixedpoint.Value `json:"frozen"`
|
Frozen fixedpoint.Value `json:"frozen"`
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
//go:generate GetRequest -url "/api/spot/v1/market/tickers" -type GetAllTickersRequest -responseDataType []Ticker
|
//go:generate GetRequest -url "/api/spot/v1/market/tickers" -type GetAllTickersRequest -responseDataType []Ticker
|
||||||
type GetAllTickersRequest struct {
|
type GetAllTickersRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RestClient) NewGetAllTickersRequest() *GetAllTickersRequest {
|
func (c *RestClient) NewGetAllTickersRequest() *GetAllTickersRequest {
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (g *GetAllTickersRequest) Do(ctx context.Context) ([]Ticker, error) {
|
||||||
|
|
||||||
apiURL := "/api/spot/v1/market/tickers"
|
apiURL := "/api/spot/v1/market/tickers"
|
||||||
|
|
||||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
31
pkg/exchange/bitget/bitgetapi/get_candles_request.go
Normal file
31
pkg/exchange/bitget/bitgetapi/get_candles_request.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package bitgetapi
|
||||||
|
|
||||||
|
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
|
||||||
|
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/c9s/requestgen"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Candle struct {
|
||||||
|
Open fixedpoint.Value `json:"open"`
|
||||||
|
High fixedpoint.Value `json:"high"`
|
||||||
|
Low fixedpoint.Value `json:"low"`
|
||||||
|
Close fixedpoint.Value `json:"close"`
|
||||||
|
QuoteVol fixedpoint.Value `json:"quoteVol"`
|
||||||
|
BaseVol fixedpoint.Value `json:"baseVol"`
|
||||||
|
UsdtVol fixedpoint.Value `json:"usdtVol"`
|
||||||
|
Ts types.MillisecondTimestamp `json:"ts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate GetRequest -url "/api/spot/v1/market/candles" -type GetCandlesRequest -responseDataType []Candle
|
||||||
|
type GetCandlesRequest struct {
|
||||||
|
client requestgen.APIClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *RestClient) NewGetCandlesRequest() *GetCandlesRequest {
|
||||||
|
return &GetCandlesRequest{client: c}
|
||||||
|
}
|
139
pkg/exchange/bitget/bitgetapi/get_candles_request_requestgen.go
Normal file
139
pkg/exchange/bitget/bitgetapi/get_candles_request_requestgen.go
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
// Code generated by "requestgen -method GET -responseType .APIResponse -responseDataField Data -url /api/spot/v1/market/candles -type GetCandlesRequest -responseDataType []Candle"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package bitgetapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
||||||
|
func (g *GetCandlesRequest) GetQueryParameters() (url.Values, error) {
|
||||||
|
var params = map[string]interface{}{}
|
||||||
|
|
||||||
|
query := url.Values{}
|
||||||
|
for _k, _v := range params {
|
||||||
|
query.Add(_k, fmt.Sprintf("%v", _v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return query, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetParameters builds and checks the parameters and return the result in a map object
|
||||||
|
func (g *GetCandlesRequest) GetParameters() (map[string]interface{}, error) {
|
||||||
|
var params = map[string]interface{}{}
|
||||||
|
|
||||||
|
return params, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
|
||||||
|
func (g *GetCandlesRequest) GetParametersQuery() (url.Values, error) {
|
||||||
|
query := url.Values{}
|
||||||
|
|
||||||
|
params, err := g.GetParameters()
|
||||||
|
if err != nil {
|
||||||
|
return query, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _k, _v := range params {
|
||||||
|
if g.isVarSlice(_v) {
|
||||||
|
g.iterateSlice(_v, func(it interface{}) {
|
||||||
|
query.Add(_k+"[]", fmt.Sprintf("%v", it))
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
query.Add(_k, fmt.Sprintf("%v", _v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return query, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetParametersJSON converts the parameters from GetParameters into the JSON format
|
||||||
|
func (g *GetCandlesRequest) GetParametersJSON() ([]byte, error) {
|
||||||
|
params, err := g.GetParameters()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
||||||
|
func (g *GetCandlesRequest) GetSlugParameters() (map[string]interface{}, error) {
|
||||||
|
var params = map[string]interface{}{}
|
||||||
|
|
||||||
|
return params, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GetCandlesRequest) applySlugsToUrl(url string, slugs map[string]string) string {
|
||||||
|
for _k, _v := range slugs {
|
||||||
|
needleRE := regexp.MustCompile(":" + _k + "\\b")
|
||||||
|
url = needleRE.ReplaceAllString(url, _v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GetCandlesRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
|
||||||
|
sliceValue := reflect.ValueOf(slice)
|
||||||
|
for _i := 0; _i < sliceValue.Len(); _i++ {
|
||||||
|
it := sliceValue.Index(_i).Interface()
|
||||||
|
_f(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GetCandlesRequest) isVarSlice(_v interface{}) bool {
|
||||||
|
rt := reflect.TypeOf(_v)
|
||||||
|
switch rt.Kind() {
|
||||||
|
case reflect.Slice:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GetCandlesRequest) GetSlugsMap() (map[string]string, error) {
|
||||||
|
slugs := map[string]string{}
|
||||||
|
params, err := g.GetSlugParameters()
|
||||||
|
if err != nil {
|
||||||
|
return slugs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _k, _v := range params {
|
||||||
|
slugs[_k] = fmt.Sprintf("%v", _v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return slugs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GetCandlesRequest) Do(ctx context.Context) ([]Candle, error) {
|
||||||
|
|
||||||
|
// no body params
|
||||||
|
var params interface{}
|
||||||
|
query := url.Values{}
|
||||||
|
|
||||||
|
apiURL := "/api/spot/v1/market/candles"
|
||||||
|
|
||||||
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := g.client.SendRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiResponse APIResponse
|
||||||
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var data []Candle
|
||||||
|
if err := json.Unmarshal(apiResponse.Data, &data); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return data, nil
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ type ServerTime = types.MillisecondTimestamp
|
||||||
|
|
||||||
//go:generate GetRequest -url "/api/spot/v1/public/time" -type GetServerTimeRequest -responseDataType .ServerTime
|
//go:generate GetRequest -url "/api/spot/v1/public/time" -type GetServerTimeRequest -responseDataType .ServerTime
|
||||||
type GetServerTimeRequest struct {
|
type GetServerTimeRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RestClient) NewGetServerTimeRequest() *GetServerTimeRequest {
|
func (c *RestClient) NewGetServerTimeRequest() *GetServerTimeRequest {
|
||||||
|
|
|
@ -118,7 +118,7 @@ func (g *GetServerTimeRequest) Do(ctx context.Context) (*types.MillisecondTimest
|
||||||
|
|
||||||
apiURL := "/api/spot/v1/public/time"
|
apiURL := "/api/spot/v1/public/time"
|
||||||
|
|
||||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Symbol struct {
|
||||||
|
|
||||||
//go:generate GetRequest -url "/api/spot/v1/public/products" -type GetSymbolsRequest -responseDataType []Symbol
|
//go:generate GetRequest -url "/api/spot/v1/public/products" -type GetSymbolsRequest -responseDataType []Symbol
|
||||||
type GetSymbolsRequest struct {
|
type GetSymbolsRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RestClient) NewGetSymbolsRequest() *GetSymbolsRequest {
|
func (c *RestClient) NewGetSymbolsRequest() *GetSymbolsRequest {
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (g *GetSymbolsRequest) Do(ctx context.Context) ([]Symbol, error) {
|
||||||
|
|
||||||
apiURL := "/api/spot/v1/public/products"
|
apiURL := "/api/spot/v1/public/products"
|
||||||
|
|
||||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ type Ticker struct {
|
||||||
|
|
||||||
//go:generate GetRequest -url "/api/spot/v1/market/ticker" -type GetTickerRequest -responseDataType .Ticker
|
//go:generate GetRequest -url "/api/spot/v1/market/ticker" -type GetTickerRequest -responseDataType .Ticker
|
||||||
type GetTickerRequest struct {
|
type GetTickerRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RestClient) NewGetTickerRequest() *GetTickerRequest {
|
func (c *RestClient) NewGetTickerRequest() *GetTickerRequest {
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) {
|
||||||
|
|
||||||
apiURL := "/api/spot/v1/market/ticker"
|
apiURL := "/api/spot/v1/market/ticker"
|
||||||
|
|
||||||
req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user