bbgo_origin/pkg/strategy/common/fee_budget_test.go

57 lines
1.3 KiB
Go
Raw Normal View History

package common
import (
"testing"
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/stretchr/testify/assert"
)
func TestFeeBudget(t *testing.T) {
cases := []struct {
budgets map[string]fixedpoint.Value
trades []types.Trade
expected bool
}{
{
budgets: map[string]fixedpoint.Value{
"MAX": fixedpoint.NewFromFloat(0.5),
},
trades: []types.Trade{
{FeeCurrency: "MAX", Fee: fixedpoint.NewFromFloat(0.1)},
{FeeCurrency: "USDT", Fee: fixedpoint.NewFromFloat(10.0)},
},
expected: true,
},
{
budgets: map[string]fixedpoint.Value{
"MAX": fixedpoint.NewFromFloat(0.5),
},
trades: []types.Trade{
{FeeCurrency: "MAX", Fee: fixedpoint.NewFromFloat(0.1)},
{FeeCurrency: "MAX", Fee: fixedpoint.NewFromFloat(0.5)},
{FeeCurrency: "USDT", Fee: fixedpoint.NewFromFloat(10.0)},
},
expected: false,
},
}
for _, c := range cases {
feeBudget := FeeBudget{
DailyFeeBudgets: c.budgets,
}
feeBudget.Initialize()
for _, trade := range c.trades {
feeBudget.HandleTradeUpdate(trade)
}
assert.Equal(t, c.expected, feeBudget.IsBudgetAllowed())
// test reset
2024-06-18 10:40:50 +00:00
feeBudget.DailyFeeTracker.StartedAt = feeBudget.DailyFeeTracker.StartedAt.Add(-24 * time.Hour)
assert.True(t, feeBudget.IsBudgetAllowed())
}
}