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.
318 lines
7.3 KiB
318 lines
7.3 KiB
2 months ago
|
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"
|
||
|
)
|
||
|
|
||
|
// ShareInrCancelReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.InrOrderReply
|
||
|
func ShareInrCancelReply(check bool, err string, req *v1.CancelInrOrderRequest) *v1.InrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.InrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationInrShareCancel
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationInrShareCancel(req *v1.CancelInrOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// ShareInrAllPositionRequest
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.AllInrOrderReply
|
||
|
func ShareInrAllPositionRequest(check bool, err string) *v1.AllInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.AllInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: "",
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareInrPositionOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.InrOrderReply
|
||
|
func ShareInrPositionOrderReply(check bool, err string, req *v1.CancelInrOrderRequest) *v1.InrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.InrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationInrSharePosition
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationInrSharePosition(req *v1.CancelInrOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// StopInrOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.StopOrder
|
||
|
func StopInrOrderQuery(request *v1.UpdateInrOrderRequest) structure.StopOrder {
|
||
|
return structure.StopOrder{
|
||
|
OrderId: request.OrderId,
|
||
|
StopType: request.StopType,
|
||
|
StopLossPrice: request.StopLossPrice,
|
||
|
StopWinPrice: request.StopWinPrice,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareInrUpdateOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.InrOrderReply
|
||
|
func ShareInrUpdateOrderReply(check bool, err string, req *v1.UpdateInrOrderRequest) *v1.InrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.InrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationInrStopOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationInrStopOrderQuery(request *v1.UpdateInrOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// ShareInrOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.ShareOrder
|
||
|
func ShareInrOrderQuery(request *v1.ShareInrOrderRequest) 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,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ResultInrOrderMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param orderId
|
||
|
// @return *v1.InrOrderResult
|
||
|
func ResultInrOrderMessage(orderId string) *v1.InrOrderResult {
|
||
|
return &v1.InrOrderResult{
|
||
|
OrderId: orderId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareInrPlaceOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param orderId
|
||
|
// @return *v1.InrOrderReply
|
||
|
func ShareInrPlaceOrderReply(check bool, err string, orderId string) *v1.InrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.InrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultInrOrderMessage(orderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationInrShareOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationInrShareOrderQuery(request *v1.ShareInrOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// BotStockInrTradeMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param stockList
|
||
|
// @return BotInrStockInrTrade
|
||
|
func BotStockInrTradeMessage(stockList []*models.BotStockInTrade) (stockTrade []*v1.BotStockInrTrade) {
|
||
|
for _, value := range stockList {
|
||
|
stockTrade = append(stockTrade, &v1.BotStockInrTrade{
|
||
|
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
|
||
|
}
|
||
|
|
||
|
// BotStockInrTradeReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @param data
|
||
|
// @param totalCount
|
||
|
// @return *v1.GetInrBotStockInrTradeReply
|
||
|
func BotStockInrTradeReply(check bool, err string, req *v1.GetInrBotStockTradeRequest, data []*models.BotStockInTrade, totalCount int64) *v1.GetBotStockInrTradeReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.GetBotStockInrTradeReply{
|
||
|
Code: code,
|
||
|
Data: &v1.BotStockInrTradeData{
|
||
|
PageSize: req.PageSize,
|
||
|
PageCount: req.PageCount,
|
||
|
Data: BotStockInrTradeMessage(data),
|
||
|
TotalCount: totalCount,
|
||
|
},
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationInrBotStockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationInrBotStockTrade(req *v1.GetInrBotStockTradeRequest) bool {
|
||
|
if req.GetPageSize() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetStatus() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetPageCount() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|