package virtual import ( "google.golang.org/protobuf/types/known/timestamppb" "matchmaking-system/internal/biz/structure" "matchmaking-system/internal/pkg/flags" "matchmaking-system/internal/service/order" "strconv" v1 "matchmaking-system/api/matchmaking/v1/virtually" models "matchmaking-system/internal/pkg/model" ) // VerificationBotSecondTrade // // @Description: // @param req // @return bool func VerificationBotSecondTrade(req *v1.GetBotSecondTradeRequest) bool { if req.GetPageSize() < 0 { return false } if req.GetStatus() < 0 { return false } if req.GetPageCount() < 0 { return false } return true } // BotSecondTradeReply // // @Description: // @param check // @param err // @param req // @param data // @param totalCount // @return *v1.GetBotContractTradeReply func BotSecondTradeReply(check bool, err string, req *v1.GetBotSecondTradeRequest, data []*models.BotContractSecTrade, totalCount int64) *v1.GetBotSecondTradeReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.GetBotSecondTradeReply{ Code: code, Data: &v1.BotSecondTradeData{ PageSize: req.PageSize, PageCount: req.PageCount, Data: BotSecondTradeMessage(data), TotalCount: totalCount, }, Message: replyStr, } } // BotSecondTradeMessage // // @Description: // @param stockList // @return contractTrade func BotSecondTradeMessage(stockList []*models.BotContractSecTrade) (contractTrade []*v1.BotSecondTrade) { for _, value := range stockList { faceValue := strconv.FormatInt(value.FaceValue, 10) contractTrade = append(contractTrade, &v1.BotSecondTrade{ OrderId: value.OrderId, ContractId: value.ContractId, TradeType: int64(value.TradeType), DealType: int64(value.DealType), LimitPrice: value.LimitPrice, MarketPrice: value.MarketPrice, DealPrice: value.DealPrice, ClosingPrice: value.ClosingPrice, OrderNumber: value.OrderNumber, StopType: int64(value.StopType), StopLossPrice: value.StopLossPrice, StopWinPrice: value.StopWinPrice, ServiceCost: value.ServiceCost, EarnestMoney: value.EarnestMoney, OrderMoney: value.OrderMoney, Status: int64(value.Status), ClosingCost: value.ClosingCost, CreateTime: timestamppb.New(value.CreateTime), UpdateTime: timestamppb.New(value.UpdateTime), OpenTime: timestamppb.New(value.OpenTime), ClosingTime: timestamppb.New(value.ClosingTime), FaceValue: faceValue, OvernightCost: value.OvernightCost, KeepDecimal: strconv.Itoa(value.KeepDecimal), PryNum: strconv.Itoa(value.PryNum), SecondTime: strconv.Itoa(value.SecondTime), State: int64(value.State), OrderStatus: int64(value.OrderStatus), OrderValue: value.OrderValue, }) } return } // VerificationSecondOrder // // @Description: 秒合约下单参数判定 // @param req // @return bool func VerificationSecondOrder(req *v1.SecondOrderRequest) bool { if len(req.GetPryNum()) <= 0 { req.PryNum = flags.SetOne } if len(req.GetContractId()) <= 0 { return false } if len(req.GetOrderAmount()) <= 0 { return false } if len(req.GetEarnestMoney()) <= 0 { return false } if len(req.GetServiceCost()) <= 0 { return false } if req.GetTime() <= 0 { return false } switch req.TradeType { case 1: case 2: default: 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 } return true } // SecondPlaceOrderReply // // @Description: // @param check // @param err // @param orderId // @return *v1.SecondOrderReply func SecondPlaceOrderReply(check bool, err string, orderId string) *v1.SecondOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.SecondOrderReply{ Code: code, Data: SecondResultMessage(orderId), Message: replyStr, } } // SecondResultMessage // // @Description: // @param orderId // @return *v1.SecondResult func SecondResultMessage(orderId string) *v1.SecondResult { return &v1.SecondResult{ OrderId: orderId, } } // SecondQuery // // @Description: // @param request // @return structure.ContractOrder func SecondQuery(request *v1.SecondOrderRequest) structure.ContractOrder { return structure.ContractOrder{ ContractId: request.ContractId, TradeType: request.TradeType, DealType: request.DealType, LimitPrice: request.LimitPrice, MarketPrice: request.MarketPrice, OrderAmount: request.OrderAmount, OrderNumber: request.OrderNumber, EarnestMoney: request.EarnestMoney, ServiceCost: request.ServiceCost, PryNum: request.PryNum, Time: request.Time, } }