|
@@ -174,7 +174,7 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取汇率配置
|
|
// 获取汇率配置
|
|
|
- exchangeRateConfigs := make([]models.Exchangerateconfig, 0)
|
|
|
|
|
|
|
+ exchangeRateConfigs := make([]models.ExchangeRateConfig, 0)
|
|
|
if err := engine.Find(&exchangeRateConfigs); err != nil {
|
|
if err := engine.Find(&exchangeRateConfigs); err != nil {
|
|
|
// 查询失败
|
|
// 查询失败
|
|
|
logger.GetLogger().Errorf("获取汇率配置失败, err: %s", err.Error())
|
|
logger.GetLogger().Errorf("获取汇率配置失败, err: %s", err.Error())
|
|
@@ -185,8 +185,13 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
|
|
|
rateMap[fmt.Sprintf("%d_%d", item.ORICURRENCYID, item.DESCURRENCYID)] = item.EXCHANGERATE
|
|
rateMap[fmt.Sprintf("%d_%d", item.ORICURRENCYID, item.DESCURRENCYID)] = item.EXCHANGERATE
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fCalcPL := func(goodsCode string, buyOrSell int64, qty, holderPrice,
|
|
|
|
|
- agreeUnit float64, decimalPlace int64, exchangeRate float64) (positionPL float64, marketAmount float64, lastPrice float64) {
|
|
|
|
|
|
|
+ fCalcPL := func(goodsCode string,
|
|
|
|
|
+ buyOrSell int64,
|
|
|
|
|
+ qty,
|
|
|
|
|
+ holderPrice,
|
|
|
|
|
+ agreeUnit float64,
|
|
|
|
|
+ decimalPlace int64,
|
|
|
|
|
+ exchangeRate float64) (positionPL float64, marketAmount float64, lastPrice float64) {
|
|
|
positionPL = 0
|
|
positionPL = 0
|
|
|
for _, q := range goodGuotes {
|
|
for _, q := range goodGuotes {
|
|
|
if goodsCode == q.Goodscode {
|
|
if goodsCode == q.Goodscode {
|
|
@@ -255,8 +260,13 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
|
|
|
// #3524 又改为跟商品价格小数位走 2022.04.07
|
|
// #3524 又改为跟商品价格小数位走 2022.04.07
|
|
|
// 运维提出, 不要四舍五入, 改为去尾法 2022.04.26
|
|
// 运维提出, 不要四舍五入, 改为去尾法 2022.04.26
|
|
|
tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Truncate(int32(v.Decimalplace + 2)).Float64()
|
|
tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Truncate(int32(v.Decimalplace + 2)).Float64()
|
|
|
- tradePosition.PositionPL, tradePosition.MarketAmount, tradePosition.LastPrice = fCalcPL(tradePosition.GoodsCode, tradePosition.BuyOrSell, tradePosition.CurPositionQTY,
|
|
|
|
|
- tradePosition.AveragePrice, tradePosition.AgreeUnit, tradePosition.DecimalPlace+1, exchangeRate)
|
|
|
|
|
|
|
+ tradePosition.PositionPL, tradePosition.MarketAmount, tradePosition.LastPrice = fCalcPL(tradePosition.GoodsCode,
|
|
|
|
|
+ tradePosition.BuyOrSell,
|
|
|
|
|
+ tradePosition.CurPositionQTY,
|
|
|
|
|
+ tradePosition.AveragePrice,
|
|
|
|
|
+ tradePosition.AgreeUnit,
|
|
|
|
|
+ tradePosition.DecimalPlace,
|
|
|
|
|
+ exchangeRate)
|
|
|
if tradePosition.CurHolderAmount > 1e-10 {
|
|
if tradePosition.CurHolderAmount > 1e-10 {
|
|
|
tradePosition.PositionPLRate = tradePosition.PositionPL / tradePosition.CurHolderAmount
|
|
tradePosition.PositionPLRate = tradePosition.PositionPL / tradePosition.CurHolderAmount
|
|
|
tradePosition.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(tradePosition.PositionPLRate, 4), 64)
|
|
tradePosition.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(tradePosition.PositionPLRate, 4), 64)
|