public async Task Handle(MarketStateChangedEvent e)
        {
            await _log.WriteInfoAsync(
                nameof(MarketStateChangedProjection),
                nameof(Handle),
                e.ToJson(),
                $"Handling new MarketStateChanged event.");

            if (e.Id == PlatformScheduleMarketId && e.IsEnabled)
            {
                var tradingDay = e.EventTimestamp.Date;

                await _taxFileMissingRepository.AddAsync(tradingDay);

                await _log.WriteInfoAsync(
                    nameof(MarketStateChangedProjection),
                    nameof(Handle),
                    new { tradingDay }.ToJson(),
                    "Added new tax file missing day");
            }
        }
コード例 #2
0
        public async Task Handle(MarketStateChangedEvent e)
        {
            if (!e.IsPlatformClosureEvent())
            {
                return;
            }

            var tradingDay = e.EventTimestamp.Date;

            await _log.WriteInfoAsync(nameof(PlatformClosureProjection), nameof(Handle), e.ToJson(),
                                      $"Platform is being closed. Starting trading snapshot backup for [{tradingDay}]");

            var result = await _snapshotService.MakeTradingDataSnapshot(e.EventTimestamp.Date,
                                                                        _identityGenerator.GenerateGuid(),
                                                                        SnapshotStatus.Draft);

            await _log.WriteInfoAsync(nameof(PlatformClosureProjection),
                                      nameof(Handle),
                                      e.ToJson(),
                                      result);
        }
コード例 #3
0
        public Task Handle(MarketStateChangedEvent e, ICommandSender sender)
        {
            if (!e.IsEnabled)
            {
                return(Task.CompletedTask);
            }

            // resuming liquidations on corresponding accounts upon market open
            _accountsCacheService.GetAll()
            .Where(a => a.IsInLiquidation())
            .SelectMany(a => _ordersCache.Positions.GetPositionsByAccountIds(a.Id))
            .GroupBy(p => p.AccountId)
            .Where(AnyAssetRelatesToMarket)
            .ForEach(account => SendResumeCommand(account.Key));

            return(Task.CompletedTask);

            #region internal functions

            bool AnyAssetRelatesToMarket(IGrouping <string, Position> positions) =>
            positions
            .Select(p => _assetPairsCache.GetAssetPairById(p.AssetPairId))
            .Any(assetPair => assetPair.MarketId == e.Id);

            void SendResumeCommand(string accountId)
            {
                var account = _accountsCacheService.Get(accountId);

                sender.SendCommand(new ResumeLiquidationInternalCommand
                {
                    OperationId  = account.LiquidationOperationId,
                    CreationTime = DateTime.UtcNow,
                    IsCausedBySpecialLiquidation = false,
                    ResumeOnlyFailed             = true,
                    Comment = "Trying to resume liquidation because market has been opened"
                }, _cqrsContextNamesSettings.TradingEngine);
            }

            #endregion
        }
コード例 #4
0
 public static bool IsPlatformClosureEvent(this MarketStateChangedEvent evt) =>
 evt.Id == LykkeConstants.PlatformMarketIdentifier && !evt.IsEnabled;