1、暂存

This commit is contained in:
2025-10-14 19:58:59 +08:00
parent 556a32cb7c
commit 643eab3496
60 changed files with 5244 additions and 657 deletions

View File

@ -14,6 +14,7 @@ import (
"go-admin/models/positiondto"
"go-admin/pkg/utility"
"go-admin/services/cacheservice"
"go-admin/services/commonservice"
"go-admin/services/positionservice"
"strconv"
"strings"
@ -44,7 +45,7 @@ func ChangeSpotOrder(mapData map[string]interface{}) {
}
// 获取数据库连接
db := GetDBConnection()
db := commonservice.GetDBConnection()
if db == nil {
logger.Error("订单回调失败, 无法获取数据库连接")
return
@ -166,7 +167,7 @@ func handleMainReduceFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
return
}
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, preOrder.Symbol, 0)
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, preOrder.Symbol, 1)
if err != nil {
logger.Errorf("handleMainReduceFilled 获取交易对设置失败,订单号:%s", preOrder.OrderSn)
@ -300,7 +301,7 @@ func nextSpotReduceTrigger(db *gorm.DB, mainId int, totalNum decimal.Decimal, tr
//移除缓存
key := fmt.Sprintf(rediskey.SpotReduceList, global.EXCHANGE_BINANCE)
vals, _ := helper.DefaultRedis.GetAllList(key)
item := ReduceListItem{}
item := positiondto.ReduceListItem{}
for _, val := range vals {
sonic.Unmarshal([]byte(val), &item)
@ -553,8 +554,8 @@ func removeSpotLossAndAddPosition(mainId int, orderSn string) {
reduceKey := fmt.Sprintf(rediskey.SpotReduceList, global.EXCHANGE_BINANCE)
reduceVal, _ := helper.DefaultRedis.GetAllList(reduceKey)
stoploss := dto.StopLossRedisList{}
addPosition := AddPositionList{}
reduce := ReduceListItem{}
addPosition := positiondto.AddPositionList{}
reduce := positiondto.ReduceListItem{}
//移除减仓后减仓策略
RemoveReduceReduceCacheByMainId(mainId, 1)
@ -646,7 +647,7 @@ func handleMainOrderFilled(db *gorm.DB, preOrder *DbModels.LinePreOrder) {
keySpotAddPosition := fmt.Sprintf(rediskey.SpotAddPositionList, global.EXCHANGE_BINANCE)
for _, addPositionOrder := range addPositionOrders {
addPositionData := AddPositionList{
addPositionData := positiondto.AddPositionList{
Id: addPositionOrder.Id,
OrderSn: addPositionOrder.OrderSn,
MainId: addPositionOrder.MainId,
@ -744,7 +745,7 @@ func updateOrderStatus(db *gorm.DB, preOrder *models.LinePreOrder, status int, r
// fist 首次止盈止损
func processTakeProfitAndStopLossOrders(db *gorm.DB, preOrder *models.LinePreOrder, positionData *positiondto.PositionDto, extOrderId int, fist bool) {
orders := []models.LinePreOrder{}
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, preOrder.Symbol, 0)
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, preOrder.Symbol, 1)
mainId := preOrder.Id
if preOrder.MainId > 0 {
@ -855,7 +856,7 @@ func SetPrice(order *models.LinePreOrder, preOrder *models.LinePreOrder, tradeSe
// 现货减仓
func processSpotReduceOrder(preOrder DbModels.LinePreOrder) {
key := fmt.Sprintf(rediskey.SpotReduceList, global.EXCHANGE_BINANCE)
item := ReduceListItem{
item := positiondto.ReduceListItem{
Id: preOrder.Id,
ApiId: preOrder.ApiId,
Pid: preOrder.Pid,
@ -882,7 +883,7 @@ func processSpotReduceOrder(preOrder DbModels.LinePreOrder) {
// 处理止盈订单
func processTakeProfitOrder(db *gorm.DB, spotApi SpotRestApi, order models.LinePreOrder) {
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, order.Symbol, 0)
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, order.Symbol, 1)
if tradeSet.Coin == "" {
logger.Error("获取交易对失败")