From 2288f0ffe2ab6ae18ae151fb0de2f7cd1b94f440 Mon Sep 17 00:00:00 2001 From: ying liu Date: Mon, 29 Jul 2024 18:35:12 +0800 Subject: [PATCH] [fix] notife --- config/ccinr.yaml | 1 + pkg/strategy/ccinr/strategy.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config/ccinr.yaml b/config/ccinr.yaml index 129ac1e..b0d1a97 100644 --- a/config/ccinr.yaml +++ b/config/ccinr.yaml @@ -47,6 +47,7 @@ exchangeStrategies: profitRange: 2% lossRange: 1% amount: 20 + place: true # recalculate: false # dry_run: false # # quantity: 3 diff --git a/pkg/strategy/ccinr/strategy.go b/pkg/strategy/ccinr/strategy.go index 7a3ebb6..2cbcfef 100644 --- a/pkg/strategy/ccinr/strategy.go +++ b/pkg/strategy/ccinr/strategy.go @@ -32,6 +32,7 @@ type Strategy struct { Interval types.Interval `json:"interval"` NrCount int `json:"nrCount"` StrictMode bool `json:"strictMode"` + Place bool `json:"place"` DryRun bool `json:"dryRun"` CCIWindow int `json:"cciWindow"` LongCCI fixedpoint.Value `json:"longCCI"` @@ -39,6 +40,7 @@ type Strategy struct { Leverage fixedpoint.Value `json:"leverage"` ProfitRange fixedpoint.Value `json:"profitRange"` LossRange fixedpoint.Value `json:"lossRange"` + qbtrade.QuantityOrAmount //Position *types.Position `persistence:"position"` @@ -151,10 +153,19 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ //midPrice := (kline.High.Add(kline.Low)).Div(fixedpoint.Value(2.0)) //midP := (kline.High + kline.Low) / 2 if s.TradeType[symbol] == "long" { - placePrice = kline.High + if s.Place { + placePrice = kline.High + } else { + placePrice = kline.Low + } //placePrice = midP } else if s.TradeType[symbol] == "short" { - placePrice = kline.Low + if s.Place { + placePrice = kline.Low + } else { + placePrice = kline.High + } + //placePrice = midP } else { return orders, nil @@ -290,7 +301,7 @@ func (s *Strategy) notifyProfit(ctx context.Context, symbol string) { } msg := fmt.Sprintf("交易完成:\n 币种: %s, 方向:%v, 收益:%v, 手续费:%v \n Trade详情:\n 开仓Trade:\n %s\n 清仓Trade:\n %s", - symbol, s.TradeType, profit, free.Float64(), strings.Join(openMsgs, "\n"), strings.Join(endMsgs, "\n")) + symbol, s.TradeType[symbol], profit, free.Float64(), strings.Join(openMsgs, "\n"), strings.Join(endMsgs, "\n")) log.Infof(msg) qbtrade.Notify(msg) @@ -412,7 +423,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor, order, order.OrderID, orderSymbol, order.Type, order.Status) s.Traded[orderSymbol] = true s.TradeRetry[orderSymbol] = 0 - qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType, + qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType[orderSymbol], order.Price, order.Quantity) } if order.Type == types.OrderTypeLimit && order.Side == types.SideTypeSell { @@ -420,7 +431,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor, order, order.OrderID, orderSymbol, order.Type, order.Status) s.Traded[orderSymbol] = true s.TradeRetry[orderSymbol] = 0 - qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType, + qbtrade.Notify("订单成交通知:\n 币种:%s, 方向:%s, 价格:%s, 数量:%s", order.Symbol, s.TradeType[orderSymbol], order.Price, order.Quantity) }