-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #599 from 0x0001/master
add fee burn service
- Loading branch information
Showing
3 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |