Skip to content

Commit 7c5348d

Browse files
committed
FEATURE: emit position when position updated and reset
1 parent f246077 commit 7c5348d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/strategy/dca2/state.go

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

209+
// emit position
210+
s.EmitPosition(s.Position)
211+
209212
// store into redis
210213
bbgo.Sync(ctx, s)
211214

pkg/strategy/dca2/strategy.go

+11
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
226226

227227
// update take profit price here
228228
s.updateTakeProfitPrice()
229+
230+
// emit position update
231+
s.EmitPosition(position)
229232
})
230233

231234
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
@@ -416,6 +419,14 @@ func (s *Strategy) ContinueNextRound() {
416419
s.nextRoundPaused = false
417420
}
418421

422+
func (s *Strategy) GetTakeProfitPrice() fixedpoint.Value {
423+
if s.Position.Base == 0 {
424+
return fixedpoint.Zero
425+
}
426+
427+
return s.takeProfitPrice
428+
}
429+
419430
func (s *Strategy) UpdateProfitStatsUntilSuccessful(ctx context.Context) error {
420431
var op = func() error {
421432
if updated, err := s.UpdateProfitStats(ctx); err != nil {

0 commit comments

Comments
 (0)