From 7c5348de2b6fb458f7adf060a59a091e9b047f7b 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 22f593437a..e22aea2a67 100644 --- a/pkg/strategy/dca2/state.go +++ b/pkg/strategy/dca2/state.go @@ -206,6 +206,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 f4c523a076..c417d75b88 100644 --- a/pkg/strategy/dca2/strategy.go +++ b/pkg/strategy/dca2/strategy.go @@ -226,6 +226,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) { @@ -416,6 +419,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 {