diff --git a/app/admin/apis/line_pre_order_ext.go b/app/admin/apis/line_pre_order_ext.go new file mode 100644 index 0000000..b47e66f --- /dev/null +++ b/app/admin/apis/line_pre_order_ext.go @@ -0,0 +1,191 @@ +package apis + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "github.com/go-admin-team/go-admin-core/sdk/api" + "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" + _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response" + + "go-admin/app/admin/models" + "go-admin/app/admin/service" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" +) + +type LinePreOrderExt struct { + api.Api +} + +// GetPage 获取委托拓展参数列表 +// @Summary 获取委托拓展参数列表 +// @Description 获取委托拓展参数列表 +// @Tags 委托拓展参数 +// @Param pageSize query int false "页条数" +// @Param pageIndex query int false "页码" +// @Success 200 {object} response.Response{data=response.Page{list=[]models.LinePreOrderExt}} "{"code": 200, "data": [...]}" +// @Router /api/v1/line-pre-order-ext [get] +// @Security Bearer +func (e LinePreOrderExt) GetPage(c *gin.Context) { + req := dto.LinePreOrderExtGetPageReq{} + s := service.LinePreOrderExt{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + p := actions.GetPermissionFromContext(c) + list := make([]models.LinePreOrderExt, 0) + var count int64 + + err = s.GetPage(&req, p, &list, &count) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取委托拓展参数失败,\r\n失败信息 %s", err.Error())) + return + } + + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") +} + +// Get 获取委托拓展参数 +// @Summary 获取委托拓展参数 +// @Description 获取委托拓展参数 +// @Tags 委托拓展参数 +// @Param id path int false "id" +// @Success 200 {object} response.Response{data=models.LinePreOrderExt} "{"code": 200, "data": [...]}" +// @Router /api/v1/line-pre-order-ext/{id} [get] +// @Security Bearer +func (e LinePreOrderExt) Get(c *gin.Context) { + req := dto.LinePreOrderExtGetReq{} + s := service.LinePreOrderExt{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + var object models.LinePreOrderExt + + p := actions.GetPermissionFromContext(c) + err = s.Get(&req, p, &object) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取委托拓展参数失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK( object, "查询成功") +} + +// Insert 创建委托拓展参数 +// @Summary 创建委托拓展参数 +// @Description 创建委托拓展参数 +// @Tags 委托拓展参数 +// @Accept application/json +// @Product application/json +// @Param data body dto.LinePreOrderExtInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/line-pre-order-ext [post] +// @Security Bearer +func (e LinePreOrderExt) Insert(c *gin.Context) { + req := dto.LinePreOrderExtInsertReq{} + s := service.LinePreOrderExt{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + // 设置创建人 + req.SetCreateBy(user.GetUserId(c)) + + err = s.Insert(&req) + if err != nil { + e.Error(500, err, fmt.Sprintf("创建委托拓展参数失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK(req.GetId(), "创建成功") +} + +// Update 修改委托拓展参数 +// @Summary 修改委托拓展参数 +// @Description 修改委托拓展参数 +// @Tags 委托拓展参数 +// @Accept application/json +// @Product application/json +// @Param id path int true "id" +// @Param data body dto.LinePreOrderExtUpdateReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" +// @Router /api/v1/line-pre-order-ext/{id} [put] +// @Security Bearer +func (e LinePreOrderExt) Update(c *gin.Context) { + req := dto.LinePreOrderExtUpdateReq{} + s := service.LinePreOrderExt{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Update(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("修改委托拓展参数失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK( req.GetId(), "修改成功") +} + +// Delete 删除委托拓展参数 +// @Summary 删除委托拓展参数 +// @Description 删除委托拓展参数 +// @Tags 委托拓展参数 +// @Param data body dto.LinePreOrderExtDeleteReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" +// @Router /api/v1/line-pre-order-ext [delete] +// @Security Bearer +func (e LinePreOrderExt) Delete(c *gin.Context) { + s := service.LinePreOrderExt{} + req := dto.LinePreOrderExtDeleteReq{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Remove(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("删除委托拓展参数失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK( req.GetId(), "删除成功") +} diff --git a/app/admin/models/line_pre_order.go b/app/admin/models/line_pre_order.go index f0bca42..e50d22f 100644 --- a/app/admin/models/line_pre_order.go +++ b/app/admin/models/line_pre_order.go @@ -9,39 +9,33 @@ import ( type LinePreOrder struct { models.Model - ExchangeType string `json:"exchangeType" gorm:"type:varchar(20);comment:交易所类型 (字典 exchange_type)"` - Pid int `json:"pid" gorm:"type:int unsigned;omitempty;comment:pid"` - ApiId int `json:"apiId" gorm:"type:varchar(255);omitempty;comment:api用户"` - GroupId string `json:"groupId" gorm:"type:int unsigned;omitempty;comment:交易对组id"` - Symbol string `json:"symbol" gorm:"type:varchar(255);omitempty;comment:交易对"` - QuoteSymbol string `json:"quoteSymbol" gorm:"type:varchar(255);omitempty;comment:计较货币"` - SignPrice string `json:"signPrice" gorm:"type:decimal(18,8);omitempty;comment:对标价"` - SignPriceU decimal.Decimal `json:"signPriceU" gorm:"type:decimal(18,8);omitempty;comment:交易对对标U的行情价"` - SignPriceType string `json:"signPriceType" gorm:"type:enum('new','tall','low','mixture','entrust','add');omitempty;comment:对标价类型: new=最新价格;tall=24小时最高;low=24小时最低;mixture=标记价;entrust=委托实价;add=补仓"` - Rate string `json:"rate" gorm:"type:decimal(18,2);omitempty;comment:下单百分比"` - Price string `json:"price" gorm:"type:decimal(18,8);omitempty;comment:触发价格"` - Num string `json:"num" gorm:"type:decimal(18,8);omitempty;comment:购买数量"` - BuyPrice string `json:"buyPrice" gorm:"type:decimal(18,8);omitempty;comment:购买金额"` - SymbolType int `json:"symbolType" gorm:"type:int;comment:交易对类型:1=现货;2=合约"` - OrderCategory int `json:"orderCategory" gorm:"type:int;comment:订单类型: 1=主单 2=对冲单"` - Site string `json:"site" gorm:"type:enum('BUY','SELL');omitempty;comment:购买方向:BUY=买;SELL=卖"` - OrderSn string `json:"orderSn" gorm:"type:varchar(255);omitempty;comment:订单号"` - OrderType int `json:"orderType" gorm:"type:int;omitempty;comment:订单类型:0=主单 1=止盈 2=止损 3=平仓"` - Desc string `json:"desc" gorm:"type:text;omitempty;comment:订单描述"` - Status int `json:"status" gorm:"type:int;omitempty;comment:是否被触发:0=待触发;1=已触发;2=下单失败;4=已取消;5=委托中;6=已成交;9=已平仓"` - AdminId string `json:"adminId" gorm:"type:int unsigned;omitempty;comment:操作管理员id"` - CloseType int `json:"closeType" gorm:"type:int unsigned;omitempty;comment:平仓类型 是否为盈利平仓 1= 是 0 =否"` - CoverType int `json:"coverType" gorm:"type:int unsigned;omitempty;comment:对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货"` - ExpireTime time.Time `json:"expireTime" gorm:"comment:过期时间"` - MainOrderType string `json:"mainOrderType" gorm:"type:enum;comment:第一笔(主单类型) 限价(LIMIT)市价(MARKET)"` - HedgeBuyType int `json:"hedge_buy_type" gorm:"type:int;comment:对冲单购买类型 1-百分比 2-实际金额"` - HedgeBuyTotal decimal.Decimal `json:"hedgeBuyTotal" gorm:"type:decimal(10,2);comment:对冲买总金额"` - HedgeOrderType string `json:"hedgeOrderType" gorm:"type:enum;comment:第二笔类型 限价(LIMIT)市价(MARKET)"` - HedgeTakeProfit decimal.Decimal `json:"hedgeTakeProfit" gorm:"type:decimal(10,2);comment:对冲止盈百分比"` - HedgeStopLoss decimal.Decimal `json:"hedgeStopLoss" gorm:"type:decimal(10,2);comment:对冲止损百分比"` - Child []LinePreOrder `json:"child" gorm:"-"` - ApiName string `json:"api_name" gorm:"->"` - ChildNum int64 `json:"child_num" gorm:"->"` + ExchangeType string `json:"exchangeType" gorm:"type:varchar(20);comment:交易所类型 (字典 exchange_type)"` + Pid int `json:"pid" gorm:"type:int unsigned;omitempty;comment:pid"` + MainId int `json:"mainId" gorm:"type:int;comment:主单id"` + ApiId int `json:"apiId" gorm:"type:varchar(255);omitempty;comment:api用户"` + GroupId string `json:"groupId" gorm:"type:int unsigned;omitempty;comment:交易对组id"` + Symbol string `json:"symbol" gorm:"type:varchar(255);omitempty;comment:交易对"` + QuoteSymbol string `json:"quoteSymbol" gorm:"type:varchar(255);omitempty;comment:计较货币"` + SignPrice string `json:"signPrice" gorm:"type:decimal(18,8);omitempty;comment:对标价"` + SignPriceU decimal.Decimal `json:"signPriceU" gorm:"type:decimal(18,8);omitempty;comment:交易对对标U的行情价"` + SignPriceType string `json:"signPriceType" gorm:"type:enum('new','tall','low','mixture','entrust','add');omitempty;comment:对标价类型: new=最新价格;tall=24小时最高;low=24小时最低;mixture=标记价;entrust=委托实价;add=补仓"` + Rate string `json:"rate" gorm:"type:decimal(18,2);omitempty;comment:下单百分比"` + Price string `json:"price" gorm:"type:decimal(18,8);omitempty;comment:触发价格"` + Num string `json:"num" gorm:"type:decimal(18,8);omitempty;comment:购买数量"` + BuyPrice string `json:"buyPrice" gorm:"type:decimal(18,8);omitempty;comment:购买金额"` + SymbolType int `json:"symbolType" gorm:"type:int;comment:交易对类型:1=现货;2=合约"` + OrderCategory int `json:"orderCategory" gorm:"type:int;comment:订单类型: 1=主单 2=对冲单"` + Site string `json:"site" gorm:"type:enum('BUY','SELL');omitempty;comment:购买方向:BUY=买;SELL=卖"` + OrderSn string `json:"orderSn" gorm:"type:varchar(255);omitempty;comment:订单号"` + OrderType int `json:"orderType" gorm:"type:int;omitempty;comment:订单类型:0=主单 1=止盈 2=止损 3=平仓"` + Desc string `json:"desc" gorm:"type:text;omitempty;comment:订单描述"` + Status int `json:"status" gorm:"type:int;omitempty;comment:是否被触发:0=待触发;1=已触发;2=下单失败;4=已取消;5=委托中;6=已成交;9=已平仓"` + CoverType int `json:"coverType" gorm:"type:int unsigned;omitempty;comment:对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货"` + ExpireTime time.Time `json:"expireTime" gorm:"comment:过期时间"` + MainOrderType string `json:"mainOrderType" gorm:"type:enum;comment:第一笔(主单类型) 限价(LIMIT)市价(MARKET)"` + Child []LinePreOrder `json:"child" gorm:"-"` + ApiName string `json:"api_name" gorm:"->"` + ChildNum int64 `json:"child_num" gorm:"->"` // LinePreOrder 线上预埋单\ models.ModelTime models.ControlBy diff --git a/app/admin/models/line_pre_order_ext.go b/app/admin/models/line_pre_order_ext.go new file mode 100644 index 0000000..e1dd8f8 --- /dev/null +++ b/app/admin/models/line_pre_order_ext.go @@ -0,0 +1,37 @@ +package models + +import ( + "go-admin/common/models" + + "github.com/shopspring/decimal" +) + +type LinePreOrderExt struct { + models.Model + + MainOrderId int `json:"mainOrderId" gorm:"type:bigint;comment:主单id"` + OrderId int `json:"orderId" gorm:"type:bigint;comment:订单id"` + TakeProfitRatio decimal.Decimal `json:"takeProfitRatio" gorm:"type:decimal(10,2);comment:止盈百分比"` + ReducePriceRatio decimal.Decimal `json:"reducePriceRatio" gorm:"type:decimal(10,2);comment:减仓价格百分比"` + ReduceNumRatio decimal.Decimal `json:"reduceNumRatio" gorm:"type:decimal(10,2);comment:减仓数量百分比"` + ReduceTakeProfitRatio decimal.Decimal `json:"reduceTakeProfitRatio" gorm:"type:decimal(10,2);comment:减仓后止盈百分比"` + ReduceStopLossRatio decimal.Decimal `json:"reduceStopLossRatio" gorm:"type:decimal(10,2);comment:减仓后止损百分比"` + AddPositionPriceRatio decimal.Decimal `json:"addPositionPriceRatio" gorm:"type:decimal(10,2);comment:加仓价格百分比"` + AddPositionType int `json:"addPositionType" gorm:"type:int;comment:加仓类型 1-百分比 2-实际金额"` + AddPositionVal decimal.Decimal `json:"addPositionVal" gorm:"type:decimal(10,2);comment:加仓值"` + models.ModelTime + models.ControlBy +} + +func (LinePreOrderExt) TableName() string { + return "line_pre_order_ext" +} + +func (e *LinePreOrderExt) Generate() models.ActiveRecord { + o := *e + return &o +} + +func (e *LinePreOrderExt) GetId() interface{} { + return e.Id +} diff --git a/app/admin/models/line_pre_order_status.go b/app/admin/models/line_pre_order_status.go index 8f47e64..424debc 100644 --- a/app/admin/models/line_pre_order_status.go +++ b/app/admin/models/line_pre_order_status.go @@ -10,7 +10,7 @@ type LinePreOrderStatus struct { OrderId int `json:"orderId" gorm:"type:bigint;comment:主订单id"` OrderSn string `json:"orderSn" gorm:"type:varchar(255);comment:主订单号"` AddPositionStatus int `json:"addPositionStatus" gorm:"type:int;comment:加仓状态 0-无 1-已加仓"` - HedgeStatus int `json:"hedgeStatus" gorm:"type:int;comment:对冲状态 0-无 1-已对冲"` + ReduceStatus int `json:"hedgeStatus" gorm:"type:int;comment:减仓状态 0-无 1-已减仓"` models.ModelTime models.ControlBy } diff --git a/app/admin/router/line_pre_order_ext.go b/app/admin/router/line_pre_order_ext.go new file mode 100644 index 0000000..e9878af --- /dev/null +++ b/app/admin/router/line_pre_order_ext.go @@ -0,0 +1,27 @@ +package router + +import ( + "github.com/gin-gonic/gin" + jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" + + "go-admin/app/admin/apis" + "go-admin/common/middleware" + "go-admin/common/actions" +) + +func init() { + routerCheckRole = append(routerCheckRole, registerLinePreOrderExtRouter) +} + +// registerLinePreOrderExtRouter +func registerLinePreOrderExtRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + api := apis.LinePreOrderExt{} + r := v1.Group("/line-pre-order-ext").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) + { + r.GET("", actions.PermissionAction(), api.GetPage) + r.GET("/:id", actions.PermissionAction(), api.Get) + r.POST("", api.Insert) + r.PUT("/:id", actions.PermissionAction(), api.Update) + r.DELETE("", api.Delete) + } +} \ No newline at end of file diff --git a/app/admin/service/dto/line_pre_order.go b/app/admin/service/dto/line_pre_order.go index d13ff4d..70249fa 100644 --- a/app/admin/service/dto/line_pre_order.go +++ b/app/admin/service/dto/line_pre_order.go @@ -3,7 +3,6 @@ package dto import ( "errors" "strconv" - "time" "go-admin/app/admin/models" "go-admin/common/dto" @@ -48,10 +47,6 @@ type LinePreOrderOrder struct { CoverRate string `form:"coverRateOrder" search:"type:order;column:cover_rate;table:line_pre_order"` Desc string `form:"descOrder" search:"type:order;column:desc;table:line_pre_order"` Status string `form:"statusOrder" search:"type:order;column:status;table:line_pre_order"` - AdminId string `form:"adminIdOrder" search:"type:order;column:admin_id;table:line_pre_order"` - IsAutoScale string `form:"isAutoScaleOrder" search:"type:order;column:is_auto_scale;table:line_pre_order"` - ScaleType string `form:"scaleTypeOrder" search:"type:order;column:scale_type;table:line_pre_order"` - CloseType string `form:"closeTypeOrder" search:"type:order;column:close_type;table:line_pre_order"` CreatedAt string `form:"createdAtOrder" search:"type:order;column:created_at;table:line_pre_order"` UpdatedAt string `form:"updatedAtOrder" search:"type:order;column:updated_at;table:line_pre_order"` DeletedAt string `form:"deletedAtOrder" search:"type:order;column:deleted_at;table:line_pre_order"` @@ -84,11 +79,6 @@ type LinePreOrderInsertReq struct { OrderType int `json:"orderType" comment:"订单类型:0=主单;1=止盈;2=止损;3=平仓"` Desc string `json:"desc" comment:"订单描述"` Status int `json:"status" comment:"是否被触发:0=待触发;1=已触发;2=下单失败;4=已取消;5=委托中;6=已成交;9=已平仓"` - AdminId string `json:"adminId" comment:"操作管理员id"` - IsAutoScale int `json:"isAutoScale" comment:"订单类型:是否为自动加仓 1 = 是 2=手动"` - ScaleType int `json:"scaleType" comment:"是否为普通对冲 1 = 是 2 = 半自动补仓(会自动平B仓)"` - CloseType int `json:"closeType" comment:"平仓类型 是否为盈利平仓 1= 是 0 =否"` - Direction string `json:"direction" comment:"预估方向"` common.ControlBy } @@ -113,8 +103,6 @@ func (s *LinePreOrderInsertReq) Generate(model *models.LinePreOrder) { model.OrderType = s.OrderType model.Desc = s.Desc model.Status = s.Status - model.AdminId = s.AdminId - model.CloseType = s.CloseType model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的 } @@ -123,27 +111,25 @@ func (s *LinePreOrderInsertReq) GetId() interface{} { } type LinePreOrderUpdateReq struct { - Id int `uri:"id" comment:"id"` // id - ExchangeType string `json:"exchangeType" comment:"交易所类型 字典exchange_type"` - Pid string `json:"pid" comment:"pid"` - ApiId string `json:"apiId" comment:"api用户"` - GroupId string `json:"groupId" comment:"交易对组id"` - Symbol string `json:"symbol" comment:"交易对"` - QuoteSymbol string `json:"quoteSymbol" comment:"计较货币"` - SignPrice string `json:"signPrice" comment:"对标价"` - SignPriceType string `json:"signPriceType" comment:"对标价类型: new=最新价格;tall=24小时最高;low=24小时最低;mixture=标记价;entrust=委托实价;add=补仓"` - Rate string `json:"rate" comment:"下单百分比"` - Price string `json:"price" comment:"触发价格"` - Num string `json:"num" comment:"购买数量"` - BuyPrice string `json:"buyPrice" comment:"购买金额"` - Site string `json:"site" comment:"购买方向:BUY=买;SELL=卖"` - OrderSn string `json:"orderSn" comment:"订单号"` - OrderType int `json:"orderType" comment:"订单类型:0=主单;1=止盈;2=止损;3=平仓"` - Desc string `json:"desc" comment:"订单描述"` - Status int `json:"status" comment:"是否被触发:0=待触发;1=已触发;2=下单失败;4=已取消;5=委托中;6=已成交;9=已平仓"` - AdminId string `json:"adminId" comment:"操作管理员id"` - CloseType int `json:"closeType" comment:"平仓类型 是否为盈利平仓 1= 是 0 =否"` - UpdateTime time.Time `json:"updateTime" comment:"修改时间"` + Id int `uri:"id" comment:"id"` // id + ExchangeType string `json:"exchangeType" comment:"交易所类型 字典exchange_type"` + Pid string `json:"pid" comment:"pid"` + MainId int `json:"mainId" comment:"mainId"` + ApiId string `json:"apiId" comment:"api用户"` + GroupId string `json:"groupId" comment:"交易对组id"` + Symbol string `json:"symbol" comment:"交易对"` + QuoteSymbol string `json:"quoteSymbol" comment:"计较货币"` + SignPrice string `json:"signPrice" comment:"对标价"` + SignPriceType string `json:"signPriceType" comment:"对标价类型: new=最新价格;tall=24小时最高;low=24小时最低;mixture=标记价;entrust=委托实价;add=补仓"` + Rate string `json:"rate" comment:"下单百分比"` + Price string `json:"price" comment:"触发价格"` + Num string `json:"num" comment:"购买数量"` + BuyPrice string `json:"buyPrice" comment:"购买金额"` + Site string `json:"site" comment:"购买方向:BUY=买;SELL=卖"` + OrderSn string `json:"orderSn" comment:"订单号"` + OrderType int `json:"orderType" comment:"订单类型:0=主单;1=止盈;2=止损;3=平仓"` + Desc string `json:"desc" comment:"订单描述"` + Status int `json:"status" comment:"是否被触发:0=待触发;1=已触发;2=下单失败;4=已取消;5=委托中;6=已成交;9=已平仓"` common.ControlBy } @@ -169,8 +155,6 @@ func (s *LinePreOrderUpdateReq) Generate(model *models.LinePreOrder) { model.OrderType = s.OrderType model.Desc = s.Desc model.Status = s.Status - model.AdminId = s.AdminId - model.CloseType = s.CloseType model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的 } @@ -197,28 +181,23 @@ func (s *LinePreOrderDeleteReq) GetId() interface{} { } type LineAddPreOrderReq struct { - ExchangeType string `json:"exchange_type"` //交易所类型 - OrderType int `json:"order_type"` //订单类型 - Symbol string `json:"symbol"` //交易对 - ApiUserId string `json:"api_id"` //下单用户 - Site string `json:"site"` //购买方向 - BuyPrice string `json:"buy_price"` //购买金额 U - PricePattern string `json:"price_pattern"` //价格模式 - Price string `json:"price"` //下单价百分比 - Profit string `json:"profit"` //止盈价 - StopPrice string `json:"stop_price"` //止损价 - PriceType string `json:"price_type"` //价格类型 - SaveTemplate string `json:"save_template"` //是否保存模板 - TemplateName string `json:"template_name"` //模板名字 - SymbolType int `json:"symbol_type"` //交易对类型 1-现货 2-合约 - CoverType int `json:"cover_type"` //对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货 - ExpireHour int `json:"expire_hour"` // 过期时间 单位小时 - MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET) - HedgeOrderType string `json:"hedge_order_type"` //第二笔(对冲单)类型:限价(LIMIT)或市价(MARKET) - HedgeBuyType int `json:"hedge_buy_type"` //对冲单购买类型 1-百分比 2-实际金额 - HedgeBuyTotal decimal.Decimal `json:"hedge_buy_total"` //对冲购买金额 - HedgeTakeProfit decimal.Decimal `json:"hedge_take_profit"` //对冲止盈 - HedgeStopLoss decimal.Decimal `json:"hedge_stop_loss"` //对冲止损 + ExchangeType string `json:"exchange_type"` //交易所类型 + OrderType int `json:"order_type"` //订单类型 + Symbol string `json:"symbol"` //交易对 + ApiUserId string `json:"api_id"` //下单用户 + Site string `json:"site"` //购买方向 + BuyPrice string `json:"buy_price"` //购买金额 U + PricePattern string `json:"price_pattern"` //价格模式 + Price string `json:"price"` //下单价百分比 + Profit string `json:"profit"` //止盈价 + StopPrice string `json:"stop_price"` //止损价 + PriceType string `json:"price_type"` //价格类型 + SaveTemplate string `json:"save_template"` //是否保存模板 + TemplateName string `json:"template_name"` //模板名字 + SymbolType int `json:"symbol_type"` //交易对类型 1-现货 2-合约 + CoverType int `json:"cover_type"` //对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货 + ExpireHour int `json:"expire_hour"` // 过期时间 单位小时 + MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET) } func (req LineAddPreOrderReq) CheckParams() error { @@ -250,31 +229,26 @@ func (req LineAddPreOrderReq) CheckParams() error { // LineBatchAddPreOrderReq 批量添加订单请求参数 type LineBatchAddPreOrderReq struct { - ExchangeType string `json:"exchange_type"` //交易所类型 字典exchange_type - SymbolType int `json:"symbolType"` //主单交易对类型 0-现货 1-合约 - OrderType int `json:"order_type"` //订单类型 - SymbolGroupId string `json:"symbol_group_id"` //交易对组id - Symbol string `json:"symbol"` //交易对 - ApiUserId string `json:"api_id"` //下单用户 - Site string `json:"site"` //购买方向 - BuyPrice string `json:"buy_price"` //购买金额 U - PricePattern string `json:"price_pattern"` //价格模式 - Price string `json:"price"` //下单价百分比 - Profit string `json:"profit"` //止盈价 - StopPrice string `json:"stop_price"` //止损价 - PriceType string `json:"price_type"` //价格类型 - SaveTemplate string `json:"save_template"` //是否保存模板 - TemplateName string `json:"template_name"` //模板名字 - OrderNum int `json:"order_num"` //脚本运行次数 - Script string `json:"script"` //是否是脚本运行 1 = 是 0= 否 - CoverType int `json:"cover_type"` //对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货 - ExpireHour int `json:"expire_hour"` // 过期时间 单位小时 - MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET) - HedgeOrderType string `json:"hedge_order_type"` //第二笔(对冲单)类型:限价(LIMIT)或市价(MARKET) - HedgeBuyType int `json:"hedge_buy_type"` //对冲单购买类型 1-百分比 2-实际金额 - HedgeBuyTotal decimal.Decimal `json:"hedge_buy_total"` //对冲购买金额 - HedgeTakeProfit decimal.Decimal `json:"hedge_take_profit"` //对冲止盈 - HedgeStopLoss decimal.Decimal `json:"hedge_stop_loss"` //对冲止损 + ExchangeType string `json:"exchange_type"` //交易所类型 字典exchange_type + SymbolType int `json:"symbolType"` //主单交易对类型 0-现货 1-合约 + OrderType int `json:"order_type"` //订单类型 + SymbolGroupId string `json:"symbol_group_id"` //交易对组id + Symbol string `json:"symbol"` //交易对 + ApiUserId string `json:"api_id"` //下单用户 + Site string `json:"site"` //购买方向 + BuyPrice string `json:"buy_price"` //购买金额 U + PricePattern string `json:"price_pattern"` //价格模式 + Price string `json:"price"` //下单价百分比 + Profit string `json:"profit"` //止盈价 + StopPrice string `json:"stop_price"` //止损价 + PriceType string `json:"price_type"` //价格类型 + SaveTemplate string `json:"save_template"` //是否保存模板 + TemplateName string `json:"template_name"` //模板名字 + OrderNum int `json:"order_num"` //脚本运行次数 + Script string `json:"script"` //是否是脚本运行 1 = 是 0= 否 + CoverType int `json:"cover_type"` //对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货 + ExpireHour int `json:"expire_hour"` // 过期时间 单位小时 + MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET) } func (req LineBatchAddPreOrderReq) CheckParams() error { diff --git a/app/admin/service/dto/line_pre_order_ext.go b/app/admin/service/dto/line_pre_order_ext.go new file mode 100644 index 0000000..c4e8f47 --- /dev/null +++ b/app/admin/service/dto/line_pre_order_ext.go @@ -0,0 +1,127 @@ +package dto + +import ( + "go-admin/app/admin/models" + "go-admin/common/dto" + common "go-admin/common/models" + + "github.com/shopspring/decimal" +) + +type LinePreOrderExtGetPageReq struct { + dto.Pagination `search:"-"` + LinePreOrderExtOrder +} + +type LinePreOrderExtOrder struct { + Id string `form:"idOrder" search:"type:order;column:id;table:line_pre_order_ext"` + MainOrderId string `form:"mainOrderIdOrder" search:"type:order;column:main_order_id;table:line_pre_order_ext"` + OrderId string `form:"orderIdOrder" search:"type:order;column:order_id;table:line_pre_order_ext"` + TakeProfitRatio string `form:"takeProfitRatioOrder" search:"type:order;column:take_profit_ratio;table:line_pre_order_ext"` + ReducePriceRatio string `form:"reducePriceRatioOrder" search:"type:order;column:reduce_price_ratio;table:line_pre_order_ext"` + ReduceNumRatio string `form:"reduceNumRatioOrder" search:"type:order;column:reduce_num_ratio;table:line_pre_order_ext"` + ReduceTakeProfitRatio string `form:"reduceTakeProfitRatioOrder" search:"type:order;column:reduce_take_profit_ratio;table:line_pre_order_ext"` + ReduceStopLossRatio string `form:"reduceStopLossRatioOrder" search:"type:order;column:reduce_stop_loss_ratio;table:line_pre_order_ext"` + AddPositionPriceRatio string `form:"addPositionPriceRatioOrder" search:"type:order;column:add_position_price_ratio;table:line_pre_order_ext"` + AddPositionType string `form:"addPositionTypeOrder" search:"type:order;column:add_position_type;table:line_pre_order_ext"` + AddPositionVal string `form:"addPositionValOrder" search:"type:order;column:add_position_val;table:line_pre_order_ext"` + CreatedAt string `form:"createdAtOrder" search:"type:order;column:created_at;table:line_pre_order_ext"` + UpdatedAt string `form:"updatedAtOrder" search:"type:order;column:updated_at;table:line_pre_order_ext"` + DeletedAt string `form:"deletedAtOrder" search:"type:order;column:deleted_at;table:line_pre_order_ext"` + CreateBy string `form:"createByOrder" search:"type:order;column:create_by;table:line_pre_order_ext"` + UpdateBy string `form:"updateByOrder" search:"type:order;column:update_by;table:line_pre_order_ext"` +} + +func (m *LinePreOrderExtGetPageReq) GetNeedSearch() interface{} { + return *m +} + +type LinePreOrderExtInsertReq struct { + Id int `json:"-" comment:"主键id"` // 主键id + MainOrderId int `json:"mainOrderId" comment:"主单id"` + OrderId int `json:"orderId" comment:"订单id"` + TakeProfitRatio decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"` + ReducePriceRatio decimal.Decimal `json:"reducePriceRatio" comment:"减仓价格百分比"` + ReduceNumRatio decimal.Decimal `json:"reduceNumRatio" comment:"减仓数量百分比"` + ReduceTakeProfitRatio decimal.Decimal `json:"reduceTakeProfitRatio" comment:"减仓后止盈百分比"` + ReduceStopLossRatio decimal.Decimal `json:"reduceStopLossRatio" comment:"减仓后止损百分比"` + AddPositionPriceRatio decimal.Decimal `json:"addPositionPriceRatio" comment:"加仓价格百分比"` + AddPositionType int `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"` + AddPositionVal decimal.Decimal `json:"addPositionVal" comment:"加仓值"` + common.ControlBy +} + +func (s *LinePreOrderExtInsertReq) Generate(model *models.LinePreOrderExt) { + if s.Id == 0 { + model.Model = common.Model{Id: s.Id} + } + model.MainOrderId = s.MainOrderId + model.OrderId = s.OrderId + model.TakeProfitRatio = s.TakeProfitRatio + model.ReducePriceRatio = s.ReducePriceRatio + model.ReduceNumRatio = s.ReduceNumRatio + model.ReduceTakeProfitRatio = s.ReduceTakeProfitRatio + model.ReduceStopLossRatio = s.ReduceStopLossRatio + model.AddPositionPriceRatio = s.AddPositionPriceRatio + model.AddPositionType = s.AddPositionType + model.AddPositionVal = s.AddPositionVal + model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的 +} + +func (s *LinePreOrderExtInsertReq) GetId() interface{} { + return s.Id +} + +type LinePreOrderExtUpdateReq struct { + Id int `uri:"id" comment:"主键id"` // 主键id + MainOrderId int `json:"mainOrderId" comment:"主单id"` + OrderId int `json:"orderId" comment:"订单id"` + TakeProfitRatio decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"` + ReducePriceRatio decimal.Decimal `json:"reducePriceRatio" comment:"减仓价格百分比"` + ReduceNumRatio decimal.Decimal `json:"reduceNumRatio" comment:"减仓数量百分比"` + ReduceTakeProfitRatio decimal.Decimal `json:"reduceTakeProfitRatio" comment:"减仓后止盈百分比"` + ReduceStopLossRatio decimal.Decimal `json:"reduceStopLossRatio" comment:"减仓后止损百分比"` + AddPositionPriceRatio decimal.Decimal `json:"addPositionPriceRatio" comment:"加仓价格百分比"` + AddPositionType int `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"` + AddPositionVal decimal.Decimal `json:"addPositionVal" comment:"加仓值"` + common.ControlBy +} + +func (s *LinePreOrderExtUpdateReq) Generate(model *models.LinePreOrderExt) { + if s.Id == 0 { + model.Model = common.Model{Id: s.Id} + } + model.MainOrderId = s.MainOrderId + model.OrderId = s.OrderId + model.TakeProfitRatio = s.TakeProfitRatio + model.ReducePriceRatio = s.ReducePriceRatio + model.ReduceNumRatio = s.ReduceNumRatio + model.ReduceTakeProfitRatio = s.ReduceTakeProfitRatio + model.ReduceStopLossRatio = s.ReduceStopLossRatio + model.AddPositionPriceRatio = s.AddPositionPriceRatio + model.AddPositionType = s.AddPositionType + model.AddPositionVal = s.AddPositionVal + model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的 +} + +func (s *LinePreOrderExtUpdateReq) GetId() interface{} { + return s.Id +} + +// LinePreOrderExtGetReq 功能获取请求参数 +type LinePreOrderExtGetReq struct { + Id int `uri:"id"` +} + +func (s *LinePreOrderExtGetReq) GetId() interface{} { + return s.Id +} + +// LinePreOrderExtDeleteReq 功能删除请求参数 +type LinePreOrderExtDeleteReq struct { + Ids []int `json:"ids"` +} + +func (s *LinePreOrderExtDeleteReq) GetId() interface{} { + return s.Ids +} diff --git a/app/admin/service/dto/line_pre_order_status.go b/app/admin/service/dto/line_pre_order_status.go index e45bcf9..d0fcbb4 100644 --- a/app/admin/service/dto/line_pre_order_status.go +++ b/app/admin/service/dto/line_pre_order_status.go @@ -44,7 +44,6 @@ func (s *LinePreOrderStatusInsertReq) Generate(model *models.LinePreOrderStatus) model.OrderId = s.OrderId model.OrderSn = s.OrderSn model.AddPositionStatus = s.AddPositionStatus - model.HedgeStatus = s.HedgeStatus model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的 } @@ -68,7 +67,6 @@ func (s *LinePreOrderStatusUpdateReq) Generate(model *models.LinePreOrderStatus) model.OrderId = s.OrderId model.OrderSn = s.OrderSn model.AddPositionStatus = s.AddPositionStatus - model.HedgeStatus = s.HedgeStatus model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的 } diff --git a/app/admin/service/line_pre_order.go b/app/admin/service/line_pre_order.go index ec2ab4e..2630e1b 100644 --- a/app/admin/service/line_pre_order.go +++ b/app/admin/service/line_pre_order.go @@ -44,13 +44,13 @@ func (e *LinePreOrder) GetPage(c *dto.LinePreOrderGetPageReq, p *actions.DataPer actions.Permission(data.TableName(), p), ).Where("pid = 0").Joins("JOIN line_api_user on line_api_user.id = line_pre_order.api_id"). Joins("JOIN line_pre_order_status on line_pre_order_status.order_sn = line_pre_order.order_sn"). - Select("line_pre_order.*,line_api_user.api_name,line_pre_order_status.add_position_status,line_pre_order_status.hedge_status") + Select("line_pre_order.*,line_api_user.api_name,line_pre_order_status.add_position_status,line_pre_order_status.reduce_status") if c.AddPositionStatus >= 0 { tx.Where("line_pre_order_status.add_position_status = ?", c.AddPositionStatus) } if c.HedgeStatus >= 0 { - tx.Where("line_pre_order_status.hedge_status = ?", c.HedgeStatus) + tx.Where("line_pre_order_status.reduce_status = ?", c.HedgeStatus) } err = tx. @@ -79,13 +79,13 @@ func (e *LinePreOrder) GetOrderPage(c *dto.LinePreOrderGetPageReq, p *actions.Da actions.Permission(data.TableName(), p), ).Where("pid = 0 AND status != '0'").Joins("JOIN line_api_user on line_api_user.id = line_pre_order.api_id"). Joins("JOIN line_pre_order_status on line_pre_order_status.order_id = line_pre_order.id"). - Select("line_pre_order.*,line_api_user.api_name,line_pre_order_status.add_position_status,line_pre_order_status.hedge_status") + Select("line_pre_order.*,line_api_user.api_name,line_pre_order_status.add_position_status,line_pre_order_status.reduce_status") if c.AddPositionStatus >= 0 { tx.Where("line_pre_order_status.add_position_status = ?", c.AddPositionStatus) } if c.HedgeStatus >= 0 { - tx.Where("line_pre_order_status.hedge_status = ?", c.HedgeStatus) + tx.Where("line_pre_order_status.reduce_status = ?", c.HedgeStatus) } err = tx. Find(list).Limit(-1).Offset(-1). @@ -369,7 +369,6 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP continue } - AddOrder.HedgeBuyType = req.HedgeBuyType AddOrder.ExchangeType = req.ExchangeType AddOrder.OrderCategory = 1 AddOrder.SignPriceType = "new" @@ -382,7 +381,6 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP } AddOrder.ExpireTime = time.Now().Add(time.Duration(req.ExpireHour) * time.Hour) //过期时间 AddOrder.MainOrderType = req.MainOrderType - AddOrder.HedgeOrderType = req.HedgeOrderType AddOrder.Site = req.Site if req.PricePattern == "percentage" { AddOrder.Rate = req.Price @@ -447,11 +445,7 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP AddOrder.QuoteSymbol = symbolInfo.QuoteAsset AddOrder.Pid = 0 AddOrder.GroupId = "0" - AddOrder.AdminId = "0" AddOrder.Status = 0 - AddOrder.HedgeBuyTotal = req.HedgeBuyTotal - AddOrder.HedgeStopLoss = req.HedgeStopLoss - AddOrder.HedgeTakeProfit = req.HedgeTakeProfit copier.Copy(&profitOrder, &AddOrder) copier.Copy(&stopOrder, &AddOrder) @@ -619,7 +613,6 @@ func (e *LinePreOrder) AddBatchPreOrder(batchReq *dto.LineBatchAddPreOrderReq, p req.CoverType = batchReq.CoverType req.ExpireHour = batchReq.ExpireHour req.MainOrderType = batchReq.MainOrderType - req.HedgeOrderType = batchReq.HedgeOrderType e.AddPreOrder(&req, p, errs, tickerSymbol) } @@ -1045,30 +1038,27 @@ func (e *LinePreOrder) SpotClosePosition(position *dto.ClosePosition, errs *[]er continue } order := models.LinePreOrder{ - ExchangeType: global.EXCHANGE_BINANCE, - Pid: list.Id, - ApiId: list.ApiId, - GroupId: "0", - Symbol: list.Symbol, - QuoteSymbol: list.QuoteSymbol, - SignPrice: lastPrice.String(), - SignPriceType: "new", - Rate: position.Rate, - Price: price.String(), - Num: total.String(), - BuyPrice: "0", - Site: "SELL", - OrderSn: paramsMaps["newClientOrderId"], - OrderType: 3, - Desc: "", - Status: 0, - AdminId: "0", - CloseType: 0, - CoverType: list.CoverType, - ExpireTime: time.Now().Add(time.Hour * 24 * 30), - MainOrderType: list.MainOrderType, - HedgeOrderType: list.HedgeOrderType, - Child: nil, + ExchangeType: global.EXCHANGE_BINANCE, + Pid: list.Id, + ApiId: list.ApiId, + GroupId: "0", + Symbol: list.Symbol, + QuoteSymbol: list.QuoteSymbol, + SignPrice: lastPrice.String(), + SignPriceType: "new", + Rate: position.Rate, + Price: price.String(), + Num: total.String(), + BuyPrice: "0", + Site: "SELL", + OrderSn: paramsMaps["newClientOrderId"], + OrderType: 3, + Desc: "", + Status: 0, + CoverType: list.CoverType, + ExpireTime: time.Now().Add(time.Hour * 24 * 30), + MainOrderType: list.MainOrderType, + Child: nil, } err := e.Orm.Model(&models.LinePreOrder{}).Create(&order).Error if err != nil { @@ -1155,29 +1145,26 @@ func (e *LinePreOrder) FutClosePosition(position *dto.ClosePosition, errs *[]err } order := models.LinePreOrder{ - Pid: parentId, - ApiId: list.ApiId, - GroupId: "0", - Symbol: list.Symbol, - QuoteSymbol: list.QuoteSymbol, - SignPrice: lastPrice.String(), - SignPriceType: "new", - Rate: position.Rate, - Price: price.String(), - Num: positionAmt.Abs().String(), - BuyPrice: "0", - Site: orderSide, - OrderSn: utility.Int64ToString(snowflakehelper.GetOrderId()), - OrderType: 3, - Desc: "", - Status: 0, - AdminId: "0", - CloseType: 0, - CoverType: list.CoverType, - ExpireTime: time.Now().Add(24 * 30 * time.Hour), - MainOrderType: list.MainOrderType, - HedgeOrderType: list.HedgeOrderType, - Child: nil, + Pid: parentId, + ApiId: list.ApiId, + GroupId: "0", + Symbol: list.Symbol, + QuoteSymbol: list.QuoteSymbol, + SignPrice: lastPrice.String(), + SignPriceType: "new", + Rate: position.Rate, + Price: price.String(), + Num: positionAmt.Abs().String(), + BuyPrice: "0", + Site: orderSide, + OrderSn: utility.Int64ToString(snowflakehelper.GetOrderId()), + OrderType: 3, + Desc: "", + Status: 0, + CoverType: list.CoverType, + ExpireTime: time.Now().Add(24 * 30 * time.Hour), + MainOrderType: list.MainOrderType, + Child: nil, } err = e.Orm.Model(&models.LinePreOrder{}).Create(&order).Error if err != nil { diff --git a/app/admin/service/line_pre_order_ext.go b/app/admin/service/line_pre_order_ext.go new file mode 100644 index 0000000..4d249b8 --- /dev/null +++ b/app/admin/service/line_pre_order_ext.go @@ -0,0 +1,109 @@ +package service + +import ( + "errors" + + "github.com/go-admin-team/go-admin-core/sdk/service" + "gorm.io/gorm" + + "go-admin/app/admin/models" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" + cDto "go-admin/common/dto" +) + +type LinePreOrderExt struct { + service.Service +} + +// GetPage 获取LinePreOrderExt列表 +func (e *LinePreOrderExt) GetPage(c *dto.LinePreOrderExtGetPageReq, p *actions.DataPermission, list *[]models.LinePreOrderExt, count *int64) error { + var err error + var data models.LinePreOrderExt + + err = e.Orm.Model(&data). + Scopes( + cDto.MakeCondition(c.GetNeedSearch()), + cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), + actions.Permission(data.TableName(), p), + ). + Find(list).Limit(-1).Offset(-1). + Count(count).Error + if err != nil { + e.Log.Errorf("LinePreOrderExtService GetPage error:%s \r\n", err) + return err + } + return nil +} + +// Get 获取LinePreOrderExt对象 +func (e *LinePreOrderExt) Get(d *dto.LinePreOrderExtGetReq, p *actions.DataPermission, model *models.LinePreOrderExt) error { + var data models.LinePreOrderExt + + err := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ). + First(model, d.GetId()).Error + if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { + err = errors.New("查看对象不存在或无权查看") + e.Log.Errorf("Service GetLinePreOrderExt error:%s \r\n", err) + return err + } + if err != nil { + e.Log.Errorf("db error:%s", err) + return err + } + return nil +} + +// Insert 创建LinePreOrderExt对象 +func (e *LinePreOrderExt) Insert(c *dto.LinePreOrderExtInsertReq) error { + var err error + var data models.LinePreOrderExt + c.Generate(&data) + err = e.Orm.Create(&data).Error + if err != nil { + e.Log.Errorf("LinePreOrderExtService Insert error:%s \r\n", err) + return err + } + return nil +} + +// Update 修改LinePreOrderExt对象 +func (e *LinePreOrderExt) Update(c *dto.LinePreOrderExtUpdateReq, p *actions.DataPermission) error { + var err error + var data = models.LinePreOrderExt{} + e.Orm.Scopes( + actions.Permission(data.TableName(), p), + ).First(&data, c.GetId()) + c.Generate(&data) + + db := e.Orm.Save(&data) + if err = db.Error; err != nil { + e.Log.Errorf("LinePreOrderExtService Save error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权更新该数据") + } + return nil +} + +// Remove 删除LinePreOrderExt +func (e *LinePreOrderExt) Remove(d *dto.LinePreOrderExtDeleteReq, p *actions.DataPermission) error { + var data models.LinePreOrderExt + + db := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ).Delete(&data, d.GetId()) + if err := db.Error; err != nil { + e.Log.Errorf("Service RemoveLinePreOrderExt error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权删除该数据") + } + return nil +} diff --git a/config/settings.yml b/config/settings.yml index 3d888a0..8f76234 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -31,7 +31,7 @@ settings: # sqlserver: sqlserver://用户名:密码@地址?database=数据库名 driver: mysql # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms - source: root:root@tcp(192.168.1.12:3306)/go_exchange?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms + source: root:root@tcp(192.168.1.12:3306)/go_exchange_single?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms # databases: # 'locaohost:8000': # driver: mysql @@ -42,7 +42,7 @@ settings: # - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms gen: # 代码生成读取的数据库名称 - dbname: gp-bian + dbname: go_exchange_single # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src extend: # 扩展项使用说明 @@ -53,7 +53,7 @@ settings: redis: addr: "192.168.1.12:6379" password: "" - db: 1 + db: 2 # 雪花算法设备id serviceId: 1 diff --git a/services/binanceservice/futuresrest.go b/services/binanceservice/futuresrest.go index 5117f65..17f6218 100644 --- a/services/binanceservice/futuresrest.go +++ b/services/binanceservice/futuresrest.go @@ -152,10 +152,10 @@ func triggerHedgeOrder(order DbModels.LinePreOrder, db *gorm.DB, preOrder *DbMod } // 检查对冲单购买金额 - if order.HedgeBuyTotal.Cmp(decimal.Zero) <= 0 { - logger.Errorf("止损单成交 对冲单购买金额为0 订单号:%s", order.OrderSn) - return true - } + // if order.HedgeBuyTotal.Cmp(decimal.Zero) <= 0 { + // logger.Errorf("止损单成交 对冲单购买金额为0 订单号:%s", order.OrderSn) + // return true + // } // 获取系统设置 setting, err := GetSystemSetting(db) @@ -200,12 +200,12 @@ func triggerHedgeOrder(order DbModels.LinePreOrder, db *gorm.DB, preOrder *DbMod // 创建对冲订单 func createHedgeOrders(order DbModels.LinePreOrder, price decimal.Decimal, tradeSet *models2.TradeSet, apiInfo *DbModels.LineApiUser, setting *DbModels.LineSystemSetting) (DbModels.LinePreOrder, DbModels.LinePreOrder, DbModels.LinePreOrder) { - buyPrice := order.HedgeBuyTotal.String() + // buyPrice := order.HedgeBuyTotal.String() - if order.HedgeBuyType == 1 { - mainTotal := utility.StrToDecimal(order.BuyPrice) - buyPrice = mainTotal.Mul(order.HedgeBuyTotal).Truncate(int32(tradeSet.PriceDigit)).String() - } + // if order.HedgeBuyType == 1 { + // mainTotal := utility.StrToDecimal(order.BuyPrice) + // buyPrice = mainTotal.Mul(order.HedgeBuyTotal).Truncate(int32(tradeSet.PriceDigit)).String() + // } hedgeOrder := DbModels.LinePreOrder{ ApiId: apiInfo.Id, @@ -216,12 +216,12 @@ func createHedgeOrders(order DbModels.LinePreOrder, price decimal.Decimal, trade SignPrice: order.Price, SignPriceType: "new", Rate: "0", - BuyPrice: buyPrice, + // BuyPrice: buyPrice, OrderCategory: 2, OrderSn: utility.Int64ToString(snowflakehelper.GetOrderId()), OrderType: 0, CoverType: 0, - MainOrderType: order.HedgeOrderType, + // MainOrderType: order.HedgeOrderType, } hedgeStoplossOrder := order @@ -238,30 +238,30 @@ func createHedgeOrders(order DbModels.LinePreOrder, price decimal.Decimal, trade } // 计算止盈止损价格 - if hedgeOrder.Site == "BUY" { - hedgeTakeProfitOrder.Price = price.Mul(decimal.NewFromInt(1).Add(order.HedgeTakeProfit.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() - hedgeStoplossOrder.Price = price.Mul(decimal.NewFromInt(1).Sub(order.HedgeStopLoss.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() - } else { - hedgeTakeProfitOrder.Price = price.Mul(decimal.NewFromInt(1).Sub(order.HedgeTakeProfit.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() - hedgeStoplossOrder.Price = price.Mul(decimal.NewFromInt(1).Add(order.HedgeStopLoss.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() - } + // if hedgeOrder.Site == "BUY" { + // hedgeTakeProfitOrder.Price = price.Mul(decimal.NewFromInt(1).Add(order.HedgeTakeProfit.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() + // hedgeStoplossOrder.Price = price.Mul(decimal.NewFromInt(1).Sub(order.HedgeStopLoss.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() + // } else { + // hedgeTakeProfitOrder.Price = price.Mul(decimal.NewFromInt(1).Sub(order.HedgeTakeProfit.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() + // hedgeStoplossOrder.Price = price.Mul(decimal.NewFromInt(1).Add(order.HedgeStopLoss.Div(decimal.NewFromInt(100)))).Truncate(int32(tradeSet.PriceDigit)).String() + // } if hedgeOrder.MainOrderType == "LIMIT" { coverRate := utility.StrToDecimal(setting.CoverOrderTypeBRate) price = price.Mul(decimal.NewFromInt(1).Add(coverRate)).Truncate(int32(tradeSet.PriceDigit)) } - num := order.HedgeBuyTotal.Div(price).Truncate(int32(tradeSet.AmountDigit)) + // num := order.HedgeBuyTotal.Div(price).Truncate(int32(tradeSet.AmountDigit)) hedgeOrder.Price = price.String() - hedgeOrder.Num = num.String() + // hedgeOrder.Num = num.String() hedgeStoplossOrder.OrderSn = utility.Int64ToString(snowflakehelper.GetOrderId()) - hedgeStoplossOrder.Rate = order.HedgeStopLoss.String() - hedgeStoplossOrder.Num = num.String() + // hedgeStoplossOrder.Rate = order.HedgeStopLoss.String() + // hedgeStoplossOrder.Num = num.String() hedgeTakeProfitOrder.OrderSn = utility.Int64ToString(snowflakehelper.GetOrderId()) - hedgeTakeProfitOrder.Rate = order.HedgeTakeProfit.String() - hedgeTakeProfitOrder.Num = num.String() + // hedgeTakeProfitOrder.Rate = order.HedgeTakeProfit.String() + // hedgeTakeProfitOrder.Num = num.String() return hedgeOrder, hedgeStoplossOrder, hedgeTakeProfitOrder }