Skip to content

Commit

Permalink
FEATURE: emit position when position updated and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
kbearXD committed Apr 11, 2024
1 parent e3a4887 commit 0616c73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/strategy/dca2/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions pkg/strategy/dca2/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0616c73

Please sign in to comment.