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.
59 lines
1.5 KiB
59 lines
1.5 KiB
package trading |
|
|
|
import ( |
|
"context" |
|
"sig-pub/api/pb" |
|
"sig-pub/pkg/types" |
|
"sig-pub/pkg/utils/times" |
|
) |
|
|
|
type TradingGrpcServer struct { |
|
pb.UnimplementedTradingServiceServer |
|
tradingService *TradingService |
|
} |
|
|
|
func NewTradingGrpcServer(tradingService *TradingService) *TradingGrpcServer { |
|
return &TradingGrpcServer{ |
|
tradingService: tradingService, |
|
} |
|
} |
|
|
|
func (svr *TradingGrpcServer) Init() (err error) { |
|
return |
|
} |
|
|
|
func (svr *TradingGrpcServer) IndicatorSeries(ctx context.Context, req *pb.ReqIndicatorSeries) (rsp *pb.RspIndicatorSeries, err error) { |
|
// s, err := structpb.NewStruct(map[string]any{}) |
|
input := req.Input.AsMap() |
|
matrix, times, err := svr.tradingService.IndicatorSeries(ctx, req.Indicator, req.Digit, types.Input(input), req.Series) |
|
if err != nil { |
|
return |
|
} |
|
rsp = &pb.RspIndicatorSeries{} |
|
rsp.Matrix = matrix |
|
rsp.Times = times |
|
return |
|
} |
|
|
|
func (svr *TradingGrpcServer) StrategySeries(ctx context.Context, req *pb.ReqStrategySeries) (rsp *pb.RspStrategySeries, err error) { |
|
rsp = &pb.RspStrategySeries{} |
|
err = svr.tradingService.StrategySeries(ctx, req, rsp) |
|
return |
|
} |
|
|
|
func (svr *TradingGrpcServer) Backtest(ctx context.Context, req *pb.ReqBacktest) (rsp *pb.RspBacktest, err error) { |
|
stime, err := times.ParseFORMAT(req.Stime) |
|
if err != nil { |
|
return |
|
} |
|
etime, err := times.ParseFORMAT(req.Etime) |
|
if err != nil { |
|
return |
|
} |
|
err = svr.tradingService.Backtest(ctx, req.PlanId, stime.UnixMilli(), etime.UnixMilli()) |
|
if err != nil { |
|
return |
|
} |
|
rsp = new(pb.RspBacktest) |
|
return |
|
}
|
|
|