mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
bbgo: optimize order cancel for back-testing
This commit is contained in:
parent
58c819bd75
commit
19d8013f49
|
@ -69,9 +69,14 @@ func (b *ActiveOrderBook) waitAllClear(ctx context.Context, waitTime, timeout ti
|
|||
|
||||
// GracefulCancel cancels the active orders gracefully
|
||||
func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange) error {
|
||||
waitTime := CancelOrderWaitTime
|
||||
// optimize order cancel for back-testing
|
||||
if IsBackTesting {
|
||||
orders := b.Orders()
|
||||
return ex.CancelOrders(context.Background(), orders...)
|
||||
}
|
||||
|
||||
log.Debugf("[ActiveOrderBook] gracefully cancelling %s orders...", b.Symbol)
|
||||
waitTime := CancelOrderWaitTime
|
||||
|
||||
startTime := time.Now()
|
||||
// ensure every order is cancelled
|
||||
|
|
|
@ -37,6 +37,16 @@ func init() {
|
|||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// IsBackTesting is a global variable that indicates the current environment is back-test or not.
|
||||
var IsBackTesting = false
|
||||
|
||||
var BackTestService *service.BacktestService
|
||||
|
||||
func SetBackTesting(s *service.BacktestService) {
|
||||
BackTestService = s
|
||||
IsBackTesting = true
|
||||
}
|
||||
|
||||
var LoadedExchangeStrategies = make(map[string]SingleExchangeStrategy)
|
||||
var LoadedCrossExchangeStrategies = make(map[string]CrossExchangeStrategy)
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@ var BacktestCmd = &cobra.Command{
|
|||
|
||||
backtestService := &service.BacktestService{DB: environ.DatabaseService.DB}
|
||||
environ.BacktestService = backtestService
|
||||
bbgo.SetBackTesting(backtestService)
|
||||
|
||||
if len(sessionName) > 0 {
|
||||
userConfig.Backtest.Sessions = []string{sessionName}
|
||||
|
|
Loading…
Reference in New Issue
Block a user