mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
xmaker: prune expired orders
This commit is contained in:
parent
bfe8ce9f2c
commit
5fbb06639d
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
@ -138,6 +139,24 @@ func (s *OrderStore) BindStream(stream types.Stream) {
|
|||
})
|
||||
}
|
||||
|
||||
func (s *OrderStore) Prune(expiryDuration time.Duration) {
|
||||
cutOffTime := time.Now().Add(-expiryDuration)
|
||||
orders := make(map[uint64]types.Order, len(s.orders))
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
for idx, o := range s.orders {
|
||||
if o.UpdateTime.Time().Before(cutOffTime) {
|
||||
continue
|
||||
}
|
||||
|
||||
orders[idx] = o
|
||||
}
|
||||
|
||||
s.orders = orders
|
||||
}
|
||||
|
||||
func (s *OrderStore) HandleOrderUpdate(order types.Order) {
|
||||
|
||||
switch order.Status {
|
||||
|
|
|
@ -1475,6 +1475,25 @@ func (s *Strategy) accountUpdater(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Strategy) houseCleanWorker(ctx context.Context) {
|
||||
expiryDuration := 3 * time.Hour
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case <-ticker.C:
|
||||
s.orderStore.Prune(expiryDuration)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Strategy) hedgeWorker(ctx context.Context) {
|
||||
ticker := time.NewTicker(util.MillisecondsJitter(s.HedgeInterval.Duration(), 200))
|
||||
defer ticker.Stop()
|
||||
|
@ -1809,6 +1828,7 @@ func (s *Strategy) CrossRun(
|
|||
go s.accountUpdater(ctx)
|
||||
go s.hedgeWorker(ctx)
|
||||
go s.quoteWorker(ctx)
|
||||
go s.houseCleanWorker(ctx)
|
||||
|
||||
if s.RecoverTrade {
|
||||
go s.tradeRecover(ctx)
|
||||
|
|
Loading…
Reference in New Issue
Block a user