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.
326 lines
7.4 KiB
326 lines
7.4 KiB
package virtual
|
|
|
|
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/virtually"
|
|
models "matchmaking-system/internal/pkg/model"
|
|
)
|
|
|
|
// ContractStopQuery
|
|
//
|
|
// @Description:
|
|
// @param request
|
|
// @return structure.StopOrder
|
|
func ContractStopQuery(request *v1.UpdateContractRequest) structure.StopOrder {
|
|
return structure.StopOrder{
|
|
OrderId: request.OrderId,
|
|
StopType: request.StopType,
|
|
StopLossPrice: request.StopLossPrice,
|
|
StopWinPrice: request.StopWinPrice,
|
|
}
|
|
}
|
|
|
|
// ContractCancelOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func ContractCancelOrderReply(check bool, err string, req *v1.CancelContractRequest) *v1.ContractReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.ContractReply{
|
|
Code: code,
|
|
Data: ResultContractMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationContractCancel
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationContractCancel(req *v1.CancelContractRequest) bool {
|
|
if len(req.GetOrderId()) <= 0 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// ContractAllPositionReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.AllOrderReply
|
|
func ContractAllPositionReply(check bool, err string) *v1.AllContractReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.AllContractReply{
|
|
Code: code,
|
|
Data: "",
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// ContractPositionOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func ContractPositionOrderReply(check bool, err string, req *v1.CancelContractRequest) *v1.ContractReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.ContractReply{
|
|
Code: code,
|
|
Data: ResultContractMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationContractPosition
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationContractPosition(req *v1.CancelContractRequest) bool {
|
|
if len(req.GetOrderId()) <= 0 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// ContractUpdatePlaceOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func ContractUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateContractRequest) *v1.ContractReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.ContractReply{
|
|
Code: code,
|
|
Data: ResultContractMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationContractUpdatePlaceOrder
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationContractUpdatePlaceOrder(req *v1.UpdateContractRequest) bool {
|
|
if len(req.GetOrderId()) <= 0 {
|
|
return false
|
|
}
|
|
switch req.StopType {
|
|
case 0:
|
|
return true
|
|
case 1:
|
|
if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 {
|
|
return false
|
|
}
|
|
default:
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// VerificationBotContractTrade
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationBotContractTrade(req *v1.GetBotContractTradeRequest) bool {
|
|
if req.GetPageSize() < 0 {
|
|
return false
|
|
}
|
|
if req.GetStatus() < 0 {
|
|
return false
|
|
}
|
|
if req.GetPageCount() < 0 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// BotContractTradeMessage
|
|
//
|
|
// @Description:
|
|
// @param stockList
|
|
// @return contractTrade
|
|
func BotContractTradeMessage(stockList []*models.BotContractTrade) (contractTrade []*v1.BotContractTrade) {
|
|
for _, value := range stockList {
|
|
faceValue := strconv.FormatInt(value.FaceValue, 10)
|
|
contractTrade = append(contractTrade, &v1.BotContractTrade{
|
|
OrderId: value.OrderId,
|
|
ContractId: value.ContractId,
|
|
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,
|
|
EarnestMoney: value.EarnestMoney,
|
|
OrderMoney: value.OrderMoney,
|
|
Status: int64(value.Status),
|
|
ClosingCost: value.ClosingCost,
|
|
CreateTime: timestamppb.New(value.CreateTime),
|
|
UpdateTime: timestamppb.New(value.UpdateTime),
|
|
OpenTime: timestamppb.New(value.OpenTime),
|
|
ClosingTime: timestamppb.New(value.ClosingTime),
|
|
FaceValue: faceValue,
|
|
OvernightCost: value.OvernightCost,
|
|
KeepDecimal: strconv.Itoa(value.KeepDecimal),
|
|
PryNum: strconv.Itoa(value.PryNum),
|
|
SecondTime: strconv.Itoa(value.SecondTime),
|
|
State: int64(value.State),
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
// BotContractTradeReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @param data
|
|
// @param totalCount
|
|
// @return *v1.GetBotContractTradeReply
|
|
func BotContractTradeReply(check bool, err string, req *v1.GetBotContractTradeRequest, data []*models.BotContractTrade, totalCount int64) *v1.GetBotContractTradeReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.GetBotContractTradeReply{
|
|
Code: code,
|
|
Data: &v1.BotContractTradeData{
|
|
PageSize: req.PageSize,
|
|
PageCount: req.PageCount,
|
|
Data: BotContractTradeMessage(data),
|
|
TotalCount: totalCount,
|
|
},
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationContractPlaceOrder
|
|
//
|
|
// @Description: 合约下单参数判定
|
|
// @param req
|
|
// @return bool
|
|
func VerificationContractPlaceOrder(req *v1.ContractRequest) bool {
|
|
if len(req.GetPryNum()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetContractId()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetOrderAmount()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetOrderNumber()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetEarnestMoney()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetServiceCost()) <= 0 {
|
|
return false
|
|
}
|
|
switch req.StopType {
|
|
case 1:
|
|
if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 {
|
|
return false
|
|
}
|
|
}
|
|
|
|
switch req.TradeType {
|
|
case 1:
|
|
case 2:
|
|
default:
|
|
return false
|
|
}
|
|
|
|
switch req.DealType {
|
|
case 1:
|
|
if len(req.GetLimitPrice()) <= 0 {
|
|
return false
|
|
}
|
|
case 2:
|
|
if len(req.GetMarketPrice()) <= 0 {
|
|
return false
|
|
}
|
|
default:
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// ContractPlaceOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param orderId
|
|
// @return *v1.OrderReply
|
|
func ContractPlaceOrderReply(check bool, err string, orderId string) *v1.ContractReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
|
|
return &v1.ContractReply{
|
|
Code: code,
|
|
Data: ResultContractMessage(orderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// ResultContractMessage
|
|
//
|
|
// @Description:
|
|
// @param orderId
|
|
// @return *v1.Result
|
|
func ResultContractMessage(orderId string) *v1.ContractResult {
|
|
return &v1.ContractResult{
|
|
OrderId: orderId,
|
|
}
|
|
}
|
|
|
|
// ContractOrderQuery
|
|
//
|
|
// @Description:
|
|
// @param request
|
|
// @return structure.ContractOrder
|
|
func ContractOrderQuery(request *v1.ContractRequest) structure.ContractOrder {
|
|
return structure.ContractOrder{
|
|
ContractId: request.ContractId,
|
|
TradeType: request.TradeType,
|
|
DealType: request.DealType,
|
|
LimitPrice: request.LimitPrice,
|
|
MarketPrice: request.MarketPrice,
|
|
OrderAmount: request.OrderAmount,
|
|
OrderNumber: request.OrderNumber,
|
|
EarnestMoney: request.EarnestMoney,
|
|
ServiceCost: request.ServiceCost,
|
|
StopType: request.StopType,
|
|
StopLossPrice: request.StopLossPrice,
|
|
StopWinPrice: request.StopWinPrice,
|
|
PryNum: request.PryNum,
|
|
}
|
|
}
|
|
|