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.
132 lines
4.0 KiB
132 lines
4.0 KiB
2 months ago
|
package service
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"matchmaking-system/internal/pkg/flags"
|
||
|
"matchmaking-system/internal/service/order"
|
||
|
"matchmaking-system/internal/service/share"
|
||
|
|
||
|
v1 "matchmaking-system/api/matchmaking/v1/share"
|
||
|
)
|
||
|
|
||
|
// GetBotStockSgdTrade
|
||
|
//
|
||
|
// @Description: 新加坡股订单列表
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.GetBotStockSgdTradeReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) GetBotStockSgdTrade(ctx context.Context, req *v1.GetSgdBotStockTradeRequest) (*v1.GetBotStockSgdTradeReply, error) {
|
||
|
if !share.VerificationSgdBotStockTrade(req) {
|
||
|
return share.BotStockSgdTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil
|
||
|
}
|
||
|
|
||
|
stockTradeList, totalCount, err := s.sg.BotStockSgdTradeList(ctx, req.PageSize, req.PageCount, req.Status)
|
||
|
if err != nil {
|
||
|
return share.BotStockSgdTradeReply(false, err.Error(), req, nil, 0), nil
|
||
|
}
|
||
|
|
||
|
return share.BotStockSgdTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil
|
||
|
}
|
||
|
|
||
|
// ShareSgdPlaceOrder
|
||
|
//
|
||
|
// @Description: 新加坡股下单
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.SgdOrderReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) ShareSgdPlaceOrder(ctx context.Context, req *v1.ShareSgdOrderRequest) (*v1.SgdOrderReply, error) {
|
||
|
if !share.VerificationSgdShareOrderQuery(req) {
|
||
|
return share.ShareSgdPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil
|
||
|
}
|
||
|
|
||
|
orderId, err := s.sg.ShareSgdPlaceOrder(ctx, share.ShareSgdOrderQuery(req))
|
||
|
if err != nil {
|
||
|
return share.ShareSgdPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil
|
||
|
}
|
||
|
|
||
|
return share.ShareSgdPlaceOrderReply(true, flags.SetNull, orderId), nil
|
||
|
}
|
||
|
|
||
|
// ShareSgdUpdateOrder
|
||
|
//
|
||
|
// @Description: 新加坡股设置止盈止损
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.SgdOrderReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) ShareSgdUpdateOrder(ctx context.Context, req *v1.UpdateSgdOrderRequest) (*v1.SgdOrderReply, error) {
|
||
|
if !share.VerificationSgdStopOrderQuery(req) {
|
||
|
return share.ShareSgdUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
||
|
}
|
||
|
|
||
|
_, err := s.sg.ShareSgdUpdateOrder(ctx, share.StopSgdOrderQuery(req))
|
||
|
if err != nil {
|
||
|
return share.ShareSgdUpdateOrderReply(false, order.CheckShareError(err), req), nil
|
||
|
}
|
||
|
|
||
|
return share.ShareSgdUpdateOrderReply(true, flags.SetNull, req), nil
|
||
|
}
|
||
|
|
||
|
// ShareSgdPosition
|
||
|
//
|
||
|
// @Description: 新加坡股平仓
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.SgdOrderReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) ShareSgdPosition(ctx context.Context, req *v1.CancelSgdOrderRequest) (*v1.SgdOrderReply, error) {
|
||
|
if !share.VerificationSgdSharePosition(req) {
|
||
|
return share.ShareSgdPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
||
|
}
|
||
|
|
||
|
_, err := s.sg.ShareSgdPosition(ctx, req.OrderId)
|
||
|
if err != nil {
|
||
|
return share.ShareSgdPositionOrderReply(false, order.CheckShareError(err), req), nil
|
||
|
}
|
||
|
|
||
|
return share.ShareSgdPositionOrderReply(true, flags.SetNull, req), nil
|
||
|
}
|
||
|
|
||
|
// ShareSgdAllPosition
|
||
|
//
|
||
|
// @Description: 新加坡股一键平仓
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.AllSgdOrderReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) ShareSgdAllPosition(ctx context.Context, req *v1.AllSgdOrderRequest) (*v1.AllSgdOrderReply, error) {
|
||
|
if err := s.sg.ShareSgdAllPosition(ctx); err != nil {
|
||
|
return share.ShareAllSgdPositionRequest(false, order.CheckShareError(err)), nil
|
||
|
}
|
||
|
|
||
|
return share.ShareAllSgdPositionRequest(true, flags.SetNull), nil
|
||
|
}
|
||
|
|
||
|
// ShareSgdCancel
|
||
|
//
|
||
|
// @Description: 新加坡股撤单
|
||
|
// @receiver s
|
||
|
// @param ctx
|
||
|
// @param req
|
||
|
// @return *v1.SgdOrderReply
|
||
|
// @return error
|
||
|
func (s *ConduitService) ShareSgdCancel(ctx context.Context, req *v1.CancelSgdOrderRequest) (*v1.SgdOrderReply, error) {
|
||
|
if !share.VerificationSgdShareCancel(req) {
|
||
|
return share.ShareSgdCancelReply(false, flags.ErrIsParameter.Error(), req), nil
|
||
|
}
|
||
|
|
||
|
_, err := s.sg.ShareSgdCancel(ctx, req.OrderId)
|
||
|
if err != nil {
|
||
|
return share.ShareSgdCancelReply(false, order.CheckShareError(err), req), nil
|
||
|
}
|
||
|
|
||
|
return share.ShareSgdCancelReply(true, flags.SetNull, req), nil
|
||
|
}
|