From 29bd6ff6ebcd546995ea3d4f59730c0e1c45f841 Mon Sep 17 00:00:00 2001 From: lychiyu Date: Tue, 30 Jul 2024 22:58:03 +0800 Subject: [PATCH] zero --- pkg/strategy/ccinr/strategy.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/strategy/ccinr/strategy.go b/pkg/strategy/ccinr/strategy.go index 9d5a1d7..cce2bd9 100644 --- a/pkg/strategy/ccinr/strategy.go +++ b/pkg/strategy/ccinr/strategy.go @@ -163,7 +163,7 @@ func (s *Strategy) placeOrders(ctx context.Context, kline types.KLine) { func (s *Strategy) getPlacePrice(ctx context.Context, kline types.KLine) fixedpoint.Value { symbol := kline.Symbol - placePrice := fixedpoint.Value(0) + placePrice := fixedpoint.Zero midPrice := (kline.High.Add(kline.Low)).Div(fixedpoint.One * 2) switch s.PlacePriceType { case 0: @@ -209,8 +209,8 @@ func (s *Strategy) generateOrders(ctx context.Context, kline types.KLine) ([]typ } // 计算止损止盈价格,以ATR为基准或者固定百分比 - lossPrice := fixedpoint.Value(0) - profitPrice := fixedpoint.Value(0) + lossPrice := fixedpoint.Zero + profitPrice := fixedpoint.Zero lastATR, err := strconv.ParseFloat(strconv.FormatFloat(s.atr[symbol].Last(0), 'f', 6, 64), 64) if err != nil { log.WithError(err).Error("failed parse atr last value float") @@ -331,10 +331,10 @@ func (s *Strategy) notifyProfit(ctx context.Context, symbol string) { if s.EndQuantity[symbol] != s.OpenQuantity[symbol] { return } - profit := fixedpoint.Value(0) - openProfit := fixedpoint.Value(0) - endProfit := fixedpoint.Value(0) - free := fixedpoint.Value(0) + profit := fixedpoint.Zero + openProfit := fixedpoint.Zero + endProfit := fixedpoint.Zero + free := fixedpoint.Zero var openMsgs []string var endMsgs []string @@ -371,7 +371,7 @@ func (s *Strategy) notifyProfit(ctx context.Context, symbol string) { s.TotalProfit = s.TotalProfit.Add(profit) s.TotalFree = s.TotalFree.Add(free) s.TotalOrderCount += 1 - if profit > fixedpoint.Value(0) { + if profit > fixedpoint.Zero { s.TotalProfitCount += 1 } else { s.TotalLossCount += 1 @@ -383,8 +383,8 @@ func (s *Strategy) notifyProfit(ctx context.Context, symbol string) { // 重置 s.OpenTrade[symbol] = []types.Trade{} s.EndTrade[symbol] = []types.Trade{} - s.OpenQuantity[symbol] = fixedpoint.Value(0) - s.EndQuantity[symbol] = fixedpoint.Value(0) + s.OpenQuantity[symbol] = fixedpoint.Zero + s.EndQuantity[symbol] = fixedpoint.Zero // 记得取消订单 s.cancelOrders(ctx, symbol) @@ -420,8 +420,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor, s.cci = make(map[string]*indicatorv2.CCIStream) s.atr = make(map[string]*indicatorv2.ATRStream) - s.TotalProfit = fixedpoint.Value(0) - s.TotalFree = fixedpoint.Value(0) + s.TotalProfit = fixedpoint.Zero + s.TotalFree = fixedpoint.Zero s.TotalOrderCount = 0 s.TotalProfitCount = 0 s.TotalLossCount = 0 @@ -545,11 +545,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor qbtrade.OrderExecutor, if (trade.Side == types.SideTypeBuy && s.TradeType[symbol] == "long") || (trade.Side == types.SideTypeSell && s.TradeType[symbol] == "short") { s.OpenTrade[symbol] = append(s.OpenTrade[symbol], trade) - s.OpenQuantity[symbol] += trade.Quantity + s.OpenQuantity[symbol] = s.OpenQuantity[symbol].Add(trade.Quantity) } if (trade.Side == types.SideTypeSell && s.TradeType[symbol] == "long") || (trade.Side == types.SideTypeBuy && s.TradeType[symbol] == "short") { s.EndTrade[symbol] = append(s.EndTrade[symbol], trade) - s.EndQuantity[symbol] += trade.Quantity + s.EndQuantity[symbol] = s.EndQuantity[symbol].Add(trade.Quantity) s.notifyProfit(ctx, symbol) } log.Infof("trade: symbol %s, side %s, price %f, fee %f, quantity %f, buyer %v, maker %v",