From c089e9a1b5f25c3fa7c6bfa348188bed74a99341 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 10 Jun 2020 13:53:31 +0800 Subject: [PATCH] add 1m kline window protection --- bbgo/kline.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bbgo/kline.go b/bbgo/kline.go index d76128889..fe6495ce1 100644 --- a/bbgo/kline.go +++ b/bbgo/kline.go @@ -173,6 +173,17 @@ func (k *KLineWindow) Add(line KLine) { *k = append(*k, line) } +func (k KLineWindow) Take(size int) KLineWindow { + return k[:size] +} + +func (k KLineWindow) Tail(size int) KLineWindow { + if len(k) <= size { + return k[:] + } + return k[len(k) - size:] +} + func (k *KLineWindow) Truncate(size int) { if len(*k) <= size { return