Merge pull request #29 from wuhewuhe/VictorWuBranche

fix asset endpoints
This commit is contained in:
CommaHunger 2024-02-22 18:21:00 +01:00 committed by GitHub
commit 8a4f616e98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 195 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package bybit_connector
import (
"context"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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

View File

@ -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)
}

View File

@ -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"

View File

@ -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))
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func 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))
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
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))
}

View File

@ -0,0 +1,51 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceBatchTrade()
}
func PlaceBatchTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "option",
"request": []map[string]interface{}{
{
"category": "option",
"symbol": "BTC-10FEB23-24000-C",
"orderType": "Limit",
"side": "Buy",
"qty": "0.1",
"price": "5",
"orderIv": "0.1",
"timeInForce": "GTC",
"orderLinkId": "9b381bb1-401",
"mmp": false,
"reduceOnly": false,
},
{
"category": "option",
"symbol": "BTC-10FEB23-24000-C",
"orderType": "Limit",
"side": "Buy",
"qty": "0.1",
"price": "5",
"orderIv": "0.1",
"timeInForce": "GTC",
"orderLinkId": "82ee86dd-001",
"mmp": false,
"reduceOnly": false,
},
},
}
orderResult, err := client.NewTradeService(params).PlaceBatchOrder(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

View File

@ -0,0 +1,21 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceOrder()
}
func PlaceOrder() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
orderResult, err := client.NewPlaceOrderService("linear", "XRPUSDT", "Buy", "Market", "10").Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

2
go.mod
View File

@ -12,7 +12,7 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect

2
go.sum
View File

@ -12,6 +12,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@ -412,7 +412,7 @@ func (s *marketTestSuite) TestInstrumentsInfo() {
category := models.CategoryInverse
symbol := "BTCUSD"
status := models.SymbolStatusTrading
baseÇoin := "BTC"
baseCoin := "BTC"
limit := 10
cursor := "cursor"
s.assertReq(func(r *request) {
@ -422,7 +422,7 @@ func (s *marketTestSuite) TestInstrumentsInfo() {
"category": category,
"symbol": symbol,
"status": status,
"baseCoin": baseÇoin,
"baseCoin": baseCoin,
"limit": limit,
"cursor": cursor,
})
@ -431,7 +431,7 @@ func (s *marketTestSuite) TestInstrumentsInfo() {
res, err := s.client.NewInstrumentsInfoService().
Category(category).Symbol(symbol).Status(status).
BaseCoin(baseÇoin).Limit(limit).Cursor(cursor).
BaseCoin(baseCoin).Limit(limit).Cursor(cursor).
Do(newContext())
e1 := &models.InstrumentInfoResponse{