fix: naming of prepare function of openPosition and add comments

This commit is contained in:
zenix 2022-11-21 12:13:19 +09:00
parent 109f4d0e3e
commit a6e0edbb3c
2 changed files with 20 additions and 4 deletions

View File

@ -181,6 +181,12 @@ func (e *GeneralOrderExecutor) CancelOrders(ctx context.Context, orders ...types
return err
}
// FastSubmitOrders send []types.SubmitOrder directly to the exchange without blocking wait on the status update.
// This is a faster version of SubmitOrders(). Created orders will be consumed in newly created goroutine (in non-backteset session).
// @param ctx: golang context type.
// @param submitOrders: Lists of types.SubmitOrder to be sent to the exchange.
// @return *types.SubmitOrder: SubmitOrder with calculated quantity and price.
// @return error: Error message.
func (e *GeneralOrderExecutor) FastSubmitOrders(ctx context.Context, submitOrders ...types.SubmitOrder) (types.OrderSlice, error) {
formattedOrders, err := e.session.FormatOrders(submitOrders)
if err != nil {
@ -297,7 +303,12 @@ func (e *GeneralOrderExecutor) reduceQuantityAndSubmitOrder(ctx context.Context,
return nil, multierr.Append(ErrExceededSubmitOrderRetryLimit, err)
}
func (e *GeneralOrderExecutor) OpenPositionPrepare(ctx context.Context, options *OpenPositionOptions) (*types.SubmitOrder, error) {
// Create new submitOrder from OpenPositionOptions.
// @param ctx: golang context type.
// @param options: OpenPositionOptions to control the generated SubmitOrder in a higher level way. Notice that the Price in options will be updated as the submitOrder price.
// @return *types.SubmitOrder: SubmitOrder with calculated quantity and price.
// @return error: Error message.
func (e *GeneralOrderExecutor) NewOrderFromOpenPosition(ctx context.Context, options *OpenPositionOptions) (*types.SubmitOrder, error) {
price := options.Price
submitOrder := types.SubmitOrder{
Symbol: e.position.Symbol,
@ -386,8 +397,13 @@ func (e *GeneralOrderExecutor) OpenPositionPrepare(ctx context.Context, options
return nil, errors.New("options Long or Short must be set")
}
// OpenPosition sends the orders generated from OpenPositionOptions to the exchange by calling SubmitOrders or reduceQuantityAndSubmitOrder.
// @param ctx: golang context type.
// @param options: OpenPositionOptions to control the generated SubmitOrder in a higher level way. Notice that the Price in options will be updated as the submitOrder price.
// @return types.OrderSlice: Created orders with information from exchange.
// @return error: Error message.
func (e *GeneralOrderExecutor) OpenPosition(ctx context.Context, options OpenPositionOptions) (types.OrderSlice, error) {
submitOrder, err := e.OpenPositionPrepare(ctx, &options)
submitOrder, err := e.NewOrderFromOpenPosition(ctx, &options)
if err != nil {
return nil, err
}

View File

@ -640,7 +640,7 @@ func (s *Strategy) klineHandler(ctx context.Context, kline types.KLine, counter
opt.Price = source
opt.Tags = []string{"long"}
submitOrder, err := s.GeneralOrderExecutor.OpenPositionPrepare(ctx, &opt)
submitOrder, err := s.GeneralOrderExecutor.NewOrderFromOpenPosition(ctx, &opt)
if err != nil {
errs := filterErrors(multierr.Errors(err))
if len(errs) > 0 {
@ -690,7 +690,7 @@ func (s *Strategy) klineHandler(ctx context.Context, kline types.KLine, counter
}
opt.Price = source
opt.Tags = []string{"short"}
submitOrder, err := s.GeneralOrderExecutor.OpenPositionPrepare(ctx, &opt)
submitOrder, err := s.GeneralOrderExecutor.NewOrderFromOpenPosition(ctx, &opt)
if err != nil {
errs := filterErrors(multierr.Errors(err))
if len(errs) > 0 {