mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Merge pull request #1822 from c9s/c9s/fix-universal-cancel-orders
IMPROVE: [tradingutil] improve UniversalCancelAllOrders by querying open orders
This commit is contained in:
commit
bd76a0e254
|
@ -607,8 +607,7 @@ func (s *Strategy) CrossRun(
|
|||
s.hedgerConnectivity = types.NewConnectivity()
|
||||
s.hedgerConnectivity.Bind(s.hedgeSession.UserDataStream)
|
||||
|
||||
connGroup := types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity)
|
||||
s.connectivityGroup = connGroup
|
||||
s.connectivityGroup = types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity)
|
||||
|
||||
if s.RecoverTrade {
|
||||
go s.runTradeRecover(ctx)
|
||||
|
@ -622,7 +621,7 @@ func (s *Strategy) CrossRun(
|
|||
return
|
||||
case <-time.After(3 * time.Minute):
|
||||
log.Panicf("authentication timeout, exiting...")
|
||||
case <-connGroup.AllAuthedC(ctx):
|
||||
case <-s.connectivityGroup.AllAuthedC(ctx):
|
||||
}
|
||||
|
||||
log.Infof("user data stream authenticated, start placing orders...")
|
||||
|
@ -1192,6 +1191,8 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {
|
|||
return
|
||||
}
|
||||
|
||||
s.logger.Infof("%d orders are generated, placing...", len(submitOrders))
|
||||
|
||||
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
||||
if err != nil {
|
||||
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
||||
|
|
|
@ -55,26 +55,39 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, symb
|
|||
}
|
||||
}
|
||||
|
||||
if len(openOrders) == 0 {
|
||||
log.Warnf("empty open orders, unable to call specific cancel all orders api, skip")
|
||||
return nil
|
||||
}
|
||||
if len(openOrders) > 0 {
|
||||
if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
|
||||
var groupIds = CollectOrderGroupIds(openOrders)
|
||||
for _, groupId := range groupIds {
|
||||
if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil {
|
||||
anyErr = err
|
||||
}
|
||||
}
|
||||
|
||||
if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
|
||||
var groupIds = CollectOrderGroupIds(openOrders)
|
||||
for _, groupId := range groupIds {
|
||||
if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil {
|
||||
anyErr = err
|
||||
if anyErr == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if anyErr == nil {
|
||||
return nil
|
||||
if anyErr != nil {
|
||||
return anyErr
|
||||
}
|
||||
}
|
||||
|
||||
if anyErr != nil {
|
||||
return anyErr
|
||||
// if we have no open order, then use the exchange service query to get the open orders and then cancel them all
|
||||
if len(openOrders) == 0 {
|
||||
if len(symbol) == 0 {
|
||||
log.Warnf("empty open orders, unable to call specific cancel all orders api, skip")
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
openOrders, err = retry.QueryOpenOrdersUntilSuccessful(ctx, exchange, symbol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return retry.CancelOrdersUntilSuccessful(ctx, exchange, openOrders...)
|
||||
}
|
||||
|
||||
return fmt.Errorf("unable to cancel all orders, openOrders:%+v", openOrders)
|
||||
|
|
Loading…
Reference in New Issue
Block a user