Bladeren bron

增加 “查询期现套利策略表信息” 和 “查询现货合同表信息” 接口

Simon Zhou 5 jaren geleden
bovenliggende
commit
ea06274794
7 gewijzigde bestanden met toevoegingen van 1700 en 363 verwijderingen
  1. 324 83
      controllers/erms2/erms2.go
  2. 469 95
      docs/docs.go
  3. 469 95
      docs/swagger.json
  4. 357 89
      docs/swagger.yaml
  5. 38 1
      models/erms2Models.go
  6. 39 0
      models/goodsModels.go
  7. 4 0
      routers/router.go

+ 324 - 83
controllers/erms2/erms2.go

@@ -19,56 +19,37 @@ type QueryInnerTradeDetailReq struct {
 
 // QueryInnerTradeDetailRsp 内部成交单信息
 type QueryInnerTradeDetailRsp struct {
-	Tradeid                  int64     `json:"tradeid"  xorm:"'TRADEID'" binding:"required"`                // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
-	Buyorsell                int64     `json:"buyorsell"  xorm:"'BUYORSELL'" binding:"required"`            // 方向 - 0:买 1:卖
-	Orderid                  int64     `json:"orderid"  xorm:"'ORDERID'"`                                   // 委托单号
-	Tradedate                string    `json:"tradedate"  xorm:"'TRADEDATE'"`                               // 交易日(yyyyMMdd)
-	Accountid                int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                               // 账号ID
-	Goodsid                  int64     `json:"goodsid"  xorm:"'GOODSID'"`                                   // 商品ID
-	Marketid                 int64     `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                int64     `json:"tradetype"  xorm:"'TRADETYPE'"`                               // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
-	Channelbuildtype         int64     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`                 // 委托单据类型 0:无 1:建仓 2:平仓
-	Closetype                int64     `json:"closetype"  xorm:"'CLOSETYPE'"`                               // 平仓方式 - 0:无 1:平今 2:平昨
-	Hedgeflag                int64     `json:"hedgeflag"  xorm:"'HEDGEFLAG'"`                               // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
-	Openqty                  int64     `json:"openqty"  xorm:"'OPENQTY'"`                                   // 开仓数量(先建后平操作 需要记录)
-	Closeqty                 int64     `json:"closeqty"  xorm:"'CLOSEQTY'"`                                 // 平仓数量(先建后平操作 需要记录)
-	Status                   int64     `json:"status"  xorm:"'STATUS'"`                                     // 处理状态 - 1:待处理 2:已处理 3:处理失败
-	Isreckoned               int64     `json:"isreckoned"  xorm:"'ISRECKONED'"`                             // 是否结算 - 0:未结算 1:已结算
-	Openfeealgorithm         int64     `json:"openfeealgorithm"  xorm:"'OPENFEEALGORITHM'"`                 // 建仓手续费收取方式  1:比率  2:固定
-	Openchargevalue          float64   `json:"openchargevalue"  xorm:"'OPENCHARGEVALUE'"`                   // 建仓手续费设置值
-	Closefeealgorithm        int64     `json:"closefeealgorithm"  xorm:"'CLOSEFEEALGORITHM'"`               // 平仓手续费收取方式 1:比率  2:固定
-	Closechargevalue         float64   `json:"closechargevalue"  xorm:"'CLOSECHARGEVALUE'"`                 // 平仓手续费设置值
-	Accountcurrencyid        int64     `json:"accountcurrencyid"  xorm:"'ACCOUNTCURRENCYID'"`               // 账户币种ID
-	Goodscurrencyid          int64     `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  int64     `json:"extenalopenfeealgorithm"  xorm:"'EXTENALOPENFEEALGORITHM'"`   // 建仓手续费收取方式(外部配置) 1:比率  2:固定
-	Extenalopenchargevalue   float64   `json:"extenalopenchargevalue"  xorm:"'EXTENALOPENCHARGEVALUE'"`     // 建仓手续费设置值
-	Extenalclosefeealgorithm int64     `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
-
-	Asapplyid      int64 `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID
-	Detailtype     int64 `json:"detailtype"  xorm:"'DETAILTYPE'"`                  // 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
-	Spotcontractid int64 `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`          // 现货合同ID [1:套利对冲 为合同ID,2:期货换月\3:期货仓位调整时为0]
-
-	ASContractno string `json:"ascontractno"  xorm:"'ASCONTRACTNO'"` // 策略编号
-
-	Spotcontractno string `json:"spotcontractno"  xorm:"'SPOTCONTRACTNO'"` // 现货合同编号
+	Tradeid           int64     `json:"tradeid"  xorm:"'TRADEID'" binding:"required"`     // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+	Buyorsell         int64     `json:"buyorsell"  xorm:"'BUYORSELL'" binding:"required"` // 方向 - 0:买 1:卖
+	Orderid           int64     `json:"orderid"  xorm:"'ORDERID'"`                        // 委托单号
+	Accountid         int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                    // 账号ID
+	Goodsid           int64     `json:"goodsid"  xorm:"'GOODSID'"`                        // 商品ID
+	Marketid          int64     `json:"marketid"  xorm:"'MARKETID'"`                      // 市场ID
+	Tradetime         time.Time `json:"tradetime"  xorm:"'TRADETIME'"`                    // 成交时间
+	Tradeprice        float64   `json:"tradeprice"  xorm:"'TRADEPRICE'"`                  // 成交价格
+	Tradeqty          int64     `json:"tradeqty"  xorm:"'TRADEQTY'"`                      // 成交数量
+	Channelbuildtype  int64     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`      // 委托单据类型 0:无 1:建仓 2:平仓
+	Closetype         int64     `json:"closetype"  xorm:"'CLOSETYPE'"`                    // 平仓方式 - 0:无 1:平今 2:平昨
+	Relatedouttradeid int64     `json:"relatedouttradeid"  xorm:"'RELATEDOUTTRADEID'"`    // 关联外部成交单ID
+
+	Asapplyid      int64  `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID
+	Detailtype     int64  `json:"detailtype"  xorm:"'DETAILTYPE'"`                  // 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
+	Spotcontractid int64  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`          // 现货合同ID [1:套利对冲 为合同ID,2:期货换月\3:期货仓位调整时为0]
+	Asno           string `json:"asno"  xorm:"'ASNO'"`                              // 策略编号
+	Asname         string `json:"asname"  xorm:"'ASNAME'"`                          // 策略名称
+	Spotcontractno string `json:"spotcontractno"  xorm:"'SPOTCONTRACTNO'"`          // 现货合同编号
+	Remark         string `json:"remark"  xorm:"'REMARK'"`                          // 备注
+
+	Goodscode      string  `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"`           // 商品代码(合约)
+	Goodsname      string  `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"`           // 商品名称(合约)
+	Agreeunit      float64 `json:"agreeunit"  xorm:"'AGREEUNIT'"`                              // 合约单位
+	Goodunit       string  `json:"goodunit" xorm:"'GOODUNIT'"`                                 // 报价单位
+	Exexchangecode string  `json:"exexchangecode" xorm:"'EXEXCHANGECODE'"`                     // 外部交易所代码
+	Exexchangename string  `json:"exexchangename" xorm:"'EXEXCHANGENAME'"`                     // 外部交易所名称
+	Outgoodscode   string  `json:"outgoodscode" xorm:"'OUTGOODSCODE'"`                         // 商品代码(外部)
+	Decimalplace   int64   `json:"decimalplace"  xorm:"'DECIMALPLACE'"`                        // 报价小数位
+	Goodsgroupid   int64   `json:"goodsgroupid"  xorm:"'GOODSGROUPID'" binding:"required"`     // 商品组ID(品种ID)
+	Goodsgroupname string  `json:"goodsgroupname"  xorm:"'GOODSGROUPNAME'" binding:"required"` // 商品组名称(品种)
 }
 
 // QueryInnerTradeDetail 查询内部成交单信息
@@ -94,58 +75,44 @@ func QueryInnerTradeDetail(c *gin.Context) {
 	// 查询数据
 	engine := db.GetEngine()
 	datas := make([]QueryInnerTradeDetailRsp, 0)
-	sql := fmt.Sprintf(`select
+	sql := fmt.Sprintf(`sselect
 							t.Tradeid,
 							t.Buyorsell,
 							t.Orderid,
-							t.Tradedate,
 							t.Accountid,
 							t.Goodsid,
 							t.Marketid,
 							t.Tradetime,
 							t.Tradeprice,
 							t.Tradeqty,
-							t.Tradeamount,
-							t.Closepl,
-							t.Opencharge,
-							t.Closecharge,
-							t.Tradetype,
 							t.Channelbuildtype,
 							t.Closetype,
-							t.Hedgeflag,
-							t.Openqty,
-							t.Closeqty,
-							t.Status,
-							t.Isreckoned,
-							t.Openfeealgorithm,
-							t.Openchargevalue,
-							t.Closefeealgorithm,
-							t.Closechargevalue,
-							t.Accountcurrencyid,
-							t.Goodscurrencyid,
-							t.Curexchangerate,
-							t.Opencharge2,
-							t.Closecharge2,
-							t.Closepl2,
-							t.Closepl3,
-							t.Closepl4,
-							t.Extenalopenfeealgorithm,
-							t.Extenalopenchargevalue,
-							t.Extenalclosefeealgorithm,
-							t.Extenalclosechargevalue,
-							t.Extenalopencharge,
-							t.Extenalclosecharge,
-							t.Parentaccountid,
 							t.Relatedouttradeid,
 							ast.Asapplyid,
 							ast.Detailtype,
 							ast.Spotcontractid,
-							asd.ContractNo ASContractno,
-							sc.contractno Spotcontractno
+							ast.Remark,
+							asd.Asno,
+							asd.ASName,
+							sc.contractno Spotcontractno,
+							g.Goodscode,
+							g.Goodsname,
+							g.Agreeunit,
+							g.Outgoodscode,
+							g.Decimalplace,
+							e.enumdicname GoodUnit,
+							ee.Exexchangecode,
+							ee.Exexchangename,
+							gg.Goodsgroupid,
+							gg.Goodsgroupname
 						from Hedge_InnerTradeDetail t
 						left join ERMS2_ASTradeDetails ast on t.relatedouttradeid = OutTradeID
 						left join ERMS2_ArbitrageStrategy asd on ast.asapplyid = asd.asapplyid
 						left join ERMS2_SpotContract sc on ast.spotcontractid = sc.spotcontractid
+						left join goods g on t.goodsid = g.goodsid
+						left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
+						left join goodsgroup gg on g.goodsgroupid = gg.goodsgroupid
+						left join ExternalExchange ee on gg.exexchangeid = ee.autoid
 						where t.Accountid = %d`, req.AccountID)
 	if err := engine.SQL(sql).Find(&datas); err != nil {
 		// 查询失败
@@ -158,3 +125,277 @@ func QueryInnerTradeDetail(c *gin.Context) {
 	logger.GetLogger().Infof("QueryInnerTradeDetail successed: %v", datas)
 	appG.Response(http.StatusOK, e.SUCCESS, datas)
 }
+
+// QueryArbitrageStrategyReq 查询期现套利策略表信息请求参数
+type QueryArbitrageStrategyReq struct {
+	AccountID    int `form:"accountid" binding:"required"`
+	GoodsGroupID int `form:"goodsgroupid"`
+}
+
+// QueryArbitrageStrategyRsp 期现套利策略表信息
+type QueryArbitrageStrategyRsp struct {
+	Asapplyid          int64     `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)
+	Asno               string    `json:"asno"  xorm:"'ASNO'"`                              // 策略编号
+	Biztype            int64     `json:"biztype"  xorm:"'BIZTYPE'"`                        // 业务类型 - 1:正向套利 -1:反向套利
+	Userid             int64     `json:"userid"  xorm:"'USERID'"`                          // 所属机构
+	Deliverygoodsid    int64     `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`        // 现货品种ID
+	Goodsgroupid       int64     `json:"goodsgroupid"  xorm:"'GOODSGROUPID'"`              // 期货品种ID
+	Spotquota          float64   `json:"spotquota"  xorm:"'SPOTQUOTA'"`                    // 现货额度
+	Futurequote        float64   `json:"futurequote"  xorm:"'FUTUREQUOTE'"`                // 期货额度
+	Applybasis         float64   `json:"applybasis"  xorm:"'APPLYBASIS'"`                  // 申请基差
+	Strategystatus     int64     `json:"strategystatus"  xorm:"'STRATEGYSTATUS'"`          // 策略状态 - 0:未结束 1:已结束
+	Remark             string    `json:"remark"  xorm:"'REMARK'"`                          // 备注
+	Marketid           int64     `json:"marketid"  xorm:"'MARKETID'"`                      // 市场ID
+	Tradedate          string    `json:"tradedate"  xorm:"'TRADEDATE'"`                    // 交易日(yyyyMMdd)
+	Closetradedate     string    `json:"closetradedate"  xorm:"'CLOSETRADEDATE'"`          // 完结交易日(yyyyMMdd)
+	Usedquota          float64   `json:"usedquota"  xorm:"'USEDQUOTA'"`                    // 已占用资金
+	Futureqty          float64   `json:"futureqty"  xorm:"'FUTUREQTY'"`                    // 期货持仓数量
+	Futureavgprice     float64   `json:"futureavgprice"  xorm:"'FUTUREAVGPRICE'"`          // 期货建仓均价
+	Futurepl           float64   `json:"futurepl"  xorm:"'FUTUREPL'"`                      // 期货总盈亏[结算更新]
+	Pricedspotqty      float64   `json:"pricedspotqty"  xorm:"'PRICEDSPOTQTY'"`            // 已定价现货数量
+	Pricedspotqtynotax float64   `json:"pricedspotqtynotax"  xorm:"'PRICEDSPOTQTYNOTAX'"`  // 已定价现货不含税数量
+	Spotavgprice       float64   `json:"spotavgprice"  xorm:"'SPOTAVGPRICE'"`              // 现货均价
+	Spotpl             float64   `json:"spotpl"  xorm:"'SPOTPL'"`                          // 现货总盈亏[结算更新]
+	Netexposure        float64   `json:"netexposure"  xorm:"'NETEXPOSURE'"`                // 单笔业务头寸净敞口 = 期货持仓数量 + 已定价现货不含税数量
+	Netexposurerate    float64   `json:"netexposurerate"  xorm:"'NETEXPOSURERATE'"`        // 净敞口比例 - 0:未结束 =  (NetExposure/PriceSpotQtyNoTax) ; 已结束为0
+	Totalpl            float64   `json:"totalpl"  xorm:"'TOTALPL'"`                        // 业务合计损益 = FuturePL + SpotPL [结算更新]
+	Openbasis          float64   `json:"openbasis"  xorm:"'OPENBASIS'"`                    // 建仓基差
+	Curbasis           float64   `json:"curbasis"  xorm:"'CURBASIS'"`                      // 当前基差[结算更新]
+	Basischangepl      float64   `json:"basischangepl"  xorm:"'BASISCHANGEPL'"`            // 基差变动损益[结算更新]
+	Netexposurepl      float64   `json:"netexposurepl"  xorm:"'NETEXPOSUREPL'"`            // 净敞口损益 = TotalPL - BasisChangePL[结算更新]
+	Spotusedquota      float64   `json:"spotusedquota"  xorm:"'SPOTUSEDQUOTA'"`            // 现货占用资金
+	Futureopenqty      float64   `json:"futureopenqty"  xorm:"'FUTUREOPENQTY'"`            // 期货开仓数量
+	Futureopenamount   float64   `json:"futureopenamount"  xorm:"'FUTUREOPENAMOUNT'"`      // 期货开仓金额
+	Futurecloseqty     float64   `json:"futurecloseqty"  xorm:"'FUTURECLOSEQTY'"`          // 期货平仓数量
+	Futurecloseamount  float64   `json:"futurecloseamount"  xorm:"'FUTURECLOSEAMOUNT'"`    // 期货平仓金额
+	Spotbuyamount      float64   `json:"spotbuyamount"  xorm:"'SPOTBUYAMOUNT'"`            // 现货采购金额
+	Spotbuyqty         float64   `json:"spotbuyqty"  xorm:"'SPOTBUYQTY'"`                  // 现货采购数量
+	Spotsellamount     float64   `json:"spotsellamount"  xorm:"'SPOTSELLAMOUNT'"`          // 现货销售金额
+	Spotsellqty        float64   `json:"spotsellqty"  xorm:"'SPOTSELLQTY'"`                // 现货销售数量
+	Updatetime         time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                  // 更新时间
+	Asname             string    `json:"asname"  xorm:"'ASNAME'"`                          // 策略名称
+}
+
+// QueryArbitrageStrategy 查询期现套利策略表信息(指定资金账户、未结束的)
+// @Summary 查询期现套利策略表信息(指定资金账户、未结束的)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountid query int true "资金账户"
+// @Param goodsgroupid query string false "商品组ID(品种ID)"
+// @Success 200 {object} QueryArbitrageStrategyRsp
+// @Failure 500 {object} app.Response
+// @Router /Erms2/QueryArbitrageStrategy [get]
+// @Tags 风险管理
+func QueryArbitrageStrategy(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryArbitrageStrategyReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryArbitrageStrategy failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 查询数据
+	engine := db.GetEngine()
+	datas := make([]QueryArbitrageStrategyRsp, 0)
+	sql := fmt.Sprintf(`select
+							t.ASApplyID,
+							t.ASNo,
+							t.ASName,
+							t.BizType,
+							t.UserID,
+							t.DeliveryGoodsID,
+							t.GoodsGroupID,
+							t.SpotQuota,
+							t.FutureQuote,
+							t.ApplyBasis,
+							t.StrategyStatus,
+							t.Remark,
+							t.MarketID,
+							t.TradeDate,
+							t.CloseTradeDate,
+							t.UsedQuota,
+							t.FutureQty,
+							t.FutureAvgPrice,
+							t.FuturePL,
+							t.PricedSpotQty,
+							t.PricedSpotQtyNoTax,
+							t.SpotAvgPrice,
+							t.SpotPL,
+							t.NetExposure,
+							t.NetExposureRate,
+							t.TotalPL,
+							t.OpenBasis,
+							t.CurBasis,
+							t.BasisChangePL,
+							t.NetExposurePL,
+							t.SpotUsedQuota,
+							t.FutureOpenQty,
+							t.FutureOpenAmount,
+							t.FutureCloseQty,
+							t.FutureCloseAmount,
+							t.SpotBuyAmount,
+							t.SpotBuyQty,
+							t.SpotSellAmount,
+							t.SpotSellQty,
+							t.UpdateTime
+						from ERMS2_ArbitrageStrategy t
+						left join ERMS2_ASAccount a on t.asapplyid = a.asapplyid
+						where t.StrategyStatus = 0 and a.accountid = %d`, req.AccountID)
+	if req.GoodsGroupID > 0 {
+		sql += fmt.Sprintf(" and t.GoodsGroupID = %d", req.GoodsGroupID)
+	}
+	if err := engine.SQL(sql).Find(&datas); err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryArbitrageStrategy failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功
+	logger.GetLogger().Infof("QueryArbitrageStrategy successed: %v", datas)
+	appG.Response(http.StatusOK, e.SUCCESS, datas)
+}
+
+// QuerySpotContractReq 查询现货合同表信息请求参数
+type QuerySpotContractReq struct {
+	AsApplyID      int `form:"asapplyid" binding:"required"`
+	SpotContractID int `form:"spotcontractid"`
+}
+
+// QuerySpotContractRsp 现货合同表
+type QuerySpotContractRsp struct {
+	Spotcontractid     int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"` // 现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)
+	Tradedate          string    `json:"tradedate"  xorm:"'TRADEDATE'"`                              // 交易日(yyyyMMdd)
+	Contractno         string    `json:"contractno"  xorm:"'CONTRACTNO'"`                            // 现货合同编号
+	Contracttype       int64     `json:"contracttype"  xorm:"'CONTRACTTYPE'"`                        // 现货合同类型 - 1:采购合同 -1:销售合同
+	Areauserid         int64     `json:"areauserid"  xorm:"'AREAUSERID'"`                            // 所属机构
+	Userid             int64     `json:"userid"  xorm:"'USERID'"`                                    // 业务员用户ID
+	Accountid          int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                              // 资金账户ID
+	Customeruserid     int64     `json:"customeruserid"  xorm:"'CUSTOMERUSERID'"`                    // 客户ID
+	Customeraccountid  int64     `json:"customeraccountid"  xorm:"'CUSTOMERACCOUNTID'"`              // 客户资金账户ID
+	Signdate           time.Time `json:"signdate"  xorm:"'SIGNDATE'"`                                // 签订日期
+	Lastdate           time.Time `json:"lastdate"  xorm:"'LASTDATE'"`                                // 交货时间
+	Contractattachment string    `json:"contractattachment"  xorm:"'CONTRACTATTACHMENT'"`            // 合同附件
+	Producttype        int64     `json:"producttype"  xorm:"'PRODUCTTYPE'"`                          // 产品类型 - 1:标准仓单 2:等标 3:非标
+	Deliverygoodsid    int64     `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`                  // 现货品种ID
+	Deliverygoodsdesc  string    `json:"deliverygoodsdesc"  xorm:"'DELIVERYGOODSDESC'"`              // 品种说明
+	Warehouseid        int64     `json:"warehouseid"  xorm:"'WAREHOUSEID'"`                          // 仓库ID
+	Wrfactortypeid     int64     `json:"wrfactortypeid"  xorm:"'WRFACTORTYPEID'"`                    // 仓单要素类型ID
+	Contractqtychar    string    `json:"contractqtychar"  xorm:"'CONTRACTQTYCHAR'"`                  // 合同数量\已订价数量 (用于显示)
+	Spotprice          float64   `json:"spotprice"  xorm:"'SPOTPRICE'"`                              // 价格
+	Contractamount     float64   `json:"contractamount"  xorm:"'CONTRACTAMOUNT'"`                    // 合同金额
+	Marketid           int64     `json:"marketid"  xorm:"'MARKETID'"`                                // 市场ID
+	Remark             string    `json:"remark"  xorm:"'REMARK'"`                                    // 备注
+	Handlestatus       int64     `json:"handlestatus"  xorm:"'HANDLESTATUS'"`                        // 处理状态
+	Contractqty        float64   `json:"contractqty"  xorm:"'CONTRACTQTY'"`                          // 合同数量(数值) (用于计算)
+	Positionqty        int64     `json:"positionqty"  xorm:"'POSITIONQTY'"`                          // 头寸数量 - 合同数量去小数部分
+	Paystatus          int64     `json:"paystatus"  xorm:"'PAYSTATUS'"`                              // 收付款状态 - 0:未支付 1:已收款 2:已付款
+	Payremark          string    `json:"payremark"  xorm:"'PAYREMARK'"`                              // 收付款备注
+	Paydatetime        time.Time `json:"paydatetime"  xorm:"'PAYDATETIME'"`                          // 收付款更新时间
+	Invoicestatus      int64     `json:"invoicestatus"  xorm:"'INVOICESTATUS'"`                      // 开收票状态 - 0:未开票 1:已开票
+	Invoiceremark      string    `json:"invoiceremark"  xorm:"'INVOICEREMARK'"`                      // 发票备注
+	Invoiceatt         string    `json:"invoiceatt"  xorm:"'INVOICEATT'"`                            // 发票附件
+	Invoicedatetime    time.Time `json:"invoicedatetime"  xorm:"'INVOICEDATETIME'"`                  // 开收票更新时间
+	Spotstatus         int64     `json:"spotstatus"  xorm:"'SPOTSTATUS'"`                            // 收发货状态 - 0:未交收 1:已发货 2:已发货
+	Spotremark         string    `json:"spotremark"  xorm:"'SPOTREMARK'"`                            // 收发货备注
+	Spotdatetime       time.Time `json:"spotdatetime"  xorm:"'SPOTDATETIME'"`                        // 收发货更新时间
+	Relatedqty         float64   `json:"relatedqty"  xorm:"'RELATEDQTY'"`                            // 已关联数量
+	Contractstatus     int64     `json:"contractstatus"  xorm:"'CONTRACTSTATUS'"`                    // 合同状态 - 0:未结束 1:已结束
+	Closeremark        string    `json:"closeremark"  xorm:"'CLOSEREMARK'"`                          // 结束备注
+	Closetradedate     string    `json:"closetradedate"  xorm:"'CLOSETRADEDATE'"`                    // 完结交易日(yyyyMMdd)
+	Relatedstatus      int64     `json:"relatedstatus"  xorm:"'RELATEDSTATUS'"`                      // 关联完结状态 - 0:未结束 1:已结束
+	Wrstandardid       int64     `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`                        // 仓单标准ID(SEQ_WRSTANDARD)
+	Invoiceopentime    time.Time `json:"invoiceopentime"  xorm:"'INVOICEOPENTIME'"`                  // 开票时间
+	Closetype          int64     `json:"closetype"  xorm:"'CLOSETYPE'"`                              // 终止类型 - 1:违约 2:提前终止
+	Closedate          time.Time `json:"closedate"  xorm:"'CLOSEDATE'"`                              // 终止日期
+}
+
+// QuerySpotContract 查询现货合同表信息(指定策略ID、未结束的)
+// @Summary 查询现货合同表信息(指定策略ID、未结束的)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param asapplyid query int true "策略申请ID"
+// @Param spotcontractid query int false "现货合同ID"
+// @Success 200 {object} QuerySpotContractRsp
+// @Failure 500 {object} app.Response
+// @Router /Erms2/QuerySpotContract [get]
+// @Tags 风险管理
+func QuerySpotContract(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QuerySpotContractReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QuerySpotContract failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 查询数据
+	engine := db.GetEngine()
+	datas := make([]QuerySpotContractRsp, 0)
+	sql := fmt.Sprintf(`select
+							t.SpotContractID,
+							t.TradeDate,
+							t.ContractNo,
+							t.ContractType,
+							t.AreaUserID,
+							t.UserID,
+							t.AccountID,
+							t.CustomerUserID,
+							t.CustomerAccountID,
+							t.SignDate,
+							t.LastDate,
+							t.ContractAttachment,
+							t.ProductType,
+							t.DeliveryGoodsID,
+							t.DeliveryGoodsDesc,
+							t.WarehouseID,
+							t.WRStandardID,
+							t.WRFactorTypeID,
+							t.ContractQtyChar,
+							t.SpotPrice,
+							t.ContractAmount,
+							t.MarketID,
+							t.Remark,
+							t.HandleStatus,
+							t.ContractQty,
+							t.PositionQty,
+							t.PayStatus,
+							t.PayRemark,
+							t.PayDateTime,
+							t.InvoiceStatus,
+							t.InvoiceRemark,
+							t.InvoiceAtt,
+							t.InvoiceOpenTime,
+							t.InvoiceDateTime,
+							t.SpotStatus,
+							t.SpotRemark,
+							t.SpotDateTime,
+							t.RelatedQty,
+							t.ContractStatus,
+							t.CloseType,
+							t.CloseDate,
+							t.CloseRemark,
+							t.CloseTradeDate,
+							t.RelatedStatus
+						from ERMS2_SpotContract t
+						left join ERMS2_ASSpotDetail a on t.spotcontractid = a.spotcontractid
+						where t.ContractStatus = 0 and a.asapplyid = %d`, req.AsApplyID)
+	if req.SpotContractID > 0 {
+		sql += fmt.Sprintf(" and a.spotcontractid = %d", req.SpotContractID)
+	}
+	if err := engine.SQL(sql).Find(&datas); err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QuerySpotContract failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功
+	logger.GetLogger().Infof("QuerySpotContract successed: %v", datas)
+	appG.Response(http.StatusOK, e.SUCCESS, datas)
+}

+ 469 - 95
docs/docs.go

@@ -419,6 +419,51 @@ var doc = `{
                 }
             }
         },
+        "/Erms2/QueryArbitrageStrategy": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理"
+                ],
+                "summary": "查询期现套利策略表信息(指定资金账户、未结束的)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "商品组ID(品种ID)",
+                        "name": "goodsgroupid",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/erms2.QueryArbitrageStrategyRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryInnerTradeDetail": {
             "get": {
                 "security": [
@@ -458,6 +503,51 @@ var doc = `{
                 }
             }
         },
+        "/Erms2/QuerySpotContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理"
+                ],
+                "summary": "查询现货合同表信息(指定策略ID、未结束的)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "策略申请ID",
+                        "name": "asapplyid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "现货合同ID",
+                        "name": "spotcontractid",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/erms2.QuerySpotContractRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [
@@ -1449,162 +1539,278 @@ var doc = `{
                 }
             }
         },
-        "erms2.QueryInnerTradeDetailRsp": {
+        "erms2.QueryArbitrageStrategyRsp": {
             "type": "object",
             "required": [
-                "asapplyid",
-                "buyorsell",
-                "tradeid"
+                "asapplyid"
             ],
             "properties": {
-                "accountcurrencyid": {
-                    "description": "账户币种ID",
-                    "type": "integer"
-                },
-                "accountid": {
-                    "description": "账号ID",
-                    "type": "integer"
+                "applybasis": {
+                    "description": "申请基差",
+                    "type": "number"
                 },
                 "asapplyid": {
-                    "description": "策略申请ID",
+                    "description": "策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)",
                     "type": "integer"
                 },
-                "ascontractno": {
+                "asname": {
+                    "description": "策略名称",
+                    "type": "string"
+                },
+                "asno": {
                     "description": "策略编号",
                     "type": "string"
                 },
-                "buyorsell": {
-                    "description": "方向 - 0:买 1:卖",
+                "basischangepl": {
+                    "description": "基差变动损益[结算更新]",
+                    "type": "number"
+                },
+                "biztype": {
+                    "description": "业务类型 - 1:正向套利 -1:反向套利",
                     "type": "integer"
                 },
-                "channelbuildtype": {
-                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
+                "closetradedate": {
+                    "description": "完结交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "curbasis": {
+                    "description": "当前基差[结算更新]",
+                    "type": "number"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
                     "type": "integer"
                 },
-                "closecharge": {
-                    "description": "平仓手续费(账户)",
+                "futureavgprice": {
+                    "description": "期货建仓均价",
                     "type": "number"
                 },
-                "closecharge2": {
-                    "description": "平仓手续费(商品)",
+                "futurecloseamount": {
+                    "description": "期货平仓金额",
                     "type": "number"
                 },
-                "closechargevalue": {
-                    "description": "平仓手续费设置值",
+                "futurecloseqty": {
+                    "description": "期货平仓数量",
                     "type": "number"
                 },
-                "closefeealgorithm": {
-                    "description": "平仓手续费收取方式 1:比率  2:固定",
-                    "type": "integer"
+                "futureopenamount": {
+                    "description": "期货开仓金额",
+                    "type": "number"
                 },
-                "closepl": {
-                    "description": "平仓盈亏(账户)",
+                "futureopenqty": {
+                    "description": "期货开仓数量",
                     "type": "number"
                 },
-                "closepl2": {
-                    "description": "平仓盈亏(商品)",
+                "futurepl": {
+                    "description": "期货总盈亏[结算更新]",
                     "type": "number"
                 },
-                "closepl3": {
-                    "description": "平仓盈亏(账户)(逐笔)",
+                "futureqty": {
+                    "description": "期货持仓数量",
                     "type": "number"
                 },
-                "closepl4": {
-                    "description": "平仓盈亏(商品)(逐笔)",
+                "futurequote": {
+                    "description": "期货额度",
                     "type": "number"
                 },
-                "closeqty": {
-                    "description": "平仓数量(先建后平操作 需要记录)",
+                "goodsgroupid": {
+                    "description": "期货品种ID",
                     "type": "integer"
                 },
-                "closetype": {
-                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
+                "marketid": {
+                    "description": "市场ID",
                     "type": "integer"
                 },
-                "curexchangerate": {
-                    "description": "当前汇率",
+                "netexposure": {
+                    "description": "单笔业务头寸净敞口 = 期货持仓数量 + 已定价现货不含税数量",
                     "type": "number"
                 },
-                "detailtype": {
-                    "description": "明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整",
-                    "type": "integer"
+                "netexposurepl": {
+                    "description": "净敞口损益 = TotalPL - BasisChangePL[结算更新]",
+                    "type": "number"
                 },
-                "extenalclosecharge": {
-                    "description": "平仓手续费(商品)(外部)",
+                "netexposurerate": {
+                    "description": "净敞口比例 - 0:未结束 =  (NetExposure/PriceSpotQtyNoTax) ; 已结束为0",
                     "type": "number"
                 },
-                "extenalclosechargevalue": {
-                    "description": "平仓手续费设置值",
+                "openbasis": {
+                    "description": "建仓基差",
                     "type": "number"
                 },
-                "extenalclosefeealgorithm": {
-                    "description": "平仓手续费收取方式 1:比率  2:固定",
+                "pricedspotqty": {
+                    "description": "已定价现货数量",
+                    "type": "number"
+                },
+                "pricedspotqtynotax": {
+                    "description": "已定价现货不含税数量",
+                    "type": "number"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "spotavgprice": {
+                    "description": "现货均价",
+                    "type": "number"
+                },
+                "spotbuyamount": {
+                    "description": "现货采购金额",
+                    "type": "number"
+                },
+                "spotbuyqty": {
+                    "description": "现货采购数量",
+                    "type": "number"
+                },
+                "spotpl": {
+                    "description": "现货总盈亏[结算更新]",
+                    "type": "number"
+                },
+                "spotquota": {
+                    "description": "现货额度",
+                    "type": "number"
+                },
+                "spotsellamount": {
+                    "description": "现货销售金额",
+                    "type": "number"
+                },
+                "spotsellqty": {
+                    "description": "现货销售数量",
+                    "type": "number"
+                },
+                "spotusedquota": {
+                    "description": "现货占用资金",
+                    "type": "number"
+                },
+                "strategystatus": {
+                    "description": "策略状态 - 0:未结束 1:已结束",
                     "type": "integer"
                 },
-                "extenalopencharge": {
-                    "description": "建仓手续费(商品)(外部)",
+                "totalpl": {
+                    "description": "业务合计损益 = FuturePL + SpotPL [结算更新]",
                     "type": "number"
                 },
-                "extenalopenchargevalue": {
-                    "description": "建仓手续费设置值",
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                },
+                "usedquota": {
+                    "description": "已占用资金",
                     "type": "number"
                 },
-                "extenalopenfeealgorithm": {
-                    "description": "建仓手续费收取方式(外部配置) 1:比率  2:固定",
+                "userid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                }
+            }
+        },
+        "erms2.QueryInnerTradeDetailRsp": {
+            "type": "object",
+            "required": [
+                "asapplyid",
+                "buyorsell",
+                "goodscode",
+                "goodsgroupid",
+                "goodsgroupname",
+                "goodsname",
+                "tradeid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
                     "type": "integer"
                 },
-                "goodscurrencyid": {
-                    "description": "商品币种ID",
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "asapplyid": {
+                    "description": "策略申请ID",
                     "type": "integer"
                 },
-                "goodsid": {
-                    "description": "商品ID",
+                "asname": {
+                    "description": "策略名称",
+                    "type": "string"
+                },
+                "asno": {
+                    "description": "策略编号",
+                    "type": "string"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
                     "type": "integer"
                 },
-                "hedgeflag": {
-                    "description": "投机套保标志 - 0:无 1:投机 2:套保 3:套利",
+                "channelbuildtype": {
+                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
                     "type": "integer"
                 },
-                "isreckoned": {
-                    "description": "是否结算 - 0:未结算 1:已结算",
+                "closetype": {
+                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
                     "type": "integer"
                 },
-                "marketid": {
-                    "description": "市场ID",
+                "decimalplace": {
+                    "description": "报价小数位",
                     "type": "integer"
                 },
-                "opencharge": {
-                    "description": "建仓手续费(账户)",
-                    "type": "number"
+                "detailtype": {
+                    "description": "明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整",
+                    "type": "integer"
                 },
-                "opencharge2": {
-                    "description": "建仓手续费(商品)",
-                    "type": "number"
+                "exexchangecode": {
+                    "description": "外部交易所代码",
+                    "type": "string"
                 },
-                "openchargevalue": {
-                    "description": "建仓手续费设置值",
-                    "type": "number"
+                "exexchangename": {
+                    "description": "外部交易所名称",
+                    "type": "string"
                 },
-                "openfeealgorithm": {
-                    "description": "建仓手续费收取方式  1:比率  2:固定",
+                "goodscode": {
+                    "description": "商品代码(合约)",
+                    "type": "string"
+                },
+                "goodsgroupid": {
+                    "description": "商品组ID(品种ID)",
                     "type": "integer"
                 },
-                "openqty": {
-                    "description": "开仓数量(先建后平操作 需要记录)",
+                "goodsgroupname": {
+                    "description": "商品组名称(品种)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称(合约)",
+                    "type": "string"
+                },
+                "goodunit": {
+                    "description": "报价单位",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
                     "type": "integer"
                 },
                 "orderid": {
                     "description": "委托单号",
                     "type": "integer"
                 },
-                "parentaccountid": {
-                    "description": "所属母账户",
-                    "type": "integer"
+                "outgoodscode": {
+                    "description": "商品代码(外部)",
+                    "type": "string"
                 },
                 "relatedouttradeid": {
                     "description": "关联外部成交单ID",
                     "type": "integer"
                 },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
                 "spotcontractid": {
                     "description": "现货合同ID [1:套利对冲 为合同ID,2:期货换月\\3:期货仓位调整时为0]",
                     "type": "integer"
@@ -1613,18 +1819,6 @@ var doc = `{
                     "description": "现货合同编号",
                     "type": "string"
                 },
-                "status": {
-                    "description": "处理状态 - 1:待处理 2:已处理 3:处理失败",
-                    "type": "integer"
-                },
-                "tradeamount": {
-                    "description": "成交金额(账户)",
-                    "type": "number"
-                },
-                "tradedate": {
-                    "description": "交易日(yyyyMMdd)",
-                    "type": "string"
-                },
                 "tradeid": {
                     "description": "成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
                     "type": "integer"
@@ -1640,9 +1834,189 @@ var doc = `{
                 "tradetime": {
                     "description": "成交时间",
                     "type": "string"
+                }
+            }
+        },
+        "erms2.QuerySpotContractRsp": {
+            "type": "object",
+            "required": [
+                "spotcontractid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "资金账户ID",
+                    "type": "integer"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "closedate": {
+                    "description": "终止日期",
+                    "type": "string"
+                },
+                "closeremark": {
+                    "description": "结束备注",
+                    "type": "string"
+                },
+                "closetradedate": {
+                    "description": "完结交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "closetype": {
+                    "description": "终止类型 - 1:违约 2:提前终止",
+                    "type": "integer"
+                },
+                "contractamount": {
+                    "description": "合同金额",
+                    "type": "number"
+                },
+                "contractattachment": {
+                    "description": "合同附件",
+                    "type": "string"
+                },
+                "contractno": {
+                    "description": "现货合同编号",
+                    "type": "string"
+                },
+                "contractqty": {
+                    "description": "合同数量(数值) (用于计算)",
+                    "type": "number"
+                },
+                "contractqtychar": {
+                    "description": "合同数量\\已订价数量 (用于显示)",
+                    "type": "string"
+                },
+                "contractstatus": {
+                    "description": "合同状态 - 0:未结束 1:已结束",
+                    "type": "integer"
+                },
+                "contracttype": {
+                    "description": "现货合同类型 - 1:采购合同 -1:销售合同",
+                    "type": "integer"
+                },
+                "customeraccountid": {
+                    "description": "客户资金账户ID",
+                    "type": "integer"
+                },
+                "customeruserid": {
+                    "description": "客户ID",
+                    "type": "integer"
+                },
+                "deliverygoodsdesc": {
+                    "description": "品种说明",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "handlestatus": {
+                    "description": "处理状态",
+                    "type": "integer"
+                },
+                "invoiceatt": {
+                    "description": "发票附件",
+                    "type": "string"
+                },
+                "invoicedatetime": {
+                    "description": "开收票更新时间",
+                    "type": "string"
+                },
+                "invoiceopentime": {
+                    "description": "开票时间",
+                    "type": "string"
+                },
+                "invoiceremark": {
+                    "description": "发票备注",
+                    "type": "string"
+                },
+                "invoicestatus": {
+                    "description": "开收票状态 - 0:未开票 1:已开票",
+                    "type": "integer"
+                },
+                "lastdate": {
+                    "description": "交货时间",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
                 },
-                "tradetype": {
-                    "description": "成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交",
+                "paydatetime": {
+                    "description": "收付款更新时间",
+                    "type": "string"
+                },
+                "payremark": {
+                    "description": "收付款备注",
+                    "type": "string"
+                },
+                "paystatus": {
+                    "description": "收付款状态 - 0:未支付 1:已收款 2:已付款",
+                    "type": "integer"
+                },
+                "positionqty": {
+                    "description": "头寸数量 - 合同数量去小数部分",
+                    "type": "integer"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "relatedqty": {
+                    "description": "已关联数量",
+                    "type": "number"
+                },
+                "relatedstatus": {
+                    "description": "关联完结状态 - 0:未结束 1:已结束",
+                    "type": "integer"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "signdate": {
+                    "description": "签订日期",
+                    "type": "string"
+                },
+                "spotcontractid": {
+                    "description": "现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "spotdatetime": {
+                    "description": "收发货更新时间",
+                    "type": "string"
+                },
+                "spotprice": {
+                    "description": "价格",
+                    "type": "number"
+                },
+                "spotremark": {
+                    "description": "收发货备注",
+                    "type": "string"
+                },
+                "spotstatus": {
+                    "description": "收发货状态 - 0:未交收 1:已发货 2:已发货",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "业务员用户ID",
+                    "type": "integer"
+                },
+                "warehouseid": {
+                    "description": "仓库ID",
+                    "type": "integer"
+                },
+                "wrfactortypeid": {
+                    "description": "仓单要素类型ID",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "仓单标准ID(SEQ_WRSTANDARD)",
                     "type": "integer"
                 }
             }

+ 469 - 95
docs/swagger.json

@@ -403,6 +403,51 @@
                 }
             }
         },
+        "/Erms2/QueryArbitrageStrategy": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理"
+                ],
+                "summary": "查询期现套利策略表信息(指定资金账户、未结束的)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "商品组ID(品种ID)",
+                        "name": "goodsgroupid",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/erms2.QueryArbitrageStrategyRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryInnerTradeDetail": {
             "get": {
                 "security": [
@@ -442,6 +487,51 @@
                 }
             }
         },
+        "/Erms2/QuerySpotContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理"
+                ],
+                "summary": "查询现货合同表信息(指定策略ID、未结束的)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "策略申请ID",
+                        "name": "asapplyid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "现货合同ID",
+                        "name": "spotcontractid",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/erms2.QuerySpotContractRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [
@@ -1433,162 +1523,278 @@
                 }
             }
         },
-        "erms2.QueryInnerTradeDetailRsp": {
+        "erms2.QueryArbitrageStrategyRsp": {
             "type": "object",
             "required": [
-                "asapplyid",
-                "buyorsell",
-                "tradeid"
+                "asapplyid"
             ],
             "properties": {
-                "accountcurrencyid": {
-                    "description": "账户币种ID",
-                    "type": "integer"
-                },
-                "accountid": {
-                    "description": "账号ID",
-                    "type": "integer"
+                "applybasis": {
+                    "description": "申请基差",
+                    "type": "number"
                 },
                 "asapplyid": {
-                    "description": "策略申请ID",
+                    "description": "策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)",
                     "type": "integer"
                 },
-                "ascontractno": {
+                "asname": {
+                    "description": "策略名称",
+                    "type": "string"
+                },
+                "asno": {
                     "description": "策略编号",
                     "type": "string"
                 },
-                "buyorsell": {
-                    "description": "方向 - 0:买 1:卖",
+                "basischangepl": {
+                    "description": "基差变动损益[结算更新]",
+                    "type": "number"
+                },
+                "biztype": {
+                    "description": "业务类型 - 1:正向套利 -1:反向套利",
                     "type": "integer"
                 },
-                "channelbuildtype": {
-                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
+                "closetradedate": {
+                    "description": "完结交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "curbasis": {
+                    "description": "当前基差[结算更新]",
+                    "type": "number"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
                     "type": "integer"
                 },
-                "closecharge": {
-                    "description": "平仓手续费(账户)",
+                "futureavgprice": {
+                    "description": "期货建仓均价",
                     "type": "number"
                 },
-                "closecharge2": {
-                    "description": "平仓手续费(商品)",
+                "futurecloseamount": {
+                    "description": "期货平仓金额",
                     "type": "number"
                 },
-                "closechargevalue": {
-                    "description": "平仓手续费设置值",
+                "futurecloseqty": {
+                    "description": "期货平仓数量",
                     "type": "number"
                 },
-                "closefeealgorithm": {
-                    "description": "平仓手续费收取方式 1:比率  2:固定",
-                    "type": "integer"
+                "futureopenamount": {
+                    "description": "期货开仓金额",
+                    "type": "number"
                 },
-                "closepl": {
-                    "description": "平仓盈亏(账户)",
+                "futureopenqty": {
+                    "description": "期货开仓数量",
                     "type": "number"
                 },
-                "closepl2": {
-                    "description": "平仓盈亏(商品)",
+                "futurepl": {
+                    "description": "期货总盈亏[结算更新]",
                     "type": "number"
                 },
-                "closepl3": {
-                    "description": "平仓盈亏(账户)(逐笔)",
+                "futureqty": {
+                    "description": "期货持仓数量",
                     "type": "number"
                 },
-                "closepl4": {
-                    "description": "平仓盈亏(商品)(逐笔)",
+                "futurequote": {
+                    "description": "期货额度",
                     "type": "number"
                 },
-                "closeqty": {
-                    "description": "平仓数量(先建后平操作 需要记录)",
+                "goodsgroupid": {
+                    "description": "期货品种ID",
                     "type": "integer"
                 },
-                "closetype": {
-                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
+                "marketid": {
+                    "description": "市场ID",
                     "type": "integer"
                 },
-                "curexchangerate": {
-                    "description": "当前汇率",
+                "netexposure": {
+                    "description": "单笔业务头寸净敞口 = 期货持仓数量 + 已定价现货不含税数量",
                     "type": "number"
                 },
-                "detailtype": {
-                    "description": "明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整",
-                    "type": "integer"
+                "netexposurepl": {
+                    "description": "净敞口损益 = TotalPL - BasisChangePL[结算更新]",
+                    "type": "number"
                 },
-                "extenalclosecharge": {
-                    "description": "平仓手续费(商品)(外部)",
+                "netexposurerate": {
+                    "description": "净敞口比例 - 0:未结束 =  (NetExposure/PriceSpotQtyNoTax) ; 已结束为0",
                     "type": "number"
                 },
-                "extenalclosechargevalue": {
-                    "description": "平仓手续费设置值",
+                "openbasis": {
+                    "description": "建仓基差",
                     "type": "number"
                 },
-                "extenalclosefeealgorithm": {
-                    "description": "平仓手续费收取方式 1:比率  2:固定",
+                "pricedspotqty": {
+                    "description": "已定价现货数量",
+                    "type": "number"
+                },
+                "pricedspotqtynotax": {
+                    "description": "已定价现货不含税数量",
+                    "type": "number"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "spotavgprice": {
+                    "description": "现货均价",
+                    "type": "number"
+                },
+                "spotbuyamount": {
+                    "description": "现货采购金额",
+                    "type": "number"
+                },
+                "spotbuyqty": {
+                    "description": "现货采购数量",
+                    "type": "number"
+                },
+                "spotpl": {
+                    "description": "现货总盈亏[结算更新]",
+                    "type": "number"
+                },
+                "spotquota": {
+                    "description": "现货额度",
+                    "type": "number"
+                },
+                "spotsellamount": {
+                    "description": "现货销售金额",
+                    "type": "number"
+                },
+                "spotsellqty": {
+                    "description": "现货销售数量",
+                    "type": "number"
+                },
+                "spotusedquota": {
+                    "description": "现货占用资金",
+                    "type": "number"
+                },
+                "strategystatus": {
+                    "description": "策略状态 - 0:未结束 1:已结束",
                     "type": "integer"
                 },
-                "extenalopencharge": {
-                    "description": "建仓手续费(商品)(外部)",
+                "totalpl": {
+                    "description": "业务合计损益 = FuturePL + SpotPL [结算更新]",
                     "type": "number"
                 },
-                "extenalopenchargevalue": {
-                    "description": "建仓手续费设置值",
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                },
+                "usedquota": {
+                    "description": "已占用资金",
                     "type": "number"
                 },
-                "extenalopenfeealgorithm": {
-                    "description": "建仓手续费收取方式(外部配置) 1:比率  2:固定",
+                "userid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                }
+            }
+        },
+        "erms2.QueryInnerTradeDetailRsp": {
+            "type": "object",
+            "required": [
+                "asapplyid",
+                "buyorsell",
+                "goodscode",
+                "goodsgroupid",
+                "goodsgroupname",
+                "goodsname",
+                "tradeid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
                     "type": "integer"
                 },
-                "goodscurrencyid": {
-                    "description": "商品币种ID",
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "asapplyid": {
+                    "description": "策略申请ID",
                     "type": "integer"
                 },
-                "goodsid": {
-                    "description": "商品ID",
+                "asname": {
+                    "description": "策略名称",
+                    "type": "string"
+                },
+                "asno": {
+                    "description": "策略编号",
+                    "type": "string"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
                     "type": "integer"
                 },
-                "hedgeflag": {
-                    "description": "投机套保标志 - 0:无 1:投机 2:套保 3:套利",
+                "channelbuildtype": {
+                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
                     "type": "integer"
                 },
-                "isreckoned": {
-                    "description": "是否结算 - 0:未结算 1:已结算",
+                "closetype": {
+                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
                     "type": "integer"
                 },
-                "marketid": {
-                    "description": "市场ID",
+                "decimalplace": {
+                    "description": "报价小数位",
                     "type": "integer"
                 },
-                "opencharge": {
-                    "description": "建仓手续费(账户)",
-                    "type": "number"
+                "detailtype": {
+                    "description": "明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整",
+                    "type": "integer"
                 },
-                "opencharge2": {
-                    "description": "建仓手续费(商品)",
-                    "type": "number"
+                "exexchangecode": {
+                    "description": "外部交易所代码",
+                    "type": "string"
                 },
-                "openchargevalue": {
-                    "description": "建仓手续费设置值",
-                    "type": "number"
+                "exexchangename": {
+                    "description": "外部交易所名称",
+                    "type": "string"
                 },
-                "openfeealgorithm": {
-                    "description": "建仓手续费收取方式  1:比率  2:固定",
+                "goodscode": {
+                    "description": "商品代码(合约)",
+                    "type": "string"
+                },
+                "goodsgroupid": {
+                    "description": "商品组ID(品种ID)",
                     "type": "integer"
                 },
-                "openqty": {
-                    "description": "开仓数量(先建后平操作 需要记录)",
+                "goodsgroupname": {
+                    "description": "商品组名称(品种)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称(合约)",
+                    "type": "string"
+                },
+                "goodunit": {
+                    "description": "报价单位",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
                     "type": "integer"
                 },
                 "orderid": {
                     "description": "委托单号",
                     "type": "integer"
                 },
-                "parentaccountid": {
-                    "description": "所属母账户",
-                    "type": "integer"
+                "outgoodscode": {
+                    "description": "商品代码(外部)",
+                    "type": "string"
                 },
                 "relatedouttradeid": {
                     "description": "关联外部成交单ID",
                     "type": "integer"
                 },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
                 "spotcontractid": {
                     "description": "现货合同ID [1:套利对冲 为合同ID,2:期货换月\\3:期货仓位调整时为0]",
                     "type": "integer"
@@ -1597,18 +1803,6 @@
                     "description": "现货合同编号",
                     "type": "string"
                 },
-                "status": {
-                    "description": "处理状态 - 1:待处理 2:已处理 3:处理失败",
-                    "type": "integer"
-                },
-                "tradeamount": {
-                    "description": "成交金额(账户)",
-                    "type": "number"
-                },
-                "tradedate": {
-                    "description": "交易日(yyyyMMdd)",
-                    "type": "string"
-                },
                 "tradeid": {
                     "description": "成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
                     "type": "integer"
@@ -1624,9 +1818,189 @@
                 "tradetime": {
                     "description": "成交时间",
                     "type": "string"
+                }
+            }
+        },
+        "erms2.QuerySpotContractRsp": {
+            "type": "object",
+            "required": [
+                "spotcontractid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "资金账户ID",
+                    "type": "integer"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "closedate": {
+                    "description": "终止日期",
+                    "type": "string"
+                },
+                "closeremark": {
+                    "description": "结束备注",
+                    "type": "string"
+                },
+                "closetradedate": {
+                    "description": "完结交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "closetype": {
+                    "description": "终止类型 - 1:违约 2:提前终止",
+                    "type": "integer"
+                },
+                "contractamount": {
+                    "description": "合同金额",
+                    "type": "number"
+                },
+                "contractattachment": {
+                    "description": "合同附件",
+                    "type": "string"
+                },
+                "contractno": {
+                    "description": "现货合同编号",
+                    "type": "string"
+                },
+                "contractqty": {
+                    "description": "合同数量(数值) (用于计算)",
+                    "type": "number"
+                },
+                "contractqtychar": {
+                    "description": "合同数量\\已订价数量 (用于显示)",
+                    "type": "string"
+                },
+                "contractstatus": {
+                    "description": "合同状态 - 0:未结束 1:已结束",
+                    "type": "integer"
+                },
+                "contracttype": {
+                    "description": "现货合同类型 - 1:采购合同 -1:销售合同",
+                    "type": "integer"
+                },
+                "customeraccountid": {
+                    "description": "客户资金账户ID",
+                    "type": "integer"
+                },
+                "customeruserid": {
+                    "description": "客户ID",
+                    "type": "integer"
+                },
+                "deliverygoodsdesc": {
+                    "description": "品种说明",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "handlestatus": {
+                    "description": "处理状态",
+                    "type": "integer"
+                },
+                "invoiceatt": {
+                    "description": "发票附件",
+                    "type": "string"
+                },
+                "invoicedatetime": {
+                    "description": "开收票更新时间",
+                    "type": "string"
+                },
+                "invoiceopentime": {
+                    "description": "开票时间",
+                    "type": "string"
+                },
+                "invoiceremark": {
+                    "description": "发票备注",
+                    "type": "string"
+                },
+                "invoicestatus": {
+                    "description": "开收票状态 - 0:未开票 1:已开票",
+                    "type": "integer"
+                },
+                "lastdate": {
+                    "description": "交货时间",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
                 },
-                "tradetype": {
-                    "description": "成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交",
+                "paydatetime": {
+                    "description": "收付款更新时间",
+                    "type": "string"
+                },
+                "payremark": {
+                    "description": "收付款备注",
+                    "type": "string"
+                },
+                "paystatus": {
+                    "description": "收付款状态 - 0:未支付 1:已收款 2:已付款",
+                    "type": "integer"
+                },
+                "positionqty": {
+                    "description": "头寸数量 - 合同数量去小数部分",
+                    "type": "integer"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "relatedqty": {
+                    "description": "已关联数量",
+                    "type": "number"
+                },
+                "relatedstatus": {
+                    "description": "关联完结状态 - 0:未结束 1:已结束",
+                    "type": "integer"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "signdate": {
+                    "description": "签订日期",
+                    "type": "string"
+                },
+                "spotcontractid": {
+                    "description": "现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "spotdatetime": {
+                    "description": "收发货更新时间",
+                    "type": "string"
+                },
+                "spotprice": {
+                    "description": "价格",
+                    "type": "number"
+                },
+                "spotremark": {
+                    "description": "收发货备注",
+                    "type": "string"
+                },
+                "spotstatus": {
+                    "description": "收发货状态 - 0:未交收 1:已发货 2:已发货",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "业务员用户ID",
+                    "type": "integer"
+                },
+                "warehouseid": {
+                    "description": "仓库ID",
+                    "type": "integer"
+                },
+                "wrfactortypeid": {
+                    "description": "仓单要素类型ID",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "仓单标准ID(SEQ_WRSTANDARD)",
                     "type": "integer"
                 }
             }

+ 357 - 89
docs/swagger.yaml

@@ -717,134 +717,208 @@ definitions:
     - mindeliveryqty
     - xdeliveryratio
     type: object
-  erms2.QueryInnerTradeDetailRsp:
+  erms2.QueryArbitrageStrategyRsp:
     properties:
-      accountcurrencyid:
-        description: 账户币种ID
-        type: integer
-      accountid:
-        description: 账号ID
-        type: integer
+      applybasis:
+        description: 申请基差
+        type: number
       asapplyid:
-        description: 策略申请ID
+        description: 策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)
         type: integer
-      ascontractno:
+      asname:
+        description: 策略名称
+        type: string
+      asno:
         description: 策略编号
         type: string
-      buyorsell:
-        description: 方向 - 0:买 1:卖
+      basischangepl:
+        description: 基差变动损益[结算更新]
+        type: number
+      biztype:
+        description: 业务类型 - 1:正向套利 -1:反向套利
         type: integer
-      channelbuildtype:
-        description: 委托单据类型 0:无 1:建仓 2:平仓
+      closetradedate:
+        description: 完结交易日(yyyyMMdd)
+        type: string
+      curbasis:
+        description: 当前基差[结算更新]
+        type: number
+      deliverygoodsid:
+        description: 现货品种ID
         type: integer
-      closecharge:
-        description: 平仓手续费(账户)
+      futureavgprice:
+        description: 期货建仓均价
         type: number
-      closecharge2:
-        description: 平仓手续费(商品)
+      futurecloseamount:
+        description: 期货平仓金额
         type: number
-      closechargevalue:
-        description: 平仓手续费设置值
+      futurecloseqty:
+        description: 期货平仓数量
         type: number
-      closefeealgorithm:
-        description: 平仓手续费收取方式 1:比率  2:固定
-        type: integer
-      closepl:
-        description: 平仓盈亏(账户)
+      futureopenamount:
+        description: 期货开仓金额
         type: number
-      closepl2:
-        description: 平仓盈亏(商品)
+      futureopenqty:
+        description: 期货开仓数量
         type: number
-      closepl3:
-        description: 平仓盈亏(账户)(逐笔)
+      futurepl:
+        description: 期货总盈亏[结算更新]
         type: number
-      closepl4:
-        description: 平仓盈亏(商品)(逐笔)
+      futureqty:
+        description: 期货持仓数量
         type: number
-      closeqty:
-        description: 平仓数量(先建后平操作 需要记录)
+      futurequote:
+        description: 期货额度
+        type: number
+      goodsgroupid:
+        description: 期货品种ID
         type: integer
-      closetype:
-        description: 平仓方式 - 0:无 1:平今 2:平昨
+      marketid:
+        description: 市场ID
         type: integer
-      curexchangerate:
-        description: 当前汇率
+      netexposure:
+        description: 单笔业务头寸净敞口 = 期货持仓数量 + 已定价现货不含税数量
         type: number
-      detailtype:
-        description: 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
-        type: integer
-      extenalclosecharge:
-        description: 平仓手续费(商品)(外部)
+      netexposurepl:
+        description: 净敞口损益 = TotalPL - BasisChangePL[结算更新]
         type: number
-      extenalclosechargevalue:
-        description: 平仓手续费设置值
+      netexposurerate:
+        description: 净敞口比例 - 0:未结束 =  (NetExposure/PriceSpotQtyNoTax) ; 已结束为0
         type: number
-      extenalclosefeealgorithm:
-        description: 平仓手续费收取方式 1:比率  2:固定
+      openbasis:
+        description: 建仓基差
+        type: number
+      pricedspotqty:
+        description: 已定价现货数量
+        type: number
+      pricedspotqtynotax:
+        description: 已定价现货不含税数量
+        type: number
+      remark:
+        description: 备注
+        type: string
+      spotavgprice:
+        description: 现货均价
+        type: number
+      spotbuyamount:
+        description: 现货采购金额
+        type: number
+      spotbuyqty:
+        description: 现货采购数量
+        type: number
+      spotpl:
+        description: 现货总盈亏[结算更新]
+        type: number
+      spotquota:
+        description: 现货额度
+        type: number
+      spotsellamount:
+        description: 现货销售金额
+        type: number
+      spotsellqty:
+        description: 现货销售数量
+        type: number
+      spotusedquota:
+        description: 现货占用资金
+        type: number
+      strategystatus:
+        description: 策略状态 - 0:未结束 1:已结束
         type: integer
-      extenalopencharge:
-        description: 建仓手续费(商品)(外部)
+      totalpl:
+        description: 业务合计损益 = FuturePL + SpotPL [结算更新]
         type: number
-      extenalopenchargevalue:
-        description: 建仓手续费设置值
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      updatetime:
+        description: 更新时间
+        type: string
+      usedquota:
+        description: 已占用资金
+        type: number
+      userid:
+        description: 所属机构
+        type: integer
+    required:
+    - asapplyid
+    type: object
+  erms2.QueryInnerTradeDetailRsp:
+    properties:
+      accountid:
+        description: 账号ID
+        type: integer
+      agreeunit:
+        description: 合约单位
         type: number
-      extenalopenfeealgorithm:
-        description: 建仓手续费收取方式(外部配置) 1:比率  2:固定
+      asapplyid:
+        description: 策略申请ID
         type: integer
-      goodscurrencyid:
-        description: 商品币种ID
+      asname:
+        description: 策略名称
+        type: string
+      asno:
+        description: 策略编号
+        type: string
+      buyorsell:
+        description: 方向 - 0:买 1:卖
         type: integer
-      goodsid:
-        description: 商品ID
+      channelbuildtype:
+        description: 委托单据类型 0:无 1:建仓 2:平仓
         type: integer
-      hedgeflag:
-        description: 投机套保标志 - 0:无 1:投机 2:套保 3:套利
+      closetype:
+        description: 平仓方式 - 0:无 1:平今 2:平昨
         type: integer
-      isreckoned:
-        description: 是否结算 - 0:未结算 1:已结算
+      decimalplace:
+        description: 报价小数位
         type: integer
-      marketid:
-        description: 市场ID
+      detailtype:
+        description: 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
         type: integer
-      opencharge:
-        description: 建仓手续费(账户)
-        type: number
-      opencharge2:
-        description: 建仓手续费(商品)
-        type: number
-      openchargevalue:
-        description: 建仓手续费设置值
-        type: number
-      openfeealgorithm:
-        description: 建仓手续费收取方式  1:比率  2:固定
+      exexchangecode:
+        description: 外部交易所代码
+        type: string
+      exexchangename:
+        description: 外部交易所名称
+        type: string
+      goodscode:
+        description: 商品代码(合约)
+        type: string
+      goodsgroupid:
+        description: 商品组ID(品种ID)
         type: integer
-      openqty:
-        description: 开仓数量(先建后平操作 需要记录)
+      goodsgroupname:
+        description: 商品组名称(品种)
+        type: string
+      goodsid:
+        description: 商品ID
+        type: integer
+      goodsname:
+        description: 商品名称(合约)
+        type: string
+      goodunit:
+        description: 报价单位
+        type: string
+      marketid:
+        description: 市场ID
         type: integer
       orderid:
         description: 委托单号
         type: integer
-      parentaccountid:
-        description: 所属母账户
-        type: integer
+      outgoodscode:
+        description: 商品代码(外部)
+        type: string
       relatedouttradeid:
         description: 关联外部成交单ID
         type: integer
+      remark:
+        description: 备注
+        type: string
       spotcontractid:
         description: 现货合同ID [1:套利对冲 为合同ID,2:期货换月\3:期货仓位调整时为0]
         type: integer
       spotcontractno:
         description: 现货合同编号
         type: string
-      status:
-        description: 处理状态 - 1:待处理 2:已处理 3:处理失败
-        type: integer
-      tradeamount:
-        description: 成交金额(账户)
-        type: number
-      tradedate:
-        description: 交易日(yyyyMMdd)
-        type: string
       tradeid:
         description: 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
         type: integer
@@ -857,14 +931,152 @@ definitions:
       tradetime:
         description: 成交时间
         type: string
-      tradetype:
-        description: 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
-        type: integer
     required:
     - asapplyid
     - buyorsell
+    - goodscode
+    - goodsgroupid
+    - goodsgroupname
+    - goodsname
     - tradeid
     type: object
+  erms2.QuerySpotContractRsp:
+    properties:
+      accountid:
+        description: 资金账户ID
+        type: integer
+      areauserid:
+        description: 所属机构
+        type: integer
+      closedate:
+        description: 终止日期
+        type: string
+      closeremark:
+        description: 结束备注
+        type: string
+      closetradedate:
+        description: 完结交易日(yyyyMMdd)
+        type: string
+      closetype:
+        description: 终止类型 - 1:违约 2:提前终止
+        type: integer
+      contractamount:
+        description: 合同金额
+        type: number
+      contractattachment:
+        description: 合同附件
+        type: string
+      contractno:
+        description: 现货合同编号
+        type: string
+      contractqty:
+        description: 合同数量(数值) (用于计算)
+        type: number
+      contractqtychar:
+        description: 合同数量\已订价数量 (用于显示)
+        type: string
+      contractstatus:
+        description: 合同状态 - 0:未结束 1:已结束
+        type: integer
+      contracttype:
+        description: 现货合同类型 - 1:采购合同 -1:销售合同
+        type: integer
+      customeraccountid:
+        description: 客户资金账户ID
+        type: integer
+      customeruserid:
+        description: 客户ID
+        type: integer
+      deliverygoodsdesc:
+        description: 品种说明
+        type: string
+      deliverygoodsid:
+        description: 现货品种ID
+        type: integer
+      handlestatus:
+        description: 处理状态
+        type: integer
+      invoiceatt:
+        description: 发票附件
+        type: string
+      invoicedatetime:
+        description: 开收票更新时间
+        type: string
+      invoiceopentime:
+        description: 开票时间
+        type: string
+      invoiceremark:
+        description: 发票备注
+        type: string
+      invoicestatus:
+        description: 开收票状态 - 0:未开票 1:已开票
+        type: integer
+      lastdate:
+        description: 交货时间
+        type: string
+      marketid:
+        description: 市场ID
+        type: integer
+      paydatetime:
+        description: 收付款更新时间
+        type: string
+      payremark:
+        description: 收付款备注
+        type: string
+      paystatus:
+        description: 收付款状态 - 0:未支付 1:已收款 2:已付款
+        type: integer
+      positionqty:
+        description: 头寸数量 - 合同数量去小数部分
+        type: integer
+      producttype:
+        description: 产品类型 - 1:标准仓单 2:等标 3:非标
+        type: integer
+      relatedqty:
+        description: 已关联数量
+        type: number
+      relatedstatus:
+        description: 关联完结状态 - 0:未结束 1:已结束
+        type: integer
+      remark:
+        description: 备注
+        type: string
+      signdate:
+        description: 签订日期
+        type: string
+      spotcontractid:
+        description: 现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)
+        type: integer
+      spotdatetime:
+        description: 收发货更新时间
+        type: string
+      spotprice:
+        description: 价格
+        type: number
+      spotremark:
+        description: 收发货备注
+        type: string
+      spotstatus:
+        description: 收发货状态 - 0:未交收 1:已发货 2:已发货
+        type: integer
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      userid:
+        description: 业务员用户ID
+        type: integer
+      warehouseid:
+        description: 仓库ID
+        type: integer
+      wrfactortypeid:
+        description: 仓单要素类型ID
+        type: integer
+      wrstandardid:
+        description: 仓单标准ID(SEQ_WRSTANDARD)
+        type: integer
+    required:
+    - spotcontractid
+    type: object
 info:
   contact: {}
   description: 新的查询服务,替代原通用查询服务。
@@ -1118,6 +1330,34 @@ paths:
       summary: 查询商品交割关系表
       tags:
       - 交割服务
+  /Erms2/QueryArbitrageStrategy:
+    get:
+      parameters:
+      - description: 资金账户
+        in: query
+        name: accountid
+        required: true
+        type: integer
+      - description: 商品组ID(品种ID)
+        in: query
+        name: goodsgroupid
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/erms2.QueryArbitrageStrategyRsp'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询期现套利策略表信息(指定资金账户、未结束的)
+      tags:
+      - 风险管理
   /Erms2/QueryInnerTradeDetail:
     get:
       parameters:
@@ -1142,6 +1382,34 @@ paths:
       summary: 查询内部成交单信息
       tags:
       - 风险管理
+  /Erms2/QuerySpotContract:
+    get:
+      parameters:
+      - description: 策略申请ID
+        in: query
+        name: asapplyid
+        required: true
+        type: integer
+      - description: 现货合同ID
+        in: query
+        name: spotcontractid
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/erms2.QuerySpotContractRsp'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询现货合同表信息(指定策略ID、未结束的)
+      tags:
+      - 风险管理
   /WRTrade/GetAllDeliveryGoods:
     get:
       produces:

+ 38 - 1
models/erms2Models.go

@@ -85,7 +85,7 @@ func (Erms2astradedetails) TableName() string {
 // Erms2arbitragestrategy 期现套利策略表 - 导历史
 type Erms2arbitragestrategy struct {
 	Asapplyid          int64     `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)
-	Contractno         string    `json:"contractno"  xorm:"'CONTRACTNO'"`                  // 策略编号
+	Asno               string    `json:"asno"  xorm:"'ASNO'"`                              // 策略编号
 	Biztype            int64     `json:"biztype"  xorm:"'BIZTYPE'"`                        // 业务类型 - 1:正向套利 -1:反向套利
 	Userid             int64     `json:"userid"  xorm:"'USERID'"`                          // 所属机构
 	Deliverygoodsid    int64     `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`        // 现货品种ID
@@ -123,6 +123,7 @@ type Erms2arbitragestrategy struct {
 	Spotsellamount     float64   `json:"spotsellamount"  xorm:"'SPOTSELLAMOUNT'"`          // 现货销售金额
 	Spotsellqty        float64   `json:"spotsellqty"  xorm:"'SPOTSELLQTY'"`                // 现货销售数量
 	Updatetime         time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                  // 更新时间
+	Asname             string    `json:"asname"  xorm:"'ASNAME'"`                          // 策略名称
 }
 
 // TableName is ERMS2_ARBITRAGESTRATEGY
@@ -182,3 +183,39 @@ type Erms2spotcontract struct {
 func (Erms2spotcontract) TableName() string {
 	return "ERMS2_SPOTCONTRACT"
 }
+
+// Erms2asaccount 期现套利资金账户表
+type Erms2asaccount struct {
+	Asapplyid        int64 `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)
+	Accountid        int64 `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"` // 资金账户
+	Taaccounttype    int64 `json:"taaccounttype"  xorm:"'TAACCOUNTTYPE'"`            // 账户类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
+	Taaccountbiztype int64 `json:"taaccountbiztype"  xorm:"'TAACCOUNTBIZTYPE'"`      // 账户业务类型 - 1:现货 2:期货
+}
+
+// TableName is ERMS2_ASACCOUNT
+func (Erms2asaccount) TableName() string {
+	return "ERMS2_ASACCOUNT"
+}
+
+// Erms2asspotdetail 期现套利现货明细表 - 导历史
+type Erms2asspotdetail struct {
+	Asapplyid          int64     `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"`           // 策略申请ID
+	Spotcontractid     int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"` // 现货合同ID
+	Contracttype       int64     `json:"contracttype"  xorm:"'CONTRACTTYPE'"`                        // 现货合同类型 - 1:采购合同 -1:销售合同
+	Pricedspotqty      float64   `json:"pricedspotqty"  xorm:"'PRICEDSPOTQTY'"`                      // 已定价数量(合同数量 * 合同类型)
+	Pricedspotqtynotax float64   `json:"pricedspotqtynotax"  xorm:"'PRICEDSPOTQTYNOTAX'"`            // 已定价不含税数量( 已定价数量 /(1+对冲税率))
+	Vatrate            float64   `json:"vatrate"  xorm:"'VATRATE'"`                                  // 税率
+	Spotprice          float64   `json:"spotprice"  xorm:"'SPOTPRICE'"`                              // 价格
+	Spotamount         float64   `json:"spotamount"  xorm:"'SPOTAMOUNT'"`                            // 收付款资金(合同金额 * 合同类型)
+	Detailstatus       int64     `json:"detailstatus"  xorm:"'DETAILSTATUS'"`                        // 明细状态 - 0:未结束 1:已结束
+	Futureqty          float64   `json:"futureqty"  xorm:"'FUTUREQTY'"`                              // 期货已对冲数量
+	Futureamount       float64   `json:"futureamount"  xorm:"'FUTUREAMOUNT'"`                        // 期货成交金额
+	Closetradedate     string    `json:"closetradedate"  xorm:"'CLOSETRADEDATE'"`                    // 完结交易日(yyyyMMdd)
+	Remark             string    `json:"remark"  xorm:"'REMARK'"`                                    // 备注
+	Updatetime         time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                            // 更新时间
+}
+
+// TableName is ERMS2_ASSPOTDETAIL
+func (Erms2asspotdetail) TableName() string {
+	return "ERMS2_ASSPOTDETAIL"
+}

+ 39 - 0
models/goodsModels.go

@@ -55,3 +55,42 @@ type Goods struct {
 func (Goods) TableName() string {
 	return "GOODS"
 }
+
+// Goodsgroup 商品组表 - 品种(通道交易\场外期权)
+type Goodsgroup struct {
+	Goodsgroupid           int64     `json:"goodsgroupid"  xorm:"'GOODSGROUPID'" binding:"required"`         // 商品组ID(自增ID)
+	Goodsgroupname         string    `json:"goodsgroupname"  xorm:"'GOODSGROUPNAME'" binding:"required"`     // 商品组名称
+	Goodsgroupstatus       int64     `json:"goodsgroupstatus"  xorm:"'GOODSGROUPSTATUS'" binding:"required"` // 商品组状态 - 1:正常 2:注销
+	Marketid               int64     `json:"marketid"  xorm:"'MARKETID'" binding:"required"`                 // 所属市场ID
+	Createtime             time.Time `json:"createtime"  xorm:"'CREATETIME'"`                                // 创建时间
+	Creatorid              int64     `json:"creatorid"  xorm:"'CREATORID'"`                                  // 创建人
+	Modifytime             time.Time `json:"modifytime"  xorm:"'MODIFYTIME'"`                                // 修改时间
+	Modifierid             int64     `json:"modifierid"  xorm:"'MODIFIERID'"`                                // 修改人
+	Quotesourcegroupid     int64     `json:"quotesourcegroupid"  xorm:"'QUOTESOURCEGROUPID'"`                // 所属行情源分组ID[参考行情市场用\通道交易]
+	Outergroupcode         string    `json:"outergroupcode"  xorm:"'OUTERGROUPCODE'"`                        // 外部商品组代码[通道交易]
+	Canshort               int64     `json:"canshort"  xorm:"'CANSHORT'"`                                    // 是否允许做空[通道交易] - 0:不能做空 1:可以做空
+	Exexchangeid           int64     `json:"exexchangeid"  xorm:"'EXEXCHANGEID'"`                            // 外部交易所ID[通道交易]
+	Currencyid             int64     `json:"currencyid"  xorm:"'CURRENCYID'"`                                // 报价货币ID
+	Goodunitid             int64     `json:"goodunitid"  xorm:"'GOODUNITID'"`                                // 报价单位ID
+	Agreeunit              float64   `json:"agreeunit"  xorm:"'AGREEUNIT'"`                                  // 合约单位
+	Decimalplace           int64     `json:"decimalplace"  xorm:"'DECIMALPLACE'"`                            // 报价小数位
+	Quoteminunit           int64     `json:"quoteminunit"  xorm:"'QUOTEMINUNIT'"`                            // 行情最小变动单位 [整数,报价小数位一起使用]
+	Innerdealmode          int64     `json:"innerdealmode"  xorm:"'INNERDEALMODE'"`                          // 内部成交方式[通道交易] - 1:净头寸 2:开平 3:平今
+	Outerdealmode          int64     `json:"outerdealmode"  xorm:"'OUTERDEALMODE'"`                          // 外部成交方式[通道交易]- 1:净头寸 2:开平 3:平今
+	Syncgoodsqty           int64     `json:"syncgoodsqty"  xorm:"'SYNCGOODSQTY'"`                            // 同步合约数[通道交易-投资管理用] - 0表示不限
+	Closepricemode         int64     `json:"closepricemode"  xorm:"'CLOSEPRICEMODE'"`                        // 强平价格方式 - 1:市价 2:最新价 3:涨跌停(未实现)
+	Closepriceparam        float64   `json:"closepriceparam"  xorm:"'CLOSEPRICEPARAM'"`                      // 强平最新价浮动比例 - 方式为2时使用
+	Qtydecimalplace        int64     `json:"qtydecimalplace"  xorm:"'QTYDECIMALPLACE'"`                      // 成交量小数位
+	Exercisetype           int64     `json:"exercisetype"  xorm:"'EXERCISETYPE'"`                            // 行权类型[场外期权]-1:欧式期权 2:美式期权
+	Premiumdecimalplace    int64     `json:"premiumdecimalplace"  xorm:"'PREMIUMDECIMALPLACE'"`              // 权利金小数位[场外期权]
+	Premiumspreadalgorithm int64     `json:"premiumspreadalgorithm"  xorm:"'PREMIUMSPREADALGORITHM'"`        // 权利金点差方式[场外期权]  1:比率  2:固定
+	Premiumspreadvalue     float64   `json:"premiumspreadvalue"  xorm:"'PREMIUMSPREADVALUE'"`                // 权利金点差值[场外期权]
+	Isbuylimited           int64     `json:"isbuylimited"  xorm:"'ISBUYLIMITED'"`                            // 是否限制建仓量 - 0:不限制 1:限制
+	Quotegear              int64     `json:"quotegear"  xorm:"'QUOTEGEAR'"`                                  // 行情档位(1-10)
+	Quoterid               int64     `json:"quoterid"  xorm:"'QUOTERID'"`                                    // 报价商ID[场外期权]
+}
+
+// TableName is GOODSGROUP
+func (Goodsgroup) TableName() string {
+	return "GOODSGROUP"
+}

+ 4 - 0
routers/router.go

@@ -72,6 +72,10 @@ func InitRouter() *gin.Engine {
 	{
 		// 查询内部成交单信息
 		erms2R.GET("/QueryInnerTradeDetail", erms2.QueryInnerTradeDetail)
+		// 查询期现套利策略表信息(指定资金账户、未结束的)
+		erms2R.GET("/QueryArbitrageStrategy", erms2.QueryArbitrageStrategy)
+		// 查询现货合同表信息(指定策略ID、未结束的)
+		erms2R.GET("/QuerySpotContract", erms2.QuerySpotContract)
 	}
 
 	return r