1、暂存
This commit is contained in:
@ -10,8 +10,11 @@ import (
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/helper"
|
||||
"go-admin/models"
|
||||
"go-admin/models/positiondto"
|
||||
"go-admin/pkg/utility"
|
||||
"go-admin/services/cacheservice"
|
||||
"go-admin/services/commonservice"
|
||||
"go-admin/services/orderservice"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -27,13 +30,16 @@ import (
|
||||
func JudgeSpotPrice(trade models.TradeSet) {
|
||||
key := fmt.Sprintf(rediskey.PreSpotOrderList, global.EXCHANGE_BINANCE)
|
||||
preOrderVal, _ := helper.DefaultRedis.GetAllList(key)
|
||||
db := GetDBConnection()
|
||||
db := commonservice.GetDBConnection()
|
||||
|
||||
if len(preOrderVal) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
spotApi := SpotRestApi{}
|
||||
orderService := orderservice.OrderService{}
|
||||
orderService.Orm = db
|
||||
|
||||
for _, item := range preOrderVal {
|
||||
preOrder := dto.PreOrderRedisList{}
|
||||
if err := sonic.Unmarshal([]byte(item), &preOrder); err != nil {
|
||||
@ -46,6 +52,18 @@ func JudgeSpotPrice(trade models.TradeSet) {
|
||||
tradePrice, _ := decimal.NewFromString(trade.LastPrice)
|
||||
//买入
|
||||
if strings.ToUpper(preOrder.Site) == "BUY" && orderPrice.Cmp(tradePrice) >= 0 && orderPrice.Cmp(decimal.Zero) > 0 && tradePrice.Cmp(decimal.Zero) > 0 {
|
||||
//判断个人websocket是否超时
|
||||
|
||||
apiInfo, _ := GetApiInfo(preOrder.ApiId)
|
||||
if err := commonservice.JudgeWebsocketTimeout(apiInfo.ApiKey, 1); err != nil {
|
||||
log.Errorf("现货行情订阅超时,apiKey:%s err:%v", err)
|
||||
|
||||
if err1 := orderService.ErrorTrigger(&preOrder, fmt.Sprintf("行情触发失败,err:%v", err)); err1 != nil {
|
||||
log.Error("触发失败", err1)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
SpotOrderLock(db, &preOrder, item, spotApi)
|
||||
}
|
||||
}
|
||||
@ -140,7 +158,7 @@ func JudgeSpotStopLoss(trade models.TradeSet) {
|
||||
return
|
||||
}
|
||||
|
||||
db := GetDBConnection()
|
||||
db := commonservice.GetDBConnection()
|
||||
spotApi := SpotRestApi{}
|
||||
setting, err := cacheservice.GetSystemSetting(db)
|
||||
|
||||
@ -149,7 +167,7 @@ func JudgeSpotStopLoss(trade models.TradeSet) {
|
||||
return
|
||||
}
|
||||
|
||||
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, trade.Coin+trade.Currency, 0)
|
||||
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, trade.Coin+trade.Currency, 1)
|
||||
|
||||
if err != nil {
|
||||
log.Error("获取交易设置失败")
|
||||
@ -257,7 +275,7 @@ func SpotStopLossTrigger(db *gorm.DB, stopOrder dto.StopLossRedisList, spotApi S
|
||||
// 判断是否触发现货减仓
|
||||
func JudgeSpotReduce(trade models.TradeSet) {
|
||||
key := fmt.Sprintf(rediskey.SpotReduceList, global.EXCHANGE_BINANCE)
|
||||
db := GetDBConnection()
|
||||
db := commonservice.GetDBConnection()
|
||||
spotApi := SpotRestApi{}
|
||||
setting, err := cacheservice.GetSystemSetting(db)
|
||||
|
||||
@ -266,12 +284,14 @@ func JudgeSpotReduce(trade models.TradeSet) {
|
||||
return
|
||||
}
|
||||
|
||||
reduceOrder := ReduceListItem{}
|
||||
reduceOrder := positiondto.ReduceListItem{}
|
||||
tradePrice, _ := decimal.NewFromString(trade.LastPrice)
|
||||
//减仓单减仓策略
|
||||
reduceReduceListKey := fmt.Sprintf(rediskey.SpotOrderReduceStrategyList, global.EXCHANGE_BINANCE)
|
||||
orderReduceVal, _ := helper.DefaultRedis.HGetAllFields(reduceReduceListKey)
|
||||
reduceOrderStrategy := dto.LineOrderReduceStrategyResp{}
|
||||
orderService := orderservice.OrderService{}
|
||||
orderService.Orm = db
|
||||
|
||||
for _, item := range orderReduceVal {
|
||||
sonic.Unmarshal([]byte(item), &reduceOrderStrategy)
|
||||
@ -297,7 +317,7 @@ func JudgeSpotReduce(trade models.TradeSet) {
|
||||
return
|
||||
}
|
||||
|
||||
order, err := CreateReduceReduceOrder(db, reduceOrderStrategy.OrderId, item2.Price, item2.Num, trade.PriceDigit)
|
||||
order, err := orderService.CreateReduceReduceOrder(db, reduceOrderStrategy.OrderId, item2.Price, item2.Num, trade.PriceDigit)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("%d 生成订单失败", reduceOrderStrategy.OrderId)
|
||||
@ -367,8 +387,8 @@ func JudgeSpotReduce(trade models.TradeSet) {
|
||||
// 触发现货减仓
|
||||
// isStrategy 是否是策略减仓单
|
||||
// reduceId 策略主减仓单id
|
||||
func SpotReduceTrigger(db *gorm.DB, reduceOrder ReduceListItem, spotApi SpotRestApi, setting DbModels.LineSystemSetting, key, item string, isStrategy bool, reduceId int) bool {
|
||||
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, reduceOrder.Symbol, 0)
|
||||
func SpotReduceTrigger(db *gorm.DB, reduceOrder positiondto.ReduceListItem, spotApi SpotRestApi, setting DbModels.LineSystemSetting, key, item string, isStrategy bool, reduceId int) bool {
|
||||
tradeSet, err := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, reduceOrder.Symbol, 1)
|
||||
result := true
|
||||
|
||||
if err != nil {
|
||||
@ -470,7 +490,7 @@ func SpotReduceTrigger(db *gorm.DB, reduceOrder ReduceListItem, spotApi SpotRest
|
||||
func JudgeSpotAddPosition(trade models.TradeSet) {
|
||||
key := fmt.Sprintf(rediskey.SpotAddPositionList, global.EXCHANGE_BINANCE)
|
||||
preOrderVal, _ := helper.DefaultRedis.GetAllList(key)
|
||||
db := GetDBConnection()
|
||||
db := commonservice.GetDBConnection()
|
||||
|
||||
if len(preOrderVal) == 0 {
|
||||
return
|
||||
@ -478,7 +498,7 @@ func JudgeSpotAddPosition(trade models.TradeSet) {
|
||||
|
||||
spotApi := SpotRestApi{}
|
||||
for _, item := range preOrderVal {
|
||||
preOrder := AddPositionList{}
|
||||
preOrder := positiondto.AddPositionList{}
|
||||
if err := sonic.Unmarshal([]byte(item), &preOrder); err != nil {
|
||||
log.Error("反序列化失败")
|
||||
continue
|
||||
@ -495,7 +515,7 @@ func JudgeSpotAddPosition(trade models.TradeSet) {
|
||||
}
|
||||
}
|
||||
|
||||
func SpotAddPositionTrigger(db *gorm.DB, v *AddPositionList, item string, spotApi SpotRestApi) {
|
||||
func SpotAddPositionTrigger(db *gorm.DB, v *positiondto.AddPositionList, item string, spotApi SpotRestApi) {
|
||||
lock := helper.NewRedisLock(fmt.Sprintf(rediskey.SpotTrigger, v.ApiId, v.Symbol), 20, 5, 100*time.Millisecond)
|
||||
|
||||
if ok, err := lock.AcquireWait(context.Background()); err != nil {
|
||||
@ -505,7 +525,7 @@ func SpotAddPositionTrigger(db *gorm.DB, v *AddPositionList, item string, spotAp
|
||||
defer lock.Release()
|
||||
|
||||
setting, _ := cacheservice.GetSystemSetting(db)
|
||||
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, v.Symbol, 0)
|
||||
tradeSet, _ := cacheservice.GetTradeSet(global.EXCHANGE_BINANCE, v.Symbol, 1)
|
||||
|
||||
if tradeSet.LastPrice == "" {
|
||||
log.Errorf("现货加仓触发 查询交易对失败 交易对:%s ordersn:%s", v.Symbol, v.OrderSn)
|
||||
|
||||
Reference in New Issue
Block a user