mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
use net asset to calculate inUSD
This commit is contained in:
parent
ef419f75ab
commit
573f8bb221
|
@ -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" `
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user