|
|
@@ -3,6 +3,7 @@ package order
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "math"
|
|
|
"mtp2_if/db"
|
|
|
"mtp2_if/global/app"
|
|
|
"mtp2_if/global/e"
|
|
|
@@ -16,6 +17,15 @@ import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
|
+type QtyCovert struct {
|
|
|
+ QTYDECIMALPLACE int32
|
|
|
+}
|
|
|
+
|
|
|
+// CovertQty 根据数位 放大缩小
|
|
|
+func (r *QtyCovert) CovertQty(v int64) float64 {
|
|
|
+ return float64(v) / math.Pow10(int(r.QTYDECIMALPLACE))
|
|
|
+}
|
|
|
+
|
|
|
// QueryTradePositionReq 持仓汇总查询请求参数(合约市场)
|
|
|
type QueryTradePositionReq struct {
|
|
|
AccountID string `form:"accountID" binding:"required"`
|
|
|
@@ -36,22 +46,23 @@ type QueryTradePositionRsp struct {
|
|
|
DecimalPlace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
|
|
|
MarketID int64 `json:"marketid" xorm:"'MARKETID'"` // 所属市场ID
|
|
|
TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
- PositionQTY int64 `json:"positionqty" xorm:"'POSITIONQTY'"` // 期初持仓数量
|
|
|
+ PositionQTY float64 `json:"positionqty" xorm:"'POSITIONQTY'"` // 期初持仓数量
|
|
|
HolderAmount float64 `json:"holderamount" xorm:"'HOLDERAMOUNT'"` // 期初持仓总金额[商品币种]
|
|
|
- CurPositionQTY int64 `json:"curpositionqty" xorm:"'CURPOSITIONQTY'"` // 当前持仓总数量
|
|
|
+ CurPositionQTY float64 `json:"curpositionqty" xorm:"'CURPOSITIONQTY'"` // 当前持仓总数量
|
|
|
CurHolderAmount float64 `json:"curholderamount" xorm:"'CURHOLDERAMOUNT'"` // 当前持仓总金额[商品币种]
|
|
|
- FrozenQTY int64 `json:"frozenqty" xorm:"'FROZENQTY'"` // 持仓冻结数量
|
|
|
- OtherFrozenQTY int64 `json:"otherfrozenqty" xorm:"'OTHERFROZENQTY'"` // 持仓其他冻结数量(交割冻结)
|
|
|
- OpenReqQTY int64 `json:"openreqqty" xorm:"'OPENREQQTY'"` // 开仓申请数量(用于比较最大持仓数量)
|
|
|
- OpenTotalQTY int64 `json:"opentotalqty" xorm:"'OPENTOTALQTY'"` // 开仓总数量
|
|
|
- CloseTotalQTY int64 `json:"closetotalqty" xorm:"'CLOSETOTALQTY'"` // 平仓总数量
|
|
|
- TNQTY int64 `json:"tnqty" xorm:"'TNQTY'"` // T+N冻结总量
|
|
|
- TNUsedQTY int64 `json:"tnusedqty" xorm:"'TNUSEDQTY'"` // T+N使用量(可以使用T+N的冻结数量)
|
|
|
- CurTDPosition int64 `json:"curtdposition" xorm:"'CURTDPOSITION'"` // 期末今日头寸
|
|
|
- FreTDPosition int64 `json:"fretdposition" xorm:"'FRETDPOSITION'"` // 冻结今日头寸
|
|
|
- EnableQTY int64 `json:"enableqty" xorm:"'ENABLEQTY'"` // 可用量
|
|
|
+ FrozenQTY float64 `json:"frozenqty" xorm:"'FROZENQTY'"` // 持仓冻结数量
|
|
|
+ OtherFrozenQTY float64 `json:"otherfrozenqty" xorm:"'OTHERFROZENQTY'"` // 持仓其他冻结数量(交割冻结)
|
|
|
+ OpenReqQTY float64 `json:"openreqqty" xorm:"'OPENREQQTY'"` // 开仓申请数量(用于比较最大持仓数量)
|
|
|
+ OpenTotalQTY float64 `json:"opentotalqty" xorm:"'OPENTOTALQTY'"` // 开仓总数量
|
|
|
+ CloseTotalQTY float64 `json:"closetotalqty" xorm:"'CLOSETOTALQTY'"` // 平仓总数量
|
|
|
+ TNQTY float64 `json:"tnqty" xorm:"'TNQTY'"` // T+N冻结总量
|
|
|
+ TNUsedQTY float64 `json:"tnusedqty" xorm:"'TNUSEDQTY'"` // T+N使用量(可以使用T+N的冻结数量)
|
|
|
+ CurTDPosition float64 `json:"curtdposition" xorm:"'CURTDPOSITION'"` // 期末今日头寸
|
|
|
+ FreTDPosition float64 `json:"fretdposition" xorm:"'FRETDPOSITION'"` // 冻结今日头寸
|
|
|
+ EnableQTY float64 `json:"enableqty" xorm:"'ENABLEQTY'"` // 可用量
|
|
|
AveragePrice float64 `json:"averageprice" xorm:"AVERAGEPRICE"` // 持仓均价
|
|
|
Usedmargin float64 `json:"usedmargin" xorm:"'USEDMARGIN'"` // 占用保证金[商品币种]
|
|
|
+ QTYDECIMALPLACE int32 `json:"qtydecimalplace"` // 成交量小数位
|
|
|
}
|
|
|
|
|
|
// QueryTradePosition 持仓汇总查询(合约市场)
|
|
|
@@ -79,16 +90,16 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
// 查询数据
|
|
|
type tradePosition struct {
|
|
|
models.Tradeposition `xorm:"extends"`
|
|
|
- Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码(内部)
|
|
|
- Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
|
|
|
- Currencyid int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
|
|
|
- Goodunitid int64 `json:"goodunitid" xorm:"'GOODUNITID'"` // 报价单位ID
|
|
|
- Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
|
|
|
- Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
|
|
|
- Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
|
|
|
- Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
|
|
|
- Trademode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
- DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码(内部)
|
|
|
+ Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
|
|
|
+ Currencyid int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
|
|
|
+ Goodunitid int64 `json:"goodunitid" xorm:"'GOODUNITID'"` // 报价单位ID
|
|
|
+ Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
|
|
|
+ Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
|
|
|
+ Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
|
|
|
+ Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
|
|
|
+ Trademode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
+ QTYDECIMALPLACE int32 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
|
|
|
}
|
|
|
datas := make([]tradePosition, 0)
|
|
|
engine := db.GetEngine()
|
|
|
@@ -97,7 +108,7 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
Join("LEFT", "GOODS", "TRADEPOSITION.GOODSID = GOODS.GOODSID").
|
|
|
Join("LEFT", "MARKET", "GOODS.MARKETID = MARKET.MARKETID").
|
|
|
Join("LEFT", "ENUMDICITEM", "GOODS.GOODUNITID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'goodsunit'").
|
|
|
- Select("TRADEPOSITION.*, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.CURRENCYID, GOODS.GOODUNITID,GOODS.DECIMALPLACE, ENUMDICITEM.ENUMDICNAME as GOODUNIT, GOODS.AGREEUNIT, GOODS.DECIMALPLACE, MARKET.MARKETID, MARKET.TRADEMODE").
|
|
|
+ Select("TRADEPOSITION.*, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.CURRENCYID, GOODS.GOODUNITID,GOODS.QTYDECIMALPLACE, ENUMDICITEM.ENUMDICNAME as GOODUNIT, GOODS.AGREEUNIT, GOODS.DECIMALPLACE, MARKET.MARKETID, MARKET.TRADEMODE").
|
|
|
Where(fmt.Sprintf(`TRADEPOSITION.ACCOUNTID in (%s)`, req.AccountID))
|
|
|
if len(req.TradeMode) > 0 {
|
|
|
s = s.And(fmt.Sprintf(`MARKET.TRADEMODE in (%s)`, req.TradeMode))
|
|
|
@@ -117,23 +128,24 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
// 反射数据
|
|
|
// struct -> json
|
|
|
if jsonBytes, err := json.Marshal(v); err == nil {
|
|
|
+ c := QtyCovert{QTYDECIMALPLACE: v.QTYDECIMALPLACE}
|
|
|
// json -> struct
|
|
|
json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
tradePosition.BuyOrSell = 0
|
|
|
- tradePosition.PositionQTY = v.Buypositionqty
|
|
|
+ tradePosition.PositionQTY = c.CovertQty(v.Buypositionqty)
|
|
|
tradePosition.HolderAmount = v.Buyholderamount
|
|
|
- tradePosition.CurPositionQTY = v.Buycurpositionqty
|
|
|
+ tradePosition.CurPositionQTY = c.CovertQty(v.Buycurpositionqty)
|
|
|
tradePosition.CurHolderAmount = v.Buycurholderamount
|
|
|
- tradePosition.FrozenQTY = v.Buyfrozenqty
|
|
|
- tradePosition.OtherFrozenQTY = v.Buyotherfrozenqty
|
|
|
- tradePosition.OpenReqQTY = v.Buyopenreqqty
|
|
|
- tradePosition.OpenTotalQTY = v.Buyopentotalqty
|
|
|
- tradePosition.CloseTotalQTY = v.Buyclosetotalqty
|
|
|
- tradePosition.TNQTY = v.Buytnqty
|
|
|
- tradePosition.TNUsedQTY = v.Buytnusedqty
|
|
|
- tradePosition.CurTDPosition = v.Buycurtdposition
|
|
|
- tradePosition.FreTDPosition = v.Buyfretdposition
|
|
|
- tradePosition.EnableQTY = v.Buycurpositionqty - v.Buyfrozenqty - v.Buyotherfrozenqty
|
|
|
+ tradePosition.FrozenQTY = c.CovertQty(v.Buyfrozenqty)
|
|
|
+ tradePosition.OtherFrozenQTY = c.CovertQty(v.Buyotherfrozenqty)
|
|
|
+ tradePosition.OpenReqQTY = c.CovertQty(v.Buyopenreqqty)
|
|
|
+ tradePosition.OpenTotalQTY = c.CovertQty(v.Buyopentotalqty)
|
|
|
+ tradePosition.CloseTotalQTY = c.CovertQty(v.Buyclosetotalqty)
|
|
|
+ tradePosition.TNQTY = c.CovertQty(v.Buytnqty)
|
|
|
+ tradePosition.TNUsedQTY = c.CovertQty(v.Buytnusedqty)
|
|
|
+ tradePosition.CurTDPosition = c.CovertQty(v.Buycurtdposition)
|
|
|
+ tradePosition.FreTDPosition = c.CovertQty(v.Buyfretdposition)
|
|
|
+ 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)
|
|
|
@@ -147,23 +159,24 @@ func QueryTradePosition(c *gin.Context) {
|
|
|
// 反射数据
|
|
|
// struct -> json
|
|
|
if jsonBytes, err := json.Marshal(v); err == nil {
|
|
|
+ c := QtyCovert{QTYDECIMALPLACE: v.QTYDECIMALPLACE}
|
|
|
// json -> struct
|
|
|
json.Unmarshal(jsonBytes, &tradePosition)
|
|
|
tradePosition.BuyOrSell = 1
|
|
|
- tradePosition.PositionQTY = v.Sellpositionqty
|
|
|
+ tradePosition.PositionQTY = c.CovertQty(v.Sellpositionqty)
|
|
|
tradePosition.HolderAmount = v.Sellholderamount
|
|
|
- tradePosition.CurPositionQTY = v.Sellcurpositionqty
|
|
|
+ tradePosition.CurPositionQTY = c.CovertQty(v.Sellcurpositionqty)
|
|
|
tradePosition.CurHolderAmount = v.Sellcurholderamount
|
|
|
- tradePosition.FrozenQTY = v.Sellfrozenqty
|
|
|
- tradePosition.OtherFrozenQTY = v.Sellotherfrozenqty
|
|
|
- tradePosition.OpenReqQTY = v.Sellopenreqqty
|
|
|
- tradePosition.OpenTotalQTY = v.Sellopentotalqty
|
|
|
- tradePosition.CloseTotalQTY = v.Sellclosetotalqty
|
|
|
- tradePosition.TNQTY = v.Selltnqty
|
|
|
- tradePosition.TNUsedQTY = v.Selltnusedqty
|
|
|
- tradePosition.CurTDPosition = v.Sellcurtdposition
|
|
|
- tradePosition.FreTDPosition = v.Sellfretdposition
|
|
|
- tradePosition.EnableQTY = v.Sellcurpositionqty - v.Sellfrozenqty - v.Sellotherfrozenqty
|
|
|
+ tradePosition.FrozenQTY = c.CovertQty(v.Sellfrozenqty)
|
|
|
+ tradePosition.OtherFrozenQTY = c.CovertQty(v.Sellotherfrozenqty)
|
|
|
+ tradePosition.OpenReqQTY = c.CovertQty(v.Sellopenreqqty)
|
|
|
+ tradePosition.OpenTotalQTY = c.CovertQty(v.Sellopentotalqty)
|
|
|
+ tradePosition.CloseTotalQTY = c.CovertQty(v.Sellclosetotalqty)
|
|
|
+ tradePosition.TNQTY = c.CovertQty(v.Selltnqty)
|
|
|
+ tradePosition.TNUsedQTY = c.CovertQty(v.Selltnusedqty)
|
|
|
+ tradePosition.CurTDPosition = c.CovertQty(v.Sellcurtdposition)
|
|
|
+ tradePosition.FreTDPosition = c.CovertQty(v.Sellfretdposition)
|
|
|
+ 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)
|
|
|
@@ -200,13 +213,13 @@ type QueryTradeOrderDetailRsp struct {
|
|
|
Buyorsell int64 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
|
|
|
Pricemode int64 `json:"pricemode" xorm:"'PRICEMODE'" binding:"required"` // 取价方式 - 1:市价 2: 限价
|
|
|
Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
|
|
|
- Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
|
|
|
- Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
|
|
|
- Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
|
|
|
- Openqty int64 `json:"openqty" xorm:"'OPENQTY'"` // 开仓数量(先建后平操作,需要记录)
|
|
|
- Closeqty int64 `json:"closeqty" xorm:"'CLOSEQTY'"` // 平仓数量(先建后平操作 需要记录)
|
|
|
- Opentradeqty int64 `json:"opentradeqty" xorm:"'OPENTRADEQTY'"` // 开仓成交数量(先建后平操作,需要记录)
|
|
|
- Closetradeqty int64 `json:"closetradeqty" xorm:"'CLOSETRADEQTY'"` // 平仓成交数量(先建后平操作,需要记录)
|
|
|
+ Orderqty float64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
|
|
|
+ Tradeqty float64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
|
|
|
+ Cancelqty float64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
|
|
|
+ Openqty float64 `json:"openqty" xorm:"'OPENQTY'"` // 开仓数量(先建后平操作,需要记录)
|
|
|
+ Closeqty float64 `json:"closeqty" xorm:"'CLOSEQTY'"` // 平仓数量(先建后平操作 需要记录)
|
|
|
+ Opentradeqty float64 `json:"opentradeqty" xorm:"'OPENTRADEQTY'"` // 开仓成交数量(先建后平操作,需要记录)
|
|
|
+ Closetradeqty float64 `json:"closetradeqty" xorm:"'CLOSETRADEQTY'"` // 平仓成交数量(先建后平操作,需要记录)
|
|
|
Freezemargin float64 `json:"freezemargin" xorm:"'FREEZEMARGIN'"` // 冻结保证金(冻结交易金额)
|
|
|
Unfreezemargin float64 `json:"unfreezemargin" xorm:"'UNFREEZEMARGIN'"` // 解冻保证金
|
|
|
Freezecharge float64 `json:"freezecharge" xorm:"'FREEZECHARGE'"` // 冻结手续费
|
|
|
@@ -227,13 +240,28 @@ type QueryTradeOrderDetailRsp struct {
|
|
|
Clienttype int64 `json:"clienttype" xorm:"'CLIENTTYPE'"` // 客户端类型 - 0:保留为未填终端类型 1:PC管理端 2:PC交易端 3:手机客户端_安卓 4:网页客户端 5:微信客户端 6:手机客户端_苹果 7:网上开户客户端 8:无效终端编号 9:报价终端(中江)
|
|
|
Operatorid int64 `json:"operatorid" xorm:"'OPERATORID'"` // 登录账号(LoginID)
|
|
|
|
|
|
- GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
- GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
- DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
- Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
- TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
+ GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
+ GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
+ DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 商品报价小数位
|
|
|
+ Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
+ TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
|
|
|
- Enableqty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量 = 委托数量 - 成交数量 - 撤单数量
|
|
|
+ Enableqty float64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量 = 委托数量 - 成交数量 - 撤单数量
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QueryTradeOrderDetailRsp) calc() {
|
|
|
+ fCovert := func(v *float64) {
|
|
|
+ *v = *v / math.Pow10(r.QTYDECIMALPLACE)
|
|
|
+ }
|
|
|
+ fCovert(&r.Orderqty)
|
|
|
+ fCovert(&r.Tradeqty)
|
|
|
+ fCovert(&r.Cancelqty)
|
|
|
+ fCovert(&r.Openqty)
|
|
|
+ fCovert(&r.Closeqty)
|
|
|
+ fCovert(&r.Opentradeqty)
|
|
|
+ fCovert(&r.Closetradeqty)
|
|
|
+ fCovert(&r.Enableqty)
|
|
|
}
|
|
|
|
|
|
// QueryTradeOrderDetail 委托单查询请求(合约市场)
|
|
|
@@ -268,7 +296,7 @@ func QueryTradeOrderDetail(c *gin.Context) {
|
|
|
Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_ORDERDETAIL.MARKETID").
|
|
|
Select(`to_char(TRADE_ORDERDETAIL.ORDERID) as ORDERID, to_char(TRADE_ORDERDETAIL.PREORDERID) as PREORDERID, to_char(TRADE_ORDERDETAIL.CANCELORDERID) as CANCELORDERID, to_char(TRADE_ORDERDETAIL.RELATEDID) as RELATEDID,
|
|
|
TRADE_ORDERDETAIL.*, TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY as ENABLEQTY,
|
|
|
- GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE`).
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE`).
|
|
|
Where(fmt.Sprintf(`TRADE_ORDERDETAIL.ORDERSRC != 10 and TRADE_ORDERDETAIL.ACCOUNTID in (%s)`, req.AccountID)).
|
|
|
Desc("TRADE_ORDERDETAIL.ORDERTIME")
|
|
|
if len(req.OrderStatus) > 0 {
|
|
|
@@ -289,6 +317,9 @@ func QueryTradeOrderDetail(c *gin.Context) {
|
|
|
|
|
|
// 查询成功
|
|
|
logger.GetLogger().Debugln("QueryTradeOrderDetail successed: %v", datas)
|
|
|
+ for i := range datas {
|
|
|
+ datas[i].calc()
|
|
|
+ }
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, datas)
|
|
|
}
|
|
|
|
|
|
@@ -306,11 +337,25 @@ type QueryHisTradeOrderDetailReq struct {
|
|
|
type QueryHisTradeOrderDetailRsp struct {
|
|
|
models.Histradeorderdetail `xorm:"extends"`
|
|
|
|
|
|
- GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
- GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
- DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
- Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
- TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
+ GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
+ GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
+ DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
|
|
|
+ Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
+ TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
+}
|
|
|
+
|
|
|
+func (r *QueryHisTradeOrderDetailRsp) calc() {
|
|
|
+ fCovert := func(v *float64) {
|
|
|
+ *v = *v / math.Pow10(r.QTYDECIMALPLACE)
|
|
|
+ }
|
|
|
+ fCovert(&r.Orderqty)
|
|
|
+ fCovert(&r.Tradeqty)
|
|
|
+ fCovert(&r.Cancelqty)
|
|
|
+ fCovert(&r.Openqty)
|
|
|
+ fCovert(&r.Closeqty)
|
|
|
+ fCovert(&r.Opentradeqty)
|
|
|
+ fCovert(&r.Closetradeqty)
|
|
|
}
|
|
|
|
|
|
// QueryHisTradeOrderDetail 历史委托单查询请求(合约市场)
|
|
|
@@ -346,7 +391,7 @@ func QueryHisTradeOrderDetail(c *gin.Context) {
|
|
|
Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_ORDERDETAIL.MARKETID").
|
|
|
Select(`to_char(HIS_TRADE_ORDERDETAIL.ORDERID) as ORDERID, to_char(HIS_TRADE_ORDERDETAIL.PREORDERID) as PREORDERID, to_char(HIS_TRADE_ORDERDETAIL.CANCELORDERID) as CANCELORDERID, to_char(HIS_TRADE_ORDERDETAIL.RELATEDID) as RELATEDID,
|
|
|
HIS_TRADE_ORDERDETAIL.*,
|
|
|
- GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE`).
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE`).
|
|
|
Where(fmt.Sprintf(`HIS_TRADE_ORDERDETAIL.ORDERSRC != 10 and HIS_TRADE_ORDERDETAIL.ISVALIDDATA = 1 and HIS_TRADE_ORDERDETAIL.ACCOUNTID in (%s)`, req.AccountID)).
|
|
|
Desc("HIS_TRADE_ORDERDETAIL.ORDERTIME")
|
|
|
if len(req.OrderStatus) > 0 {
|
|
|
@@ -373,6 +418,9 @@ func QueryHisTradeOrderDetail(c *gin.Context) {
|
|
|
|
|
|
// 查询成功
|
|
|
logger.GetLogger().Debugln("QueryHisTradeOrderDetail successed: %v", datas)
|
|
|
+ for i := range datas {
|
|
|
+ datas[i].calc()
|
|
|
+ }
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, datas)
|
|
|
}
|
|
|
|
|
|
@@ -394,6 +442,7 @@ type QueryTradeDetailRsp struct {
|
|
|
GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 商品报价小数位
|
|
|
Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
ListingSelectType int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 关联委托单挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
|
|
|
@@ -401,6 +450,15 @@ type QueryTradeDetailRsp struct {
|
|
|
Charge float64 `json:"charge" xorm:"CHARGE"` // 手续费
|
|
|
}
|
|
|
|
|
|
+func (r *QueryTradeDetailRsp) calc() {
|
|
|
+ fCovert := func(v *float64) {
|
|
|
+ *v = *v / math.Pow10(r.QTYDECIMALPLACE)
|
|
|
+ }
|
|
|
+ fCovert(&r.Tradeqty)
|
|
|
+ fCovert(&r.Openqty)
|
|
|
+ fCovert(&r.Closeqty)
|
|
|
+}
|
|
|
+
|
|
|
// QueryTradeDetail 成交单查询(合约市场)
|
|
|
// @Summary 成交单查询(合约市场)
|
|
|
// @Produce json
|
|
|
@@ -436,7 +494,7 @@ func QueryTradeDetail(c *gin.Context) {
|
|
|
Join("LEFT", "TRADE_ORDERDETAIL", "TRADE_ORDERDETAIL.ORDERID = TRADE_TRADEDETAIL.ORDERID").
|
|
|
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, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
TRADE_ORDERDETAIL.LISTINGSELECTTYPE`).
|
|
|
Where(fmt.Sprintf("TRADE_TRADEDETAIL.TRADETYPE <= 13 and TRADE_TRADEDETAIL.ACCOUNTID in (%s)", req.AccountID)).
|
|
|
Desc("TRADE_TRADEDETAIL.TRADETIME")
|
|
|
@@ -467,6 +525,9 @@ func QueryTradeDetail(c *gin.Context) {
|
|
|
|
|
|
// 查询成功
|
|
|
logger.GetLogger().Debugln("QueryTradeDetail successed: %v", datas)
|
|
|
+ for i := range datas {
|
|
|
+ datas[i].calc()
|
|
|
+ }
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, datas)
|
|
|
}
|
|
|
|
|
|
@@ -490,6 +551,7 @@ type QueryHisTradeDetailRsp struct {
|
|
|
GoodsCode string `json:"goodscode" xorm:"GOODSCODE"` // 商品代码
|
|
|
GoodsName string `json:"goodsname" xorm:"GOODSNAME"` // 商品名称
|
|
|
DECIMALPLACE int32 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 商品报价小数位
|
|
|
+ QTYDECIMALPLACE int `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 商品报价小数位
|
|
|
Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
|
|
|
TradeMode int32 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式
|
|
|
ListingSelectType int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 关联委托单挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
|
|
|
@@ -497,6 +559,15 @@ type QueryHisTradeDetailRsp struct {
|
|
|
Charge float64 `json:"charge" xorm:"CHARGE"` // 手续费
|
|
|
}
|
|
|
|
|
|
+func (r *QueryHisTradeDetailRsp) calc() {
|
|
|
+ fCovert := func(v *float64) {
|
|
|
+ *v = *v / math.Pow10(r.QTYDECIMALPLACE)
|
|
|
+ }
|
|
|
+ fCovert(&r.Tradeqty)
|
|
|
+ fCovert(&r.Openqty)
|
|
|
+ fCovert(&r.Closeqty)
|
|
|
+}
|
|
|
+
|
|
|
// QueryHisTradeDetail 历史成交单查询(合约市场)
|
|
|
// @Summary 历史成交单查询(合约市场)
|
|
|
// @Produce json
|
|
|
@@ -534,7 +605,7 @@ func QueryHisTradeDetail(c *gin.Context) {
|
|
|
Join("LEFT", "HIS_TRADE_ORDERDETAIL", "HIS_TRADE_ORDERDETAIL.ORDERID = HIS_TRADE_TRADEDETAIL.ORDERID").
|
|
|
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, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME,GOODS.DECIMALPLACE, GOODS.QTYDECIMALPLACE, MARKET.MARKETNAME, MARKET.TRADEMODE,
|
|
|
HIS_TRADE_ORDERDETAIL.LISTINGSELECTTYPE`).
|
|
|
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")
|
|
|
@@ -571,5 +642,8 @@ func QueryHisTradeDetail(c *gin.Context) {
|
|
|
|
|
|
// 查询成功
|
|
|
logger.GetLogger().Debugln("QueryHisTradeDetail successed: %v", datas)
|
|
|
+ for i := range datas {
|
|
|
+ datas[i].calc()
|
|
|
+ }
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, datas)
|
|
|
}
|