void IEventConsumer <StopOutEventArgs> .ConsumeEvent(object sender, StopOutEventArgs ea) { var account = ea.Account; var orders = ea.Orders; var eventTime = _dateService.Now(); var accountMarginEventMessage = AccountMarginEventMessageConverter.Create(account, true, eventTime); var accuracy = _assetsCache.GetAssetAccuracy(account.BaseAssetId); var totalPnl = Math.Round(orders.Sum(x => x.GetTotalFpl()), accuracy); _threadSwitcher.SwitchThread(async() => { _operationsLogService.AddLog("stopout", account.ClientId, account.Id, "", ea.ToJson()); var marginEventTask = _rabbitMqNotifyService.AccountMarginEvent(accountMarginEventMessage); _notifyService.NotifyAccountStopout(account.ClientId, account.Id, orders.Length, totalPnl); var notificationTask = SendMarginEventNotification(account.ClientId, string.Format(MtMessages.Notifications_StopOutNotification, orders.Length, totalPnl, account.BaseAssetId)); var clientEmail = await _clientAccountService.GetEmail(account.ClientId); var emailTask = !string.IsNullOrEmpty(clientEmail) ? _emailService.SendStopOutEmailAsync(clientEmail, account.BaseAssetId, account.Id) : Task.CompletedTask; await Task.WhenAll(marginEventTask, notificationTask, emailTask); }); }
void IEventConsumer <StopOutEventArgs> .ConsumeEvent(object sender, StopOutEventArgs ea) { var account = ea.Account; var eventTime = _dateService.Now(); var accountMarginEventMessage = AccountMarginEventMessageConverter.Create(account, MarginEventTypeContract.Stopout, eventTime); _threadSwitcher.SwitchThread(async() => { if (_lastNotifications.TryGetValue(account.Id, out var lastNotification) && lastNotification.AddMinutes(_settings.Throttling.StopOutThrottlingPeriodMin) > eventTime) { return; } _operationsLogService.AddLog("stopout", account.Id, "", ea.ToJson()); await _rabbitMqNotifyService.AccountMarginEvent(accountMarginEventMessage); _lastNotifications.AddOrUpdate(account.Id, eventTime, (s, times) => eventTime); }); }
void IEventConsumer <StopOutEventArgs> .ConsumeEvent(object sender, StopOutEventArgs ea) { var account = ea.Account; var eventTime = _dateService.Now(); var accountMarginEventMessage = AccountMarginEventMessageConverter.Create(account, MarginEventTypeContract.Stopout, eventTime); _threadSwitcher.SwitchThread(async() => { if (_lastNotifications.TryGetValue(account.Id, out var lastNotification) && lastNotification.AddMinutes(_settings.Throttling.StopOutThrottlingPeriodMin) > eventTime) { _log.WriteInfo(nameof(StopOutConsumer), nameof(IEventConsumer <StopOutEventArgs> .ConsumeEvent), $"StopOut event is ignored for accountId {account.Id} because of throttling: event time {eventTime}, last notification was sent at {lastNotification}"); return; } _operationsLogService.AddLog("stopout", account.Id, "", ea.ToJson()); await _rabbitMqNotifyService.AccountMarginEvent(accountMarginEventMessage); _lastNotifications.AddOrUpdate(account.Id, eventTime, (s, times) => eventTime); }); }