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 Mar 27, 2024
1 parent f246077 commit 7c5348d
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
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions pkg/strategy/dca2/strategy.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -416,6 +419,14 @@ func (s *Strategy) ContinueNextRound() {
s.nextRoundPaused = false
}

func (s *Strategy) GetTakeProfitPrice() fixedpoint.Value {
if s.Position.Base == 0 {

Check failure on line 423 in pkg/strategy/dca2/strategy.go

View workflow job for this annotation

GitHub Actions / build (6.2, 1.20)

cannot convert 0 (untyped int constant) to type struct{coef uint64; sign int8; exp int}
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 7c5348d

Please sign in to comment.