forked from caronwang/OKEX_V5SDK_GO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_test.go
100 lines (87 loc) · 2.73 KB
/
rest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package rest
import (
"context"
"fmt"
"testing"
)
/*
GET请求
*/
func TestRESTAPIGet(t *testing.T) {
rest := NewRESTAPI("https://www.okex.win", GET, "/api/v5/account/balance", nil)
rest.SetSimulate(true).SetAPIKey("xxxx", "xxxx", "xxxx")
rest.SetUserId("xxxxx")
response, err := rest.Run(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Response:")
fmt.Println("\thttp code: ", response.Code)
fmt.Println("\t总耗时: ", response.TotalUsedTime)
fmt.Println("\t请求耗时: ", response.ReqUsedTime)
fmt.Println("\t返回消息: ", response.Body)
fmt.Println("\terrCode: ", response.V5Response.Code)
fmt.Println("\terrMsg: ", response.V5Response.Msg)
fmt.Println("\tdata: ", response.V5Response.Data)
// 请求的另一种方式
apikey := APIKeyInfo{
ApiKey: "xxxxx",
SecKey: "xxxxx",
PassPhrase: "xxx",
}
cli := NewRESTClient("https://www.okex.win", &apikey, true)
rsp, err := cli.Get(context.Background(), "/api/v5/account/balance", nil)
if err != nil {
return
}
fmt.Println("Response:")
fmt.Println("\thttp code: ", rsp.Code)
fmt.Println("\t总耗时: ", rsp.TotalUsedTime)
fmt.Println("\t请求耗时: ", rsp.ReqUsedTime)
fmt.Println("\t返回消息: ", rsp.Body)
fmt.Println("\terrCode: ", rsp.V5Response.Code)
fmt.Println("\terrMsg: ", rsp.V5Response.Msg)
fmt.Println("\tdata: ", rsp.V5Response.Data)
}
/*
POST请求
*/
func TestRESTAPIPost(t *testing.T) {
param := make(map[string]interface{})
param["greeksType"] = "PA"
rest := NewRESTAPI("https://www.okex.win", POST, "/api/v5/account/set-greeks", ¶m)
rest.SetSimulate(true).SetAPIKey("xxxx", "xxxx", "xxxx")
response, err := rest.Run(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Response:")
fmt.Println("\thttp code: ", response.Code)
fmt.Println("\t总耗时: ", response.TotalUsedTime)
fmt.Println("\t请求耗时: ", response.ReqUsedTime)
fmt.Println("\t返回消息: ", response.Body)
fmt.Println("\terrCode: ", response.V5Response.Code)
fmt.Println("\terrMsg: ", response.V5Response.Msg)
fmt.Println("\tdata: ", response.V5Response.Data)
// 请求的另一种方式
apikey := APIKeyInfo{
ApiKey: "xxxx",
SecKey: "xxxxx",
PassPhrase: "xxxx",
}
cli := NewRESTClient("https://www.okex.win", &apikey, true)
rsp, err := cli.Post(context.Background(), "/api/v5/account/set-greeks", ¶m)
if err != nil {
return
}
fmt.Println("Response:")
fmt.Println("\thttp code: ", rsp.Code)
fmt.Println("\t总耗时: ", rsp.TotalUsedTime)
fmt.Println("\t请求耗时: ", rsp.ReqUsedTime)
fmt.Println("\t返回消息: ", rsp.Body)
fmt.Println("\terrCode: ", rsp.V5Response.Code)
fmt.Println("\terrMsg: ", rsp.V5Response.Msg)
fmt.Println("\tdata: ", rsp.V5Response.Data)
}