mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
types: update account struct
This commit is contained in:
parent
1ab20e6397
commit
06fc821b3d
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user