Paper trading readiness에서 API/worker/CLI가 같은 protobuf 계약으로 paper state를 시작하고 조회할 수 있어야 한다. Headless 운영 경로를 먼저 닫기 위해 contract, worker runtime, API forwarding, CLI scenario, client parser map과 검증 artifact를 함께 반영한다.
70 lines
3.2 KiB
Go
70 lines
3.2 KiB
Go
package operator
|
|
|
|
import (
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
altv1 "git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1"
|
|
protoSocket "git.toki-labs.com/toki/proto-socket/go"
|
|
)
|
|
|
|
// messageFactories lists every ALT protobuf message the CLI API client must
|
|
// decode. It mirrors the API/worker parser maps (services/api/internal/contracts
|
|
// and services/worker/internal/contracts) because Go's internal boundary keeps
|
|
// apps/cli from importing those packages. Keeping a single factory list here, as
|
|
// the runtime rails do, ensures a contract message cannot be registered through
|
|
// one runner path and missed in another.
|
|
func messageFactories() []func() proto.Message {
|
|
return []func() proto.Message{
|
|
func() proto.Message { return &altv1.HelloRequest{} },
|
|
func() proto.Message { return &altv1.HelloResponse{} },
|
|
// market read surface: instruments and bars
|
|
func() proto.Message { return &altv1.ListInstrumentsRequest{} },
|
|
func() proto.Message { return &altv1.ListInstrumentsResponse{} },
|
|
func() proto.Message { return &altv1.ListBarsRequest{} },
|
|
func() proto.Message { return &altv1.ListBarsResponse{} },
|
|
// market import command: daily bars
|
|
func() proto.Message { return &altv1.ImportDailyBarsRequest{} },
|
|
func() proto.Message { return &altv1.ImportDailyBarsResponse{} },
|
|
// backtest surface: start / list / detail / result / compare
|
|
func() proto.Message { return &altv1.StartBacktestRequest{} },
|
|
func() proto.Message { return &altv1.StartBacktestResponse{} },
|
|
func() proto.Message { return &altv1.GetBacktestRunRequest{} },
|
|
func() proto.Message { return &altv1.GetBacktestRunResponse{} },
|
|
func() proto.Message { return &altv1.GetBacktestResultRequest{} },
|
|
func() proto.Message { return &altv1.GetBacktestResultResponse{} },
|
|
func() proto.Message { return &altv1.BacktestResult{} },
|
|
func() proto.Message { return &altv1.ListBacktestRunsRequest{} },
|
|
func() proto.Message { return &altv1.ListBacktestRunsResponse{} },
|
|
func() proto.Message { return &altv1.GetBacktestRunDetailRequest{} },
|
|
func() proto.Message { return &altv1.GetBacktestRunDetailResponse{} },
|
|
func() proto.Message { return &altv1.CompareBacktestRunsRequest{} },
|
|
func() proto.Message { return &altv1.CompareBacktestRunsResponse{} },
|
|
// paper trading surface: start / state
|
|
func() proto.Message { return &altv1.StartPaperTradingRequest{} },
|
|
func() proto.Message { return &altv1.StartPaperTradingResponse{} },
|
|
func() proto.Message { return &altv1.GetPaperTradingStateRequest{} },
|
|
func() proto.Message { return &altv1.GetPaperTradingStateResponse{} },
|
|
func() proto.Message { return &altv1.PaperTradingState{} },
|
|
}
|
|
}
|
|
|
|
// ParserMap returns a fresh ParserMap populated with all ALT messages the CLI
|
|
// runner can send or receive over the proto-socket API rail.
|
|
func ParserMap() protoSocket.ParserMap {
|
|
factories := messageFactories()
|
|
pm := make(protoSocket.ParserMap, len(factories))
|
|
for _, factory := range factories {
|
|
pm[protoSocket.TypeNameOf(factory())] = parserFor(factory)
|
|
}
|
|
return pm
|
|
}
|
|
|
|
func parserFor(factory func() proto.Message) func([]byte) (proto.Message, error) {
|
|
return func(data []byte) (proto.Message, error) {
|
|
msg := factory()
|
|
if err := proto.Unmarshal(data, msg); err != nil {
|
|
return nil, err
|
|
}
|
|
return msg, nil
|
|
}
|
|
}
|