Exemplo n.º 1
0
        public async Task <RiskExposureReport> GetAsync()
        {
            IReadOnlyCollection <AssetInvestment> investments     = _investmentService.GetAll();
            IReadOnlyCollection <IndexSettings>   indicesSettings = await _indexSettingsService.GetAllAsync();

            IReadOnlyCollection <IndexPrice> indexPrices = await _indexPriceService.GetAllAsync();

            IReadOnlyCollection <Token> tokens = await _tokenService.GetAllAsync();

            IReadOnlyCollection <AssetHedgeSettings> assetHedgeSettings = await _assetHedgeSettingsService.GetAllAsync();

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

            IReadOnlyCollection <string> assets = indexPrices
                                                  .SelectMany(o => o.Weights?.Select(e => e.AssetId) ?? new string[0])
                                                  .Distinct()
                                                  .ToArray();

            decimal totalRemainingAmount = investments.Sum(o => o.RemainingAmount);

            return(new RiskExposureReport
            {
                // If remaining amount is negative position in usd should be displayed as positive.
                UsdCash = -totalRemainingAmount,
                Indices = GetIndexReports(indicesSettings, indexPrices, tokens),
                Tokens = GetTokensDelta(indicesSettings, indexPrices, tokens),
                Assets = GetAssetsDelta(assets, assetHedgeSettings, positions)
            });
        }
        public async Task UpdateLimitOrdersAsync()
        {
            IReadOnlyCollection <string> assets = await GetAssetsAsync();

            await CancelLimitOrdersAsync(assets);

            if (!await ValidateIndexPricesAsync())
            {
                return;
            }

            IReadOnlyCollection <Token> tokens = await _tokenService.GetAllAsync();

            IReadOnlyCollection <Position> positions = await GetCurrentPositionsAsync();

            IReadOnlyCollection <IndexPrice> indexPrices = await _indexPriceService.GetAllAsync();

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

            IReadOnlyDictionary <string, Quote> assetPrices = await GetAssetPricesAsync(assets);

            IReadOnlyCollection <AssetInvestment> assetInvestments =
                InvestmentCalculator.Calculate(assets, indicesSettings, tokens, indexPrices, positions, assetPrices);

            _log.InfoWithDetails("Investments calculated", assetInvestments);

            IReadOnlyCollection <HedgeLimitOrder> hedgeLimitOrders = await CreateLimitOrdersAsync(assetInvestments);

            await ValidateHedgeLimitOrdersAsync(hedgeLimitOrders);

            _log.InfoWithDetails("Hedge limit orders calculated", hedgeLimitOrders);

            _investmentService.Update(assetInvestments);

            await ApplyLimitOrdersAsync(assets, hedgeLimitOrders);
        }
        public async Task <IReadOnlyCollection <IndexPriceModel> > GetAllAsync()
        {
            IReadOnlyCollection <IndexPrice> indexStates = await _indexPriceService.GetAllAsync();

            return(Mapper.Map <IndexPriceModel[]>(indexStates));
        }