Пример #1
0
        private static List <InstrumentDeltaReport> GetTokensDelta(IReadOnlyCollection <IndexSettings> indicesSettings,
                                                                   IReadOnlyCollection <IndexPrice> indexPrices, IReadOnlyCollection <Token> tokens)
        {
            var tokensDelta = new List <InstrumentDeltaReport>();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = indexPrices.SingleOrDefault(o => o.Name == indexSettings.Name);

                Token token = tokens.SingleOrDefault(o => o.AssetId == indexSettings.AssetId)
                              ?? new Token {
                    AssetId = indexSettings.AssetId
                };

                IReadOnlyCollection <AssetWeight> weights = indexPrice?.Weights ?? new AssetWeight[0];

                decimal volume      = -token.OpenVolume;
                decimal?volumeInUsd = indexPrice?.Price * volume;

                tokensDelta.Add(new InstrumentDeltaReport
                {
                    Name        = indexSettings.Name,
                    AssetId     = indexSettings.AssetId,
                    Price       = indexPrice?.Price,
                    Volume      = volume,
                    VolumeInUsd = volumeInUsd,
                    IsVirtual   = false,
                    AssetsDelta = volumeInUsd != null
                        ? ComputeAssetsDelta(volumeInUsd.Value, DeltaRate, weights)
                        : new AssetDelta[0]
                });
            }

            return(tokensDelta);
        }
Пример #2
0
        private static List <TokenReport> GetIndexReports(IReadOnlyCollection <IndexSettings> indicesSettings,
                                                          IReadOnlyCollection <IndexPrice> indexPrices, IReadOnlyCollection <Token> tokens)
        {
            var tokenReports = new List <TokenReport>();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = indexPrices.SingleOrDefault(o => o.Name == indexSettings.Name);

                Token token = tokens.SingleOrDefault(o => o.AssetId == indexSettings.AssetId)
                              ?? new Token {
                    AssetId = indexSettings.AssetId
                };

                tokenReports.Add(new TokenReport
                {
                    Name       = indexSettings.Name,
                    AssetId    = indexSettings.AssetId,
                    Price      = indexPrice?.Price,
                    OpenVolume = token.OpenVolume,
                    Weights    = indexPrice?.Weights ?? new AssetWeight[0]
                });
            }

            return(tokenReports);
        }
        private async Task <bool> ValidateIndexPricesAsync()
        {
            bool valid = true;

            IReadOnlyCollection <IndexSettings> indicesSettings = await _indexSettingsService.GetAllAsync();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexSettings.Name);

                if (indexPrice == null)
                {
                    _log.WarningWithDetails("Index price not found", indexSettings.Name);
                    valid = false;
                }
                else if (!indexPrice.ValidateValue())
                {
                    _log.WarningWithDetails("Invalid index price", indexPrice);
                    valid = false;
                }
                else if (!indexPrice.ValidateWeights())
                {
                    _log.WarningWithDetails("Invalid index price weights", indexPrice);
                    valid = false;
                }
            }

            return(valid);
        }
        public async Task RecalculateAsync(string settlementId, string userId)
        {
            Settlement settlement = await GetByIdAsync(settlementId);

            if (settlement.Status != SettlementStatus.New)
            {
                throw new InvalidOperationException("Only new settlement can be recalculated");
            }

            IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(settlement.IndexName);

            if (indexPrice == null)
            {
                throw new InvalidOperationException("Index price not found");
            }

            settlement.Price = indexPrice.Price;

            await CalculateAssetSettlementsAsync(settlement, indexPrice.Weights);

            await ValidateBalanceAsync(settlement);

            await _settlementRepository.ReplaceAsync(settlement);

            _log.InfoWithDetails("Settlement recalculated", new { settlement, userId });
        }
Пример #5
0
        private static void Complete(IReadOnlyCollection <AssetInvestment> assetInvestments,
                                     IReadOnlyDictionary <string, Quote> assetPrice, IReadOnlyCollection <IndexSettings> indexSettings,
                                     IReadOnlyCollection <IndexPrice> indexPrices, IReadOnlyCollection <Token> tokens)
        {
            foreach (AssetInvestment assetInvestment in assetInvestments)
            {
                assetInvestment.Quote = assetPrice[assetInvestment.AssetId];

                foreach (AssetIndexInvestment assetIndexInvestment in assetInvestment.Indices)
                {
                    IndexPrice indexPrice = indexPrices.Single(o => o.Name == assetIndexInvestment.Name);

                    IndexSettings settings = indexSettings.Single(p => p.Name == assetIndexInvestment.Name);

                    Token token = tokens.SingleOrDefault(t => t.AssetId == settings.AssetId);

                    assetIndexInvestment.Value          = indexPrice.Value;
                    assetIndexInvestment.Price          = indexPrice.Price;
                    assetIndexInvestment.OpenVolume     = token?.OpenVolume ?? 0;
                    assetIndexInvestment.OppositeVolume = token?.OppositeVolume ?? 0;
                    assetIndexInvestment.Weight         = indexPrice.Weights
                                                          .SingleOrDefault(o => o.AssetId == assetInvestment.AssetId)
                                                          ?.Weight ?? 0;
                }
            }
        }
        public async Task InsertAsync(IndexPrice indexPrice)
        {
            var entity = new IndexPriceEntity(GetPartitionKey(), GetRowKey(indexPrice.Name));

            Mapper.Map(indexPrice, entity);

            await _storage.InsertAsync(entity);
        }
 public async Task UpdateAsync(IndexPrice indexPrice)
 {
     await _storage.MergeAsync(GetPartitionKey(), GetRowKey(indexPrice.Name), entity =>
     {
         Mapper.Map(indexPrice, entity);
         return(entity);
     });
 }
Пример #8
0
        public async Task UpdateAsync(Index index)
        {
            if (!index.ValidateValue())
            {
                throw new InvalidOperationException("Invalid index value");
            }

            if (!index.ValidateWeights())
            {
                throw new InvalidOperationException("Invalid index weights");
            }

            IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(index.Name);

            if (indexSettings == null)
            {
                throw new InvalidOperationException("Index settings not found");
            }

            IndexPrice indexPrice = await GetByIndexAsync(index.Name);

            if (indexPrice == null)
            {
                indexPrice = IndexPrice.Init(index.Name, index.Value, index.Timestamp, index.Weights);

                await _indexPriceRepository.InsertAsync(indexPrice);

                _log.InfoWithDetails("The index price initialized", indexPrice);
            }
            else
            {
                IndexSettlementPrice indexSettlementPrice = IndexSettlementPriceCalculator.Calculate(
                    index.Value, indexPrice.Value, indexSettings.Alpha, indexPrice.K, indexPrice.Price,
                    index.Timestamp, indexPrice.Timestamp, indexSettings.TrackingFee, indexSettings.PerformanceFee,
                    indexSettings.IsShort);

                indexPrice.Update(index.Value, index.Timestamp, indexSettlementPrice.Price, indexSettlementPrice.K,
                                  indexSettlementPrice.R, indexSettlementPrice.Delta, index.Weights);

                await _indexPriceRepository.UpdateAsync(indexPrice);

                _log.InfoWithDetails("The index price calculated", new
                {
                    indexPrice,
                    indexSettings
                });
            }

            _cache.Set(indexPrice);
        }
Пример #9
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Direction.GetHashCode();

                hashCode = hashCode * 59 + TickDirection.GetHashCode();
                if (Timestamp != null)
                {
                    hashCode = hashCode * 59 + Timestamp.GetHashCode();
                }
                if (Price != null)
                {
                    hashCode = hashCode * 59 + Price.GetHashCode();
                }
                if (TradeSeq != null)
                {
                    hashCode = hashCode * 59 + TradeSeq.GetHashCode();
                }
                if (TradeId != null)
                {
                    hashCode = hashCode * 59 + TradeId.GetHashCode();
                }
                if (Iv != null)
                {
                    hashCode = hashCode * 59 + Iv.GetHashCode();
                }
                if (IndexPrice != null)
                {
                    hashCode = hashCode * 59 + IndexPrice.GetHashCode();
                }
                if (Amount != null)
                {
                    hashCode = hashCode * 59 + Amount.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }
                return(hashCode);
            }
        }
        public async Task CreateAsync(string indexName, decimal amount, string comment, string walletId,
                                      string clientId, string userId, bool isDirect)
        {
            IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexName);

            if (indexPrice == null)
            {
                throw new InvalidOperationException("Index price not found");
            }

            Settlement settlement = await CreateSettlementAsync(indexName, amount, comment, walletId, clientId, userId,
                                                                isDirect, indexPrice);

            await ValidateBalanceAsync(settlement);

            await _settlementRepository.InsertAsync(settlement);

            _log.InfoWithDetails("Settlement created", settlement);
        }
        private async Task <IReadOnlyCollection <string> > GetAssetsAsync()
        {
            IReadOnlyCollection <IndexSettings> indicesSettings = await _indexSettingsService.GetAllAsync();

            IReadOnlyCollection <Position> positions = await _positionService.GetAllAsync();

            List <string> assets = positions.Select(o => o.AssetId).ToList();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexSettings.Name);

                if (indexPrice != null)
                {
                    assets.AddRange(indexPrice.Weights.Select(o => o.AssetId));
                }
            }

            return(assets.Distinct().ToList());
        }
        public async Task <IReadOnlyCollection <IndexReport> > GetAsync()
        {
            IReadOnlyCollection <IndexSettings> indicesSettings = await _indexSettingsService.GetAllAsync();

            var indexReports = new List <IndexReport>();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexSettings.Name);

                Token token = await _tokenService.GetAsync(indexSettings.AssetId);

                Balance balance = _balanceService.GetByAssetId(ExchangeNames.Lykke, indexSettings.AssetId);

                indexReports.Add(new IndexReport
                {
                    Name           = indexSettings.Name,
                    AssetId        = indexSettings.AssetId,
                    AssetPairId    = indexSettings.AssetPairId,
                    Value          = indexPrice?.Value,
                    Price          = indexPrice?.Price,
                    Timestamp      = indexPrice?.Timestamp,
                    K              = indexPrice?.K,
                    Amount         = token.Amount,
                    OpenVolume     = token.OpenVolume,
                    OppositeVolume = token.OppositeVolume,
                    Balance        = balance.Amount,
                    Alpha          = indexSettings.Alpha,
                    TrackingFee    = indexSettings.TrackingFee,
                    PerformanceFee = indexSettings.PerformanceFee,
                    SellMarkup     = indexSettings.SellMarkup,
                    SellVolume     = indexSettings.SellVolume,
                    BuyVolume      = indexSettings.BuyVolume,
                    Weights        = indexPrice?.Weights ?? new AssetWeight[0]
                });
            }

            return(indexReports);
        }
Пример #13
0
        public async Task <ProfitLossReport> GetAsync()
        {
            IReadOnlyCollection <Position> positions = await _positionService.GetAllAsync();

            decimal positionsVolumeInUsd    = 0;
            decimal positionsOppositeVolume = 0;

            foreach (Position position in positions.Where(position => position.Exchange != ExchangeNames.Virtual))
            {
                positionsOppositeVolume += position.OppositeVolume;

                if (_rateService.TryConvertToUsd(position.AssetId, position.Exchange, position.Volume,
                                                 out decimal amountInUsd))
                {
                    positionsVolumeInUsd += amountInUsd;
                }
            }

            decimal investments           = 0;
            decimal openTokensAmountInUsd = 0;

            IReadOnlyCollection <IndexSettings> indicesSettings = await _indexSettingsService.GetAllAsync();

            foreach (IndexSettings indexSettings in indicesSettings)
            {
                IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexSettings.Name);

                Token token = await _tokenService.GetAsync(indexSettings.AssetId);

                investments           += token?.OppositeVolume ?? 0;
                openTokensAmountInUsd += token?.OpenVolume * indexPrice?.Price ?? 0;
            }

            decimal balance = positionsVolumeInUsd + (investments - Math.Abs(positionsOppositeVolume));
            decimal pnl     = openTokensAmountInUsd - balance;

            return(new ProfitLossReport(balance, pnl));
        }
        private async Task <Settlement> CreateSettlementAsync(string indexName, decimal amount, string comment,
                                                              string walletId, string clientId, string userId, bool isDirect, IndexPrice indexPrice)
        {
            var settlement = new Settlement
            {
                Id          = Guid.NewGuid().ToString("D"),
                IndexName   = indexName,
                Amount      = amount,
                Price       = indexPrice.Price,
                WalletId    = walletId,
                ClientId    = clientId,
                Comment     = comment,
                IsDirect    = isDirect,
                Status      = SettlementStatus.New,
                CreatedBy   = userId,
                CreatedDate = DateTime.UtcNow
            };

            await CalculateAssetSettlementsAsync(settlement, indexPrice.Weights);

            return(settlement);
        }
Пример #15
0
        public static IReadOnlyCollection <AssetInvestment> Calculate(
            IEnumerable <string> assets,
            IReadOnlyCollection <IndexSettings> indicesSettings,
            IReadOnlyCollection <Token> tokens,
            IReadOnlyCollection <IndexPrice> indexPrices,
            IReadOnlyCollection <Position> positions,
            IReadOnlyDictionary <string, Quote> assetPrices)
        {
            var assetsInvestments = new List <AssetInvestment>();

            foreach (string assetId in assets)
            {
                var indexInvestments = new List <AssetIndexInvestment>();

                bool isDisabled = false;

                foreach (IndexSettings indexSettings in indicesSettings)
                {
                    Token token = tokens.SingleOrDefault(o => o.AssetId == indexSettings.AssetId);

                    IndexPrice indexPrice = indexPrices.Single(o => o.Name == indexSettings.Name);

                    AssetWeight assetWeight = indexPrice.Weights.SingleOrDefault(o => o.AssetId == assetId);

                    decimal weight = assetWeight?.Weight ?? 0;

                    decimal openVolume = token?.OpenVolume ?? 0;

                    decimal amount = openVolume * indexPrice.Price * weight;

                    isDisabled = isDisabled || (assetWeight?.IsDisabled ?? false);

                    indexInvestments.Add(new AssetIndexInvestment
                    {
                        Name           = indexSettings.Name,
                        Value          = indexPrice.Value,
                        Price          = indexPrice.Price,
                        OpenVolume     = token?.OpenVolume ?? 0,
                        OppositeVolume = token?.OppositeVolume ?? 0,
                        Amount         = amount,
                        Weight         = weight
                    });
                }

                Position position = positions.SingleOrDefault(o => o.AssetId == assetId);

                decimal assetVolume = position?.Volume ?? 0;

                assetPrices.TryGetValue(assetId, out Quote quote);

                decimal assetPrice = quote?.Mid ?? 0;

                decimal totalAmount = indexInvestments.Sum(o => o.Amount);

                decimal remainingAmount = assetVolume * assetPrice - totalAmount;

                assetsInvestments.Add(new AssetInvestment
                {
                    AssetId         = assetId,
                    Volume          = assetVolume,
                    Quote           = quote,
                    TotalAmount     = totalAmount,
                    RemainingAmount = remainingAmount,
                    IsDisabled      = isDisabled,
                    Indices         = indexInvestments
                });
            }

            return(assetsInvestments);
        }
Пример #16
0
        /// <summary>
        /// Returns true if PublicTrade instances are equal
        /// </summary>
        /// <param name="other">Instance of PublicTrade to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PublicTrade other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Direction == other.Direction ||

                     Direction.Equals(other.Direction)
                     ) &&
                 (
                     TickDirection == other.TickDirection ||

                     TickDirection.Equals(other.TickDirection)
                 ) &&
                 (
                     Timestamp == other.Timestamp ||
                     Timestamp != null &&
                     Timestamp.Equals(other.Timestamp)
                 ) &&
                 (
                     Price == other.Price ||
                     Price != null &&
                     Price.Equals(other.Price)
                 ) &&
                 (
                     TradeSeq == other.TradeSeq ||
                     TradeSeq != null &&
                     TradeSeq.Equals(other.TradeSeq)
                 ) &&
                 (
                     TradeId == other.TradeId ||
                     TradeId != null &&
                     TradeId.Equals(other.TradeId)
                 ) &&
                 (
                     Iv == other.Iv ||
                     Iv != null &&
                     Iv.Equals(other.Iv)
                 ) &&
                 (
                     IndexPrice == other.IndexPrice ||
                     IndexPrice != null &&
                     IndexPrice.Equals(other.IndexPrice)
                 ) &&
                 (
                     Amount == other.Amount ||
                     Amount != null &&
                     Amount.Equals(other.Amount)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ));
        }
Пример #17
0
        public async Task UpdateLimitOrdersAsync(string indexName)
        {
            IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexName);

            if (indexPrice == null)
            {
                throw new InvalidOperationException("Index price not found");
            }

            IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(indexName);

            if (indexSettings == null)
            {
                throw new InvalidOperationException("Index settings not found");
            }

            AssetPairSettings assetPairSettings =
                await _instrumentService.GetAssetPairAsync(indexSettings.AssetPairId, Exchange);

            if (assetPairSettings == null)
            {
                throw new InvalidOperationException("Asset pair settings not found");
            }

            AssetSettings baseAssetSettings =
                await _instrumentService.GetAssetAsync(assetPairSettings.BaseAsset, ExchangeNames.Lykke);

            if (baseAssetSettings == null)
            {
                throw new InvalidOperationException("Base asset settings not found");
            }

            AssetSettings quoteAssetSettings =
                await _instrumentService.GetAssetAsync(assetPairSettings.QuoteAsset, ExchangeNames.Lykke);

            if (quoteAssetSettings == null)
            {
                throw new InvalidOperationException("Quote asset settings not found");
            }

            decimal sellPrice = (indexPrice.Price + indexSettings.SellMarkup)
                                .TruncateDecimalPlaces(assetPairSettings.PriceAccuracy, true);

            decimal buyPrice = indexPrice.Price.TruncateDecimalPlaces(assetPairSettings.PriceAccuracy);

            IReadOnlyCollection <LimitOrder> limitOrders =
                CreateLimitOrders(indexSettings, assetPairSettings, sellPrice, buyPrice);

            ValidateBalance(limitOrders, baseAssetSettings, quoteAssetSettings);

            ValidateMinVolume(limitOrders, assetPairSettings.MinVolume);

            LimitOrder[] allowedLimitOrders = limitOrders
                                              .Where(o => o.Error == LimitOrderError.None)
                                              .ToArray();

            _log.InfoWithDetails("Limit orders created", limitOrders);

            _limitOrderService.Update(indexSettings.AssetPairId, limitOrders);

            await _lykkeExchangeService.ApplyAsync(indexSettings.AssetPairId, allowedLimitOrders);

            _traceWriter.LimitOrders(indexSettings.AssetPairId, limitOrders);
        }
Пример #18
0
        /// <summary>
        /// Returns true if Settlement instances are equal
        /// </summary>
        /// <param name="other">Instance of Settlement to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Settlement other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     SessionProfitLoss == other.SessionProfitLoss ||
                     SessionProfitLoss != null &&
                     SessionProfitLoss.Equals(other.SessionProfitLoss)
                     ) &&
                 (
                     MarkPrice == other.MarkPrice ||
                     MarkPrice != null &&
                     MarkPrice.Equals(other.MarkPrice)
                 ) &&
                 (
                     Funding == other.Funding ||
                     Funding != null &&
                     Funding.Equals(other.Funding)
                 ) &&
                 (
                     Socialized == other.Socialized ||
                     Socialized != null &&
                     Socialized.Equals(other.Socialized)
                 ) &&
                 (
                     SessionBankrupcy == other.SessionBankrupcy ||
                     SessionBankrupcy != null &&
                     SessionBankrupcy.Equals(other.SessionBankrupcy)
                 ) &&
                 (
                     Timestamp == other.Timestamp ||
                     Timestamp != null &&
                     Timestamp.Equals(other.Timestamp)
                 ) &&
                 (
                     ProfitLoss == other.ProfitLoss ||
                     ProfitLoss != null &&
                     ProfitLoss.Equals(other.ProfitLoss)
                 ) &&
                 (
                     Funded == other.Funded ||
                     Funded != null &&
                     Funded.Equals(other.Funded)
                 ) &&
                 (
                     IndexPrice == other.IndexPrice ||
                     IndexPrice != null &&
                     IndexPrice.Equals(other.IndexPrice)
                 ) &&
                 (
                     SessionTax == other.SessionTax ||
                     SessionTax != null &&
                     SessionTax.Equals(other.SessionTax)
                 ) &&
                 (
                     SessionTaxRate == other.SessionTaxRate ||
                     SessionTaxRate != null &&
                     SessionTaxRate.Equals(other.SessionTaxRate)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     Position == other.Position ||
                     Position != null &&
                     Position.Equals(other.Position)
                 ) &&
                 (
                     Type == other.Type ||

                     Type.Equals(other.Type)
                 ));
        }
Пример #19
0
        public async Task <SimulationReport> GetReportAsync(string indexName)
        {
            SimulationParameters simulationParameters =
                await _simulationParametersRepository.GetByIndexNameAsync(indexName);

            if (simulationParameters == null)
            {
                simulationParameters = SimulationParameters.Create(indexName);
            }

            IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(indexName);

            if (indexSettings == null)
            {
                return(null);
            }

            IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexSettings.Name);

            var simulationReport = new SimulationReport
            {
                IndexName      = indexName,
                AssetId        = indexSettings.AssetId,
                AssetPairId    = indexSettings.AssetPairId,
                Value          = indexPrice?.Value,
                Price          = indexPrice?.Price,
                Timestamp      = indexPrice?.Timestamp,
                K              = indexPrice?.K,
                OpenTokens     = simulationParameters.OpenTokens,
                AmountInUsd    = simulationParameters.OpenTokens * indexPrice?.Price ?? 0,
                Investments    = simulationParameters.Investments,
                Alpha          = indexSettings.Alpha,
                TrackingFee    = indexSettings.TrackingFee,
                PerformanceFee = indexSettings.PerformanceFee,
                SellMarkup     = indexSettings.SellMarkup,
                SellVolume     = indexSettings.SellVolume,
                BuyVolume      = indexSettings.BuyVolume,
                PnL            = simulationParameters.OpenTokens * indexPrice?.Price - simulationParameters.Investments ?? 0
            };

            var assets = new List <AssetDistribution>();

            if (indexPrice != null)
            {
                foreach (AssetWeight assetWeight in indexPrice.Weights)
                {
                    decimal amountInUsd = simulationReport.AmountInUsd * assetWeight.Weight;

                    decimal amount = amountInUsd / assetWeight.Price;

                    assets.Add(new AssetDistribution
                    {
                        Asset       = assetWeight.AssetId,
                        Weight      = assetWeight.Weight,
                        IsHedged    = simulationParameters.Assets.Contains(assetWeight.AssetId),
                        Amount      = amount,
                        AmountInUsd = amountInUsd,
                        Price       = assetWeight.Price
                    });
                }
            }

            simulationReport.Assets = assets;

            return(simulationReport);
        }
Пример #20
0
        /// <summary>
        /// Returns true if UserTrade instances are equal
        /// </summary>
        /// <param name="other">Instance of UserTrade to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(UserTrade other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Direction == other.Direction ||

                     Direction.Equals(other.Direction)
                     ) &&
                 (
                     FeeCurrency == other.FeeCurrency ||

                     FeeCurrency.Equals(other.FeeCurrency)
                 ) &&
                 (
                     OrderId == other.OrderId ||
                     OrderId != null &&
                     OrderId.Equals(other.OrderId)
                 ) &&
                 (
                     Timestamp == other.Timestamp ||
                     Timestamp != null &&
                     Timestamp.Equals(other.Timestamp)
                 ) &&
                 (
                     Price == other.Price ||
                     Price != null &&
                     Price.Equals(other.Price)
                 ) &&
                 (
                     Iv == other.Iv ||
                     Iv != null &&
                     Iv.Equals(other.Iv)
                 ) &&
                 (
                     TradeId == other.TradeId ||
                     TradeId != null &&
                     TradeId.Equals(other.TradeId)
                 ) &&
                 (
                     Fee == other.Fee ||
                     Fee != null &&
                     Fee.Equals(other.Fee)
                 ) &&
                 (
                     OrderType == other.OrderType ||

                     OrderType.Equals(other.OrderType)
                 ) &&
                 (
                     TradeSeq == other.TradeSeq ||
                     TradeSeq != null &&
                     TradeSeq.Equals(other.TradeSeq)
                 ) &&
                 (
                     SelfTrade == other.SelfTrade ||
                     SelfTrade != null &&
                     SelfTrade.Equals(other.SelfTrade)
                 ) &&
                 (
                     State == other.State ||

                     State.Equals(other.State)
                 ) &&
                 (
                     Label == other.Label ||
                     Label != null &&
                     Label.Equals(other.Label)
                 ) &&
                 (
                     IndexPrice == other.IndexPrice ||
                     IndexPrice != null &&
                     IndexPrice.Equals(other.IndexPrice)
                 ) &&
                 (
                     Amount == other.Amount ||
                     Amount != null &&
                     Amount.Equals(other.Amount)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     TickDirection == other.TickDirection ||

                     TickDirection.Equals(other.TickDirection)
                 ) &&
                 (
                     MatchingId == other.MatchingId ||
                     MatchingId != null &&
                     MatchingId.Equals(other.MatchingId)
                 ) &&
                 (
                     Liquidity == other.Liquidity ||

                     Liquidity.Equals(other.Liquidity)
                 ));
        }
Пример #21
0
 private static string GetKey(IndexPrice indexPrice)
 => GetKey(indexPrice.Name);
Пример #22
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Direction.GetHashCode();
                if (AveragePriceUsd != null)
                {
                    hashCode = hashCode * 59 + AveragePriceUsd.GetHashCode();
                }
                if (EstimatedLiquidationPrice != null)
                {
                    hashCode = hashCode * 59 + EstimatedLiquidationPrice.GetHashCode();
                }
                if (FloatingProfitLoss != null)
                {
                    hashCode = hashCode * 59 + FloatingProfitLoss.GetHashCode();
                }
                if (FloatingProfitLossUsd != null)
                {
                    hashCode = hashCode * 59 + FloatingProfitLossUsd.GetHashCode();
                }
                if (OpenOrdersMargin != null)
                {
                    hashCode = hashCode * 59 + OpenOrdersMargin.GetHashCode();
                }
                if (TotalProfitLoss != null)
                {
                    hashCode = hashCode * 59 + TotalProfitLoss.GetHashCode();
                }
                if (RealizedProfitLoss != null)
                {
                    hashCode = hashCode * 59 + RealizedProfitLoss.GetHashCode();
                }
                if (Delta != null)
                {
                    hashCode = hashCode * 59 + Delta.GetHashCode();
                }
                if (InitialMargin != null)
                {
                    hashCode = hashCode * 59 + InitialMargin.GetHashCode();
                }
                if (Size != null)
                {
                    hashCode = hashCode * 59 + Size.GetHashCode();
                }
                if (MaintenanceMargin != null)
                {
                    hashCode = hashCode * 59 + MaintenanceMargin.GetHashCode();
                }

                hashCode = hashCode * 59 + Kind.GetHashCode();
                if (MarkPrice != null)
                {
                    hashCode = hashCode * 59 + MarkPrice.GetHashCode();
                }
                if (AveragePrice != null)
                {
                    hashCode = hashCode * 59 + AveragePrice.GetHashCode();
                }
                if (SettlementPrice != null)
                {
                    hashCode = hashCode * 59 + SettlementPrice.GetHashCode();
                }
                if (IndexPrice != null)
                {
                    hashCode = hashCode * 59 + IndexPrice.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }
                if (SizeCurrency != null)
                {
                    hashCode = hashCode * 59 + SizeCurrency.GetHashCode();
                }
                return(hashCode);
            }
        }
Пример #23
0
        /// <summary>
        /// Returns true if Position instances are equal
        /// </summary>
        /// <param name="other">Instance of Position to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Position other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Direction == other.Direction ||

                     Direction.Equals(other.Direction)
                     ) &&
                 (
                     AveragePriceUsd == other.AveragePriceUsd ||
                     AveragePriceUsd != null &&
                     AveragePriceUsd.Equals(other.AveragePriceUsd)
                 ) &&
                 (
                     EstimatedLiquidationPrice == other.EstimatedLiquidationPrice ||
                     EstimatedLiquidationPrice != null &&
                     EstimatedLiquidationPrice.Equals(other.EstimatedLiquidationPrice)
                 ) &&
                 (
                     FloatingProfitLoss == other.FloatingProfitLoss ||
                     FloatingProfitLoss != null &&
                     FloatingProfitLoss.Equals(other.FloatingProfitLoss)
                 ) &&
                 (
                     FloatingProfitLossUsd == other.FloatingProfitLossUsd ||
                     FloatingProfitLossUsd != null &&
                     FloatingProfitLossUsd.Equals(other.FloatingProfitLossUsd)
                 ) &&
                 (
                     OpenOrdersMargin == other.OpenOrdersMargin ||
                     OpenOrdersMargin != null &&
                     OpenOrdersMargin.Equals(other.OpenOrdersMargin)
                 ) &&
                 (
                     TotalProfitLoss == other.TotalProfitLoss ||
                     TotalProfitLoss != null &&
                     TotalProfitLoss.Equals(other.TotalProfitLoss)
                 ) &&
                 (
                     RealizedProfitLoss == other.RealizedProfitLoss ||
                     RealizedProfitLoss != null &&
                     RealizedProfitLoss.Equals(other.RealizedProfitLoss)
                 ) &&
                 (
                     Delta == other.Delta ||
                     Delta != null &&
                     Delta.Equals(other.Delta)
                 ) &&
                 (
                     InitialMargin == other.InitialMargin ||
                     InitialMargin != null &&
                     InitialMargin.Equals(other.InitialMargin)
                 ) &&
                 (
                     Size == other.Size ||
                     Size != null &&
                     Size.Equals(other.Size)
                 ) &&
                 (
                     MaintenanceMargin == other.MaintenanceMargin ||
                     MaintenanceMargin != null &&
                     MaintenanceMargin.Equals(other.MaintenanceMargin)
                 ) &&
                 (
                     Kind == other.Kind ||

                     Kind.Equals(other.Kind)
                 ) &&
                 (
                     MarkPrice == other.MarkPrice ||
                     MarkPrice != null &&
                     MarkPrice.Equals(other.MarkPrice)
                 ) &&
                 (
                     AveragePrice == other.AveragePrice ||
                     AveragePrice != null &&
                     AveragePrice.Equals(other.AveragePrice)
                 ) &&
                 (
                     SettlementPrice == other.SettlementPrice ||
                     SettlementPrice != null &&
                     SettlementPrice.Equals(other.SettlementPrice)
                 ) &&
                 (
                     IndexPrice == other.IndexPrice ||
                     IndexPrice != null &&
                     IndexPrice.Equals(other.IndexPrice)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     SizeCurrency == other.SizeCurrency ||
                     SizeCurrency != null &&
                     SizeCurrency.Equals(other.SizeCurrency)
                 ));
        }
Пример #24
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (SessionProfitLoss != null)
                {
                    hashCode = hashCode * 59 + SessionProfitLoss.GetHashCode();
                }
                if (MarkPrice != null)
                {
                    hashCode = hashCode * 59 + MarkPrice.GetHashCode();
                }
                if (Funding != null)
                {
                    hashCode = hashCode * 59 + Funding.GetHashCode();
                }
                if (Socialized != null)
                {
                    hashCode = hashCode * 59 + Socialized.GetHashCode();
                }
                if (SessionBankrupcy != null)
                {
                    hashCode = hashCode * 59 + SessionBankrupcy.GetHashCode();
                }
                if (Timestamp != null)
                {
                    hashCode = hashCode * 59 + Timestamp.GetHashCode();
                }
                if (ProfitLoss != null)
                {
                    hashCode = hashCode * 59 + ProfitLoss.GetHashCode();
                }
                if (Funded != null)
                {
                    hashCode = hashCode * 59 + Funded.GetHashCode();
                }
                if (IndexPrice != null)
                {
                    hashCode = hashCode * 59 + IndexPrice.GetHashCode();
                }
                if (SessionTax != null)
                {
                    hashCode = hashCode * 59 + SessionTax.GetHashCode();
                }
                if (SessionTaxRate != null)
                {
                    hashCode = hashCode * 59 + SessionTaxRate.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }
                if (Position != null)
                {
                    hashCode = hashCode * 59 + Position.GetHashCode();
                }

                hashCode = hashCode * 59 + Type.GetHashCode();
                return(hashCode);
            }
        }
Пример #25
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Direction.GetHashCode();

                hashCode = hashCode * 59 + FeeCurrency.GetHashCode();
                if (OrderId != null)
                {
                    hashCode = hashCode * 59 + OrderId.GetHashCode();
                }
                if (Timestamp != null)
                {
                    hashCode = hashCode * 59 + Timestamp.GetHashCode();
                }
                if (Price != null)
                {
                    hashCode = hashCode * 59 + Price.GetHashCode();
                }
                if (Iv != null)
                {
                    hashCode = hashCode * 59 + Iv.GetHashCode();
                }
                if (TradeId != null)
                {
                    hashCode = hashCode * 59 + TradeId.GetHashCode();
                }
                if (Fee != null)
                {
                    hashCode = hashCode * 59 + Fee.GetHashCode();
                }

                hashCode = hashCode * 59 + OrderType.GetHashCode();
                if (TradeSeq != null)
                {
                    hashCode = hashCode * 59 + TradeSeq.GetHashCode();
                }
                if (SelfTrade != null)
                {
                    hashCode = hashCode * 59 + SelfTrade.GetHashCode();
                }

                hashCode = hashCode * 59 + State.GetHashCode();
                if (Label != null)
                {
                    hashCode = hashCode * 59 + Label.GetHashCode();
                }
                if (IndexPrice != null)
                {
                    hashCode = hashCode * 59 + IndexPrice.GetHashCode();
                }
                if (Amount != null)
                {
                    hashCode = hashCode * 59 + Amount.GetHashCode();
                }
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }

                hashCode = hashCode * 59 + TickDirection.GetHashCode();
                if (MatchingId != null)
                {
                    hashCode = hashCode * 59 + MatchingId.GetHashCode();
                }

                hashCode = hashCode * 59 + Liquidity.GetHashCode();
                return(hashCode);
            }
        }
        public async Task <IndexPriceModel> GetByIndexAsync(string indexName)
        {
            IndexPrice indexPrice = await _indexPriceService.GetByIndexAsync(indexName);

            return(Mapper.Map <IndexPriceModel>(indexPrice));
        }