bbgo_origin/pkg/exchange/ftx/rest_wallet_request.go

63 lines
1.3 KiB
Go
Raw Normal View History

2021-03-21 12:17:41 +00:00
package ftx
import (
"context"
"encoding/json"
"fmt"
"strconv"
"time"
2021-03-21 12:17:41 +00:00
)
type walletRequest struct {
*restRequest
}
func (r *walletRequest) DepositHistory(ctx context.Context, since time.Time, until time.Time, limit int) (depositHistoryResponse, error) {
q := make(map[string]string)
if limit > 0 {
q["limit"] = strconv.Itoa(limit)
}
if since != (time.Time{}) {
q["start_time"] = strconv.FormatInt(since.Unix(), 10)
}
if until != (time.Time{}) {
q["end_time"] = strconv.FormatInt(until.Unix(), 10)
}
2021-03-21 12:17:41 +00:00
resp, err := r.
Method("GET").
ReferenceURL("api/wallet/deposits").
Query(q).
2021-03-21 12:17:41 +00:00
DoAuthenticatedRequest(ctx)
if err != nil {
return depositHistoryResponse{}, err
}
var d depositHistoryResponse
if err := json.Unmarshal(resp.Body, &d); err != nil {
return depositHistoryResponse{}, fmt.Errorf("failed to unmarshal deposit history response body to json: %w", err)
}
return d, nil
}
func (r *walletRequest) Balances(ctx context.Context) (balances, error) {
resp, err := r.
Method("GET").
ReferenceURL("api/wallet/balances").
DoAuthenticatedRequest(ctx)
if err != nil {
return balances{}, err
}
var b balances
if err := json.Unmarshal(resp.Body, &b); err != nil {
return balances{}, fmt.Errorf("failed to unmarshal balance response body to json: %w", err)
}
return b, nil
}