protected override EventHandler <BasicDeliverEventArgs> CreateOnMessageReceivedEventHandler(IModel channel)
        {
            var deserializer = new ProtobufMessageDeserializer <ExecutionProcessedEvent>();

            void OnMessageReceived(object o, BasicDeliverEventArgs basicDeliverEventArgs)
            {
                try
                {
                    var message = deserializer.Deserialize(basicDeliverEventArgs.Body);

                    var orders = Mapper.Map <IEnumerable <Order> >(message).ToList();

                    foreach (var order in orders.Where(x => WalletIds.Contains(x.WalletId.ToString())))
                    {
                        Log.Info("Order from ME (ExecutionProcessedEvent)", context: $"order: {new {order.Id, order.Status, order.SequenceNumber}.ToJson()}");
                    }

                    Queue.Enqueue(new CustomQueueItem <IEnumerable <Order> >(orders,
                                                                             basicDeliverEventArgs.DeliveryTag, channel));
                }
                catch (Exception e)
                {
                    Log.Error(e);

                    channel.BasicReject(basicDeliverEventArgs.DeliveryTag, false);
                }
            }

            return(OnMessageReceived);
        }
        protected override async Task ProcessBatch(IList <CustomQueueItem <IEnumerable <Order> > > batch)
        {
            var orders  = batch.SelectMany(x => x.Value).ToList();
            var batchId = Guid.NewGuid().ToString();

            foreach (var order in orders.Where(x => WalletIds.Contains(x.WalletId.ToString())))
            {
                Log.Info("Saving order (ProcessBatch)", context: $"order: {new {order.Id, order.Status, order.SequenceNumber, batchId}.ToJson()}");
            }

            await _ordersRepository.UpsertBulkAsync(orders);

            var trades = orders.SelectMany(x => x.Trades);

            var batched = trades.Batch(TradesBulkSize).ToList();

            foreach (var tradesBatch in batched)
            {
                await _historyRecordsRepository.InsertBulkAsync(tradesBatch);
            }
        }