From a0cbf82d970cea57859cef5396d62d15f8e18667 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 20 Aug 2024 17:51:44 +0800 Subject: [PATCH] twap: handle delayInterval after canceling order --- pkg/twap/v2/stream_executor.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/twap/v2/stream_executor.go b/pkg/twap/v2/stream_executor.go index 1b41889bb..9fb2e9a50 100644 --- a/pkg/twap/v2/stream_executor.go +++ b/pkg/twap/v2/stream_executor.go @@ -49,8 +49,6 @@ type FixedQuantityExecutor struct { executionCtx context.Context cancelExecution context.CancelFunc - orderUpdateRateLimit *rate.Limiter - userDataStreamCtx context.Context cancelUserDataStream context.CancelFunc @@ -61,10 +59,11 @@ type FixedQuantityExecutor struct { userDataStream types.Stream - activeMakerOrders *bbgo.ActiveOrderBook - orderStore *core.OrderStore - position *types.Position - tradeCollector *core.TradeCollector + orderUpdateRateLimit *rate.Limiter + activeMakerOrders *bbgo.ActiveOrderBook + orderStore *core.OrderStore + position *types.Position + tradeCollector *core.TradeCollector logger logrus.FieldLogger @@ -353,6 +352,10 @@ func (e *FixedQuantityExecutor) updateOrder(ctx context.Context) error { e.tradeCollector.Process() + if e.delayInterval > 0 { + time.Sleep(e.delayInterval) + } + orderForm, err := e.generateOrder() if err != nil { return err