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.
346 lines
7.5 KiB
346 lines
7.5 KiB
package money
|
|
|
|
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/money"
|
|
models "matchmaking-system/internal/pkg/model"
|
|
)
|
|
|
|
// MoneyStopQuery
|
|
//
|
|
// @Description:
|
|
// @param request
|
|
// @return structure.StopOrder
|
|
func MoneyStopQuery(request *v1.UpdateMoneyRequest) structure.StopOrder {
|
|
return structure.StopOrder{
|
|
OrderId: request.OrderId,
|
|
StopType: request.StopType,
|
|
StopLossPrice: request.StopLossPrice,
|
|
StopWinPrice: request.StopWinPrice,
|
|
}
|
|
}
|
|
|
|
// MoneyCancelOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func MoneyCancelOrderReply(check bool, err string, req *v1.CancelMoneyRequest) *v1.MoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.MoneyReply{
|
|
Code: code,
|
|
Data: ResultMoneyMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationMoneyCancel
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationMoneyCancel(req *v1.CancelMoneyRequest) bool {
|
|
if len(req.GetOrderId()) <= 0 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// MoneyAllPositionReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.AllOrderReply
|
|
func MoneyAllPositionReply(check bool, err string) *v1.AllMoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.AllMoneyReply{
|
|
Code: code,
|
|
Data: "",
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// MoneyPositionOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func MoneyPositionOrderReply(check bool, err string, req *v1.CancelMoneyRequest) *v1.MoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.MoneyReply{
|
|
Code: code,
|
|
Data: ResultMoneyMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationMoneyPosition
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationMoneyPosition(req *v1.CancelMoneyRequest) bool {
|
|
if len(req.GetOrderId()) <= 0 {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// MoneyUpdatePlaceOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @return *v1.OrderReply
|
|
func MoneyUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateMoneyRequest) *v1.MoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.MoneyReply{
|
|
Code: code,
|
|
Data: ResultMoneyMessage(req.OrderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationMoneyUpdatePlaceOrder
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationMoneyUpdatePlaceOrder(req *v1.UpdateMoneyRequest) 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
|
|
}
|
|
|
|
// VerificationBotMoneyTrade
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func VerificationBotMoneyTrade(req *v1.GetBotMoneyTradeRequest) 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
|
|
}
|
|
|
|
// BotMoneyTradeMessage
|
|
//
|
|
// @Description:
|
|
// @param stockList
|
|
// @return contractTrade
|
|
func BotMoneyTradeMessage(stockList []*models.BotMoneyTrade) (contractTrade []*v1.BotMoneyTrade) {
|
|
for _, value := range stockList {
|
|
contractTrade = append(contractTrade, &v1.BotMoneyTrade{
|
|
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,
|
|
EarnestMoney: value.MarketMoney,
|
|
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),
|
|
OvernightCost: value.OvernightCost,
|
|
KeepDecimal: strconv.Itoa(value.KeepDecimal),
|
|
PryNum: strconv.Itoa(value.PryNum),
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
// BotMoneyTradeReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param req
|
|
// @param data
|
|
// @param totalCount
|
|
// @return *v1.GetBotMoneyTradeReply
|
|
func BotMoneyTradeReply(check bool, err string, req *v1.GetBotMoneyTradeRequest, data []*models.BotMoneyTrade, totalCount int64) *v1.GetBotMoneyTradeReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
return &v1.GetBotMoneyTradeReply{
|
|
Code: code,
|
|
Data: &v1.BotMoneyTradeData{
|
|
PageSize: req.PageSize,
|
|
PageCount: req.PageCount,
|
|
Data: BotMoneyTradeMessage(data),
|
|
TotalCount: totalCount,
|
|
},
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// VerificationMoneyPlaceOrder
|
|
//
|
|
// @Description: 合约下单参数判定
|
|
// @param req
|
|
// @return bool
|
|
func VerificationMoneyPlaceOrder(req *v1.MoneyRequest) bool {
|
|
if len(req.GetPryNum()) <= 0 {
|
|
return false
|
|
}
|
|
if len(req.GetStockId()) <= 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
|
|
}
|
|
|
|
// MoneyPlaceOrderReply
|
|
//
|
|
// @Description:
|
|
// @param check
|
|
// @param err
|
|
// @param orderId
|
|
// @return *v1.OrderReply
|
|
func MoneyPlaceOrderReply(check bool, err string, orderId string) *v1.MoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
|
|
return &v1.MoneyReply{
|
|
Code: code,
|
|
Data: ResultMoneyMessage(orderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
|
|
// ResultMoneyMessage
|
|
//
|
|
// @Description:
|
|
// @param orderId
|
|
// @return *v1.Result
|
|
func ResultMoneyMessage(orderId string) *v1.MoneyResult {
|
|
return &v1.MoneyResult{
|
|
OrderId: orderId,
|
|
}
|
|
}
|
|
|
|
// MoneyOrderQuery
|
|
//
|
|
// @Description:
|
|
// @param request
|
|
// @return structure.MoneyOrder
|
|
func MoneyOrderQuery(request *v1.MoneyRequest) structure.MoneyOrder {
|
|
return structure.MoneyOrder{
|
|
StockId: request.StockId,
|
|
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,
|
|
Type: request.Type,
|
|
}
|
|
}
|
|
|
|
// VerificationSpotsPlaceOrder
|
|
//
|
|
// @Description:
|
|
// @param req
|
|
// @return bool
|
|
func SharePlaceOrderReply(check bool, err string, orderId string) *v1.MoneyReply {
|
|
code, replyStr := order.ResultCodeSrr(check, err)
|
|
|
|
return &v1.MoneyReply{
|
|
Code: code,
|
|
Data: ResultMessage(orderId),
|
|
Message: replyStr,
|
|
}
|
|
}
|
|
func ResultMessage(orderId string) *v1.MoneyResult {
|
|
return &v1.MoneyResult{
|
|
OrderId: orderId,
|
|
}
|
|
}
|
|
|