Exemplo n.º 1
0
 private SnapshotResult(SnapshotStatus status, Snapshot oldSnapshot, Snapshot newSnapshot, int index)
 {
     Status      = status;
     OldSnapshot = oldSnapshot;
     NewSnapshot = newSnapshot;
     Index       = index;
 }
Exemplo n.º 2
0
        /// <inheritdoc cref="ComputeApi.WaitForVolumeStatusAsync{TServer,TStatus}(string,TStatus,TimeSpan?,TimeSpan?,IProgress{bool},CancellationToken)" />
        /// <exception cref="InvalidOperationException">When the instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
        public async Task WaitForStatusAsync(SnapshotStatus status, TimeSpan?refreshDelay = null, TimeSpan?timeout = null, IProgress <bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var owner  = this.GetOwnerOrThrow <ComputeApi>();
            var result = await owner.WaitForVolumeSnapshotStatusAsync <VolumeSnapshot, SnapshotStatus>(Id, status, refreshDelay, timeout, progress, cancellationToken).ConfigureAwait(false);

            result.CopyProperties(this);
        }
Exemplo n.º 3
0
        public void Read(TProtocol iprot)
        {
            TField field;

            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }
                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.String)
                    {
                        this.name         = iprot.ReadBinary();
                        this.__isset.name = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.I32)
                    {
                        this.status         = (SnapshotStatus)iprot.ReadI32();
                        this.__isset.status = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 3:
                    if (field.Type == TType.String)
                    {
                        this.hosts         = iprot.ReadBinary();
                        this.__isset.hosts = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                default:
                    TProtocolUtil.Skip(iprot, field.Type);
                    break;
                }
                iprot.ReadFieldEnd();
            }
            iprot.ReadStructEnd();
        }
Exemplo n.º 4
0
 public TradingEngineSnapshot(DateTime tradingDay,
                              string correlationId,
                              DateTime timestamp,
                              string ordersJson,
                              string positionsJson,
                              string accountsJson,
                              string bestFxPricesJson,
                              string bestTradingPricesJson,
                              SnapshotStatus status)
 {
     TradingDay            = tradingDay;
     CorrelationId         = correlationId;
     Timestamp             = timestamp;
     OrdersJson            = ordersJson;
     PositionsJson         = positionsJson;
     AccountsJson          = accountsJson;
     BestFxPricesJson      = bestFxPricesJson;
     BestTradingPricesJson = bestTradingPricesJson;
     Status = status;
 }
Exemplo n.º 5
0
 public static Snapshot CreateInstance(int snapshotId, DateTime createdDate, DateTime importDate, string name,
     string description, Guid? creatorGuid, string creatorName, DateTime? asAtDate, int version, int? parentId,
     SnapshotStatus status, Guid? teamId)
 {
     return new Snapshot
     {
         SnapshotId = snapshotId,
         CreatedDate = createdDate,
         ImportDate = importDate,
         Name = name,
         Description = description,
         CreatorGuid = creatorGuid,
         CreatorName = creatorName,
         AsAtDate = asAtDate,
         Version = version,
         ParentId = parentId,
         Status = status,
         TeamId = teamId
     };
 }
 public ImagerSnapshotEventArgs(string file, SnapshotStatus stat)
 {
     Filename = file;
     Status = stat;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Convert order to a model, supposed to be used for snapshot serialization
 /// </summary>
 /// <param name="order">Order domain model</param>
 /// <param name="status">Snapshot status</param>
 /// <param name="orderReader"></param>
 /// <returns></returns>
 public static object ConvertToSnapshotContract(this Order order, IOrderReader orderReader, SnapshotStatus status = SnapshotStatus.Final)
 {
     return(status == SnapshotStatus.Draft
         ? (object)order
         : order.ConvertToContract(orderReader));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Convert account to a model, supposed to be used for snapshot serialization
 /// </summary>
 /// <param name="account">Account domain model</param>
 /// <param name="status">Snapshot status</param>
 /// <returns></returns>
 public static object ConvertToSnapshotContract(this IMarginTradingAccount account, SnapshotStatus status = SnapshotStatus.Final)
 {
     return(status == SnapshotStatus.Draft
         ? (object)account
         : account.ConvertToContract());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Convert position to a model, supposed to be used for snapshot serialization
 /// </summary>
 /// <param name="position">Position domain model</param>
 /// <param name="status">Snapshot status</param>
 /// <param name="orderReader"></param>
 /// <returns></returns>
 public static object ConvertToSnapshotContract(this Position position, IOrderReader orderReader, SnapshotStatus status = SnapshotStatus.Final)
 {
     return(status == SnapshotStatus.Draft
         ? (object)position
         : position.ConvertToContract(orderReader));
 }
 public ImagerSnapshotEventArgs(string file, SnapshotStatus stat)
 {
     Filename = file;
     Status   = stat;
 }
Exemplo n.º 11
0
 public SnapshotStatusString(SnapshotStatus status)
 {
     _value = status.ToString();
 }
Exemplo n.º 12
0
 /// <inheritdoc cref="ComputeApi.WaitForVolumeStatusAsync{TServer,TStatus}(string,TStatus,TimeSpan?,TimeSpan?,IProgress{bool},CancellationToken)" />
 /// <exception cref="InvalidOperationException">When the instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
 public async Task WaitForStatusAsync(SnapshotStatus status, TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     var owner = this.GetOwnerOrThrow<ComputeApi>();
     var result = await owner.WaitForVolumeSnapshotStatusAsync<VolumeSnapshot, SnapshotStatus>(Id, status, refreshDelay, timeout, progress, cancellationToken).ConfigureAwait(false);
     result.CopyProperties(this);
 }
Exemplo n.º 13
0
        /// <inheritdoc />
        public async Task <string> MakeTradingDataSnapshot(DateTime tradingDay, string correlationId, SnapshotStatus status = SnapshotStatus.Final)
        {
            if (!_scheduleSettingsCacheService.TryGetPlatformCurrentDisabledInterval(out var disabledInterval))
            {
                //TODO: remove later (if everything will work and we will never go to this branch)
                _scheduleSettingsCacheService.MarketsCacheWarmUp();

                if (!_scheduleSettingsCacheService.TryGetPlatformCurrentDisabledInterval(out disabledInterval))
                {
                    throw new Exception(
                              $"Trading should be stopped for whole platform in order to make trading data snapshot. Current schedule: {_scheduleSettingsCacheService.GetPlatformTradingSchedule()?.ToJson()}");
                }
            }

            if (disabledInterval.Start.AddDays(-1) > tradingDay.Date || disabledInterval.End < tradingDay.Date)
            {
                throw new Exception(
                          $"{nameof(tradingDay)}'s Date component must be from current disabled interval's Start -1d to End: [{disabledInterval.Start.AddDays(-1)}, {disabledInterval.End}].");
            }

            if (Lock.CurrentCount == 0)
            {
                throw new InvalidOperationException("Trading data snapshot creation is already in progress");
            }

            // We must be sure all messages have been processed by history brokers before starting current state validation.
            // If one or more queues contain not delivered messages the snapshot can not be created.
            _queueValidationService.ThrowExceptionIfQueuesNotEmpty(true);

            // Before starting snapshot creation the current state should be validated.
            var validationResult = await _snapshotValidationService.ValidateCurrentStateAsync();

            if (!validationResult.IsValid)
            {
                var ex = new InvalidOperationException(
                    $"The trading data snapshot might be corrupted. The current state of orders and positions is incorrect. Check the dbo.BlobData table for more info: container {LykkeConstants.MtCoreSnapshotBlobContainer}, correlationId {correlationId}");
                await _log.WriteFatalErrorAsync(nameof(SnapshotService),
                                                nameof(MakeTradingDataSnapshot),
                                                validationResult.ToJson(),
                                                ex);

                await _blobRepository.WriteAsync(LykkeConstants.MtCoreSnapshotBlobContainer, correlationId, validationResult);
            }
            else
            {
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          "The current state of orders and positions is correct.");
            }

            await Lock.WaitAsync();

            try
            {
                var orders     = _orderReader.GetAllOrders();
                var ordersJson = orders.Select(o => o.ConvertToSnapshotContract(_orderReader, status)).ToJson();
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Preparing data... {orders.Length} orders prepared.");

                var positions     = _orderReader.GetPositions();
                var positionsJson = positions.Select(p => p.ConvertToSnapshotContract(_orderReader, status)).ToJson();
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Preparing data... {positions.Length} positions prepared.");

                var accountStats = _accountsCacheService.GetAll();
                var accountsJson = accountStats.Select(a => a.ConvertToSnapshotContract(status)).ToJson();
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Preparing data... {accountStats.Count} accounts prepared.");

                var bestFxPrices     = _fxRateCacheService.GetAllQuotes();
                var bestFxPricesData = bestFxPrices.ToDictionary(q => q.Key, q => q.Value.ConvertToContract()).ToJson();
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Preparing data... {bestFxPrices.Count} best FX prices prepared.");

                var bestPrices     = _quoteCacheService.GetAllQuotes();
                var bestPricesData = bestPrices.ToDictionary(q => q.Key, q => q.Value.ConvertToContract()).ToJson();
                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Preparing data... {bestPrices.Count} best trading prices prepared.");

                var msg = $"TradingDay: {tradingDay:yyyy-MM-dd}, Orders: {orders.Length}, positions: {positions.Length}, accounts: {accountStats.Count}, best FX prices: {bestFxPrices.Count}, best trading prices: {bestPrices.Count}.";

                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Starting to write trading data snapshot. {msg}");

                var snapshot = new TradingEngineSnapshot(
                    tradingDay,
                    correlationId,
                    _dateService.Now(),
                    ordersJson: ordersJson,
                    positionsJson: positionsJson,
                    accountsJson: accountsJson,
                    bestFxPricesJson: bestFxPricesData,
                    bestTradingPricesJson: bestPricesData,
                    status: status);

                await _tradingEngineSnapshotsRepository.AddAsync(snapshot);

                await _log.WriteInfoAsync(nameof(SnapshotService), nameof(MakeTradingDataSnapshot),
                                          $"Trading data snapshot was written to the storage. {msg}");

                return($"Trading data snapshot was written to the storage. {msg}");
            }
            finally
            {
                Lock.Release();
            }
        }