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.
306 lines
7.1 KiB
306 lines
7.1 KiB
2 months ago
|
package block
|
||
|
|
||
|
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/block"
|
||
|
models "matchmaking-system/internal/pkg/model"
|
||
|
)
|
||
|
|
||
|
// ShareBlockCancelReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderBlockReply
|
||
|
func ShareBlockCancelReply(check bool, err string, req *v1.CancelBlockOrderRequest) *v1.OrderBlockReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OrderBlockReply{
|
||
|
Code: code,
|
||
|
Data: ResultBlockOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationShareBlockCancel
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationShareBlockCancel(req *v1.CancelBlockOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetType() <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// ShareBlockPositionOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderBlockReply
|
||
|
func ShareBlockPositionOrderReply(check bool, err string, req *v1.CancelBlockOrderRequest) *v1.OrderBlockReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OrderBlockReply{
|
||
|
Code: code,
|
||
|
Data: ResultBlockOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationShareBlockPosition
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationShareBlockPosition(req *v1.CancelBlockOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// StopOrderBlockQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.StopOrder
|
||
|
func StopOrderBlockQuery(request *v1.UpdateBlockOrderRequest) structure.StopOrder {
|
||
|
return structure.StopOrder{
|
||
|
OrderId: request.OrderId,
|
||
|
StopType: request.StopType,
|
||
|
StopLossPrice: request.StopLossPrice,
|
||
|
StopWinPrice: request.StopWinPrice,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareBlockUpdateOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderBlockReply
|
||
|
func ShareBlockUpdateOrderReply(check bool, err string, req *v1.UpdateBlockOrderRequest) *v1.OrderBlockReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OrderBlockReply{
|
||
|
Code: code,
|
||
|
Data: ResultBlockOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationStopOrderBlockQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationStopOrderBlockQuery(request *v1.UpdateBlockOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// ShareBlockOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.ShareOrder
|
||
|
func ShareBlockOrderQuery(request *v1.OrderBlockRequest) 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,
|
||
|
Type: request.Type,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareBlockPlaceOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param orderId
|
||
|
// @return *v1.OrderBlockReply
|
||
|
func ShareBlockPlaceOrderReply(check bool, err string, orderId string) *v1.OrderBlockReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OrderBlockReply{
|
||
|
Code: code,
|
||
|
Data: ResultBlockOrderMessage(orderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ResultBlockOrderMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param orderId
|
||
|
// @return *v1.OrderBlockResult
|
||
|
func ResultBlockOrderMessage(orderId string) *v1.OrderBlockResult {
|
||
|
return &v1.OrderBlockResult{
|
||
|
OrderId: orderId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationShareBlockOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationShareBlockOrderQuery(request *v1.OrderBlockRequest) 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 request.Type <= 0 {
|
||
|
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.TradeType {
|
||
|
case 1:
|
||
|
case 2:
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// VerificationBotStockBlockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationBotStockBlockTrade(req *v1.GetBotStockBlockTradeRequest) bool {
|
||
|
if req.GetPageSize() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetStatus() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetPageCount() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetType() <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// BotStockBlockTradeReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @param data
|
||
|
// @param totalCount
|
||
|
// @return *v1.GetBotStockBlockTradeReply
|
||
|
func BotStockBlockTradeReply(check bool, err string, req *v1.GetBotStockBlockTradeRequest, data []*models.BotStockBlockTrade, totalCount int64) *v1.GetBotStockBlockTradeReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.GetBotStockBlockTradeReply{
|
||
|
Code: code,
|
||
|
Data: &v1.BotStockBlockTradeData{
|
||
|
PageSize: req.PageSize,
|
||
|
PageCount: req.PageCount,
|
||
|
Data: BotStockBlockTradeMessage(data),
|
||
|
TotalCount: totalCount,
|
||
|
},
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBlockTradeMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param stockList
|
||
|
// @return stockTrade
|
||
|
func BotStockBlockTradeMessage(stockList []*models.BotStockBlockTrade) (stockTrade []*v1.BotOrderBlockTrade) {
|
||
|
for _, value := range stockList {
|
||
|
stockTrade = append(stockTrade, &v1.BotOrderBlockTrade{
|
||
|
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: timestamppb.New(value.CreateTime),
|
||
|
UpdateTime: timestamppb.New(value.UpdateTime),
|
||
|
OpenTime: timestamppb.New(value.OpenTime),
|
||
|
ClosingTime: timestamppb.New(value.ClosingTime),
|
||
|
KeepDecimal: strconv.Itoa(value.KeepDecimal),
|
||
|
StockName: value.StockName,
|
||
|
PryNum: strconv.Itoa(value.PryNum),
|
||
|
Type: int64(value.Type),
|
||
|
})
|
||
|
}
|
||
|
return
|
||
|
}
|