Skip to content

Commit

Permalink
change api struct
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0001 committed Nov 13, 2024
1 parent 11d2fa3 commit 6af0c8b
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 87 deletions.
64 changes: 2 additions & 62 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,68 +1356,8 @@ func (c *Client) NewGetFuturesAlgoSubOrdersService() *GetFuturesAlgoSubOrdersSer
}

// ----- simple earn service -----

func (c *Client) NewGetSimpleEarnAccountService() *SimpleEarnGetAccountService {
return &SimpleEarnGetAccountService{c: c}
}

func (c *Client) NewListSimpleEarnFlexibleProductService() *SimpleEarnListFlexibleProductService {
return &SimpleEarnListFlexibleProductService{c: c}
}

func (c *Client) NewListSimpleEarnLockedProductService() *SimpleEarnListLockedProductService {
return &SimpleEarnListLockedProductService{c: c}
}

func (c *Client) NewGetSimpleEarnFlexiblePositionService() *SimpleEarnGetFlexiblePositionService {
return &SimpleEarnGetFlexiblePositionService{c: c}
}

func (c *Client) NewGetSimpleEarnLockedPositionService() *SimpleEarnGetLockedPositionService {
return &SimpleEarnGetLockedPositionService{c: c}
}

func (c *Client) NewGetSimpleEarnFlexibleQuotaService() *SimpleEarnGetFlexibleQuotaService {
return &SimpleEarnGetFlexibleQuotaService{c: c}
}

func (c *Client) NewGetSimpleEarnLockedQuotaService() *SimpleEarnGetLockedQuotaService {
return &SimpleEarnGetLockedQuotaService{c: c}
}

func (c *Client) NewSimpleEarnSubscribeFlexibleProductService() *SimpleEarnSubscribeFlexibleProductService {
return &SimpleEarnSubscribeFlexibleProductService{c: c}
}

func (c *Client) NewSimpleEarnSubscribeLockedProductService() *SimpleEarnSubscribeLockedProductService {
return &SimpleEarnSubscribeLockedProductService{c: c}
}

func (c *Client) NewSimpleEarnRedeemFlexibleProductService() *SimpleEarnRedeemFlexibleProductService {
return &SimpleEarnRedeemFlexibleProductService{c: c}
}

func (c *Client) NewSimpleEarnRedeemLockedProductService() *SimpleEarnRedeemLockedProductService {
return &SimpleEarnRedeemLockedProductService{c: c}
}

func (c *Client) NewSimpleEarnSetAutoSubscribeFlexibleProductService() *SimpleEarnSetAutoSubscribeFlexibleProductService {
return &SimpleEarnSetAutoSubscribeFlexibleProductService{c: c}
}

func (c *Client) NewSimpleEarnSetAutoSubscribeLockedProductService() *SimpleEarnSetAutoSubscribeLockedProductService {
return &SimpleEarnSetAutoSubscribeLockedProductService{c: c}
}

func (c *Client) NewSimpleEarnSubscriptionPreviewService() *SimpleEarnSubscriptionPreviewService {
return &SimpleEarnSubscriptionPreviewService{c: c}
}

func (c *Client) NewSimpleEarnLockedSubscriptionPreviewService() *SimpleEarnLockedSubscriptionPreviewService {
return &SimpleEarnLockedSubscriptionPreviewService{c: c}
}
func (c *Client) NewSimpleEarnSetRedeemOptionService() *SimpleEarnSetRedeemOptionService {
return &SimpleEarnSetRedeemOptionService{c: c}
func (c *Client) NewSimpleEarnService() *SimpleEarnService {
return &SimpleEarnService{c: c}
}

// ----- end simple earn service -----
96 changes: 90 additions & 6 deletions v2/simple_earn_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,90 @@ import (
"net/http"
)

type SimpleEarnService struct {
c *Client
}

func (s *SimpleEarnService) GetAccount() *SimpleEarnGetAccountService {
return &SimpleEarnGetAccountService{c: s.c}
}

func (s *SimpleEarnService) FlexibleService() *SimpleEarnFlexiableService {

Check warning on line 16 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnFlexiableService{c: s.c}

Check warning on line 17 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
}

func (s *SimpleEarnService) LockedService() *SimpleEarnLockedService {
return &SimpleEarnLockedService{c: s.c}
}

// --
type SimpleEarnFlexiableService struct {

Check warning on line 25 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
c *Client
}

func (s *SimpleEarnFlexiableService) ListProduct() *SimpleEarnListFlexibleProductService {

Check warning on line 29 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnListFlexibleProductService{c: s.c}
}

func (s *SimpleEarnFlexiableService) GetPosition() *SimpleEarnGetFlexiblePositionService {

Check warning on line 33 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnGetFlexiblePositionService{c: s.c}
}

func (s *SimpleEarnFlexiableService) GetLeftQuote() *SimpleEarnGetFlexibleQuotaService {

Check warning on line 37 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnGetFlexibleQuotaService{c: s.c}
}

func (s *SimpleEarnFlexiableService) Subscribe() *SimpleEarnSubscribeFlexibleProductService {

Check warning on line 41 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnSubscribeFlexibleProductService{c: s.c}
}

func (s *SimpleEarnFlexiableService) Redeem() *SimpleEarnRedeemFlexibleProductService {

Check warning on line 45 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnRedeemFlexibleProductService{c: s.c}
}

func (s *SimpleEarnFlexiableService) SetAutoSubscribe() *SimpleEarnSetAutoSubscribeFlexibleProductService {

Check warning on line 49 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnSetAutoSubscribeFlexibleProductService{c: s.c}
}

func (s *SimpleEarnFlexiableService) PreviewSubscribe() *SimpleEarnFlexiableSubscriptionPreviewService {

Check warning on line 53 in v2/simple_earn_service.go

View workflow job for this annotation

GitHub Actions / TyposCheck

"Flexiable" should be "Flexible".
return &SimpleEarnFlexiableSubscriptionPreviewService{c: s.c}
}

// --

type SimpleEarnLockedService struct {
c *Client
}

func (s *SimpleEarnLockedService) ListProduct() *SimpleEarnListLockedProductService {
return &SimpleEarnListLockedProductService{c: s.c}
}
func (s *SimpleEarnLockedService) GetPosition() *SimpleEarnGetLockedPositionService {
return &SimpleEarnGetLockedPositionService{c: s.c}
}
func (s *SimpleEarnLockedService) GetLeftQuote() *SimpleEarnGetLockedQuotaService {
return &SimpleEarnGetLockedQuotaService{c: s.c}
}
func (s *SimpleEarnLockedService) Subscribe() *SimpleEarnSubscribeLockedProductService {
return &SimpleEarnSubscribeLockedProductService{c: s.c}
}
func (s *SimpleEarnLockedService) Redeem() *SimpleEarnRedeemLockedProductService {
return &SimpleEarnRedeemLockedProductService{c: s.c}
}
func (s *SimpleEarnLockedService) SetAutoSubscribe() *SimpleEarnSetAutoSubscribeLockedProductService {
return &SimpleEarnSetAutoSubscribeLockedProductService{c: s.c}
}

func (s *SimpleEarnLockedService) PreviewSubscribe() *SimpleEarnLockedSubscriptionPreviewService {
return &SimpleEarnLockedSubscriptionPreviewService{c: s.c}
}

func (s *SimpleEarnLockedService) SetRedeemOption() *SimpleEarnSetRedeemOptionService {
return &SimpleEarnSetRedeemOptionService{c: s.c}
}

// --------------------

type SimpleEarnGetAccountService struct {
c *Client
}
Expand Down Expand Up @@ -788,23 +872,23 @@ func (s *SimpleEarnSetAutoSubscribeLockedProductService) Do(ctx context.Context,
return res, nil
}

type SimpleEarnSubscriptionPreviewService struct {
type SimpleEarnFlexiableSubscriptionPreviewService struct {
c *Client
productId string
amount string
}

func (s *SimpleEarnSubscriptionPreviewService) ProductId(productId string) *SimpleEarnSubscriptionPreviewService {
func (s *SimpleEarnFlexiableSubscriptionPreviewService) ProductId(productId string) *SimpleEarnFlexiableSubscriptionPreviewService {
s.productId = productId
return s
}

func (s *SimpleEarnSubscriptionPreviewService) Amount(amount string) *SimpleEarnSubscriptionPreviewService {
func (s *SimpleEarnFlexiableSubscriptionPreviewService) Amount(amount string) *SimpleEarnFlexiableSubscriptionPreviewService {
s.amount = amount
return s
}

type SimpleEarnSubscriptionPreviewResp struct {
type SimpleEarnFlexiableSubscriptionPreviewResp struct {
TotalAmount string `json:"totalAmount"`
RewardAsset string `json:"rewardAsset"`
AirDropAsset string `json:"airDropAsset"`
Expand All @@ -813,7 +897,7 @@ type SimpleEarnSubscriptionPreviewResp struct {
EstDailyAirdropRewards string `json:"estDailyAirdropRewards"`
}

func (s *SimpleEarnSubscriptionPreviewService) Do(ctx context.Context, opts ...RequestOption) (res *SimpleEarnSubscriptionPreviewResp, err error) {
func (s *SimpleEarnFlexiableSubscriptionPreviewService) Do(ctx context.Context, opts ...RequestOption) (res *SimpleEarnFlexiableSubscriptionPreviewResp, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/simple-earn/flexible/subscriptionPreview",
Expand All @@ -832,7 +916,7 @@ func (s *SimpleEarnSubscriptionPreviewService) Do(ctx context.Context, opts ...R
return nil, err
}

res = new(SimpleEarnSubscriptionPreviewResp)
res = new(SimpleEarnFlexiableSubscriptionPreviewResp)
if err := json.Unmarshal(data, &res); err != nil {
return nil, err
}
Expand Down
38 changes: 19 additions & 19 deletions v2/simple_earn_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *simpleEarnServiceTestSuite) TestGetAccount() {
s.assertRequestEqual(e, r)
})

account, err := s.client.NewGetSimpleEarnAccountService().Do(newContext())
account, err := s.client.NewSimpleEarnService().GetAccount().Do(newContext())
s.r().NoError(err)
s.r().Equal("0.01067982", account.TotalAmountInBTC)
s.r().Equal("77.13289230", account.TotalAmountInUSDT)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *simpleEarnServiceTestSuite) TestListFlexibleProduct() {
s.assertRequestEqual(e, r)
})

product, err := s.client.NewListSimpleEarnFlexibleProductService().Asset("BTC").Do(newContext())
product, err := s.client.NewSimpleEarnService().FlexibleService().ListProduct().Asset("BTC").Do(newContext())
s.r().NoError(err)
s.r().Equal("BTC001", product.Rows[0].ProductId)
s.r().Equal("BTC", product.Rows[0].Asset)
Expand All @@ -86,7 +86,7 @@ func (s *simpleEarnServiceTestSuite) TestListFlexibleProduct() {
s.r().Equal(true, product.Rows[0].IsSoldOut)
s.r().Equal(true, product.Rows[0].Hot)
s.r().Equal("0.01000000", product.Rows[0].MinPurchaseAmount)
s.r().Equal("1646182276000", product.Rows[0].SubscriptionStartTime)
s.r().EqualValues(1646182276000, product.Rows[0].SubscriptionStartTime)
s.r().Equal("PURCHASING", product.Rows[0].Status)
s.r().Equal(1, product.Total)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (s *simpleEarnServiceTestSuite) TestListLockedProduct() {
s.assertRequestEqual(e, r)
})

product, err := s.client.NewListSimpleEarnLockedProductService().Asset("AXS").Do(newContext())
product, err := s.client.NewSimpleEarnService().LockedService().ListProduct().Asset("AXS").Do(newContext())
s.r().NoError(err)
s.r().Equal("Axs*90", product.Rows[0].ProjectId)
s.r().Equal("AXS", product.Rows[0].Detail.Asset)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *simpleEarnServiceTestSuite) TestGetSimpleEarnFlexiblePositionService()
s.assertRequestEqual(e, r)
})

position, err := s.client.NewGetSimpleEarnFlexiblePositionService().Asset("USDT").Do(newContext())
position, err := s.client.NewSimpleEarnService().FlexibleService().GetPosition().Asset("USDT").Do(newContext())
s.r().NoError(err)
s.r().Equal("75.46000000", position.Rows[0].TotalAmount)
s.r().Equal(map[string]string{"0-5BTC": "0.05", "5-10BTC": "0.03"}, position.Rows[0].TierAnnualPercentageRate)
Expand Down Expand Up @@ -250,7 +250,7 @@ func (s *simpleEarnServiceTestSuite) TestGetSimpleEarnLockedPositionService() {
s.assertRequestEqual(e, r)
})

position, err := s.client.NewGetSimpleEarnLockedPositionService().
position, err := s.client.NewSimpleEarnService().LockedService().GetPosition().
Asset("AXS").
PositionId(123123).
ProjectId("Axs*90").
Expand Down Expand Up @@ -305,7 +305,7 @@ func (s *simpleEarnServiceTestSuite) TestGetSimpleEarnFlexibleQuotaService() {
s.assertRequestEqual(e, r)
})

quota, err := s.client.NewGetSimpleEarnFlexibleQuotaService().
quota, err := s.client.NewSimpleEarnService().FlexibleService().GetLeftQuote().
ProductId("BTC001").
Do(newContext())
s.r().NoError(err)
Expand All @@ -326,7 +326,7 @@ func (s *simpleEarnServiceTestSuite) TestGetSimpleEarnLockedQuotaService() {
s.assertRequestEqual(e, r)
})

quota, err := s.client.NewGetSimpleEarnLockedQuotaService().
quota, err := s.client.NewSimpleEarnService().LockedService().GetLeftQuote().
ProjectId("AXS001").
Do(newContext())
s.r().NoError(err)
Expand All @@ -351,7 +351,7 @@ func (s *simpleEarnServiceTestSuite) TestSubscribeFlexibleProduct() {
s.assertRequestEqual(e, r)
})

subscribeResp, err := s.client.NewSimpleEarnSubscribeFlexibleProductService().
subscribeResp, err := s.client.NewSimpleEarnService().FlexibleService().Subscribe().
ProductId("BTC001").
Amount("0.1").
AutoSubscribe(true).
Expand Down Expand Up @@ -382,7 +382,7 @@ func (s *simpleEarnServiceTestSuite) TestSubscribeLockedProduct() {
s.assertRequestEqual(e, r)
})

subscribeResp, err := s.client.NewSimpleEarnSubscribeLockedProductService().
subscribeResp, err := s.client.NewSimpleEarnService().LockedService().Subscribe().
ProjectId("AXS001").
Amount("0.1").
AutoSubscribe(true).
Expand Down Expand Up @@ -413,7 +413,7 @@ func (s *simpleEarnServiceTestSuite) TestRedeemFlexibleProduct() {
s.assertRequestEqual(e, r)
})

redeemResp, err := s.client.NewSimpleEarnRedeemFlexibleProductService().
redeemResp, err := s.client.NewSimpleEarnService().FlexibleService().Redeem().
ProductId("BTC001").
RedeemAll(true).
Amount("0.1").
Expand All @@ -439,7 +439,7 @@ func (s *simpleEarnServiceTestSuite) TestRedeemLockedProduct() {
s.assertRequestEqual(e, r)
})

redeemResp, err := s.client.NewSimpleEarnRedeemLockedProductService().
redeemResp, err := s.client.NewSimpleEarnService().LockedService().Redeem().
PositionId(12345).
Do(newContext())
s.r().NoError(err)
Expand All @@ -462,7 +462,7 @@ func (s *simpleEarnServiceTestSuite) TestSetAutoSubscribeFlexibleProduct() {
s.assertRequestEqual(e, r)
})

resp, err := s.client.NewSimpleEarnSetAutoSubscribeFlexibleProductService().
resp, err := s.client.NewSimpleEarnService().FlexibleService().SetAutoSubscribe().
ProductId("BTC001").
AutoSubscribe(true).
Do(newContext())
Expand All @@ -485,15 +485,15 @@ func (s *simpleEarnServiceTestSuite) TestSetAutoSubscribeLockedProduct() {
s.assertRequestEqual(e, r)
})

resp, err := s.client.NewSimpleEarnSetAutoSubscribeLockedProductService().
resp, err := s.client.NewSimpleEarnService().LockedService().SetAutoSubscribe().
PositionId(12345).
AutoSubscribe(true).
Do(newContext())
s.r().NoError(err)
s.r().Equal(true, resp.Success)
}

func (s *simpleEarnServiceTestSuite) TestSubscriptionPreview() {
func (s *simpleEarnServiceTestSuite) TestFlexiableSubscriptionPreview() {
data := []byte(`{
"totalAmount": "1232.32230982",
"rewardAsset": "BUSD",
Expand All @@ -513,7 +513,7 @@ func (s *simpleEarnServiceTestSuite) TestSubscriptionPreview() {
s.assertRequestEqual(e, r)
})

preview, err := s.client.NewSimpleEarnSubscriptionPreviewService().
preview, err := s.client.NewSimpleEarnService().FlexibleService().PreviewSubscribe().
ProductId("BTC001").
Amount("0.1").
Do(newContext())
Expand Down Expand Up @@ -553,7 +553,7 @@ func (s *simpleEarnServiceTestSuite) TestLockedSubscriptionPreview() {
s.assertRequestEqual(e, r)
})

preview, err := s.client.NewSimpleEarnLockedSubscriptionPreviewService().
preview, err := s.client.NewSimpleEarnService().LockedService().PreviewSubscribe().
ProjectId("AXS001").
Amount("0.1").
AutoSubscribe(true).
Expand All @@ -571,7 +571,7 @@ func (s *simpleEarnServiceTestSuite) TestLockedSubscriptionPreview() {
s.r().EqualValues(1651536000000, preview.NextSubscriptionDate)
}

func (s *simpleEarnServiceTestSuite) TestSetRedeemOption() {
func (s *simpleEarnServiceTestSuite) TestLockedSetRedeemOption() {
data := []byte(`{
"success": true
}`)
Expand All @@ -586,7 +586,7 @@ func (s *simpleEarnServiceTestSuite) TestSetRedeemOption() {
s.assertRequestEqual(e, r)
})

resp, err := s.client.NewSimpleEarnSetRedeemOptionService().
resp, err := s.client.NewSimpleEarnService().LockedService().SetRedeemOption().
PositionId("12345").
RedeemTo(RedeemToSpot).
Do(newContext())
Expand Down

0 comments on commit 6af0c8b

Please sign in to comment.