mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
render borrowed in the attachment
This commit is contained in:
parent
573f8bb221
commit
d5b203a925
|
@ -76,7 +76,7 @@ func (m AssetMap) Slice() (assets []Asset) {
|
||||||
|
|
||||||
func (m AssetMap) SlackAttachment() slack.Attachment {
|
func (m AssetMap) SlackAttachment() slack.Attachment {
|
||||||
var fields []slack.AttachmentField
|
var fields []slack.AttachmentField
|
||||||
var totalBTC, totalUSD fixedpoint.Value
|
var netAssetInBTC, netAssetInUSD fixedpoint.Value
|
||||||
|
|
||||||
var assets = m.Slice()
|
var assets = m.Slice()
|
||||||
|
|
||||||
|
@ -86,26 +86,38 @@ func (m AssetMap) SlackAttachment() slack.Attachment {
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, a := range assets {
|
for _, a := range assets {
|
||||||
totalUSD = totalUSD.Add(a.InUSD)
|
netAssetInUSD = netAssetInUSD.Add(a.InUSD)
|
||||||
totalBTC = totalBTC.Add(a.InBTC)
|
netAssetInBTC = netAssetInBTC.Add(a.InBTC)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range assets {
|
for _, a := range assets {
|
||||||
if !a.InUSD.IsZero() {
|
if !a.InUSD.IsZero() {
|
||||||
|
text := fmt.Sprintf("%s (≈ %s) (≈ %s) (%s)",
|
||||||
|
a.NetAsset.String(),
|
||||||
|
USD.FormatMoney(a.InUSD),
|
||||||
|
BTC.FormatMoney(a.InBTC),
|
||||||
|
a.InUSD.Div(netAssetInUSD).FormatPercentage(2),
|
||||||
|
)
|
||||||
|
|
||||||
|
if !a.Borrowed.IsZero() {
|
||||||
|
text += fmt.Sprintf(" Borrowed: %s", a.Borrowed.String())
|
||||||
|
}
|
||||||
|
|
||||||
fields = append(fields, slack.AttachmentField{
|
fields = append(fields, slack.AttachmentField{
|
||||||
Title: a.Currency,
|
Title: a.Currency,
|
||||||
Value: fmt.Sprintf("%s (≈ %s) (≈ %s) (%s)",
|
Value: text,
|
||||||
a.Total.String(),
|
|
||||||
USD.FormatMoney(a.InUSD),
|
|
||||||
BTC.FormatMoney(a.InBTC),
|
|
||||||
a.InUSD.Div(totalUSD).FormatPercentage(2),
|
|
||||||
),
|
|
||||||
Short: false,
|
Short: false,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
text := fmt.Sprintf("%s", a.NetAsset.String())
|
||||||
|
|
||||||
|
if !a.Borrowed.IsZero() {
|
||||||
|
text += fmt.Sprintf(" Borrowed: %s", a.Borrowed.String())
|
||||||
|
}
|
||||||
|
|
||||||
fields = append(fields, slack.AttachmentField{
|
fields = append(fields, slack.AttachmentField{
|
||||||
Title: a.Currency,
|
Title: a.Currency,
|
||||||
Value: fmt.Sprintf("%s", a.Total.String()),
|
Value: text,
|
||||||
Short: false,
|
Short: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -113,8 +125,8 @@ func (m AssetMap) SlackAttachment() slack.Attachment {
|
||||||
|
|
||||||
return slack.Attachment{
|
return slack.Attachment{
|
||||||
Title: fmt.Sprintf("Net Asset Value %s (≈ %s)",
|
Title: fmt.Sprintf("Net Asset Value %s (≈ %s)",
|
||||||
USD.FormatMoney(totalUSD),
|
USD.FormatMoney(netAssetInUSD),
|
||||||
BTC.FormatMoney(totalBTC),
|
BTC.FormatMoney(netAssetInBTC),
|
||||||
),
|
),
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user