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.
73 lines
1.9 KiB
73 lines
1.9 KiB
package market |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"sig-pub/api/pb" |
|
"sig-pub/pkg/grpc/session" |
|
"sig-pub/pkg/mapping" |
|
) |
|
|
|
type MarketGrpcServer struct { |
|
pb.UnimplementedMarketServer |
|
tradeInstanceService *TradeInstanceService |
|
} |
|
|
|
func NewMarketGrpcServer(instanceService *TradeInstanceService) *MarketGrpcServer { |
|
return &MarketGrpcServer{ |
|
tradeInstanceService: instanceService, |
|
} |
|
} |
|
|
|
func (svr *MarketGrpcServer) GetTradeInstance(ctx context.Context, req *pb.ReqGetTradeInstance) (rsp *pb.RspGetTradeInstance, err error) { |
|
subject, err := session.GetSubject(ctx) |
|
if err != nil { |
|
return |
|
} |
|
fmt.Printf("subject: %#v\n", subject) |
|
|
|
inst, err := svr.tradeInstanceService.GetInstance(req.InstId) |
|
if err != nil { |
|
return |
|
} |
|
|
|
rsp = &pb.RspGetTradeInstance{ |
|
Inst: mapping.TradeInstance2Proto(inst), |
|
} |
|
return |
|
} |
|
|
|
func (svr *MarketGrpcServer) AddTradeInstance(ctx context.Context, req *pb.ReqAddTradeInstance) (rsp *pb.RspAddTradeInstance, err error) { |
|
subject, err := session.GetSubject(ctx) |
|
if err != nil { |
|
return |
|
} |
|
|
|
inst := mapping.Proto2TradeInstance(req.Inst) |
|
err = svr.tradeInstanceService.InsertInstance(subject.Uid, inst) |
|
if err != nil { |
|
return |
|
} |
|
|
|
rsp = &pb.RspAddTradeInstance{ |
|
Inst: mapping.TradeInstance2Proto(inst), |
|
} |
|
return |
|
} |
|
|
|
// ListExchangeTradeInstance 获取指定交易所的正常状态的交易产品 |
|
func (svr *MarketGrpcServer) ListExchangeTradeInstance(ctx context.Context, req *pb.ReqListExchangeTradeInstance) (rsp *pb.RspListExchangeTradeInstance, err error) { |
|
rsp = new(pb.RspListExchangeTradeInstance) |
|
var exchanges []int32 |
|
for _, exchange := range req.Exchanges { |
|
exchanges = append(exchanges, int32(exchange)) |
|
} |
|
exchangeInsts, err := svr.tradeInstanceService.ListExchangeTradeInstance(exchanges) |
|
if err != nil { |
|
return |
|
} |
|
for _, inst := range exchangeInsts { |
|
rsp.ExchangeInsts = append(rsp.ExchangeInsts, mapping.ExchangeInstance2Proto(inst)) |
|
} |
|
return |
|
}
|
|
|