history.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package quote
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "time"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // HistoryData 历史数据
  12. type HistoryData struct {
  13. Opened float32 `json:"Opened"` // 开盘价
  14. Highest float32 `json:"highest"` // 收盘价
  15. Lowest float32 `json:"lowest"` // 最低价
  16. Closed float32 `json:"closed"` // 收盘价
  17. TotleVolume float32 `json:"totleVolume"` // 总量
  18. TotleTurnover float32 `json:"totleTurnover"` // 总金额
  19. HoldVolume float32 `json:"holdVolume"` // 持仓量
  20. Settle float32 `json:"settle"` // 结算价
  21. TimeStamp time.Time `json:"timeStamp"` // 开盘时间
  22. }
  23. // QueryTSDataReq 分时图数据查询请求参数
  24. type QueryTSDataReq struct {
  25. GoodsCode string `form:"goodsCode" binding:"required"` // 商品代码
  26. }
  27. // QueryTSDataRsp 分时图数据查询返回模型
  28. type QueryTSDataRsp struct {
  29. GoodsCode string `json:"goodsCode"` // 商品代码
  30. DecimalPlace int `json:"decimalPlace"` // 小数位
  31. TradeDate string `json:"tradeDate"` // 交易日
  32. StartTime string `json:"startTime"` // 开始时间
  33. EndTime string `json:"endTime"` // 结束时间
  34. PreSettle float32 `json:"preSettle"` // 昨结
  35. HistoryDatas []HistoryData `json:"historyDatas"` // 历史数据
  36. }
  37. // QueryTSData 分时图数据查询
  38. // @Summary 分时图数据查询
  39. // @Produce json
  40. // @Param GoodsCode query string true "商品代码"
  41. // @Success 200 {object} QueryTSDataRsp
  42. // @Failure 500 {object} app.Response
  43. // @Router /History/QueryTSData [get]
  44. // @Tags 通用服务
  45. func QueryTSData(c *gin.Context) {
  46. appG := app.Gin{C: c}
  47. // 获取请求参数
  48. var req QueryTSDataReq
  49. if err := appG.C.ShouldBindQuery(&req); err != nil {
  50. logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
  51. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  52. return
  53. }
  54. var queryTSDataRsp QueryTSDataRsp
  55. // 获取目标品种交易日
  56. // FIXME: - 一些不常变化的数据(如市场信息、商品信息等)应缓存到Redis中
  57. market, err := models.GetMarketByGoodsCode(req.GoodsCode)
  58. if err != nil {
  59. logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
  60. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  61. return
  62. }
  63. if market == nil {
  64. logger.GetLogger().Errorf("QueryTSData failed: %s", err.Error())
  65. appG.Response(http.StatusBadRequest, e.ERROR_GET_MARKET_FAILED, nil)
  66. return
  67. }
  68. // FIXME: - 由于mtp2.0目前未同步外部交易所品种的当前交易日,
  69. // 故通道交易的品种目前只能在交易系统的外部市场中获
  70. // 取统一的交易日,后期应要求服务端同步外部数据
  71. // 获取目标品种的开休市计划
  72. // 查询成功
  73. logger.GetLogger().Debugln("QueryTSData successed: %v", queryTSDataRsp)
  74. appG.Response(http.StatusOK, e.SUCCESS, queryTSDataRsp)
  75. }