From 0616c73a887dcc43f0d4096c9971833a28373a56 Mon Sep 17 00:00:00 2001 From: kbearXD Date: Tue, 26 Mar 2024 16:42:29 +0800 Subject: [PATCH] FEATURE: emit position when position updated and reset --- pkg/strategy/dca2/state.go | 3 +++ pkg/strategy/dca2/strategy.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/strategy/dca2/state.go b/pkg/strategy/dca2/state.go index 79594d1e5..c91fcfa0c 100644 --- a/pkg/strategy/dca2/state.go +++ b/pkg/strategy/dca2/state.go @@ -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) diff --git a/pkg/strategy/dca2/strategy.go b/pkg/strategy/dca2/strategy.go index 348cddb6c..35d377e7f 100644 --- a/pkg/strategy/dca2/strategy.go +++ b/pkg/strategy/dca2/strategy.go @@ -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 {