Skip to content

Commit 63d13d5

Browse files
committed
use existing TradeCollector's EmitPositionUpdate
1 parent 0616c73 commit 63d13d5

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

pkg/strategy/dca2/state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (s *Strategy) runTakeProfitReady(ctx context.Context, next State) {
216216
s.Position.Reset()
217217

218218
// emit position
219-
s.EmitPosition(s.Position)
219+
s.OrderExecutor.TradeCollector().EmitPositionUpdate(s.Position)
220220

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

pkg/strategy/dca2/strategy.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ type Strategy struct {
101101

102102
// callbacks
103103
common.StatusCallbacks
104-
positionCallbacks []func(*types.Position)
105-
profitCallbacks []func(*ProfitStats)
104+
profitCallbacks []func(*ProfitStats)
106105
}
107106

108107
func (s *Strategy) ID() string {
@@ -237,9 +236,6 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
237236

238237
// update take profit price here
239238
s.updateTakeProfitPrice()
240-
241-
// emit position update
242-
s.EmitPosition(position)
243239
})
244240

245241
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
@@ -283,6 +279,11 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
283279
return
284280
}
285281

282+
if s.takeProfitPrice.IsZero() {
283+
s.logger.Warn("take profit price should not be 0 when there is at least one open-position order filled, please check it")
284+
return
285+
}
286+
286287
compRes := kline.Close.Compare(s.takeProfitPrice)
287288
// price doesn't hit the take profit price
288289
if compRes < 0 {
@@ -430,14 +431,6 @@ func (s *Strategy) ContinueNextRound() {
430431
s.nextRoundPaused = false
431432
}
432433

433-
func (s *Strategy) GetTakeProfitPrice() fixedpoint.Value {
434-
if s.Position.Base == 0 {
435-
return fixedpoint.Zero
436-
}
437-
438-
return s.takeProfitPrice
439-
}
440-
441434
func (s *Strategy) UpdateProfitStatsUntilSuccessful(ctx context.Context) error {
442435
var op = func() error {
443436
if updated, err := s.UpdateProfitStats(ctx); err != nil {

pkg/strategy/dca2/strategy_callbacks.go

-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)