Files
coin/trade/lock.go
2026-01-09 15:48:31 +08:00

31 lines
540 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package trade
import (
"time"
cache "github.com/patrickmn/go-cache"
)
var MemCache *cache.Cache
func NewLock() {
if MemCache != nil {
return
}
MemCache = cache.New(5*time.Minute, 10*time.Minute)
}
// 锁仓可以采用MemCache,Redis,File等。
func IsLock(symbol, side string) bool {
lockKey := symbol + ":" + side
_, found := MemCache.Get(lockKey)
if found {
return true
}
return false
}
func SetLock(symbol, side string, duration int64) {
MemCache.Set(symbol+":"+side, true, time.Duration(duration)*time.Second)
}