This commit is contained in:
2025-03-04 15:34:32 +08:00
parent ca92638554
commit 981d2c0108
3 changed files with 13 additions and 7 deletions

View File

@ -261,10 +261,10 @@ func getFuturesPositionNum(apiUserInfo DbModels.LineApiUser, preOrder *DbModels.
positionAmt := utility.StrToDecimal(item.PositionAmt)
//多
if positionAmt.Cmp(decimal.Zero) > 0 && preOrder.Site == "SELL" {
if positionAmt.Cmp(decimal.Zero) > 0 && ((preOrder.OrderType == 0 && preOrder.Site == "BUY") || (preOrder.OrderType != 0 && preOrder.Site == "SELL")) {
num = positionAmt.Abs().Truncate(int32(tradeSet.AmountDigit))
break
} else if positionAmt.Cmp(decimal.Zero) < 0 && preOrder.Site == "BUY" {
} else if positionAmt.Cmp(decimal.Zero) < 0 && ((preOrder.OrderType != 0 && preOrder.Site == "BUY") || (preOrder.OrderType == 0 && preOrder.Site == "SELL")) {
//空
num = positionAmt.Abs().Truncate(int32(tradeSet.AmountDigit))
break
@ -499,7 +499,10 @@ func cancelPositionOtherOrders(apiUserInfo DbModels.LineApiUser, db *gorm.DB, pr
mainId = mainOrder.MainId
}
removeFutLossAndAddPosition(mainId, mainOrder.OrderSn)
mainIds = append(mainIds, mainId)
if !utility.ContainsInt(mainIds, mainId) {
mainIds = append(mainIds, mainId)
}
}
if len(mainIds) > 0 {
@ -620,7 +623,7 @@ func processFutTakeProfitOrder(db *gorm.DB, futApi FutRestApi, order models.Line
}
if err := db.Model(&DbModels.LinePreOrder{}).Where("id = ? and status =0", order.Id).
Updates(map[string]interface{}{"status": "1", "num": num.String()}).Error; err != nil {
Updates(map[string]interface{}{"status": "1", "num": num.String(), "price": order.Price}).Error; err != nil {
logger.Error("合约止盈下单成功,更新状态失败:", order.OrderSn, " err:", err)
}
}

View File

@ -543,7 +543,7 @@ func handleMainOrderFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
if err != nil {
logger.Errorf("取消未成交订单失败, 交易对:%s 主单号:%s, 错误信息:%v", preOrder.Symbol, preOrder.MainId, err)
} else if len(mainIds) > 0 {
if err := db.Exec("UPDATE line_pre_order SET status=4,desc=desc +' 新单触发取消' WHERE id IN ? AND status =6", mainIds).Error; err != nil {
if err := db.Exec("UPDATE line_pre_order SET `status`=4,`desc`=CONCAT(`desc`, ' 新单触发取消') WHERE id IN ? AND `status` =6", mainIds).Error; err != nil {
logger.Errorf("新下单成功后更新主单取消状态失败, 新主单号:%s, 错误信息:%v", preOrder.MainId, err)
}
}
@ -770,7 +770,7 @@ func processTakeProfitOrder(db *gorm.DB, spotApi SpotRestApi, order models.LineP
logger.Error("更新现货止盈单触发事件 ordersn:", order.OrderSn)
}
if err := db.Model(&DbModels.LinePreOrder{}).Where("id = ? and status ='0'", order.Id).
Updates(map[string]interface{}{"status": "1", "num": order.Num}).Error; err != nil {
Updates(map[string]interface{}{"status": "1", "num": order.Num, "price": order.Price}).Error; err != nil {
logger.Error("现货止盈下单成功,更新状态失败:", order.OrderSn, " err:", err)
}
}

View File

@ -77,8 +77,11 @@ func (e *BinancePositionManagement) SavePosition(data *positiondto.PositionAddRe
result.LastPrice = data.Price
}
if totalLoss.Cmp(decimal.Zero) > 0 {
//总亏损大于0
if totalLoss.Add(result.TotalLoss).Cmp(decimal.Zero) > 0 {
result.TotalLoss = result.TotalLoss.Add(totalLoss)
} else {
result.TotalLoss = decimal.Zero
}
result.Quantity = data.Quantity.Add(result.Quantity)