Skip to content

Commit

Permalink
Fix checl conditional orders bug
Browse files Browse the repository at this point in the history
  • Loading branch information
evsamsonov committed Sep 8, 2024
1 parent 4b3d921 commit 3b6e5a0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tinkoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (t *Tinkoff) processOrderTrades(ctx context.Context, orderTrades *pb.OrderT
}
err := t.positionStorage.ForEach(func(tinkoffPosition *tnkposition.Position) error {
position := tinkoffPosition.Position()
logger := t.logger.With(zap.Any("position", position), zap.Any("orderTrades", orderTrades))

if orderTrades.Figi != position.FIGI {
return nil
}
Expand All @@ -290,15 +292,17 @@ func (t *Tinkoff) processOrderTrades(ctx context.Context, orderTrades *pb.OrderT
return nil
}

// Conditional orders may not be processed in real time. Wait a little to be sure
<-time.After(300 * time.Millisecond)
conditionalOrdersFound, err := t.conditionalOrdersFound(tinkoffPosition)
if err != nil {
return fmt.Errorf("conditional orders found: %w", err)
}
if conditionalOrdersFound {
logger.Debug("Conditional orders were found")
return nil
}

logger := t.logger.With(zap.Any("position", position))
tinkoffPosition.AddOrderTrade(orderTrades.GetTrades()...)

var executedQuantity int64
Expand Down Expand Up @@ -330,7 +334,7 @@ func (t *Tinkoff) processOrderTrades(ctx context.Context, orderTrades *pb.OrderT
}
return fmt.Errorf("close: %w", err)
}
logger.Info("Position was closed by order trades", zap.Any("orderTrades", orderTrades))
logger.Info("Position was closed by order trades")
return nil
})
return err
Expand Down

0 comments on commit 3b6e5a0

Please sign in to comment.