1、移除策略u下单缓存

This commit is contained in:
2025-04-12 18:32:36 +08:00
parent e3a737a7d6
commit 79af1ab2c1
6 changed files with 135 additions and 5 deletions

View File

@ -251,11 +251,15 @@ func (e *AddPosition) CalculateAmount(req dto.ManuallyCover, totalNum, lastPrice
// mainOrderId 主单id
// symbolType 1现货 2合约
func MainClosePositionClearCache(mainId int, symbolType int) {
strategyDto := dto.StrategyOrderRedisList{}
if symbolType == 1 {
keySpotStop := fmt.Sprintf(rediskey.SpotStopLossList, global.EXCHANGE_BINANCE)
keySpotAddposition := fmt.Sprintf(rediskey.SpotAddPositionList, global.EXCHANGE_BINANCE)
spotStopArray, _ := helper.DefaultRedis.GetAllList(keySpotStop)
spotAddpositionArray, _ := helper.DefaultRedis.GetAllList(keySpotAddposition)
spotStrategyKey := fmt.Sprintf(rediskey.StrategySpotOrderList, global.EXCHANGE_BINANCE)
spotStrategyList, _ := helper.DefaultRedis.GetAllList(spotStrategyKey)
var position AddPositionList
var stop dto.StopLossRedisList
@ -279,11 +283,23 @@ func MainClosePositionClearCache(mainId int, symbolType int) {
}
}
for _, item := range spotStrategyList {
sonic.Unmarshal([]byte(item), &strategyDto)
if strategyDto.Id == mainId {
if _, err := helper.DefaultRedis.LRem(spotStrategyKey, item); err != nil {
logger.Errorf("id:%d 移除缓存失败,err:%v", mainId, err)
}
}
}
} else {
keyFutStop := fmt.Sprintf(rediskey.FuturesAddPositionList, global.EXCHANGE_BINANCE)
keyFutAddposition := fmt.Sprintf(rediskey.FuturesStopLossList, global.EXCHANGE_BINANCE)
futAddpositionArray, _ := helper.DefaultRedis.GetAllList(keyFutStop)
futStopArray, _ := helper.DefaultRedis.GetAllList(keyFutAddposition)
futStrategyKey := fmt.Sprintf(rediskey.StrategyFutOrderList, global.EXCHANGE_BINANCE)
futStrategyList, _ := helper.DefaultRedis.GetAllList(futStrategyKey)
var position AddPositionList
var stop dto.StopLossRedisList
@ -306,6 +322,16 @@ func MainClosePositionClearCache(mainId int, symbolType int) {
helper.DefaultRedis.LRem(keyFutStop, item)
}
}
for _, item := range futStrategyList {
sonic.Unmarshal([]byte(item), &strategyDto)
if strategyDto.Id == mainId {
if _, err := helper.DefaultRedis.LRem(futStrategyKey, item); err != nil {
logger.Errorf("id:%d 移除缓存失败,err:%v", mainId, err)
}
}
}
}
}