This commit is contained in:
2025-02-08 14:05:57 +08:00
parent c0b8749eef
commit 979ef507fe
30 changed files with 660 additions and 431 deletions

View File

@ -27,11 +27,17 @@ import (
func ChangeSpotOrder(mapData map[string]interface{}) {
// 检查订单号是否存在
orderSn, ok := mapData["c"]
originOrderSn := mapData["C"] //取消操作 代表原始订单号
if !ok {
logger.Error("订单回调失败, 没有订单号", mapData)
return
}
if originOrderSn != "" {
orderSn = originOrderSn
}
// 获取数据库连接
db := GetDBConnection()
if db == nil {
@ -123,6 +129,13 @@ func handleOrderByType(db *gorm.DB, preOrder *DbModels.LinePreOrder, orderStatus
if err := db.Model(&DbModels.LinePreOrder{}).Where("id =?", preOrder.Pid).Update("status", 9).Error; err != nil {
logger.Errorf("主单止损回调 订单号:%s 修改主单状态失败:%v", preOrder.OrderSn, err)
}
} else {
order, err := GetOrderById(db, preOrder.Pid)
if err != nil {
logger.Errorf("主单止损回调 获取主单失败 订单号:%s err:%v", preOrder.OrderSn, err)
return
}
triggerHedgeOrder(order, db, preOrder)
}
}
}
@ -178,7 +191,7 @@ func handleSpotTakeProfitFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
for _, v := range stoplossVal {
sonic.Unmarshal([]byte(v), &stoploss)
if stoploss.Pid == preOrder.Id {
if stoploss.Pid == preOrder.Pid {
_, err := helper.DefaultRedis.LRem(stoplossKey, v)
if err != nil {
@ -235,7 +248,7 @@ func updateOrderStatus(db *gorm.DB, preOrder *models.LinePreOrder, status int, r
params["num"] = num
params["price"] = total.Div(totalAmount)
preOrder.Num = num.String()
preOrder.Price = params["price"].(string)
preOrder.Price = total.Div(totalAmount).String()
}
case false:
status, _ := mapData["X"].(string)
@ -243,10 +256,11 @@ func updateOrderStatus(db *gorm.DB, preOrder *models.LinePreOrder, status int, r
if status == "FILLED" {
num, _ := decimal.NewFromString(mapData["z"].(string))
params["num"] = num.Mul(decimal.NewFromFloat(0.998)).String()
params["price"], _ = mapData["ap"].(string)
price, _ := mapData["ap"].(string)
params["price"] = price
preOrder.Num = num.String()
preOrder.Price = params["price"].(string)
preOrder.Price = price
}
}