1代码生成

This commit is contained in:
2025-02-08 18:01:53 +08:00
parent 979ef507fe
commit 52860fc37f
12 changed files with 647 additions and 203 deletions

View File

@ -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(), "删除成功")
}

View File

@ -11,6 +11,7 @@ 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"`
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:交易对"`
@ -29,16 +30,9 @@ type LinePreOrder struct {
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:"->"`

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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 // 添加这而,需要记录是被谁创建的
}
@ -126,6 +114,7 @@ type LinePreOrderUpdateReq struct {
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:"交易对"`
@ -141,9 +130,6 @@ type LinePreOrderUpdateReq 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"`
CloseType int `json:"closeType" comment:"平仓类型 是否为盈利平仓 1= 是 0 =否"`
UpdateTime time.Time `json:"updateTime" comment:"修改时间"`
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 // 添加这而,需要记录是被谁更新的
}
@ -214,11 +198,6 @@ type LineAddPreOrderReq struct {
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"` //对冲止损
}
func (req LineAddPreOrderReq) CheckParams() error {
@ -270,11 +249,6 @@ type LineBatchAddPreOrderReq struct {
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"` //对冲止损
}
func (req LineBatchAddPreOrderReq) CheckParams() error {

View File

@ -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
}

View File

@ -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 // 添加这而,需要记录是被谁更新的
}

View File

@ -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)
}
@ -1062,12 +1055,9 @@ func (e *LinePreOrder) SpotClosePosition(position *dto.ClosePosition, errs *[]er
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,
}
err := e.Orm.Model(&models.LinePreOrder{}).Create(&order).Error
@ -1171,12 +1161,9 @@ func (e *LinePreOrder) FutClosePosition(position *dto.ClosePosition, errs *[]err
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,
}
err = e.Orm.Model(&models.LinePreOrder{}).Create(&order).Error

View File

@ -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
}

View File

@ -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

View File

@ -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
}