Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: emit position when position updated and reset #1609

Merged
merged 2 commits into from Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.