bbgo: rename market value to totalValue

This commit is contained in:
c9s 2024-10-05 14:30:19 +08:00
parent a94d1b424f
commit c13c33dcbb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 17 additions and 6 deletions

View File

@ -70,7 +70,7 @@ func (c *AccountValueCalculator) DebtValue() fixedpoint.Value {
}) })
} }
func (c *AccountValueCalculator) MarketValue() fixedpoint.Value { func (c *AccountValueCalculator) TotalValue() fixedpoint.Value {
balances := c.session.Account.Balances() balances := c.session.Account.Balances()
return totalValueInQuote(balances, c.priceSolver, c.quoteCurrency, func( return totalValueInQuote(balances, c.priceSolver, c.quoteCurrency, func(
prev fixedpoint.Value, b types.Balance, price fixedpoint.Value, prev fixedpoint.Value, b types.Balance, price fixedpoint.Value,
@ -141,15 +141,26 @@ func (c *AccountValueCalculator) AvailableQuote() (fixedpoint.Value, error) {
// MarginLevel calculates the margin level from the asset market value and the debt value // MarginLevel calculates the margin level from the asset market value and the debt value
// See https://www.binance.com/en/support/faq/360030493931 // See https://www.binance.com/en/support/faq/360030493931
func (c *AccountValueCalculator) MarginLevel() (fixedpoint.Value, error) { func (c *AccountValueCalculator) MarginLevel() fixedpoint.Value {
marketValue := c.MarketValue() marketValue := c.TotalValue()
debtValue := c.DebtValue() debtValue := c.DebtValue()
if marketValue.IsZero() || debtValue.IsZero() { if marketValue.IsZero() || debtValue.IsZero() {
return fixedpoint.NewFromFloat(999.0), nil return fixedpoint.NewFromFloat(999.0)
} }
return marketValue.Div(debtValue), nil return marketValue.Div(debtValue)
}
func (c *AccountValueCalculator) Leverage() fixedpoint.Value {
netValue := c.NetValue()
debtValue := c.DebtValue()
if debtValue.IsZero() || netValue.IsZero() {
return fixedpoint.One
}
return debtValue.Div(netValue)
} }
func aggregateUsdNetValue(balances types.BalanceMap) fixedpoint.Value { func aggregateUsdNetValue(balances types.BalanceMap) fixedpoint.Value {

View File

@ -133,7 +133,7 @@ func TestNewAccountValueCalculator_MarginLevel(t *testing.T) {
cal := NewAccountValueCalculator(session, priceSolver, "USDT") cal := NewAccountValueCalculator(session, priceSolver, "USDT")
assert.NotNil(t, cal) assert.NotNil(t, cal)
marginLevel, err := cal.MarginLevel() marginLevel := cal.MarginLevel()
assert.NoError(t, err) assert.NoError(t, err)
// expected (21000 / 19000 * 1.003) // expected (21000 / 19000 * 1.003)