core: pull out cool trade period to a constant

This commit is contained in:
c9s 2023-12-12 18:25:09 +08:00
parent 21c8593c45
commit 4e26b9d2ad
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 3 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import (
) )
const TradeExpiryTime = 3 * time.Hour const TradeExpiryTime = 3 * time.Hour
const CoolTradePeriod = 1 * time.Hour
const MaximumTradeStoreSize = 1_000 const MaximumTradeStoreSize = 1_000
type TradeStore struct { type TradeStore struct {
@ -139,7 +140,7 @@ func (s *TradeStore) Prune(curTime time.Time) {
func (s *TradeStore) isCoolTrade(trade types.Trade) bool { func (s *TradeStore) isCoolTrade(trade types.Trade) bool {
// if the duration between the current trade and the last trade is over 1 hour, we call it "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.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > time.Hour return !s.lastTradeTime.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > CoolTradePeriod
} }
func (s *TradeStore) exceededMaximumTradeStoreSize() bool { func (s *TradeStore) exceededMaximumTradeStoreSize() bool {

View File

@ -30,7 +30,7 @@ func TestTradeStore_Prune(t *testing.T) {
store := NewTradeStore() store := NewTradeStore()
store.Add( store.Add(
types.Trade{ID: 1, Time: types.Time(now.Add(-25 * time.Hour))}, types.Trade{ID: 1, Time: types.Time(now.Add(-25 * time.Hour))},
types.Trade{ID: 2, Time: types.Time(now.Add(-23 * time.Hour))}, types.Trade{ID: 2, Time: types.Time(now.Add(-2 * time.Hour))},
types.Trade{ID: 3, Time: types.Time(now.Add(-2 * time.Minute))}, types.Trade{ID: 3, Time: types.Time(now.Add(-2 * time.Minute))},
types.Trade{ID: 4, Time: types.Time(now.Add(-1 * time.Minute))}, types.Trade{ID: 4, Time: types.Time(now.Add(-1 * time.Minute))},
) )