Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing services and properties (#338)
* Added rebate service * Added missing fields in asset dividende record response. * Added convert trade service * Fix asset dividend service tests * Added missing property 'OrigQuoteOrderQuantity' in Order * Added missing property 'OrderListId' in Trade * Added missing property 'UnlockConfirm' in Deposit * Added missing property 'ConfirmNo' in Withdraw * Fixed unit test for Go 1.13
- Loading branch information
Showing
16 changed files
with
462 additions
and
48 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
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
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,78 @@ | ||
package binance | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type ConvertTradeHistoryService struct { | ||
c *Client | ||
startTime int64 | ||
endTime int64 | ||
limit *int32 | ||
} | ||
|
||
// StartTime set startTime | ||
func (s *ConvertTradeHistoryService) StartTime(startTime int64) *ConvertTradeHistoryService { | ||
s.startTime = startTime | ||
return s | ||
} | ||
|
||
// EndTime set endTime | ||
func (s *ConvertTradeHistoryService) EndTime(endTime int64) *ConvertTradeHistoryService { | ||
s.endTime = endTime | ||
return s | ||
} | ||
|
||
// Limit set limit | ||
func (s *ConvertTradeHistoryService) Limit(limit int32) *ConvertTradeHistoryService { | ||
s.limit = &limit | ||
return s | ||
} | ||
|
||
// Do send request | ||
func (s *ConvertTradeHistoryService) Do(ctx context.Context, opts ...RequestOption) (*ConvertTradeHistory, error) { | ||
r := &request{ | ||
method: http.MethodGet, | ||
endpoint: "/sapi/v1/convert/tradeFlow", | ||
secType: secTypeSigned, | ||
} | ||
r.setParam("startTime", s.startTime) | ||
r.setParam("endTime", s.endTime) | ||
if s.limit != nil { | ||
r.setParam("limit", *s.limit) | ||
} | ||
data, err := s.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := ConvertTradeHistory{} | ||
if err = json.Unmarshal(data, &res); err != nil { | ||
return nil, err | ||
} | ||
return &res, nil | ||
} | ||
|
||
// ConvertTradeHistory define the convert trade history | ||
type ConvertTradeHistory struct { | ||
List []ConvertTradeHistoryItem `json:"list"` | ||
StartTime int64 `json:"startTime"` | ||
EndTime int64 `json:"endTime"` | ||
Limit int32 `json:"limit"` | ||
MoreData bool `json:"moreData"` | ||
} | ||
|
||
// ConvertTradeHistoryItem define a convert trade history item | ||
type ConvertTradeHistoryItem struct { | ||
QuoteId string `json:"quoteId"` | ||
OrderId int64 `json:"orderId"` | ||
OrderStatus string `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"` | ||
} |
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,105 @@ | ||
package binance | ||
|
||
import ( | ||
"github.com/stretchr/testify/suite" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type convertTradeTestSuite struct { | ||
baseTestSuite | ||
} | ||
|
||
func TestConvertTradeService(t *testing.T) { | ||
suite.Run(t, new(convertTradeTestSuite)) | ||
} | ||
|
||
func (s *convertTradeTestSuite) TestConvertTradeHistory() { | ||
data := []byte(`{ | ||
"list": [ | ||
{ | ||
"quoteId": "f3b91c525b2644c7bc1e1cd31b6e1aa6", | ||
"orderId": 940708407462087195, | ||
"orderStatus": "SUCCESS", | ||
"fromAsset": "USDT", | ||
"fromAmount": "20", | ||
"toAsset": "BNB", | ||
"toAmount": "0.06154036", | ||
"ratio": "0.00307702", | ||
"inverseRatio": "324.99", | ||
"createTime": 1624248872184 | ||
} | ||
], | ||
"startTime": 1623824139000, | ||
"endTime": 1626416139000, | ||
"limit": 100, | ||
"moreData": false | ||
}`) | ||
s.mockDo(data, nil) | ||
defer s.assertDo() | ||
|
||
startTime := time.Now().AddDate(0, 0, -7).Unix() * 1000 | ||
endTime := time.Now().Unix() * 1000 | ||
s.assertReq(func(r *request) { | ||
e := newSignedRequest().setParams(params{ | ||
"startTime": startTime, | ||
"endTime": endTime, | ||
}) | ||
s.assertRequestEqual(e, r) | ||
}) | ||
|
||
res, err := s.client.NewConvertTradeHistoryService(). | ||
StartTime(startTime). | ||
EndTime(endTime). | ||
Do(newContext()) | ||
s.r().NoError(err) | ||
e := &ConvertTradeHistory{ | ||
List: []ConvertTradeHistoryItem{ | ||
{ | ||
QuoteId: "f3b91c525b2644c7bc1e1cd31b6e1aa6", | ||
OrderId: 940708407462087195, | ||
OrderStatus: "SUCCESS", | ||
FromAsset: "USDT", | ||
FromAmount: "20", | ||
ToAsset: "BNB", | ||
ToAmount: "0.06154036", | ||
Ratio: "0.00307702", | ||
InverseRatio: "324.99", | ||
CreateTime: 1624248872184, | ||
}, | ||
}, | ||
StartTime: 1623824139000, | ||
EndTime: 1626416139000, | ||
Limit: 100, | ||
MoreData: false, | ||
} | ||
s.assertConvertTradeHistoryEqual(e, res) | ||
} | ||
|
||
func (s *convertTradeTestSuite) assertConvertTradeHistoryEqual(e, a *ConvertTradeHistory) { | ||
r := s.r() | ||
|
||
r.Len(a.List, len(e.List)) | ||
for i := 0; i < len(a.List); i++ { | ||
s.assertConvertTradeHistoryItemEqual(&e.List[i], &a.List[i]) | ||
} | ||
|
||
r.Equal(e.StartTime, a.StartTime, "StartTime") | ||
r.Equal(e.EndTime, a.EndTime, "EndTime") | ||
r.Equal(e.Limit, a.Limit, "Limit") | ||
r.Equal(e.MoreData, a.MoreData, "MoreData") | ||
} | ||
|
||
func (s *convertTradeTestSuite) assertConvertTradeHistoryItemEqual(e, a *ConvertTradeHistoryItem) { | ||
r := s.r() | ||
r.Equal(e.QuoteId, a.QuoteId, "QuoteId") | ||
r.Equal(e.OrderId, a.OrderId, "OrderId") | ||
r.Equal(e.OrderStatus, a.OrderStatus, "OrderStatus") | ||
r.Equal(e.FromAsset, a.FromAsset, "FromAsset") | ||
r.Equal(e.FromAmount, a.FromAmount, "FromAmount") | ||
r.Equal(e.ToAsset, a.ToAsset, "ToAsset") | ||
r.Equal(e.ToAmount, a.ToAmount, "ToAmount") | ||
r.Equal(e.Ratio, a.Ratio, "Ratio") | ||
r.Equal(e.InverseRatio, a.InverseRatio, "InverseRatio") | ||
r.Equal(e.CreateTime, a.CreateTime, "CreateTime") | ||
} |
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
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
Oops, something went wrong.