1、批量下单 没配置波段修改
This commit is contained in:
		| @ -2,6 +2,7 @@ package models | ||||
|  | ||||
| import ( | ||||
| 	"go-admin/common/models" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| type LineApiUser struct { | ||||
| @ -9,13 +10,12 @@ 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"` | ||||
| 	// 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=多空"` | ||||
| @ -23,8 +23,8 @@ type LineApiUser struct { | ||||
| 	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 | ||||
| } | ||||
|  | ||||
| @ -16,7 +16,7 @@ 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"` | ||||
| 	// 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,7 +44,7 @@ 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"` | ||||
| 	// JysId        int64  `json:"jysId" comment:"关联交易所账号id"` | ||||
| 	ApiName     string `json:"apiName" comment:"api用户名"` | ||||
| 	ApiKey      string `json:"apiKey" comment:"apiKey"` | ||||
| 	ApiSecret   string `json:"apiSecret" comment:"apiSecret"` | ||||
| @ -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,13 +90,13 @@ 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"` | ||||
| 	// 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"` | ||||
| 	// 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=多空"` | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @ -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) | ||||
| 			} | ||||
|  | ||||
| @ -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初始化完毕") | ||||
| 	}) | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -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) | ||||
| 	} | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user