-
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 branch 'master' into feat/wss-futures-client
- Loading branch information
Showing
8 changed files
with
763 additions
and
130 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,37 @@ | ||
package delivery | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type GetFundingInfoService struct { | ||
c *Client | ||
} | ||
|
||
type FundingInfo struct { | ||
Symbol string `json:"symbol"` | ||
AdjustedFundingRateCap string `json:"adjustedFundingRateCap"` | ||
AdjustedFundingRateFloor string `json:"adjustedFundingRateFloor"` | ||
FundingIntervalHours int `json:"fundingIntervalHours"` | ||
Disclaimer bool `json:"disclaimer"` | ||
} | ||
|
||
func (s *GetFundingInfoService) Do(ctx context.Context, opts ...RequestOption) (fundingInfo []*FundingInfo, err error) { | ||
r := &request{ | ||
method: http.MethodGet, | ||
endpoint: "/dapi/v1/fundingInfo", | ||
secType: secTypeNone, | ||
} | ||
data, err := s.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fundingInfo = make([]*FundingInfo, 0) | ||
err = json.Unmarshal(data, &fundingInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return fundingInfo, nil | ||
} |
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 delivery | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type fundingInfoServiceTestSuite struct { | ||
baseTestSuite | ||
} | ||
|
||
func TestFundingInfoService(t *testing.T) { | ||
suite.Run(t, new(fundingInfoServiceTestSuite)) | ||
} | ||
|
||
func (s *fundingInfoServiceTestSuite) TestGetFundingInfo() { | ||
data := []byte(`[ | ||
{ | ||
"symbol": "BLZUSDT", | ||
"adjustedFundingRateCap": "0.3", | ||
"adjustedFundingRateFloor": "-0.3", | ||
"fundingIntervalHours": 8, | ||
"disclaimer": true | ||
} | ||
]`) | ||
s.mockDo(data, nil) | ||
defer s.assertDo() | ||
|
||
s.assertReq(func(r *request) { | ||
e := newRequest().setParams(params{}) | ||
s.assertRequestEqual(e, r) | ||
}) | ||
|
||
fundingInfo, err := s.client.NewGetFundingInfoService().Do(newContext()) | ||
s.r().NoError(err) | ||
s.Len(fundingInfo, 1) | ||
e := &FundingInfo{ | ||
Symbol: "BLZUSDT", | ||
AdjustedFundingRateCap: "0.3", | ||
AdjustedFundingRateFloor: "-0.3", | ||
FundingIntervalHours: 8, | ||
Disclaimer: true, | ||
} | ||
s.assertFundingInfoEqual(e, fundingInfo[0]) | ||
} | ||
|
||
func (s *fundingInfoServiceTestSuite) assertFundingInfoEqual(e, a *FundingInfo) { | ||
r := s.r() | ||
r.Equal(e.Symbol, a.Symbol, "Symbol") | ||
r.Equal(e.AdjustedFundingRateCap, a.AdjustedFundingRateCap, "AdjustedFundingRateCap") | ||
r.Equal(e.AdjustedFundingRateFloor, a.AdjustedFundingRateFloor, "AdjustedFundingRateFloor") | ||
r.Equal(e.FundingIntervalHours, a.FundingIntervalHours, "FundingIntervalHours") | ||
r.Equal(e.Disclaimer, a.Disclaimer, "Disclaimer") | ||
} |
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,238 @@ | ||
package futures | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type ListConvertExchangeInfoService struct { | ||
c *Client | ||
fromAsset string | ||
toAsset string | ||
} | ||
|
||
type ConvertExchangeInfo struct { | ||
FromAsset string `json:"fromAsset"` | ||
ToAsset string `json:"toAsset"` | ||
FromAssetMinAmount string `json:"fromAssetMinAmount"` | ||
FromAssetMaxAmount string `json:"fromAssetMaxAmount"` | ||
ToAssetMinAmount string `json:"toAssetMinAmount"` | ||
ToAssetMaxAmount string `json:"toAssetMaxAmount"` | ||
} | ||
|
||
func (l *ListConvertExchangeInfoService) FromAsset(fromAsset string) *ListConvertExchangeInfoService { | ||
l.fromAsset = fromAsset | ||
return l | ||
} | ||
|
||
func (l *ListConvertExchangeInfoService) ToAsset(toAsset string) *ListConvertExchangeInfoService { | ||
l.toAsset = toAsset | ||
return l | ||
} | ||
|
||
func (l *ListConvertExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res []ConvertExchangeInfo, err error) { | ||
r := &request{ | ||
method: http.MethodGet, | ||
endpoint: "/fapi/v1/convert/exchangeInfo", | ||
secType: secTypeNone, | ||
} | ||
if l.fromAsset != "" { | ||
r.setParam("fromAsset", l.fromAsset) | ||
} | ||
if l.toAsset != "" { | ||
r.setParam("toAsset", l.toAsset) | ||
} | ||
|
||
data, _, err := l.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = make([]ConvertExchangeInfo, 0, 50) | ||
if err := json.Unmarshal(data, &res); err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
type ConvertValidTime string | ||
|
||
const ( | ||
ConvertValidTime10S ConvertValidTime = "10s" | ||
ConvertValidTime30S ConvertValidTime = "30s" | ||
ConvertValidTime1M ConvertValidTime = "1m" | ||
ConvertValidTime2M ConvertValidTime = "2m" | ||
) | ||
|
||
type CreateConvertQuoteService struct { | ||
c *Client | ||
fromAsset string | ||
toAsset string | ||
fromAmount string | ||
toAmount string | ||
validTime ConvertValidTime | ||
} | ||
|
||
func (c *CreateConvertQuoteService) FromAsset(fromAsset string) *CreateConvertQuoteService { | ||
c.fromAsset = fromAsset | ||
return c | ||
} | ||
|
||
func (c *CreateConvertQuoteService) ToAsset(toAsset string) *CreateConvertQuoteService { | ||
c.toAsset = toAsset | ||
return c | ||
} | ||
|
||
func (c *CreateConvertQuoteService) FromAmount(fromAmount string) *CreateConvertQuoteService { | ||
c.fromAmount = fromAmount | ||
return c | ||
} | ||
|
||
func (c *CreateConvertQuoteService) ToAmount(toAmount string) *CreateConvertQuoteService { | ||
c.toAmount = toAmount | ||
return c | ||
} | ||
|
||
func (c *CreateConvertQuoteService) ValidTime(validTime ConvertValidTime) *CreateConvertQuoteService { | ||
c.validTime = validTime | ||
return c | ||
} | ||
|
||
type ConvertQuote struct { | ||
QuoteId string `json:"quoteId"` | ||
Ratio string `json:"ratio"` | ||
InverseRatio string `json:"inverseRatio"` | ||
ValidTimestamp int64 `json:"validTimestamp"` | ||
ToAmount string `json:"toAmount"` | ||
FromAmount string `json:"fromAmount"` | ||
} | ||
|
||
func (c *CreateConvertQuoteService) Do(ctx context.Context, opts ...RequestOption) (res *ConvertQuote, err error) { | ||
r := &request{ | ||
method: http.MethodPost, | ||
endpoint: "/fapi/v1/convert/getQuote", | ||
secType: secTypeSigned, | ||
} | ||
m := params{ | ||
"fromAsset": c.fromAsset, | ||
"toAsset": c.toAsset, | ||
} | ||
if c.fromAmount != "" { | ||
m["fromAmount"] = c.fromAmount | ||
} | ||
if c.toAmount != "" { | ||
m["toAmount"] = c.toAmount | ||
} | ||
if c.validTime != "" { | ||
m["validTime"] = c.validTime | ||
} | ||
r.setFormParams(m) | ||
data, _, err := c.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = new(ConvertQuote) | ||
if err := json.Unmarshal(data, res); err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
type ConvertAcceptService struct { | ||
c *Client | ||
quoteId string | ||
} | ||
|
||
func (c *ConvertAcceptService) QuoteId(quoteId string) *ConvertAcceptService { | ||
c.quoteId = quoteId | ||
return c | ||
} | ||
|
||
type ConvertAcceptStatus string | ||
|
||
const ( | ||
ConvertAcceptStatusProcess ConvertAcceptStatus = "PROCESS" | ||
ConvertAcceptStatusAcceptSuccess ConvertAcceptStatus = "ACCEPT_SUCCESS" | ||
ConvertAcceptStatusSuccess ConvertAcceptStatus = "SUCCESS" | ||
ConvertAcceptStatusFailed ConvertAcceptStatus = "FAILED" | ||
) | ||
|
||
type ConvertResult struct { | ||
OrderId string `json:"orderId"` | ||
CreateTime int64 `json:"createTime"` | ||
OrderStatus ConvertAcceptStatus `json:"orderStatus"` | ||
} | ||
|
||
func (c *ConvertAcceptService) Do(ctx context.Context, opts ...RequestOption) (res *ConvertResult, err error) { | ||
r := &request{ | ||
method: http.MethodPost, | ||
endpoint: "/fapi/v1/convert/acceptQuote", | ||
secType: secTypeSigned, | ||
} | ||
m := params{ | ||
"quoteId": c.quoteId, | ||
} | ||
r.setFormParams(m) | ||
data, _, err := c.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = new(ConvertResult) | ||
if err := json.Unmarshal(data, res); err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
type ConvertStatusService struct { | ||
c *Client | ||
quoteId string | ||
orderId string | ||
} | ||
|
||
func (c *ConvertStatusService) QuoteId(quoteId string) *ConvertStatusService { | ||
c.quoteId = quoteId | ||
return c | ||
} | ||
|
||
func (c *ConvertStatusService) OrderId(orderId string) *ConvertStatusService { | ||
c.orderId = orderId | ||
return c | ||
} | ||
|
||
type ConvertStatusResult struct { | ||
OrderId string `json:"orderId"` | ||
OrderStatus ConvertAcceptStatus `json:"orderStatus"` | ||
FromAsset string `json:"fromAsset"` | ||
FromAmount string `json:"fromAmount"` | ||
ToAsset string `json:"toAsset"` | ||
ToAmount string `json:"toAmount"` | ||
Ratio string `json:"ratio"` | ||
InverseRatio string `json:"inverseRatio"` | ||
CreateTime int64 `json:"createTime"` | ||
} | ||
|
||
func (c *ConvertStatusService) Do(ctx context.Context, opts ...RequestOption) (res *ConvertStatusResult, err error) { | ||
r := &request{ | ||
method: http.MethodGet, | ||
endpoint: "/fapi/v1/convert/orderStatus", | ||
secType: secTypeSigned, | ||
} | ||
m := params{ | ||
"quoteId": c.quoteId, | ||
} | ||
if c.orderId != "" { | ||
m["orderId"] = c.orderId | ||
} | ||
r.setParam("quoteId", c.quoteId) | ||
r.setFormParams(m) | ||
data, _, err := c.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = new(ConvertStatusResult) | ||
if err := json.Unmarshal(data, res); err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} |
Oops, something went wrong.