bollmaker: assign strategy id and instance id

This commit is contained in:
c9s 2022-03-06 15:38:58 +08:00
parent f6ec2e78e6
commit 8fa0e6702c
2 changed files with 19 additions and 18 deletions

View File

@ -566,6 +566,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.tradeCollector.OnProfit(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
log.Infof("generated profit: %v", profit)
p := s.state.Position.NewProfit(trade, profit, netProfit)
p.Strategy = ID
p.StrategyInstanceID = instanceID
s.state.ProfitStats.AddProfit(p)
s.Notify(&p)
s.Notify(&s.state.ProfitStats)

View File

@ -60,30 +60,28 @@ func (p *Position) NewProfit(trade Trade, profit, netProfit fixedpoint.Value) Pr
QuoteCurrency: p.QuoteCurrency,
BaseCurrency: p.BaseCurrency,
AverageCost: p.AverageCost,
// profit related fields
Profit: profit,
NetProfit: netProfit,
ProfitMargin: profit.Div(trade.QuoteQuantity),
NetProfitMargin: netProfit.Div(trade.QuoteQuantity),
// trade related fields
TradeID: trade.ID,
Price: trade.Price,
Quantity: trade.Quantity,
QuoteQuantity: trade.QuoteQuantity,
IsMaker: trade.IsMaker,
IsBuyer: trade.IsBuyer,
Side: trade.Side,
Fee: trade.Fee,
FeeCurrency: trade.FeeCurrency,
TradedAt: trade.Time.Time(),
IsFutures: trade.IsFutures,
IsMargin: trade.IsMargin,
IsIsolated: trade.IsIsolated,
TradeID: trade.ID,
Side: trade.Side,
IsBuyer: trade.IsBuyer,
IsMaker: trade.IsMaker,
Price: trade.Price,
Quantity: trade.Quantity,
QuoteQuantity: trade.QuoteQuantity,
// FeeInUSD: 0,
Fee: trade.Fee,
FeeCurrency: trade.FeeCurrency,
Exchange: trade.Exchange,
IsMargin: trade.IsMargin,
IsFutures: trade.IsFutures,
IsIsolated: trade.IsIsolated,
TradedAt: trade.Time.Time(),
}
}