fix position test for net profit

This commit is contained in:
c9s 2021-05-22 17:43:53 +08:00
parent cca3284140
commit 0a908e5dda

View File

@ -38,7 +38,7 @@ func TestPosition_ExchangeFeeRate_Short(t *testing.T) {
FeeCurrency: "BNB", FeeCurrency: "BNB",
}) })
profit, _, madeProfit := pos.AddTrade(types.Trade{ _, netProfit, madeProfit := pos.AddTrade(types.Trade{
Exchange: types.ExchangeBinance, Exchange: types.ExchangeBinance,
Price: 2000.0, Price: 2000.0,
Quantity: 10.0, Quantity: 10.0,
@ -51,7 +51,7 @@ func TestPosition_ExchangeFeeRate_Short(t *testing.T) {
expectedProfit := (averageCost-2000.0)*10.0 - (2000.0 * 10.0 * feeRate) expectedProfit := (averageCost-2000.0)*10.0 - (2000.0 * 10.0 * feeRate)
assert.True(t, madeProfit) assert.True(t, madeProfit)
assert.Equal(t, fixedpoint.NewFromFloat(expectedProfit), profit) assert.Equal(t, fixedpoint.NewFromFloat(expectedProfit), netProfit)
} }
func TestPosition_ExchangeFeeRate_Long(t *testing.T) { func TestPosition_ExchangeFeeRate_Long(t *testing.T) {
@ -83,7 +83,7 @@ func TestPosition_ExchangeFeeRate_Long(t *testing.T) {
FeeCurrency: "BNB", FeeCurrency: "BNB",
}) })
profit, _, madeProfit := pos.AddTrade(types.Trade{ _, netProfit, madeProfit := pos.AddTrade(types.Trade{
Exchange: types.ExchangeBinance, Exchange: types.ExchangeBinance,
Price: 4000.0, Price: 4000.0,
Quantity: 10.0, Quantity: 10.0,
@ -96,7 +96,7 @@ func TestPosition_ExchangeFeeRate_Long(t *testing.T) {
expectedProfit := (4000.0-averageCost)*10.0 - (4000.0 * 10.0 * feeRate) expectedProfit := (4000.0-averageCost)*10.0 - (4000.0 * 10.0 * feeRate)
assert.True(t, madeProfit) assert.True(t, madeProfit)
assert.Equal(t, fixedpoint.NewFromFloat(expectedProfit), profit) assert.Equal(t, fixedpoint.NewFromFloat(expectedProfit), netProfit)
} }
func TestPosition(t *testing.T) { func TestPosition(t *testing.T) {