mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
move report struct
This commit is contained in:
parent
63ea81b648
commit
27b582e948
|
@ -1,2 +0,0 @@
|
||||||
package accounting
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/accounting"
|
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ type AverageCostCalculator struct {
|
||||||
TradingFeeCurrency string
|
TradingFeeCurrency string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice float64) *accounting.ProfitAndLossReport {
|
func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice float64) *AverageCostPnlReport {
|
||||||
// copy trades, so that we can truncate it.
|
// copy trades, so that we can truncate it.
|
||||||
var bidVolume = 0.0
|
var bidVolume = 0.0
|
||||||
var bidAmount = 0.0
|
var bidAmount = 0.0
|
||||||
|
@ -88,7 +87,7 @@ func (c *AverageCostCalculator) Calculate(trades []types.Trade, currentPrice flo
|
||||||
unrealizedProfit += (currentPrice-averageCost)*stock - stockFee
|
unrealizedProfit += (currentPrice-averageCost)*stock - stockFee
|
||||||
}
|
}
|
||||||
|
|
||||||
return &accounting.ProfitAndLossReport{
|
return &AverageCostPnlReport{
|
||||||
Symbol: c.Symbol,
|
Symbol: c.Symbol,
|
||||||
StartTime: c.StartTime,
|
StartTime: c.StartTime,
|
||||||
CurrentPrice: currentPrice,
|
CurrentPrice: currentPrice,
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package accounting
|
package pnl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/slack-go/slack"
|
"github.com/slack-go/slack"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/slack/slackstyle"
|
"github.com/c9s/bbgo/pkg/slack/slackstyle"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProfitAndLossReport struct {
|
type AverageCostPnlReport struct {
|
||||||
CurrentPrice float64
|
CurrentPrice float64
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
Symbol string
|
Symbol string
|
||||||
|
@ -27,23 +27,23 @@ type ProfitAndLossReport struct {
|
||||||
CurrencyFees map[string]float64
|
CurrencyFees map[string]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (report ProfitAndLossReport) Print() {
|
func (report AverageCostPnlReport) Print() {
|
||||||
logrus.Infof("trades since: %v", report.StartTime)
|
log.Infof("trades since: %v", report.StartTime)
|
||||||
logrus.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
|
log.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
|
||||||
logrus.Infof("total bid volume: %f", report.BidVolume)
|
log.Infof("total bid volume: %f", report.BidVolume)
|
||||||
logrus.Infof("total ask volume: %f", report.AskVolume)
|
log.Infof("total ask volume: %f", report.AskVolume)
|
||||||
logrus.Infof("stock: %f", report.Stock)
|
log.Infof("stock: %f", report.Stock)
|
||||||
logrus.Infof("fee (USD): %f", report.FeeUSD)
|
log.Infof("fee (USD): %f", report.FeeUSD)
|
||||||
logrus.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
|
log.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
|
||||||
logrus.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit))
|
log.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit))
|
||||||
logrus.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
|
log.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
|
||||||
logrus.Infof("currency fees:")
|
log.Infof("currency fees:")
|
||||||
for currency, fee := range report.CurrencyFees {
|
for currency, fee := range report.CurrencyFees {
|
||||||
logrus.Infof(" - %s: %f", currency, fee)
|
log.Infof(" - %s: %f", currency, fee)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (report ProfitAndLossReport) SlackAttachment() slack.Attachment {
|
func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
|
||||||
var color = slackstyle.Red
|
var color = slackstyle.Red
|
||||||
|
|
||||||
if report.UnrealizedProfit > 0 {
|
if report.UnrealizedProfit > 0 {
|
|
@ -1,14 +1,14 @@
|
||||||
package bbgo
|
package bbgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/c9s/bbgo/pkg/accounting"
|
"github.com/c9s/bbgo/pkg/accounting/pnl"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Notifier interface {
|
type Notifier interface {
|
||||||
Notify(format string, args ...interface{})
|
Notify(format string, args ...interface{})
|
||||||
NotifyTrade(trade *types.Trade)
|
NotifyTrade(trade *types.Trade)
|
||||||
NotifyPnL(report *accounting.ProfitAndLossReport)
|
NotifyPnL(report *pnl.AverageCostPnlReport)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullNotifier struct{}
|
type NullNotifier struct{}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/slack-go/slack"
|
"github.com/slack-go/slack"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/accounting"
|
"github.com/c9s/bbgo/pkg/accounting/pnl"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"github.com/c9s/bbgo/pkg/util"
|
"github.com/c9s/bbgo/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -106,7 +106,7 @@ func (n *Notifier) NotifyTrade(trade *types.Trade) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) NotifyPnL(report *accounting.ProfitAndLossReport) {
|
func (n *Notifier) NotifyPnL(report *pnl.AverageCostPnlReport) {
|
||||||
attachment := report.SlackAttachment()
|
attachment := report.SlackAttachment()
|
||||||
|
|
||||||
_, _, err := n.client.PostMessageContext(context.Background(), n.PnlChannel,
|
_, _, err := n.client.PostMessageContext(context.Background(), n.PnlChannel,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user