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.
317 lines
7.3 KiB
317 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"
|
||
|
)
|
||
|
|
||
|
// ShareGbxCancelReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderGbxReply
|
||
|
func ShareGbxCancelReply(check bool, err string, req *v1.CancelGbxOrderRequest) *v1.OrderGbxReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OrderGbxReply{
|
||
|
Code: code,
|
||
|
Data: ResultGbxOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationGbxShareCancel
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationGbxShareCancel(req *v1.CancelGbxOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// ShareAllGbxPositionRequest
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @return *v1.AllGbxOrderReply
|
||
|
func ShareAllGbxPositionRequest(check bool, err string) *v1.AllGbxOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.AllGbxOrderReply{
|
||
|
Code: code,
|
||
|
Data: "",
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareGbxPositionOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderGbxReply
|
||
|
func ShareGbxPositionOrderReply(check bool, err string, req *v1.CancelGbxOrderRequest) *v1.OrderGbxReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OrderGbxReply{
|
||
|
Code: code,
|
||
|
Data: ResultGbxOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationGbxSharePosition
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationGbxSharePosition(req *v1.CancelGbxOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// StopGbxOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.StopOrder
|
||
|
func StopGbxOrderQuery(request *v1.UpdateGbxOrderRequest) structure.StopOrder {
|
||
|
return structure.StopOrder{
|
||
|
OrderId: request.OrderId,
|
||
|
StopType: request.StopType,
|
||
|
StopLossPrice: request.StopLossPrice,
|
||
|
StopWinPrice: request.StopWinPrice,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareGbxUpdateOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OrderGbxReply
|
||
|
func ShareGbxUpdateOrderReply(check bool, err string, req *v1.UpdateGbxOrderRequest) *v1.OrderGbxReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OrderGbxReply{
|
||
|
Code: code,
|
||
|
Data: ResultGbxOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationGbxStopOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationGbxStopOrderQuery(request *v1.UpdateGbxOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// ShareGbxOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.ShareOrder
|
||
|
func ShareGbxOrderQuery(request *v1.OrderGbxRequest) 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,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ResultGbxOrderMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param orderId
|
||
|
// @return *v1.OrderGbxResult
|
||
|
func ResultGbxOrderMessage(orderId string) *v1.OrderGbxResult {
|
||
|
return &v1.OrderGbxResult{
|
||
|
OrderId: orderId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ShareGbxPlaceOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param orderId
|
||
|
// @return *v1.OrderGbxReply
|
||
|
func ShareGbxPlaceOrderReply(check bool, err string, orderId string) *v1.OrderGbxReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OrderGbxReply{
|
||
|
Code: code,
|
||
|
Data: ResultGbxOrderMessage(orderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationGbxShareOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationGbxShareOrderQuery(request *v1.OrderGbxRequest) 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
|
||
|
}
|
||
|
|
||
|
// VerificationGbxBotStockTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationGbxBotStockTrade(req *v1.GetBotStockGbxTradeRequest) bool {
|
||
|
if req.GetPageSize() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetStatus() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetPageCount() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// BotStockGbxTradeReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @param data
|
||
|
// @param totalCount
|
||
|
// @return *v1.GetBotStockGbxTradeReply
|
||
|
func BotStockGbxTradeReply(check bool, err string, req *v1.GetBotStockGbxTradeRequest, data []*models.BotStockGbxTrade, totalCount int64) *v1.GetBotStockGbxTradeReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.GetBotStockGbxTradeReply{
|
||
|
Code: code,
|
||
|
Data: &v1.BotStockGbxTradeData{
|
||
|
PageSize: req.PageSize,
|
||
|
PageCount: req.PageCount,
|
||
|
Data: BotStockGbxTradeMessage(data),
|
||
|
TotalCount: totalCount,
|
||
|
},
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BotStockGbxTradeMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param stockList
|
||
|
// @return stockTrade
|
||
|
func BotStockGbxTradeMessage(stockList []*models.BotStockGbxTrade) (stockTrade []*v1.BotOrderGbxTrade) {
|
||
|
for _, value := range stockList {
|
||
|
stockTrade = append(stockTrade, &v1.BotOrderGbxTrade{
|
||
|
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
|
||
|
}
|