-
Notifications
You must be signed in to change notification settings - Fork 2
/
loader_test.go
59 lines (45 loc) · 1.69 KB
/
loader_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
package order_book_depth_loader_test
import (
"github.com/bogdantimes/order-book-depth-loader/depth"
"github.com/kaz-yamam0t0/go-timeparser/timeparser"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
const DateFmt = "m-d-Y"
func ParseOrDie(s string) time.Time {
rangeStart, err := timeparser.ParseFormat(DateFmt, s)
if err != nil {
panic(err)
}
return *rangeStart
}
func TestLoader(t *testing.T) {
depthLoader := depth.NewCCDepthLoader(depth.MarketBinance)
result := depthLoader.Load([]depth.Pair{"BTC-BUSD"}, ParseOrDie("11-24-2022"), ParseOrDie("11-25-2022"))
assert.NotEmpty(t, result["BTC-BUSD"])
assert.Empty(t, result["ETH-BUSD"])
minutesInDay := 24 * 60
assert.Len(t, result["BTC-BUSD"], minutesInDay*4)
result = depthLoader.Load([]depth.Pair{"ETH-BUSD"}, ParseOrDie("11-24-2022"), ParseOrDie("11-25-2022"))
assert.NotEmpty(t, result["ETH-BUSD"])
assert.Len(t, result["ETH-BUSD"], minutesInDay*4)
assert.Len(t, result["BTC-BUSD"], minutesInDay*4)
record1 := depthLoader.GetDepth("BTC-BUSD")
assert.NotEmpty(t, record1.BidPrice)
assert.NotEmpty(t, record1.AskPrice)
assert.NotEmpty(t, record1.BidSize)
assert.NotEmpty(t, record1.AskSize)
depthLoader.Tick()
record2 := depthLoader.GetDepth("BTC-BUSD")
assert.NotEmpty(t, record2.BidPrice)
assert.NotEmpty(t, record2.AskPrice)
assert.NotEmpty(t, record2.BidSize)
assert.NotEmpty(t, record2.AskSize)
assert.NotEqual(t, record1.BidPrice, record2.BidPrice)
result = depthLoader.Load([]depth.Pair{}, ParseOrDie("11-24-2022"), ParseOrDie("11-25-2022"))
assert.Greater(t, len(result), 3)
assert.FileExists(t, "data/2022-11-24_2022-11-25_depth.csv")
assert.NoError(t, os.Remove("data/2022-11-24_2022-11-25_depth.csv"))
}