Skip to content

Commit

Permalink
fix: refactor response(binance spot)
Browse files Browse the repository at this point in the history
  • Loading branch information
linstohu committed Nov 28, 2023
1 parent 7b88c49 commit 9e411b2
Show file tree
Hide file tree
Showing 35 changed files with 868 additions and 372 deletions.
31 changes: 19 additions & 12 deletions binance/spot/margin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"log/slog"
"net/http"
"time"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/linstohu/nexapi/binance/spot/margin/types"
spotutils "github.com/linstohu/nexapi/binance/spot/utils"
bnutils "github.com/linstohu/nexapi/binance/utils"
"github.com/linstohu/nexapi/utils"
)

type SpotMarginClient struct {
Expand Down Expand Up @@ -77,16 +77,18 @@ func NewSpotMarginClient(cfg *SpotMarginClientCfg) (*SpotMarginClient, error) {
}, nil
}

func (s *SpotMarginClient) GetInterestHistory(ctx context.Context, param types.GetInterestHistoryParam) (*types.InterestHistory, error) {
req := spotutils.HTTPRequest{
SecurityType: spotutils.USER_DATA,
BaseURL: s.GetBaseURL(),
Path: "/sapi/v1/margin/interestHistory",
Method: http.MethodGet,
func (s *SpotMarginClient) GetInterestHistory(ctx context.Context, param types.GetInterestHistoryParam) (*types.GetInterestHistoryResp, error) {
req := utils.HTTPRequest{
Debug: s.GetDebug(),
BaseURL: s.GetBaseURL(),
Path: "/sapi/v1/margin/interestHistory",
Method: http.MethodGet,
}

st := spotutils.USER_DATA

{
headers, err := s.GenHeaders(req.SecurityType)
headers, err := s.GenHeaders(st)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +109,7 @@ func (s *SpotMarginClient) GetInterestHistory(ctx context.Context, param types.G
return nil, err
}

if need := s.NeedSignature(req.SecurityType); need {
if need := s.NeedSignature(st); need {
signString, err := bnutils.NormalizeRequestContent(query, nil)
if err != nil {
return nil, err
Expand All @@ -128,10 +130,15 @@ func (s *SpotMarginClient) GetInterestHistory(ctx context.Context, param types.G
return nil, err
}

var ret types.InterestHistory
if err := json.Unmarshal(resp, &ret); err != nil {
var body types.InterestHistory
if err := resp.ReadJsonBody(&body); err != nil {
return nil, err
}

return &ret, nil
data := &types.GetInterestHistoryResp{
Http: resp,
Body: &body,
}

return data, nil
}
12 changes: 10 additions & 2 deletions binance/spot/margin/types/interest_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package types

import "github.com/linstohu/nexapi/binance/utils"
import (
bnutils "github.com/linstohu/nexapi/binance/utils"
"github.com/linstohu/nexapi/utils"
)

type GetInterestHistoryParam struct {
Asset string `url:"asset,omitempty" validate:"omitempty"`
Expand All @@ -31,7 +34,12 @@ type GetInterestHistoryParam struct {

type GetInterestHistoryParams struct {
GetInterestHistoryParam
utils.DefaultParam
bnutils.DefaultParam
}

type GetInterestHistoryResp struct {
Http *utils.ApiResponse
Body *InterestHistory
}

type InterestHistory struct {
Expand Down
Loading

0 comments on commit 9e411b2

Please sign in to comment.