package share import ( "matchmaking-system/internal/biz/structure" "matchmaking-system/internal/pkg/flags" "matchmaking-system/internal/service/order" "strconv" v1 "matchmaking-system/api/matchmaking/v1/share" models "matchmaking-system/internal/pkg/model" ) // ShareCancelReply // // @Description: // @param check // @param err // @param req // @return *v1.UsOrderReply func ShareCancelReply(check bool, err string, req *v1.CancelUsOrderRequest) *v1.UsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.UsOrderReply{ Code: code, Data: ResultUsOrderMessage(req.OrderId), Message: replyStr, } } // VerificationShareCancel // // @Description: // @param req // @return bool func VerificationShareCancel(req *v1.CancelUsOrderRequest) bool { if len(req.GetOrderId()) <= 0 { return false } return true } // ShareAllPositionRequest // // @Description: // @param check // @param err // @param req // @return *v1.AllUsOrderReply func ShareAllPositionRequest(check bool, err string) *v1.AllUsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.AllUsOrderReply{ Code: code, Data: "", Message: replyStr, } } // SharePositionOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.UsOrderReply func SharePositionOrderReply(check bool, err string, req *v1.CancelUsOrderRequest) *v1.UsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.UsOrderReply{ Code: code, Data: ResultUsOrderMessage(req.OrderId), Message: replyStr, } } // VerificationSharePosition // // @Description: // @param req // @return bool func VerificationSharePosition(req *v1.CancelUsOrderRequest) bool { if len(req.GetOrderId()) <= 0 { return false } return true } // StopOrderQuery // // @Description: // @param request // @return structure.StopOrder func StopOrderQuery(request *v1.UpdateUsOrderRequest) structure.StopOrder { return structure.StopOrder{ OrderId: request.OrderId, StopType: request.StopType, StopLossPrice: request.StopLossPrice, StopWinPrice: request.StopWinPrice, } } // ShareUpdateOrderReply // // @Description: // @param check // @param err // @param req // @return *v1.UsOrderReply func ShareUpdateOrderReply(check bool, err string, req *v1.UpdateUsOrderRequest) *v1.UsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.UsOrderReply{ Code: code, Data: ResultUsOrderMessage(req.OrderId), Message: replyStr, } } // VerificationStopOrderQuery // // @Description: // @param request // @return bool func VerificationStopOrderQuery(request *v1.UpdateUsOrderRequest) bool { if len(request.GetOrderId()) <= 0 { return false } switch request.StopType { case 1: if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { return false } case 0: //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { // return false //} return true default: return false } return true } // ShareUsOrderQuery // // @Description: // @param request // @return structure.ShareOrder func ShareUsOrderQuery(request *v1.UsOrderRequest) structure.ShareOrder { return structure.ShareOrder{ StockId: request.StockId, TradeType: request.TradeType, DealType: request.DealType, LimitPrice: request.LimitPrice, MarketPrice: request.MarketPrice, MarketMoney: request.MarketMoney, OrderNumber: request.OrderNumber, ServiceCost: request.ServiceCost, StopType: request.StopType, StopLossPrice: request.StopLossPrice, StopWinPrice: request.StopWinPrice, PryNum: request.PryNum, } } // ShareUsPlaceOrderReply // // @Description: // @param check // @param err // @param orderId // @return *v1.UsOrderReply func ShareUsPlaceOrderReply(check bool, err string, orderId string) *v1.UsOrderReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.UsOrderReply{ Code: code, Data: ResultUsOrderMessage(orderId), Message: replyStr, } } // ResultUsOrderMessage // // @Description: // @param orderId // @return *v1.UsOrderResult func ResultUsOrderMessage(orderId string) *v1.UsOrderResult { return &v1.UsOrderResult{ OrderId: orderId, } } // VerificationShareOrderQuery // // @Description: // @param request // @return bool func VerificationShareOrderQuery(request *v1.UsOrderRequest) bool { if len(request.GetStockId()) <= 0 { return false } switch request.DealType { case 1: if len(request.GetLimitPrice()) <= 0 { return false } case 2: if len(request.GetMarketPrice()) <= 0 { return false } default: return false } if len(request.GetMarketMoney()) <= 0 { return false } if len(request.GetOrderNumber()) <= 0 { return false } if len(request.GetServiceCost()) <= 0 { return false } switch request.StopType { case 1: if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { return false } } switch request.TradeType { case 1: case 2: default: return false } return true } // VerificationBotStockTrade // // @Description: // @param req // @return bool func VerificationBotStockTrade(req *v1.GetUsBotStockTradeRequest) bool { if req.GetPageSize() < 0 { return false } if req.GetStatus() < 0 { return false } if req.GetPageCount() < 0 { return false } return true } // BotStockTradeReply // // @Description: // @param check // @param err // @param req // @param data // @param totalCount // @return *v1.GetUsBotStockTradeReply func BotStockTradeReply(check bool, err string, req *v1.GetUsBotStockTradeRequest, data []*models.BotStockTrade, totalCount int64) *v1.GetUsBotStockTradeReply { code, replyStr := order.ResultCodeSrr(check, err) return &v1.GetUsBotStockTradeReply{ Code: code, Data: &v1.BotUsStockTradeData{ PageSize: req.PageSize, PageCount: req.PageCount, Data: BotStockTradeMessage(data), TotalCount: totalCount, }, Message: replyStr, } } // BotStockTradeMessage // // @Description: // @param stockList // @return BotUsOrderTrade func BotStockTradeMessage(stockList []*models.BotStockTrade) (stockTrade []*v1.BotUsOrderTrade) { for _, value := range stockList { stockTrade = append(stockTrade, &v1.BotUsOrderTrade{ OrderId: value.OrderId, StockId: value.StockId, 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, MarketMoney: value.MarketMoney, OrderMoney: value.OrderMoney, ClosingCost: value.ClosingCost, Status: int64(value.Status), CreateTime: value.CreateTime.Format(flags.LayoutTime), UpdateTime: value.UpdateTime.Format(flags.LayoutTime), OpenTime: value.OpenTime.Format(flags.LayoutTime), ClosingTime: value.ClosingTime.Format(flags.LayoutTime), KeepDecimal: strconv.Itoa(value.KeepDecimal), StockName: value.StockName, PryNum: strconv.Itoa(value.PryNum), }) } return }