1、累计亏损
This commit is contained in:
@ -211,7 +211,7 @@ func handleMainReduceFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
|
||||
if orders[index].OrderType == 1 {
|
||||
//亏损大于0 重新计算比例
|
||||
if positionData.TotalLoss.Cmp(decimal.Zero) > 0 && orderExt.Id > 0 {
|
||||
percentag := positionData.TotalLoss.Div(totalNum).Div(price)
|
||||
percentag := positionData.TotalLoss.Div(totalNum).Div(price).Mul(decimal.NewFromInt(100))
|
||||
percentag = percentag.Add(orderExt.TakeProfitRatio).Truncate(2)
|
||||
orders[index].Rate = percentag.String()
|
||||
percentag = percentag.Div(decimal.NewFromInt(100))
|
||||
@ -429,11 +429,11 @@ func handleSpotTakeProfitFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.Model(&DbModels.LinePreOrder{}).Where("main_id =? AND status=0").Update("status", 4).Error; err != nil {
|
||||
logger.Errorf("止盈订单回调失败, 回调订单号:%s 更新取消状态失败:%v", preOrder.OrderSn, err)
|
||||
// if err := db.Model(&DbModels.LinePreOrder{}).Where("main_id =? AND status=0",).Update("status", 4).Error; err != nil {
|
||||
// logger.Errorf("止盈订单回调失败, 回调订单号:%s 更新取消状态失败:%v", preOrder.OrderSn, err)
|
||||
|
||||
return err
|
||||
}
|
||||
// return err
|
||||
// }
|
||||
|
||||
return nil
|
||||
})
|
||||
@ -522,8 +522,19 @@ func handleMainOrderFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
|
||||
mainOrders, _ := getOpenPositionMainOrderId(db, preOrder.Id, preOrder.ApiId, preOrder.SymbolType, preOrder.ExchangeType, preOrder.Symbol, preOrder.Site)
|
||||
|
||||
if len(mainOrders) > 0 {
|
||||
mainIds := []int{}
|
||||
for _, mainOrder := range mainOrders {
|
||||
removeSpotLossAndAddPosition(mainOrder.Id, mainOrder.OrderSn)
|
||||
mainId := mainOrder.Id
|
||||
|
||||
if mainOrder.MainId > 0 {
|
||||
mainId = mainOrder.MainId
|
||||
}
|
||||
|
||||
removeSpotLossAndAddPosition(mainId, mainOrder.OrderSn)
|
||||
|
||||
if !utility.ContainsInt(mainIds, mainId) {
|
||||
mainIds = append(mainIds, mainId)
|
||||
}
|
||||
}
|
||||
|
||||
spotApi := SpotRestApi{}
|
||||
@ -531,6 +542,10 @@ 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 {
|
||||
logger.Errorf("新下单成功后更新主单取消状态失败, 新主单号:%s, 错误信息:%v", preOrder.MainId, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -658,7 +673,7 @@ func processTakeProfitAndStopLossOrders(db *gorm.DB, preOrder *models.LinePreOrd
|
||||
case 1: // 止盈
|
||||
//亏损大于0 重新计算比例
|
||||
if positionData.TotalLoss.Cmp(decimal.Zero) > 0 && orderExt.Id > 0 {
|
||||
percentag := positionData.TotalLoss.Div(num).Div(price)
|
||||
percentag := positionData.TotalLoss.Div(num).Div(price).Mul(decimal.NewFromInt(100))
|
||||
percentag = percentag.Add(orderExt.TakeProfitRatio).Truncate(2)
|
||||
order.Rate = percentag.String()
|
||||
percentag = percentag.Div(decimal.NewFromInt(100))
|
||||
|
||||
Reference in New Issue
Block a user