-
Notifications
You must be signed in to change notification settings - Fork 0
/
xapi_test.go
74 lines (64 loc) · 1.66 KB
/
xapi_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
package xapi
import (
"fmt"
"os"
"testing"
"time"
)
func TestNewClient(t *testing.T) {
_, err := NewClient(os.Getenv("XAPI_USER_ID"), "wrong-password", "demo")
if err.Error() != "userPasswordCheck: Invalid login or password" {
t.Error(err)
}
_, err = NewClient("wrong-user-id", os.Getenv("XAPI_PASSWORD"), "demo")
if err.Error() != "Invalid parameters" {
fmt.Println(err)
t.Error(err)
}
_, err = NewClient(os.Getenv("XAPI_USER_ID"), os.Getenv("XAPI_PASSWORD"), "demo")
if err != nil {
t.Error(err)
}
}
func TestSuscribeCandles(t *testing.T) {
xapiClient, err := NewClient(os.Getenv("XAPI_USER_ID"), os.Getenv("XAPI_PASSWORD"), "demo")
if err != nil {
t.Error(err)
}
xapiClient.SubscribeCandles("EURUSD")
select {
case candle := <-xapiClient.CandlesChannel:
fmt.Printf("%+v\n", candle)
case <-time.After(2 * time.Minute):
t.Error("Did not receive candles")
}
}
func TestGetCandles(t *testing.T) {
xapiClient, err := NewClient(os.Getenv("XAPI_USER_ID"), os.Getenv("XAPI_PASSWORD"), "demo")
if err != nil {
t.Error(err)
}
start := int(time.Now().Add(-24 * 1 * time.Hour).UnixMilli())
period := 1
ticks := 1
end := int(time.Now().Add(-24 * 1 * time.Hour).UnixMilli())
candles, err := xapiClient.GetCandles(start, period, end, "EURUSD", ticks)
if err != nil {
t.Error(err)
} else {
length := len(candles)
if length != 1 {
t.Errorf("Should contain 1 candle, but contains %d", length)
}
}
ticks = 50
candles, err = xapiClient.GetCandles(start, period, end, "EURUSD", ticks)
if err != nil {
t.Error(err)
} else {
length := len(candles)
if length != 50 {
t.Errorf("Should contain 50 candle, but contains %d", length)
}
}
}