-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackpack_rest_test.go
198 lines (176 loc) · 5.13 KB
/
backpack_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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package backpackgo
import (
"fmt"
"testing"
"time"
"github.com/UnipayFI/backpack-go/options"
"github.com/UnipayFI/backpack-go/utils"
)
func TestBackpackPublicREST(t *testing.T) {
rest := NewRESTClient()
symbol := "BTC_USDC"
// test GetAssets
t.Run("test GetAssets", func(t *testing.T) {
assets, err := rest.GetMarketAssets()
if err != nil {
t.Errorf("GetAssets failed: %v", err)
} else {
fmt.Printf("OK: GetAssets, Assets count: %d\n\n", len(assets))
}
})
// test GetCollateral
t.Run("test GetCollateral", func(t *testing.T) {
collaterals, err := rest.GetMarketCollateral()
if err != nil {
t.Errorf("GetCollateral failed: %v", err)
} else {
fmt.Printf("OK: GetCollateral, Collateral count: %d\n\n", len(collaterals))
}
})
// test GetBorrowLendMarkets
t.Run("test GetBorrowLendMarkets", func(t *testing.T) {
markets, err := rest.GetBorrowLendMarkets()
if err != nil {
t.Errorf("GetBorrowLendMarkets failed: %v", err)
} else {
fmt.Printf("OK: GetBorrowLendMarkets, BorrowLendMarkets count: %d\n\n", len(markets))
}
})
// test GetBorrowLendMarketsHistory
t.Run("test GetBorrowLendMarketsHistory", func(t *testing.T) {
history, err := rest.GetBorrowLendMarketsHistory(options.OneDay)
if err != nil {
t.Errorf("GetBorrowLendMarketsHistory failed: %v", err)
} else {
fmt.Printf("OK: GetBorrowLendMarketsHistory, BorrowLendMarketsHistory count: %d\n\n", len(history))
}
})
// test GetMarkets
t.Run("test GetMarkets", func(t *testing.T) {
markets, err := rest.GetMarkets()
if err != nil {
t.Errorf("GetMarkets failed: %v", err)
} else {
fmt.Printf("OK: GetMarkets, Markets count: %d\n\n", len(markets))
}
})
// test GetMarket
t.Run("test GetMarket", func(t *testing.T) {
market, err := rest.GetMarket(symbol)
if err != nil {
t.Errorf("GetMarket failed: %v", err)
} else {
fmt.Printf("OK: GetMarket, %s Market orderbook state: %+v\n\n", market.Symbol, market.OrderBookState)
}
})
// test GetTicker
t.Run("test GetTicker", func(t *testing.T) {
ticker, err := rest.GetTicker(symbol)
if err != nil {
t.Errorf("GetTicker failed: %v", err)
} else {
fmt.Printf("OK: GetTicker, %s price: %+v\n\n", ticker.Symbol, ticker.FirstPrice)
}
})
// test GetDepth
t.Run("test GetDepth", func(t *testing.T) {
depth, err := rest.GetDepth(symbol)
if err != nil {
t.Errorf("GetDepth failed: %v", err)
} else {
fmt.Printf("OK: GetDepth, depth last update id: %s\n\n", depth.LastUpdateID)
}
})
// test GetKlines
t.Run("test GetKlines", func(t *testing.T) {
endTime := time.Now()
startTime := endTime.Add(-24 * time.Hour) // 过去24小时
klines, err := rest.GetKlines(symbol, options.KLineInterval1h, startTime, endTime)
if err != nil {
t.Errorf("GetKlines failed: %v", err)
} else {
fmt.Printf("OK: GetKlines, klines count: %d\n\n", len(klines))
}
})
// test GetOpenInterest
t.Run("test GetOpenInterest", func(t *testing.T) {
interests, err := rest.GetOpenInterest()
if err != nil {
t.Errorf("GetOpenInterest failed: %v", err)
} else {
fmt.Printf("OK: GetOpenInterest, open interest count: %+v\n\n", len(interests))
}
})
// test GetFundingRates
t.Run("test GetFundingRates", func(t *testing.T) {
headers, rates, err := rest.GetFundingRates(symbol + "_PERP")
if err != nil {
t.Errorf("GetFundingRates failed: %v", err)
} else {
fmt.Printf("OK: GetFundingRates, total: %+v, count: %d\n\n", headers.Total, len(rates))
}
})
// test GetTickers
t.Run("test GetTickers", func(t *testing.T) {
tickers, err := rest.GetTickers()
if err != nil {
t.Errorf("GetTickers failed: %v", err)
} else {
fmt.Printf("OK: GetTickers, tickers count: %d\n\n", len(tickers))
}
})
// test GetMarkPrices
t.Run("test GetMarkPrices", func(t *testing.T) {
prices, err := rest.GetMarkPrices()
if err != nil {
t.Errorf("GetMarkPrices failed: %v", err)
} else {
fmt.Printf("OK: GetMarkPrices, mark prices count: %d\n\n", len(prices))
}
})
// test Ping
t.Run("test Ping", func(t *testing.T) {
err := rest.Ping()
if err != nil {
t.Errorf("Ping failed: %v", err)
} else {
fmt.Printf("OK: Ping\n\n")
}
})
// test GetTime
t.Run("test GetTime", func(t *testing.T) {
time, err := rest.GetTime()
if err != nil {
t.Errorf("GetTime failed: %v", err)
} else {
fmt.Printf("OK: GetTime, Server time: %v\n\n", time)
}
})
// test GetStatus
t.Run("test GetStatus", func(t *testing.T) {
status, err := rest.GetStatus()
if err != nil {
t.Errorf("GetStatus failed: %v", err)
} else {
fmt.Printf("OK: GetStatus, Status: %+v\n\n", status)
}
})
// test GetTrades
t.Run("test GetTrades", func(t *testing.T) {
trades, err := rest.GetTrades(symbol, options.LimitOffset{Limit: utils.Ptr(100)})
if err != nil {
t.Errorf("GetTrades failed: %v", err)
} else {
fmt.Printf("OK: GetTrades, trades count: %d\n\n", len(trades))
}
})
// test GetTradesHistory
t.Run("test GetTradesHistory", func(t *testing.T) {
trades, err := rest.GetTradesHistory(symbol, 100)
if err != nil {
t.Errorf("GetTradesHistory failed: %v", err)
} else {
fmt.Printf("OK: GetTradesHistory, trades count: %d\n\n", len(trades))
}
})
}