mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
core: add exceededMaximumTradeStoreSize check
This commit is contained in:
parent
685f332495
commit
21c8593c45
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
const TradeExpiryTime = 3 * time.Hour
|
||||
const PruneTriggerNumOfTrades = 10_000
|
||||
const MaximumTradeStoreSize = 1_000
|
||||
|
||||
type TradeStore struct {
|
||||
// any created trades for tracking trades
|
||||
|
@ -142,6 +142,10 @@ func (s *TradeStore) isCoolTrade(trade types.Trade) bool {
|
|||
return !s.lastTradeTime.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > time.Hour
|
||||
}
|
||||
|
||||
func (s *TradeStore) exceededMaximumTradeStoreSize() bool {
|
||||
return len(s.trades) > MaximumTradeStoreSize
|
||||
}
|
||||
|
||||
func (s *TradeStore) BindStream(stream types.Stream) {
|
||||
stream.OnTradeUpdate(func(trade types.Trade) {
|
||||
s.Add(trade)
|
||||
|
@ -149,7 +153,7 @@ func (s *TradeStore) BindStream(stream types.Stream) {
|
|||
|
||||
if s.EnablePrune {
|
||||
stream.OnTradeUpdate(func(trade types.Trade) {
|
||||
if s.isCoolTrade(trade) {
|
||||
if s.isCoolTrade(trade) || s.exceededMaximumTradeStoreSize() {
|
||||
s.Prune(time.Time(trade.Time))
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user