Skip to content

Commit

Permalink
Merge pull request #1609 from c9s/kbearXD/dca2/emit-position
Browse files Browse the repository at this point in the history
FEATURE: emit position when position updated and reset
  • Loading branch information
kbearXD committed Apr 15, 2024
2 parents e3a4887 + 63d13d5 commit 27ea566
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 3 additions & 0 deletions pkg/strategy/dca2/state.go
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.OrderExecutor.TradeCollector().EmitPositionUpdate(s.Position)

// store into redis
bbgo.Sync(ctx, s)

Expand Down
8 changes: 6 additions & 2 deletions pkg/strategy/dca2/strategy.go
Expand Up @@ -101,8 +101,7 @@ type Strategy struct {

// callbacks
common.StatusCallbacks
positionCallbacks []func(*types.Position)
profitCallbacks []func(*ProfitStats)
profitCallbacks []func(*ProfitStats)
}

func (s *Strategy) ID() string {
Expand Down Expand Up @@ -280,6 +279,11 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
return
}

if s.takeProfitPrice.IsZero() {
s.logger.Warn("take profit price should not be 0 when there is at least one open-position order filled, please check it")
return
}

compRes := kline.Close.Compare(s.takeProfitPrice)
// price doesn't hit the take profit price
if compRes < 0 {
Expand Down
14 changes: 0 additions & 14 deletions pkg/strategy/dca2/strategy_callbacks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27ea566

Please sign in to comment.