-
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: [dca2] when all open-position orders are filled, place the t…
…ake-profit order
- Loading branch information
Showing
5 changed files
with
77 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dca2 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/c9s/bbgo/pkg/bbgo" | ||
"github.com/c9s/bbgo/pkg/util" | ||
) | ||
|
||
func (s *Strategy) runBackgrounTask(ctx context.Context) { | ||
s.logger.Info("run background task") | ||
|
||
// recover active orders | ||
recoverActiveOrdersInterval := util.MillisecondsJitter(10*time.Minute, 5*60*1000) | ||
recoverActiveOrdersTicker := time.NewTicker(recoverActiveOrdersInterval) | ||
defer recoverActiveOrdersTicker.Stop() | ||
|
||
// sync strategy | ||
syncPersistenceTicker := time.NewTicker(1 * time.Hour) | ||
defer syncPersistenceTicker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-syncPersistenceTicker.C: | ||
bbgo.Sync(ctx, s) | ||
case <-recoverActiveOrdersTicker.C: | ||
if err := s.recoverActiveOrders(ctx); err != nil { | ||
s.logger.WithError(err).Warn(err, "failed to recover active orders") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters