This commit is contained in:
2026-01-09 15:48:31 +08:00
parent e32eabbf95
commit c8e189e9c7
28 changed files with 2795 additions and 0 deletions

30
trade/lock.go Normal file
View File

@@ -0,0 +1,30 @@
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)
}