bbgo_origin/pkg/indicator/v2/volume_profile_test.go

38 lines
948 B
Go
Raw Normal View History

2023-11-02 17:03:16 +00:00
package indicatorv2
import (
"encoding/csv"
"os"
"path"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datasource/csvsource"
"github.com/c9s/bbgo/pkg/types"
)
func TestVolumeProfile(t *testing.T) {
file, _ := os.Open(path.Join("testdata", "BTCUSDT-1m-2022-05-06.csv"))
defer func() {
assert.NoError(t, file.Close())
}()
candles, err := csvsource.NewCSVKLineReader(csv.NewReader(file)).ReadAll(time.Minute)
assert.NoError(t, err)
stream := &types.StandardStream{}
kLines := KLines(stream, "", "")
ind := VolumeProfile(kLines, 10)
2023-11-02 17:03:16 +00:00
for _, candle := range candles {
stream.EmitKLineClosed(candle)
}
assert.InDelta(t, 36512.7, ind.VP.Low, 0.01, "VP.LOW")
assert.InDelta(t, 36600.811, ind.VP.VAL, 0.01, "VP.VAL")
assert.InDelta(t, 36612.559, ind.VP.POC, 0.01, "VP.POC")
assert.InDelta(t, 36618.433, ind.VP.VAH, 0.01, "VP.VAH")
2023-11-02 17:03:16 +00:00
assert.InDelta(t, 36617.433, ind.VP.High, 0.01, "VP.HIGH")
}