bbgo: add USDTTWD price test case

This commit is contained in:
c9s 2022-09-14 02:17:21 +08:00
parent c9b064f0ac
commit 02dab542c4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 21 additions and 2 deletions

View File

@ -140,8 +140,7 @@ func calculateNetValueInQuote(balances types.BalanceMap, prices types.PriceMap,
if price, ok := prices[symbol]; ok { if price, ok := prices[symbol]; ok {
accountValue = accountValue.Add(b.Net().Mul(price)) accountValue = accountValue.Add(b.Net().Mul(price))
} else if priceReverse, ok2 := prices[symbolReverse]; ok2 { } else if priceReverse, ok2 := prices[symbolReverse]; ok2 {
price2 := one.Div(priceReverse) accountValue = accountValue.Add(b.Net().Div(priceReverse))
accountValue = accountValue.Add(b.Net().Mul(price2))
} }
} }

View File

@ -256,6 +256,26 @@ func Test_calculateNetValueInQuote(t *testing.T) {
}, },
wantAccountValue: number(19000.0*0.01 + 100.0 + 80.0 + 70.0), wantAccountValue: number(19000.0*0.01 + 100.0 + 80.0 + 70.0),
}, },
{
name: "reversed usdt price",
args: args{
balances: types.BalanceMap{
"USDC": types.Balance{Currency: "USDC", Available: number(70.0)},
"TWD": types.Balance{Currency: "TWD", Available: number(3000.0)},
"USDT": types.Balance{Currency: "USDT", Available: number(100.0)},
"BUSD": types.Balance{Currency: "BUSD", Available: number(80.0)},
"BTC": types.Balance{Currency: "BTC", Available: number(0.01)},
},
prices: types.PriceMap{
"USDTTWD": number(30.0),
"USDCUSDT": number(1.0),
"BUSDUSDT": number(1.0),
"BTCUSDT": number(19000.0),
},
quoteCurrency: "USDT",
},
wantAccountValue: number(19000.0*0.01 + 100.0 + 80.0 + 70.0 + (3000.0 / 30.0)),
},
{ {
name: "borrow base asset", name: "borrow base asset",
args: args{ args: args{