|
|
@@ -10,12 +10,11 @@ import (
|
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/models"
|
|
|
"mtp2_if/mtpcache"
|
|
|
- "mtp2_if/utils"
|
|
|
"net/http"
|
|
|
- "strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
)
|
|
|
|
|
|
type QtyCovert struct {
|
|
|
@@ -27,6 +26,16 @@ func (r *QtyCovert) CovertQty(v int64) float64 {
|
|
|
return float64(v) / math.Pow10(int(r.QTYDECIMALPLACE))
|
|
|
}
|
|
|
|
|
|
+// 成交付款信息
|
|
|
+type TradePayInfo struct {
|
|
|
+ PAYAMOUNT float64 `json:"payamount" xorm:"PAYAMOUNT"` // 支付金额(付款金额)
|
|
|
+ ADVANCERATIO float64 `json:"advanceratio" xorm:"ADVANCERATIO"` // 首付比率
|
|
|
+ TRADECHARGE float64 `json:"-" xorm:"TRADECHARGE"` // 成交手续费(买方)
|
|
|
+
|
|
|
+ TOTALAMOUNT float64 `json:"totalamount"` // 订单总额 = 成交金额 + 手续费
|
|
|
+ RECVAMOUNT float64 `json:"recvamount"` // 到账金额 = 成交金额 - 手续费
|
|
|
+}
|
|
|
+
|
|
|
// QueryTradePositionReq 持仓汇总查询请求参数(合约市场)
|
|
|
type QueryTradePositionReq struct {
|
|
|
AccountID string `form:"accountID" binding:"required"`
|
|
|
@@ -131,7 +140,7 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
if jsonBytes, err := json.Marshal(v); err == nil {
|
|
|
c := QtyCovert{QTYDECIMALPLACE: v.QTYDECIMALPLACE}
|
|
|
// json -> struct
|
|
|
- json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
+ _ = json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
tradePosition.BuyOrSell = 0
|
|
|
tradePosition.PositionQTY = c.CovertQty(v.Buypositionqty)
|
|
|
tradePosition.HolderAmount = v.Buyholderamount
|
|
|
@@ -149,7 +158,9 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
tradePosition.EnableQTY = c.CovertQty(v.Buycurpositionqty - v.Buyfrozenqty - v.Buyotherfrozenqty)
|
|
|
// 计算持仓均价
|
|
|
averagePrice := tradePosition.CurHolderAmount / float64(tradePosition.CurPositionQTY) / tradePosition.AgreeUnit
|
|
|
- tradePosition.AveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(v.Decimalplace)), 64)
|
|
|
+ //tradePosition.AveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(v.Decimalplace)), 64)
|
|
|
+ // #96004 改为固定3位小数
|
|
|
+ tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Round(3).Float64()
|
|
|
rst = append(rst, tradePosition)
|
|
|
}
|
|
|
}
|
|
|
@@ -162,7 +173,7 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
if jsonBytes, err := json.Marshal(v); err == nil {
|
|
|
c := QtyCovert{QTYDECIMALPLACE: v.QTYDECIMALPLACE}
|
|
|
// json -> struct
|
|
|
- json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
+ _ = json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
tradePosition.BuyOrSell = 1
|
|
|
tradePosition.PositionQTY = c.CovertQty(v.Sellpositionqty)
|
|
|
tradePosition.HolderAmount = v.Sellholderamount
|
|
|
@@ -180,7 +191,9 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
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)
|
|
|
+ //tradePosition.AveragePrice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(v.Decimalplace)), 64)
|
|
|
+ // #96004 改为固定3位小数
|
|
|
+ tradePosition.AveragePrice, _ = decimal.NewFromFloat(averagePrice).Round(3).Float64()
|
|
|
|
|
|
rst = append(rst, tradePosition)
|
|
|
}
|
|
|
@@ -445,15 +458,15 @@ type QueryTradeDetailReq struct {
|
|
|
// QueryTradeDetailRsp 成交单查询返回模型
|
|
|
type QueryTradeDetailRsp struct {
|
|
|
models.Tradetradedetail `xorm:"extends"`
|
|
|
-
|
|
|
- GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
- GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
- DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
- QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 商品报价小数位
|
|
|
- GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 商品单位id
|
|
|
- Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
- TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
- ListingSelectType int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 关联委托单挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
|
|
|
+ TradePayInfo `xorm:"extends"`
|
|
|
+ GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
+ GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
+ DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 商品报价小数位
|
|
|
+ GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 商品单位id
|
|
|
+ Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
+ TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
+ ListingSelectType int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 关联委托单挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
|
|
|
|
|
|
Charge float64 `json:"charge" xorm:"CHARGE"` // 手续费
|
|
|
ENUMDICNAME string `json:"enumdicname"` // 单位名称
|
|
|
@@ -467,6 +480,9 @@ func (r *QueryTradeDetailRsp) calc() {
|
|
|
fCovert(&r.Openqty)
|
|
|
fCovert(&r.Closeqty)
|
|
|
r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
|
|
|
+
|
|
|
+ r.TOTALAMOUNT = r.Tradeamount + r.Opencharge + r.Closecharge
|
|
|
+ r.RECVAMOUNT = r.Tradeamount - r.Opencharge - r.Closecharge
|
|
|
}
|
|
|
|
|
|
// QueryTradeDetail 成交单查询(合约市场)
|
|
|
@@ -502,10 +518,11 @@ func QueryTradeDetail(c *gin.Context) {
|
|
|
Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_TRADEDETAIL.GOODSID").
|
|
|
Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_TRADEDETAIL.MARKETID").
|
|
|
Join("LEFT", "TRADE_ORDERDETAIL", "TRADE_ORDERDETAIL.ORDERID = TRADE_TRADEDETAIL.ORDERID").
|
|
|
+ Join("LEFT", "TRADE_PAYORDER", "TRADE_PAYORDER.TRADEID = TRADE_TRADEDETAIL.TRADEID").
|
|
|
Select(`to_char(TRADE_TRADEDETAIL.TRADEID) as TRADEID, to_char(TRADE_TRADEDETAIL.ORDERID) as ORDERID,
|
|
|
TRADE_TRADEDETAIL.*, CASE TRADE_TRADEDETAIL.BUILDTYPE WHEN 1 THEN TRADE_TRADEDETAIL.OPENCHARGE ELSE TRADE_TRADEDETAIL.CLOSECHARGE END as CHARGE,
|
|
|
GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE,GOODS.GOODUNITID, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
- TRADE_ORDERDETAIL.LISTINGSELECTTYPE`).
|
|
|
+ TRADE_ORDERDETAIL.LISTINGSELECTTYPE, TRADE_PAYORDER.ADVANCERATIO, TRADE_PAYORDER.PAYAMOUNT, TRADE_PAYORDER.TRADECHARGE`).
|
|
|
Where(fmt.Sprintf("TRADE_TRADEDETAIL.TRADETYPE <= 13 and TRADE_TRADEDETAIL.ACCOUNTID in (%s)", req.AccountID)).
|
|
|
Desc("TRADE_TRADEDETAIL.TRADETIME")
|
|
|
if req.TradeID > 0 {
|
|
|
@@ -557,6 +574,7 @@ type QueryHisTradeDetailReq struct {
|
|
|
// QueryHisTradeDetailRsp 历史成交单查询返回模型
|
|
|
type QueryHisTradeDetailRsp struct {
|
|
|
models.Histradetradedetail `xorm:"extends"`
|
|
|
+ TradePayInfo `xorm:"extends"`
|
|
|
|
|
|
GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
@@ -579,6 +597,9 @@ func (r *QueryHisTradeDetailRsp) calc() {
|
|
|
fCovert(&r.Openqty)
|
|
|
fCovert(&r.Closeqty)
|
|
|
r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
|
|
|
+
|
|
|
+ r.TOTALAMOUNT = r.Tradeamount + r.Opencharge + r.Closecharge
|
|
|
+ r.RECVAMOUNT = r.Tradeamount - r.Opencharge - r.Closecharge
|
|
|
}
|
|
|
|
|
|
// QueryHisTradeDetail 历史成交单查询(合约市场)
|
|
|
@@ -616,10 +637,11 @@ func QueryHisTradeDetail(c *gin.Context) {
|
|
|
Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
|
|
|
Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_TRADEDETAIL.MARKETID").
|
|
|
Join("LEFT", "HIS_TRADE_ORDERDETAIL", "HIS_TRADE_ORDERDETAIL.ORDERID = HIS_TRADE_TRADEDETAIL.ORDERID").
|
|
|
+ Join("LEFT", "TRADE_PAYORDER", "TRADE_PAYORDER.TRADEID = HIS_TRADE_TRADEDETAIL.TRADEID").
|
|
|
Select(`to_char(HIS_TRADE_TRADEDETAIL.TRADEID) as TRADEID, to_char(HIS_TRADE_TRADEDETAIL.ORDERID) as ORDERID,
|
|
|
HIS_TRADE_TRADEDETAIL.*, CASE HIS_TRADE_TRADEDETAIL.BUILDTYPE WHEN 1 THEN HIS_TRADE_TRADEDETAIL.OPENCHARGE ELSE HIS_TRADE_TRADEDETAIL.CLOSECHARGE END as CHARGE,
|
|
|
GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE, GOODS.GOODUNITID, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
- HIS_TRADE_ORDERDETAIL.LISTINGSELECTTYPE`).
|
|
|
+ HIS_TRADE_ORDERDETAIL.LISTINGSELECTTYPE, TRADE_PAYORDER.ADVANCERATIO, TRADE_PAYORDER.PAYAMOUNT, TRADE_PAYORDER.TRADECHARGE`).
|
|
|
Where(fmt.Sprintf("HIS_TRADE_TRADEDETAIL.TRADETYPE <= 13 and HIS_TRADE_TRADEDETAIL.ISVALIDDATA = 1 and HIS_TRADE_TRADEDETAIL.ACCOUNTID in (%s)", req.AccountID)).
|
|
|
Desc("HIS_TRADE_TRADEDETAIL.TRADETIME")
|
|
|
if req.TradeID > 0 {
|