bollmaker: use the new profit generator method

This commit is contained in:
c9s 2022-03-05 01:41:23 +08:00
parent 197d750cb4
commit 5fe0b69927
2 changed files with 3 additions and 13 deletions

View File

@ -571,17 +571,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.tradeCollector = bbgo.NewTradeCollector(s.Symbol, s.state.Position, s.orderStore)
s.tradeCollector.OnProfit(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
log.Infof("generated profit: %v", profit)
p := types.Profit{
Symbol: s.Symbol,
Profit: profit,
NetProfit: netProfit,
QuoteQuantity: trade.QuoteQuantity,
ProfitMargin: profit.Div(trade.QuoteQuantity),
NetProfitMargin: netProfit.Div(trade.QuoteQuantity),
QuoteCurrency: s.state.Position.QuoteCurrency,
BaseCurrency: s.state.Position.BaseCurrency,
TradedAt: trade.Time.Time(),
}
p := s.state.Position.NewProfit(trade, profit, netProfit)
s.state.ProfitStats.AddProfit(p)
s.Notify(&p)
s.Notify(&s.state.ProfitStats)

View File

@ -54,8 +54,8 @@ type Position struct {
}
// NewProfit generates the profit object from the current position
func (p *Position) NewProfit(profit, netProfit fixedpoint.Value, trade Trade) *Profit {
return &Profit{
func (p *Position) NewProfit(trade Trade, profit, netProfit fixedpoint.Value) Profit {
return Profit{
Symbol: p.Symbol,
QuoteCurrency: p.QuoteCurrency,
BaseCurrency: p.BaseCurrency,