Ejemplo n.º 1
0
        public async Task <decimal?> ConvertPriceAsync(string assetPairId, decimal price)
        {
            AssetPair assetPair = await _assetsServiceWithCache.TryGetAssetPairAsync(assetPairId);

            if (assetPair.QuotingAssetId == UsdAssetId)
            {
                return(price);
            }

            IReadOnlyCollection <CrossRateInstrument> crossInstruments = await GetAllAsync();

            CrossRateInstrument crossInstrument = crossInstruments.SingleOrDefault(o => o.AssetPairId == assetPairId);

            if (crossInstrument == null)
            {
                _log.WarningWithDetails("Cross instrument not found", assetPairId);
                return(null);
            }

            Quote quote = await _quoteService
                          .GetAsync(crossInstrument.QuoteSource, crossInstrument.ExternalAssetPairId);

            if (quote == null)
            {
                _log.WarningWithDetails("No quote for cross instrument", crossInstrument);
                return(null);
            }

            (decimal crossPrice, decimal _) =
                Calculator.CalculateCrossMidPrice(price, quote, crossInstrument.IsInverse);

            return(crossPrice);
        }
Ejemplo n.º 2
0
        public async Task AddAsync(CrossRateInstrument crossInstrument)
        {
            await _crossRateInstrumentRepository.InsertAsync(crossInstrument);

            _cache.Set(crossInstrument);

            _log.InfoWithDetails("Cross-rate instrument was added", crossInstrument);
        }
 public async Task UpdateAsync(CrossRateInstrument instrument)
 {
     await _storage.MergeAsync(GetPartitionKey(), GetRowKey(instrument.AssetPairId), entity =>
     {
         Mapper.Map(instrument, entity);
         return(entity);
     });
 }
        public async Task InsertAsync(CrossRateInstrument instrument)
        {
            var entity = new CrossRateInstrumentEntity(GetPartitionKey(), GetRowKey(instrument.AssetPairId));

            Mapper.Map(instrument, entity);

            await _storage.InsertThrowConflictAsync(entity);
        }
Ejemplo n.º 5
0
        public async Task DeleteAsync(string assetPairId)
        {
            CrossRateInstrument crossInstrument = await GetByAssetPairIdAsync(assetPairId);

            await _crossRateInstrumentRepository.DeleteAsync(assetPairId);

            _cache.Remove(assetPairId);

            _log.InfoWithDetails("Cross-rate instrument was deleted", crossInstrument);
        }
Ejemplo n.º 6
0
        public async Task UpdateAsync(CrossRateInstrument crossInstrument)
        {
            CrossRateInstrument currentCrossInstrument = await GetByAssetPairIdAsync(crossInstrument.AssetPairId);

            currentCrossInstrument.Update(crossInstrument);

            await _crossRateInstrumentRepository.UpdateAsync(currentCrossInstrument);

            _cache.Set(currentCrossInstrument);

            _log.InfoWithDetails("Cross-rate instrument was updated", currentCrossInstrument);
        }
Ejemplo n.º 7
0
        public async Task <CrossRateInstrument> GetByAssetPairIdAsync(string assetPairId)
        {
            IReadOnlyCollection <CrossRateInstrument> crossInstruments = await GetAllAsync();

            CrossRateInstrument crossInstrument = crossInstruments.SingleOrDefault(o => o.AssetPairId == assetPairId);

            if (crossInstrument == null)
            {
                throw new EntityNotFoundException();
            }

            return(crossInstrument);
        }
Ejemplo n.º 8
0
        public async Task <CrossRateInstrumentModel> GetByAssetPairIdAsync(string assetPairId)
        {
            try
            {
                CrossRateInstrument crossInstrument =
                    await _crossRateInstrumentService.GetByAssetPairIdAsync(assetPairId);

                return(Mapper.Map <CrossRateInstrumentModel>(crossInstrument));
            }
            catch (EntityNotFoundException)
            {
                throw new ValidationApiException(HttpStatusCode.NotFound, "Cross-rate instrument does not exist.");
            }
        }
 public void Update(CrossRateInstrument crossInstrument)
 {
     QuoteSource         = crossInstrument.QuoteSource;
     ExternalAssetPairId = crossInstrument.ExternalAssetPairId;
     IsInverse           = crossInstrument.IsInverse;
 }