Skip to content

Commit

Permalink
fix asset endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorFrWu committed Feb 22, 2024
1 parent 2cef19a commit 6052079
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 6 deletions.
49 changes: 49 additions & 0 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bybit_connector

import (
"context"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

Expand All @@ -16,6 +17,7 @@ func (s *AssetClient) GetAssetOrderRecord(ctx context.Context, opts ...RequestOp
endpoint: "/v5/asset/exchange/order-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -34,6 +36,7 @@ func (s *AssetClient) GetAssetInfo(ctx context.Context, opts ...RequestOption) (
endpoint: "/v5/asset/transfer/query-asset-info",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -52,6 +55,7 @@ func (s *AssetClient) GetDeliveryRecord(ctx context.Context, opts ...RequestOpti
endpoint: "/v5/asset/delivery-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -70,6 +74,7 @@ func (s *AssetClient) GetUsdcSettlement(ctx context.Context, opts ...RequestOpti
endpoint: "/v5/asset/settlement-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -88,6 +93,7 @@ func (s *AssetClient) GetAllCoinsBalance(ctx context.Context, opts ...RequestOpt
endpoint: "/v5/asset/transfer/query-account-coins-balance",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -101,11 +107,15 @@ func (s *AssetClient) GetAllCoinsBalance(ctx context.Context, opts ...RequestOpt
}

func (s *AssetClient) GetSingleCoinsBalance(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-account-coin-balance",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -119,11 +129,15 @@ func (s *AssetClient) GetSingleCoinsBalance(ctx context.Context, opts ...Request
}

func (s *AssetClient) GetTransferableCoin(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-transfer-coin-list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -137,11 +151,15 @@ func (s *AssetClient) GetTransferableCoin(ctx context.Context, opts ...RequestOp
}

func (s *AssetClient) CreateInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/transfer/inter-transfer",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -155,11 +173,15 @@ func (s *AssetClient) CreateInternalTransfer(ctx context.Context, opts ...Reques
}

func (s *AssetClient) CreateUniversalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/transfer/universal-transfer",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -173,11 +195,15 @@ func (s *AssetClient) CreateUniversalTransfer(ctx context.Context, opts ...Reque
}

func (s *AssetClient) SetDepositAccount(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/deposit/deposit-to-account",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -191,11 +217,15 @@ func (s *AssetClient) SetDepositAccount(ctx context.Context, opts ...RequestOpti
}

func (s *AssetClient) WithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/withdraw/create",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -209,11 +239,15 @@ func (s *AssetClient) WithdrawAsset(ctx context.Context, opts ...RequestOption)
}

func (s *AssetClient) CancelWithdrawAsset(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodPost,
endpoint: "/v5/asset/withdraw/cancel",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -227,11 +261,15 @@ func (s *AssetClient) CancelWithdrawAsset(ctx context.Context, opts ...RequestOp
}

func (s *AssetClient) GetInternalTransfer(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/asset/transfer/query-inter-transfer-list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -250,6 +288,7 @@ func (s *AssetClient) GetUniversalTransfer(ctx context.Context, opts ...RequestO
endpoint: "/v5/asset/transfer/query-universal-transfer-list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -268,6 +307,7 @@ func (s *AssetClient) GetSubUids(ctx context.Context, opts ...RequestOption) (re
endpoint: "/v5/asset/transfer/query-sub-member-list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -286,6 +326,7 @@ func (s *AssetClient) GetAllowedDepositCoin(ctx context.Context, opts ...Request
endpoint: "/v5/asset/deposit/query-allowed-list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -304,6 +345,7 @@ func (s *AssetClient) GetDepositRecords(ctx context.Context, opts ...RequestOpti
endpoint: "/v5/asset/deposit/query-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -322,6 +364,7 @@ func (s *AssetClient) GetSubDepositRecords(ctx context.Context, opts ...RequestO
endpoint: "/v5/asset/deposit/query-sub-member-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -340,6 +383,7 @@ func (s *AssetClient) GetInternalDepositRecords(ctx context.Context, opts ...Req
endpoint: "/v5/asset/deposit/query-internal-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -358,6 +402,7 @@ func (s *AssetClient) GetMasterDepositAddress(ctx context.Context, opts ...Reque
endpoint: "/v5/asset/deposit/query-address",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -376,6 +421,7 @@ func (s *AssetClient) GetSubDepositAddress(ctx context.Context, opts ...RequestO
endpoint: "/v5/asset/deposit/query-sub-member-address",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -394,6 +440,7 @@ func (s *AssetClient) GetCoinInfo(ctx context.Context, opts ...RequestOption) (r
endpoint: "/v5/asset/coin/query-info",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -412,6 +459,7 @@ func (s *AssetClient) GetWithdrawalAmount(ctx context.Context, opts ...RequestOp
endpoint: "/v5/asset/withdraw/withdrawable-amount",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -429,6 +477,7 @@ func (s *AssetClient) GetWithdrawalRecords(ctx context.Context, opts ...RequestO
endpoint: "/v5/asset/withdraw/query-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion bybit_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func WithBaseURL(baseURL string) ClientOption {
}

func PrettyPrint(i interface{}) string {
s, _ := json.MarshalIndent(i, "", "\t")
s, _ := json.MarshalIndent(i, "", " ")
return string(s)
}

Expand Down
2 changes: 1 addition & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bybit_connector

const (
Name = "bybit.api.go"
Version = "1.0.1"
Version = "1.0.2"
// Https
MAINNET = "https://api.bybit.com"
MAINNET_BACKT = "https://api.bytick.com"
Expand Down
22 changes: 22 additions & 0 deletions examples/Account/get_transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)

func main() {
PlaceTrade()
}

func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"accountType": "UNIFIED", "category": "linear"}
accountResult, err := client.NewAccountService(params).GetTransactionLog(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(accountResult))
}
22 changes: 22 additions & 0 deletions examples/Asset/get_coin_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)

func main() {

Check failure on line 9 in examples/Asset/get_coin_info.go

View workflow job for this annotation

GitHub Actions / build

other declaration of main
GetCoinInfo()
}

func GetCoinInfo() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"coin": "USDT"}
assetResult, err := client.NewAssetService(params).GetCoinInfo(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(assetResult))
}
22 changes: 22 additions & 0 deletions examples/Asset/get_transfer_coin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)

func main() {

Check failure on line 9 in examples/Asset/get_transfer_coin.go

View workflow job for this annotation

GitHub Actions / build

main redeclared in this block
PlaceOrder()
}

func PlaceOrder() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"fromAccountType": "UNIFIED", "toAccountType": "CONTRACT"}
response, err := client.NewAssetService(params).GetTransferableCoin(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(response))
}
Loading

0 comments on commit 6052079

Please sign in to comment.