1
This commit is contained in:
@ -282,6 +282,12 @@ func (e LinePreOrder) AddPreOrder(c *gin.Context) {
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := req.Valid(); err != nil {
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
errs := make([]error, 0)
|
||||
errStr := make([]string, 0)
|
||||
|
||||
@ -181,30 +181,63 @@ 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"` //止盈价
|
||||
ExchangeType string `json:"exchange_type" vd:"len($)>0"` //交易所类型
|
||||
OrderType int `json:"order_type"` //订单类型
|
||||
Symbol string `json:"symbol" vd:"len($)>0"` //交易对
|
||||
ApiUserId string `json:"api_id" ` //下单用户
|
||||
Site string `json:"site" ` //购买方向
|
||||
BuyPrice string `json:"buy_price" vd:"$>0"` //购买金额 U
|
||||
PricePattern string `json:"price_pattern"` //价格模式
|
||||
Price string `json:"price" vd:"$>0"` //下单价百分比
|
||||
Profit string `json:"profit" vd:"$>0"` //止盈价
|
||||
// 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"` //对冲类型 0=无对冲 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"` //主单减仓后止损价百分比
|
||||
ReduceReTakeProfitRatio decimal.Decimal `json:"reTakeProfitRatio" comment:"减仓后亏损回本止盈百分比"`
|
||||
PriceType string `json:"price_type"` //价格类型
|
||||
SaveTemplate string `json:"save_template"` //是否保存模板
|
||||
TemplateName string `json:"template_name"` //模板名字
|
||||
SymbolType int `json:"symbol_type" vd:"$>0"` //交易对类型 1-现货 2-合约
|
||||
CoverType int `json:"cover_type"` //对冲类型 0=无对冲 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"` //主单减仓后止损价百分比
|
||||
ReduceReTakeProfitRatio decimal.Decimal `json:"re_take_profit_ratio" comment:"减仓后亏损回本止盈百分比"`
|
||||
|
||||
Ext []LineAddPreOrderExtReq `json:"ext"` //拓展字段
|
||||
Ext []LineAddPreOrderExtReq `json:"ext" ` //拓展字段
|
||||
}
|
||||
|
||||
func (req LineAddPreOrderReq) Valid() error {
|
||||
if req.ReducePriceRatio.IsZero() {
|
||||
return errors.New("主单减仓价格百分比不能为空")
|
||||
}
|
||||
|
||||
if req.ReduceNumRatio.IsZero() {
|
||||
return errors.New("主单减仓数量百分比不能为空")
|
||||
}
|
||||
|
||||
for _, v := range req.Ext {
|
||||
if v.AddPositionVal.IsZero() {
|
||||
return errors.New("加仓单数量不能为空")
|
||||
}
|
||||
if v.AddPositionPriceRatio.IsZero() {
|
||||
return errors.New("加仓单下跌价格不能为空")
|
||||
}
|
||||
|
||||
if v.ReduceNumRatio.IsZero() || v.ReduceNumRatio.Cmp(decimal.NewFromInt(100)) > 0 {
|
||||
return errors.New("减仓数量不正确")
|
||||
}
|
||||
|
||||
if v.ReducePriceRatio.IsZero() || v.ReducePriceRatio.Cmp(decimal.NewFromInt(100)) > 0 {
|
||||
return errors.New("减仓下跌价格不正确")
|
||||
}
|
||||
|
||||
if v.ReduceTakeProfitRatio.IsZero() || v.ReduceTakeProfitRatio.Cmp(decimal.NewFromInt(100)) > 0 {
|
||||
return errors.New("减仓后止盈价格不正确")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (req LineAddPreOrderReq) CheckParams() error {
|
||||
@ -292,6 +325,35 @@ func (req LineBatchAddPreOrderReq) CheckParams() error {
|
||||
return errors.New("请选择交易所")
|
||||
}
|
||||
|
||||
if req.ReducePriceRatio.IsZero() {
|
||||
return errors.New("主单减仓价格百分比不能为空")
|
||||
}
|
||||
|
||||
if req.ReduceNumRatio.IsZero() {
|
||||
return errors.New("主单减仓数量百分比不能为空")
|
||||
}
|
||||
|
||||
for _, v := range req.Ext {
|
||||
if v.AddPositionVal.IsZero() {
|
||||
return errors.New("加仓单数量不能为空")
|
||||
}
|
||||
if v.AddPositionPriceRatio.IsZero() {
|
||||
return errors.New("加仓单下跌价格不能为空")
|
||||
}
|
||||
|
||||
if v.ReduceNumRatio.IsZero() || v.ReduceNumRatio.Cmp(decimal.Zero) > 0 {
|
||||
return errors.New("减仓数量不正确")
|
||||
}
|
||||
|
||||
if v.ReducePriceRatio.IsZero() || v.ReducePriceRatio.Cmp(decimal.Zero) > 0 {
|
||||
return errors.New("减仓下跌价格不正确")
|
||||
}
|
||||
|
||||
if v.ReduceTakeProfitRatio.IsZero() || v.ReduceTakeProfitRatio.Cmp(decimal.Zero) > 0 {
|
||||
return errors.New("减仓后止盈价格不正确")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -37,14 +37,14 @@ func (m *LinePreOrderExtGetPageReq) GetNeedSearch() interface{} {
|
||||
}
|
||||
|
||||
type LineAddPreOrderExtReq struct {
|
||||
TakeProfitRatio decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"`
|
||||
TakeProfitRatio decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比" `
|
||||
ReTakeProfitRatio decimal.Decimal `json:"reTakeProfitRatio" comment:"亏损回本止盈百分比"`
|
||||
ReducePriceRatio decimal.Decimal `json:"reducePriceRatio" comment:"减仓价格百分比"`
|
||||
ReduceNumRatio decimal.Decimal `json:"reduceNumRatio" comment:"减仓数量百分比"`
|
||||
ReduceTakeProfitRatio decimal.Decimal `json:"reduceTakeProfitRatio" 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:"减仓后止损百分比"`
|
||||
ReduceReTakeProfitRatio decimal.Decimal `json:"reduceReTakeProfitRatio" comment:"减仓后回本止盈百分比"`
|
||||
AddPositionPriceRatio decimal.Decimal `json:"addPositionPriceRatio" 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:"加仓值"`
|
||||
|
||||
@ -447,9 +447,14 @@ func (e *LinePreOrder) AddPreOrder(req *dto.LineAddPreOrderReq, p *actions.DataP
|
||||
}
|
||||
|
||||
//计算减仓后
|
||||
mainParam.LossEndPercent = req.ReducePriceRatio
|
||||
mainParam.RemainingQuantity = mainAmount
|
||||
e.CalculateBreakEvenRatio(&mainParam, &calculateResp)
|
||||
mainParam.RemainingQuantity = calculateResp.RemainingQuantity //mainAmount.Mul(decimal.NewFromInt(100).Sub(req.ReduceNumRatio).Div(decimal.NewFromInt(100))).Truncate(int32(tradeSet.AmountDigit))
|
||||
mainParam.TotalLossAmountU = calculateResp.TotalLossAmountU //buyPrice.Mul(req.ReducePriceRatio.Div(decimal.NewFromInt(100)).Truncate(4)).Truncate(int32(tradeSet.PriceDigit))
|
||||
req.ReduceReTakeProfitRatio = calculateResp.Ratio
|
||||
mainParam.LossBeginPercent = req.ReducePriceRatio
|
||||
mainParam.RemainingQuantity = mainAmount.Mul(decimal.NewFromInt(100).Sub(req.ReduceNumRatio).Div(decimal.NewFromInt(100))).Truncate(int32(tradeSet.AmountDigit))
|
||||
mainParam.TotalLossAmountU = buyPrice.Mul(req.ReducePriceRatio.Div(decimal.NewFromInt(100)).Truncate(4)).Truncate(int32(tradeSet.PriceDigit))
|
||||
defultExt.ReduceReTakeRatio = calculateResp.Ratio
|
||||
|
||||
for index, addPosition := range req.Ext {
|
||||
ext := models.LinePreOrderExt{
|
||||
@ -1619,7 +1624,7 @@ func (e *LinePreOrder) GenerateOrder(req *dto.LineAddPreOrderReq) ([]models.Line
|
||||
}
|
||||
|
||||
buyPrice := utility.StrToDecimal(req.BuyPrice)
|
||||
mainAmount := buyPrice.Div(price)
|
||||
mainAmount := buyPrice.Div(price).Truncate(int32(tradeSet.AmountDigit))
|
||||
calculateResp := dto.CalculateBreakEvenRatioResp{}
|
||||
mainParam := dto.CalculateBreakEevenRatioReq{
|
||||
Price: price,
|
||||
@ -1635,9 +1640,13 @@ func (e *LinePreOrder) GenerateOrder(req *dto.LineAddPreOrderReq) ([]models.Line
|
||||
}
|
||||
|
||||
//计算减仓后
|
||||
mainParam.LossEndPercent = req.ReducePriceRatio
|
||||
mainParam.RemainingQuantity = mainAmount
|
||||
e.CalculateBreakEvenRatio(&mainParam, &calculateResp)
|
||||
mainParam.RemainingQuantity = calculateResp.RemainingQuantity
|
||||
mainParam.TotalLossAmountU = calculateResp.TotalLossAmountU
|
||||
req.ReduceReTakeProfitRatio = calculateResp.Ratio
|
||||
mainParam.LossBeginPercent = req.ReducePriceRatio
|
||||
mainParam.RemainingQuantity = mainAmount.Mul(decimal.NewFromInt(100).Sub(req.ReduceNumRatio).Div(decimal.NewFromInt(100))).Truncate(int32(tradeSet.AmountDigit))
|
||||
mainParam.TotalLossAmountU = buyPrice.Mul(req.ReducePriceRatio.Div(decimal.NewFromInt(100)).Truncate(4)).Truncate(int32(tradeSet.PriceDigit))
|
||||
|
||||
for index := range req.Ext {
|
||||
mainParam.LossEndPercent = req.Ext[index].AddPositionPriceRatio
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/bytedance/sonic"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
@ -16,17 +15,18 @@ import (
|
||||
"go-admin/pkg/utility/snowflakehelper"
|
||||
"go-admin/services/binanceservice"
|
||||
"go-admin/services/fileservice"
|
||||
"gorm.io/driver/mysql"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"gorm.io/driver/mysql"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"github.com/go-admin-team/go-admin-core/sdk"
|
||||
@ -389,7 +389,7 @@ func (l ListenSymbol) Exec(arg interface{}) error {
|
||||
//发送邮箱
|
||||
emails := strings.Split(configResp.ConfigValue, ",")
|
||||
for _, email := range emails {
|
||||
emailhelper.SendNoticeEmail(email, chain, symbol.Token0Symbol+"/"+symbol.Token1Symbol, symbol.TargetToken)
|
||||
emailhelper.SendNoticeEmail(email, chain, symbol.Token0Symbol+"/"+symbol.Token1Symbol, symbol.Pair)
|
||||
}
|
||||
// 清除数据
|
||||
db.Model(&models.SpiderListenSymbol{}).Where("coin = ? AND currency = ?", symbol.Token0Symbol, symbol.Token1Symbol).Delete(&models.SpiderListenSymbol{})
|
||||
@ -405,7 +405,7 @@ func (l ListenSymbol) Exec(arg interface{}) error {
|
||||
func (l ListenSymbol) GetAveRequestId() (aveToken string, err error) {
|
||||
execPath, err := os.Getwd()
|
||||
// 获取可执行文件所在的目录
|
||||
execDir := fmt.Sprintf("%s/config/ave.js", filepath.Dir(filepath.Dir(execPath)))
|
||||
execDir := fmt.Sprintf("%s/config/ave.js", execPath)
|
||||
_, err = os.Stat(execDir)
|
||||
if err != nil {
|
||||
logger.Error("可执行的js 文件不存在")
|
||||
|
||||
Reference in New Issue
Block a user