Exemple #1
0
        public async Task StartApplicationAsync()
        {
            _consoleWriter.WriteLine($"Starting {ServiceName}");
            await _logger.WriteInfoAsync(ServiceName, null, null, "Starting...");

            try
            {
                await _migrationService.InvokeAll();

                _rabbitMqService.Subscribe(
                    _marginSettings.MarketMakerRabbitMqSettings, false, HandleNewOrdersMessage,
                    _rabbitMqService.GetJsonDeserializer <MarketMakerOrderCommandsBatchMessage>());

                if (_marginSettings.RisksRabbitMqSettings != null)
                {
                    _rabbitMqService.Subscribe(_marginSettings.RisksRabbitMqSettings,
                                               true, _matchingEngineRoutesManager.HandleRiskManagerCommand,
                                               _rabbitMqService.GetJsonDeserializer <MatchingEngineRouteRisksCommand>());
                }
                else if (_marginSettings.IsLive)
                {
                    _logger.WriteWarning(ServiceName, nameof(StartApplicationAsync),
                                         "RisksRabbitMqSettings is not configured");
                }

                // Demo server works only in MM mode
                if (_marginSettings.IsLive)
                {
                    _rabbitMqService.Subscribe(_marginSettings.StpAggregatorRabbitMqSettings
                                               .RequiredNotNull(nameof(_marginSettings.StpAggregatorRabbitMqSettings)), false,
                                               HandleStpOrderbook,
                                               _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>());
                }

                var settingsCalcTime = (_marginSettings.OvernightSwapCalculationTime.Hours,
                                        _marginSettings.OvernightSwapCalculationTime.Minutes);
                var registry = new Registry();
                registry.Schedule <OvernightSwapJob>().ToRunEvery(0).Days().At(settingsCalcTime.Hours, settingsCalcTime.Minutes);
                JobManager.Initialize(registry);
                JobManager.JobException += info => _logger.WriteError(ServiceName, nameof(JobManager), info.Exception);
            }
            catch (Exception ex)
            {
                _consoleWriter.WriteLine($"{ServiceName} error: {ex.Message}");
                await _logger.WriteErrorAsync(ServiceName, "Application.RunAsync", null, ex);
            }
        }
Exemple #2
0
        public async Task StartApplicationAsync()
        {
            _consoleWriter.WriteLine($"Starting {ServiceName}");
            await _logger.WriteInfoAsync(ServiceName, null, null, "Starting...");

            if (_marginSettings.MarketMakerRabbitMqSettings == null &&
                _marginSettings.StpAggregatorRabbitMqSettings == null)
            {
                throw new Exception("Both MM and STP connections are not configured. Can not start service.");
            }

            try
            {
                await _migrationService.InvokeAll();

                if (_marginSettings.MarketMakerRabbitMqSettings != null)
                {
                    _rabbitMqService.Subscribe(
                        _marginSettings.MarketMakerRabbitMqSettings, false, HandleNewOrdersMessage,
                        _rabbitMqService.GetJsonDeserializer <MarketMakerOrderCommandsBatchMessage>());
                }
                else
                {
                    _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync),
                                      "MarketMakerRabbitMqSettings is not configured");
                }

                if (_marginSettings.FxRateRabbitMqSettings != null)
                {
                    _rabbitMqService.Subscribe(_marginSettings.FxRateRabbitMqSettings, false,
                                               _fxRateCacheService.SetQuote, _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>());
                }

                if (_marginSettings.StpAggregatorRabbitMqSettings != null)
                {
                    _rabbitMqService.Subscribe(_marginSettings.StpAggregatorRabbitMqSettings,
                                               false, HandleStpOrderbook,
                                               _rabbitMqService.GetMsgPackDeserializer <ExternalExchangeOrderbookMessage>());
                }
                else
                {
                    _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync),
                                      "StpAggregatorRabbitMqSettings is not configured");
                }

                if (_marginSettings.RisksRabbitMqSettings != null)
                {
                    _rabbitMqService.Subscribe(_marginSettings.RisksRabbitMqSettings,
                                               true, _matchingEngineRoutesManager.HandleRiskManagerCommand,
                                               _rabbitMqService.GetJsonDeserializer <MatchingEngineRouteRisksCommand>());
                }
                else
                {
                    _logger.WriteInfo(ServiceName, nameof(StartApplicationAsync),
                                      "RisksRabbitMqSettings is not configured");
                }

                var settingsChanged = new RabbitMqSettings
                {
                    ConnectionString = _marginSettings.MtRabbitMqConnString,
                    ExchangeName     = _marginSettings.RabbitMqQueues.SettingsChanged.ExchangeName
                };

                _rabbitMqService.Subscribe(settingsChanged,
                                           true, HandleChangeSettingsMessage,
                                           _rabbitMqService.GetJsonDeserializer <SettingsChangedEvent>());
            }
            catch (Exception ex)
            {
                _consoleWriter.WriteLine($"{ServiceName} error: {ex.Message}");
                await _logger.WriteErrorAsync(ServiceName, "Application.RunAsync", null, ex);
            }
        }