bbgo: make position object optional for trade collector

This commit is contained in:
c9s 2022-08-04 21:13:13 +08:00
parent cae8bc2882
commit f191d3c091
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -115,6 +115,7 @@ func (c *TradeCollector) Process() bool {
if c.orderStore.Exists(trade.OrderID) {
c.doneTrades[key] = struct{}{}
if c.position != nil {
profit, netProfit, madeProfit := c.position.AddTrade(trade)
if madeProfit {
p := c.position.NewProfit(trade, profit, netProfit)
@ -125,11 +126,15 @@ func (c *TradeCollector) Process() bool {
c.EmitProfit(trade, nil)
}
positionChanged = true
} else {
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
}
return true
}
return false
})
if positionChanged {
if positionChanged && c.position != nil {
c.EmitPositionUpdate(c.position)
}
@ -149,6 +154,7 @@ func (c *TradeCollector) processTrade(trade types.Trade) bool {
return false
}
if c.position != nil {
profit, netProfit, madeProfit := c.position.AddTrade(trade)
if madeProfit {
p := c.position.NewProfit(trade, profit, netProfit)
@ -159,6 +165,10 @@ func (c *TradeCollector) processTrade(trade types.Trade) bool {
c.EmitProfit(trade, nil)
}
c.EmitPositionUpdate(c.position)
} else {
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
}
c.doneTrades[key] = struct{}{}
return true
}