mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 17:25:16 +00:00
bbgo: rename market value to totalValue
This commit is contained in:
parent
a94d1b424f
commit
c13c33dcbb
|
@ -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 {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user