-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathclient_test.go
More file actions
168 lines (148 loc) · 3.92 KB
/
client_test.go
File metadata and controls
168 lines (148 loc) · 3.92 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package gotdx
import (
"fmt"
"github.com/bensema/gotdx/proto"
"os"
"testing"
)
func newClient() *Client {
tdx := New(WithTCPAddress("124.71.187.122:7709"))
reply, err := tdx.Connect()
if err != nil {
fmt.Println(err)
}
fmt.Println(reply.Info)
return tdx
}
func requireIntegration(t *testing.T) {
t.Helper()
if os.Getenv("GOTDX_INTEGRATION") != "1" {
t.Skip("set GOTDX_INTEGRATION=1 to run integration tests")
}
}
func Test_tdx_Connect(t *testing.T) {
requireIntegration(t)
fmt.Println("================ Connect ================")
tdx := New(WithTCPAddress("124.71.187.122:7709"))
defer tdx.Disconnect()
reply, err := tdx.Connect()
if err != nil {
t.Errorf("error:%s", err)
}
fmt.Println(reply.Info)
}
func Test_tdx_GetSecurityCount(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetSecurityCount ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetSecurityCount(MarketSH)
if err != nil {
t.Errorf("error:%s", err)
}
fmt.Println(reply.Count)
}
func Test_tdx_GetSecurityQuotes(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetSecurityQuotes ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetSecurityQuotes([]uint8{MarketSZ}, []string{"002062"})
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetSecurityList(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetSecurityList ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetSecurityList(MarketSH, 0)
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetSecurityBars(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetSecurityBars ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetSecurityBars(proto.KLINE_TYPE_RI_K, MarketSZ, "000001", 0, 10)
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetIndexBars(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetIndexBars ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetIndexBars(proto.KLINE_TYPE_RI_K, MarketSH, "000001", 0, 10)
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetMinuteTimeData(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetMinuteTimeData ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetMinuteTimeData(MarketSZ, "159607")
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetHistoryMinuteTimeData(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetHistoryMinuteTimeData ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetHistoryMinuteTimeData(20220511, MarketSZ, "159607")
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetTransactionData(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetTransactionData ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetTransactionData(MarketSZ, "159607", 0, 10)
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}
func Test_tdx_GetHistoryTransactionData(t *testing.T) {
requireIntegration(t)
fmt.Println("================ GetHistoryTransactionData ================")
tdx := newClient()
defer tdx.Disconnect()
reply, err := tdx.GetHistoryTransactionData(20230922, MarketSZ, "159607", 0, 10)
if err != nil {
t.Errorf("error:%s", err)
}
for _, obj := range reply.List {
fmt.Printf("%+v \n", obj)
}
}