mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +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,
|
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
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
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.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 {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user