Pārlūkot izejas kodu

期货头寸持仓均价计算改为根据价格小数位“去尾法"

zou.yingbin 3 gadi atpakaļ
vecāks
revīzija
d1acc77150
1 mainītis faili ar 3 papildinājumiem un 4 dzēšanām
  1. 3 4
      controllers/order/order.go

+ 3 - 4
controllers/order/order.go

@@ -222,7 +222,7 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
 				// #96004 改为固定3位小数
 				// #3524 又改为跟商品价格小数位走 2022.04.07
 				// 运维提出, 不要四舍五入, 改为去尾法 2022.04.26
-				tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Truncate(v.QTYDECIMALPLACE).Float64()
+				tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Truncate(int32(v.Decimalplace)).Float64()
 				tradePosition.PositionPL, tradePosition.MarketAmount, tradePosition.LastPrice = fCalcPL(tradePosition.GoodsCode, tradePosition.BuyOrSell, tradePosition.CurPositionQTY,
 					tradePosition.AveragePrice, tradePosition.AgreeUnit, tradePosition.DecimalPlace)
 				if tradePosition.CurHolderAmount > 1e-10 {
@@ -262,9 +262,8 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
 				tradePosition.EnableQTY = c.CovertQty(v.Sellcurpositionqty - v.Sellfrozenqty - v.Sellotherfrozenqty)
 				// 计算持仓均价
 				averagePrice := tradePosition.CurHolderAmount / float64(tradePosition.CurPositionQTY) / tradePosition.AgreeUnit
-				//tradePosition.AveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(v.Decimalplace)), 64)
-				// #96004 改为固定3位小数
-				tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Round(3).Float64()
+
+				tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Truncate(int32(v.Decimalplace)).Float64()
 				tradePosition.PositionPL, tradePosition.MarketAmount, tradePosition.LastPrice = fCalcPL(tradePosition.GoodsCode, tradePosition.BuyOrSell, tradePosition.CurPositionQTY,
 					tradePosition.AveragePrice, tradePosition.AgreeUnit, tradePosition.DecimalPlace)
 				if tradePosition.CurHolderAmount > 1e-10 {