diff --git a/app/admin/models/line_api_user.go b/app/admin/models/line_api_user.go index 2d29adf..ff44a02 100644 --- a/app/admin/models/line_api_user.go +++ b/app/admin/models/line_api_user.go @@ -2,6 +2,7 @@ package models import ( "go-admin/common/models" + "time" ) type LineApiUser struct { @@ -9,22 +10,21 @@ type LineApiUser struct { ExchangeType string `json:"exchangeType" gorm:"type:varchar(20);comment:交易所类型(字典 exchange_type)"` UserId int64 `json:"userId" gorm:"type:int unsigned;comment:用户id"` - JysId int64 `json:"jysId" gorm:"type:int;comment:关联交易所账号id"` ApiName string `json:"apiName" gorm:"type:varchar(255);comment:api用户名"` ApiKey string `json:"apiKey" gorm:"type:varchar(255);comment:apiKey"` ApiSecret string `json:"apiSecret" gorm:"type:varchar(255);comment:apiSecret"` IpAddress string `json:"ipAddress" gorm:"type:varchar(255);comment:代理地址"` UserPass string `json:"userPass" gorm:"type:varchar(255);comment:代码账号密码"` - AdminId int64 `json:"adminId" gorm:"type:int unsigned;comment:管理员id"` - Affiliation int64 `json:"affiliation" gorm:"type:int;comment:归属:1=现货,2=合约,3=现货合约"` - AdminShow int64 `json:"adminShow" gorm:"type:int;comment:是否超管可见:1=是,0=否"` - Site string `json:"site" gorm:"type:enum('1','2','3');comment:允许下单的方向:1=多;2=空;3=多空"` - Subordinate string `json:"subordinate" gorm:"type:enum('0','1','2');comment:从属关系:0=未绑定关系;1=主账号;2=副帐号"` - GroupId int64 `json:"groupId" gorm:"type:int unsigned;comment:所属组id"` - OpenStatus int64 `json:"openStatus" gorm:"type:int unsigned;comment:开启状态 0=关闭 1=开启"` + // AdminId int64 `json:"adminId" gorm:"type:int unsigned;comment:管理员id"` + Affiliation int64 `json:"affiliation" gorm:"type:int;comment:归属:1=现货,2=合约,3=现货合约"` + AdminShow int64 `json:"adminShow" gorm:"type:int;comment:是否超管可见:1=是,0=否"` + Site string `json:"site" gorm:"type:enum('1','2','3');comment:允许下单的方向:1=多;2=空;3=多空"` + Subordinate string `json:"subordinate" gorm:"type:enum('0','1','2');comment:从属关系:0=未绑定关系;1=主账号;2=副帐号"` + GroupId int64 `json:"groupId" gorm:"type:int unsigned;comment:所属组id"` + OpenStatus int64 `json:"openStatus" gorm:"type:int unsigned;comment:开启状态 0=关闭 1=开启"` - SpotLastTime string `json:"spotLastTime" gorm:"-"` //现货websocket最后通信时间 - FuturesLastTime string `json:"futuresLastTime" gorm:"-"` //合约websocket最后通信时间 + SpotLastTime *time.Time `json:"spotLastTime" gorm:"-"` //现货websocket最后通信时间 + FuturesLastTime *time.Time `json:"futuresLastTime" gorm:"-"` //合约websocket最后通信时间 models.ModelTime models.ControlBy } diff --git a/app/admin/service/dto/line_api_user.go b/app/admin/service/dto/line_api_user.go index d710531..9077cbd 100644 --- a/app/admin/service/dto/line_api_user.go +++ b/app/admin/service/dto/line_api_user.go @@ -14,9 +14,9 @@ type LineApiUserGetPageReq struct { } type LineApiUserOrder struct { - Id string `form:"idOrder" search:"type:order;column:id;table:line_api_user"` - UserId string `form:"userIdOrder" search:"type:order;column:user_id;table:line_api_user"` - JysId string `form:"jysIdOrder" search:"type:order;column:jys_id;table:line_api_user"` + Id string `form:"idOrder" search:"type:order;column:id;table:line_api_user"` + UserId string `form:"userIdOrder" search:"type:order;column:user_id;table:line_api_user"` + // JysId string `form:"jysIdOrder" search:"type:order;column:jys_id;table:line_api_user"` ApiName string `form:"apiNameOrder" search:"type:order;column:api_name;table:line_api_user"` ApiKey string `form:"apiKeyOrder" search:"type:order;column:api_key;table:line_api_user"` ApiSecret string `form:"apiSecretOrder" search:"type:order;column:api_secret;table:line_api_user"` @@ -44,19 +44,19 @@ type LineApiUserInsertReq struct { Id int `json:"-" comment:"id"` // id ExchangeType string `json:"exchangeType" comment:"交易所code"` UserId int64 `json:"userId" comment:"用户id"` - JysId int64 `json:"jysId" comment:"关联交易所账号id"` - ApiName string `json:"apiName" comment:"api用户名"` - ApiKey string `json:"apiKey" comment:"apiKey"` - ApiSecret string `json:"apiSecret" comment:"apiSecret"` - IpAddress string `json:"ipAddress" comment:"代理地址"` - UserPass string `json:"userPass" comment:"代码账号密码"` - AdminId int64 `json:"adminId" comment:"管理员id"` - Affiliation int64 `json:"affiliation" comment:"归属:1=现货,2=合约,3=现货合约"` - AdminShow int64 `json:"adminShow" comment:"是否超管可见:1=是,0=否"` - Site string `json:"site" comment:"允许下单的方向:1=多;2=空;3=多空"` - Subordinate string `json:"subordinate" comment:"从属关系:0=未绑定关系;1=主账号;2=副帐号"` - GroupId int64 `json:"groupId" comment:"所属组id"` - OpenStatus int64 `json:"openStatus" comment:"开启状态 0=关闭 1=开启"` + // JysId int64 `json:"jysId" comment:"关联交易所账号id"` + ApiName string `json:"apiName" comment:"api用户名"` + ApiKey string `json:"apiKey" comment:"apiKey"` + ApiSecret string `json:"apiSecret" comment:"apiSecret"` + IpAddress string `json:"ipAddress" comment:"代理地址"` + UserPass string `json:"userPass" comment:"代码账号密码"` + AdminId int64 `json:"adminId" comment:"管理员id"` + Affiliation int64 `json:"affiliation" comment:"归属:1=现货,2=合约,3=现货合约"` + AdminShow int64 `json:"adminShow" comment:"是否超管可见:1=是,0=否"` + Site string `json:"site" comment:"允许下单的方向:1=多;2=空;3=多空"` + Subordinate string `json:"subordinate" comment:"从属关系:0=未绑定关系;1=主账号;2=副帐号"` + GroupId int64 `json:"groupId" comment:"所属组id"` + OpenStatus int64 `json:"openStatus" comment:"开启状态 0=关闭 1=开启"` common.ControlBy } @@ -66,13 +66,13 @@ func (s *LineApiUserInsertReq) Generate(model *models.LineApiUser) { } model.ExchangeType = s.ExchangeType model.UserId = s.UserId - model.JysId = s.JysId + // model.JysId = s.JysId model.ApiName = s.ApiName model.ApiKey = s.ApiKey model.ApiSecret = s.ApiSecret model.IpAddress = s.IpAddress model.UserPass = s.UserPass - model.AdminId = s.AdminId + // model.AdminId = s.AdminId model.Affiliation = s.Affiliation model.AdminShow = s.AdminShow model.Site = s.Site @@ -90,19 +90,19 @@ type LineApiUserUpdateReq struct { Id int `uri:"id" comment:"id"` // id ExchangeType string `json:"exchangeType" comment:"交易所code"` UserId int64 `json:"userId" comment:"用户id"` - JysId int64 `json:"jysId" comment:"关联交易所账号id"` - ApiName string `json:"apiName" comment:"api用户名"` - ApiKey string `json:"apiKey" comment:"apiKey"` - ApiSecret string `json:"apiSecret" comment:"apiSecret"` - IpAddress string `json:"ipAddress" comment:"代理地址"` - UserPass string `json:"userPass" comment:"代码账号密码"` - AdminId int64 `json:"adminId" comment:"管理员id"` - Affiliation int64 `json:"affiliation" comment:"归属:1=现货,2=合约,3=现货合约"` - AdminShow int64 `json:"adminShow" comment:"是否超管可见:1=是,0=否"` - Site string `json:"site" comment:"允许下单的方向:1=多;2=空;3=多空"` - Subordinate string `json:"subordinate" comment:"从属关系:0=未绑定关系;1=主账号;2=副帐号"` - GroupId int64 `json:"groupId" comment:"所属组id"` - OpenStatus int64 `json:"openStatus" comment:"开启状态 0=关闭 1=开启"` + // JysId int64 `json:"jysId" comment:"关联交易所账号id"` + ApiName string `json:"apiName" comment:"api用户名"` + ApiKey string `json:"apiKey" comment:"apiKey"` + ApiSecret string `json:"apiSecret" comment:"apiSecret"` + IpAddress string `json:"ipAddress" comment:"代理地址"` + UserPass string `json:"userPass" comment:"代码账号密码"` + // AdminId int64 `json:"adminId" comment:"管理员id"` + Affiliation int64 `json:"affiliation" comment:"归属:1=现货,2=合约,3=现货合约"` + AdminShow int64 `json:"adminShow" comment:"是否超管可见:1=是,0=否"` + Site string `json:"site" comment:"允许下单的方向:1=多;2=空;3=多空"` + Subordinate string `json:"subordinate" comment:"从属关系:0=未绑定关系;1=主账号;2=副帐号"` + GroupId int64 `json:"groupId" comment:"所属组id"` + OpenStatus int64 `json:"openStatus" comment:"开启状态 0=关闭 1=开启"` common.ControlBy } @@ -112,13 +112,13 @@ func (s *LineApiUserUpdateReq) Generate(model *models.LineApiUser) { } model.ExchangeType = s.ExchangeType model.UserId = s.UserId - model.JysId = s.JysId + // model.JysId = s.JysId model.ApiName = s.ApiName model.ApiKey = s.ApiKey model.ApiSecret = s.ApiSecret model.IpAddress = s.IpAddress model.UserPass = s.UserPass - model.AdminId = s.AdminId + // model.AdminId = s.AdminId model.Affiliation = s.Affiliation model.AdminShow = s.AdminShow model.Site = s.Site diff --git a/app/admin/service/line_api_user.go b/app/admin/service/line_api_user.go index 55ed4bc..a674c93 100644 --- a/app/admin/service/line_api_user.go +++ b/app/admin/service/line_api_user.go @@ -52,19 +52,19 @@ func (e *LineApiUser) GetPage(c *dto.LineApiUserGetPageReq, p *actions.DataPermi return err } - var userSub binancedto.UserSubscribeState for index := range *list { val, _ := helper.DefaultRedis.GetString(fmt.Sprintf(global.USER_SUBSCRIBE, (*list)[index].ApiKey)) + var userSub binancedto.UserSubscribeState if val != "" { sonic.Unmarshal([]byte(val), &userSub) if userSub.FuturesLastTime != nil { - (*list)[index].FuturesLastTime = userSub.FuturesLastTime.Format("2006-01-02 15:04:05") + (*list)[index].FuturesLastTime = userSub.FuturesLastTime } if userSub.SpotLastTime != nil { - (*list)[index].SpotLastTime = userSub.SpotLastTime.Format("2006-01-02 15:04:05") + (*list)[index].SpotLastTime = userSub.SpotLastTime } } } diff --git a/app/admin/service/line_pre_order.go b/app/admin/service/line_pre_order.go index 93e99b8..1d1789f 100644 --- a/app/admin/service/line_pre_order.go +++ b/app/admin/service/line_pre_order.go @@ -1267,14 +1267,25 @@ func (e *LinePreOrder) AddBatchPreOrder(batchReq *dto.LineBatchAddPreOrderReq, p var symbolGroupInfo models.LineSymbolGroup e.Orm.Model(&models.LineSymbolGroup{}).Where("id = ?", utility.StringToInt(batchReq.SymbolGroupId)).Find(&symbolGroupInfo) if symbolGroupInfo.Id <= 0 || symbolGroupInfo.Symbol == "" { - *errs = append(*errs, errors.New(fmt.Sprintf("选择的交易对组:%s不存在或交易对组的交易对为空", batchReq.SymbolGroupId))) + *errs = append(*errs, fmt.Errorf("选择的交易对组:%s不存在或交易对组的交易对为空", batchReq.SymbolGroupId)) return nil } + + if batchReq.StrategyTemplateType == 1 && batchReq.StrategyTemplateId > 0 { + cachePriceSymbols, _ := helper.DefaultRedis.GetAllList(rediskey.CacheSymbolLastPrice) + symbols := strings.Split(symbolGroupInfo.Symbol, ",") + + for _, symbol := range symbols { + if !utility.ContainsStr(cachePriceSymbols, symbol) { + *errs = append(*errs, fmt.Errorf("交易对[%s]涨跌幅缓存不存在", symbol)) + return nil + } + } + } batchReq.Symbol = symbolGroupInfo.Symbol } //脚本次数 - // if batchReq.OrderNum > 0 { apiUserIds := strings.Split(batchReq.ApiUserId, ",") var tickerSymbol string if batchReq.SymbolType == global.SYMBOL_SPOT { @@ -1299,7 +1310,7 @@ func (e *LinePreOrder) AddBatchPreOrder(batchReq *dto.LineBatchAddPreOrderReq, p log.ScriptParams = string(marshal) log.AdminId = 0 log.Status = "0" - //scriptLogs = append(scriptLogs, log) + err := e.Orm.Model(&models.LinePreScript{}).Create(&log).Error if err != nil { *errs = append(*errs, fmt.Errorf("记录脚本失败:%+v", err.Error())) @@ -1339,6 +1350,8 @@ func (e *LinePreOrder) AddBatchPreOrder(batchReq *dto.LineBatchAddPreOrderReq, p req.ReduceStopLossRatio = batchReq.ReduceStopLossRatio req.ReduceTakeProfitRatio = batchReq.ReduceTakeProfitRatio req.CreateBy = batchReq.CreateBy + req.StrategyTemplateId = batchReq.StrategyTemplateId + req.StrategyTemplateType = batchReq.StrategyTemplateType e.AddPreOrderCheck(&req, p, errs, tickerSymbol) } diff --git a/common/helper/redislock.go b/common/helper/redislock.go index a2bef22..193fa7a 100644 --- a/common/helper/redislock.go +++ b/common/helper/redislock.go @@ -3,6 +3,7 @@ package helper import ( "context" "errors" + "fmt" "go-admin/pkg/utility" "math/rand" "strconv" @@ -60,6 +61,8 @@ func InitLockRedisConn(host, password, dbIndex string) { log.Error("Failed to connect to Redis", zap.Error(err)) panic(err) } + + fmt.Println("redis lock初始化完毕") }) } diff --git a/config/serverinit/business_init.go b/config/serverinit/business_init.go index 95a0518..4426e54 100644 --- a/config/serverinit/business_init.go +++ b/config/serverinit/business_init.go @@ -24,9 +24,11 @@ import ( // 业务初始化 func BusinessInit(db *gorm.DB) { + httputils.InitProxy(config.ExtConfig.ProxyUrl) if err := loadApiUser(db); err != nil { //加载api用户 + fmt.Printf("加载api用户失败 err:%v", err) os.Exit(-1) }