mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
246 lines
5.6 KiB
Go
246 lines
5.6 KiB
Go
// Code generated by "requestgen -method POST -url /sapi/v1/capital/withdraw/apply -type WithdrawRequest -responseType .WithdrawResponse"; DO NOT EDIT.
|
|
|
|
package binanceapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"reflect"
|
|
"regexp"
|
|
)
|
|
|
|
func (w *WithdrawRequest) Coin(coin string) *WithdrawRequest {
|
|
w.coin = coin
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) Network(network string) *WithdrawRequest {
|
|
w.network = &network
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) Address(address string) *WithdrawRequest {
|
|
w.address = address
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) AddressTag(addressTag string) *WithdrawRequest {
|
|
w.addressTag = &addressTag
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) Amount(amount string) *WithdrawRequest {
|
|
w.amount = amount
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) WithdrawOrderId(withdrawOrderId string) *WithdrawRequest {
|
|
w.withdrawOrderId = &withdrawOrderId
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) TransactionFeeFlag(transactionFeeFlag bool) *WithdrawRequest {
|
|
w.transactionFeeFlag = &transactionFeeFlag
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) Name(name string) *WithdrawRequest {
|
|
w.name = &name
|
|
return w
|
|
}
|
|
|
|
func (w *WithdrawRequest) WalletType(walletType WalletType) *WithdrawRequest {
|
|
w.walletType = &walletType
|
|
return w
|
|
}
|
|
|
|
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
|
func (w *WithdrawRequest) 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 (w *WithdrawRequest) GetParameters() (map[string]interface{}, error) {
|
|
var params = map[string]interface{}{}
|
|
// check coin field -> json key coin
|
|
coin := w.coin
|
|
|
|
// assign parameter of coin
|
|
params["coin"] = coin
|
|
// check network field -> json key network
|
|
if w.network != nil {
|
|
network := *w.network
|
|
|
|
// assign parameter of network
|
|
params["network"] = network
|
|
} else {
|
|
}
|
|
// check address field -> json key address
|
|
address := w.address
|
|
|
|
// assign parameter of address
|
|
params["address"] = address
|
|
// check addressTag field -> json key addressTag
|
|
if w.addressTag != nil {
|
|
addressTag := *w.addressTag
|
|
|
|
// assign parameter of addressTag
|
|
params["addressTag"] = addressTag
|
|
} else {
|
|
}
|
|
// check amount field -> json key amount
|
|
amount := w.amount
|
|
|
|
// assign parameter of amount
|
|
params["amount"] = amount
|
|
// check withdrawOrderId field -> json key withdrawOrderId
|
|
if w.withdrawOrderId != nil {
|
|
withdrawOrderId := *w.withdrawOrderId
|
|
|
|
// assign parameter of withdrawOrderId
|
|
params["withdrawOrderId"] = withdrawOrderId
|
|
} else {
|
|
}
|
|
// check transactionFeeFlag field -> json key transactionFeeFlag
|
|
if w.transactionFeeFlag != nil {
|
|
transactionFeeFlag := *w.transactionFeeFlag
|
|
|
|
// assign parameter of transactionFeeFlag
|
|
params["transactionFeeFlag"] = transactionFeeFlag
|
|
} else {
|
|
}
|
|
// check name field -> json key name
|
|
if w.name != nil {
|
|
name := *w.name
|
|
|
|
// assign parameter of name
|
|
params["name"] = name
|
|
} else {
|
|
}
|
|
// check walletType field -> json key walletType
|
|
if w.walletType != nil {
|
|
walletType := *w.walletType
|
|
|
|
// assign parameter of walletType
|
|
params["walletType"] = walletType
|
|
} else {
|
|
}
|
|
|
|
return params, nil
|
|
}
|
|
|
|
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
|
|
func (w *WithdrawRequest) GetParametersQuery() (url.Values, error) {
|
|
query := url.Values{}
|
|
|
|
params, err := w.GetParameters()
|
|
if err != nil {
|
|
return query, err
|
|
}
|
|
|
|
for k, v := range params {
|
|
if w.isVarSlice(v) {
|
|
w.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 (w *WithdrawRequest) GetParametersJSON() ([]byte, error) {
|
|
params, err := w.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 (w *WithdrawRequest) GetSlugParameters() (map[string]interface{}, error) {
|
|
var params = map[string]interface{}{}
|
|
|
|
return params, nil
|
|
}
|
|
|
|
func (w *WithdrawRequest) 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 (w *WithdrawRequest) 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 (w *WithdrawRequest) isVarSlice(v interface{}) bool {
|
|
rt := reflect.TypeOf(v)
|
|
switch rt.Kind() {
|
|
case reflect.Slice:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (w *WithdrawRequest) GetSlugsMap() (map[string]string, error) {
|
|
slugs := map[string]string{}
|
|
params, err := w.GetSlugParameters()
|
|
if err != nil {
|
|
return slugs, nil
|
|
}
|
|
|
|
for k, v := range params {
|
|
slugs[k] = fmt.Sprintf("%v", v)
|
|
}
|
|
|
|
return slugs, nil
|
|
}
|
|
|
|
func (w *WithdrawRequest) Do(ctx context.Context) (*WithdrawResponse, error) {
|
|
|
|
params, err := w.GetParameters()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
query := url.Values{}
|
|
|
|
apiURL := "/sapi/v1/capital/withdraw/apply"
|
|
|
|
req, err := w.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response, err := w.client.SendRequest(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var apiResponse WithdrawResponse
|
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
|
return nil, err
|
|
}
|
|
return &apiResponse, nil
|
|
}
|