Skip to content

Commit 27ea566

Browse files
authored
Merge pull request #1609 from c9s/kbearXD/dca2/emit-position
FEATURE: emit position when position updated and reset
2 parents e3a4887 + 63d13d5 commit 27ea566

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

pkg/strategy/dca2/state.go

+3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ func (s *Strategy) runTakeProfitReady(ctx context.Context, next State) {
215215
// reset position and open new round for profit stats before position opening
216216
s.Position.Reset()
217217

218+
// emit position
219+
s.OrderExecutor.TradeCollector().EmitPositionUpdate(s.Position)
220+
218221
// store into redis
219222
bbgo.Sync(ctx, s)
220223

pkg/strategy/dca2/strategy.go

+6-2
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 {
@@ -280,6 +279,11 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
280279
return
281280
}
282281

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+
283287
compRes := kline.Close.Compare(s.takeProfitPrice)
284288
// price doesn't hit the take profit price
285289
if compRes < 0 {

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)