use net asset to calculate inUSD

This commit is contained in:
c9s 2022-05-04 19:26:26 +08:00
parent ef419f75ab
commit 573f8bb221
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 6 additions and 6 deletions

View File

@ -14,13 +14,13 @@ type Asset struct {
Currency string `json:"currency" db:"currency"`
Total fixedpoint.Value `json:"total" db:"total"`
NetAsset fixedpoint.Value `json:"netAsset" db:"net_asset"`
NetAsset fixedpoint.Value `json:"netAsset" db:"net_asset"`
// InUSD is net asset in USD
InUSD fixedpoint.Value `json:"inUSD" db:"net_asset_in_usd"`
// InBTC is net asset in BTC
InBTC fixedpoint.Value `json:"inBTC" db:"net_asset_in_btc"`
InBTC fixedpoint.Value `json:"inBTC" db:"net_asset_in_btc"`
Time time.Time `json:"time" db:"time"`
Locked fixedpoint.Value `json:"lock" db:"lock" `

View File

@ -129,13 +129,13 @@ func (m BalanceMap) Assets(prices map[string]fixedpoint.Value, priceTime time.Ti
if market, usdPrice, ok := findUSDMarketPrice(currency, prices); ok {
// this includes USDT, USD, USDC and so on
if strings.HasPrefix(market, "USD") { // for prices like USDT/TWD
if !asset.Total.IsZero() {
asset.InUSD = asset.Total.Div(usdPrice)
if !asset.NetAsset.IsZero() {
asset.InUSD = asset.NetAsset.Div(usdPrice)
}
asset.PriceInUSD = fixedpoint.One.Div(usdPrice)
} else { // for prices like BTC/USDT
if !asset.Total.IsZero() {
asset.InUSD = asset.Total.Mul(usdPrice)
if !asset.NetAsset.IsZero() {
asset.InUSD = asset.NetAsset.Mul(usdPrice)
}
asset.PriceInUSD = usdPrice
}