mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +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)
|
||||
|
||||
|
@ -69,18 +79,18 @@ const (
|
|||
|
||||
// Environment presents the real exchange data layer
|
||||
type Environment struct {
|
||||
DatabaseService *service.DatabaseService
|
||||
OrderService *service.OrderService
|
||||
TradeService *service.TradeService
|
||||
ProfitService *service.ProfitService
|
||||
PositionService *service.PositionService
|
||||
BacktestService *service.BacktestService
|
||||
RewardService *service.RewardService
|
||||
MarginService *service.MarginService
|
||||
SyncService *service.SyncService
|
||||
AccountService *service.AccountService
|
||||
WithdrawService *service.WithdrawService
|
||||
DepositService *service.DepositService
|
||||
DatabaseService *service.DatabaseService
|
||||
OrderService *service.OrderService
|
||||
TradeService *service.TradeService
|
||||
ProfitService *service.ProfitService
|
||||
PositionService *service.PositionService
|
||||
BacktestService *service.BacktestService
|
||||
RewardService *service.RewardService
|
||||
MarginService *service.MarginService
|
||||
SyncService *service.SyncService
|
||||
AccountService *service.AccountService
|
||||
WithdrawService *service.WithdrawService
|
||||
DepositService *service.DepositService
|
||||
|
||||
// startTime is the time of start point (which is used in the backtest)
|
||||
startTime time.Time
|
||||
|
@ -105,7 +115,7 @@ func NewEnvironment() *Environment {
|
|||
sessions: make(map[string]*ExchangeSession),
|
||||
startTime: now,
|
||||
|
||||
syncStatus: SyncNotStarted,
|
||||
syncStatus: SyncNotStarted,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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