From 9505c8b997dd2f8a67f504881acf89b93e5c43b0 Mon Sep 17 00:00:00 2001 From: dwd Date: Sun, 3 Mar 2024 13:06:52 +0800 Subject: [PATCH] add func: bnc.NewSimpleKlineFromStrcut --- bnc/kline.go | 15 +++++++++++++++ bnc/kline_test.go | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/bnc/kline.go b/bnc/kline.go index 1b0bbb0..bbe52bf 100644 --- a/bnc/kline.go +++ b/bnc/kline.go @@ -55,6 +55,21 @@ func NewSimpleKlineFromRaw(k RawKline) (kline SimpleKline, err error) { return kline, nil } +func NewSimpleKlineFromStruct(k Kline) (kline SimpleKline, err error) { + kline[0] = float64(k.OpenTime) + kline[1] = k.OpenPrice + kline[2] = k.HighPrice + kline[3] = k.LowPrice + kline[4] = k.ClosePrice + kline[5] = k.Volume + kline[6] = float64(k.CloseTime) + kline[7] = k.QuoteAssetVolume + kline[8] = float64(k.TradesNumber) + kline[9] = k.TakerBuyBaseAssetVolume + kline[10] = k.TakerBuyQuoteAssetVolume + return +} + func (k SimpleKline) NotExist() bool { return k[0] == 0 } diff --git a/bnc/kline_test.go b/bnc/kline_test.go index 8b5a6fa..427b5f0 100644 --- a/bnc/kline_test.go +++ b/bnc/kline_test.go @@ -44,10 +44,16 @@ func TestNewSimpleKline(t *testing.T) { klineFromRaw, err := NewSimpleKlineFromRaw(rawKline) props.PanicIfNotNil(err) + klineFromStruct, err := NewSimpleKlineFromStruct(structKline) + props.PanicIfNotNil(err) + for i, v := range klineFromStr { if klineFromRaw[i] != v { panic("from str != from raw") } + if klineFromStruct[i] != v { + panic("from struct != from raw") + } } if klineFromStr.OpenTime() != structKline.OpenTime {