You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1.4 KiB

package service
import (
"net/http"
"sig-pub/internal/sig/args"
repository "sig-pub/internal/sig/repoitory"
"sig-pub/pkg/data"
"sig-pub/pkg/resp"
"github.com/gin-gonic/gin"
)
type BacktestService struct {
repo *repository.BacktestRepository
}
func NewBacktestService(repo *repository.BacktestRepository) *BacktestService {
return &BacktestService{
repo: repo,
}
}
func (svc *BacktestService) Route(group *gin.RouterGroup) {
group.GET("listBacktestLog", svc.ListBacktestLog) // 回测记录
group.POST("listBacktestLogTrades", svc.ListBacktestLogTrades) // 回测记录订单详情
}
func (svc *BacktestService) ListBacktestLog(ctx *gin.Context) {
page := data.PageArgs(ctx)
logs, err := svc.repo.ListBacktestLogs(10001, page)
if err != nil {
ctx.JSON(http.StatusInternalServerError, resp.Error(err.Error()))
return
}
ctx.JSON(http.StatusOK, resp.Success(resp.H{
"total": len(logs),
"logs": logs,
}))
}
func (svc *BacktestService) ListBacktestLogTrades(ctx *gin.Context) {
page := data.PageArgs(ctx)
arg := new(args.ListBacktestLogTradesReq)
if err := ctx.ShouldBindJSON(arg); err != nil {
ctx.JSON(http.StatusBadRequest, resp.Fail(err.Error()))
return
}
total, trades, err := svc.repo.BacktestLogTrades(10001, arg.BacktestId, page)
if err != nil {
ctx.JSON(http.StatusInternalServerError, resp.Error(err.Error()))
return
}
ctx.JSON(http.StatusOK, resp.Success(resp.H{
"total": total,
"trades": trades,
}))
}