xalign: graceful cancel orders when shutting down

This commit is contained in:
c9s 2023-06-13 17:29:19 +08:00
parent a126bc3bb6
commit 1855e52838
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"time"
log "github.com/sirupsen/logrus"
@ -234,6 +235,15 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
s.orderBooks[sessionName] = orderBook
}
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
for n, session := range s.sessions {
if ob, ok := s.orderBooks[n]; ok {
_ = ob.GracefulCancel(ctx, session.Exchange)
}
}
})
go func() {
s.align(ctx, s.sessions)