mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pivotshort: clean up ClosePosition method
This commit is contained in:
parent
dbc6d4fb44
commit
09d0a9bbc7
|
@ -162,35 +162,16 @@ func (s *Strategy) placeMarketSell(ctx context.Context, quantity fixedpoint.Valu
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Strategy) InstanceID() string {
|
||||||
|
return fmt.Sprintf("%s:%s", ID, s.Symbol)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Strategy) CurrentPosition() *types.Position {
|
func (s *Strategy) CurrentPosition() *types.Position {
|
||||||
return s.Position
|
return s.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error {
|
func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error {
|
||||||
// Cancel active orders
|
return s.orderExecutor.ClosePosition(ctx, percentage)
|
||||||
_ = s.orderExecutor.GracefulCancel(ctx)
|
|
||||||
|
|
||||||
submitOrder := s.Position.NewMarketCloseOrder(percentage) // types.SubmitOrder{
|
|
||||||
if submitOrder == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.session.Margin {
|
|
||||||
submitOrder.MarginSideEffect = s.Exit.MarginSideEffect
|
|
||||||
}
|
|
||||||
|
|
||||||
bbgo.Notify("Closing %s position by %f", s.Symbol, percentage.Float64())
|
|
||||||
log.Infof("Closing %s position by %f", s.Symbol, percentage.Float64())
|
|
||||||
_, err := s.orderExecutor.SubmitOrders(ctx, *submitOrder)
|
|
||||||
if err != nil {
|
|
||||||
bbgo.Notify("close %s position error", s.Symbol)
|
|
||||||
log.WithError(err).Errorf("close %s position error", s.Symbol)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Strategy) InstanceID() string {
|
|
||||||
return fmt.Sprintf("%s:%s", ID, s.Symbol)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user