1、重写
This commit is contained in:
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go-admin/common/const/rediskey"
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/helper"
|
||||
"go-admin/config"
|
||||
@ -118,16 +117,7 @@ func handleTickerAllMessage(msg []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
pairs := make([]map[string]interface{}, 0)
|
||||
trades := make([]models.TradeSet, 0)
|
||||
pairVal, _ := helper.DefaultRedis.GetString(rediskey.FutSymbolTicker)
|
||||
|
||||
if pairVal != "" {
|
||||
err := sonic.Unmarshal([]byte(pairVal), &pairs)
|
||||
if err != nil {
|
||||
log.Error("获取redis数据失败", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
for _, data := range dataAll.Data {
|
||||
symbol := data["s"].(string)
|
||||
@ -149,7 +139,6 @@ func handleTickerAllMessage(msg []byte) {
|
||||
tradeSet.LowPrice = utility.StringFloat64Cut(data["l"].(string), int32(tradeSet.PriceDigit))
|
||||
tradeSet.Volume = utility.StringFloat64Cut(data["v"].(string), int32(tradeSet.AmountDigit))
|
||||
tradeSet.QuoteVolume = utility.StringFloat64Cut(data["q"].(string), 5)
|
||||
hasData := false
|
||||
trades = append(trades, tradeSet)
|
||||
|
||||
tradeSetVal, _ := sonic.MarshalString(&tradeSet)
|
||||
@ -158,56 +147,14 @@ func handleTickerAllMessage(msg []byte) {
|
||||
log.Error(symbol, "ticker@all ws处理失败", err)
|
||||
}
|
||||
}
|
||||
|
||||
for index := range pairs {
|
||||
if cacheSymbol, ok := pairs[index]["symbol"].(string); ok {
|
||||
if cacheSymbol == symbol {
|
||||
pairs[index]["price"] = tradeSet.LastPrice
|
||||
hasData = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !hasData {
|
||||
pairs = append(pairs, map[string]interface{}{
|
||||
"symbol": symbol,
|
||||
"price": tradeSet.LastPrice,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(trades) > 0 {
|
||||
|
||||
for index := range trades {
|
||||
if wsBin.WorkType == "normal" {
|
||||
//主单触发
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesPrice, trades[index])
|
||||
//止损信息
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesStoplossPrice, trades[index])
|
||||
//加仓信息
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesAddPositionPrice, trades[index])
|
||||
//对冲平仓
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesHedgeClosePosition, trades[index])
|
||||
//保险对冲
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesProtectHedge, trades[index])
|
||||
} else {
|
||||
//合约对冲主动平仓
|
||||
// utility.SafeGoParam(binanceservice.FutureClosePositionTrigger, trades[index])
|
||||
binanceservice.FutureClosePositionTrigger(trades[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wsBin.WorkType == "normal" {
|
||||
if len(pairs) > 0 {
|
||||
pairVal, _ = sonic.MarshalString(&pairs)
|
||||
|
||||
if pairVal != "" {
|
||||
if err := helper.DefaultRedis.SetString(rediskey.FutSymbolTicker, pairVal); err != nil {
|
||||
log.Error("pair@all ws处理合约价格失败", err)
|
||||
}
|
||||
}
|
||||
//主单触发
|
||||
utility.SafeGoParam(binanceservice.JudgeFuturesPrice, trades[index])
|
||||
//止损信息
|
||||
// utility.SafeGoParam(binanceservice.JudgeFuturesStoplossPrice, trades[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user