1、参数组装
This commit is contained in:
@ -195,9 +195,15 @@ type LineAddPreOrderReq struct {
|
||||
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 合约对现货
|
||||
CoverType int `json:"cover_type"` //对冲类型 0=无对冲 1= 现货对合约 2=合约对合约 3 合约对现货
|
||||
ExpireHour int `json:"expire_hour"` // 过期时间 单位小时
|
||||
MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET)
|
||||
TakeProfitRatio decimal.Decimal `json:"take_profit"` //主单止盈比例
|
||||
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 LineAddPreOrderReq) CheckParams() error {
|
||||
@ -249,6 +255,12 @@ type LineBatchAddPreOrderReq struct {
|
||||
CoverType int `json:"cover_type"` //对冲类型 1= 现货对合约 2=合约对合约 3 合约对现货
|
||||
ExpireHour int `json:"expire_hour"` // 过期时间 单位小时
|
||||
MainOrderType string `json:"main_order_type"` //主单类型:限价(LIMIT)或市价(MARKET)
|
||||
TakeProfitRatio decimal.Decimal `json:"take_profit"` //主单止盈比例
|
||||
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 {
|
||||
|
||||
@ -36,6 +36,17 @@ func (m *LinePreOrderExtGetPageReq) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
type LineAddPreOrderExtReq struct {
|
||||
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:"加仓值"`
|
||||
}
|
||||
|
||||
type LinePreOrderExtInsertReq struct {
|
||||
Id int `json:"-" comment:"主键id"` // 主键id
|
||||
MainOrderId int `json:"mainOrderId" comment:"主单id"`
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/helper"
|
||||
models2 "go-admin/models"
|
||||
"go-admin/models/binancedto"
|
||||
"go-admin/pkg/utility"
|
||||
"go-admin/pkg/utility/snowflakehelper"
|
||||
"go-admin/services/binanceservice"
|
||||
@ -217,8 +216,6 @@ func (e *LinePreOrder) Remove(d *dto.LinePreOrderDeleteReq, p *actions.DataPermi
|
||||
return err
|
||||
}
|
||||
ints := make([]int, 0)
|
||||
stoplossMarket, _ := helper.DefaultRedis.GetAllList(rediskey.StoplossMarkt)
|
||||
stoploss := binancedto.StoplossMarket{}
|
||||
apiIds := make([]int, 0)
|
||||
|
||||
if db.RowsAffected == 0 {
|
||||
@ -254,64 +251,9 @@ func (e *LinePreOrder) Remove(d *dto.LinePreOrderDeleteReq, p *actions.DataPermi
|
||||
|
||||
binanceservice.MainClosePositionClearCache(order.Id, order.CoverType)
|
||||
|
||||
helper.DefaultRedis.DeleteString(fmt.Sprintf(rediskey.SpotHedgeClosePosition, order.Id, order.Symbol))
|
||||
helper.DefaultRedis.DeleteString(fmt.Sprintf(rediskey.FuturesHedgeClosePosition, order.Id, order.Symbol))
|
||||
|
||||
helper.DefaultRedis.DeleteString(fmt.Sprintf(rediskey.HoldeA, order.Id))
|
||||
helper.DefaultRedis.DeleteString(fmt.Sprintf(rediskey.HoldeB, order.Id))
|
||||
helper.DefaultRedis.DeleteString(fmt.Sprintf(rediskey.HedgeClosePosition, order.Id))
|
||||
|
||||
for _, st := range stoplossMarket {
|
||||
sonic.Unmarshal([]byte(st), &stoploss)
|
||||
|
||||
if stoploss.Pid == order.Id {
|
||||
helper.DefaultRedis.LRem(rediskey.StoplossMarkt, st)
|
||||
}
|
||||
}
|
||||
|
||||
ints = append(ints, order.Id)
|
||||
}
|
||||
|
||||
if len(apiIds) > 0 {
|
||||
apiSymbols := make([]models.LinePreOrder, 0)
|
||||
userHold := make(map[int][]string)
|
||||
|
||||
e.Orm.Model(&models.LinePreOrder{}).Where("pid = 0 AND status IN ('1','5','9','13') AND api_id IN ?", apiIds).
|
||||
Group("api_id,symbol,quote_symbol").
|
||||
Select("api_id,symbol,quote_symbol").
|
||||
Find(&apiSymbols)
|
||||
|
||||
for _, apiId := range apiIds {
|
||||
bre := false
|
||||
|
||||
for _, api := range apiSymbols {
|
||||
if apiId == api.ApiId {
|
||||
coin := utility.ReplaceSuffix(api.Symbol, api.QuoteSymbol, "")
|
||||
userHold[api.ApiId] = append(userHold[api.ApiId], coin)
|
||||
bre = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bre {
|
||||
userHold[apiId] = make([]string, 0)
|
||||
}
|
||||
}
|
||||
|
||||
for key, val := range userHold {
|
||||
key := fmt.Sprintf(rediskey.UserHolding, key)
|
||||
|
||||
if len(val) > 0 {
|
||||
if err := helper.DefaultRedis.SetListCache(key, 0, val...); err != nil {
|
||||
logger.Errorf("重新设置用户持仓失败 apiid:%v,err:%v", key, err)
|
||||
}
|
||||
} else {
|
||||
if err := helper.DefaultRedis.SetEmptyListCache(key, 0); err != nil {
|
||||
logger.Errorf("重新设置用户持仓为空 失败 apiid:%v,err:%v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(ints) > 0 {
|
||||
e.Orm.Model(&models.LinePreOrder{}).Where("pid >0 AND pid in ?", ints).Unscoped().Delete(&models.LinePreOrder{})
|
||||
}
|
||||
|
||||
@ -41,22 +41,12 @@ const (
|
||||
|
||||
//需要清理键值---------BEGIN---------------
|
||||
|
||||
UserHolding = "api_user_hold:%v" //用户持仓币种 {主单apiid} 不是交易对
|
||||
|
||||
SpotHedgeClosePosition = "spot_hedge_close_position:%v_%s" //现货对冲平仓 {mainorderid|symbol}
|
||||
FuturesHedgeClosePosition = "futures_hedge_close_position:%v_%s" //合约对冲平仓 {mainorderid|symbol}
|
||||
|
||||
SpotStopLossList = "spot_stoploss_list:%s" //现货止损待触发列表 {交易所类型code}
|
||||
FuturesStopLossList = "futures_stoploss_list:%s" //合约止损待触发列表 {交易所类型code}
|
||||
|
||||
SpotAddPositionList = "spot_add_position_list" //现货加仓待触发
|
||||
FuturesAddPositionList = "futures_add_position_list" //合约加仓待触发
|
||||
StoplossMarkt = "stop_loss_markt" //对冲保险单(市价) 对冲单成交之后、清除
|
||||
|
||||
HoldeA = "holde_a:%v" //持仓A {主单id}
|
||||
HoldeB = "holde_b:%v" //持仓B {主单id}
|
||||
|
||||
HedgeClosePosition = "hedge_close_position:%v" //对冲平仓记录 {主单id}
|
||||
//需要清理键值---------END-----------------
|
||||
|
||||
)
|
||||
|
||||
@ -45,7 +45,7 @@ func ChangeFutureOrder(mapData map[string]interface{}) {
|
||||
}
|
||||
|
||||
// 获取 Redis 锁
|
||||
lock := helper.NewRedisLock(fmt.Sprintf(rediskey.SpotCallBack, orderSn), 10, 5, 500*time.Millisecond)
|
||||
lock := helper.NewRedisLock(fmt.Sprintf(rediskey.FutCallBack, orderSn), 10, 5, 500*time.Millisecond)
|
||||
acquired, err := lock.AcquireWait(context.Background())
|
||||
if err != nil {
|
||||
logger.Error("合约订单回调失败,获取锁失败:", orderSn, " err:", err)
|
||||
|
||||
Reference in New Issue
Block a user