This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
/
binanceExchange_ws_test.go
91 lines (72 loc) · 2.4 KB
/
binanceExchange_ws_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
package plugins
import (
"fmt"
"testing"
"github.com/stellar/kelp/model"
"github.com/stretchr/testify/assert"
)
func Test_createStateEvents(t *testing.T) {
events := createStateEvents()
assert.NotNil(t, events)
}
func Test_binanceExchangeWs_GetTickerPrice(t *testing.T) {
pair := model.TradingPair{Base: model.XLM, Quote: model.BTC}
pairs := []model.TradingPair{pair}
testBinanceExchangeWs, err := makeBinanceWs()
if !assert.NoError(t, err) {
return
}
m, e := testBinanceExchangeWs.GetTickerPrice(pairs)
if !assert.NoError(t, e) {
return
}
assert.Equal(t, 1, len(m))
ticker := m[pair]
fmt.Printf("ticker price: bid=%s, ask=%s, last=%s\n", ticker.BidPrice.AsString(), ticker.AskPrice.AsString(), ticker.LastPrice.AsString())
if !assert.True(t, ticker.AskPrice.AsFloat() < 1, ticker.AskPrice.AsString()) {
return
}
if !assert.True(t, ticker.BidPrice.AsFloat() < 1, ticker.BidPrice.AsString()) {
return
}
if !assert.True(t, ticker.BidPrice.AsFloat() < ticker.AskPrice.AsFloat(), fmt.Sprintf("bid price (%s) should be less than ask price (%s)", ticker.BidPrice.AsString(), ticker.AskPrice.AsString())) {
return
}
if !assert.True(t, ticker.LastPrice.AsFloat() < 1, ticker.LastPrice.AsString()) {
return
}
}
func Test_binanceExchangeWs_GetOrderBook(t *testing.T) {
testBinanceExchangeWs, e := makeBinanceWs()
if !assert.NoError(t, e) {
return
}
for _, obDepth := range []int32{1, 5, 8, 10, 15, 16, 20} {
pair := model.TradingPair{Base: model.XLM, Quote: model.BTC}
ob, e := testBinanceExchangeWs.GetOrderBook(&pair, obDepth)
if !assert.NoError(t, e) {
return
}
assert.Equal(t, ob.Pair(), &pair)
if !assert.True(t, len(ob.Asks()) > 0, len(ob.Asks())) {
return
}
if !assert.True(t, len(ob.Bids()) > 0, len(ob.Bids())) {
return
}
if !assert.True(t, len(ob.Asks()) <= int(obDepth), fmt.Sprintf("asks should be <= %d", obDepth)) {
return
}
if !assert.True(t, len(ob.Bids()) <= int(obDepth), fmt.Sprintf("bids should be <= %d", obDepth)) {
return
}
assert.True(t, ob.Asks()[0].OrderAction.IsSell())
assert.True(t, ob.Asks()[0].OrderType.IsLimit())
assert.True(t, ob.Bids()[0].OrderAction.IsBuy())
assert.True(t, ob.Bids()[0].OrderType.IsLimit())
assert.True(t, ob.Asks()[0].Price.AsFloat() > 0)
assert.True(t, ob.Asks()[0].Volume.AsFloat() > 0)
assert.True(t, ob.Bids()[0].Price.AsFloat() > 0)
assert.True(t, ob.Bids()[0].Volume.AsFloat() > 0)
}
}