Ver código fonte

增加“分时图数据查询”接口

zhou.xiaoning 4 anos atrás
pai
commit
b9fa256fae

+ 1 - 0
controllers/ermcp/qryOrder.go

@@ -0,0 +1 @@
+package ermcp

+ 171 - 16
controllers/quote/history.go

@@ -139,7 +139,7 @@ type QueryTSDataRsp struct {
 	TradeDate    string        `json:"tradeDate"`    // 交易日
 	StartTime    time.Time     `json:"startTime"`    // 开始时间
 	EndTime      time.Time     `json:"endTime"`      // 结束时间
-	PreSettle    float32       `json:"preSettle"`    // 昨结
+	PreSettle    float64       `json:"preSettle"`    // 昨结
 	HistoryDatas []HistoryData `json:"historyDatas"` // 历史数据
 }
 
@@ -163,6 +163,14 @@ func QueryTSData(c *gin.Context) {
 	}
 
 	// FIXME: - 一些不常变化的数据(如市场信息、商品信息等)应缓存到Redis中, 或缓存到服务内存
+	// 获取商品信息
+	goods, err := models.GetGoodsByGoodsCode(req.GoodsCode)
+	if goods == nil {
+		logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_GET_GOODS_FAILED, nil)
+		return
+	}
+	// 获取市场
 	market, err := models.GetMarketByGoodsCode(req.GoodsCode)
 	if err != nil {
 		logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
@@ -190,13 +198,13 @@ func QueryTSData(c *gin.Context) {
 	// 通道交易外部市场开休市计划表 - QuoteSourceGroupRunStep; 其它市场的 - MarketRunStepDetail
 	if market.Trademode == 15 {
 		// 外部市场
-		sourceRunSteps, err := models.FindQuoteSourceGroupRunStepsByMarket(*market)
+		sourceRunSteps, err := models.FindQuoteSourceGroupRunSteps(*goods)
 		if err != nil {
 			logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
 			appG.Response(http.StatusBadRequest, e.ERROR_GET_RUNSTEP_FAILED, nil)
 			return
 		}
-		for v := range sourceRunSteps {
+		for _, v := range sourceRunSteps {
 			// struct -> json
 			if jsonBytes, err := json.Marshal(v); err == nil {
 				// json -> struct
@@ -227,13 +235,25 @@ func QueryTSData(c *gin.Context) {
 		}
 	}
 
-	// 获取商品信息
-	goods, err := models.GetGoodsByGoodsCode(req.GoodsCode)
-	if goods == nil {
+	// 获取目标商品的盘面信息
+	quoteDays, err := models.GetQuoteDays("'" + goods.Outgoodscode + "'")
+	if err != nil {
 		logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_GET_GOODS_FAILED, nil)
 		return
 	}
+	var preSettle float64
+	var preSettleInt int
+	if len(quoteDays) > 0 {
+		if quoteDays[0].Presettle != 0 {
+			preSettleInt = int(quoteDays[0].Presettle)
+			preSettle = utils.IntToFloat64(preSettleInt, int(goods.Decimalplace))
+		}
+		if preSettle == 0 && quoteDays[0].Preclose != 0 {
+			preSettleInt = int(quoteDays[0].Preclose)
+			preSettle = utils.IntToFloat64(preSettleInt, int(goods.Decimalplace))
+		}
+	}
 
 	// 构建返回数据
 	queryTSDataRsp := QueryTSDataRsp{
@@ -241,6 +261,7 @@ func QueryTSData(c *gin.Context) {
 		OutGoodsCode: goods.Outgoodscode,
 		TradeDate:    marketRun.Tradedate,
 		DecimalPlace: int(goods.Decimalplace),
+		PreSettle:    preSettle,
 	}
 
 	// 构建分时图可直接使用的开休市数据
@@ -253,6 +274,7 @@ func QueryTSData(c *gin.Context) {
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
 		return
 	}
+	// !!!开休市计划明细
 	curWeekRunSteps := make([]map[string]interface{}, 0)
 	for _, v := range runSteps {
 		tradeWeekDay := int(v["tradeweekday"].(float64))
@@ -290,7 +312,7 @@ func QueryTSData(c *gin.Context) {
 		duration, _ := time.ParseDuration(fmt.Sprintf("%dh", endInterval*24))
 		queryTSDataRsp.EndTime = queryTSDataRsp.EndTime.Add(duration)
 	}
-	fmt.Printf("开始时间:%s 结束时间:%s\n", queryTSDataRsp.StartTime.Format(timeFormat), queryTSDataRsp.EndTime.Format(timeFormat))
+	// fmt.Printf("开始时间:%s 结束时间:%s\n", queryTSDataRsp.StartTime.Format(timeFormat), queryTSDataRsp.EndTime.Format(timeFormat))
 
 	// 获取目标时间段的历史数据
 	// 这里要注意:由于交易库和行情库由于GoodsCode大小写不一定对得上,所以在使用交易库的商品查询行情数据时间,都要使用OutGoodsCode字段
@@ -301,8 +323,8 @@ func QueryTSData(c *gin.Context) {
 		return
 	}
 	// ==================== 补数据(补休市数据和缺少的数据)====================
-	// 补数据第一步:如果第一数据不是开始时间的,需要补数据
 	if len(cycleDatas) > 0 {
+		// 补数据第一步:如果第一数据不是开始时间的,需要补数据
 		sources := time.Unix(int64(cycleDatas[0].ST), 0)
 		diff := sources.Sub(queryTSDataRsp.StartTime)
 		if diff.Minutes() > 0 {
@@ -322,6 +344,7 @@ func QueryTSData(c *gin.Context) {
 					SP:    cycleDatas[0].SP,
 					ST:    st,
 					SST:   stt,
+					FI:    true,
 				})
 			}
 		}
@@ -329,19 +352,23 @@ func QueryTSData(c *gin.Context) {
 		sort.Slice(cycleDatas, func(i int, j int) bool {
 			return cycleDatas[i].ST < cycleDatas[j].ST
 		})
-	}
-	// 补数据第二步:按尾部的时间(当前服务器时间或最后休市时间)进行全补
-	if len(cycleDatas) > 0 {
+
+		// 补数据第二步:按尾部的时间(当前服务器时间或最后休市时间)进行全补
+		// 获取服务器时间
 		s, _ := models.GetServerTime()
-		endTime, _ := time.ParseInLocation("2006/01/02 15:04:05", *s, time.Local)
+		endTime, err := time.ParseInLocation("2006-01-02T15:04:05Z", *s, time.Local)
+		if err != nil {
+			logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
 		if endTime.After(queryTSDataRsp.EndTime) {
 			endTime = queryTSDataRsp.EndTime
 		}
 
-		// 判断是否需要补数据,与上一条数据的间距不是一分钟
 		index := len(cycleDatas) - 1
-		sources := time.Unix(int64(cycleDatas[index].ST), 0)
-		diff := sources.Sub(endTime)
+		sources = time.Unix(int64(cycleDatas[index].ST), 0)
+		diff = endTime.Sub(sources)
 		if diff.Minutes() > 0 {
 			minute := int(diff.Minutes())
 			for i := 0; i < minute; i++ {
@@ -359,6 +386,7 @@ func QueryTSData(c *gin.Context) {
 					SP:    cycleDatas[index].SP,
 					ST:    st,
 					SST:   stt,
+					FI:    true,
 				})
 			}
 		}
@@ -366,8 +394,135 @@ func QueryTSData(c *gin.Context) {
 		sort.Slice(cycleDatas, func(i int, j int) bool {
 			return cycleDatas[i].ST < cycleDatas[j].ST
 		})
+
+		// 补数据第三步:补中间数据
+		fillDatas := make([]models.CycleData, 0)
+		for i := range cycleDatas {
+			// 第一条记录跳过
+			if i == 0 {
+				continue
+			}
+
+			current := time.Unix(int64(cycleDatas[i].ST), 0)
+			prev := time.Unix(int64(cycleDatas[i-1].ST), 0)
+			diff := current.Sub(prev)
+			if diff.Minutes() > 0 {
+				minute := int(diff.Minutes())
+				// 判断是否需要补数据,与上一条数据的间距不是一分钟
+				if minute > 1 {
+					for j := 1; j < minute; j++ {
+						st := cycleDatas[i-1].ST + j*60
+						stt := time.Unix(int64(st), 0).Format("2006-01-02 15:04:05")
+						fillDatas = append(fillDatas, models.CycleData{
+							GC:    cycleDatas[i-1].GC,
+							Open:  cycleDatas[i-1].Open,
+							High:  cycleDatas[i-1].High,
+							Low:   cycleDatas[i-1].Low,
+							Close: cycleDatas[i-1].Close,
+							TV:    cycleDatas[i-1].TV,
+							TT:    cycleDatas[i-1].TT,
+							HV:    cycleDatas[i-1].HV,
+							SP:    cycleDatas[i-1].SP,
+							ST:    st,
+							SST:   stt,
+							FI:    true,
+						})
+					}
+				}
+			}
+		}
+		// 加入到源数据
+		cycleDatas = append(cycleDatas, fillDatas...)
+		// 接时间戳排序
+		sort.Slice(cycleDatas, func(i int, j int) bool {
+			return cycleDatas[i].ST < cycleDatas[j].ST
+		})
+	} else {
+		// TODO: - 下面这块操作需求确认
+		// 如果查询结果是空数据,则使用昨结价补到服务器时间(或最后休市时间)
+		// 获取服务器时间
+		s, _ := models.GetServerTime()
+		endTime, err := time.ParseInLocation("2006-01-02T15:04:05Z", *s, time.Local)
+		if err != nil {
+			logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
+		if endTime.After(queryTSDataRsp.EndTime) {
+			endTime = queryTSDataRsp.EndTime
+		}
+
+		diff := endTime.Sub(queryTSDataRsp.StartTime)
+		minute := int(diff.Minutes())
+		for i := 0; i < minute; i++ {
+			st := int(queryTSDataRsp.StartTime.Unix()) + i*60
+			stt := time.Unix(int64(st), 0).Format("2006-01-02 15:04:05")
+			cycleDatas = append(cycleDatas, models.CycleData{
+				GC:    queryTSDataRsp.GoodsCode,
+				Open:  preSettleInt,
+				High:  preSettleInt,
+				Low:   preSettleInt,
+				Close: preSettleInt,
+				TV:    0,
+				TT:    0,
+				HV:    0,
+				SP:    0,
+				ST:    st,
+				SST:   stt,
+				FI:    true,
+			})
+		}
+		// 接时间戳排序
+		sort.Slice(cycleDatas, func(i int, j int) bool {
+			return cycleDatas[i].ST < cycleDatas[j].ST
+		})
+	}
+
+	// 补数据第四步:清除掉开市计划外的数据
+	// 先计算出每条计划明细的真正开始与结束时间
+	for _, v := range curWeekRunSteps {
+		// 开始时间
+		startInterval := getTradeDay(int(v["tradeweekday"].(float64)), int(v["startweekday"].(float64)))
+		v["start"], _ = time.ParseInLocation(timeFormat, fmt.Sprintf("%s %s", marketRun.Tradedate, v["starttime"].(string)), time.Local)
+		if startInterval != 0 {
+			duration, _ := time.ParseDuration(fmt.Sprintf("%dh", startInterval*24))
+			v["start"] = v["start"].(time.Time).Add(duration)
+		}
+		// 结束时间
+		endInterval := getTradeDay(int(v["tradeweekday"].(float64)), int(v["endweekday"].(float64)))
+		v["end"], _ = time.ParseInLocation(timeFormat, fmt.Sprintf("%s %s", marketRun.Tradedate, v["endtime"].(string)), time.Local)
+		if endInterval != 0 {
+			duration, _ := time.ParseDuration(fmt.Sprintf("%dh", endInterval*24))
+			v["end"] = v["end"].(time.Time).Add(duration)
+		}
+	}
+	// 最终返回的历史数据
+	historyDatas := make([]HistoryData, 0)
+	for _, cycleData := range cycleDatas {
+		needAdd := false
+		for _, runStep := range curWeekRunSteps {
+			// 判断是否在开市计划内
+			if cycleData.ST >= int(runStep["start"].(time.Time).Unix()) && cycleData.ST <= int(runStep["end"].(time.Time).Unix()) {
+				needAdd = true
+				break
+			}
+		}
+		if needAdd {
+			historyDatas = append(historyDatas, HistoryData{
+				Opened:        utils.IntToFloat64(cycleData.Open, int(goods.Decimalplace)),
+				Highest:       utils.IntToFloat64(cycleData.High, int(goods.Decimalplace)),
+				Lowest:        utils.IntToFloat64(cycleData.Low, int(goods.Decimalplace)),
+				Closed:        utils.IntToFloat64(cycleData.Close, int(goods.Decimalplace)),
+				TotleVolume:   cycleData.TV,
+				TotleTurnover: float64(cycleData.TT),
+				HoldVolume:    cycleData.HV,
+				Settle:        utils.IntToFloat64(cycleData.SP, int(goods.Decimalplace)),
+				TimeStamp:     time.Unix(int64(cycleData.ST), 0),
+				IsFill:        cycleData.FI,
+			})
+		}
 	}
-	// 补数据第三步:补中间数据
+	queryTSDataRsp.HistoryDatas = historyDatas
 
 	// 查询成功
 	logger.GetLogger().Debugln("QueryTSData successed: %v", queryTSDataRsp)

+ 2 - 0
models/ermcpGoods.go

@@ -1,5 +1,7 @@
 package models
 
+// 企业风管期货商品相关
+
 import "mtp2_if/db"
 
 // GetErmcpGoodses 企业风管专用获取商品信息的方法

+ 147 - 0
models/ermcpOrder.go

@@ -0,0 +1,147 @@
+package models
+
+import "time"
+
+// 企业风管期货单据相关
+
+// Hedgeouttradeposition 对冲外部持仓头寸表 - 导历史
+type Hedgeouttradeposition struct {
+	Accountid         int64  `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"`       // 资金账号[外部母账户]
+	Hedgegoodsid      int64  `json:"hedgegoodsid"  xorm:"'HEDGEGOODSID'" binding:"required"` // 对冲合约ID
+	Hedgeaccountcode  string `json:"hedgeaccountcode"  xorm:"'HEDGEACCOUNTCODE'"`            // 对冲账号
+	Tradedate         string `json:"tradedate"  xorm:"'TRADEDATE'"`                          // 交易日(yyyyMMdd)
+	Marketid          int32  `json:"marketid"  xorm:"'MARKETID'"`                            // 市场ID
+	Ydbuyposition     int64  `json:"ydbuyposition"  xorm:"'YDBUYPOSITION'"`                  // 期初买头寸
+	Curbuyposition    int64  `json:"curbuyposition"  xorm:"'CURBUYPOSITION'"`                // 期末买头寸
+	Curydbuyposition  int64  `json:"curydbuyposition"  xorm:"'CURYDBUYPOSITION'"`            // 期末上日买头寸
+	Curtdbuyposition  int64  `json:"curtdbuyposition"  xorm:"'CURTDBUYPOSITION'"`            // 期末今日买头寸
+	Freydbuyposition  int64  `json:"freydbuyposition"  xorm:"'FREYDBUYPOSITION'"`            // 冻结上日买头寸
+	Fretdbuyposition  int64  `json:"fretdbuyposition"  xorm:"'FRETDBUYPOSITION'"`            // 冻结今日买头寸
+	Ydsellposition    int64  `json:"ydsellposition"  xorm:"'YDSELLPOSITION'"`                // 期初卖头寸
+	Cursellposition   int64  `json:"cursellposition"  xorm:"'CURSELLPOSITION'"`              // 期末卖头寸
+	Curydsellposition int64  `json:"curydsellposition"  xorm:"'CURYDSELLPOSITION'"`          // 期末上日卖头寸
+	Curtdsellposition int64  `json:"curtdsellposition"  xorm:"'CURTDSELLPOSITION'"`          // 期末今日卖头寸
+	Freydsellposition int64  `json:"freydsellposition"  xorm:"'FREYDSELLPOSITION'"`          // 冻结上日卖头寸
+	Fretdsellposition int64  `json:"fretdsellposition"  xorm:"'FRETDSELLPOSITION'"`          // 冻结今日卖头寸
+}
+
+// TableName is HEDGE_OUTTRADEPOSITION
+func (Hedgeouttradeposition) TableName() string {
+	return "HEDGE_OUTTRADEPOSITION"
+}
+
+// Hedgeinnerorderdetail 对冲内部委托单表 - 导历史
+type Hedgeinnerorderdetail struct {
+	Orderid                 int64     `json:"orderid"  xorm:"'ORDERID'" binding:"required"`              // 委托单号(107+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+	Tradedate               string    `json:"tradedate"  xorm:"'TRADEDATE'"`                             // 交易日(yyyyMMdd)
+	Channelbuildtype        int32     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`               // 开平标志 - 0:无 1:建仓 2:平仓
+	Closetype               int32     `json:"closetype"  xorm:"'CLOSETYPE'"`                             // 平仓方式 - 0:无 1:平今 2:平昨
+	Hedgeflag               int32     `json:"hedgeflag"  xorm:"'HEDGEFLAG'"`                             // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
+	Marketid                int32     `json:"marketid"  xorm:"'MARKETID'"`                               // 市场ID
+	Goodsid                 int32     `json:"goodsid"  xorm:"'GOODSID'"`                                 // 商品ID
+	Accountid               int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                             // 账户ID
+	Buyorsell               int32     `json:"buyorsell"  xorm:"'BUYORSELL'"`                             // 买卖 - 0:买 1:卖
+	Pricemode               int32     `json:"pricemode"  xorm:"'PRICEMODE'"`                             // 取价方式 - 1:市价 2: 限价
+	Orderprice              float64   `json:"orderprice"  xorm:"'ORDERPRICE'"`                           // 委托价格(账户)
+	Openorderqty            int64     `json:"openorderqty"  xorm:"'OPENORDERQTY'"`                       // 委托数量
+	Opentradeqty            int64     `json:"opentradeqty"  xorm:"'OPENTRADEQTY'"`                       // 成交数量
+	Opencancelqty           int64     `json:"opencancelqty"  xorm:"'OPENCANCELQTY'"`                     // 撤单数量
+	Openfailqty             int64     `json:"openfailqty"  xorm:"'OPENFAILQTY'"`                         // 失败数量
+	Opensuccessqty          int64     `json:"opensuccessqty"  xorm:"'OPENSUCCESSQTY'"`                   // 建仓委托成功数量
+	Closeorderqty           int64     `json:"closeorderqty"  xorm:"'CLOSEORDERQTY'"`                     // 委托数量
+	Closetradeqty           int64     `json:"closetradeqty"  xorm:"'CLOSETRADEQTY'"`                     // 成交数量
+	Closecancelqty          int64     `json:"closecancelqty"  xorm:"'CLOSECANCELQTY'"`                   // 撤单数量
+	Closefailqty            int64     `json:"closefailqty"  xorm:"'CLOSEFAILQTY'"`                       // 失败数量
+	Closesuccessqty         int64     `json:"closesuccessqty"  xorm:"'CLOSESUCCESSQTY'"`                 // 委托成功数量
+	Openfreezemargin        float64   `json:"openfreezemargin"  xorm:"'OPENFREEZEMARGIN'"`               // 冻结保证金(冻结交易金额)
+	Openunfreezemargin      float64   `json:"openunfreezemargin"  xorm:"'OPENUNFREEZEMARGIN'"`           // 解冻保证金
+	Openfreezecharge        float64   `json:"openfreezecharge"  xorm:"'OPENFREEZECHARGE'"`               // 建仓冻结手续费(账户)
+	Openunfreezecharge      float64   `json:"openunfreezecharge"  xorm:"'OPENUNFREEZECHARGE'"`           // 建仓解冻手续费(账户)
+	Validtype               int32     `json:"validtype"  xorm:"'VALIDTYPE'"`                             // 有效类型 - 1当日有效
+	Validtime               time.Time `json:"validtime"  xorm:"'VALIDTIME'"`                             // 有效期限
+	Channeloperatetype      int32     `json:"channeloperatetype"  xorm:"'CHANNELOPERATETYPE'"`           // 操作类型 - 1:正常委托 2:斩仓委托 3:强平委托
+	Ordertime               time.Time `json:"ordertime"  xorm:"'ORDERTIME'"`                             // 委托时间
+	Channelordersrc         int32     `json:"channelordersrc"  xorm:"'CHANNELORDERSRC'"`                 // 委托来源 -  1:客户端 2:风控服务 3:管理端 4:下单接口平台 5:交易服务 6:跟单服务 7:监控终端
+	Channelinnerorderstatus int32     `json:"channelinnerorderstatus"  xorm:"'CHANNELINNERORDERSTATUS'"` // 委托状态 - 1:委托请求 2:冻结成功 3:委托失败 4:委托部成部失败                  5:委托成功 6:全部撤销 7:部成部撤 8:部成部撤部失败 9:全部成交
+	Operatorid              int64     `json:"operatorid"  xorm:"'OPERATORID'"`                           // 登录账号(LoginID)
+	Updatetime              time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                           // 更新时间
+	Clientordertime         time.Time `json:"clientordertime"  xorm:"'CLIENTORDERTIME'"`                 // 客户端委托时间
+	Clientticket            string    `json:"clientticket"  xorm:"'CLIENTTICKET'"`                       // 客户端流水号
+	Uuid                    string    `json:"uuid"  xorm:"'UUID'"`                                       // 发起端唯一id
+	Clienttype              int32     `json:"clienttype"  xorm:"'CLIENTTYPE'"`                           // 客户端类型 - 0:保留为未填终端类型 1:PC管理端 2:PC交易端 3:手机客户端_安卓 4:网页客户端 5:微信客户端 6:手机客户端_苹果 7:网上开户客户端 8:无效终端编号 9:报价终端(中江) 10;监控终端
+	Retcode                 int32     `json:"retcode"  xorm:"'RETCODE'"`                                 // 错误代码
+	Marginalgorithm         int32     `json:"marginalgorithm"  xorm:"'MARGINALGORITHM'"`                 // 保证金收取方式  1:比率  2:固定
+	Marginvalue             float64   `json:"marginvalue"  xorm:"'MARGINVALUE'"`                         // 即市保证金设置值
+	Openfeealgorithm        int32     `json:"openfeealgorithm"  xorm:"'OPENFEEALGORITHM'"`               // 建仓手续费收取方式  1:比率  2:固定
+	Openchargevalue         float64   `json:"openchargevalue"  xorm:"'OPENCHARGEVALUE'"`                 // 建仓手续费设置值
+	Closefeealgorithm       int32     `json:"closefeealgorithm"  xorm:"'CLOSEFEEALGORITHM'"`             // 平仓手续费收取方式 1:比率  2:固定
+	Closechargevalue        float64   `json:"closechargevalue"  xorm:"'CLOSECHARGEVALUE'"`               // 平仓手续费设置值
+	Accountcurrencyid       int32     `json:"accountcurrencyid"  xorm:"'ACCOUNTCURRENCYID'"`             // 账户币种ID
+	Goodscurrencyid         int32     `json:"goodscurrencyid"  xorm:"'GOODSCURRENCYID'"`                 // 商品币种ID
+	Margincurrencyid        int32     `json:"margincurrencyid"  xorm:"'MARGINCURRENCYID'"`               // 保证金币种ID 比率时等于账户币种
+	Marginrate              float64   `json:"marginrate"  xorm:"'MARGINRATE'"`                           // 保证金汇率-比率时等于1
+	Curexchangerate         float64   `json:"curexchangerate"  xorm:"'CUREXCHANGERATE'"`                 // 当前汇率
+	Goodsorderprice         float64   `json:"goodsorderprice"  xorm:"'GOODSORDERPRICE'"`                 // 委托价格(商品)
+	Openfreezemargin2       float64   `json:"openfreezemargin2"  xorm:"'OPENFREEZEMARGIN2'"`             // 建仓冻结保证金(保证金/商品)
+	Openfreezecharge2       float64   `json:"openfreezecharge2"  xorm:"'OPENFREEZECHARGE2'"`             // 建仓冻结手续费(商品)
+	Openunfreezemargin2     float64   `json:"openunfreezemargin2"  xorm:"'OPENUNFREEZEMARGIN2'"`         // 建仓解冻保证金(保证金/商品)
+	Openunfreezecharge2     float64   `json:"openunfreezecharge2"  xorm:"'OPENUNFREEZECHARGE2'"`         // 建仓解冻手续费(商品)
+	Parentaccountid         int64     `json:"parentaccountid"  xorm:"'PARENTACCOUNTID'"`                 // 所属母账户
+	Sessionid               int64     `json:"sessionid"  xorm:"'SESSIONID'"`                             // 会话ID
+}
+
+// TableName is HEDGE_INNERORDERDETAIL
+func (Hedgeinnerorderdetail) TableName() string {
+	return "HEDGE_INNERORDERDETAIL"
+}
+
+// Hedgeinnertradedetail 对冲内部成交单表 - 导历史
+type Hedgeinnertradedetail struct {
+	Tradeid                  int64     `json:"tradeid"  xorm:"'TRADEID'" binding:"required"`                // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+	Buyorsell                int32     `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                  int32     `json:"goodsid"  xorm:"'GOODSID'"`                                   // 商品ID
+	Marketid                 int32     `json:"marketid"  xorm:"'MARKETID'"`                                 // 市场ID
+	Tradetime                time.Time `json:"tradetime"  xorm:"'TRADETIME'"`                               // 成交时间
+	Tradeprice               float64   `json:"tradeprice"  xorm:"'TRADEPRICE'"`                             // 成交价格
+	Tradeqty                 int64     `json:"tradeqty"  xorm:"'TRADEQTY'"`                                 // 成交数量
+	Tradeamount              float64   `json:"tradeamount"  xorm:"'TRADEAMOUNT'"`                           // 成交金额(账户)
+	Closepl                  float64   `json:"closepl"  xorm:"'CLOSEPL'"`                                   // 平仓盈亏(账户)
+	Opencharge               float64   `json:"opencharge"  xorm:"'OPENCHARGE'"`                             // 建仓手续费(账户)
+	Closecharge              float64   `json:"closecharge"  xorm:"'CLOSECHARGE'"`                           // 平仓手续费(账户)
+	Tradetype                int32     `json:"tradetype"  xorm:"'TRADETYPE'"`                               // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
+	Channelbuildtype         int32     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`                 // 委托单据类型 0:无 1:建仓 2:平仓
+	Closetype                int32     `json:"closetype"  xorm:"'CLOSETYPE'"`                               // 平仓方式 - 0:无 1:平今 2:平昨
+	Hedgeflag                int32     `json:"hedgeflag"  xorm:"'HEDGEFLAG'"`                               // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
+	Openqty                  int64     `json:"openqty"  xorm:"'OPENQTY'"`                                   // 开仓数量(先建后平操作 需要记录)
+	Closeqty                 int64     `json:"closeqty"  xorm:"'CLOSEQTY'"`                                 // 平仓数量(先建后平操作 需要记录)
+	Status                   int32     `json:"status"  xorm:"'STATUS'"`                                     // 处理状态 - 1:待处理 2:已处理 3:处理失败
+	Isreckoned               int32     `json:"isreckoned"  xorm:"'ISRECKONED'"`                             // 是否结算 - 0:未结算 1:已结算
+	Openfeealgorithm         int32     `json:"openfeealgorithm"  xorm:"'OPENFEEALGORITHM'"`                 // 建仓手续费收取方式  1:比率  2:固定
+	Openchargevalue          float64   `json:"openchargevalue"  xorm:"'OPENCHARGEVALUE'"`                   // 建仓手续费设置值
+	Closefeealgorithm        int32     `json:"closefeealgorithm"  xorm:"'CLOSEFEEALGORITHM'"`               // 平仓手续费收取方式 1:比率  2:固定
+	Closechargevalue         float64   `json:"closechargevalue"  xorm:"'CLOSECHARGEVALUE'"`                 // 平仓手续费设置值
+	Accountcurrencyid        int32     `json:"accountcurrencyid"  xorm:"'ACCOUNTCURRENCYID'"`               // 账户币种ID
+	Goodscurrencyid          int32     `json:"goodscurrencyid"  xorm:"'GOODSCURRENCYID'"`                   // 商品币种ID
+	Curexchangerate          float64   `json:"curexchangerate"  xorm:"'CUREXCHANGERATE'"`                   // 当前汇率
+	Opencharge2              float64   `json:"opencharge2"  xorm:"'OPENCHARGE2'"`                           // 建仓手续费(商品)
+	Closecharge2             float64   `json:"closecharge2"  xorm:"'CLOSECHARGE2'"`                         // 平仓手续费(商品)
+	Closepl2                 float64   `json:"closepl2"  xorm:"'CLOSEPL2'"`                                 // 平仓盈亏(商品)
+	Closepl3                 float64   `json:"closepl3"  xorm:"'CLOSEPL3'"`                                 // 平仓盈亏(账户)(逐笔)
+	Closepl4                 float64   `json:"closepl4"  xorm:"'CLOSEPL4'"`                                 // 平仓盈亏(商品)(逐笔)
+	Extenalopenfeealgorithm  int32     `json:"extenalopenfeealgorithm"  xorm:"'EXTENALOPENFEEALGORITHM'"`   // 建仓手续费收取方式(外部配置) 1:比率  2:固定
+	Extenalopenchargevalue   float64   `json:"extenalopenchargevalue"  xorm:"'EXTENALOPENCHARGEVALUE'"`     // 建仓手续费设置值
+	Extenalclosefeealgorithm int32     `json:"extenalclosefeealgorithm"  xorm:"'EXTENALCLOSEFEEALGORITHM'"` // 平仓手续费收取方式 1:比率  2:固定
+	Extenalclosechargevalue  float64   `json:"extenalclosechargevalue"  xorm:"'EXTENALCLOSECHARGEVALUE'"`   // 平仓手续费设置值
+	Extenalopencharge        float64   `json:"extenalopencharge"  xorm:"'EXTENALOPENCHARGE'"`               // 建仓手续费(商品)(外部)
+	Extenalclosecharge       float64   `json:"extenalclosecharge"  xorm:"'EXTENALCLOSECHARGE'"`             // 平仓手续费(商品)(外部)
+	Parentaccountid          int64     `json:"parentaccountid"  xorm:"'PARENTACCOUNTID'"`                   // 所属母账户
+	Relatedouttradeid        int64     `json:"relatedouttradeid"  xorm:"'RELATEDOUTTRADEID'"`               // 关联外部成交单ID
+}
+
+// TableName is HEDGE_INNERTRADEDETAIL
+func (Hedgeinnertradedetail) TableName() string {
+	return "HEDGE_INNERTRADEDETAIL"
+}

+ 0 - 51
models/erms2.go

@@ -7,57 +7,6 @@ import (
 	"time"
 )
 
-// Hedgeinnertradedetail 对冲内部成交单表 - 导历史
-type Hedgeinnertradedetail 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
-}
-
-// TableName is HEDGE_INNERTRADEDETAIL
-func (Hedgeinnertradedetail) TableName() string {
-	return "HEDGE_INNERTRADEDETAIL"
-}
-
 // Erms2astradedetails 期现套利期货成交单关联表
 type Erms2astradedetails struct {
 	Asapplyid      int64     `json:"asapplyid"  xorm:"'ASAPPLYID'" binding:"required"`   // 策略申请ID

+ 15 - 12
models/market.go

@@ -1,7 +1,6 @@
 package models
 
 import (
-	"errors"
 	"mtp2_if/db"
 	"strconv"
 	"time"
@@ -265,20 +264,24 @@ func GetMarketRuns(marketID int) ([]Marketrun, error) {
 	return marketRuns, nil
 }
 
-// FindQuoteSourceGroupRunStepsByMarket 通过市场获取对应的行情源分组开休市计划明细信息
-// 参数 market Market 市场信息
-// 返回值 []Quotesourcegrouprunstep 行情源分组开休市计划明细信息
-// 返回值 error 错误
-func FindQuoteSourceGroupRunStepsByMarket(market Market) ([]Quotesourcegrouprunstep, error) {
-	if market.Trademode != 15 {
-		return nil, errors.New("目标市场非外部市场")
-	}
+// FindQuoteSourceGroupRunSteps 获取行情源分组开休市计划明细信息
+func FindQuoteSourceGroupRunSteps(goods Goods) ([]Quotesourcegrouprunstep, error) {
+	// if market.Trademode != 15 {
+	// 	return nil, errors.New("目标市场非外部市场")
+	// }
 
 	engine := db.GetEngine()
 	runSteps := make([]Quotesourcegrouprunstep, 0)
-	if err := engine.Join("INNER", "GOODSGROUP", "GOODSGROUP.GOODSGROUPID = QUOTESOURCEGROUPRUNSTEP.GROUPID").
-		Join("INNER", "MARKET", "MARKET.MARKETID = GOODSGROUP.MARKETID").
-		Where("QUOTESOURCEGROUPRUNSTEP.SECTIONID <> 0 and MARKET.MARKETID = ?", market.Marketid).Find(&runSteps); err != nil {
+	// if err := engine.Join("INNER", "GOODSGROUP", "GOODSGROUP.GOODSGROUPID = QUOTESOURCEGROUPRUNSTEP.GROUPID").
+	// 	Join("INNER", "MARKET", "MARKET.MARKETID = GOODSGROUP.MARKETID").
+	// 	Where("QUOTESOURCEGROUPRUNSTEP.SECTIONID <> 0 and MARKET.MARKETID = ?", market.Marketid).Find(&runSteps); err != nil {
+	// 	return nil, err
+	// }
+	if err := engine.Table("QUOTESOURCEGROUPRUNSTEP T").
+		Join("INNER", "GOODSGROUP GG", "GG.QUOTESOURCEGROUPID = T.GROUPID").
+		Where("GG.GOODSGROUPID = ?", goods.Goodsgroupid).
+		And("T.SECTIONID <> 0").
+		Find(&runSteps); err != nil {
 		return nil, err
 	}
 

+ 1 - 0
models/quote.go

@@ -47,6 +47,7 @@ type CycleData struct {
 	TT    int           `bson:"TT"`           // 总金额
 	HV    int           `bson:"HV"`           // 持仓量
 	SP    int           `bson:"SP"`           // 结算价,日线周期(包括)以上才有
+	FI    bool          `json:"FI"`           // 是否补充数据
 }
 
 // Quoteday 行情盘面