| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- // Package models 211.2风险管理系统2020_期现套利
- package models
- import (
- "fmt"
- "mtp2_if/db"
- "time"
- )
- // Erms2astradedetails 期现套利期货成交单关联表
- type Erms2astradedetails struct {
- Asapplyid int64 `json:"asapplyid" xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID
- Outtradeid int64 `json:"outtradeid" xorm:"'OUTTRADEID'" binding:"required"` // 外部成交单ID(114+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
- Biztype int64 `json:"biztype" xorm:"'BIZTYPE'"` // 策略业务类型 - 1:正向套利 2:反向套利
- Detailtype int64 `json:"detailtype" xorm:"'DETAILTYPE'"` // 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
- Spotcontractid int64 `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 现货合同ID [1:套利对冲 为合同ID,2:期货换月\3:期货仓位调整时为0]
- Contracttype int64 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购合同 -1:销售合同
- Hedgegoodsid int64 `json:"hedgegoodsid" xorm:"'HEDGEGOODSID'"` // 对冲合约ID
- Buyorsell int64 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向 - 0:买 1:卖 [成交单方向]
- Buildtype int64 `json:"buildtype" xorm:"'BUILDTYPE'"` // 开平标志- 0:无 1:开仓 2:平仓 [根据成交单方向及策略业务类型确定]正向套利 成交单:卖 开 成交单:买 平反向套利 成交单:买 开 成交单:卖 平
- Goodsgroupid int64 `json:"goodsgroupid" xorm:"'GOODSGROUPID'"` // 对冲品种ID[期货合约商品组ID]
- Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 成交交易日(yyyyMMdd)
- Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价
- Tradelot float64 `json:"tradelot" xorm:"'TRADELOT'"` // 成交手数
- Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
- Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额 = 成交价*成交手数*合约单位
- Tradecharge float64 `json:"tradecharge" xorm:"'TRADECHARGE'"` // 交易手续费
- Basisflag int64 `json:"basisflag" xorm:"'BASISFLAG'"` // 是否计入基差损益 - 0:不计入 1:计入 [明细类型:1\2为1,3:期货仓位调整是为0]
- Remark string `json:"remark" xorm:"'REMARK'"` // 备注
- Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
- }
- // TableName is ERMS2_ASTRADEDETAILS
- func (Erms2astradedetails) TableName() string {
- return "ERMS2_ASTRADEDETAILS"
- }
- // Erms2Wrrcontract 仓单回购业务表
- type Erms2Wrrcontract struct {
- Wrrcontractid string `json:"wrrcontractid" xorm:"WRRCONTRACTID"` // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
- Wrrcontractno string `json:"wrrcontractno" xorm:"WRRCONTRACTNO"` // 回购业务编号
- Wrrcontractname string `json:"wrrcontractname" xorm:"WRRCONTRACTNAME"` // 回购名称
- Areauserid int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID
- Wrfactortypeid int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID
- Accountid int64 `json:"accountid" xorm:"ACCOUNTID"` // 现货账户
- Contractqtychar string `json:"contractqtychar" xorm:"CONTRACTQTYCHAR"` // 合同数量(显示)
- Contractqty float64 `json:"contractqty" xorm:"CONTRACTQTY"` // 合同数量
- Contractprice float64 `json:"contractprice" xorm:"CONTRACTPRICE"` // 合同价格
- Contractamount float64 `json:"contractamount" xorm:"CONTRACTAMOUNT"` // 合同金额
- Interestratemode int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率
- Interestrate float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
- Interestmindays int64 `json:"interestmindays" xorm:"INTERESTMINDAYS"` // 最小计息天数
- Contractinterest float64 `json:"contractinterest" xorm:"CONTRACTINTEREST"` // 合同利息
- Orimargin float64 `json:"orimargin" xorm:"ORIMARGIN"` // 初始保证金
- Marginrate float64 `json:"marginrate" xorm:"MARGINRATE"` // 保证金率
- Begindate time.Time `json:"begindate" xorm:"BEGINDATE"` // 开始日期
- Enddate time.Time `json:"enddate" xorm:"ENDDATE"` // 结束日期
- Warningline float64 `json:"warningline" xorm:"WARNINGLINE"` // 预警线
- Closeline float64 `json:"closeline" xorm:"CLOSELINE"` // 强平线
- Customeruserid int64 `json:"customeruserid" xorm:"CUSTOMERUSERID"` // 回购客户ID
- Customeraccountid int64 `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"` // 客户资金账户ID
- Curqty float64 `json:"curqty" xorm:"CURQTY"` // 当前数量
- Curamount float64 `json:"curamount" xorm:"CURAMOUNT"` // 当前金额
- Curinterest float64 `json:"curinterest" xorm:"CURINTEREST"` // 当前利息
- Curmargin float64 `json:"curmargin" xorm:"CURMARGIN"` // 当前保证金
- Addedmargin float64 `json:"addedmargin" xorm:"ADDEDMARGIN"` // 已追加保证金
- Curenddate time.Time `json:"curenddate" xorm:"CURENDDATE"` // 最新结束日期(默认为结束日期)
- Remark string `json:"remark" xorm:"REMARK"` // 备注
- Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
- Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
- Updatetime time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
- Relatedspotcontractid int64 `json:"relatedspotcontractid" xorm:"RELATEDSPOTCONTRACTID"` // 关联销售合同ID
- Handlestatus int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理状态
- Contractstatus int32 `json:"contractstatus" xorm:"CONTRACTSTATUS"` // 合同状态 - 0:未结束 1:已结束
- Closetradedate string `json:"closetradedate" xorm:"CLOSETRADEDATE"` // 完结交易日(yyyyMMdd)
- }
- // TableName is ERMS2_WRRCONTRACT
- func (Erms2Wrrcontract) TableName() string {
- return "ERMS2_WRRCONTRACT"
- }
- // Erms2WrrcontractInfo 仓单回购业务详细信息.
- type Erms2WrrcontractInfo struct {
- Wrrcontractid string `json:"wrrcontractid" xorm:"WRRCONTRACTID"` // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- Contractqty float64 `json:"contractqty" xorm:"CONTRACTQTY"` // 合同数量
- Contractstatus int32 `json:"contractstatus" xorm:"CONTRACTSTATUS"` // 合同状态 - 0:未结束 1:已结束
- Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购量.
- Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购额.
- Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售量.
- Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售额.
- }
- // Erms2Spottradebiz 现货贸易业务表
- type Erms2Spottradebiz struct {
- Spottradeid string `json:"spottradeid" xorm:"SPOTTRADEID"` // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
- Spottradeno string `json:"spottradeno" xorm:"SPOTTRADENO"` // 业务编号
- Spottradename string `json:"spottradename" xorm:"SPOTTRADENAME"` // 业务名称
- Areauserid int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID
- Goodsgroupid int64 `json:"goodsgroupid" xorm:"GOODSGROUPID"` // 期货品种
- Spotaccountid int64 `json:"spotaccountid" xorm:"SPOTACCOUNTID"` // 现货资金账户
- Futureaccountid int64 `json:"futureaccountid" xorm:"FUTUREACCOUNTID"` // 期货资金账户
- Remark string `json:"remark" xorm:"REMARK"` // 备注
- Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
- Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
- Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购总量
- Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购总金额
- Buydeliveryqty float64 `json:"buydeliveryqty" xorm:"BUYDELIVERYQTY"` // 采购已交收数量
- Buydeliveryamount float64 `json:"buydeliveryamount" xorm:"BUYDELIVERYAMOUNT"` // 采购已交收金额
- Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售总量
- Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售总金额
- Selldeliveryqty float64 `json:"selldeliveryqty" xorm:"SELLDELIVERYQTY"` // 销售已交收数量
- Selldeliveryamount float64 `json:"selldeliveryamount" xorm:"SELLDELIVERYAMOUNT"` // 销售已交收金额
- Futurelot float64 `json:"futurelot" xorm:"FUTURELOT"` // 期货手数
- Closestatus int32 `json:"closestatus" xorm:"CLOSESTATUS"` // 完结状态 - 0:未完结 1:已完结
- Closetradedate string `json:"closetradedate" xorm:"CLOSETRADEDATE"` // 完结交易日(yyyyMMdd)
- }
- // TableName is ERMS2_SPOTTRADEBIZ
- func (Erms2Spottradebiz) TableName() string {
- return "ERMS2_SPOTTRADEBIZ"
- }
- // Erms2SpottradebizInfo 现货贸易详细信息.
- type Erms2SpottradebizInfo struct {
- Spottradeid string `json:"spottradeid" xorm:"SPOTTRADEID"` // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购总量
- Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售总量
- Closestatus int32 `json:"closestatus" xorm:"CLOSESTATUS"` // 完结状态 - 0:未完结 1:已完结
- TradeBuyqty float64 `json:"tradebuyqty" xorm:"TRADEBUYQTY"` // 采购量.
- TradeBuyamount float64 `json:"tradebuyamount" xorm:"TRADEBUYAMOUNT"` // 采购额.
- TradeSellqty float64 `json:"tradesellqty" xorm:"TRADESELLQTY"` // 销售量.
- TradeSellamount float64 `json:"tradesellamount" xorm:"TRADESELLAMOUNT"` // 销售额.
- }
- // Erms2Arbitragestrategy 期现套利业务表
- type Erms2Arbitragestrategy struct {
- Asapplyid string `json:"asapplyid" xorm:"ASAPPLYID"` // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
- Asno string `json:"asno" xorm:"ASNO"` // 策略编号
- Asname string `json:"asname" xorm:"ASNAME"` // 策略名称
- Biztype int32 `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 int32 `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"` // 更新时间
- }
- // TableName is ERMS2_ARBITRAGESTRATEGY
- func (Erms2Arbitragestrategy) TableName() string {
- return "ERMS2_ARBITRAGESTRATEGY"
- }
- // 期现套利详细信息.
- type Erms2AribitrageInfo struct {
- Asapplyid string `json:"asapplyid" xorm:"ASAPPLYID"` // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- Pricedspotqty float64 `json:"pricedspotqty" xorm:"PRICEDSPOTQTY"` // 已定价现货数量
- Futureqty float64 `json:"futureqty" xorm:"FUTUREQTY"` // 期货持仓数量
- Strategystatus int32 `json:"strategystatus" xorm:"STRATEGYSTATUS"` // 策略状态 - 0:未结束 1:已结束
- Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购量.
- Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购额.
- Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售量.
- Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售额.
- }
- // Erms2spotcontract 现货合同表
- type Erms2spotcontract 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'"` // 终止日期
- }
- // TableName is ERMS2_SPOTCONTRACT
- 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"
- }
- // QueryASAccountInfoByAccountID 根据资金账号ID查询.
- func QueryASAccountInfoByAccountID(accountids []int64) ([]Erms2asaccount, error) {
- engine := db.GetEngine()
- data := make([]Erms2asaccount, 0)
- err := engine.In("ACCOUNTID", accountids).Find(&data)
- return data, err
- }
- // QueryASApplyIDSByAccountID 根据资金账号ID查询业务ID集合.
- func QueryASApplyIDSByAccountID(accountids []int64) ([]int64, error) {
- data, err := QueryASAccountInfoByAccountID(accountids)
- if err != nil {
- return nil, err
- }
- distinctID := make(map[int64]struct{})
- applyids := make([]int64, 0, len(data))
- for i := range data {
- if _, ok := distinctID[data[i].Asapplyid]; ok {
- continue
- }
- applyids = append(applyids, data[i].Asapplyid)
- distinctID[data[i].Asapplyid] = struct{}{}
- }
- return applyids, nil
- }
- // buildSQL 构建sql.
- func (asa Erms2Arbitragestrategy) buildSQL(accountids string, status int32) string {
- statement := `select to_char(asa.asapplyid) asapplyid,
- asa.deliverygoodsid, asa.pricedspotqty, asa.futureqty, asa.strategystatus,
- d.buyqty,
- d.buyamount,
- d.sellqty,
- d.sellamount
- from erms2_arbitragestrategy asa
- left join (select bt.relatedbizid,
- sum(case bt.contracttype
- when 1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) buyqty,
- sum(case bt.contracttype
- when 1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) buyamount,
- sum(case bt.contracttype
- when -1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) sellqty,
- sum(case bt.contracttype
- when -1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) sellamount
- from erms3_biztradedetail bt
- left join erms2_asaccount ea
- on bt.relatedbizid = ea.asapplyid
- where ea.accountid in (%v)
- group by bt.relatedbizid) d
- on asa.asapplyid = d.relatedbizid
- where asa.strategystatus = %v`
- return fmt.Sprintf(statement, accountids, status)
- }
- // GetByAccountIDSAndStatus 根据账号和状态获取期现套利详细信息.
- func (asa Erms2Arbitragestrategy) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2AribitrageInfo, error) {
- engine := db.GetEngine()
- data := make([]Erms2AribitrageInfo, 0)
- err := engine.SQL(asa.buildSQL(accountids, status)).Find(&data)
- return data, err
- }
- func (Erms2Wrrcontract) buildSQL(accountids string, status int32) string {
- statement := `select to_char(wr.wrrcontractid) wrrcontractid,
- wr.deliverygoodsid,
- wr.contractqty,
- wr.contractstatus,
- sum(case bt.contracttype
- when 1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) buyqty,
- sum(case bt.contracttype
- when 1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) buyamount,
- sum(case bt.contracttype
- when -1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) sellqty,
- sum(case bt.contracttype
- when -1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) sellamount
- from erms3_biztradedetail bt
- left join erms2_wrrcontract wr
- on wr.wrrcontractid = bt.relatedbizid
- where wr.accountid in (%v)
- and wr.contractstatus = %v
- group by wr.wrrcontractid,
- wr.deliverygoodsid,
- wr.contractqty,
- wr.contractstatus`
- return fmt.Sprintf(statement, accountids, status)
- }
- // GetByAccountIDSAndStatus 根据账号和状态获取仓单回购业务.
- func (wr Erms2Wrrcontract) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2WrrcontractInfo, error) {
- engine := db.GetEngine()
- data := make([]Erms2WrrcontractInfo, 0)
- err := engine.SQL(wr.buildSQL(accountids, status)).Find(&data)
- return data, err
- }
- // buildSQL 构建sql.
- func (Erms2Spottradebiz) buildSQL(accountids string, status int32) string {
- statement := `select to_char(sbt.spottradeid) spottradeid,
- sbt.deliverygoodsid,
- sbt.buyqty,
- sbt.sellqty,
- sbt.closestatus,
- sum(case bt.contracttype
- when 1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) tradebuyqty,
- sum(case bt.contracttype
- when 1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) tradebuyamount,
- sum(case bt.contracttype
- when -1 then
- bt.relatedqty - bt.cancelledqty
- else
- 0
- end) tradesellqty,
- sum(case bt.contracttype
- when -1 then
- bt.relatedamount - bt.cancelledamount
- else
- 0
- end) tradesellamount
- from erms3_biztradedetail bt
- left join erms2_spottradebiz sbt
- on sbt.spottradeid = bt.relatedbizid
- where sbt.spotaccountid in (%v)
- and sbt.closestatus = %v
- group by sbt.spottradeid,
- sbt.deliverygoodsid,
- sbt.buyqty,
- sbt.sellqty,
- sbt.closestatus`
- return fmt.Sprintf(statement, accountids, status)
- }
- // GetByAccountIDSAndStatus 根据账号和状态获取现货贸易业务.
- func (stb Erms2Spottradebiz) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2SpottradebizInfo, error) {
- engine := db.GetEngine()
- data := make([]Erms2SpottradebizInfo, 0)
- err := engine.SQL(stb.buildSQL(accountids, status)).Find(&data)
- return data, err
- }
|