1、
This commit is contained in:
@ -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,8 +499,11 @@ func cancelPositionOtherOrders(apiUserInfo DbModels.LineApiUser, db *gorm.DB, pr
|
||||
mainId = mainOrder.MainId
|
||||
}
|
||||
removeFutLossAndAddPosition(mainId, mainOrder.OrderSn)
|
||||
|
||||
if !utility.ContainsInt(mainIds, mainId) {
|
||||
mainIds = append(mainIds, mainId)
|
||||
}
|
||||
}
|
||||
|
||||
if len(mainIds) > 0 {
|
||||
orderSns, err := getOpenOrderSns(db, mainIds)
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user