1
This commit is contained in:
@ -91,6 +91,45 @@ func (e LineDirection) Get(c *gin.Context) {
|
||||
e.OK(object, "查询成功")
|
||||
}
|
||||
|
||||
// Get 获取预估方向管理
|
||||
// @Summary 获取预估方向管理
|
||||
// @Description 获取预估方向管理
|
||||
// @Tags 预估方向管理
|
||||
// @Param id path int false "id"
|
||||
// @Success 200 {object} response.Response{data=models.LineDirection} "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/line-direction/{id} [get]
|
||||
// @Security Bearer
|
||||
func (e LineDirection) GetBySymbol(c *gin.Context) {
|
||||
req := dto.LineDirectionGetReq{}
|
||||
s := service.LineDirection{}
|
||||
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
|
||||
}
|
||||
|
||||
if req.Symbol == "" || req.SymbolType == 0 {
|
||||
e.Error(500, nil, "参数缺失")
|
||||
return
|
||||
}
|
||||
|
||||
var object models.LineDirection
|
||||
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
err = s.GetBySymbol(&req, p, &object)
|
||||
if err != nil {
|
||||
e.Error(500, err, fmt.Sprintf("获取预估方向管理失败,\r\n失败信息 %s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(object, "查询成功")
|
||||
}
|
||||
|
||||
// Insert 创建预估方向管理
|
||||
// @Summary 创建预估方向管理
|
||||
// @Description 创建预估方向管理
|
||||
|
||||
@ -33,7 +33,7 @@ type LinePreOrder struct {
|
||||
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)"`
|
||||
LossAmount decimal.Decimal `json:"lossAmount" gorm:"type:decimal(15,2);comment:亏损金额(U)"`
|
||||
LossAmount decimal.Decimal `json:"lossAmount" gorm:"type:decimal(18,8);comment:亏损金额(U)"`
|
||||
Child []LinePreOrder `json:"child" gorm:"-"`
|
||||
ApiName string `json:"api_name" gorm:"->"`
|
||||
ChildNum int64 `json:"child_num" gorm:"->"`
|
||||
|
||||
@ -30,6 +30,7 @@ func registerLineDirectionRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWT
|
||||
{
|
||||
r.GET("", actions.PermissionAction(), api.GetPage)
|
||||
r.GET("/:id", actions.PermissionAction(), api.Get)
|
||||
r.GET("/symbol", actions.PermissionAction(), api.GetBySymbol)
|
||||
r.POST("", api.Insert)
|
||||
r.PUT("/:id", actions.PermissionAction(), api.Update)
|
||||
r.DELETE("", api.Delete)
|
||||
|
||||
@ -114,7 +114,9 @@ func (s *LineDirectionUpdateReq) GetId() interface{} {
|
||||
|
||||
// LineDirectionGetReq 功能获取请求参数
|
||||
type LineDirectionGetReq struct {
|
||||
Id int `uri:"id"`
|
||||
Id int `uri:"id"`
|
||||
Symbol string `json:"symbol" form:"symbol"`
|
||||
SymbolType int `json:"symbolType" form:"symbolType"`
|
||||
}
|
||||
|
||||
func (s *LineDirectionGetReq) GetId() interface{} {
|
||||
|
||||
@ -234,31 +234,31 @@ 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)
|
||||
ReducePriceRatio decimal.Decimal `json:"reduce_price"` //主单减仓价格百分比
|
||||
ReduceNumRatio decimal.Decimal `json:"reduce_num"` //主单减仓数量百分比
|
||||
ReduceTakeProfitRatio decimal.Decimal `json:"reduce_take_profit"` //主单减仓后止盈价百分比
|
||||
ReduceStopLossRatio decimal.Decimal `json:"reduce_stop_price"` //主单减仓后止损价百分比
|
||||
Ext LineAddPreOrderExtReq `json:"ext"` //拓展字段
|
||||
ExchangeType string `json:"exchange_type"` //交易所类型 字典exchange_type
|
||||
SymbolType int `json:"symbol_type"` //主单交易对类型 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)
|
||||
ReducePriceRatio decimal.Decimal `json:"reduce_price"` //主单减仓价格百分比
|
||||
ReduceNumRatio decimal.Decimal `json:"reduce_num"` //主单减仓数量百分比
|
||||
ReduceTakeProfitRatio decimal.Decimal `json:"reduce_take_profit"` //主单减仓后止盈价百分比
|
||||
ReduceStopLossRatio decimal.Decimal `json:"reduce_stop_price"` //主单减仓后止损价百分比
|
||||
Ext []LineAddPreOrderExtReq `json:"ext"` //拓展字段
|
||||
}
|
||||
|
||||
func (req LineBatchAddPreOrderReq) CheckParams() error {
|
||||
@ -337,6 +337,11 @@ type GetChildOrderReq struct {
|
||||
Id int `json:"id"` //id
|
||||
}
|
||||
|
||||
type LinePreOrderChildCount struct {
|
||||
Id int `json:"id"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
func (c MarginTypeReq) CheckParams() error {
|
||||
if c.Symbol == "" && c.GroupId == 0 {
|
||||
return errors.New("请选择交易对或交易对组")
|
||||
|
||||
@ -43,6 +43,7 @@ type LineAddPreOrderExtReq struct {
|
||||
ReduceTakeProfitRatio decimal.Decimal `json:"reduceTakeProfitRatio" comment:"减仓后止盈百分比"`
|
||||
ReduceStopLossRatio decimal.Decimal `json:"reduceStopLossRatio" comment:"减仓后止损百分比"`
|
||||
AddPositionPriceRatio decimal.Decimal `json:"addPositionPriceRatio" comment:"加仓价格百分比"`
|
||||
AddPositionOrderType string `json:"addPositionOrderType" comment:"加仓订单类型 LIMIT-限价 MARKET-市价"`
|
||||
AddPositionType int `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"`
|
||||
AddPositionVal decimal.Decimal `json:"addPositionVal" comment:"加仓值"`
|
||||
}
|
||||
|
||||
@ -77,6 +77,8 @@ func (s *LineSystemSettingUpdateReq) Generate(model *models.LineSystemSetting) {
|
||||
model.ProfitRate = s.ProfitRate
|
||||
model.CoverOrderTypeBRate = s.CoverOrderTypeBRate
|
||||
model.StopLossPremium = s.StopLossPremium
|
||||
model.AddPositionPremium = s.AddPositionPremium
|
||||
model.ReducePremium = s.ReducePremium
|
||||
model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,25 @@ func (e *LineDirection) Get(d *dto.LineDirectionGetReq, p *actions.DataPermissio
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get 获取LineDirection对象
|
||||
func (e *LineDirection) GetBySymbol(d *dto.LineDirectionGetReq, p *actions.DataPermission, model *models.LineDirection) error {
|
||||
var data models.LineDirection
|
||||
|
||||
err := e.Orm.Model(&data).
|
||||
Where("symbol =? AND type =?", d.Symbol, d.SymbolType).
|
||||
First(model).Error
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = errors.New("查看对象不存在")
|
||||
e.Log.Errorf("Service GetLineDirection error:%s \r\n", err)
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
e.Log.Errorf("db error:%s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert 创建LineDirection对象
|
||||
func (e *LineDirection) Insert(c *dto.LineDirectionInsertReq) error {
|
||||
var err error
|
||||
|
||||
@ -139,6 +139,29 @@ func (e *LinePreOrder) GetChildList(req *dto.GetChildOrderReq, p *actions.DataPe
|
||||
e.Log.Errorf("LinePreOrderService GetPage error:%s \r\n", err)
|
||||
return err
|
||||
}
|
||||
ids := make([]int, 0)
|
||||
|
||||
for _, v := range *order {
|
||||
ids = append(ids, v.Id)
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
var counts []dto.LinePreOrderChildCount
|
||||
|
||||
if err := e.Orm.Model(&models.LinePreOrder{}).Where("pid in ?", ids).Group("pid").Select("pid as id,count(*) as count").Find(&counts).Error; err != nil {
|
||||
logger.Errorf("获取子订单数量失败 %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
for index := range *order {
|
||||
for _, v := range counts {
|
||||
if v.Id == (*order)[index].Id {
|
||||
(*order)[index].ChildNum = int64(v.Count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
@ -249,7 +272,7 @@ func (e *LinePreOrder) Remove(d *dto.LinePreOrderDeleteReq, p *actions.DataPermi
|
||||
helper.DefaultRedis.LRem(listKey, string(marshal))
|
||||
}
|
||||
|
||||
binanceservice.MainClosePositionClearCache(order.Id, order.CoverType)
|
||||
binanceservice.MainClosePositionClearCache(order.Id, order.SymbolType)
|
||||
|
||||
ints = append(ints, order.Id)
|
||||
}
|
||||
@ -341,7 +364,7 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP
|
||||
} else { //实际价格下单
|
||||
AddOrder.Price = utility.StringToDecimal(req.Price).Truncate(int32(tradeSet.PriceDigit)).String()
|
||||
AddOrder.SignPrice = req.Price
|
||||
AddOrder.SignPriceType = "mixture"
|
||||
AddOrder.SignPriceType = req.PricePattern
|
||||
AddOrder.Rate = "0"
|
||||
}
|
||||
buyPrice, _ := decimal.NewFromString(req.BuyPrice) //购买多少U
|
||||
@ -413,6 +436,7 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP
|
||||
ReduceTakeProfitRatio: addPosition.ReduceTakeProfitRatio,
|
||||
ReduceStopLossRatio: addPosition.ReduceStopLossRatio,
|
||||
AddPositionPriceRatio: addPosition.AddPositionPriceRatio,
|
||||
AddPositionOrderType: addPosition.AddPositionOrderType,
|
||||
AddPositionType: addPosition.AddPositionType,
|
||||
AddPositionVal: addPosition.AddPositionVal,
|
||||
}
|
||||
@ -510,7 +534,7 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP
|
||||
// CheckRepeatOrder 检查重复下单 检查基础货币
|
||||
func (e *LinePreOrder) CheckRepeatOrder(orderType int, apiUserId, site, baseCoin string) int64 {
|
||||
var count int64
|
||||
e.Orm.Model(&models.LinePreOrder{}).Where("api_id = ? AND symbol like ? AND order_type = ? AND site = ? AND `status` IN (1,5,6)", apiUserId, baseCoin+"%", orderType, site).Count(&count)
|
||||
e.Orm.Model(&models.LinePreOrder{}).Where("api_id = ? AND pid=0 AND symbol like ? AND order_type = ? AND site = ? AND `status` IN (1,5,6)", apiUserId, baseCoin+"%", orderType, site).Count(&count)
|
||||
return count
|
||||
}
|
||||
|
||||
@ -597,6 +621,7 @@ func (e *LinePreOrder) AddBatchPreOrder(batchReq *dto.LineBatchAddPreOrderReq, p
|
||||
req.PricePattern = batchReq.PricePattern
|
||||
req.Price = batchReq.Price
|
||||
req.Profit = batchReq.Profit
|
||||
req.Ext = batchReq.Ext
|
||||
// req.StopPrice = batchReq.StopPrice
|
||||
req.ReducePriceRatio = batchReq.ReducePriceRatio
|
||||
req.PriceType = batchReq.PriceType
|
||||
@ -1056,6 +1081,7 @@ func (e *LinePreOrder) SpotClosePosition(position *dto.ClosePosition, errs *[]er
|
||||
ApiId: list.ApiId,
|
||||
GroupId: "0",
|
||||
Symbol: list.Symbol,
|
||||
SymbolType: position.CloseType,
|
||||
QuoteSymbol: list.QuoteSymbol,
|
||||
SignPrice: lastPrice.String(),
|
||||
SignPriceType: "new",
|
||||
@ -1086,7 +1112,7 @@ func (e *LinePreOrder) SpotClosePosition(position *dto.ClosePosition, errs *[]er
|
||||
*errs = append(*errs, errors.New(fmt.Sprintf("api_id:%d 币安下订单失败:%s", position.ApiId, err.Error())))
|
||||
continue
|
||||
}
|
||||
binanceservice.MainClosePositionClearCache(list.Id, list.CoverType)
|
||||
binanceservice.MainClosePositionClearCache(list.Id, list.SymbolType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1160,10 +1186,12 @@ func (e *LinePreOrder) FutClosePosition(position *dto.ClosePosition, errs *[]err
|
||||
|
||||
order := models.LinePreOrder{
|
||||
Pid: parentId,
|
||||
ExchangeType: list.ExchangeType,
|
||||
ApiId: list.ApiId,
|
||||
MainId: list.Id,
|
||||
GroupId: "0",
|
||||
Symbol: list.Symbol,
|
||||
SymbolType: position.CloseType,
|
||||
QuoteSymbol: list.QuoteSymbol,
|
||||
SignPrice: lastPrice.String(),
|
||||
SignPriceType: "new",
|
||||
@ -1205,7 +1233,7 @@ func (e *LinePreOrder) FutClosePosition(position *dto.ClosePosition, errs *[]err
|
||||
continue
|
||||
}
|
||||
// 主单平仓删除缓存
|
||||
binanceservice.MainClosePositionClearCache(list.Id, list.CoverType)
|
||||
binanceservice.MainClosePositionClearCache(list.Id, list.SymbolType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user