bbgo_origin/pkg/strategy/common/inventory_skew_test.go

70 lines
2.0 KiB
Go
Raw Normal View History

2024-05-20 07:11:18 +00:00
package common
2023-11-08 09:59:37 +00:00
import (
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/stretchr/testify/assert"
)
func Test_InventorySkew_CalculateBidAskRatios(t *testing.T) {
cases := []struct {
quantity fixedpoint.Value
price fixedpoint.Value
baseBalance fixedpoint.Value
quoteBalance fixedpoint.Value
want *InventorySkewBidAskRatios
}{
{
quantity: fixedpoint.NewFromFloat(1.0),
price: fixedpoint.NewFromFloat(1000),
baseBalance: fixedpoint.NewFromFloat(1.0),
quoteBalance: fixedpoint.NewFromFloat(1000),
want: &InventorySkewBidAskRatios{
2023-12-21 08:34:05 +00:00
BidRatio: fixedpoint.NewFromFloat(1.0),
AskRatio: fixedpoint.NewFromFloat(1.0),
2023-11-08 09:59:37 +00:00
},
},
{
quantity: fixedpoint.NewFromFloat(1.0),
price: fixedpoint.NewFromFloat(1000),
baseBalance: fixedpoint.NewFromFloat(1.0),
quoteBalance: fixedpoint.NewFromFloat(1200),
want: &InventorySkewBidAskRatios{
2023-12-21 08:34:05 +00:00
BidRatio: fixedpoint.NewFromFloat(1.5),
AskRatio: fixedpoint.NewFromFloat(0.5),
2023-11-08 09:59:37 +00:00
},
},
{
quantity: fixedpoint.NewFromFloat(1.0),
price: fixedpoint.NewFromFloat(1000),
baseBalance: fixedpoint.NewFromFloat(0.0),
quoteBalance: fixedpoint.NewFromFloat(10000),
want: &InventorySkewBidAskRatios{
2023-12-21 08:34:05 +00:00
BidRatio: fixedpoint.NewFromFloat(2.0),
AskRatio: fixedpoint.NewFromFloat(0.0),
2023-11-08 09:59:37 +00:00
},
},
{
quantity: fixedpoint.NewFromFloat(1.0),
price: fixedpoint.NewFromFloat(1000),
baseBalance: fixedpoint.NewFromFloat(2.0),
quoteBalance: fixedpoint.NewFromFloat(0.0),
want: &InventorySkewBidAskRatios{
2023-12-21 08:34:05 +00:00
BidRatio: fixedpoint.NewFromFloat(0.0),
AskRatio: fixedpoint.NewFromFloat(2.0),
2023-11-08 09:59:37 +00:00
},
},
}
for _, c := range cases {
s := &InventorySkew{
InventoryRangeMultiplier: fixedpoint.NewFromFloat(0.1),
TargetBaseRatio: fixedpoint.NewFromFloat(0.5),
}
got := s.CalculateBidAskRatios(c.quantity, c.price, c.baseBalance, c.quoteBalance)
2023-12-21 08:34:05 +00:00
assert.Equal(t, c.want.BidRatio.Float64(), got.BidRatio.Float64())
assert.Equal(t, c.want.AskRatio.Float64(), got.AskRatio.Float64())
2023-11-08 09:59:37 +00:00
}
}