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.
129 lines
3.7 KiB
129 lines
3.7 KiB
package service
|
|
|
|
import (
|
|
"context"
|
|
v1 "matchmaking-system/api/matchmaking/v1/forex"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
"matchmaking-system/internal/service/forex"
|
|
)
|
|
|
|
// GetBotForexTrade
|
|
//
|
|
// @Description: 外汇订单列表
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.GetBotForexTradeReply
|
|
// @return error
|
|
func (s *ConduitService) GetBotForexTrade(ctx context.Context, req *v1.GetBotForexTradeRequest) (*v1.GetBotForexTradeReply, error) {
|
|
if !forex.VerificationBotForexTrade(req) {
|
|
return forex.BotForexTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil
|
|
}
|
|
|
|
contractTradeList, totalCount, err := s.fr.BotForexTradeList(ctx, req.PageSize, req.PageCount, req.Status)
|
|
if err != nil {
|
|
return forex.BotForexTradeReply(false, err.Error(), req, nil, 0), nil
|
|
}
|
|
|
|
return forex.BotForexTradeReply(true, flags.SetNull, req, contractTradeList, totalCount), nil
|
|
}
|
|
|
|
// ForexPlaceOrder
|
|
//
|
|
// @Description: 外汇下单
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ForexReply
|
|
// @return error
|
|
func (s *ConduitService) ForexPlaceOrder(ctx context.Context, req *v1.ForexRequest) (*v1.ForexReply, error) {
|
|
if !forex.VerificationForexPlaceOrder(req) {
|
|
return forex.ForexPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil
|
|
}
|
|
|
|
orderId, err := s.fr.ForexPlaceOrder(ctx, forex.ForexOrderQuery(req))
|
|
if err != nil {
|
|
return forex.ForexPlaceOrderReply(false, err.Error(), flags.SetNull), nil
|
|
}
|
|
|
|
return forex.ForexPlaceOrderReply(true, flags.SetNull, orderId), nil
|
|
}
|
|
|
|
// ForexUpdatePlaceOrder
|
|
//
|
|
// @Description: 外汇设置止盈止损
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ForexReply
|
|
// @return error
|
|
func (s *ConduitService) ForexUpdatePlaceOrder(ctx context.Context, req *v1.UpdateForexRequest) (*v1.ForexReply, error) {
|
|
if !forex.VerificationForexUpdatePlaceOrder(req) {
|
|
return forex.ForexUpdatePlaceOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.fr.ForexUpdatePlaceOrder(ctx, forex.ForexStopQuery(req))
|
|
if err != nil {
|
|
return forex.ForexUpdatePlaceOrderReply(false, err.Error(), req), nil
|
|
}
|
|
|
|
return forex.ForexUpdatePlaceOrderReply(true, flags.SetNull, req), nil
|
|
}
|
|
|
|
// ForexPosition
|
|
//
|
|
// @Description: 外汇平仓
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ForexReply
|
|
// @return error
|
|
func (s *ConduitService) ForexPosition(ctx context.Context, req *v1.CancelForexRequest) (*v1.ForexReply, error) {
|
|
if !forex.VerificationForexPosition(req) {
|
|
return forex.ForexPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.fr.ForexPosition(ctx, req.OrderId)
|
|
if err != nil {
|
|
return forex.ForexPositionOrderReply(false, err.Error(), req), nil
|
|
}
|
|
|
|
return forex.ForexPositionOrderReply(true, flags.SetNull, req), nil
|
|
}
|
|
|
|
// ForexAllPosition
|
|
//
|
|
// @Description: 外汇一键平仓
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.AllForexReply
|
|
// @return error
|
|
func (s *ConduitService) ForexAllPosition(ctx context.Context, req *v1.AllForexRequest) (*v1.AllForexReply, error) {
|
|
if err := s.fr.ForexAllPosition(ctx); err != nil {
|
|
return forex.ForexAllPositionReply(false, err.Error()), nil
|
|
}
|
|
|
|
return forex.ForexAllPositionReply(true, flags.SetNull), nil
|
|
}
|
|
|
|
// ForexCancel
|
|
//
|
|
// @Description: 外汇撤单
|
|
// @receiver s
|
|
// @param ctx
|
|
// @param req
|
|
// @return *v1.ForexReply
|
|
// @return error
|
|
func (s *ConduitService) ForexCancel(ctx context.Context, req *v1.CancelForexRequest) (*v1.ForexReply, error) {
|
|
if !forex.VerificationForexCancel(req) {
|
|
return forex.ForexCancelOrderReply(false, flags.ErrIsParameter.Error(), req), nil
|
|
}
|
|
|
|
_, err := s.fr.ForexCancel(ctx, req.OrderId)
|
|
if err != nil {
|
|
return forex.ForexCancelOrderReply(false, err.Error(), req), nil
|
|
}
|
|
|
|
return forex.ForexCancelOrderReply(true, flags.SetNull, req), nil
|
|
}
|
|
|