1、子订单增加过期时间
This commit is contained in:
@ -7,10 +7,14 @@ import (
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/const/rediskey"
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/helper"
|
||||
"go-admin/pkg/utility"
|
||||
"go-admin/services/binanceservice"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/go-admin-team/go-admin-core/logger"
|
||||
"github.com/go-admin-team/go-admin-core/sdk"
|
||||
sysservice "github.com/go-admin-team/go-admin-core/sdk/service"
|
||||
"gorm.io/gorm"
|
||||
@ -100,9 +104,95 @@ func (receiver DeleteExpireOrder) Exec(arg interface{}) error {
|
||||
//删除主单
|
||||
db.Model(&models.LinePreOrder{}).Where("id = ?", order.Id).Unscoped().Delete(&models.LinePreOrder{})
|
||||
}
|
||||
|
||||
//子订单 加仓、检查过期
|
||||
childOrders := make([]models.LinePreOrder, 0)
|
||||
err = db.Model(&models.LinePreOrder{}).Where("pid >0 AND order_type IN (0,4) AND status=0 AND expire_time <= ?", time.Now()).Select("id", "order_category", "order_type").Find(&childOrders).Error
|
||||
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
removeExpirateChildOrder(childOrders, db)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeExpirateChildOrder(childOrders []models.LinePreOrder, db *gorm.DB) {
|
||||
childOrderId := make([]int, 0)
|
||||
futAddKey := fmt.Sprintf(rediskey.FuturesAddPositionList, global.EXCHANGE_BINANCE)
|
||||
spotAddKey := fmt.Sprintf(rediskey.SpotAddPositionList, global.EXCHANGE_BINANCE)
|
||||
futReduceKey := fmt.Sprintf(rediskey.FuturesReduceList, global.EXCHANGE_BINANCE)
|
||||
spotReduceKey := fmt.Sprintf(rediskey.SpotReduceList, global.EXCHANGE_BINANCE)
|
||||
futAddPositionStr, _ := helper.DefaultRedis.GetAllList(futAddKey)
|
||||
spotAdPositionStr, _ := helper.DefaultRedis.GetAllList(spotAddKey)
|
||||
futReduceStr, _ := helper.DefaultRedis.GetAllList(futReduceKey)
|
||||
spotReduceStr, _ := helper.DefaultRedis.GetAllList(spotReduceKey)
|
||||
futAddPositionCache := binanceservice.AddPositionList{}
|
||||
spotAddPositionCache := binanceservice.AddPositionList{}
|
||||
futReduceCache := binanceservice.ReduceListItem{}
|
||||
spotReduceCache := binanceservice.ReduceListItem{}
|
||||
futAddPositionMap := map[int]string{}
|
||||
spotAddPositionMap := map[int]string{}
|
||||
futReduceMap := map[int]string{}
|
||||
spotReduceMap := map[int]string{}
|
||||
|
||||
for _, item := range futAddPositionStr {
|
||||
sonic.Unmarshal([]byte(item), &futAddPositionCache)
|
||||
futAddPositionMap[futAddPositionCache.Id] = item
|
||||
}
|
||||
|
||||
for _, item := range spotAdPositionStr {
|
||||
sonic.Unmarshal([]byte(item), &spotAddPositionCache)
|
||||
spotAddPositionMap[spotAddPositionCache.Id] = item
|
||||
}
|
||||
|
||||
for _, item := range futReduceStr {
|
||||
sonic.Unmarshal([]byte(item), &futReduceCache)
|
||||
futReduceMap[futReduceCache.Id] = item
|
||||
}
|
||||
|
||||
for _, item := range spotReduceStr {
|
||||
sonic.Unmarshal([]byte(item), &spotReduceCache)
|
||||
spotReduceMap[spotReduceCache.Id] = item
|
||||
}
|
||||
|
||||
for _, childOrder := range childOrders {
|
||||
switch {
|
||||
//加仓单
|
||||
case childOrder.OrderType == 0 && childOrder.OrderCategory == 3:
|
||||
if val, ok := futAddPositionMap[childOrder.Id]; ok {
|
||||
helper.DefaultRedis.LRem(futAddKey, val)
|
||||
}
|
||||
|
||||
if val, ok := spotAddPositionMap[childOrder.Id]; ok {
|
||||
helper.DefaultRedis.LRem(spotAddKey, val)
|
||||
}
|
||||
|
||||
//减仓单
|
||||
case childOrder.OrderType == 4 && childOrder.OrderCategory == 1:
|
||||
if val, ok := futReduceMap[childOrder.Id]; ok {
|
||||
helper.DefaultRedis.LRem(futReduceKey, val)
|
||||
}
|
||||
|
||||
if val, ok := spotReduceMap[childOrder.Id]; ok {
|
||||
helper.DefaultRedis.LRem(spotReduceKey, val)
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
childOrderId = append(childOrderId, childOrder.Id)
|
||||
}
|
||||
|
||||
idArrays := utility.SplitSlice(childOrderId, 1000)
|
||||
|
||||
for _, idArray := range idArrays {
|
||||
if err := db.Delete(&models.LinePreOrder{}, idArray).Error; err != nil {
|
||||
logger.Errorf("删除过期子订单失败,err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpRange 更新涨跌幅
|
||||
type UpRange struct {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user