diff --git a/pkg/types/kline.go b/pkg/types/kline.go index b45bb67d0..db76aa8f2 100644 --- a/pkg/types/kline.go +++ b/pkg/types/kline.go @@ -355,7 +355,7 @@ func (k KLineWindow) Tail(size int) KLineWindow { } win := make(KLineWindow, size) - copy(win, k[length-1-size:]) + copy(win, k[length-size:]) return win } diff --git a/pkg/types/kline_test.go b/pkg/types/kline_test.go index 3e7af5f07..9cb0c5ac9 100644 --- a/pkg/types/kline_test.go +++ b/pkg/types/kline_test.go @@ -9,17 +9,20 @@ import ( func TestKLineWindow_Tail(t *testing.T) { var win = KLineWindow{ {Open: 11600.0, Close: 11600.0, High: 11600.0, Low: 11600.0}, - {Open: 11600.0, Close: 11600.0, High: 11600.0, Low: 11600.0}, + {Open: 11700.0, Close: 11700.0, High: 11700.0, Low: 11700.0}, } var win2 = win.Tail(1) assert.Len(t, win2, 1) + assert.ElementsMatch(t, win2, win[1:]) var win3 = win.Tail(2) assert.Len(t, win3, 2) + assert.ElementsMatch(t, win3, win) var win4 = win.Tail(3) assert.Len(t, win4, 2) + assert.ElementsMatch(t, win4, win) } func TestKLineWindow_Truncate(t *testing.T) {