backtest: add kline fixture generator

Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
c9s 2022-06-25 17:55:31 +08:00
parent 118928d388
commit 66f923ad0d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 10 additions and 2 deletions

View File

@ -68,12 +68,14 @@ func (g *KLineFixtureGenerator) Generate(ctx context.Context, c chan types.KLine
} }
func TestKLineFixtureGenerator(t *testing.T) { func TestKLineFixtureGenerator(t *testing.T) {
startTime := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.Local)
endTime := time.Date(2022, time.January, 31, 0, 0, 0, 0, time.Local)
ctx := context.Background() ctx := context.Background()
g := &KLineFixtureGenerator{ g := &KLineFixtureGenerator{
Symbol: "BTCUSDT", Symbol: "BTCUSDT",
Interval: types.Interval1m, Interval: types.Interval1m,
StartTime: time.Date(2022, time.January, 1, 0, 0, 0, 0, time.Local), StartTime: startTime,
EndTime: time.Date(2022, time.January, 31, 0, 0, 0, 0, time.Local), EndTime: endTime,
StartPrice: fixedpoint.NewFromFloat(18000.0), StartPrice: fixedpoint.NewFromFloat(18000.0),
} }
@ -85,5 +87,7 @@ func TestKLineFixtureGenerator(t *testing.T) {
for k := range c { for k := range c {
// high must higher than low // high must higher than low
assert.True(t, k.High.Compare(k.Low) > 0) assert.True(t, k.High.Compare(k.Low) > 0)
assert.True(t, k.StartTime.After(startTime) || k.StartTime.Equal(startTime))
assert.True(t, k.StartTime.Before(endTime))
} }
} }

View File

@ -165,6 +165,10 @@ func (t Time) UnixMilli() int64 {
return time.Time(t).UnixMilli() return time.Time(t).UnixMilli()
} }
func (t Time) Equal(time2 time.Time) bool {
return time.Time(t).Equal(time2)
}
func (t Time) After(time2 time.Time) bool { func (t Time) After(time2 time.Time) bool {
return time.Time(t).After(time2) return time.Time(t).After(time2)
} }