|
|
@@ -43,7 +43,7 @@ type QueryHistoryDatasReq struct {
|
|
|
// @Summary 查询行情历史数据
|
|
|
// @Produce json
|
|
|
// @Security ApiKeyAuth
|
|
|
-// @Param cycleType query int true "周期类型, 0-秒 1: 1分钟 2: 5分钟 3: 30分钟 4: 60分钟 120: 2小时 240: 4小时 11: 日线 10: Tik"
|
|
|
+// @Param cycleType query int true "周期类型, 0-秒 1: 1分钟 2: 5分钟 3: 30分钟 4: 60分钟 120: 2小时 240: 4小时 11: 日线"
|
|
|
// @Param goodsCode query string true "商品代码"
|
|
|
// @Param startTime query string false "开始时间,格式:yyyy-MM-dd HH:mm:ss"
|
|
|
// @Param endTime query string false "结束时间,格式:yyyy-MM-dd HH:mm:ss"
|
|
|
@@ -126,6 +126,123 @@ func QueryHistoryDatas(c *gin.Context) {
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, rst)
|
|
|
}
|
|
|
|
|
|
+// HistoryTikData Tik数据
|
|
|
+type HistoryTikData struct {
|
|
|
+ TimeStamp time.Time `json:"TS"` // 行情时间文本
|
|
|
+ PE float64 `json:"PE"` // 现价
|
|
|
+ Vol int `json:"Vol"` // 现量
|
|
|
+ TT float64 `json:"TT"` // 现金额
|
|
|
+ Bid float64 `json:"Bid"` // 买价
|
|
|
+ BV int `json:"BV"` // 买量
|
|
|
+ Ask float64 `json:"Ask"` // 卖价
|
|
|
+ AV int `json:"AV"` // 卖量
|
|
|
+ HV int `json:"HV"` // 持仓量
|
|
|
+ HI int `json:"HI"` // 单笔持仓
|
|
|
+ TDR int `json:"TDR"` // 交易方向,0:买 1:卖
|
|
|
+ TK int `json:"TK"` // 交易类型
|
|
|
+}
|
|
|
+
|
|
|
+// QueryHistoryTikDatasReq 查询行情Tik数据请求参数
|
|
|
+type QueryHistoryTikDatasReq struct {
|
|
|
+ GoodsCode string `form:"goodsCode" binding:"required"`
|
|
|
+ StartTime string `form:"startTime"`
|
|
|
+ EndTime string `form:"endTime"`
|
|
|
+ Count int `form:"count"`
|
|
|
+ IsAsc bool `form:"isAsc"`
|
|
|
+}
|
|
|
+
|
|
|
+// QueryHistoryTikDatas 查询行情Tik数据
|
|
|
+// @Summary 查询行情Tik数据
|
|
|
+// @Produce json
|
|
|
+// @Security ApiKeyAuth
|
|
|
+// @Param goodsCode query string true "商品代码"
|
|
|
+// @Param startTime query string false "开始时间,格式:yyyy-MM-dd HH:mm:ss"
|
|
|
+// @Param endTime query string false "结束时间,格式:yyyy-MM-dd HH:mm:ss"
|
|
|
+// @Param count query int false "条数"
|
|
|
+// @Param isAsc query bool false "是否按时间顺序排序(默认为时间倒序排序)"
|
|
|
+// @Success 200 {object} HistoryTikData
|
|
|
+// @Failure 500 {object} app.Response
|
|
|
+// @Router /Quote/QueryHistoryTikDatas [get]
|
|
|
+// @Tags 行情服务
|
|
|
+func QueryHistoryTikDatas(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ // 获取请求参数
|
|
|
+ var req QueryHistoryTikDatasReq
|
|
|
+ if err := appG.C.ShouldBindQuery(&req); err != nil {
|
|
|
+ logger.GetLogger().Errorf("QueryHistoryTikDatas failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换时间
|
|
|
+ timeFormat := "2006-01-02 15:04:05" // go中的时间格式化必须是这个时间
|
|
|
+ var startTime *time.Time
|
|
|
+ if len(req.StartTime) > 0 {
|
|
|
+ st, err := time.ParseInLocation(timeFormat, req.StartTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("QueryHistoryTikDatas failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_TIME_FORMAT_FAIL, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ startTime = &st
|
|
|
+ }
|
|
|
+ var endTime *time.Time
|
|
|
+ if len(req.EndTime) > 0 {
|
|
|
+ et, err := time.ParseInLocation(timeFormat, req.EndTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("QueryHistoryTikDatas failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_TIME_FORMAT_FAIL, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endTime = &et
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询数据
|
|
|
+ tikDatas, err := models.GetHistoryTikDatas(req.GoodsCode, startTime, endTime, req.Count, req.IsAsc)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("QueryHistoryTikDatas failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取目标商品信息
|
|
|
+ goods, err := models.GetGoodsByGoodsCode(req.GoodsCode)
|
|
|
+ if err != nil {
|
|
|
+ logger.GetLogger().Errorf("QueryHistoryTikDatas failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算最终价格
|
|
|
+ rst := make([]HistoryTikData, 0)
|
|
|
+ for _, v := range tikDatas {
|
|
|
+ // 获取方向
|
|
|
+ buyOrSell := 0
|
|
|
+ if v.TDR == 83 { // (Ascii) B-66 S-83
|
|
|
+ buyOrSell = 1
|
|
|
+ }
|
|
|
+ rst = append(rst, HistoryTikData{
|
|
|
+ TimeStamp: time.Unix(int64(v.AT), 0),
|
|
|
+ PE: utils.IntToFloat64(v.PE, int(goods.Decimalplace)),
|
|
|
+ Vol: v.Vol,
|
|
|
+ TT: float64(v.TT),
|
|
|
+ Bid: utils.IntToFloat64(v.Bid, int(goods.Decimalplace)),
|
|
|
+ BV: v.BV,
|
|
|
+ Ask: utils.IntToFloat64(v.Ask, int(goods.Decimalplace)),
|
|
|
+ AV: v.AV,
|
|
|
+ HV: v.HV,
|
|
|
+ HI: v.HI,
|
|
|
+ TDR: buyOrSell,
|
|
|
+ TK: v.TK,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询成功
|
|
|
+ logger.GetLogger().Debugln("QueryHistoryTikDatas successed: %v", rst)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, rst)
|
|
|
+}
|
|
|
+
|
|
|
// QueryTSDataReq 分时图数据查询请求参数
|
|
|
type QueryTSDataReq struct {
|
|
|
GoodsCode string `form:"goodsCode" binding:"required"` // 商品代码
|