mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1621 from c9s/kbearXD/dca2/emit-position
FEATURE: [dca2] add position callback
This commit is contained in:
commit
489889d1e6
|
@ -100,7 +100,8 @@ type Strategy struct {
|
|||
|
||||
// callbacks
|
||||
common.StatusCallbacks
|
||||
profitCallbacks []func(*ProfitStats)
|
||||
profitCallbacks []func(*ProfitStats)
|
||||
positionUpdateCallbacks []func(*types.Position)
|
||||
}
|
||||
|
||||
func (s *Strategy) ID() string {
|
||||
|
@ -229,6 +230,9 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
|||
|
||||
// update take profit price here
|
||||
s.updateTakeProfitPrice()
|
||||
|
||||
// emit position update
|
||||
s.EmitPositionUpdate(position)
|
||||
})
|
||||
|
||||
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
package dca2
|
||||
|
||||
import (
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func (s *Strategy) OnProfit(cb func(*ProfitStats)) {
|
||||
s.profitCallbacks = append(s.profitCallbacks, cb)
|
||||
}
|
||||
|
@ -11,3 +15,13 @@ func (s *Strategy) EmitProfit(profitStats *ProfitStats) {
|
|||
cb(profitStats)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Strategy) OnPositionUpdate(cb func(*types.Position)) {
|
||||
s.positionUpdateCallbacks = append(s.positionUpdateCallbacks, cb)
|
||||
}
|
||||
|
||||
func (s *Strategy) EmitPositionUpdate(position *types.Position) {
|
||||
for _, cb := range s.positionUpdateCallbacks {
|
||||
cb(position)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user