Checks / verify (push) Failing after 9m52s
统一单入口 Go 工程与前端依赖目录,增加后台供应商配置、候选审核、计划预算、成交冲正、持仓复盘和站内通知。接入策略版本、Python 回测、可配置 A 股公开行情及 zap 文件轮转日志,补充迁移、契约与验证。
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"git.sundynix.cn/Blizzard/Veyra/internal/apperror"
|
|
"git.sundynix.cn/Blizzard/Veyra/internal/model"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
func bindBacktests(r *gin.Engine, o IdentityOptions) {
|
|
g := r.Group("/api/admin/v1/backtests", func(c *gin.Context) { authenticate(c, o, "admin") })
|
|
g.Use(func(c *gin.Context) {
|
|
if o.Backtests == nil {
|
|
fail(c, apperror.ErrUnavailable)
|
|
return
|
|
}
|
|
c.Next()
|
|
})
|
|
g.GET("", func(c *gin.Context) {
|
|
v, e := o.Backtests.List(c.Request.Context(), currentUser(c))
|
|
if e != nil {
|
|
fail(c, e)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, v)
|
|
})
|
|
g.GET("/:id", func(c *gin.Context) {
|
|
v, e := o.Backtests.Detail(c.Request.Context(), currentUser(c), c.Param("id"))
|
|
if e != nil {
|
|
fail(c, e)
|
|
return
|
|
}
|
|
success(c, http.StatusOK, v)
|
|
})
|
|
g.POST("", func(c *gin.Context) {
|
|
if !sameOrigin(c.Request) {
|
|
fail(c, apperror.ErrForbidden)
|
|
return
|
|
}
|
|
var input model.BacktestInput
|
|
if !decodeLimit(c, &input, 256<<10) {
|
|
return
|
|
}
|
|
v, e := o.Backtests.Create(c.Request.Context(), currentUser(c), input, c.Writer.Header().Get("X-Request-ID"))
|
|
if e != nil {
|
|
fail(c, e)
|
|
return
|
|
}
|
|
success(c, http.StatusAccepted, v)
|
|
})
|
|
g.POST("/from-market", func(c *gin.Context) {
|
|
if !sameOrigin(c.Request) {
|
|
fail(c, apperror.ErrForbidden)
|
|
return
|
|
}
|
|
var input struct {
|
|
StrategyVersionID string `json:"strategy_version_id"`
|
|
Symbol string `json:"symbol"`
|
|
Exchange string `json:"exchange"`
|
|
Start string `json:"start"`
|
|
End string `json:"end"`
|
|
InitialCash string `json:"initial_cash"`
|
|
}
|
|
if !decode(c, &input) {
|
|
return
|
|
}
|
|
v, e := o.Backtests.CreateMarket(c.Request.Context(), currentUser(c), input.StrategyVersionID, input.Symbol, input.Exchange, input.Start, input.End, input.InitialCash, c.Writer.Header().Get("X-Request-ID"))
|
|
if e != nil {
|
|
fail(c, e)
|
|
return
|
|
}
|
|
success(c, http.StatusAccepted, v)
|
|
})
|
|
|
|
}
|