|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"mtp2_if/global/e"
|
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/models"
|
|
|
+ "mtp2_if/utils"
|
|
|
"net/http"
|
|
|
"sort"
|
|
|
"time"
|
|
|
@@ -15,15 +16,15 @@ import (
|
|
|
|
|
|
// 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"` // 开盘时间
|
|
|
+ Opened float64 `json:"o"` // 开盘价
|
|
|
+ Highest float64 `json:"h"` // 最高价
|
|
|
+ Lowest float64 `json:"l"` // 最低价
|
|
|
+ Closed float64 `json:"c"` // 收盘价
|
|
|
+ TotleVolume int `json:"tv"` // 总量
|
|
|
+ TotleTurnover float64 `json:"tt"` // 总金额
|
|
|
+ HoldVolume int `json:"hv"` // 持仓量
|
|
|
+ Settle float64 `json:"s"` // 结算价,日线周期(包括)以上才有
|
|
|
+ TimeStamp time.Time `json:"ts"` // 开盘时间
|
|
|
}
|
|
|
|
|
|
// QueryHistoryDatasReq 查询行情历史数据请求参数
|
|
|
@@ -46,7 +47,7 @@ type QueryHistoryDatasReq struct {
|
|
|
// @Param endTime query string false "结束时间,格式:yyyy-MM-dd HH:mm:ss"
|
|
|
// @Param count query int false "条数"
|
|
|
// @Param IsAsc query bool false "是否按时间顺序排序(默认为时间倒序排序)"
|
|
|
-// @Success 200 {object} models.CycleData
|
|
|
+// @Success 200 {object} models.HistoryData
|
|
|
// @Failure 500 {object} app.Response
|
|
|
// @Router /Quote/QueryHistoryDatas [get]
|
|
|
// @Tags 行情服务
|
|
|
@@ -85,16 +86,42 @@ func QueryHistoryDatas(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
// 查询数据
|
|
|
- cycleData, err := models.GetHistoryCycleDatas(models.CycleType(req.CycleType), req.GoodsCode, startTime, endTime, req.Count, req.IsAsc)
|
|
|
+ cycleDatas, err := models.GetHistoryCycleDatas(models.CycleType(req.CycleType), req.GoodsCode, startTime, endTime, req.Count, req.IsAsc)
|
|
|
if err != nil {
|
|
|
logger.GetLogger().Errorf("QueryTSData 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("QueryTSData failed: %s", err.Error())
|
|
|
+ appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算最终价格
|
|
|
+ rst := make([]HistoryData, 0)
|
|
|
+ for _, v := range cycleDatas {
|
|
|
+ historyData := HistoryData{
|
|
|
+ Opened: utils.IntToFloat64(v.Open, int(goods.Decimalplace)),
|
|
|
+ Highest: utils.IntToFloat64(v.High, int(goods.Decimalplace)),
|
|
|
+ Lowest: utils.IntToFloat64(v.Low, int(goods.Decimalplace)),
|
|
|
+ Closed: utils.IntToFloat64(v.Close, int(goods.Decimalplace)),
|
|
|
+ TotleVolume: v.TV,
|
|
|
+ TotleTurnover: float64(v.TT),
|
|
|
+ HoldVolume: v.HV,
|
|
|
+ Settle: utils.IntToFloat64(v.SP, int(goods.Decimalplace)),
|
|
|
+ TimeStamp: time.Unix(int64(v.ST), 0),
|
|
|
+ }
|
|
|
+
|
|
|
+ rst = append(rst, historyData)
|
|
|
+ }
|
|
|
+
|
|
|
// 查询成功
|
|
|
- logger.GetLogger().Debugln("QueryHistoryDatas successed: %v", cycleData)
|
|
|
- appG.Response(http.StatusOK, e.SUCCESS, cycleData)
|
|
|
+ logger.GetLogger().Debugln("QueryHistoryDatas successed: %v", rst)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, rst)
|
|
|
}
|
|
|
|
|
|
// QueryTSDataReq 分时图数据查询请求参数
|