| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package quote
- import (
- "mtp2_if/global/app"
- "mtp2_if/global/e"
- "mtp2_if/logger"
- "mtp2_if/models"
- "net/http"
- "time"
- "github.com/gin-gonic/gin"
- )
- // HistoryData 历史数据
- type HistoryData struct {
- Opened float32 `json:"Opened"` // 开盘价
- Highest float32 `json:"highest"` // 收盘价
- Lowest float32 `json:"lowest"` // 最低价
- Closed float32 `json:"closed"` // 收盘价
- TotleVolume float32 `json:"totleVolume"` // 总量
- TotleTurnover float32 `json:"totleTurnover"` // 总金额
- HoldVolume float32 `json:"holdVolume"` // 持仓量
- Settle float32 `json:"settle"` // 结算价
- TimeStamp time.Time `json:"timeStamp"` // 开盘时间
- }
- // QueryTSDataReq 分时图数据查询请求参数
- type QueryTSDataReq struct {
- GoodsCode string `form:"goodsCode" binding:"required"` // 商品代码
- }
- // QueryTSDataRsp 分时图数据查询返回模型
- type QueryTSDataRsp struct {
- GoodsCode string `json:"goodsCode"` // 商品代码
- DecimalPlace int `json:"decimalPlace"` // 小数位
- TradeDate string `json:"tradeDate"` // 交易日
- StartTime string `json:"startTime"` // 开始时间
- EndTime string `json:"endTime"` // 结束时间
- PreSettle float32 `json:"preSettle"` // 昨结
- HistoryDatas []HistoryData `json:"historyDatas"` // 历史数据
- }
- // QueryTSData 分时图数据查询
- // @Summary 分时图数据查询
- // @Produce json
- // @Param GoodsCode query string true "商品代码"
- // @Success 200 {object} QueryTSDataRsp
- // @Failure 500 {object} app.Response
- // @Router /History/QueryTSData [get]
- // @Tags 通用服务
- func QueryTSData(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryTSDataReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- var queryTSDataRsp QueryTSDataRsp
- // 获取目标品种交易日
- // FIXME: - 一些不常变化的数据(如市场信息、商品信息等)应缓存到Redis中
- market, err := models.GetMarketByGoodsCode(req.GoodsCode)
- if err != nil {
- logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- if market == nil {
- logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_GET_MARKET_FAILED, nil)
- return
- }
- // FIXME: - 由于mtp2.0目前未同步外部交易所品种的当前交易日,
- // 故通道交易的品种目前只能在交易系统的外部市场中获
- // 取统一的交易日,后期应要求服务端同步外部数据
- // 获取目标品种的开休市计划
- // 查询成功
- logger.GetLogger().Debugln("QueryTSData successed: %v", queryTSDataRsp)
- appG.Response(http.StatusOK, e.SUCCESS, queryTSDataRsp)
- }
|