1、波段触发修改

This commit is contained in:
2025-04-21 17:32:57 +08:00
parent 79af1ab2c1
commit 44ba8bfbf1
11 changed files with 314 additions and 71 deletions

View File

@ -46,9 +46,9 @@ const (
SpotTrigger = "spot_trigger_lock:%v_%s" //现货触发 {apiuserid|symbol}
FutTrigger = "fut_trigger_lock:%v_%s" //合约触发 {apiuserid|symbol}
//波段现货触发{apiuserid|symbol}
//波段现货触发{apiuserid|ordersn}
StrategySpotTriggerLock = "strategy_spot_trigger_l:%v_%s"
//波段合约触发{apiuserid|symbol}
//波段合约触发{apiuserid|ordersn}
StrategyFutTriggerLock = "strategy_fut_trigger_l:%v_%s"
//减仓波段合约触发 {apiuserid|symbol}

View File

@ -106,6 +106,9 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
baseInterval = time.Second
}
if baseInterval <= 0 {
baseInterval = time.Millisecond * 100 // 至少 100ms
}
// 随机退避
retryInterval := time.Duration(rand.Int63n(int64(baseInterval))) // 随机退避
if retryInterval < time.Millisecond*100 {
@ -129,6 +132,13 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
return false, ErrFailed
}
func safeRandomDuration(max time.Duration) time.Duration {
if max <= 0 {
return 100 * time.Millisecond // fallback default
}
return time.Duration(rand.Int63n(int64(max)))
}
// Release 释放锁
func (rl *RedisLock) Release() (bool, error) {
return rl.releaseCtx(context.Background())