add more position tests

This commit is contained in:
c9s 2021-01-20 16:10:20 +08:00
parent 34148948ab
commit 169af63846

View File

@ -12,14 +12,16 @@ import (
func TestPosition(t *testing.T) { func TestPosition(t *testing.T) {
trades := []types.Trade{ trades := []types.Trade{
{ {
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Price: 1000.0, Price: 1000.0,
Quantity: 0.01, Quantity: 0.01,
QuoteQuantity: 1000.0 * 0.01,
}, },
{ {
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Price: 2000.0, Price: 2000.0,
Quantity: 0.03, Quantity: 0.03,
QuoteQuantity: 2000.0 * 0.03,
}, },
} }
@ -28,6 +30,7 @@ func TestPosition(t *testing.T) {
pos.AddTrade(trade) pos.AddTrade(trade)
} }
assert.Equal(t, fixedpoint.NewFromFloat(-70.0), pos.Quote)
assert.Equal(t, fixedpoint.NewFromFloat(0.04), pos.Base) assert.Equal(t, fixedpoint.NewFromFloat(0.04), pos.Base)
assert.Equal(t, fixedpoint.NewFromFloat((1000.0*0.01+2000.0*0.03)/0.04), pos.AverageCost) assert.Equal(t, fixedpoint.NewFromFloat((1000.0*0.01+2000.0*0.03)/0.04), pos.AverageCost)
} }