mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
bbgo: make position object optional for trade collector
This commit is contained in:
parent
cae8bc2882
commit
f191d3c091
|
@ -115,6 +115,7 @@ func (c *TradeCollector) Process() bool {
|
||||||
|
|
||||||
if c.orderStore.Exists(trade.OrderID) {
|
if c.orderStore.Exists(trade.OrderID) {
|
||||||
c.doneTrades[key] = struct{}{}
|
c.doneTrades[key] = struct{}{}
|
||||||
|
if c.position != nil {
|
||||||
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
||||||
if madeProfit {
|
if madeProfit {
|
||||||
p := c.position.NewProfit(trade, profit, netProfit)
|
p := c.position.NewProfit(trade, profit, netProfit)
|
||||||
|
@ -125,11 +126,15 @@ func (c *TradeCollector) Process() bool {
|
||||||
c.EmitProfit(trade, nil)
|
c.EmitProfit(trade, nil)
|
||||||
}
|
}
|
||||||
positionChanged = true
|
positionChanged = true
|
||||||
|
} else {
|
||||||
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if positionChanged {
|
|
||||||
|
if positionChanged && c.position != nil {
|
||||||
c.EmitPositionUpdate(c.position)
|
c.EmitPositionUpdate(c.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +154,7 @@ func (c *TradeCollector) processTrade(trade types.Trade) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.position != nil {
|
||||||
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
||||||
if madeProfit {
|
if madeProfit {
|
||||||
p := c.position.NewProfit(trade, profit, netProfit)
|
p := c.position.NewProfit(trade, profit, netProfit)
|
||||||
|
@ -159,6 +165,10 @@ func (c *TradeCollector) processTrade(trade types.Trade) bool {
|
||||||
c.EmitProfit(trade, nil)
|
c.EmitProfit(trade, nil)
|
||||||
}
|
}
|
||||||
c.EmitPositionUpdate(c.position)
|
c.EmitPositionUpdate(c.position)
|
||||||
|
} else {
|
||||||
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
|
}
|
||||||
|
|
||||||
c.doneTrades[key] = struct{}{}
|
c.doneTrades[key] = struct{}{}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user