新增二板历史角度
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"level_go/internal/model"
|
||||
)
|
||||
|
||||
// GetSecondBoardProfitSummary 返回 2020 年至今二板早盘股票的 T+1 最大获利汇总。
|
||||
func (h *LimitBoardHandler) GetSecondBoardProfitSummary(c *gin.Context) {
|
||||
req, err := parseSecondBoardProfitRequest(c, false)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := h.Service.GetSecondBoardProfitSummary(req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetSecondBoardProfitDetail 返回单只股票二板早盘后的 T+1 最大获利详情。
|
||||
func (h *LimitBoardHandler) GetSecondBoardProfitDetail(c *gin.Context) {
|
||||
req, err := parseSecondBoardProfitRequest(c, true)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := h.Service.GetSecondBoardProfitDetail(req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// parseSecondBoardProfitRequest 解析二板早盘获利综合和详情接口参数。
|
||||
func parseSecondBoardProfitRequest(c *gin.Context, requireCode bool) (model.SecondBoardProfitRequest, error) {
|
||||
req := model.SecondBoardProfitRequest{
|
||||
TradeStartDate: firstNonEmptyQuery(c, "tradeStartDate", "trade_start_date", "start_date"),
|
||||
TradeEndDate: firstNonEmptyQuery(c, "tradeEndDate", "trade_end_date", "end_date"),
|
||||
TsCode: firstNonEmptyQuery(c, "tsCode", "ts_code"),
|
||||
Symbol: firstNonEmptyQuery(c, "symbol", "code"),
|
||||
}
|
||||
if req.TradeStartDate == "" {
|
||||
req.TradeStartDate = defaultSecondProfitStartDate
|
||||
}
|
||||
if req.TradeEndDate == "" {
|
||||
req.TradeEndDate = time.Now().Format("2006-01-02")
|
||||
}
|
||||
if err := validateSecondProfitDateRange(req.TradeStartDate, req.TradeEndDate); err != nil {
|
||||
return req, err
|
||||
}
|
||||
if requireCode && req.TsCode == "" && req.Symbol == "" {
|
||||
return req, errors.New("tsCode 或 symbol 参数不能为空")
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
Reference in New Issue
Block a user