-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdecoders_test.go
54 lines (45 loc) · 1.03 KB
/
decoders_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
package ibapi
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDecodeRealTimeBars(t *testing.T) {
// Assemble
messageId := realTimeBars
version := 3
requestId := 9000
timestamp := int64(1642465785)
open := 4658.00
high := 4658.25
low := 4658.00
close := 4658.00
volume := int64(5)
wap := 4658.05
count := 3
packet := []string{
fmt.Sprintf("%d", messageId),
fmt.Sprintf("%d", version),
fmt.Sprintf("%d", requestId),
fmt.Sprintf("%d", timestamp),
fmt.Sprintf("%f", open),
fmt.Sprintf("%f", high),
fmt.Sprintf("%f", low),
fmt.Sprintf("%f", close),
fmt.Sprintf("%d", volume),
fmt.Sprintf("%f", wap),
fmt.Sprintf("%d", count),
}
// Activate
bar := decodeRealTimeBars(packet)
// Assert
assert.Equal(t, time.Unix(timestamp, 0), bar.Time)
assert.Equal(t, open, bar.Open)
assert.Equal(t, high, bar.High)
assert.Equal(t, low, bar.Low)
assert.Equal(t, close, bar.Close)
assert.Equal(t, volume, bar.Volume)
assert.Equal(t, wap, bar.WAP)
assert.Equal(t, count, bar.Count)
}