Exemple #1
0
        static async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            // Process the message
            //YJYGlobal.LogLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber}");

            try
            {
                var posToClose = Serialization.ByteArrayToObject(message.Body) as PosToClose;
                YJYGlobal.LogLine(
                    $"Received: {posToClose.Id} {posToClose.closeType} {posToClose.closePx} {posToClose.closePxTime}");
                var autoClosePosition = PositionService.AutoClosePosition(posToClose);

                var checkAndCloseFollowPositions = PositionService.CheckAndCloseFollowPositions(autoClosePosition.Id);

                MessageService.AddAutoCloseMessage(autoClosePosition);

                MessageService.AddAutoCloseMessages(checkAndCloseFollowPositions);

                YJYGlobal.LogLine(
                    $"pos closed: {autoClosePosition.Id} type:{autoClosePosition.CloseType} pl:{autoClosePosition.PL}");

                // Complete the message so that it is not received again.
                // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
                await queueClient.CompleteAsync(message.SystemProperties.LockToken);

                // Note: Use the cancellationToken passed as necessary to determine if the queueClient has already been closed.
                // If queueClient has already been Closed, you may chose to not call CompleteAsync() or AbandonAsync() etc. calls
                // to avoid unnecessary exceptions.
            }
            catch (Exception e)
            {
                YJYGlobal.LogException(e);

                await queueClient.AbandonAsync(message.SystemProperties.LockToken);
            }
        }