Skip to content

Commit

Permalink
add func: bnc.NewSimpleKlineFromStrcut
Browse files Browse the repository at this point in the history
  • Loading branch information
dwdwow committed Mar 3, 2024
1 parent cbb98f5 commit 9505c8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bnc/kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions bnc/kline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9505c8b

Please sign in to comment.