mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
bbgo: make position object optional for trade collector
This commit is contained in:
parent
cae8bc2882
commit
f191d3c091
|
@ -115,21 +115,26 @@ 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{}{}
|
||||||
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
if c.position != nil {
|
||||||
if madeProfit {
|
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
||||||
p := c.position.NewProfit(trade, profit, netProfit)
|
if madeProfit {
|
||||||
c.EmitTrade(trade, profit, netProfit)
|
p := c.position.NewProfit(trade, profit, netProfit)
|
||||||
c.EmitProfit(trade, &p)
|
c.EmitTrade(trade, profit, netProfit)
|
||||||
|
c.EmitProfit(trade, &p)
|
||||||
|
} else {
|
||||||
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
|
c.EmitProfit(trade, nil)
|
||||||
|
}
|
||||||
|
positionChanged = true
|
||||||
} else {
|
} else {
|
||||||
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
c.EmitProfit(trade, nil)
|
|
||||||
}
|
}
|
||||||
positionChanged = true
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if positionChanged {
|
|
||||||
|
if positionChanged && c.position != nil {
|
||||||
c.EmitPositionUpdate(c.position)
|
c.EmitPositionUpdate(c.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,16 +154,21 @@ func (c *TradeCollector) processTrade(trade types.Trade) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
if c.position != nil {
|
||||||
if madeProfit {
|
profit, netProfit, madeProfit := c.position.AddTrade(trade)
|
||||||
p := c.position.NewProfit(trade, profit, netProfit)
|
if madeProfit {
|
||||||
c.EmitTrade(trade, profit, netProfit)
|
p := c.position.NewProfit(trade, profit, netProfit)
|
||||||
c.EmitProfit(trade, &p)
|
c.EmitTrade(trade, profit, netProfit)
|
||||||
|
c.EmitProfit(trade, &p)
|
||||||
|
} else {
|
||||||
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
|
c.EmitProfit(trade, nil)
|
||||||
|
}
|
||||||
|
c.EmitPositionUpdate(c.position)
|
||||||
} else {
|
} else {
|
||||||
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
c.EmitTrade(trade, fixedpoint.Zero, fixedpoint.Zero)
|
||||||
c.EmitProfit(trade, nil)
|
|
||||||
}
|
}
|
||||||
c.EmitPositionUpdate(c.position)
|
|
||||||
c.doneTrades[key] = struct{}{}
|
c.doneTrades[key] = struct{}{}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user