mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-17 01:14:40 +08:00
Fix equity-history-batch API to support POST JSON requests
- Change route from GET to POST for equity-history-batch endpoint - Update handleEquityHistoryBatch to parse JSON body from POST requests - Maintain backward compatibility with GET query parameters - Ensure public access without authentication as required 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -94,7 +94,7 @@ func (s *Server) setupRoutes() {
|
|||||||
api.GET("/competition", s.handlePublicCompetition)
|
api.GET("/competition", s.handlePublicCompetition)
|
||||||
api.GET("/top-traders", s.handleTopTraders)
|
api.GET("/top-traders", s.handleTopTraders)
|
||||||
api.GET("/equity-history", s.handleEquityHistory)
|
api.GET("/equity-history", s.handleEquityHistory)
|
||||||
api.GET("/equity-history-batch", s.handleEquityHistoryBatch)
|
api.POST("/equity-history-batch", s.handleEquityHistoryBatch)
|
||||||
api.GET("/traders/:id/public-config", s.handleGetPublicTraderConfig)
|
api.GET("/traders/:id/public-config", s.handleGetPublicTraderConfig)
|
||||||
|
|
||||||
// 需要认证的路由
|
// 需要认证的路由
|
||||||
@@ -1602,7 +1602,13 @@ func (s *Server) handleTopTraders(c *gin.Context) {
|
|||||||
|
|
||||||
// handleEquityHistoryBatch 批量获取多个交易员的收益率历史数据(无需认证,用于表现对比)
|
// handleEquityHistoryBatch 批量获取多个交易员的收益率历史数据(无需认证,用于表现对比)
|
||||||
func (s *Server) handleEquityHistoryBatch(c *gin.Context) {
|
func (s *Server) handleEquityHistoryBatch(c *gin.Context) {
|
||||||
// 获取trader_ids参数,支持逗号分隔的多个ID
|
var requestBody struct {
|
||||||
|
TraderIDs []string `json:"trader_ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试解析POST请求的JSON body
|
||||||
|
if err := c.ShouldBindJSON(&requestBody); err != nil {
|
||||||
|
// 如果JSON解析失败,尝试从query参数获取(兼容GET请求)
|
||||||
traderIDsParam := c.Query("trader_ids")
|
traderIDsParam := c.Query("trader_ids")
|
||||||
if traderIDsParam == "" {
|
if traderIDsParam == "" {
|
||||||
// 如果没有指定trader_ids,则返回前10名的历史数据
|
// 如果没有指定trader_ids,则返回前10名的历史数据
|
||||||
@@ -1634,17 +1640,18 @@ func (s *Server) handleEquityHistoryBatch(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 解析逗号分隔的trader IDs
|
// 解析逗号分隔的trader IDs
|
||||||
traderIDs := strings.Split(traderIDsParam, ",")
|
requestBody.TraderIDs = strings.Split(traderIDsParam, ",")
|
||||||
for i := range traderIDs {
|
for i := range requestBody.TraderIDs {
|
||||||
traderIDs[i] = strings.TrimSpace(traderIDs[i])
|
requestBody.TraderIDs[i] = strings.TrimSpace(requestBody.TraderIDs[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 限制最多20个交易员,防止请求过大
|
// 限制最多20个交易员,防止请求过大
|
||||||
if len(traderIDs) > 20 {
|
if len(requestBody.TraderIDs) > 20 {
|
||||||
traderIDs = traderIDs[:20]
|
requestBody.TraderIDs = requestBody.TraderIDs[:20]
|
||||||
}
|
}
|
||||||
|
|
||||||
result := s.getEquityHistoryForTraders(traderIDs)
|
result := s.getEquityHistoryForTraders(requestBody.TraderIDs)
|
||||||
c.JSON(http.StatusOK, result)
|
c.JSON(http.StatusOK, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user