-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindicator_stoch_test.go
47 lines (43 loc) · 1.03 KB
/
indicator_stoch_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
package alphavantage
import (
"testing"
"github.com/AMekss/assert"
)
func TestToIndicatorStoch(t *testing.T) {
var buf = `
{
"Meta Data": {
"1: Symbol": "MSFT",
"2: Indicator": "Stochastic (STOCH)",
"3: Last Refreshed": "2019-09-20",
"4: Interval": "daily",
"5.1: FastK Period": 5,
"5.2: SlowK Period": 3,
"5.3: SlowK MA Type": 0,
"5.4: SlowD Period": 3,
"5.5: SlowD MA Type": 0,
"6: Time Zone": "US/Eastern Time"
},
"Technical Analysis: STOCH": {
"2019-09-20": {
"SlowK": "77.3256",
"SlowD": "76.3691"
},
"2019-09-19": {
"SlowK": "81.5707",
"SlowD": "69.3987"
}
}
}
`
indicator, err := toIndicatorStoch([]byte(buf))
assert.NoError(t, err)
assert.EqualStrings(t, "MSFT", indicator.Metadata.Symbol)
assert.EqualInt(t, 2, len(indicator.TechnicalAnalysis))
ta1, exists := indicator.TechnicalAnalysis["2019-09-20"]
if !exists {
assert.Panic(t, "entry for 2019-09-20 is missing")
}
assert.EqualFloat64(t, 77.3256, ta1.SlowK)
assert.EqualFloat64(t, 76.3691, ta1.SlowD)
}