FEATURE: emit position when position updated and reset

This commit is contained in:
kbearXD 2024-03-26 16:42:29 +08:00
parent e3a4887302
commit 0616c73a88
2 changed files with 14 additions and 0 deletions

View File

@ -215,6 +215,9 @@ func (s *Strategy) runTakeProfitReady(ctx context.Context, next State) {
// reset position and open new round for profit stats before position opening
s.Position.Reset()
// emit position
s.EmitPosition(s.Position)
// store into redis
bbgo.Sync(ctx, s)

View File

@ -237,6 +237,9 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
// update take profit price here
s.updateTakeProfitPrice()
// emit position update
s.EmitPosition(position)
})
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
@ -427,6 +430,14 @@ func (s *Strategy) ContinueNextRound() {
s.nextRoundPaused = false
}
func (s *Strategy) GetTakeProfitPrice() fixedpoint.Value {
if s.Position.Base == 0 {
return fixedpoint.Zero
}
return s.takeProfitPrice
}
func (s *Strategy) UpdateProfitStatsUntilSuccessful(ctx context.Context) error {
var op = func() error {
if updated, err := s.UpdateProfitStats(ctx); err != nil {