diff --git a/pkg/service/account.go b/pkg/service/account.go index 4c001a79e..0bc22062d 100644 --- a/pkg/service/account.go +++ b/pkg/service/account.go @@ -28,7 +28,7 @@ func (s *AccountService) InsertAsset(time time.Time, name types.ExchangeName, ac insert into nav_history_details ( exchange, subaccount, time, currency, balance_in_usd, balance_in_btc, balance,available,locked) values (?,?,?,?,?,?,?,?,?); - `, name, account, time, v.Currency, v.InUSD, v.InBTC, v.Total, 0, 0 /* v.Available, v.Lock */) + `, name, account, time, v.Currency, v.InUSD, v.InBTC, v.Total, v.Available, v.Locked) err = multierr.Append(err, _err) // successful request diff --git a/pkg/types/account.go b/pkg/types/account.go index dabd13c10..21ae4640b 100644 --- a/pkg/types/account.go +++ b/pkg/types/account.go @@ -41,25 +41,36 @@ func (b Balance) String() string { } type Asset struct { - Currency string `json:"currency" db:"currency"` - Total fixedpoint.Value `json:"total" db:"total"` - InUSD fixedpoint.Value `json:"inUSD" db:"inUSD"` - InBTC fixedpoint.Value `json:"inBTC" db:"inBTC"` - Time time.Time `json:"time" db:"time"` + Currency string `json:"currency" db:"currency"` + Total fixedpoint.Value `json:"total" db:"total"` + InUSD fixedpoint.Value `json:"inUSD" db:"inUSD"` + InBTC fixedpoint.Value `json:"inBTC" db:"inBTC"` + Time time.Time `json:"time" db:"time"` + Locked fixedpoint.Value `json:"lock" db:"lock" ` + Available fixedpoint.Value `json:"available" db:"available"` } type AssetMap map[string]Asset func (m AssetMap) PlainText() (o string) { + sumUsd := 0.0 + sumBTC := 0.0 for _, a := range m { - o += fmt.Sprintf("%s: %f (≈ %s) (≈ %s)", + usd := a.InUSD.Float64() + btc := a.InBTC.Float64() + o += fmt.Sprintf(" %s: %f (≈ %s) (≈ %s)", a.Currency, a.Total.Float64(), - USD.FormatMoneyFloat64(a.InUSD.Float64()), - BTC.FormatMoneyFloat64(a.InBTC.Float64()), + USD.FormatMoneyFloat64(usd), + BTC.FormatMoneyFloat64(btc), ) + "\n" + sumUsd += usd + sumBTC += btc } - + o += fmt.Sprintf(" Summary: (≈ %s) (≈ %s)", + USD.FormatMoneyFloat64(sumUsd), + BTC.FormatMoneyFloat64(sumBTC), + ) + "\n" return o } @@ -138,14 +149,17 @@ func (m BalanceMap) Assets(prices map[string]float64) AssetMap { } asset := Asset{ - Currency: currency, - Total: b.Available + b.Locked, - Time: now, + Currency: currency, + Total: b.Available + b.Locked, + Time: now, + Locked: b.Locked, + Available: b.Available, } btcusdt, hasBtcPrice := prices["BTCUSDT"] usdMarkets := []string{currency + "USDT", currency + "USDC", currency + "USD", "USDT" + currency} + for _, market := range usdMarkets { if val, ok := prices[market]; ok {