binance: add GetDepositHistoryRequest

This commit is contained in:
c9s 2022-04-28 01:35:23 +08:00
parent ed8ff89f34
commit 2008f179a2
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 234 additions and 0 deletions

View File

@ -71,6 +71,21 @@ func TestClient_GetDepositAddressRequest(t *testing.T) {
t.Logf("deposit address: %+v", address)
}
func TestClient_GetDepositHistoryRequest(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()
err := client.SetTimeOffsetFromServer(ctx)
assert.NoError(t, err)
req := client.NewGetDepositHistoryRequest()
history, err := req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, history)
assert.NotEmpty(t, history)
t.Logf("deposit history: %+v", history)
}
func TestClient_privateCall(t *testing.T) {

View File

@ -0,0 +1,38 @@
package binanceapi
import (
"time"
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
type DepositHistory struct {
Amount fixedpoint.Value `json:"amount"`
Coin string `json:"coin"`
Network string `json:"network"`
Status int `json:"status"`
Address string `json:"address"`
AddressTag string `json:"addressTag"`
TxId string `json:"txId"`
InsertTime types.MillisecondTimestamp `json:"insertTime"`
TransferType int `json:"transferType"`
UnlockConfirm int `json:"unlockConfirm"`
ConfirmTimes string `json:"confirmTimes"`
}
//go:generate requestgen -method GET -url "/sapi/v1/capital/deposit/hisrec" -type GetDepositHistoryRequest -responseType []DepositHistory
type GetDepositHistoryRequest struct {
client requestgen.AuthenticatedAPIClient
coin *string `param:"coin"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *RestClient) NewGetDepositHistoryRequest() *GetDepositHistoryRequest {
return &GetDepositHistoryRequest{client: c}
}

View File

@ -0,0 +1,181 @@
// Code generated by "requestgen -method GET -url /sapi/v1/capital/deposit/hisrec -type GetDepositHistoryRequest -responseType []DepositHistory"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (g *GetDepositHistoryRequest) Coin(coin string) *GetDepositHistoryRequest {
g.coin = &coin
return g
}
func (g *GetDepositHistoryRequest) StartTime(startTime time.Time) *GetDepositHistoryRequest {
g.startTime = &startTime
return g
}
func (g *GetDepositHistoryRequest) EndTime(endTime time.Time) *GetDepositHistoryRequest {
g.endTime = &endTime
return g
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (g *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check coin field -> json key coin
if g.coin != nil {
coin := *g.coin
// assign parameter of coin
params["coin"] = coin
} else {
}
// check startTime field -> json key startTime
if g.startTime != nil {
startTime := *g.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if g.endTime != nil {
endTime := *g.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (g *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (g *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) isVarSlice(v interface{}) bool {
rt := reflect.TypeOf(v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (g *GetDepositHistoryRequest) 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 *GetDepositHistoryRequest) Do(ctx context.Context) ([]DepositHistory, error) {
// empty params for GET operation
var params interface{}
query, err := g.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/sapi/v1/capital/deposit/hisrec"
req, err := g.client.NewAuthenticatedRequest(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 []DepositHistory
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}