mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
types: add test for PriceHeartBeat
This commit is contained in:
parent
5755c44845
commit
c3356fa694
|
@ -107,9 +107,6 @@ type Strategy struct {
|
||||||
orderStore *bbgo.OrderStore
|
orderStore *bbgo.OrderStore
|
||||||
tradeCollector *bbgo.TradeCollector
|
tradeCollector *bbgo.TradeCollector
|
||||||
|
|
||||||
lastBidPrice, lastAskPrice fixedpoint.Value
|
|
||||||
lastBidPriceTime, lastAskPriceTime time.Time
|
|
||||||
|
|
||||||
askPriceHeartBeat, bidPriceHeartBeat types.PriceHeartBeat
|
askPriceHeartBeat, bidPriceHeartBeat types.PriceHeartBeat
|
||||||
|
|
||||||
lastPrice float64
|
lastPrice float64
|
||||||
|
|
29
pkg/types/price_volume_heartbeat_test.go
Normal file
29
pkg/types/price_volume_heartbeat_test.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPriceHeartBeat_Update(t *testing.T) {
|
||||||
|
hb := PriceHeartBeat{}
|
||||||
|
updated, err := hb.Update(PriceVolume{Price: fixedpoint.NewFromFloat(22.0), Volume: fixedpoint.NewFromFloat(100.0)}, time.Minute)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, updated)
|
||||||
|
|
||||||
|
updated, err = hb.Update(PriceVolume{Price: fixedpoint.NewFromFloat(22.0), Volume: fixedpoint.NewFromFloat(100.0)}, time.Minute)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.False(t, updated, "should not be updated when pv is not changed")
|
||||||
|
|
||||||
|
updated, err = hb.Update(PriceVolume{Price: fixedpoint.NewFromFloat(23.0), Volume: fixedpoint.NewFromFloat(100.0)}, time.Minute)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, updated, "should be updated when the price is changed")
|
||||||
|
|
||||||
|
updated, err = hb.Update(PriceVolume{Price: fixedpoint.NewFromFloat(23.0), Volume: fixedpoint.NewFromFloat(200.0)}, time.Minute)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, updated, "should be updated when the volume is changed")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user