|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"mtp2_if/models"
|
|
|
"mtp2_if/utils"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
@@ -156,8 +157,10 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 计算价格与盈亏
|
|
|
// 开仓均价 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
item.OpenAveragePrice = v.Buyopencost / float64(v.Curbuyposition) / goods.Agreeunit
|
|
|
+ item.OpenAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.OpenAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 持仓均价 = 持仓成本 / 期末头寸 / 合约单位
|
|
|
item.PositionAveragePrice = v.Buypositioncost / float64(v.Curbuyposition) / goods.Agreeunit
|
|
|
+ item.PositionAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 盯市浮盈(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位
|
|
|
if item.Last != 0 {
|
|
|
item.PositionPL = (item.Last - item.PositionAveragePrice) * float64(v.Curbuyposition) * goods.Agreeunit
|
|
|
@@ -169,6 +172,7 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 持仓盈亏比例 = 持仓盈亏 / 开仓成本
|
|
|
if item.PositionPL != 0 && v.Buyopencost != 0 {
|
|
|
item.PositionPLRate = item.PositionPL / v.Buyopencost
|
|
|
+ item.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionPLRate, 4), 64)
|
|
|
}
|
|
|
|
|
|
rsp = append(rsp, item)
|
|
|
@@ -237,8 +241,10 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 计算价格与盈亏
|
|
|
// 开仓均价 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
item.OpenAveragePrice = v.Sellopencost / float64(v.Cursellposition) / goods.Agreeunit
|
|
|
+ item.OpenAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.OpenAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 持仓均价 = 持仓成本 / 期末头寸 / 合约单位
|
|
|
item.PositionAveragePrice = v.Sellpositioncost / float64(v.Cursellposition) / goods.Agreeunit
|
|
|
+ item.PositionAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 盯市浮盈(MTP:浮动盈亏、持仓盈亏) 卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
if item.Last != 0 {
|
|
|
item.PositionPL = (item.PositionAveragePrice - item.Last) * float64(v.Cursellposition) * goods.Agreeunit
|
|
|
@@ -250,6 +256,7 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 持仓盈亏比例 = 持仓盈亏 / 开仓成本
|
|
|
if item.PositionPL != 0 && v.Sellopencost != 0 {
|
|
|
item.PositionPLRate = item.PositionPL / v.Sellopencost
|
|
|
+ item.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionPLRate, 4), 64)
|
|
|
}
|
|
|
|
|
|
rsp = append(rsp, item)
|
|
|
@@ -345,10 +352,12 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
}
|
|
|
// 开仓均价 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
item.OpenAveragePrice = item.OpenCost / float64(item.CurPositionQTY) / goods.Agreeunit
|
|
|
+ item.OpenAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.OpenAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 持仓成本
|
|
|
item.PositionCost = v.Buycurholderamount
|
|
|
// 持仓均价 = 持仓成本 / 期末头寸 / 合约单位
|
|
|
item.PositionAveragePrice = v.Buycurholderamount / float64(v.Buycurpositionqty) / goods.Agreeunit
|
|
|
+ item.PositionAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 盯市浮盈(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位
|
|
|
if item.Last != 0 {
|
|
|
item.PositionPL = (item.Last - item.PositionAveragePrice) * float64(v.Buycurpositionqty) * goods.Agreeunit
|
|
|
@@ -360,6 +369,7 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 持仓盈亏比例 = 持仓盈亏 / 开仓成本
|
|
|
if item.PositionPL != 0 && item.OpenCost != 0 {
|
|
|
item.PositionPLRate = item.PositionPL / item.OpenCost
|
|
|
+ item.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionPLRate, 4), 64)
|
|
|
}
|
|
|
|
|
|
rsp = append(rsp, item)
|
|
|
@@ -443,10 +453,12 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
}
|
|
|
// 开仓均价 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
item.OpenAveragePrice = item.OpenCost / float64(item.CurPositionQTY) / goods.Agreeunit
|
|
|
+ item.OpenAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.OpenAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 持仓成本
|
|
|
item.PositionCost = v.Sellcurholderamount
|
|
|
// 持仓均价 = 持仓成本 / 期末头寸 / 合约单位
|
|
|
item.PositionAveragePrice = v.Sellcurholderamount / float64(v.Sellcurpositionqty) / goods.Agreeunit
|
|
|
+ item.PositionAveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionAveragePrice, int(goods.Decimalplace)), 64)
|
|
|
// 盯市浮盈(MTP:浮动盈亏、持仓盈亏) 卖方向 = (持仓均价 - 最新价) * 买期末头寸 * 合约单位
|
|
|
if item.Last != 0 {
|
|
|
item.PositionPL = (item.PositionAveragePrice - item.Last) * float64(v.Sellcurpositionqty) * goods.Agreeunit
|
|
|
@@ -458,6 +470,7 @@ func QueryErmcpTradePosition(c *gin.Context) {
|
|
|
// 持仓盈亏比例 = 持仓盈亏 / 开仓成本
|
|
|
if item.PositionPL != 0 && item.OpenCost != 0 {
|
|
|
item.PositionPLRate = item.PositionPL / item.OpenCost
|
|
|
+ item.PositionPLRate, _ = strconv.ParseFloat(utils.FormatFloat(item.PositionPLRate, 4), 64)
|
|
|
}
|
|
|
|
|
|
rsp = append(rsp, item)
|