Skip to content

Commit

Permalink
use existing TradeCollector's EmitPositionUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
kbearXD committed Apr 11, 2024
1 parent 0616c73 commit 63d13d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pkg/strategy/dca2/state.go
Expand Up @@ -216,7 +216,7 @@ func (s *Strategy) runTakeProfitReady(ctx context.Context, next State) {
s.Position.Reset()

// emit position
s.EmitPosition(s.Position)
s.OrderExecutor.TradeCollector().EmitPositionUpdate(s.Position)

// store into redis
bbgo.Sync(ctx, s)
Expand Down
19 changes: 6 additions & 13 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 @@ -237,9 +236,6 @@ 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 @@ -283,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 Expand Up @@ -430,14 +431,6 @@ 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
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 63d13d5

Please sign in to comment.