Merge pull request #384 from tony1223/feature/record-account

types: update account struct
This commit is contained in:
Yo-An Lin 2021-12-22 00:04:30 +08:00 committed by GitHub
commit 53f6ea6490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -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, insert into nav_history_details ( exchange, subaccount, time, currency, balance_in_usd, balance_in_btc,
balance,available,locked) balance,available,locked)
values (?,?,?,?,?,?,?,?,?); 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 err = multierr.Append(err, _err) // successful request

View File

@ -46,20 +46,31 @@ type Asset struct {
InUSD fixedpoint.Value `json:"inUSD" db:"inUSD"` InUSD fixedpoint.Value `json:"inUSD" db:"inUSD"`
InBTC fixedpoint.Value `json:"inBTC" db:"inBTC"` InBTC fixedpoint.Value `json:"inBTC" db:"inBTC"`
Time time.Time `json:"time" db:"time"` 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 type AssetMap map[string]Asset
func (m AssetMap) PlainText() (o string) { func (m AssetMap) PlainText() (o string) {
sumUsd := 0.0
sumBTC := 0.0
for _, a := range m { for _, a := range m {
usd := a.InUSD.Float64()
btc := a.InBTC.Float64()
o += fmt.Sprintf(" %s: %f (≈ %s) (≈ %s)", o += fmt.Sprintf(" %s: %f (≈ %s) (≈ %s)",
a.Currency, a.Currency,
a.Total.Float64(), a.Total.Float64(),
USD.FormatMoneyFloat64(a.InUSD.Float64()), USD.FormatMoneyFloat64(usd),
BTC.FormatMoneyFloat64(a.InBTC.Float64()), BTC.FormatMoneyFloat64(btc),
) + "\n" ) + "\n"
sumUsd += usd
sumBTC += btc
} }
o += fmt.Sprintf(" Summary: (≈ %s) (≈ %s)",
USD.FormatMoneyFloat64(sumUsd),
BTC.FormatMoneyFloat64(sumBTC),
) + "\n"
return o return o
} }
@ -141,11 +152,14 @@ func (m BalanceMap) Assets(prices map[string]float64) AssetMap {
Currency: currency, Currency: currency,
Total: b.Available + b.Locked, Total: b.Available + b.Locked,
Time: now, Time: now,
Locked: b.Locked,
Available: b.Available,
} }
btcusdt, hasBtcPrice := prices["BTCUSDT"] btcusdt, hasBtcPrice := prices["BTCUSDT"]
usdMarkets := []string{currency + "USDT", currency + "USDC", currency + "USD", "USDT" + currency} usdMarkets := []string{currency + "USDT", currency + "USDC", currency + "USD", "USDT" + currency}
for _, market := range usdMarkets { for _, market := range usdMarkets {
if val, ok := prices[market]; ok { if val, ok := prices[market]; ok {