mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
tradingutil: improve UniversalCancelAllOrders by querying open orders
This commit is contained in:
parent
8dcd6f2f72
commit
9d2e61dc6e
|
@ -607,8 +607,7 @@ func (s *Strategy) CrossRun(
|
||||||
s.hedgerConnectivity = types.NewConnectivity()
|
s.hedgerConnectivity = types.NewConnectivity()
|
||||||
s.hedgerConnectivity.Bind(s.hedgeSession.UserDataStream)
|
s.hedgerConnectivity.Bind(s.hedgeSession.UserDataStream)
|
||||||
|
|
||||||
connGroup := types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity)
|
s.connectivityGroup = types.NewConnectivityGroup(s.makerConnectivity, s.hedgerConnectivity)
|
||||||
s.connectivityGroup = connGroup
|
|
||||||
|
|
||||||
if s.RecoverTrade {
|
if s.RecoverTrade {
|
||||||
go s.runTradeRecover(ctx)
|
go s.runTradeRecover(ctx)
|
||||||
|
@ -622,7 +621,7 @@ func (s *Strategy) CrossRun(
|
||||||
return
|
return
|
||||||
case <-time.After(3 * time.Minute):
|
case <-time.After(3 * time.Minute):
|
||||||
log.Panicf("authentication timeout, exiting...")
|
log.Panicf("authentication timeout, exiting...")
|
||||||
case <-connGroup.AllAuthedC(ctx):
|
case <-s.connectivityGroup.AllAuthedC(ctx):
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("user data stream authenticated, start placing orders...")
|
log.Infof("user data stream authenticated, start placing orders...")
|
||||||
|
@ -1192,6 +1191,8 @@ func (s *Strategy) updateQuote(ctx context.Context, maxLayer int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.logger.Infof("%d orders are generated, placing...", len(submitOrders))
|
||||||
|
|
||||||
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
_, err = s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
s.logger.WithError(err).Errorf("submit order error: %s", err.Error())
|
||||||
|
|
|
@ -55,11 +55,7 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, symb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(openOrders) == 0 {
|
if len(openOrders) > 0 {
|
||||||
log.Warnf("empty open orders, unable to call specific cancel all orders api, skip")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
|
if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
|
||||||
var groupIds = CollectOrderGroupIds(openOrders)
|
var groupIds = CollectOrderGroupIds(openOrders)
|
||||||
for _, groupId := range groupIds {
|
for _, groupId := range groupIds {
|
||||||
|
@ -76,6 +72,23 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, symb
|
||||||
if anyErr != nil {
|
if anyErr != nil {
|
||||||
return anyErr
|
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)
|
return fmt.Errorf("unable to cancel all orders, openOrders:%+v", openOrders)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user