|
|
@@ -527,3 +527,214 @@ func GetHedgeOutOrderDetails(accountID int) ([]QueryHedgeOrderDetailRsp, error)
|
|
|
|
|
|
return rsp, nil
|
|
|
}
|
|
|
+
|
|
|
+// QueryHedgeTradeDetailRsp 获取企业风管成交单返回模型
|
|
|
+type QueryHedgeTradeDetailRsp struct {
|
|
|
+ Tradeid string `json:"tradeid"` // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
|
|
|
+ Buyorsell int32 `json:"buyorsell"` // 方向 - 0:买 1:卖
|
|
|
+ Orderid string `json:"orderid"` // 委托单号
|
|
|
+ Tradedate string `json:"tradedate"` // 交易日(yyyyMMdd)
|
|
|
+ Accountid int64 `json:"accountid"` // 账号ID
|
|
|
+ Goodsid int32 `json:"goodsid"` // 商品ID
|
|
|
+ Marketid int32 `json:"marketid"` // 市场ID
|
|
|
+ Tradetime time.Time `json:"tradetime"` // 成交时间
|
|
|
+ Tradeprice float64 `json:"tradeprice"` // 成交价格
|
|
|
+ Tradeqty int64 `json:"tradeqty"` // 成交数量
|
|
|
+ Tradeamount float64 `json:"tradeamount"` // 成交金额(账户)
|
|
|
+ Opencharge float64 `json:"opencharge"` // 建仓手续费(账户)
|
|
|
+ Closecharge float64 `json:"closecharge"` // 平仓手续费(账户)
|
|
|
+ Tradetype int32 `json:"tradetype"` // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
|
|
|
+ Channelbuildtype int32 `json:"channelbuildtype"` // 委托单据类型 0:无 1:建仓 2:平仓
|
|
|
+ Closetype int32 `json:"closetype"` // 平仓方式 - 0:无 1:平今 2:平昨
|
|
|
+ Curexchangerate float64 `json:"curexchangerate"` // 当前汇率
|
|
|
+ Opencharge2 float64 `json:"opencharge2"` // 建仓手续费(商品)
|
|
|
+ Closecharge2 float64 `json:"closecharge2"` // 平仓手续费(商品)
|
|
|
+
|
|
|
+ Goodscode string `json:"goodscode"` // 商品代码(内部)
|
|
|
+ Goodsname string `json:"goodsname"` // 商品名称
|
|
|
+
|
|
|
+ Exchangefullname string `json:"exchangefullname"` // 外部交易所全称
|
|
|
+}
|
|
|
+
|
|
|
+// GetHedgeInnerTradeDetails 获取通道交易内部成交单信息
|
|
|
+func GetHedgeInnerTradeDetails(accountID, goodsID, buyOrSell int) ([]QueryHedgeTradeDetailRsp, error) {
|
|
|
+ type tradeDetail struct {
|
|
|
+ Tradeid string `json:"tradeid" xorm:"'TRADEIDSTR'"` // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
|
|
|
+ Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 方向 - 0:买 1:卖
|
|
|
+ Orderid string `json:"orderid" xorm:"'ORDERIDSTR'"` // 委托单号
|
|
|
+ Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
|
|
|
+ Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 账号ID
|
|
|
+ Goodsid int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
|
|
|
+ Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
|
|
|
+ Tradetime time.Time `json:"tradetime" xorm:"'TRADETIME'"` // 成交时间
|
|
|
+ Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价格
|
|
|
+ Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
|
|
|
+ Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额(账户)
|
|
|
+ Closepl float64 `json:"closepl" xorm:"'CLOSEPL'"` // 平仓盈亏(账户)
|
|
|
+ Opencharge float64 `json:"opencharge" xorm:"'OPENCHARGE'"` // 建仓手续费(账户)
|
|
|
+ Closecharge float64 `json:"closecharge" xorm:"'CLOSECHARGE'"` // 平仓手续费(账户)
|
|
|
+ Tradetype int32 `json:"tradetype" xorm:"'TRADETYPE'"` // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
|
|
|
+ Channelbuildtype int32 `json:"channelbuildtype" xorm:"'CHANNELBUILDTYPE'"` // 委托单据类型 0:无 1:建仓 2:平仓
|
|
|
+ Closetype int32 `json:"closetype" xorm:"'CLOSETYPE'"` // 平仓方式 - 0:无 1:平今 2:平昨
|
|
|
+ Hedgeflag int32 `json:"hedgeflag" xorm:"'HEDGEFLAG'"` // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
|
|
|
+ Openqty int64 `json:"openqty" xorm:"'OPENQTY'"` // 开仓数量(先建后平操作 需要记录)
|
|
|
+ Closeqty int64 `json:"closeqty" xorm:"'CLOSEQTY'"` // 平仓数量(先建后平操作 需要记录)
|
|
|
+ Status int32 `json:"status" xorm:"'STATUS'"` // 处理状态 - 1:待处理 2:已处理 3:处理失败
|
|
|
+ Isreckoned int32 `json:"isreckoned" xorm:"'ISRECKONED'"` // 是否结算 - 0:未结算 1:已结算
|
|
|
+ Openfeealgorithm int32 `json:"openfeealgorithm" xorm:"'OPENFEEALGORITHM'"` // 建仓手续费收取方式 1:比率 2:固定
|
|
|
+ Openchargevalue float64 `json:"openchargevalue" xorm:"'OPENCHARGEVALUE'"` // 建仓手续费设置值
|
|
|
+ Closefeealgorithm int32 `json:"closefeealgorithm" xorm:"'CLOSEFEEALGORITHM'"` // 平仓手续费收取方式 1:比率 2:固定
|
|
|
+ Closechargevalue float64 `json:"closechargevalue" xorm:"'CLOSECHARGEVALUE'"` // 平仓手续费设置值
|
|
|
+ Accountcurrencyid int32 `json:"accountcurrencyid" xorm:"'ACCOUNTCURRENCYID'"` // 账户币种ID
|
|
|
+ Goodscurrencyid int32 `json:"goodscurrencyid" xorm:"'GOODSCURRENCYID'"` // 商品币种ID
|
|
|
+ Curexchangerate float64 `json:"curexchangerate" xorm:"'CUREXCHANGERATE'"` // 当前汇率
|
|
|
+ Opencharge2 float64 `json:"opencharge2" xorm:"'OPENCHARGE2'"` // 建仓手续费(商品)
|
|
|
+ Closecharge2 float64 `json:"closecharge2" xorm:"'CLOSECHARGE2'"` // 平仓手续费(商品)
|
|
|
+ Closepl2 float64 `json:"closepl2" xorm:"'CLOSEPL2'"` // 平仓盈亏(商品)
|
|
|
+ Closepl3 float64 `json:"closepl3" xorm:"'CLOSEPL3'"` // 平仓盈亏(账户)(逐笔)
|
|
|
+ Closepl4 float64 `json:"closepl4" xorm:"'CLOSEPL4'"` // 平仓盈亏(商品)(逐笔)
|
|
|
+ Extenalopenfeealgorithm int32 `json:"extenalopenfeealgorithm" xorm:"'EXTENALOPENFEEALGORITHM'"` // 建仓手续费收取方式(外部配置) 1:比率 2:固定
|
|
|
+ Extenalopenchargevalue float64 `json:"extenalopenchargevalue" xorm:"'EXTENALOPENCHARGEVALUE'"` // 建仓手续费设置值
|
|
|
+ Extenalclosefeealgorithm int32 `json:"extenalclosefeealgorithm" xorm:"'EXTENALCLOSEFEEALGORITHM'"` // 平仓手续费收取方式 1:比率 2:固定
|
|
|
+ Extenalclosechargevalue float64 `json:"extenalclosechargevalue" xorm:"'EXTENALCLOSECHARGEVALUE'"` // 平仓手续费设置值
|
|
|
+ Extenalopencharge float64 `json:"extenalopencharge" xorm:"'EXTENALOPENCHARGE'"` // 建仓手续费(商品)(外部)
|
|
|
+ Extenalclosecharge float64 `json:"extenalclosecharge" xorm:"'EXTENALCLOSECHARGE'"` // 平仓手续费(商品)(外部)
|
|
|
+ Parentaccountid int64 `json:"parentaccountid" xorm:"'PARENTACCOUNTID'"` // 所属母账户
|
|
|
+ Relatedouttradeid int64 `json:"relatedouttradeid" xorm:"'RELATEDOUTTRADEID'"` // 关联外部成交单ID
|
|
|
+
|
|
|
+ Orderidstr string `xorm:"ORDERIDSTR"`
|
|
|
+ Goodscode string `xorm:"GOODSCODE"`
|
|
|
+ Goodsname string `xorm:"GOODSNAME"`
|
|
|
+ Exchangefullname string `xorm:"'EXCHANGEFULLNAME'"`
|
|
|
+ }
|
|
|
+
|
|
|
+ tradeDetails := make([]tradeDetail, 0)
|
|
|
+ session := db.GetEngine().Table("HEDGE_INNERTRADEDETAIL T").
|
|
|
+ Select("to_char(T.TRADEID) TRADEIDSTR, to_char(T.ORDERID) ORDERIDSTR, G.GOODSCODE, G.GOODSNAME, T.*, EX.EXCHANGEFULLNAME").
|
|
|
+ Join("LEFT", "GOODS G", "G.GOODSID = T.GOODSID").
|
|
|
+ Join("LEFT", "GOODSGROUP GG", "GG.GOODSGROUPID = G.GOODSGROUPID").
|
|
|
+ Join("LEFT", "EXTERNALEXCHANGE EX", "GG.EXEXCHANGEID = EX.AUTOID").
|
|
|
+ Where("T.ACCOUNTID = ?", accountID)
|
|
|
+ if goodsID != 0 {
|
|
|
+ session = session.And("T.GOODSID = ?", goodsID)
|
|
|
+ }
|
|
|
+ if buyOrSell != 0 {
|
|
|
+ session = session.And("T.BUYORSELL = ?", buyOrSell)
|
|
|
+ }
|
|
|
+ if err := session.Desc("T.TRADEID").
|
|
|
+ Find(&tradeDetails); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ rsp := make([]QueryHedgeTradeDetailRsp, 0)
|
|
|
+ for _, v := range tradeDetails {
|
|
|
+ rsp = append(rsp, QueryHedgeTradeDetailRsp{
|
|
|
+ Tradeid: v.Tradeid,
|
|
|
+ Buyorsell: v.Buyorsell,
|
|
|
+ Orderid: v.Orderid,
|
|
|
+ Tradedate: v.Tradedate,
|
|
|
+ Accountid: v.Accountid,
|
|
|
+ Goodsid: v.Goodsid,
|
|
|
+ Marketid: v.Marketid,
|
|
|
+ Tradetime: v.Tradetime,
|
|
|
+ Tradeprice: v.Tradeprice,
|
|
|
+ Tradeqty: v.Tradeqty,
|
|
|
+ Tradeamount: v.Tradeamount,
|
|
|
+ Opencharge: v.Opencharge,
|
|
|
+ Closecharge: v.Closecharge,
|
|
|
+ Tradetype: v.Tradetype,
|
|
|
+ Channelbuildtype: v.Channelbuildtype,
|
|
|
+ Closetype: v.Closetype,
|
|
|
+ Curexchangerate: v.Curexchangerate,
|
|
|
+ Opencharge2: v.Opencharge2,
|
|
|
+ Closecharge2: v.Closecharge2,
|
|
|
+ Goodscode: v.Goodscode,
|
|
|
+ Goodsname: v.Goodsname,
|
|
|
+ Exchangefullname: v.Exchangefullname,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return rsp, nil
|
|
|
+}
|
|
|
+
|
|
|
+// GetHedgeOutTradeDetails 获取通道交易外部成交单信息
|
|
|
+func GetHedgeOutTradeDetails(accountID, goodsID, buyOrSell int) ([]QueryHedgeTradeDetailRsp, error) {
|
|
|
+ type tradeDetail struct {
|
|
|
+ Outtradeid string `json:"outtradeid" xorm:"'OUTTRADEIDSTR'" binding:"required"` // 外部成交单ID(114+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
|
|
|
+ Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
|
|
|
+ Relatedoutorderid string `json:"relatedoutorderid" xorm:"'RELATEDOUTORDERIDSTR'"` // 关联外部委托单ID
|
|
|
+ Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账号[外部母账户]
|
|
|
+ Hedgeaccountcode string `json:"hedgeaccountcode" xorm:"'HEDGEACCOUNTCODE'"` // 对冲账号
|
|
|
+ Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
|
|
|
+ Hedgegoodsid int64 `json:"hedgegoodsid" xorm:"'HEDGEGOODSID'"` // 对冲合约ID
|
|
|
+ Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向 - 0:买 1:卖
|
|
|
+ Channelbuildtype int32 `json:"channelbuildtype" xorm:"'CHANNELBUILDTYPE'"` // 开平标志- 0:无 1:建仓 2:平仓
|
|
|
+ Closetype int32 `json:"closetype" xorm:"'CLOSETYPE'"` // 平仓方式 - 0:无 1:平今 2:平昨
|
|
|
+ Hedgeflag int32 `json:"hedgeflag" xorm:"'HEDGEFLAG'"` // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
|
|
|
+ Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价格
|
|
|
+ Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
|
|
|
+ Tradetime time.Time `json:"tradetime" xorm:"'TRADETIME'"` // 成交时间
|
|
|
+ Relatedmhpinnerorderid int64 `json:"relatedmhpinnerorderid" xorm:"'RELATEDMHPINNERORDERID'"` // 接口平台委托单ID
|
|
|
+ Mhpinnertradeid int64 `json:"mhpinnertradeid" xorm:"'MHPINNERTRADEID'"` // 接口平台成交单ID
|
|
|
+ Hasinnerorder int32 `json:"hasinnerorder" xorm:"'HASINNERORDER'"` // 是否有内部单关联 - 0:无 1:有
|
|
|
+ Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
|
|
|
+ Optiontype int32 `json:"optiontype" xorm:"'OPTIONTYPE'"` // 期权类型 - 1:认购(看涨) 2:认沽(看跌)
|
|
|
+ Premium float64 `json:"premium" xorm:"'PREMIUM'"` // 权利金
|
|
|
+ Tradetype int32 `json:"tradetype" xorm:"'TRADETYPE'"` // 成交类别 - 1:正常委托成交3:修正持仓成交
|
|
|
+
|
|
|
+ Orderidstr string `xorm:"ORDERIDSTR"`
|
|
|
+ Goodscode string `xorm:"GOODSCODE"`
|
|
|
+ Goodsname string `xorm:"GOODSNAME"`
|
|
|
+ Exchangefullname string `xorm:"'EXCHANGEFULLNAME'"`
|
|
|
+
|
|
|
+ Tradeamount float64 `xorm:"TRADEAMOUNT"` // 成交金额
|
|
|
+ }
|
|
|
+
|
|
|
+ tradeDetails := make([]tradeDetail, 0)
|
|
|
+ session := db.GetEngine().Table("HEDGE_OUTTRADEDETAIL T").
|
|
|
+ Select("to_char(T.OUTTRADEID) OUTTRADEIDSTR, to_char(T.RELATEDOUTORDERID) RELATEDOUTORDERIDSTR, G.GOODSCODE, G.GOODSNAME, T.*, EX.EXCHANGEFULLNAME, (T.TRADEPRICE * T.TRADEQTY * G.AGREEUNIT) TRADEAMOUNT").
|
|
|
+ Join("LEFT", "GOODS G", "G.GOODSID = T.HEDGEGOODSID").
|
|
|
+ Join("LEFT", "GOODSGROUP GG", "GG.GOODSGROUPID = G.GOODSGROUPID").
|
|
|
+ Join("LEFT", "EXTERNALEXCHANGE EX", "GG.EXEXCHANGEID = EX.AUTOID").
|
|
|
+ Where("T.ACCOUNTID = ?", accountID)
|
|
|
+ if goodsID != 0 {
|
|
|
+ session = session.And("T.HEDGEGOODSID = ?", goodsID)
|
|
|
+ }
|
|
|
+ if buyOrSell != 0 {
|
|
|
+ session = session.And("T.BUYORSELL = ?", buyOrSell)
|
|
|
+ }
|
|
|
+ if err := session.Desc("T.OUTTRADEID").
|
|
|
+ Find(&tradeDetails); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ rsp := make([]QueryHedgeTradeDetailRsp, 0)
|
|
|
+ for _, v := range tradeDetails {
|
|
|
+ rsp = append(rsp, QueryHedgeTradeDetailRsp{
|
|
|
+ Tradeid: v.Outtradeid,
|
|
|
+ Buyorsell: v.Buyorsell,
|
|
|
+ Orderid: v.Relatedoutorderid,
|
|
|
+ Tradedate: v.Tradedate,
|
|
|
+ Accountid: v.Accountid,
|
|
|
+ Goodsid: int32(v.Hedgegoodsid),
|
|
|
+ Marketid: v.Marketid,
|
|
|
+ Tradetime: v.Tradetime,
|
|
|
+ Tradeprice: v.Tradeprice,
|
|
|
+ Tradeqty: v.Tradeqty,
|
|
|
+ Tradeamount: v.Tradeamount,
|
|
|
+ Opencharge: 0,
|
|
|
+ Closecharge: 0,
|
|
|
+ Tradetype: v.Tradetype,
|
|
|
+ Channelbuildtype: v.Channelbuildtype,
|
|
|
+ Closetype: v.Closetype,
|
|
|
+ Curexchangerate: 1,
|
|
|
+ Opencharge2: 0,
|
|
|
+ Closecharge2: 0,
|
|
|
+ Goodscode: v.Goodscode,
|
|
|
+ Goodsname: v.Goodsname,
|
|
|
+ Exchangefullname: v.Exchangefullname,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return rsp, nil
|
|
|
+}
|