-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: v5 get internal transfer records (#117)
* feat: implement * test: integration * test: unit * docs: update
- Loading branch information
Showing
7 changed files
with
227 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,8 @@ | ||
BYBIT_TEST_UPDATED=false | ||
|
||
test: | ||
BYBIT_TEST_UPDATED=${BYBIT_TEST_UPDATED} BYBIT_TEST_KEY=${BYBIT_TEST_KEY} BYBIT_TEST_SECRET=${BYBIT_TEST_SECRET} go test github.com/hirokisan/bybit/v2/integrationtest/v5/asset -v -tags=integrationtestv5asset | ||
|
||
test-spec: | ||
BYBIT_TEST_UPDATED=${BYBIT_TEST_UPDATED} BYBIT_TEST_KEY=${BYBIT_TEST_KEY} BYBIT_TEST_SECRET=${BYBIT_TEST_SECRET} go test github.com/hirokisan/bybit/v2/integrationtest/v5/asset -v -tags=integrationtestv5asset -run ${BYBIT_TEST_METHOD} | ||
|
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,25 @@ | ||
//go:build integrationtestv5asset | ||
|
||
package integrationtestv5asset | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hirokisan/bybit/v2" | ||
"github.com/hirokisan/bybit/v2/integrationtest/testhelper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetInternalTransferRecords(t *testing.T) { | ||
client := bybit.NewTestClient().WithAuthFromEnv() | ||
limit := 1 | ||
res, err := client.V5().Asset().GetInternalTransferRecords(bybit.V5GetInternalTransferRecordsParam{ | ||
Limit: &limit, | ||
}) | ||
require.NoError(t, err) | ||
{ | ||
goldenFilename := "./testdata/v5-asset-get-internal-transfer-records.json" | ||
testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) | ||
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
integrationtest/v5/asset/testdata/v5-asset-get-internal-transfer-records.json
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,14 @@ | ||
{ | ||
"list": [ | ||
{ | ||
"transferId": "selfTransfer_5ce5b8d9-8477-4bc6-91a4-9a98dad6dc65", | ||
"coin": "BTC", | ||
"amount": "0.1", | ||
"fromAccountType": "SPOT", | ||
"toAccountType": "CONTRACT", | ||
"timestamp": "1637939106000", | ||
"status": "SUCCESS" | ||
} | ||
], | ||
"nextPageCursor": "eyJtaW5JRCI6MTYyMjgwLCJtYXhJRCI6MTYyMjgwfQ==" | ||
} |
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 |
---|---|---|
@@ -1,10 +1,66 @@ | ||
package bybit | ||
|
||
import "github.com/google/go-querystring/query" | ||
|
||
// V5AssetServiceI : | ||
type V5AssetServiceI interface { | ||
GetInternalTransferRecords(V5GetInternalTransferRecordsParam) (*V5GetInternalTransferRecordsResponse, error) | ||
} | ||
|
||
// V5AssetService : | ||
type V5AssetService struct { | ||
client *Client | ||
} | ||
|
||
// V5GetInternalTransferRecordsParam : | ||
type V5GetInternalTransferRecordsParam struct { | ||
TransferID *string `url:"transferId,omitempty"` | ||
Coin *Coin `url:"coin,omitempty"` | ||
Status *TransferStatusV5 `url:"status,omitempty"` | ||
StartTime *int64 `url:"startTime,omitempty"` // The start timestamp (ms) | ||
EndTime *int64 `url:"endTime,omitempty"` // The start timestamp (ms) | ||
Limit *int `url:"limit,omitempty"` // Limit for data size per page. [1, 50]. Default: 20 | ||
Cursor *string `url:"cursor,omitempty"` | ||
} | ||
|
||
// V5GetInternalTransferRecordsResponse : | ||
type V5GetInternalTransferRecordsResponse struct { | ||
CommonV5Response `json:",inline"` | ||
Result V5GetInternalTransferRecordsResult `json:"result"` | ||
} | ||
|
||
// V5GetInternalTransferRecordsResult : | ||
type V5GetInternalTransferRecordsResult struct { | ||
List V5GetInternalTransferRecordsList `json:"list"` | ||
NextPageCursor string `json:"nextPageCursor"` | ||
} | ||
|
||
// V5GetInternalTransferRecordsList : | ||
type V5GetInternalTransferRecordsList []V5GetInternalTransferRecordsItem | ||
|
||
// V5GetInternalTransferRecordsItem : | ||
type V5GetInternalTransferRecordsItem struct { | ||
TransferID string `json:"transferId"` | ||
Coin Coin `json:"coin"` | ||
Amount string `json:"amount"` | ||
FromAccountType AccountTypeV5 `json:"fromAccountType"` | ||
ToAccountType AccountTypeV5 `json:"toAccountType"` | ||
Timestamp string `json:"timestamp"` | ||
Status TransferStatusV5 `json:"status"` | ||
} | ||
|
||
// GetInternalTransferRecords : | ||
func (s *V5AssetService) GetInternalTransferRecords(param V5GetInternalTransferRecordsParam) (*V5GetInternalTransferRecordsResponse, error) { | ||
var res V5GetInternalTransferRecordsResponse | ||
|
||
queryString, err := query.Values(param) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := s.client.getV5Privately("/v5/asset/transfer/query-inter-transfer-list", queryString, &res); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &res, 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,90 @@ | ||
package bybit | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/hirokisan/bybit/v2/testhelper" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestV5Asset_GetInternalTransferRecords(t *testing.T) { | ||
t.Run("success", func(t *testing.T) { | ||
param := V5GetInternalTransferRecordsParam{} | ||
|
||
path := "/v5/asset/transfer/query-inter-transfer-list" | ||
method := http.MethodGet | ||
status := http.StatusOK | ||
respBody := map[string]interface{}{ | ||
"result": map[string]interface{}{ | ||
"list": []map[string]interface{}{ | ||
{ | ||
"transferId": "selfTransfer_5ce5b8d9-8477-4bc6-91a4-9a98dad6dc65", | ||
"coin": "BTC", | ||
"amount": "0.1", | ||
"fromAccountType": "SPOT", | ||
"toAccountType": "CONTRACT", | ||
"timestamp": "1637939106000", | ||
"status": "SUCCESS", | ||
}, | ||
}, | ||
"nextPageCursor": "eyJtaW5JRCI6MTYyMjgwLCJtYXhJRCI6MTYyMjgwfQ==", | ||
}, | ||
} | ||
bytesBody, err := json.Marshal(respBody) | ||
require.NoError(t, err) | ||
|
||
server, teardown := testhelper.NewServer( | ||
testhelper.WithHandlerOption(path, method, status, bytesBody), | ||
) | ||
defer teardown() | ||
|
||
client := NewTestClient(). | ||
WithBaseURL(server.URL). | ||
WithAuth("test", "test") | ||
|
||
resp, err := client.V5().Asset().GetInternalTransferRecords(param) | ||
require.NoError(t, err) | ||
|
||
require.NotNil(t, resp) | ||
testhelper.Compare(t, respBody["result"], resp.Result) | ||
}) | ||
t.Run("authentication required", func(t *testing.T) { | ||
param := V5GetInternalTransferRecordsParam{} | ||
|
||
path := "/v5/asset/transfer/query-inter-transfer-list" | ||
method := http.MethodGet | ||
status := http.StatusOK | ||
respBody := map[string]interface{}{ | ||
"result": map[string]interface{}{ | ||
"list": []map[string]interface{}{ | ||
{ | ||
"transferId": "selfTransfer_5ce5b8d9-8477-4bc6-91a4-9a98dad6dc65", | ||
"coin": "BTC", | ||
"amount": "0.1", | ||
"fromAccountType": "SPOT", | ||
"toAccountType": "CONTRACT", | ||
"timestamp": "1637939106000", | ||
"status": "SUCCESS", | ||
}, | ||
}, | ||
"nextPageCursor": "eyJtaW5JRCI6MTYyMjgwLCJtYXhJRCI6MTYyMjgwfQ==", | ||
}, | ||
} | ||
bytesBody, err := json.Marshal(respBody) | ||
require.NoError(t, err) | ||
|
||
server, teardown := testhelper.NewServer( | ||
testhelper.WithHandlerOption(path, method, status, bytesBody), | ||
) | ||
defer teardown() | ||
|
||
client := NewTestClient(). | ||
WithBaseURL(server.URL) | ||
|
||
_, err = client.V5().Asset().GetInternalTransferRecords(param) | ||
assert.Error(t, err) | ||
}) | ||
} |
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