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.
131 lines
4.0 KiB
131 lines
4.0 KiB
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"
|
|
)
|
|
|
|
// GetBotStockThaTrade
|
|
//
|
|
// @Description: 泰股订单列表
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.GetThaBotStockThaTradeReply
|
|
// @return error
|
|
func (s *ConduitService) GetBotStockThaTrade(ctx context.Context, req *v1.GetThaBotStockTradeRequest) (*v1.GetBotStockThaTradeReply, error) {
|
|
if !share.VerificationThaBotStockTrade(req) {
|
|
return share.BotStockThaTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil
|
|
}
|
|
|
|
stockTradeList, totalCount, err := s.ta.BotStockThaTradeList(ctx, req.PageSize, req.PageCount, req.Status)
|
|
if err != nil {
|
|
return share.BotStockThaTradeReply(false, err.Error(), req, nil, 0), nil
|
|
}
|
|
|
|
return share.BotStockThaTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil
|
|
}
|
|
|
|
// ShareThaPlaceOrder
|
|
//
|
|
// @Description: 泰股下单
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ThaOrderReply
|
|
// @return error
|
|
func (s *ConduitService) ShareThaPlaceOrder(ctx context.Context, req *v1.ShareThaOrderRequest) (*v1.ThaOrderReply, error) {
|
|
if !share.VerificationThaShareOrderQuery(req) {
|
|
return share.ShareThaPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil
|
|
}
|
|
|
|
orderId, err := s.ta.ShareThaPlaceOrder(ctx, share.ShareThaOrderQuery(req))
|
|
if err != nil {
|
|
return share.ShareThaPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil
|
|
}
|
|
|
|
return share.ShareThaPlaceOrderReply(true, flags.SetNull, orderId), nil
|
|
}
|
|
|
|
// ShareThaUpdateOrder
|
|
//
|
|
// @Description: 泰股设置止盈止损
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ThaOrderReply
|
|
// @return error
|
|
func (s *ConduitService) ShareThaUpdateOrder(ctx context.Context, req *v1.UpdateThaOrderRequest) (*v1.ThaOrderReply, error) {
|
|
if !share.VerificationThaStopOrderQuery(req) {
|
|
return share.ShareThaUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.ta.ShareThaUpdateOrder(ctx, share.StopThaOrderQuery(req))
|
|
if err != nil {
|
|
return share.ShareThaUpdateOrderReply(false, order.CheckShareError(err), req), nil
|
|
}
|
|
|
|
return share.ShareThaUpdateOrderReply(true, flags.SetNull, req), nil
|
|
}
|
|
|
|
// ShareThaPosition
|
|
//
|
|
// @Description: 泰股平仓
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ThaOrderReply
|
|
// @return error
|
|
func (s *ConduitService) ShareThaPosition(ctx context.Context, req *v1.CancelThaOrderRequest) (*v1.ThaOrderReply, error) {
|
|
if !share.VerificationThaSharePosition(req) {
|
|
return share.ShareThaPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.ta.ShareThaPosition(ctx, req.OrderId)
|
|
if err != nil {
|
|
return share.ShareThaPositionOrderReply(false, order.CheckShareError(err), req), nil
|
|
}
|
|
|
|
return share.ShareThaPositionOrderReply(true, flags.SetNull, req), nil
|
|
}
|
|
|
|
// ShareThaAllPosition
|
|
//
|
|
// @Description: 泰股一键平仓
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.AllThaOrderReply
|
|
// @return error
|
|
func (s *ConduitService) ShareThaAllPosition(ctx context.Context, req *v1.AllThaOrderRequest) (*v1.AllThaOrderReply, error) {
|
|
if err := s.ta.ShareThaAllPosition(ctx); err != nil {
|
|
return share.ShareAllThaPositionRequest(false, order.CheckShareError(err)), nil
|
|
}
|
|
|
|
return share.ShareAllThaPositionRequest(true, flags.SetNull), nil
|
|
}
|
|
|
|
// ShareThaCancel
|
|
//
|
|
// @Description: 泰股撤单
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ThaOrderReply
|
|
// @return error
|
|
func (s *ConduitService) ShareThaCancel(ctx context.Context, req *v1.CancelThaOrderRequest) (*v1.ThaOrderReply, error) {
|
|
if !share.VerificationThaShareCancel(req) {
|
|
return share.ShareThaCancelReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.ta.ShareThaCancel(ctx, req.OrderId)
|
|
if err != nil {
|
|
return share.ShareThaCancelReply(false, order.CheckShareError(err), req), nil
|
|
}
|
|
|
|
return share.ShareThaCancelReply(true, flags.SetNull, req), nil
|
|
}
|
|
|