mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
core: pull out cool trade period to a constant
This commit is contained in:
parent
21c8593c45
commit
4e26b9d2ad
|
@ -10,6 +10,7 @@ import (
|
|||
)
|
||||
|
||||
const TradeExpiryTime = 3 * time.Hour
|
||||
const CoolTradePeriod = 1 * time.Hour
|
||||
const MaximumTradeStoreSize = 1_000
|
||||
|
||||
type TradeStore struct {
|
||||
|
@ -139,7 +140,7 @@ func (s *TradeStore) Prune(curTime time.Time) {
|
|||
|
||||
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"
|
||||
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 {
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestTradeStore_Prune(t *testing.T) {
|
|||
store := NewTradeStore()
|
||||
store.Add(
|
||||
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: 4, Time: types.Time(now.Add(-1 * time.Minute))},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user