Skip to content

Commit

Permalink
Merge pull request #599 from 0x0001/master
Browse files Browse the repository at this point in the history
add fee burn service
  • Loading branch information
xyq-c-cpp authored Aug 7, 2024
2 parents 5905362 + 2ac2df0 commit 639815a
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
8 changes: 8 additions & 0 deletions v2/futures/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,11 @@ func (c *Client) NewConstituentsService() *ConstituentsService {
func (c *Client) NewLvtKlinesService() *LvtKlinesService {
return &LvtKlinesService{c: c}
}

func (c *Client) NewGetFeeBurnService() *GetFeeBurnService {
return &GetFeeBurnService{c: c}
}

func (c *Client) NewFeeBurnService() *FeeBurnService {
return &FeeBurnService{c: c}
}
83 changes: 83 additions & 0 deletions v2/futures/fee_burn_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package futures

import (
"context"
"encoding/json"
"fmt"
"net/http"
)

// FeeBurnService set fee burn info
type FeeBurnService struct {
c *Client
feeBurn string
}

func (f *FeeBurnService) Enable() *FeeBurnService {
f.feeBurn = "true"
return f
}

func (f *FeeBurnService) Disable() *FeeBurnService {
f.feeBurn = "false"
return f
}

// Do send request
func (s *FeeBurnService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: http.MethodPost,
endpoint: "/fapi/v1/feeBurn",
secType: secTypeSigned,
}
m := params{
"feeBurn": s.feeBurn,
}
r.setFormParams(m)
data, _, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return err
}
j, err := newJSON(data)
if err != nil {
return err
}
msg, err := j.Get("msg").String()
if err != nil {
return err
}
if msg != "success" {
code, _ := j.Get("code").Int()
return fmt.Errorf("code: %d, msg: %s", code, msg)
}
return nil
}

// GetFeeBurnService get fee burn info
type GetFeeBurnService struct {
c *Client
}

// Do send request
func (s *GetFeeBurnService) Do(ctx context.Context, opts ...RequestOption) (res *FeeBurn, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/fapi/v1/feeBurn",
secType: secTypeSigned,
}
data, _, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(FeeBurn)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}

return res, nil
}

type FeeBurn struct {
FeeBurn bool `json:"feeBurn"`
}
55 changes: 55 additions & 0 deletions v2/futures/fee_burn_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package futures

import (
"testing"

"github.com/stretchr/testify/suite"
)

type feeburnServiceTestSuite struct {
baseTestSuite
}

func TestFeeBurnService(t *testing.T) {
suite.Run(t, new(feeburnServiceTestSuite))
}

func (s *feeburnServiceTestSuite) TestGetFeeBurn() {
data := []byte(`{"feeBurn": true}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest()
s.assertRequestEqual(e, r)
})

res, err := s.client.NewGetFeeBurnService().Do(newContext())
s.r().NoError(err)
s.r().True(res.FeeBurn)
}

func (s *feeburnServiceTestSuite) TestFeeBurnEnable() {
data := []byte(`{"msg": "success"}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest().setFormParam("feeBurn", "true")
s.assertRequestEqual(e, r)
})

err := s.client.NewFeeBurnService().Enable().Do(newContext())
s.r().NoError(err)
}

func (s *feeburnServiceTestSuite) TestFeeBurnDisable() {
data := []byte(`{"msg": "success"}`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest().setFormParam("feeBurn", "false")
s.assertRequestEqual(e, r)
})

err := s.client.NewFeeBurnService().Disable().Do(newContext())
s.r().NoError(err)
}

0 comments on commit 639815a

Please sign in to comment.