315 lines
7.2 KiB
315 lines
7.2 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"
|
||
|
)
|
||
|
|
||
|
// ShareBrlCancelReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.BrlOrderReply
|
||
|
func ShareBrlCancelReply(check bool, err string, req *v1.CancelBrlOrderRequest) *v1.BrlOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.BrlOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultBrlOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationBrlShareCancel
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationBrlShareCancel(req *v1.CancelBrlOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// ShareAllBrlPositionRequest
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.AllBrlOrderReply
|
||
|
func ShareAllBrlPositionRequest(check bool, err string) *v1.AllBrlOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.AllBrlOrderReply{
|
||
|
Code: code,
|
||
|
Data: "",
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareBrlPositionOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.BrlOrderReply
|
||
|
func ShareBrlPositionOrderReply(check bool, err string, req *v1.CancelBrlOrderRequest) *v1.BrlOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.BrlOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultBrlOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationBrlSharePosition
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationBrlSharePosition(req *v1.CancelBrlOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// StopBrlOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.StopOrder
|
||
|
func StopBrlOrderQuery(request *v1.UpdateBrlOrderRequest) structure.StopOrder {
|
||
|
return structure.StopOrder{
|
||
|
OrderId: request.OrderId,
|
||
|
StopType: request.StopType,
|
||
|
StopLossPrice: request.StopLossPrice,
|
||
|
StopWinPrice: request.StopWinPrice,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareBrlUpdateOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.SgdOrderReply
|
||
|
func ShareBrlUpdateOrderReply(check bool, err string, req *v1.UpdateBrlOrderRequest) *v1.BrlOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.BrlOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultBrlOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationBrlStopOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationBrlStopOrderQuery(request *v1.UpdateBrlOrderRequest) 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:
|
||
|
return true
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// ShareBrlOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.ShareOrder
|
||
|
func ShareBrlOrderQuery(request *v1.ShareBrlOrderRequest) 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,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ResultBrlOrderMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param orderId
|
||
|
// @return *v1.SgdOrderResult
|
||
|
func ResultBrlOrderMessage(orderId string) *v1.BrlOrderResult {
|
||
|
return &v1.BrlOrderResult{
|
||
|
OrderId: orderId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareBrlPlaceOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param orderId
|
||
|
// @return *v1.SgdOrderReply
|
||
|
func ShareBrlPlaceOrderReply(check bool, err string, orderId string) *v1.BrlOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.BrlOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultBrlOrderMessage(orderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationSgdShareOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationBrlShareOrderQuery(request *v1.ShareBrlOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// VerificationBrlBotStockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationBrlBotStockTrade(req *v1.GetBrlBotStockTradeRequest) bool {
|
||
|
if req.GetPageSize() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetStatus() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetPageCount() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// BotStockBrlTradeReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @param data
|
||
|
// @param totalCount
|
||
|
// @return *v1.GetBotStockBrlTradeReply
|
||
|
func BotStockBrlTradeReply(check bool, err string, req *v1.GetBrlBotStockTradeRequest, data []*models.BotStockBrlTrade, totalCount int64) *v1.GetBotStockBrlTradeReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.GetBotStockBrlTradeReply{
|
||
|
Code: code,
|
||
|
Data: &v1.BotStockBrlTradeReply{
|
||
|
PageSize: req.PageSize,
|
||
|
PageCount: req.PageCount,
|
||
|
Data: BotStockBrlTradeMessage(data),
|
||
|
TotalCount: totalCount,
|
||
|
},
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockBrlTradeMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param stockList
|
||
|
// @return BotStockBrlTrade
|
||
|
func BotStockBrlTradeMessage(stockList []*models.BotStockBrlTrade) (stockTrade []*v1.BotStockBrlTrade) {
|
||
|
for _, value := range stockList {
|
||
|
stockTrade = append(stockTrade, &v1.BotStockBrlTrade{
|
||
|
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
|
||
|
}
|