Exemplo n.º 1
0
        public async Task ProcessUserUpdates(UserUpdateEntityBackendContract userUpdate)
        {
            var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.UserUpdates.ExchangeName, _settings.MarginTradingFront.Env);

            _consoleWriter.WriteLine($"Get user update from {queueName} queue for {userUpdate.ClientIds.Length} clients");

            foreach (var clientId in userUpdate.ClientIds)
            {
                try
                {
                    var notificationId = await _clientNotificationService.GetNotificationId(clientId);

                    var userTopic =
                        _realm.Services.GetSubject <NotifyResponse <UserUpdateEntityClientContract> >(
                            $"user.{notificationId}");

                    var response = new NotifyResponse <UserUpdateEntityClientContract>
                    {
                        Entity = userUpdate.ToClientContract(),
                        Type   = NotifyEntityType.UserUpdate
                    };

                    userTopic.OnNext(response);

                    var eventType = string.Empty;

                    if (userUpdate.UpdateAccountAssetPairs)
                    {
                        eventType = "account assets";
                    }

                    if (userUpdate.UpdateAccounts)
                    {
                        eventType = "accounts";
                    }

                    _operationsLog.AddLog($"topic user.{notificationId} ({eventType} changed)", clientId, null, null,
                                          response.ToJson());
                    _consoleWriter.WriteLine(
                        $"topic user.{notificationId} ({eventType} changed) for clientId = {clientId}");

                    var userUpdateTopic         = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}");
                    var userUpdateTopicResponse = new NotifyResponse {
                        UserUpdate = response.Entity
                    };

                    userUpdateTopic.OnNext(userUpdateTopicResponse);

                    _operationsLog.AddLog($"topic user.updates.{notificationId} ({eventType} changed)", clientId, null,
                                          null, userUpdateTopicResponse.ToJson());
                    _consoleWriter.WriteLine(
                        $"topic user.updates.{notificationId} (account assets changed) for clientId = {clientId}");
                }
                catch (Exception ex)
                {
                    await _log.WriteErrorAsync(nameof(RabbitMqHandler), nameof(ProcessUserUpdates), clientId, ex);
                }
            }
        }
Exemplo n.º 2
0
        public async Task ProcessAccountChanged(AccountChangedMessage accountChangedMessage)
        {
            if (accountChangedMessage.EventType != AccountEventTypeEnum.Updated)
            {
                return;
            }

            var account   = accountChangedMessage.Account;
            var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.AccountChanged.ExchangeName, _settings.MarginTradingFront.Env);

            _consoleWriter.WriteLine($"Get account change from {queueName} queue for clientId = {account.ClientId}");
            var notificationId = await _clientNotificationService.GetNotificationId(account.ClientId);

            var userTopic = _realm.Services.GetSubject <NotifyResponse <MarginTradingAccountClientContract> >($"user.{notificationId}");

            var notifyResponse = new NotifyResponse <MarginTradingAccountClientContract>
            {
                Entity = account.ToClientContract(),
                Type   = NotifyEntityType.Account
            };

            userTopic.OnNext(notifyResponse);

            _operationsLog.AddLog($"topic user.{notificationId} (account changed)", account.ClientId, account.Id, null, notifyResponse.ToJson());
            _consoleWriter.WriteLine($"topic user.{notificationId} (account changed) for clientId = {account.ClientId}");

            var userUpdateTopic         = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}");
            var userUpdateTopicResponse = new NotifyResponse {
                Account = notifyResponse.Entity, Order = null
            };

            userUpdateTopic.OnNext(userUpdateTopicResponse);

            _operationsLog.AddLog($"topic user.updates.{notificationId} (account changed)", account.ClientId,
                                  account.Id, null, userUpdateTopicResponse.ToJson());
            _consoleWriter.WriteLine($"topic user.updates.{notificationId} (account changed) for clientId = {account.ClientId}");
        }
Exemplo n.º 3
0
        public async Task ProcessAccountStopout(AccountStopoutBackendContract stopout)
        {
            var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.AccountStopout.ExchangeName, _settings.MarginTradingFront.Env);

            _consoleWriter.WriteLine($"Get account stopout from {queueName} queue for clientId = {stopout.ClientId}");

            var notificationId = await _clientNotificationService.GetNotificationId(stopout.ClientId);

            var userTopic = _realm.Services.GetSubject <NotifyResponse <AccountStopoutClientContract> >($"user.{notificationId}");

            var response = new NotifyResponse <AccountStopoutClientContract>
            {
                Entity = stopout.ToClientContract(),
                Type   = NotifyEntityType.AccountStopout
            };

            userTopic.OnNext(response);

            _operationsLog.AddLog($"topic user.{notificationId} (account stopout)", stopout.ClientId, response.Entity.AccountId, null, response.ToJson());
            _consoleWriter.WriteLine($"topic user.{notificationId} (account stopout) for clientId = {stopout.ClientId}");

            var userUpdateTopic         = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}");
            var userUpdateTopicResponse = new NotifyResponse {
                Account = null, Order = null, AccountStopout = response.Entity
            };

            userUpdateTopic.OnNext(userUpdateTopicResponse);

            _operationsLog.AddLog($"topic user.updates.{notificationId} (account stopout)", stopout.ClientId, response.Entity.AccountId, null, userUpdateTopicResponse.ToJson());
            _consoleWriter.WriteLine($"topic user.updates.{notificationId} (account stopout) for clientId = {stopout.ClientId}");
        }
Exemplo n.º 4
0
        public async Task ProcessOrderChanged(OrderContract order)
        {
            var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.OrderChanged.ExchangeName, _settings.MarginTradingFront.Env);

            _consoleWriter.WriteLine($"Get order change from {queueName} queue for clientId = {order.ClientId}");

            var notificationId = await _clientNotificationService.GetNotificationId(order.ClientId);

            var userTopic = _realm.Services.GetSubject <NotifyResponse <OrderClientContract> >($"user.{notificationId}");

            var notifyResponse = new NotifyResponse <OrderClientContract>
            {
                Entity = order.ToClientContract(),
                Type   = NotifyEntityType.Order
            };

            userTopic.OnNext(notifyResponse);

            _operationsLog.AddLog($"topic user.{notificationId} (position changed)", order.ClientId, order.AccountId, null, notifyResponse.ToJson());
            _consoleWriter.WriteLine($"topic user.{notificationId} (order changed) for clientId = {order.ClientId}");

            var userUpdateTopic         = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}");
            var userUpdateTopicResponse = new NotifyResponse {
                Account = null, Order = notifyResponse.Entity
            };

            userUpdateTopic.OnNext(userUpdateTopicResponse);

            _operationsLog.AddLog($"topic user.updates.{notificationId} (position changed)", order.ClientId, notifyResponse.Entity.AccountId, null, userUpdateTopicResponse.ToJson());
            _consoleWriter.WriteLine($"topic user.updates.{notificationId} (order changed) for clientId = {order.ClientId}");
        }