mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
xfunding: cancel open orders before closing the futures position
This commit is contained in:
parent
0c9e0649c6
commit
7e2688b8c7
|
@ -416,6 +416,17 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
|||
|
||||
s.futuresSession.UserDataStream.OnStart(func() {
|
||||
if s.CloseFuturesPosition {
|
||||
|
||||
openOrders, err := s.futuresSession.Exchange.QueryOpenOrders(ctx, s.Symbol)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("query open orders error")
|
||||
} else {
|
||||
// canceling open orders
|
||||
if err = s.futuresSession.Exchange.CancelOrders(ctx, openOrders...); err != nil {
|
||||
log.WithError(err).Errorf("query open orders error")
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.futuresOrderExecutor.ClosePosition(ctx, fixedpoint.One); err != nil {
|
||||
log.WithError(err).Errorf("close position error")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user