package forex import ( "google.golang.org/protobuf/types/known/timestamppb" v1 "matchmaking-system/api/matchmaking/v1/forex" "matchmaking-system/internal/biz/structure" models "matchmaking-system/internal/pkg/model" "matchmaking-system/internal/service/order" "strconv" ) // ForexStopQuery // // @Description: // @param request // @return structure.StopOrder func ForexStopQuery(request *v1.UpdateForexRequest) structure.StopOrder { return structure.StopOrder{ OrderId: request.OrderId, StopType: request.StopType, StopLossPrice: request.StopLossPrice, StopWinPrice: request.StopWinPrice, } } // ForexCancelOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.OrderReply func ForexCancelOrderReply(check bool, err string, req *v1.CancelForexRequest) *v1.ForexReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.ForexReply{ Code: code, Data: ResultForexMessage(req.OrderId), Message: replyStr, } } // VerificationForexCancel // // @Description: // @param req // @return bool func VerificationForexCancel(req *v1.CancelForexRequest) bool { if len(req.GetOrderId()) <= 0 { return false } return true } // ForexAllPositionReply // // @Description: // @param check // @param err // @param req // @return *v1.AllOrderReply func ForexAllPositionReply(check bool, err string) *v1.AllForexReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.AllForexReply{ Code: code, Data: "", Message: replyStr, } } // ForexPositionOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.OrderReply func ForexPositionOrderReply(check bool, err string, req *v1.CancelForexRequest) *v1.ForexReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.ForexReply{ Code: code, Data: ResultForexMessage(req.OrderId), Message: replyStr, } } // VerificationForexPosition // // @Description: // @param req // @return bool func VerificationForexPosition(req *v1.CancelForexRequest) bool { if len(req.GetOrderId()) <= 0 { return false } return true } // ForexUpdatePlaceOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.OrderReply func ForexUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateForexRequest) *v1.ForexReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.ForexReply{ Code: code, Data: ResultForexMessage(req.OrderId), Message: replyStr, } } // VerificationForexUpdatePlaceOrder // // @Description: // @param req // @return bool func VerificationForexUpdatePlaceOrder(req *v1.UpdateForexRequest) bool { if len(req.GetOrderId()) <= 0 { return false } switch req.StopType { case 0: return true case 1: if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { return false } default: return false } return true } // VerificationBotForexTrade // // @Description: // @param req // @return bool func VerificationBotForexTrade(req *v1.GetBotForexTradeRequest) bool { if req.GetPageSize() < 0 { return false } if req.GetStatus() < 0 { return false } if req.GetPageCount() < 0 { return false } return true } // BotForexTradeMessage // // @Description: // @param stockList // @return contractTrade func BotForexTradeMessage(stockList []*models.BotForexTrade) (contractTrade []*v1.BotForexTrade) { for _, value := range stockList { faceValue := strconv.FormatInt(value.FaceValue, 10) contractTrade = append(contractTrade, &v1.BotForexTrade{ OrderId: value.OrderId, ForexId: 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), }) } return } // BotForexTradeReply // // @Description: // @param check // @param err // @param req // @param data // @param totalCount // @return *v1.GetBotForexTradeReply func BotForexTradeReply(check bool, err string, req *v1.GetBotForexTradeRequest, data []*models.BotForexTrade, totalCount int64) *v1.GetBotForexTradeReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.GetBotForexTradeReply{ Code: code, Data: &v1.BotForexTradeData{ PageSize: req.PageSize, PageCount: req.PageCount, Data: BotForexTradeMessage(data), TotalCount: totalCount, }, Message: replyStr, } } // VerificationForexPlaceOrder // // @Description: 合约下单参数判定 // @param req // @return bool func VerificationForexPlaceOrder(req *v1.ForexRequest) bool { if len(req.GetPryNum()) <= 0 { return false } if len(req.GetForexId()) <= 0 { return false } if len(req.GetOrderAmount()) <= 0 { return false } if len(req.GetOrderNumber()) <= 0 { return false } if len(req.GetEarnestMoney()) <= 0 { return false } if len(req.GetServiceCost()) <= 0 { return false } switch req.StopType { case 1: if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 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 } // ForexPlaceOrderReply // // @Description: // @param check // @param err // @param orderId // @return *v1.OrderReply func ForexPlaceOrderReply(check bool, err string, orderId string) *v1.ForexReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.ForexReply{ Code: code, Data: ResultForexMessage(orderId), Message: replyStr, } } // ResultForexMessage // // @Description: // @param orderId // @return *v1.Result func ResultForexMessage(orderId string) *v1.ForexResult { return &v1.ForexResult{ OrderId: orderId, } } // ForexOrderQuery // // @Description: // @param request // @return structure.ForexOrder func ForexOrderQuery(request *v1.ForexRequest) structure.ForexOrder { return structure.ForexOrder{ ForexId: request.ForexId, TradeType: request.TradeType, DealType: request.DealType, LimitPrice: request.LimitPrice, MarketPrice: request.MarketPrice, OrderAmount: request.OrderAmount, OrderNumber: request.OrderNumber, EarnestMoney: request.EarnestMoney, ServiceCost: request.ServiceCost, StopType: request.StopType, StopLossPrice: request.StopLossPrice, StopWinPrice: request.StopWinPrice, PryNum: request.PryNum, } }