-
Notifications
You must be signed in to change notification settings - Fork 3
/
indicators_test.go
87 lines (81 loc) · 2.08 KB
/
indicators_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
package dexter
import (
"encoding/json"
"io/ioutil"
"log"
"testing"
"time"
"github.com/davecgh/go-spew/spew"
//"github.com/davecgh/go-spew/spew"
)
func LoadFixture(filename string) []Candle {
file, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
data := []Candle{}
_ = json.Unmarshal([]byte(file), &data)
return data
}
func TestPrice(t *testing.T) {
candles := LoadFixture("./fixtures/20190827.binance.btcusdt.1h.json")
chart := Chart{
Exchange: "binance",
Market: "BTC/USDT",
Timeframe: "1h",
Candles: candles,
}
price, _ := FindIndicatorByName("Price")
output := price.Fn([]float64{ 10000 }, chart)
if len(output) != 500 {
t.Errorf("There should be 500 values in output")
}
if output[0][0] != 11674.38 {
t.Errorf("The 0th price should be 11674.38 but was %f", output[0][0])
}
if output[499][0] != 10145.82 {
t.Errorf("The last price should be 10145.82 but was %f", output[499][0])
}
}
func TestHorizontalLine(t *testing.T) {
candles := LoadFixture("./fixtures/20190827.binance.btcusdt.1h.json")
chart := Chart{
Exchange: "binance",
Market: "BTC/USDT",
Timeframe: "1h",
Candles: candles,
}
horizontalLine, _ := FindIndicatorByName("Horizontal Line")
output := horizontalLine.Fn([]float64{ 10000 }, chart)
if len(output) != 500 {
t.Errorf("There should be 500 values in output")
}
if output[0][0] != 10000 {
t.Errorf("The first value should be 10000")
}
if output[499][0] != 10000 {
t.Errorf("The last value should be 10000")
}
}
func TestMovingAverage(t *testing.T) {
candles := LoadFixture("./fixtures/20190827.binance.btcusdt.1h.json")
chart := Chart{
Exchange: "binance",
Market: "BTC/USDT",
Timeframe: "1h",
Candles: candles,
}
movingAverage, _ := FindIndicatorByName("Moving Average")
output := movingAverage.Fn([]float64{ 10 }, chart)
if len(output) != 500 {
t.Errorf("There should be 490 values in output")
}
}
func TestTimestamp(t *testing.T) {
// ccxt gives me time back in milliseconds
ts := time.Unix(1566946800000 / 1000, 0)
if ts.Unix() != 1566946800 {
spew.Dump(ts, ts.Unix())
t.Errorf("No good.")
}
}