package virtual import ( "google.golang.org/protobuf/types/known/timestamppb" "matchmaking-system/internal/biz/structure" "matchmaking-system/internal/service/order" "strconv" v1 "matchmaking-system/api/matchmaking/v1/virtually" models "matchmaking-system/internal/pkg/model" ) // BotDigitalTradeMessage // // @Description: // @param stockList // @return BotDigitalTrade func BotDigitalTradeMessage(stockList []*models.BotDigitalTrade) (stockTrade []*v1.BotDigitalTrade) { for _, value := range stockList { stockTrade = append(stockTrade, &v1.BotDigitalTrade{ OrderId: value.OrderId, DigitalId: value.DigitalId, TradeType: int64(value.TradeType), DealType: int64(value.DealType), LimitPrice: value.LimitPrice, MarketPrice: value.MarketPrice, DealPrice: value.DealPrice, ClosingPrice: value.ClosingPrice, OrderNumber: value.OrderNumber, ServiceCost: value.ServiceCost, OrderMoney: value.OrderMoney, TotalMoney: value.TotalMoney, ClosingCost: value.ClosingCost, Status: int64(value.Status), CreateTime: timestamppb.New(value.CreateTime), UpdateTime: timestamppb.New(value.UpdateTime), OpenTime: timestamppb.New(value.OpenTime), ClosingTime: timestamppb.New(value.ClosingTime), KeepDecimal: strconv.Itoa(value.KeepDecimal), }) } return } // BotDigitalTradeReply // // @Description: // @param check // @param err // @param req // @param data // @param totalCount // @return *v1.GetBotDigitalTradeReply func BotDigitalTradeReply(check bool, err string, req *v1.GetBotDigitalTradeRequest, data []*models.BotDigitalTrade, totalCount int64) *v1.GetBotDigitalTradeReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.GetBotDigitalTradeReply{ Code: code, Data: &v1.BotDigitalTradeData{ PageSize: req.PageSize, PageCount: req.PageCount, Data: BotDigitalTradeMessage(data), TotalCount: totalCount, }, Message: replyStr, } } // VerificationBotDigitalTrade // // @Description: // @param req // @return bool func VerificationBotDigitalTrade(req *v1.GetBotDigitalTradeRequest) bool { if req.GetPageSize() < 0 { return false } if req.GetStatus() < 0 { return false } if req.GetPageCount() < 0 { return false } return true } // SpotsPlaceOrderReply // // @Description: // @param check // @param err // @param orderId // @return *v1.SpotsOrderReply func SpotsPlaceOrderReply(check bool, err string, orderId string) *v1.SpotsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.SpotsOrderReply{ Code: code, Data: ResultMessage(orderId), Message: replyStr, } } // SpotsCancelOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.SpotsOrderReply func SpotsCancelOrderReply(check bool, err string, req *v1.CancelSpotsOrderRequest) *v1.SpotsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.SpotsOrderReply{ Code: code, Data: ResultMessage(req.OrderId), Message: replyStr, } } // VerificationSpotsCancel // // @Description: // @param req // @return bool func VerificationSpotsCancel(req *v1.CancelSpotsOrderRequest) bool { if len(req.GetOrderId()) <= 0 { return false } return true } // SpotsOrderQuery // // @Description: // @param request // @return structure.SpotsOrder func SpotsOrderQuery(request *v1.SpotsOrderRequest) structure.SpotsOrder { return structure.SpotsOrder{ DigitalId: request.DigitalId, TradeType: request.TradeType, DealType: request.DealType, DealPrice: request.DealPrice, LimitPrice: request.LimitPrice, MarketPrice: request.MarketPrice, OrderNumber: request.OrderNumber, OrderMoney: request.OrderMoney, ServiceCost: request.ServiceCost, } } // ResultMessage // // @Description: // @param orderId // @return *v1.SpotsOrderResult func ResultMessage(orderId string) *v1.SpotsOrderResult { return &v1.SpotsOrderResult{ OrderId: orderId, } } // SharePlaceOrderReply // // @Description: // @param check // @param err // @param orderId // @return *v1.SpotsOrderReply func SharePlaceOrderReply(check bool, err string, orderId string) *v1.SpotsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.SpotsOrderReply{ Code: code, Data: ResultMessage(orderId), Message: replyStr, } } // VerificationSpotsPlaceOrder // // @Description: // @param req // @return bool func VerificationSpotsPlaceOrder(req *v1.SpotsOrderRequest) bool { if len(req.GetDigitalId()) <= 0 { return false } if len(req.GetOrderNumber()) <= 0 { return false } if len(req.GetOrderMoney()) <= 0 { return false } if len(req.GetServiceCost()) <= 0 { return false } switch req.DealType { case 1: if len(req.GetLimitPrice()) <= 0 { return false } case 2: if len(req.GetMarketPrice()) <= 0 { return false } default: return false } switch req.TradeType { case 1: case 2: default: return false } return true }