mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
core: log trades pruning
This commit is contained in:
parent
b2895a0434
commit
8025d05eac
|
@ -4,6 +4,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -112,14 +114,16 @@ func (s *TradeStore) touchLastTradeTime(trade types.Trade) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pruneExpiredTrades prunes trades that are older than the expiry time
|
// Prune prunes trades that are older than the expiry time
|
||||||
// see TradeExpiryTime
|
// see TradeExpiryTime (24 hours)
|
||||||
func (s *TradeStore) pruneExpiredTrades(curTime time.Time) {
|
func (s *TradeStore) Prune(curTime time.Time) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
var trades = make(map[uint64]types.Trade)
|
var trades = make(map[uint64]types.Trade)
|
||||||
var cutOffTime = curTime.Add(-TradeExpiryTime)
|
var cutOffTime = curTime.Add(-TradeExpiryTime)
|
||||||
|
|
||||||
|
log.Infof("pruning expired trades, cutoff time = %s", cutOffTime.String())
|
||||||
for _, trade := range s.trades {
|
for _, trade := range s.trades {
|
||||||
if trade.Time.Before(cutOffTime) {
|
if trade.Time.Before(cutOffTime) {
|
||||||
continue
|
continue
|
||||||
|
@ -129,15 +133,13 @@ func (s *TradeStore) pruneExpiredTrades(curTime time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.trades = trades
|
s.trades = trades
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TradeStore) Prune(curTime time.Time) {
|
log.Infof("trade pruning done, size: %d", len(trades))
|
||||||
s.pruneExpiredTrades(curTime)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStore) isCoolTrade(trade types.Trade) bool {
|
func (s *TradeStore) isCoolTrade(trade types.Trade) bool {
|
||||||
// if the time of last trade is over 1 hour, we call it's cool trade
|
// if the duration between the current trade and the last trade is over 1 hour, we call it "cool trade"
|
||||||
return s.lastTradeTime != (time.Time{}) && time.Time(trade.Time).Sub(s.lastTradeTime) > time.Hour
|
return !s.lastTradeTime.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > time.Hour
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStore) BindStream(stream types.Stream) {
|
func (s *TradeStore) BindStream(stream types.Stream) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user