Skip to content

Commit 78765b2

Browse files
authored
Merge pull request #19 from wuhewuhe/master
fix users endpoints and add examples
2 parents 212c7d2 + 3f46595 commit 78765b2

File tree

6 files changed

+71
-11
lines changed

6 files changed

+71
-11
lines changed

bybit_api_client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ func (c *Client) NewUserService(params map[string]interface{}) *UserServiceClien
288288
}
289289
}
290290

291+
func (c *Client) NewUserServiceNoParams() *UserServiceClient {
292+
return &UserServiceClient{
293+
c: c,
294+
}
295+
}
296+
291297
func (c *Client) NewBrokerService(params map[string]interface{}) *BrokerServiceClient {
292298
return &BrokerServiceClient{
293299
c: c,

examples/Trade/place_trade.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ func main() {
1212

1313
func PlaceTrade() {
1414
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
15-
params := map[string]interface{}{"category": "linear", "symbol": "BTCUSDT", "side": "Buy", "positionIdx": 0, "orderType": "Limit", "qty": "0.001", "price": "10000", "timeInForce": "GTC"}
15+
params := map[string]interface{}{
16+
"category": "linear",
17+
"symbol": "BTCUSDT",
18+
"side": "Buy",
19+
"positionIdx": 0,
20+
"orderType": "Limit",
21+
"qty": "0.001",
22+
"price": "10000",
23+
"timeInForce": "GTC",
24+
}
1625
orderResult, err := client.NewTradeService(params).PlaceOrder(context.Background())
1726
if err != nil {
1827
fmt.Println(err)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
bybit "github.com/wuhewuhe/bybit.go.api"
7+
)
8+
9+
func main() {
10+
CreateSubApiKey()
11+
}
12+
13+
func CreateSubApiKey() {
14+
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
15+
params := map[string]interface{}{"subuid": "100366706", "readOnly": 0,
16+
"permissions": []map[string]interface{}{
17+
{
18+
"Wallet": []string{"AccountTransfer", "SubMemberTransferList"},
19+
},
20+
},
21+
}
22+
userResult, err := client.NewUserService(params).CreateSubApiKey(context.Background())
23+
if err != nil {
24+
fmt.Println(err)
25+
return
26+
}
27+
fmt.Println(bybit.PrettyPrint(userResult))
28+
}

examples/user/create_sub_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
)
88

99
func main() {
10-
PlaceTrade()
10+
CreateNewSubUser()
1111
}
1212

13-
func PlaceTrade() {
13+
func CreateNewSubUser() {
1414
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
1515
params := map[string]interface{}{"username": "06112023Victor", "memberType": 1}
1616
userResult, err := client.NewUserService(params).CreateSubMember(context.Background())

examples/user/get_api_key_info.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
bybit "github.com/wuhewuhe/bybit.go.api"
7+
)
8+
9+
func main() {
10+
GetApiKeyInfo()
11+
}
12+
13+
func GetApiKeyInfo() {
14+
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
15+
userResult, err := client.NewUserServiceNoParams().GetAPIKeyInfo(context.Background())
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
fmt.Println(bybit.PrettyPrint(userResult))
21+
}

user.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (s *UserServiceClient) GetSubUidList(ctx context.Context, opts ...RequestOp
193193
return nil, err
194194
}
195195
r := &request{
196-
method: http.MethodPost,
196+
method: http.MethodGet,
197197
endpoint: "/v5/user/query-sub-members",
198198
secType: secTypeSigned,
199199
}
@@ -211,15 +211,11 @@ func (s *UserServiceClient) GetSubUidList(ctx context.Context, opts ...RequestOp
211211
}
212212

213213
func (s *UserServiceClient) GetAPIKeyInfo(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
214-
if err = handlers.ValidateParams(s.params); err != nil {
215-
return nil, err
216-
}
217214
r := &request{
218-
method: http.MethodPost,
215+
method: http.MethodGet,
219216
endpoint: "/v5/user/query-api",
220217
secType: secTypeSigned,
221218
}
222-
r.setParams(s.params)
223219
data, err := s.c.callAPI(ctx, r, opts...)
224220
if err != nil {
225221
return nil, err
@@ -237,7 +233,7 @@ func (s *UserServiceClient) GetUidWalletType(ctx context.Context, opts ...Reques
237233
return nil, err
238234
}
239235
r := &request{
240-
method: http.MethodPost,
236+
method: http.MethodGet,
241237
endpoint: "/v5/user/get-member-type",
242238
secType: secTypeSigned,
243239
}
@@ -259,7 +255,7 @@ func (s *UserServiceClient) GetAffiliateUserInfo(ctx context.Context, opts ...Re
259255
return nil, err
260256
}
261257
r := &request{
262-
method: http.MethodPost,
258+
method: http.MethodGet,
263259
endpoint: "/v5/user/aff-customer-info",
264260
secType: secTypeSigned,
265261
}

0 commit comments

Comments
 (0)