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.
359 lines
8.6 KiB
359 lines
8.6 KiB
2 months ago
|
package option
|
||
|
|
||
|
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/option"
|
||
|
models "matchmaking-system/internal/pkg/model"
|
||
|
)
|
||
|
|
||
|
// OptionInrCancelReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OptionInrOrderReply
|
||
|
func OptionInrCancelReply(check bool, err string, req *v1.CancelOptionInrOrderRequest) *v1.OptionInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OptionInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultOptionInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationOptionInrCancel
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationOptionInrCancel(req *v1.CancelOptionInrOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// OptionInrAllPositionRequest
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.AllOptionInrOrderReply
|
||
|
func OptionInrAllPositionRequest(check bool, err string) *v1.AllOptionInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.AllOptionInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: "",
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OptionInrPositionOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OptionInrOrderReply
|
||
|
func OptionInrPositionOrderReply(check bool, err string, req *v1.CancelOptionInrOrderRequest) *v1.OptionInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OptionInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultOptionInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationOptionInrPosition
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationOptionInrPosition(req *v1.CancelOptionInrOrderRequest) bool {
|
||
|
if len(req.GetOrderId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// StopOptionInrOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.StopOrder
|
||
|
func StopOptionInrOrderQuery(request *v1.UpdateOptionInrOrderRequest) structure.StopOrder {
|
||
|
return structure.StopOrder{
|
||
|
OrderId: request.OrderId,
|
||
|
StopType: request.StopType,
|
||
|
StopLossPrice: request.StopLossPrice,
|
||
|
StopWinPrice: request.StopWinPrice,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OptionInrUpdateOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @return *v1.OptionInrOrderReply
|
||
|
func OptionInrUpdateOrderReply(check bool, err string, req *v1.UpdateOptionInrOrderRequest) *v1.OptionInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.OptionInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultOptionInrOrderMessage(req.OrderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationOptionInrStopOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationOptionInrStopOrderQuery(request *v1.UpdateOptionInrOrderRequest) 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
|
||
|
}
|
||
|
|
||
|
// OptionInrOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return structure.ShareOrder
|
||
|
func OptionInrOrderQuery(request *v1.OptionInrOrderRequest) 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,
|
||
|
StrikePrice: request.StrikePrice,
|
||
|
StockCode: request.StockCode,
|
||
|
StopTime: request.StopTime,
|
||
|
Multiplier: request.Multiplier,
|
||
|
TradingType: request.TradingType,
|
||
|
Ask: request.Ask,
|
||
|
Bid: request.Bid,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ResultOptionInrOrderMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param orderId
|
||
|
// @return *v1.OptionInrOrderResult
|
||
|
func ResultOptionInrOrderMessage(orderId string) *v1.OptionInrOrderResult {
|
||
|
return &v1.OptionInrOrderResult{
|
||
|
OrderId: orderId,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OptionInrPlaceOrderReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param orderId
|
||
|
// @return *v1.OptionInrOrderReply
|
||
|
func OptionInrPlaceOrderReply(check bool, err string, orderId string) *v1.OptionInrOrderReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
|
||
|
return &v1.OptionInrOrderReply{
|
||
|
Code: code,
|
||
|
Data: ResultOptionInrOrderMessage(orderId),
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationOptionInrOrderQuery
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param request
|
||
|
// @return bool
|
||
|
func VerificationOptionInrOrderQuery(request *v1.OptionInrOrderRequest) bool {
|
||
|
if len(request.GetMultiplier()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetStockCode()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetStockId()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetMarketMoney()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetOrderNumber()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetServiceCost()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetStrikePrice()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetStopTime()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetAsk()) <= 0 {
|
||
|
return false
|
||
|
}
|
||
|
if len(request.GetBid()) <= 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
|
||
|
}
|
||
|
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
|
||
|
}
|
||
|
switch request.TradingType {
|
||
|
case 1: // 买入
|
||
|
case 2: // 卖出
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// BotStockOptionInrTradeMessage
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param stockList
|
||
|
// @return BotInrStockInrTrade
|
||
|
func BotStockOptionInrTradeMessage(stockList []*models.BotStockOptionInrTrade) (stockTrade []*v1.BotStockOptionInrTrade) {
|
||
|
for _, value := range stockList {
|
||
|
stockTrade = append(stockTrade, &v1.BotStockOptionInrTrade{
|
||
|
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),
|
||
|
StopTime: value.StopTime,
|
||
|
StrikePrice: value.StrikePrice,
|
||
|
StockCode: value.StockCode,
|
||
|
TradingType: int64(value.TradingType),
|
||
|
Multiplier: int64(value.Multiplier),
|
||
|
CostPrice: value.CostPrice,
|
||
|
Ratio: int64(value.Ratio),
|
||
|
Bid: value.Bid,
|
||
|
Ask: value.Ask,
|
||
|
})
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// BotStockOptionInrTradeReply
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param check
|
||
|
// @param err
|
||
|
// @param req
|
||
|
// @param data
|
||
|
// @param totalCount
|
||
|
// @return *v1.GetBotStockOptionInrTradeReply
|
||
|
func BotStockOptionInrTradeReply(check bool, err string, req *v1.GetBotStockOptionInrTradeRequest, data []*models.BotStockOptionInrTrade, totalCount int64) *v1.GetBotStockOptionInrTradeReply {
|
||
|
code, replyStr := order.ResultCodeSrr(check, err)
|
||
|
return &v1.GetBotStockOptionInrTradeReply{
|
||
|
Code: code,
|
||
|
Data: &v1.BotStockOptionInrTradeData{
|
||
|
PageSize: req.PageSize,
|
||
|
PageCount: req.PageCount,
|
||
|
Data: BotStockOptionInrTradeMessage(data),
|
||
|
TotalCount: totalCount,
|
||
|
},
|
||
|
Message: replyStr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// VerificationBotStockOptionInrTrade
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param req
|
||
|
// @return bool
|
||
|
func VerificationBotStockOptionInrTrade(req *v1.GetBotStockOptionInrTradeRequest) bool {
|
||
|
if req.GetPageSize() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetStatus() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
if req.GetPageCount() < 0 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|